private void setGeneticProfiles(HttpServletRequest request) throws DaoException { CancerStudy cancerStudy = (CancerStudy) request.getAttribute(CANCER_STUDY); GeneticProfile mutProfile = cancerStudy.getMutationProfile(); if (mutProfile != null) { request.setAttribute(MUTATION_PROFILE, mutProfile); } GeneticProfile cnaProfile = cancerStudy.getCopyNumberAlterationProfile(true); if (cnaProfile != null) { request.setAttribute(CNA_PROFILE, cnaProfile); } }
private boolean validate(HttpServletRequest request) throws DaoException { String cancerStudyID = request.getParameter(ID); if (cancerStudyID == null) { cancerStudyID = request.getParameter(QueryBuilder.CANCER_STUDY_ID); } CancerStudy cancerStudy = DaoCancerStudy.getCancerStudyByStableId(cancerStudyID); if (cancerStudy == null) { try { cancerStudy = DaoCancerStudy.getCancerStudyByInternalId(Integer.parseInt(cancerStudyID)); } catch (NumberFormatException ex) { } } if (cancerStudy == null) { request.setAttribute(ERROR, "No such cancer study"); return false; } String cancerStudyIdentifier = cancerStudy.getCancerStudyStableId(); if (accessControl.isAccessibleCancerStudy(cancerStudyIdentifier).size() != 1) { request.setAttribute( ERROR, "You are not authorized to view the cancer study with id: '" + cancerStudyIdentifier + "'. "); return false; } else { UserDetails ud = accessControl.getUserDetails(); if (ud != null) { logger.info("CancerStudyView.validate: Query initiated by user: "******"_all"; request.setAttribute(QueryBuilder.CASE_SET_ID, sampleListId); } SampleList sampleList = daoSampleList.getSampleListByStableId(sampleListId); if (sampleList == null) { request.setAttribute(ERROR, "Could not find sample list of '" + sampleListId + "'. "); return false; } request.setAttribute(QueryBuilder.CASE_IDS, sampleList.getSampleList()); request.setAttribute(CANCER_STUDY, cancerStudy); request.setAttribute(QueryBuilder.HTML_TITLE, cancerStudy.getName()); return true; }
/** * Test importing of Clinical Data File. * * @throws DaoException Database Access Error. * @throws IOException IO Error. */ @Test @Ignore("To be fixed") public void testImportClinicalDataSurvival() throws Exception { // TBD: change this to use getResourceAsStream() File clinicalFile = new File("target/test-classes/clinical_data.txt"); ImportClinicalData importClinicalData = new ImportClinicalData(study, clinicalFile); importClinicalData.importData(); LinkedHashSet<String> caseSet = new LinkedHashSet<String>(); caseSet.add("TCGA-A1-A0SB"); caseSet.add("TCGA-A1-A0SI"); caseSet.add("TCGA-A1-A0SE"); List<Patient> clinicalCaseList = DaoClinicalData.getSurvivalData(study.getInternalId(), caseSet); assertEquals(3, clinicalCaseList.size()); Patient clinical0 = clinicalCaseList.get(0); assertEquals(new Double(79.04), clinical0.getAgeAtDiagnosis()); assertEquals("DECEASED", clinical0.getOverallSurvivalStatus()); assertEquals("Recurred/Progressed", clinical0.getDiseaseFreeSurvivalStatus()); assertEquals(new Double(43.8), clinical0.getOverallSurvivalMonths()); assertEquals(new Double(15.05), clinical0.getDiseaseFreeSurvivalMonths()); Patient clinical1 = clinicalCaseList.get(1); assertEquals(new Double(55.53), clinical1.getAgeAtDiagnosis()); assertEquals("LIVING", clinical1.getOverallSurvivalStatus()); assertEquals("DiseaseFree", clinical1.getDiseaseFreeSurvivalStatus()); assertEquals(new Double(49.02), clinical1.getOverallSurvivalMonths()); assertEquals(new Double(49.02), clinical1.getDiseaseFreeSurvivalMonths()); Patient clinical2 = clinicalCaseList.get(2); assertEquals(null, clinical2.getDiseaseFreeSurvivalMonths()); }
public static CancerStudy loadCancerStudy(File file, boolean strict, boolean addStudyToDb) throws IOException, DaoException { TrimmedProperties properties = new TrimmedProperties(); properties.load(new FileInputStream(file)); CancerStudy cancerStudy = getCancerStudy(properties); if (strict && null == DaoTypeOfCancer.getTypeOfCancerById(cancerStudy.getTypeOfCancerId())) { throw new IllegalArgumentException( cancerStudy.getTypeOfCancerId() + " is not a supported cancer type."); } if (addStudyToDb) { DaoCancerStudy.addCancerStudy(cancerStudy, true); // overwrite if exist } return cancerStudy; }
/** * Test importing of Clinical Data File. * * @throws DaoException Database Access Error. * @throws IOException IO Error. */ @Test @Ignore("To be fixed") public void testImportClinicalDataParameters() throws Exception { // TBD: change this to use getResourceAsStream() File clinicalFile = new File("target/test-classes/clinical_data.txt"); ImportClinicalData importClinicalData = new ImportClinicalData(study, clinicalFile); importClinicalData.importData(); Set<String> paramSet = DaoClinicalData.getDistinctParameters(study.getInternalId()); assertEquals(9, paramSet.size()); }
private static CancerStudy getCancerStudy(TrimmedProperties properties) { String cancerStudyIdentifier = properties.getProperty("cancer_study_identifier"); if (cancerStudyIdentifier == null) { throw new IllegalArgumentException("cancer_study_identifier is not specified."); } String name = properties.getProperty("name"); if (name == null) { throw new IllegalArgumentException("name is not specified."); } String description = properties.getProperty("description"); if (description == null) { throw new IllegalArgumentException("description is not specified."); } String typeOfCancer = properties.getProperty("type_of_cancer").toLowerCase(); if (typeOfCancer == null) { throw new IllegalArgumentException("type of cancer is not specified."); } String shortName = properties.getProperty("short_name"); if (shortName == null) { throw new IllegalArgumentException("short_name is not specified."); } CancerStudy cancerStudy = new CancerStudy( name, description, cancerStudyIdentifier, typeOfCancer, publicStudy(properties)); cancerStudy.setPmid(properties.getProperty("pmid")); cancerStudy.setCitation(properties.getProperty("citation")); cancerStudy.setGroupsInUpperCase(properties.getProperty("groups")); cancerStudy.setShortName(shortName); return cancerStudy; }
/** * Test importing of Clinical Data File. * * @throws DaoException Database Access Error. * @throws IOException IO Error. */ @Test @Ignore("To be fixed") public void testImportClinicalDataSlice() throws Exception { // TBD: change this to use getResourceAsStream() File clinicalFile = new File("target/test-classes/clinical_data.txt"); ImportClinicalData importClinicalData = new ImportClinicalData(study, clinicalFile); importClinicalData.importData(); List<ClinicalParameterMap> slice = DaoClinicalData.getDataSlice(study.getInternalId(), Arrays.asList("PLATINUMSTATUS")); assertTrue(slice.size() >= 1); ClinicalParameterMap paramMap = slice.get(0); assertEquals("PLATINUMSTATUS", paramMap.getName()); assertEquals("Sensitive", paramMap.getValue("TCGA-A1-A0SD")); assertEquals("NA", paramMap.getValue("TCGA-A1-A0SE")); assertEquals(2, paramMap.getDistinctCategories().size()); }
private void processRequestStatistics( HttpServletRequest request, HttpServletResponse response, String type) throws ServletException, IOException { String cancerStudyIds = request.getParameter(QueryBuilder.CANCER_STUDY_ID); try { boolean includeMut = "mut".equalsIgnoreCase(type); boolean includeCna = "cna".equalsIgnoreCase(type); Map<String, Map<String, Object>> data = new HashMap<String, Map<String, Object>>(); // get list of cancer studies AccessControl accessControl = getaccessControl(); List<CancerStudy> cancerStudies; if (cancerStudyIds == null || cancerStudyIds.isEmpty()) { cancerStudies = accessControl.getCancerStudies(); } else { cancerStudies = new ArrayList<CancerStudy>(); for (String studyId : cancerStudyIds.split("[ ,]+")) { CancerStudy study = DaoCancerStudy.getCancerStudyByStableId(studyId); if (study != null && !accessControl.isAccessibleCancerStudy(studyId).isEmpty()) { cancerStudies.add(study); } } } for (CancerStudy cancerStudy : cancerStudies) { if (cancerStudy.getCancerStudyStableId().equalsIgnoreCase("all")) { continue; } Map<String, Object> row = new HashMap<String, Object>(); data.put(cancerStudy.getCancerStudyStableId(), row); if (!includeMut && !includeMut) { row.put("name", cancerStudy.getName()); String pmid = cancerStudy.getPmid(); if (pmid != null) { row.put("pmid", pmid); } String citation = cancerStudy.getCitation(); if (citation != null) { row.put("citation", citation); } row.put( "cases", DaoPatient.getPatientsByCancerStudyId(cancerStudy.getInternalId()).size()); } if (includeMut) { GeneticProfile mutProfile = cancerStudy.getMutationProfile(); if (mutProfile == null) { row.put("mut", 0); } else { int mutEvents = DaoMutation.countMutationEvents(mutProfile.getGeneticProfileId()); int samplesWithMut = DaoSampleProfile.countSamplesInProfile(mutProfile.getGeneticProfileId()); row.put("mut", 1.0 * mutEvents / samplesWithMut); } } if (includeCna) { GeneticProfile cnaProfile = cancerStudy.getCopyNumberAlterationProfile(false); if (cnaProfile == null) { row.put("cna", 0); } else { List<Integer> samples = DaoSampleProfile.getAllSampleIdsInProfile(cnaProfile.getGeneticProfileId()); Map<Integer, Double> fracs = DaoCopyNumberSegment.getCopyNumberActeredFraction( samples, cnaProfile.getCancerStudyId(), GlobalProperties.getPatientViewGenomicOverviewCnaCutoff()[0]); double aveFrac = 0; for (double frac : fracs.values()) { aveFrac += frac; } aveFrac /= samples.size(); row.put("cna", aveFrac); } } } response.setContentType("application/json"); PrintWriter out = response.getWriter(); try { JSONValue.writeJSONString(data, out); } finally { out.close(); } } catch (DaoException ex) { throw new ServletException(ex); } catch (ProtocolException ex) { throw new ServletException(ex); } }
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * * @param request servlet request * @param response servlet response * @throws javax.servlet.ServletException if a servlet-specific error occurs * @throws java.io.IOException if an I/O error occurs */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { XDebug xdebug = new XDebug(); xdebug.startTimer(); response.setContentType("application/json"); PrintWriter writer = response.getWriter(); try { List resultsList = new LinkedList(); // Get the gene list String geneList = request.getParameter(QueryBuilder.GENE_LIST); if (request instanceof XssRequestWrapper) { geneList = ((XssRequestWrapper) request).getRawParameter(QueryBuilder.GENE_LIST); } String cancerStudyIdListString = request.getParameter(QueryBuilder.CANCER_STUDY_LIST); String[] cancerStudyIdList = cancerStudyIdListString.split(","); // Get the priority Integer dataTypePriority; try { dataTypePriority = Integer.parseInt(request.getParameter(QueryBuilder.DATA_PRIORITY).trim()); } catch (NumberFormatException e) { dataTypePriority = 0; } // Cancer All Cancer Studies List<CancerStudy> cancerStudiesList = accessControl.getCancerStudies(); HashMap<String, Boolean> studyMap = new HashMap<>(); for (String studyId : cancerStudyIdList) { studyMap.put(studyId, Boolean.TRUE); } for (CancerStudy cancerStudy : cancerStudiesList) { String cancerStudyId = cancerStudy.getCancerStudyStableId(); if (!studyMap.containsKey(cancerStudyId)) { continue; } if (cancerStudyId.equalsIgnoreCase("all")) continue; Map cancerMap = new LinkedHashMap(); cancerMap.put("studyId", cancerStudyId); cancerMap.put("typeOfCancer", cancerStudy.getTypeOfCancerId()); // Get all Genetic Profiles Associated with this Cancer Study ID. ArrayList<GeneticProfile> geneticProfileList = GetGeneticProfiles.getGeneticProfiles(cancerStudyId); // Get all Patient Lists Associated with this Cancer Study ID. ArrayList<SampleList> sampleSetList = GetSampleLists.getSampleLists(cancerStudyId); // Get the default patient set AnnotatedSampleSets annotatedSampleSets = new AnnotatedSampleSets(sampleSetList, dataTypePriority); SampleList defaultSampleSet = annotatedSampleSets.getDefaultSampleList(); if (defaultSampleSet == null) { continue; } List<String> sampleIds = defaultSampleSet.getSampleList(); // Get the default genomic profiles CategorizedGeneticProfileSet categorizedGeneticProfileSet = new CategorizedGeneticProfileSet(geneticProfileList); HashMap<String, GeneticProfile> defaultGeneticProfileSet = null; switch (dataTypePriority) { case 2: defaultGeneticProfileSet = categorizedGeneticProfileSet.getDefaultCopyNumberMap(); break; case 1: defaultGeneticProfileSet = categorizedGeneticProfileSet.getDefaultMutationMap(); break; case 0: default: defaultGeneticProfileSet = categorizedGeneticProfileSet.getDefaultMutationAndCopyNumberMap(); } String mutationProfile = "", cnaProfile = ""; for (GeneticProfile geneticProfile : defaultGeneticProfileSet.values()) { GeneticAlterationType geneticAlterationType = geneticProfile.getGeneticAlterationType(); if (geneticAlterationType.equals(GeneticAlterationType.COPY_NUMBER_ALTERATION)) { cnaProfile = geneticProfile.getStableId(); } else if (geneticAlterationType.equals(GeneticAlterationType.MUTATION_EXTENDED)) { mutationProfile = geneticProfile.getStableId(); } } cancerMap.put("mutationProfile", mutationProfile); cancerMap.put("cnaProfile", cnaProfile); cancerMap.put("caseSetId", defaultSampleSet.getStableId()); cancerMap.put("caseSetLength", sampleIds.size()); ProfileDataSummary genomicData = getGenomicData( cancerStudyId, defaultGeneticProfileSet, defaultSampleSet, geneList, sampleSetList, request, response); ArrayList<GeneWithScore> geneFrequencyList = genomicData.getGeneFrequencyList(); ArrayList<String> genes = new ArrayList<String>(); for (GeneWithScore geneWithScore : geneFrequencyList) genes.add(geneWithScore.getGene()); int noOfMutated = 0, noOfCnaUp = 0, noOfCnaDown = 0, noOfCnaLoss = 0, noOfCnaGain = 0, noOfOther = 0, noOfAll = 0; boolean skipStudy = defaultGeneticProfileSet.isEmpty(); if (!skipStudy) { for (String sampleId : sampleIds) { if (sampleId == null) { continue; } if (!genomicData.isCaseAltered(sampleId)) continue; boolean isAnyMutated = false, isAnyCnaUp = false, isAnyCnaDown = false, isAnyCnaLoss = false, isAnyCnaGain = false; for (String gene : genes) { isAnyMutated |= genomicData.isGeneMutated(gene, sampleId); GeneticTypeLevel cnaLevel = genomicData.getCNALevel(gene, sampleId); boolean isCnaUp = cnaLevel != null && cnaLevel.equals(GeneticTypeLevel.Amplified); isAnyCnaUp |= isCnaUp; boolean isCnaDown = cnaLevel != null && cnaLevel.equals(GeneticTypeLevel.HomozygouslyDeleted); isAnyCnaDown |= isCnaDown; boolean isCnaLoss = cnaLevel != null && cnaLevel.equals(GeneticTypeLevel.HemizygouslyDeleted); isAnyCnaLoss |= isCnaLoss; boolean isCnaGain = cnaLevel != null && cnaLevel.equals(GeneticTypeLevel.Gained); isAnyCnaGain |= isCnaGain; } boolean isAnyCnaChanged = isAnyCnaUp || isAnyCnaDown; if (isAnyMutated && !isAnyCnaChanged) noOfMutated++; else if (isAnyMutated && isAnyCnaChanged) noOfOther++; else if (isAnyCnaUp) noOfCnaUp++; else if (isAnyCnaDown) noOfCnaDown++; else if (isAnyCnaGain) noOfCnaGain++; else if (isAnyCnaLoss) noOfCnaLoss++; noOfAll++; } } Map alterations = new LinkedHashMap(); cancerMap.put("alterations", alterations); alterations.put("all", noOfAll); alterations.put("mutation", noOfMutated); alterations.put("cnaUp", noOfCnaUp); alterations.put("cnaDown", noOfCnaDown); alterations.put("cnaLoss", noOfCnaLoss); alterations.put("cnaGain", noOfCnaGain); alterations.put("other", noOfOther); cancerMap.put("genes", genes); cancerMap.put("skipped", skipStudy); resultsList.add(cancerMap); } JSONValue.writeJSONString(resultsList, writer); } catch (DaoException e) { throw new ServletException(e); } catch (ProtocolException e) { throw new ServletException(e); } finally { writer.close(); } }