private void runImportCnaData() throws DaoException, IOException { DaoGeneticAlteration dao = DaoGeneticAlteration.getInstance(); DaoGeneOptimized daoGene = DaoGeneOptimized.getInstance(); // the largest current true Entrez gene ID counts 8 digits daoGene.addGene(new CanonicalGene(999999207, "TESTAKT1")); daoGene.addGene(new CanonicalGene(999999208, "TESTAKT2")); daoGene.addGene(new CanonicalGene(999910000, "TESTAKT3")); daoGene.addGene(new CanonicalGene(999999369, "TESTARAF")); daoGene.addGene(new CanonicalGene(999999472, "TESTATM")); daoGene.addGene(new CanonicalGene(999999673, "TESTBRAF")); daoGene.addGene(new CanonicalGene(999999672, "TESTBRCA1")); daoGene.addGene(new CanonicalGene(999999675, "TESTBRCA2")); ProgressMonitor.setConsoleMode(false); // TBD: change this to use getResourceAsStream() File file = new File("src/test/resources/cna_test.txt"); ImportTabDelimData parser = new ImportTabDelimData(file, "Barry", geneticProfileId, null); int numLines = FileUtil.getNumLines(file); parser.importData(numLines); String value = dao.getGeneticAlteration(geneticProfileId, sample1, 999999207); assertEquals("0", value); value = dao.getGeneticAlteration(geneticProfileId, sample4, 999999207); assertEquals("-1", value); value = dao.getGeneticAlteration(geneticProfileId, sample2, 999999207); assertEquals("0", value); value = dao.getGeneticAlteration(geneticProfileId, sample2, 999910000); assertEquals("2", value); value = dao.getGeneticAlteration(geneticProfileId, sample3, 999910000); assertEquals("2", value); int cnaStatus = Integer.parseInt(dao.getGeneticAlteration(geneticProfileId, sample3, 999910000)); assertEquals(CopyNumberStatus.COPY_NUMBER_AMPLIFICATION, cnaStatus); cnaStatus = Integer.parseInt(dao.getGeneticAlteration(geneticProfileId, sample2, 999910000)); assertEquals(CopyNumberStatus.COPY_NUMBER_AMPLIFICATION, cnaStatus); cnaStatus = Integer.parseInt(dao.getGeneticAlteration(geneticProfileId, sample4, 999999207)); assertEquals(CopyNumberStatus.HEMIZYGOUS_DELETION, cnaStatus); Patient patient = DaoPatient.getPatientByCancerStudyAndPatientId(studyId, "TCGA-A1-A0SB"); Sample sample = DaoSample.getSampleByPatientAndSampleId(patient.getInternalId(), "TCGA-A1-A0SB-01"); assertTrue( DaoSampleProfile.sampleExistsInGeneticProfile(sample.getInternalId(), geneticProfileId)); patient = DaoPatient.getPatientByCancerStudyAndPatientId(studyId, "TCGA-A1-A0SJ"); sample = DaoSample.getSampleByPatientAndSampleId(patient.getInternalId(), "TCGA-A1-A0SJ-01"); assertTrue( DaoSampleProfile.sampleExistsInGeneticProfile(sample.getInternalId(), geneticProfileId)); ArrayList caseIds = DaoSampleProfile.getAllSampleIdsInProfile(geneticProfileId); assertEquals(14, caseIds.size()); }
@Before public void setUp() throws DaoException { study = DaoCancerStudy.getCancerStudyByStableId("study_tcga_pub"); DaoGeneticProfile.reCache(); DaoPatient.reCache(); DaoSample.reCache(); }
private void runImportCnaData2() throws DaoException, IOException { DaoGeneticAlteration dao = DaoGeneticAlteration.getInstance(); ProgressMonitor.setConsoleMode(false); // TBD: change this to use getResourceAsStream() File file = new File("src/test/resources/cna_test2.txt"); ImportTabDelimData parser = new ImportTabDelimData(file, geneticProfileId, null); int numLines = FileUtil.getNumLines(file); parser.importData(numLines); String value = dao.getGeneticAlteration(geneticProfileId, sample1, 207); assertEquals(value, "0"); value = dao.getGeneticAlteration(geneticProfileId, sample4, 207); assertEquals(value, "-1"); value = dao.getGeneticAlteration(geneticProfileId, sample2, 207); assertEquals(value, "0"); value = dao.getGeneticAlteration(geneticProfileId, sample2, 10000); assertEquals(value, "2"); value = dao.getGeneticAlteration(geneticProfileId, sample3, 10000); assertEquals(value, "2"); int cnaStatus = Integer.parseInt(dao.getGeneticAlteration(geneticProfileId, sample3, 10000)); assertEquals(CopyNumberStatus.COPY_NUMBER_AMPLIFICATION, cnaStatus); cnaStatus = Integer.parseInt(dao.getGeneticAlteration(geneticProfileId, sample2, 10000)); assertEquals(CopyNumberStatus.COPY_NUMBER_AMPLIFICATION, cnaStatus); cnaStatus = Integer.parseInt(dao.getGeneticAlteration(geneticProfileId, sample4, 207)); assertEquals(CopyNumberStatus.HEMIZYGOUS_DELETION, cnaStatus); Patient patient = DaoPatient.getPatientByCancerStudyAndPatientId(studyId, "TCGA-A1-A0SB"); Sample sample = DaoSample.getSampleByPatientAndSampleId(patient.getInternalId(), "TCGA-A1-A0SB-01"); assertTrue( DaoSampleProfile.sampleExistsInGeneticProfile(sample.getInternalId(), geneticProfileId)); patient = DaoPatient.getPatientByCancerStudyAndPatientId(studyId, "TCGA-A1-A0SJ"); sample = DaoSample.getSampleByPatientAndSampleId(patient.getInternalId(), "TCGA-A1-A0SJ-01"); assertTrue( DaoSampleProfile.sampleExistsInGeneticProfile(sample.getInternalId(), geneticProfileId)); ArrayList sampleIds = DaoSampleProfile.getAllSampleIdsInProfile(geneticProfileId); assertEquals(14, sampleIds.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); } }