use of org.opencb.opencga.catalog.exceptions.CatalogException in project opencga by opencb.
the class IndividualQcUtils method getSamples.
public static List<String> getSamples(String study, String familyId, CatalogManager catalogManager, String token) throws ToolException {
Set<String> sampleSet = new HashSet<>();
// Sanity check
if (StringUtils.isEmpty(familyId)) {
throw new ToolException("Missing family ID");
}
try {
OpenCGAResult<Family> familyResult = catalogManager.getFamilyManager().get(study, familyId, QueryOptions.empty(), token);
// Check family result
if (familyResult.getResults().size() == 0) {
throw new ToolException("Family not found for family ID '" + familyId + "'");
}
if (familyResult.getResults().size() > 1) {
throw new ToolException("More than one family result for family ID '" + familyId + "'");
}
// Get list of individual IDs
List<String> individualIds = familyResult.first().getMembers().stream().map(m -> m.getId()).collect(Collectors.toList());
// Populate individual (and sample IDs) from individual IDs
Query query = new Query(IndividualDBAdaptor.QueryParams.ID.key(), individualIds);
QueryOptions queryOptions = new QueryOptions(QueryOptions.INCLUDE, "samples.id");
OpenCGAResult<Individual> individualResult = catalogManager.getIndividualManager().search(study, query, queryOptions, token);
for (Individual individual : individualResult.getResults()) {
sampleSet.addAll(individual.getSamples().stream().map(s -> s.getId()).collect(Collectors.toList()));
}
} catch (CatalogException e) {
throw new ToolException(e);
}
return sampleSet.stream().collect(Collectors.toList());
}
use of org.opencb.opencga.catalog.exceptions.CatalogException in project opencga by opencb.
the class IndividualQcUtils method getFamilyByIndividualId.
public static Family getFamilyByIndividualId(String studyId, String individualId, CatalogManager catalogManager, String token) throws ToolException {
Query query = new Query();
query.put("members", individualId);
OpenCGAResult<Family> familyResult;
try {
familyResult = catalogManager.getFamilyManager().search(studyId, query, QueryOptions.empty(), token);
} catch (CatalogException e) {
throw new ToolException(e);
}
if (familyResult.getNumResults() == 0) {
return null;
}
// Return the first family
return familyResult.first();
}
use of org.opencb.opencga.catalog.exceptions.CatalogException in project opencga by opencb.
the class InferredSexComputation method computeRatios.
@Deprecated
public static double[] computeRatios(String study, String sample, String assembly, FileManager fileManager, AlignmentStorageManager alignmentStorageManager, String token) throws ToolException {
// Look for the bam file for each sample
OpenCGAResult<File> fileQueryResult;
Query query = new Query(FileDBAdaptor.QueryParams.FORMAT.key(), File.Format.BAM);
QueryOptions queryOptions = new QueryOptions(QueryOptions.INCLUDE, FileDBAdaptor.QueryParams.UUID.key());
query.put(FileDBAdaptor.QueryParams.SAMPLE_IDS.key(), sample);
try {
fileQueryResult = fileManager.search(study, query, queryOptions, token);
} catch (CatalogException e) {
throw new ToolException(e);
}
// Sanity check
if (fileQueryResult.getNumResults() == 0) {
throw new ToolException("BAM file not found for sample " + sample);
}
if (fileQueryResult.getNumResults() > 1) {
throw new ToolException("Found more than one BAM files (" + fileQueryResult.getNumResults() + ") for sample " + sample);
}
// Compute coverage for each chromosome for each BAM file
// TODO get chromosomes from cellbase
Map<String, Integer> chromosomes;
if (assembly.toLowerCase().equals("grch37")) {
chromosomes = GRCH37_CHROMOSOMES;
} else {
chromosomes = GRCH38_CHROMOSOMES;
}
double[] means = new double[] { 0d, 0d, 0d };
for (String chrom : chromosomes.keySet()) {
int chromSize = chromosomes.get(chrom);
Region region = new Region(chrom, 1, chromSize - 1);
try {
List<RegionCoverage> regionCoverages = alignmentStorageManager.coverageQuery(study, fileQueryResult.first().getUuid(), region, 0, 100, chromSize, token).getResults();
double meanCoverage = 0d;
for (RegionCoverage regionCoverage : regionCoverages) {
meanCoverage += regionCoverage.meanCoverage();
}
meanCoverage /= regionCoverages.size();
String name = chrom.toUpperCase();
switch(name) {
case "Y":
{
means[2] = meanCoverage;
break;
}
case "X":
{
means[1] = meanCoverage;
break;
}
default:
{
means[0] += meanCoverage;
break;
}
}
} catch (Exception e) {
throw new ToolException(e);
}
}
means[0] /= (chromosomes.size() - 2);
// Create sex report for that sample
return new double[] { 1.0d * means[1] / means[0], 1.0d * means[2] / means[0] };
}
use of org.opencb.opencga.catalog.exceptions.CatalogException in project opencga by opencb.
the class JobIndexTask method run.
@Override
protected void run() throws Exception {
// Get all the studies
Query query = new Query();
QueryOptions options = new QueryOptions().append(QueryOptions.INCLUDE, Arrays.asList(StudyDBAdaptor.QueryParams.UID.key(), StudyDBAdaptor.QueryParams.ID.key(), StudyDBAdaptor.QueryParams.FQN.key(), StudyDBAdaptor.QueryParams.VARIABLE_SET.key())).append(DBAdaptor.INCLUDE_ACLS, true);
OpenCGAResult<Study> studyDataResult = catalogManager.getStudyManager().search(query, options, token);
if (studyDataResult.getNumResults() == 0) {
throw new CatalogException("Could not index catalog into solr. No studies found");
}
// Create solr collections if they don't exist
catalogSolrManager.createSolrCollections(CatalogSolrManager.JOB_SOLR_COLLECTION);
for (Study study : studyDataResult.getResults()) {
Map<String, Set<String>> studyAcls = SolrConverterUtil.parseInternalOpenCGAAcls((List<Map<String, Object>>) study.getAttributes().get("OPENCGA_ACL"));
// We replace the current studyAcls for the parsed one
study.getAttributes().put("OPENCGA_ACL", studyAcls);
indexJob(catalogSolrManager, study);
}
}
use of org.opencb.opencga.catalog.exceptions.CatalogException in project opencga by opencb.
the class TieringInterpretationAnalysisExecutor method query.
private Boolean query(Pedigree pedigree, Disorder disorder, Map<String, String> sampleMap, ClinicalProperty.ModeOfInheritance moi, Map<ClinicalProperty.ModeOfInheritance, List<Variant>> resultMap) {
Query query;
Map<String, List<String>> genotypes;
switch(moi) {
case AUTOSOMAL_DOMINANT:
query = new Query(dominantQuery);
genotypes = ModeOfInheritance.dominant(pedigree, disorder, penetrance);
break;
case Y_LINKED:
query = new Query(dominantQuery).append(VariantQueryParam.REGION.key(), "Y");
genotypes = ModeOfInheritance.yLinked(pedigree, disorder, penetrance);
break;
case X_LINKED_DOMINANT:
query = new Query(dominantQuery).append(VariantQueryParam.REGION.key(), "X");
genotypes = ModeOfInheritance.xLinked(pedigree, disorder, true, penetrance);
break;
case AUTOSOMAL_RECESSIVE:
query = new Query(recessiveQuery);
genotypes = ModeOfInheritance.recessive(pedigree, disorder, penetrance);
break;
case X_LINKED_RECESSIVE:
query = new Query(recessiveQuery).append(VariantQueryParam.REGION.key(), "X");
genotypes = ModeOfInheritance.xLinked(pedigree, disorder, false, penetrance);
break;
case MITOCHONDRIAL:
query = new Query(mitochondrialQuery);
genotypes = ModeOfInheritance.mitochondrial(pedigree, disorder, penetrance);
filterOutHealthyGenotypes(genotypes);
break;
default:
return false;
}
query.append(VariantQueryParam.INCLUDE_GENOTYPE.key(), true).append(VariantQueryParam.STUDY.key(), studyId).append(VariantQueryParam.FILTER.key(), VCFConstants.PASSES_FILTERS_v4).append(VariantQueryParam.UNKNOWN_GENOTYPE.key(), "./.");
if (ModeOfInheritance.isEmptyMapOfGenotypes(genotypes)) {
return false;
}
addGenotypeFilter(genotypes, sampleMap, query);
try {
resultMap.put(moi, clinicalInterpretationManager.getVariantStorageManager().get(query, QueryOptions.empty(), sessionId).getResults());
} catch (CatalogException | StorageEngineException | IOException e) {
return false;
}
return true;
}
Aggregations