Skip to content

Commit

Permalink
Add Qvalue for Structural Variant and CNA
Browse files Browse the repository at this point in the history
  • Loading branch information
haynescd committed Oct 2, 2024
1 parent b3f345e commit 7c1ba35
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.cbioportal.model.AlterationFilter;
import org.cbioportal.model.AlterationType;
import org.cbioportal.model.CopyNumberCountByGene;
import org.cbioportal.model.Gistic;
import org.cbioportal.model.GisticToGene;
import org.cbioportal.model.MolecularProfile;
import org.cbioportal.model.MolecularProfileCaseIdentifier;
import org.cbioportal.model.MutSig;
Expand All @@ -16,6 +18,7 @@
import org.cbioportal.persistence.MolecularProfileRepository;
import org.cbioportal.persistence.StudyViewRepository;
import org.cbioportal.service.AlterationCountService;
import org.cbioportal.service.SignificantCopyNumberRegionService;
import org.cbioportal.service.SignificantlyMutatedGeneService;
import org.cbioportal.service.exception.StudyNotFoundException;
import org.cbioportal.service.util.AlterationEnrichmentUtil;
Expand Down Expand Up @@ -46,8 +49,8 @@ public class AlterationCountServiceImpl implements AlterationCountService {
private final AlterationEnrichmentUtil<AlterationCountByStructuralVariant> alterationEnrichmentUtilStructVar;
private final MolecularProfileRepository molecularProfileRepository;
private final SignificantlyMutatedGeneService significantlyMutatedGeneService;

private final StudyViewRepository studyViewRepository;
private final SignificantCopyNumberRegionService significantCopyNumberRegionService;

private static final String WHOLE_EXOME_SEQUENCING = "WES";

Expand All @@ -57,14 +60,16 @@ public AlterationCountServiceImpl(AlterationRepository alterationRepository, Alt
AlterationEnrichmentUtil<CopyNumberCountByGene> alterationEnrichmentUtilCna,
AlterationEnrichmentUtil<AlterationCountByStructuralVariant> alterationEnrichmentUtilStructVar,
MolecularProfileRepository molecularProfileRepository,
StudyViewRepository studyViewRepository, SignificantlyMutatedGeneService significantlyMutatedGeneService) {
StudyViewRepository studyViewRepository, SignificantlyMutatedGeneService significantlyMutatedGeneService,
SignificantCopyNumberRegionService significantCopyNumberRegionService) {
this.alterationRepository = alterationRepository;
this.alterationEnrichmentUtil = alterationEnrichmentUtil;
this.alterationEnrichmentUtilCna = alterationEnrichmentUtilCna;
this.alterationEnrichmentUtilStructVar = alterationEnrichmentUtilStructVar;
this.molecularProfileRepository = molecularProfileRepository;
this.studyViewRepository = studyViewRepository;
this.significantlyMutatedGeneService = significantlyMutatedGeneService;
this.significantCopyNumberRegionService = significantCopyNumberRegionService;
}
@Override
public Pair<List<AlterationCountByGene>, Long> getSampleAlterationGeneCounts(List<MolecularProfileCaseIdentifier> molecularProfileCaseIdentifiers,
Expand Down Expand Up @@ -260,32 +265,23 @@ public Pair<List<CopyNumberCountByGene>, Long> getPatientCnaGeneCounts(List<Mole

@Override
public List<AlterationCountByGene> getMutatedGenes(StudyViewFilterContext studyViewFilterContext) throws StudyNotFoundException {
var alterationCountByGenes = studyViewRepository.getMutatedGenes(studyViewFilterContext);
var updatedAlterationCounts = populateAlterationCounts(combineAlterationCountsWithConflictingHugoSymbols(alterationCountByGenes), studyViewFilterContext, AlterationType.MUTATION_EXTENDED);
// Query MutSig
final var mutSigs = getMutSigs(studyViewFilterContext);
// If MutSig is not empty update Mutated Genes
if (!mutSigs.isEmpty()) {
updatedAlterationCounts.parallelStream()
.filter(alterationCount -> mutSigs.containsKey(alterationCount.getHugoGeneSymbol()))
.forEach(alterationCount ->
alterationCount.setqValue(mutSigs.get(alterationCount.getHugoGeneSymbol()).getqValue())
);
}
return updatedAlterationCounts;
var alterationCountByGenes = populateAlterationCounts(combineAlterationCountsWithConflictingHugoSymbols( studyViewRepository.getMutatedGenes(studyViewFilterContext)),
studyViewFilterContext, AlterationType.MUTATION_EXTENDED);
return populateAlterationCountsWithMutSigQValue(alterationCountByGenes, studyViewFilterContext);
}

public List<CopyNumberCountByGene> getCnaGenes(StudyViewFilterContext studyViewFilterContext) throws StudyNotFoundException {
var copyNumberCountByGenes = studyViewRepository.getCnaGenes(studyViewFilterContext);
return populateAlterationCounts(combineCopyNumberCountsWithConflictingHugoSymbols(copyNumberCountByGenes), studyViewFilterContext, AlterationType.COPY_NUMBER_ALTERATION);
var copyNumberAlterationCounts = populateAlterationCounts(combineCopyNumberCountsWithConflictingHugoSymbols(studyViewRepository.getCnaGenes(studyViewFilterContext)), studyViewFilterContext, AlterationType.COPY_NUMBER_ALTERATION);
return populateAlterationCountsWithCNASigQValue(copyNumberAlterationCounts, studyViewFilterContext);
}

@Override
public List<AlterationCountByGene> getStructuralVariantGenes(StudyViewFilterContext studyViewFilterContext) throws StudyNotFoundException {
var alterationCountByGenes = studyViewRepository.getStructuralVariantGenes(studyViewFilterContext);
return populateAlterationCounts(combineAlterationCountsWithConflictingHugoSymbols(alterationCountByGenes), studyViewFilterContext, AlterationType.STRUCTURAL_VARIANT);
var alterationCountByGenes = populateAlterationCounts(combineAlterationCountsWithConflictingHugoSymbols(studyViewRepository.getStructuralVariantGenes(studyViewFilterContext)),
studyViewFilterContext, AlterationType.STRUCTURAL_VARIANT);
return populateAlterationCountsWithMutSigQValue(alterationCountByGenes, studyViewFilterContext);
}

private < T extends AlterationCountByGene> List<T> populateAlterationCounts(@NonNull List<T> alterationCounts,
@NonNull StudyViewFilterContext studyViewFilterContext,
@NonNull AlterationType alterationType) {
Expand All @@ -312,6 +308,30 @@ private < T extends AlterationCountByGene> List<T> populateAlterationCounts(@Non
return alterationCounts;
}

private List<AlterationCountByGene> populateAlterationCountsWithMutSigQValue(List<AlterationCountByGene> alterationCountByGenes, StudyViewFilterContext studyViewFilterContext) throws StudyNotFoundException {
final var mutSigs = getMutSigs(studyViewFilterContext);
// If MutSig is not empty update Mutated Genes
if (!mutSigs.isEmpty()) {
alterationCountByGenes.parallelStream()
.filter(alterationCount -> mutSigs.containsKey(alterationCount.getHugoGeneSymbol()))
.forEach(alterationCount ->
alterationCount.setqValue(mutSigs.get(alterationCount.getHugoGeneSymbol()).getqValue())
);
}
return alterationCountByGenes;
}

private List<CopyNumberCountByGene> populateAlterationCountsWithCNASigQValue(List<CopyNumberCountByGene> alterationCountByGenes, StudyViewFilterContext studyViewFilterContext) throws StudyNotFoundException {
final var gisticMap = getGisticMap(studyViewFilterContext);
alterationCountByGenes.parallelStream()
.filter(alterationCount -> gisticMap.containsKey(Pair.create(alterationCount.getHugoGeneSymbol(), alterationCount.getAlteration())))
.forEach(alterationCount -> {
alterationCount.setqValue(gisticMap.get(Pair.create(alterationCount.getHugoGeneSymbol(), alterationCount.getAlteration())).getqValue());
});
return alterationCountByGenes;
}


/**
* Combines alteration counts by Hugo gene symbols. If multiple entries exist for the same
* gene symbol, their number of altered cases and total counts are summed up. Returns a
Expand Down Expand Up @@ -384,6 +404,32 @@ private Map<String, MutSig> getMutSigs(StudyViewFilterContext studyViewFilterCon
}
return mutSigs;
}

private Map<Pair<String, Integer>, Gistic> getGisticMap(StudyViewFilterContext studyViewFilterContext) throws StudyNotFoundException {
var distinctStudyIds = new HashSet<>(studyViewFilterContext.studyViewFilter().getStudyIds()).stream().toList();
Map<Pair<String, Integer>, Gistic> gisticMap = new HashMap<>();
if (distinctStudyIds.size() == 1) {
var studyId = distinctStudyIds.getFirst();
List<Gistic> gisticList = significantCopyNumberRegionService.getSignificantCopyNumberRegions(
studyId,
Projection.SUMMARY.name(),
null,
null,
null,
null);
for(Gistic gistic : gisticList) {
var amp = (gistic.getAmp()) ? 2 : -2;
for (GisticToGene gene : gistic.getGenes()) {
var key = Pair.create(gene.getHugoGeneSymbol(), amp);
Gistic g = gisticMap.get(key);
if (g == null || g.getqValue().compareTo(gistic.getqValue()) < 0) {
gisticMap.put(key, g);
}
}
}
}
return gisticMap;
}

private <S extends AlterationCountBase> Pair<List<S>, Long> getAlterationGeneCounts(
List<MolecularProfileCaseIdentifier> molecularProfileCaseIdentifiers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public class AlterationCountServiceImplTest extends BaseServiceImplTest {
private StudyViewRepository studyViewRepository;
@Mock
private SignificantlyMutatedGeneService significantlyMutatedGeneService;
@Mock
private SignificantCopyNumberRegionServiceImpl significantCopyNumberRegionService;

List<MolecularProfileCaseIdentifier> caseIdentifiers = Arrays.asList(new MolecularProfileCaseIdentifier("A", MOLECULAR_PROFILE_ID));
Select<MutationEventType> mutationEventTypes = Select.byValues(Arrays.asList(MutationEventType.missense_mutation));
Expand Down Expand Up @@ -89,7 +91,7 @@ public void setup() {

alterationCountService = new AlterationCountServiceImpl(alterationRepository, alterationEnrichmentUtil,
alterationEnrichmentUtilCna, alterationEnrichmentUtilStructVar, molecularProfileRepository,
studyViewRepository, significantlyMutatedGeneService);
studyViewRepository, significantlyMutatedGeneService, significantCopyNumberRegionService);

MolecularProfile molecularProfile = new MolecularProfile();
molecularProfile.setStableId(MOLECULAR_PROFILE_ID);
Expand Down

0 comments on commit 7c1ba35

Please sign in to comment.