/** Gets all Genomic Data. */ private ProfileDataSummary getGenomicData( String cancerStudyId, HashMap<String, GeneticProfile> defaultGeneticProfileSet, SampleList defaultSampleSet, String geneListStr, ArrayList<SampleList> sampleList, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException, DaoException { // parse geneList, written in the OncoPrintSpec language (except for changes by XSS clean) double zScore = ZScoreUtil.getZScore( new HashSet<String>(defaultGeneticProfileSet.keySet()), new ArrayList<GeneticProfile>(defaultGeneticProfileSet.values()), request); double rppaScore = ZScoreUtil.getRPPAScore(request); ParserOutput theOncoPrintSpecParserOutput = OncoPrintSpecificationDriver.callOncoPrintSpecParserDriver( geneListStr, new HashSet<String>(defaultGeneticProfileSet.keySet()), new ArrayList<GeneticProfile>(defaultGeneticProfileSet.values()), zScore, rppaScore); ArrayList<String> geneList = new ArrayList<String>(); geneList.addAll(theOncoPrintSpecParserOutput.getTheOncoPrintSpecification().listOfGenes()); ArrayList<ProfileData> profileDataList = new ArrayList<ProfileData>(); Set<String> warningUnion = new HashSet<String>(); for (GeneticProfile profile : defaultGeneticProfileSet.values()) { try { GetProfileData remoteCall = new GetProfileData( profile, geneList, StringUtils.join(defaultSampleSet.getSampleList(), " ")); ProfileData pData = remoteCall.getProfileData(); warningUnion.addAll(remoteCall.getWarnings()); profileDataList.add(pData); } catch (IllegalArgumentException e) { e.getStackTrace(); } } ProfileMerger merger = new ProfileMerger(profileDataList); ProfileData mergedProfile = merger.getMergedProfile(); ProfileDataSummary dataSummary = new ProfileDataSummary( mergedProfile, theOncoPrintSpecParserOutput.getTheOncoPrintSpecification(), zScore, rppaScore); return dataSummary; }
private String getShortcutScript(HashMap<String, String> usedButtonShortCuts) { StringBuffer shortcuts = new StringBuffer(); shortcuts.append(" function buttonListShorcuts() {\n"); Iterator<String> ik = usedButtonShortCuts.keySet().iterator(); Iterator<String> iv = usedButtonShortCuts.values().iterator(); while (ik.hasNext() && iv.hasNext()) { shortcuts .append(" keyArray[keyArray.length] = new keyArrayItem(\"") .append(ik.next()) .append("\", \"") .append(iv.next()) .append("\", null, \"altKey\", false, \"onkeydown\");\n"); } shortcuts.append(" return true;\n}"); return shortcuts.toString(); }
/** * 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(); } }
private static Interpreter getInterpreter(String contextId) throws EvalError { // Get the appropriate interpreter Interpreter i = null; boolean createdInterp = false; synchronized (interpreters) { // serialize two gets of the same name i = interpreters.get(contextId); if (i == null) { i = new Interpreter(); interpreters.put(contextId, i); createdInterp = true; } } if (createdInterp) { Log.log("Created context: " + contextId + " (" + i + ")"); // Now configure stdin and stdout to capture 10k of content // Store references to the circular buffers within the interpreter itself. // This provides a nice place to store them plus theoretically allows // advanced use from within the bsh environment. // On Windows print() outputs \r\n but in XQuery that's normalized to \n // so the 10k of Java buffer may produce less than 10k of content in XQuery! OutputStream circularOutput = new CircularByteArrayOutputStream(10240); PrintStream printOutput = new PrintStream(circularOutput); i.setOut(printOutput); i.set("mljamout", circularOutput); OutputStream circularError = new CircularByteArrayOutputStream(10240); PrintStream printError = new PrintStream(circularError); i.setErr(printError); i.set("mljamerr", circularError); // Capture the built-in System.out and System.err also. // (Commented out since System appears global, can't do per interpreter.) // i.set("mljamprintout", printOutput); // i.set("mljamprinterr", printError); // i.eval("System.setOut(mljamprintout);"); // i.eval("System.setErr(mljamprinterr);"); // Need to expose hexdecode() and base64decode() built-in functions i.eval("hexdecode(String s) { return com.xqdev.jam.MLJAM.hexDecode(s); }"); i.eval("base64decode(String s) { return com.xqdev.jam.MLJAM.base64Decode(s); }"); // Let's tell the context what its id is i.set("mljamid", contextId); } // Update the last accessed time, used for cleaning i.set("mljamlast", System.currentTimeMillis()); // If it's been long enough, go snooping for stale contexts if (System.currentTimeMillis() > lastClean + CLEAN_INTERVAL) { Log.log("Initiated periodic scan for stale context objects"); lastClean = System.currentTimeMillis(); Iterator<Interpreter> itr = interpreters.values().iterator(); while (itr.hasNext()) { Interpreter interp = itr.next(); Long last = (Long) interp.get("mljamlast"); if (System.currentTimeMillis() > last + STALE_TIMEOUT) { itr.remove(); Log.log("Staled context: " + interp.get("mljamid") + " (" + interp + ")"); } else if ((System.currentTimeMillis() > last + TEMP_STALE_TIMEOUT) && ("" + interp.get("mljamid")).startsWith("temp:")) { itr.remove(); Log.log("Staled temp context: " + interp.get("mljamid") + " (" + interp + ")"); } } } return i; }