Commit 54ac7cb0 authored by Guillaume Jimenez's avatar Guillaume Jimenez

Added API to determine if a project + run has analysis samples.

parent 2f28584b
......@@ -431,6 +431,77 @@ public class APIController {
}
}
/**
* Finds from a run and project id if any samples are analysis samples
* Returns either an error response or true/false if no error
* @param model
* @param session
* @param token
* @param projectId
* @param runId
* @param userAgent
* @param prettyPrint
* @return
* @throws JsonProcessingException
*/
@RequestMapping("/hasAnalysisSample")
@ResponseBody
public String hasAnalysisSample(Model model, HttpSession session,
@RequestParam String token, @RequestParam String projectId,
@RequestParam String runId,
@RequestHeader(value = "User-Agent") String userAgent,
@RequestParam(defaultValue="false") boolean prettyPrint) throws JsonProcessingException {
AjaxResponse response = new AjaxResponse();
Token theToken = pipelineDAO2.getPipelineToken(token);
if (theToken == null) {
response.setIsAllowed(false);
response.setMessage("You are not allowed to run this servlet.");
return response.createObjectJSON();
}
Subject subject = subjectDAO.getSubjectByName(projectId);
if (subject == null) {
response.setSuccess(false);
response.setMessage("No project with name: " + projectId);
return response.createObjectJSON();
}
List<Sample> samples = sampleDAO.getSamplesBySubjectId(subject.getSubjectId());
List<Sample> normalDNASamples = new ArrayList<Sample>();
List<Sample> tumorDNASamples = new ArrayList<Sample>();
List<Sample> tumorRNASamples = new ArrayList<Sample>();
if (samples != null && !samples.isEmpty()) {
normalDNASamples = samples.stream().filter(s -> s.getAnalysisSample() != null && s.isDna() && !s.isTumor()).collect(Collectors.toList());
tumorDNASamples = samples.stream().filter(s -> s.getAnalysisSample() != null && s.isDna() && s.isTumor()).collect(Collectors.toList());
tumorRNASamples = samples.stream().filter(s -> s.getAnalysisSample() != null && s.isRna() && s.isTumor()).collect(Collectors.toList());
}
else {
response.setSuccess(false);
response.setMessage("No samples found for project: " + projectId);
return response.createObjectJSON();
}
if (normalDNASamples != null && !normalDNASamples.isEmpty()) {
boolean found = modelDAO.areSamplesInRunAnalysisSamples(normalDNASamples.stream().map(s -> s.getSampleId()).collect(Collectors.toList()), runId);
if (found) {
return "true";
}
}
if (tumorDNASamples != null && !tumorDNASamples.isEmpty()) {
boolean found = modelDAO.areSamplesInRunAnalysisSamples(tumorDNASamples.stream().map(s -> s.getSampleId()).collect(Collectors.toList()), runId);
if (found) {
return "true";
}
}
if (tumorRNASamples != null && !tumorRNASamples.isEmpty()) {
boolean found = modelDAO.areSamplesInRunAnalysisSamples(tumorRNASamples.stream().map(s -> s.getSampleId()).collect(Collectors.toList()), runId);
if (found) {
return "true";
}
}
return "false";
}
// @RequestMapping("/addAllPipelineResults")
// @ResponseBody
// public String addAllPipelineResults(Model model, @RequestParam String token,
......
......@@ -801,6 +801,23 @@ public class ModelDAO {
.setParameter("sampleIds", sampleIds).list();
return runs;
}
@Transactional
public boolean areSamplesInRunAnalysisSamples(List<Integer> sampleIds, String runId) {
if (sampleIds.size() > 20 || sampleIds.isEmpty()) {
return false; //too many samples or none at all
}
Session session = sessionFactory.getCurrentSession();
StringBuilder sql = new StringBuilder("select s.* from seq_run r, demultiplex d, sample s")
.append(" where r.seq_run_id = d.seq_run_id and d.sample_id = s.sample_id and d.sample_id in :sampleIds ")
.append(" and r.seq_run_id = :runId ")
.append(" and s.analysis_sample is true ");
List<Sample> samples = session.createNativeQuery(sql.toString(), Sample.class)
.setParameter("sampleIds", sampleIds)
.setParameter("runId", runId)
.list();
return samples != null && !samples.isEmpty();
}
@Transactional
public List<CoverageViewer> getCoverageViewerBySampleIdRunId(Integer sampleId, String runId, Boolean unique) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment