Skip to content

Commit

Permalink
storage: Fix return annotation from sample data. Fix test. #TASK-6005
Browse files Browse the repository at this point in the history
  • Loading branch information
j-coll committed May 15, 2024
1 parent c668143 commit f6b73fe
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.mockito.Mockito;
import org.opencb.biodata.models.variant.metadata.Aggregation;
import org.opencb.biodata.models.variant.metadata.VariantSetStats;
import org.opencb.commons.datastore.core.DataResult;
import org.opencb.commons.datastore.core.Event;
import org.opencb.commons.datastore.core.Query;
import org.opencb.commons.datastore.core.QueryOptions;
Expand All @@ -43,8 +42,8 @@
import org.opencb.opencga.core.models.file.File;
import org.opencb.opencga.core.models.file.FileInternalVariantIndex;
import org.opencb.opencga.core.models.file.VariantIndexStatus;
import org.opencb.opencga.core.models.study.Study;
import org.opencb.opencga.core.models.operations.variant.VariantIndexParams;
import org.opencb.opencga.core.models.study.Study;
import org.opencb.opencga.core.testclassification.duration.MediumTests;
import org.opencb.opencga.core.tools.result.ExecutionResult;
import org.opencb.opencga.storage.core.StorageEngineFactory;
Expand Down Expand Up @@ -186,7 +185,7 @@ public void testDeleteIndexedFile() throws Exception {
Study study = catalogManager.getFileManager().getStudy(inputFile, sessionId);

thrown.expect(CatalogException.class);
thrown.expectMessage("The status is READY");
thrown.expectMessage("Could not unlink file '" + inputFile.getId() + "'");
catalogManager.getFileManager().unlink(study.getFqn(), inputFile.getId(), sessionId);
}

Expand All @@ -200,7 +199,7 @@ public void testDeleteSampleFromIndexedFile() throws Exception {
Query query = new Query(SampleDBAdaptor.QueryParams.ID.key(), inputFile.getSampleIds().get(100));
thrown.expect(CatalogException.class);
thrown.expectMessage("Sample associated to the files");
DataResult delete = catalogManager.getSampleManager().delete(studyFqn, query, null, sessionId);
catalogManager.getSampleManager().delete(studyFqn, query, null, sessionId);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1832,9 +1832,9 @@ public OpenCGAResult<File> unlink(@Nullable String studyId, String fileId, Strin
study.getUuid(), auditParams, new AuditRecord.Status(AuditRecord.Status.Result.SUCCESS));

return result;
} catch (CatalogException e) {
} catch (Exception e) {
auditManager.audit(userId, Enums.Action.UNLINK, Enums.Resource.FILE, fileId, "", study.getId(), study.getUuid(),
auditParams, new AuditRecord.Status(AuditRecord.Status.Result.ERROR, e.getError()));
auditParams, new AuditRecord.Status(AuditRecord.Status.Result.ERROR, new Error(0, "", e.getMessage())));
throw new CatalogException("Could not unlink file '" + fileId + "'", e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public HBaseVariantSampleDataManager(VariantHadoopDBAdaptor dbAdaptor) {
}

@Override
protected DataResult<Variant> getSampleData(Variant variant, String study, QueryOptions options,
protected DataResult<Variant> getSampleData(Variant inputVariant, String study, QueryOptions options,
List<String> includeSamples,
Set<String> genotypes,
int sampleLimit) {
Expand All @@ -78,14 +78,15 @@ protected DataResult<Variant> getSampleData(Variant variant, String study, Query

int skip = Math.max(0, options.getInt(QueryOptions.SKIP, 0));
int limit = Math.max(0, options.getInt(QueryOptions.LIMIT, 10));
byte[] rowKey = VariantPhoenixKeyFactory.generateVariantRowKey(inputVariant);

try {
List<Integer> samples = new ArrayList<>(limit);
List<VariantRow.SampleColumn> sampleDataMap = new ArrayList<>(limit);

dbAdaptor.getHBaseManager().act(dbAdaptor.getVariantTable(), table -> {
// Create one GET for samples
Get get = new Get(VariantPhoenixKeyFactory.generateVariantRowKey(variant));
Get get = new Get(rowKey);
LinkedList<Filter> filters = new LinkedList<>();

filters.add(new QualifierFilter(CompareFilter.CompareOp.EQUAL,
Expand Down Expand Up @@ -127,7 +128,7 @@ protected DataResult<Variant> getSampleData(Variant variant, String study, Query
samples.add(sampleColumn.getSampleId());
sampleDataMap.add(sampleColumn);
}
}).walk(variant);
}).walk(inputVariant);
}
});

Expand All @@ -136,8 +137,9 @@ protected DataResult<Variant> getSampleData(Variant variant, String study, Query
Set<Integer> fileIdsFromSampleIds = metadataManager.getFileIdsFromSampleIds(studyId, samples);
HBaseToVariantStatsConverter statsConverter = new HBaseToVariantStatsConverter();
List<VariantStats> stats = new LinkedList<>();
Variant variantResult = new Variant(inputVariant.toString());
dbAdaptor.getHBaseManager().act(dbAdaptor.getVariantTable(), table -> {
Get get = new Get(VariantPhoenixKeyFactory.generateVariantRowKey(variant));
Get get = new Get(rowKey);

// Add file columns
for (Integer fileId : fileIdsFromSampleIds) {
Expand All @@ -161,7 +163,7 @@ protected DataResult<Variant> getSampleData(Variant variant, String study, Query
Result result = table.get(get);

if (result == null || result.isEmpty()) {
throw VariantQueryException.variantNotFound(variant.toString());
throw VariantQueryException.variantNotFound(variantResult.toString());
}
// Walk row
VariantRow.walker(result)
Expand All @@ -175,9 +177,9 @@ protected DataResult<Variant> getSampleData(Variant variant, String study, Query
})
.onVariantAnnotation(column -> {
ImmutableBytesWritable b = column.toBytesWritable();
variant.setAnnotation(new HBaseToVariantAnnotationConverter().convert(b.get(), b.getOffset(), b.getLength()));
variantResult.setAnnotation(new HBaseToVariantAnnotationConverter().convert(b));
})
.walk(variant);
.walk(variantResult);
});

// Convert to VariantSampleData
Expand All @@ -193,8 +195,7 @@ protected DataResult<Variant> getSampleData(Variant variant, String study, Query
new ArrayList<>(fileIdsFromSampleIds)))
.build());

Variant variantResult = new Variant(variant.toString());
variantResult.setId(variant.toString());
variantResult.setId(inputVariant.toString());
StudyEntry studyEntry = converter.convert(sampleDataMap, filesMap, variantResult, studyId);

variantResult.addStudyEntry(studyEntry);
Expand Down

0 comments on commit f6b73fe

Please sign in to comment.