Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic Assay categorical patient level filtering - legacy #11381

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/main/java/org/cbioportal/legacy/model/GenericAssayData.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public class GenericAssayData extends MolecularData implements Serializable {

@NotNull
private String genericAssayStableId;

private boolean patientLevel;

/**
* @return the genericAssayStableId
Expand All @@ -26,4 +28,12 @@ public void setGenericAssayStableId(String genericAssayStableId) {
public String getStableId() {
return genericAssayStableId;
}

public void setPatientLevel(boolean patientLevel) {
this.patientLevel = patientLevel;
}

public boolean getPatientLevel() {
return patientLevel;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ public List<GenericAssayData> fetchGenericAssayData(List<String> molecularProfil
molecularData.setStudyId(sample.getCancerStudyIdentifier());
molecularData.setGenericAssayStableId(molecularAlteration.getGenericAssayStableId());
molecularData.setValue(molecularAlteration.getSplitValues()[indexOfSampleId]);
if (molecularProfile.getPatientLevel() != null) {
molecularData.setPatientLevel(molecularProfile.getPatientLevel());
}
result.add(molecularData);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,36 +440,53 @@ public List<GenericAssayDataCountItem> fetchGenericAssayDataCounts(List<String>

return data
.stream()
.filter(g -> StringUtils.isNotEmpty(g.getValue()) && !g.getValue().equals("NA"))
.collect(Collectors.groupingBy(GenericAssayData::getGenericAssayStableId))
.entrySet()
.stream()
.map(entry -> {
int totalCount = entry.getValue().size();
int naCount = sampleIds.size() - totalCount;
List<GenericAssayDataCount> counts = entry.getValue()
.stream()
List<GenericAssayData> groupData = entry.getValue();
boolean isPatientLevel = !groupData.isEmpty() && groupData.get(0).getPatientLevel();

List<GenericAssayData> filteredData;
int totalIds;

if (isPatientLevel) {
Set<String> uniquePatientIds = data.stream()
.map(GenericAssayData::getPatientId)
.collect(Collectors.toSet());
totalIds = uniquePatientIds.size();

filteredData = groupData.stream()
.filter(g -> StringUtils.isNotEmpty(g.getValue()) && !g.getValue().equals("NA"))
.collect(Collectors.groupingBy(GenericAssayData::getPatientId))
.values()
.stream()
.map(patientSamples -> patientSamples.get(0))
.toList();
} else {
totalIds = sampleIds.size();
filteredData = groupData.stream()
.filter(g -> StringUtils.isNotEmpty(g.getValue()) && !g.getValue().equals("NA"))
.toList();
}

int naCount = totalIds - filteredData.size();

List<GenericAssayDataCount> counts = filteredData.stream()
.collect(Collectors.groupingBy(GenericAssayData::getValue))
.entrySet()
.stream()
.map(datum -> {
GenericAssayDataCount dataCount = new GenericAssayDataCount();
dataCount.setValue(datum.getKey());
dataCount.setCount(datum.getValue().size());
return dataCount;
}).collect(Collectors.toList());
.map(datum -> new GenericAssayDataCount(datum.getKey(), datum.getValue().size()))
.collect(Collectors.toList());

if (naCount > 0) {
GenericAssayDataCount dataCount = new GenericAssayDataCount();
dataCount.setValue("NA");
dataCount.setCount(naCount);
counts.add(dataCount);
counts.add(new GenericAssayDataCount("NA", naCount));
}

GenericAssayDataCountItem genericAssayDataCountItem = new GenericAssayDataCountItem();
genericAssayDataCountItem.setStableId(entry.getKey());
genericAssayDataCountItem.setCounts(counts);
return genericAssayDataCountItem;
GenericAssayDataCountItem countItem = new GenericAssayDataCountItem();
countItem.setStableId(entry.getKey());
countItem.setCounts(counts);
return countItem;
}).toList();
}

Expand Down
Loading