Skip to content

Commit

Permalink
Query sample IDs using Virtual Study View Filters is it's of dynamic …
Browse files Browse the repository at this point in the history
…type
  • Loading branch information
forus committed Oct 2, 2024
1 parent 6e948ff commit be8648c
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion src/main/java/org/cbioportal/web/SessionServiceController.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@
import org.cbioportal.web.parameter.PageSettingsIdentifier;
import org.cbioportal.web.parameter.PagingConstants;
import org.cbioportal.web.parameter.ResultsPageSettings;
import org.cbioportal.web.parameter.SampleIdentifier;
import org.cbioportal.web.parameter.SessionPage;
import org.cbioportal.web.parameter.StudyPageSettings;
import org.cbioportal.web.parameter.VirtualStudy;
import org.cbioportal.web.parameter.VirtualStudyData;
import org.cbioportal.web.parameter.VirtualStudySamples;
import org.cbioportal.web.util.StudyViewFilterApplier;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
Expand Down Expand Up @@ -57,6 +60,7 @@
import java.util.Optional;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static org.cbioportal.web.PublicVirtualStudiesController.ALL_USERS;

Expand All @@ -76,6 +80,9 @@ public class SessionServiceController {
@Autowired
private ObjectMapper sessionServiceObjectMapper;

@Autowired
private StudyViewFilterApplier studyViewFilterApplier;

@Value("${session.service.url:}")
private String sessionServiceURL;

Expand Down Expand Up @@ -211,7 +218,12 @@ public ResponseEntity<Session> getSession(@PathVariable Session.SessionType type
Session session;
switch (type) {
case virtual_study:
session = sessionServiceObjectMapper.readValue(sessionDataJson, VirtualStudy.class);
VirtualStudy virtualStudy = sessionServiceObjectMapper.readValue(sessionDataJson, VirtualStudy.class);
VirtualStudyData virtualStudyData = virtualStudy.getData();
if (Boolean.TRUE.equals(virtualStudyData.getDynamic())) {
populateVirtualStudySamples(virtualStudyData);
}
session = virtualStudy;
break;
case settings:
session = sessionServiceObjectMapper.readValue(sessionDataJson, PageSettings.class);
Expand All @@ -232,6 +244,29 @@ public ResponseEntity<Session> getSession(@PathVariable Session.SessionType type
}
}

/**
* This method populates the `virtualStudyData` object with a new set of sample IDs retrieved as the result of executing a query based on virtual study view filters.
* It first applies the filters defined within the study view, runs the query to fetch the relevant sample IDs, and then updates the virtualStudyData to reflect these fresh results.
* This ensures that the virtual study contains the latest sample IDs.
* @param virtualStudyData
*/
private void populateVirtualStudySamples(VirtualStudyData virtualStudyData) {
List<SampleIdentifier> sampleIdentifiers = studyViewFilterApplier.apply(virtualStudyData.getStudyViewFilter());
Map<String, Set<String>> sampleIdsByStudyId = sampleIdentifiers
.stream()
.collect(
Collectors.groupingBy(
SampleIdentifier::getStudyId,
Collectors.mapping(SampleIdentifier::getSampleId, Collectors.toSet())));
Set<VirtualStudySamples> virtualStudySamples = sampleIdsByStudyId.entrySet().stream().map(entry -> {
VirtualStudySamples vss = new VirtualStudySamples();
vss.setId(entry.getKey());
vss.setSamples(entry.getValue());
return vss;
}).collect(Collectors.toSet());
virtualStudyData.setStudies(virtualStudySamples);
}

@RequestMapping(value = "/virtual_study", method = RequestMethod.GET)
@ApiResponse(responseCode = "200", description = "OK",
content = @Content(array = @ArraySchema(schema = @Schema(implementation = VirtualStudy.class))))
Expand Down

0 comments on commit be8648c

Please sign in to comment.