Skip to content

Commit

Permalink
resolve sonarcloud issues
Browse files Browse the repository at this point in the history
  • Loading branch information
qlu-cls committed Jan 24, 2024
1 parent 5ca3580 commit 5b9aa40
Show file tree
Hide file tree
Showing 9 changed files with 220 additions and 227 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ portal/src/main/webapp/WEB-INF/logback.xml
!src/main/resource/*.EXAMPLE
firehose-importer/reference_data/gene_info
portal.properties
application.properties
src/main/resources/application.properties
importer.properties
log4j.properties
build.properties
Expand Down Expand Up @@ -103,7 +103,6 @@ package.json
*.tramp_history
pom.version.*
pom.xml.*
pom.xml.*
Dockerfile.local
.factorypath
.retype
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
import org.cbioportal.service.exception.MolecularProfileNotFoundException;
import org.cbioportal.service.exception.StudyNotFoundException;
import org.cbioportal.service.util.MolecularProfileUtil;
import org.cbioportal.web.parameter.Projection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PostFilter;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;

@Service
public class MolecularProfileServiceImpl implements MolecularProfileService {
Expand Down Expand Up @@ -145,13 +148,13 @@ public List<MolecularProfileCaseIdentifier> getFirstStructuralVariantProfileCase

private List<MolecularProfileCaseIdentifier> getFirstFilteredMolecularProfileCaseIdentifiers(List<String> studyIds, List<String> sampleIds, Optional<Predicate<MolecularProfile>> profileFilter) {
List<MolecularProfile> molecularProfiles =
getMolecularProfilesInStudies(studyIds.stream().distinct().collect(Collectors.toList()), "SUMMARY");
getMolecularProfilesInStudies(studyIds.stream().distinct().toList(), Projection.SUMMARY.name());
return molecularProfileUtil.getFirstFilteredMolecularProfileCaseIdentifiers(molecularProfiles, studyIds, sampleIds, profileFilter);
}

private List<MolecularProfileCaseIdentifier> getFilteredMolecularProfileCaseIdentifiers(List<String> studyIds, List<String> sampleIds, Optional<Predicate<MolecularProfile>> profileFilter) {
List<MolecularProfile> molecularProfiles =
getMolecularProfilesInStudies(studyIds.stream().distinct().collect(Collectors.toList()), "SUMMARY");
getMolecularProfilesInStudies(studyIds.stream().distinct().toList(), Projection.SUMMARY.name());
return molecularProfileUtil.getFilteredMolecularProfileCaseIdentifiers(molecularProfiles, studyIds, sampleIds, profileFilter);
}
}
113 changes: 56 additions & 57 deletions src/main/java/org/cbioportal/service/impl/StudyViewServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.cbioportal.service.exception.MolecularProfileNotFoundException;
import org.cbioportal.service.exception.StudyNotFoundException;
import org.cbioportal.service.util.MolecularProfileUtil;
import org.cbioportal.web.parameter.GeneIdType;
import org.cbioportal.web.parameter.Projection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -41,20 +43,20 @@ public class StudyViewServiceImpl implements StudyViewService {

@Autowired
private GeneService geneService;
@Autowired

@Autowired
private MolecularDataService molecularDataService;

@Autowired
private MutationService mutationService;

@Override
public List<GenomicDataCount> getGenomicDataCounts(List<String> studyIds, List<String> sampleIds) {
List<MolecularProfileCaseIdentifier> molecularProfileSampleIdentifiers =
molecularProfileService.getMolecularProfileCaseIdentifiers(studyIds, sampleIds);

List<MolecularProfile> molecularProfiles = molecularProfileService
.getMolecularProfilesInStudies(new ArrayList<>(new HashSet<>(studyIds)),"SUMMARY");
.getMolecularProfilesInStudies(new ArrayList<>(new HashSet<>(studyIds)), Projection.SUMMARY.name());
Map<String, MolecularProfile> molecularProfileMap = molecularProfiles
.stream()
.collect(Collectors.toMap(MolecularProfile::getStableId, Function.identity()));
Expand All @@ -66,8 +68,8 @@ public List<GenomicDataCount> getGenomicDataCounts(List<String> studyIds, List<S
.collect(Collectors.groupingBy(GenePanelData::getMolecularProfileId))
.entrySet()
.stream()
.collect(Collectors.toMap(entry -> entry.getKey(), entry -> (int)entry.getValue().stream().map(d -> molecularProfileMap.get(entry.getKey()).getPatientLevel() ? d.getPatientId() : d.getSampleId()).distinct().count()));
.collect(Collectors.toMap(entry -> entry.getKey(), entry -> (int) entry.getValue().stream().map(d -> molecularProfileMap.get(entry.getKey()).getPatientLevel() ? d.getPatientId() : d.getSampleId()).distinct().count()));

return molecularProfileUtil
.categorizeMolecularProfilesByStableIdSuffixes(molecularProfiles)
.entrySet()
Expand All @@ -87,7 +89,7 @@ public List<GenomicDataCount> getGenomicDataCounts(List<String> studyIds, List<S
return dataCount;
})
.filter(dataCount -> dataCount.getCount() > 0)
.collect(Collectors.toList());
.toList();
}

@Override
Expand Down Expand Up @@ -119,11 +121,11 @@ public List<GenomicDataCountItem> getMutationCountsByGeneSpecific(List<String> s
.collect(Collectors.toSet());

List<Integer> entrezGeneIds = geneService
.fetchGenes(new ArrayList<>(hugoGeneSymbols), "HUGO_GENE_SYMBOL",
"SUMMARY")
.fetchGenes(new ArrayList<>(hugoGeneSymbols), GeneIdType.HUGO_GENE_SYMBOL.name(),
Projection.SUMMARY.name())
.stream()
.map(Gene::getEntrezGeneId)
.collect(Collectors.toList());
.toList();

List<AlterationCountByGene> alterationCountByGenes = alterationCountService.getSampleMutationGeneCounts(
caseIdentifiers,
Expand Down Expand Up @@ -155,7 +157,7 @@ public List<GenomicDataCountItem> getMutationCountsByGeneSpecific(List<String> s
int totalCount = sampleIds.size();

List<GenomicDataCount> genomicDataCounts = new ArrayList<>();

GenomicDataCount genomicDataCountMutated = new GenomicDataCount();
genomicDataCountMutated.setLabel(MutationFilterOption.MUTATED.getMutationFilterOption());
genomicDataCountMutated.setValue(MutationFilterOption.MUTATED.name());
Expand All @@ -180,8 +182,7 @@ public List<GenomicDataCountItem> getMutationCountsByGeneSpecific(List<String> s
genomicDataCountItem.setCounts(genomicDataCounts);

return Stream.of(genomicDataCountItem);
})
.collect(Collectors.toList());
}).toList();
}

@Override
Expand All @@ -192,36 +193,35 @@ public List<GenomicDataCountItem> getMutationTypeCountsByGeneSpecific(List<Strin
.collect(Collectors.toSet());

Map<String, Integer> geneSymbolIdMap = geneService
.fetchGenes(new ArrayList<>(hugoGeneSymbols), "HUGO_GENE_SYMBOL",
"SUMMARY")
.fetchGenes(new ArrayList<>(hugoGeneSymbols), GeneIdType.HUGO_GENE_SYMBOL.name(),
Projection.SUMMARY.name())
.stream().collect(Collectors.toMap(Gene::getHugoGeneSymbol, Gene::getEntrezGeneId));

return genomicDataFilters
.stream()
.flatMap(gdFilter -> {
String hugoGeneSymbol = gdFilter.getKey();
String profileType = gdFilter.getValue();

List<Integer> stableIds = Collections.singletonList(geneSymbolIdMap.get(hugoGeneSymbol));

Pair<List<String>, List<String>> sampleAndProfileIds = getMappedSampleAndProfileIds(studyIds, sampleIds, profileType);
List<String> mappedSampleIds = sampleAndProfileIds.getFirst();
List<String> mappedProfileIds = sampleAndProfileIds.getSecond();

if (mappedSampleIds.isEmpty() || mappedProfileIds.isEmpty()) {
return Stream.of();
}
GenomicDataCountItem genomicDataCountItem = mutationService.getMutationCountsByType(mappedProfileIds,

GenomicDataCountItem genomicDataCountItem = mutationService.getMutationCountsByType(mappedProfileIds,
mappedSampleIds, stableIds, profileType);

if (genomicDataCountItem != null) {
return Stream.of(genomicDataCountItem);
} else {
return Stream.empty();
}
})
.collect(Collectors.toList());
}).toList();
}

@Override
Expand Down Expand Up @@ -259,12 +259,12 @@ private void annotateDataWithQValue(List<String> studyIds, List<AlterationCountB
if (!alterationCountByGenes.isEmpty() && distinctStudyIds.size() == 1) {
Map<Integer, MutSig> mutSigMap =
significantlyMutatedGeneService.getSignificantlyMutatedGenes(
studyIds.get(0),
"SUMMARY",
null,
null,
null,
null)
studyIds.get(0),
Projection.SUMMARY.name(),
null,
null,
null,
null)
.stream()
.collect(Collectors.toMap(MutSig::getEntrezGeneId, Function.identity()));
alterationCountByGenes.forEach(r -> {
Expand All @@ -282,7 +282,7 @@ public List<CopyNumberCountByGene> getCNAAlterationCountByGenes(List<String> stu
throws StudyNotFoundException {
List<MolecularProfileCaseIdentifier> caseIdentifiers =
molecularProfileService.getFirstDiscreteCNAProfileCaseIdentifiers(studyIds, sampleIds);

List<CopyNumberCountByGene> copyNumberCountByGenes = alterationCountService.getSampleCnaGeneCounts(
caseIdentifiers,
Select.all(),
Expand All @@ -293,7 +293,7 @@ public List<CopyNumberCountByGene> getCNAAlterationCountByGenes(List<String> stu
if (distinctStudyIds.size() == 1 && !copyNumberCountByGenes.isEmpty()) {
List<Gistic> gisticList = significantCopyNumberRegionService.getSignificantCopyNumberRegions(
studyIds.get(0),
"SUMMARY",
Projection.SUMMARY.name(),
null,
null,
null,
Expand All @@ -315,17 +315,17 @@ public List<CopyNumberCountByGene> getCNAAlterationCountByGenes(List<String> stu
}

@Override
public List<GenomicDataCountItem> getCNAAlterationCountsByGeneSpecific(List<String> studyIds,
public List<GenomicDataCountItem> getCNAAlterationCountsByGeneSpecific(List<String> studyIds,
List<String> sampleIds,
List<Pair<String, String>> genomicDataFilters) {
Set<String> hugoGeneSymbols = genomicDataFilters.stream().map(Pair::getKey)
.collect(Collectors.toSet());

Map<String, Integer> geneSymbolIdMap = geneService
.fetchGenes(new ArrayList<>(hugoGeneSymbols), "HUGO_GENE_SYMBOL",
"SUMMARY")
.fetchGenes(new ArrayList<>(hugoGeneSymbols), GeneIdType.HUGO_GENE_SYMBOL.name(),
Projection.SUMMARY.name())
.stream().collect(Collectors.toMap(Gene::getHugoGeneSymbol, Gene::getEntrezGeneId));

return genomicDataFilters
.stream()
.flatMap(gdFilter -> {
Expand All @@ -334,7 +334,7 @@ public List<GenomicDataCountItem> getCNAAlterationCountsByGeneSpecific(List<Stri
String profileType = gdFilter.getValue();
genomicDataCountItem.setHugoGeneSymbol(hugoGeneSymbol);
genomicDataCountItem.setProfileType(profileType);

List<String> stableIds = Arrays.asList(geneSymbolIdMap.get(hugoGeneSymbol).toString());

Pair<List<String>, List<String>> sampleAndProfileIds = getMappedSampleAndProfileIds(studyIds, sampleIds, profileType);
Expand All @@ -346,8 +346,8 @@ public List<GenomicDataCountItem> getCNAAlterationCountsByGeneSpecific(List<Stri
}

List<GeneMolecularData> geneMolecularDataList = molecularDataService.getMolecularDataInMultipleMolecularProfiles(mappedProfileIds, mappedSampleIds,
stableIds.stream().map(Integer::parseInt).collect(Collectors.toList()), "SUMMARY");
stableIds.stream().map(Integer::parseInt).toList(), Projection.SUMMARY.name());

List<GenomicDataCount> genomicDataCounts = geneMolecularDataList
.stream()
.filter(g -> StringUtils.isNotEmpty(g.getValue()) && !g.getValue().equals("NA"))
Expand All @@ -367,27 +367,29 @@ public List<GenomicDataCountItem> getCNAAlterationCountsByGeneSpecific(List<Stri
genomicDataCount.setCount(count);

return genomicDataCount;
}).collect(Collectors.toList());
}).toList();

int totalCount = genomicDataCounts.stream().mapToInt(GenomicDataCount::getCount).sum();
int naCount = sampleIds.size() - totalCount;

if (naCount > 0) {
GenomicDataCount genomicDataCount = new GenomicDataCount();
genomicDataCount.setLabel("NA");
genomicDataCount.setValue("NA");
genomicDataCount.setCount(naCount);
genomicDataCounts.add(genomicDataCount);
}

genomicDataCountItem.setCounts(genomicDataCounts);
return Stream.of(genomicDataCountItem);
}).collect(Collectors.toList());
};
}).toList();
}

;

@Override
public List<GenericAssayDataCountItem> fetchGenericAssayDataCounts(List<String> sampleIds, List<String> studyIds,
List<String> stableIds, List<String> profileTypes) {
List<String> stableIds, List<String> profileTypes) {
if (stableIds.isEmpty()) {
return new ArrayList<>();
}
Expand All @@ -398,12 +400,12 @@ public List<GenericAssayDataCountItem> fetchGenericAssayDataCounts(List<String>
List<String> mappedProfileIds = sampleAndProfileIds.getSecond();

try {
return genericAssayService.fetchGenericAssayData(mappedProfileIds, mappedSampleIds, stableIds, "SUMMARY").stream();
return genericAssayService.fetchGenericAssayData(mappedProfileIds, mappedSampleIds, stableIds, Projection.SUMMARY.name()).stream();
} catch (MolecularProfileNotFoundException e) {
return new ArrayList<GenericAssayData>().stream();
}
}).collect(Collectors.toList());
}).toList();

return data
.stream()
.filter(g -> StringUtils.isNotEmpty(g.getValue()) && !g.getValue().equals("NA"))
Expand All @@ -422,10 +424,9 @@ public List<GenericAssayDataCountItem> fetchGenericAssayDataCounts(List<String>
GenericAssayDataCount dataCount = new GenericAssayDataCount();
dataCount.setValue(datum.getKey());
dataCount.setCount(datum.getValue().size());
return dataCount;
})
.collect(Collectors.toList());

return dataCount;
}).toList();

if (naCount > 0) {
GenericAssayDataCount dataCount = new GenericAssayDataCount();
dataCount.setValue("NA");
Expand All @@ -437,14 +438,12 @@ public List<GenericAssayDataCountItem> fetchGenericAssayDataCounts(List<String>
genericAssayDataCountItem.setStableId(entry.getKey());
genericAssayDataCountItem.setCounts(counts);
return genericAssayDataCountItem;
})
.collect(Collectors.toList());
}).toList();
}

private Pair<List<String>, List<String>> getMappedSampleAndProfileIds(List<String> studyIds, List<String> sampleIds, String profileType) {
// Get data from fetchGenericAssayData service
List<MolecularProfile> molecularProfiles = molecularProfileService.getMolecularProfilesInStudies(studyIds,
"SUMMARY");
Projection.SUMMARY.name());

Map<String, List<MolecularProfile>> molecularProfileMap = molecularProfileUtil
.categorizeMolecularProfilesByStableIdSuffixes(molecularProfiles);
Expand All @@ -464,7 +463,7 @@ private Pair<List<String>, List<String>> getMappedSampleAndProfileIds(List<Strin
mappedProfileIds.add(studyIdToMolecularProfileIdMap.get(studyId));
}
}

return new Pair<>(mappedSampleIds, mappedProfileIds);
}
}
Loading

0 comments on commit 5b9aa40

Please sign in to comment.