private File getOriginalFromTransformed(String study, File file, String sessionId)
throws URISyntaxException, CatalogException {
String vcfId = null;
if (file.getRelatedFiles() == null || file.getRelatedFiles().isEmpty()) {
catalogManager.getFileManager().matchUpVariantFiles(null, Collections.singletonList(file), sessionId);
}
for (File.RelatedFile relatedFile : file.getRelatedFiles()) {
if (File.RelatedFile.Relation.PRODUCED_FROM.equals(relatedFile.getRelation())) {
long fileUid = relatedFile.getFileId();
vcfId = catalogManager.getFileManager().get(study,
new Query(UID.key(), fileUid),
new QueryOptions(QueryOptions.INCLUDE, ID.key()), sessionId).first().getId();
break;
}
}
if (vcfId == null) {
logger.error("This code should never be executed. Every transformed avro file should come from a registered vcf file");
throw new CatalogException("Internal error. No vcf file could be found for file " + file.getPath());
}
QueryResult<File> vcfQueryResult = fileManager.get(study, vcfId, FILE_GET_QUERY_OPTIONS, sessionId);
if (vcfQueryResult.getNumResults() != 1) {
logger.error("This code should never be executed. No vcf file could be found for vcf id " + vcfId);
throw new CatalogException("Internal error. No vcf file could be found under id " + vcfId);
}
file = vcfQueryResult.first();
return file;
}