List of usage examples for org.apache.commons.lang3.tuple Pair get
V get(Object key);
From source file:act.installer.pubchem.PubchemSynonymFinder.java
public static void main(String[] args) throws Exception { org.apache.commons.cli.Options opts = new org.apache.commons.cli.Options(); for (Option.Builder b : OPTION_BUILDERS) { opts.addOption(b.build());/*from w w w . ja v a 2s .c om*/ } CommandLine cl = null; try { CommandLineParser parser = new DefaultParser(); cl = parser.parse(opts, args); } catch (ParseException e) { System.err.format("Argument parsing failed: %s\n", e.getMessage()); HELP_FORMATTER.printHelp(PubchemSynonymFinder.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } if (cl.hasOption("help")) { HELP_FORMATTER.printHelp(PubchemSynonymFinder.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); return; } File rocksDBFile = new File(cl.getOptionValue(OPTION_INDEX_PATH)); if (!rocksDBFile.isDirectory()) { System.err.format("Index directory does not exist or is not a directory at '%s'", rocksDBFile.getAbsolutePath()); HELP_FORMATTER.printHelp(PubchemSynonymFinder.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } List<String> compoundIds = null; if (cl.hasOption(OPTION_PUBCHEM_COMPOUND_ID)) { compoundIds = Collections.singletonList(cl.getOptionValue(OPTION_PUBCHEM_COMPOUND_ID)); } else if (cl.hasOption(OPTION_IDS_FILE)) { File idsFile = new File(cl.getOptionValue(OPTION_IDS_FILE)); if (!idsFile.exists()) { System.err.format("Cannot find Pubchem CIDs file at %s", idsFile.getAbsolutePath()); HELP_FORMATTER.printHelp(PubchemSynonymFinder.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } compoundIds = getCIDsFromFile(idsFile); if (compoundIds.size() == 0) { System.err.format("Found zero Pubchem CIDs to process in file at '%s', exiting", idsFile.getAbsolutePath()); HELP_FORMATTER.printHelp(PubchemSynonymFinder.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } } else { System.err.format("Must specify one of '%s' or '%s'; index is too big to print all synonyms.", OPTION_PUBCHEM_COMPOUND_ID, OPTION_IDS_FILE); HELP_FORMATTER.printHelp(PubchemSynonymFinder.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } // Run a quick check to warn users of malformed ids. compoundIds.forEach(x -> { if (!PC_CID_PATTERN.matcher(x).matches()) { // Use matches() for complete matching. LOGGER.warn("Specified compound id does not match expected format: %s", x); } }); LOGGER.info("Opening DB and searching for %d Pubchem CIDs", compoundIds.size()); Pair<RocksDB, Map<PubchemTTLMerger.COLUMN_FAMILIES, ColumnFamilyHandle>> dbAndHandles = null; Map<String, PubchemSynonyms> results = new LinkedHashMap<>(compoundIds.size()); try { dbAndHandles = PubchemTTLMerger.openExistingRocksDB(rocksDBFile); RocksDB db = dbAndHandles.getLeft(); ColumnFamilyHandle cidToSynonymsCfh = dbAndHandles.getRight() .get(PubchemTTLMerger.COLUMN_FAMILIES.CID_TO_SYNONYMS); for (String cid : compoundIds) { PubchemSynonyms synonyms = null; byte[] val = db.get(cidToSynonymsCfh, cid.getBytes(UTF8)); if (val != null) { ObjectInputStream oi = new ObjectInputStream(new ByteArrayInputStream(val)); // We're relying on our use of a one-value-type per index model here so we can skip the instanceof check. synonyms = (PubchemSynonyms) oi.readObject(); } else { LOGGER.warn("No synonyms available for compound id '%s'", cid); } results.put(cid, synonyms); } } finally { if (dbAndHandles != null) { dbAndHandles.getLeft().close(); } } try (OutputStream outputStream = cl.hasOption(OPTION_OUTPUT) ? new FileOutputStream(cl.getOptionValue(OPTION_OUTPUT)) : System.out) { OBJECT_MAPPER.writerWithDefaultPrettyPrinter().writeValue(outputStream, results); new OutputStreamWriter(outputStream).append('\n'); } LOGGER.info("Done searching for Pubchem synonyms"); }
From source file:com.addthis.hydra.kafka.consumer.ConsumerUtils.java
public static Pair<ConsumerConnector, KafkaStream<Bundle, Bundle>> newBundleConsumer(String zookeeper, String topic, HashMap<String, String> overrides) { Map<String, Integer> topicStreams = new HashMap<>(); topicStreams.put(topic, 1);// w w w .j a v a2 s . c o m Pair<ConsumerConnector, Map<String, List<KafkaStream<Bundle, Bundle>>>> connectorAndStreams = newBundleStreams( zookeeper, topicStreams, overrides); return new ImmutablePair<>(connectorAndStreams.getLeft(), connectorAndStreams.getRight().get(topic).get(0)); }
From source file:com.act.lcms.db.analysis.ConfigurableAnalysis.java
public static void runAnalysis(DB db, File lcmsDir, String outputPrefix, List<AnalysisStep> steps, boolean makeHeatmaps, Double fontScale, boolean useSNR) throws SQLException, Exception { HashMap<String, Plate> platesByBarcode = new HashMap<>(); HashMap<Integer, Plate> platesById = new HashMap<>(); Map<Integer, Pair<List<ScanData<LCMSWell>>, Double>> lcmsResults = new HashMap<>(); Map<Integer, Pair<List<ScanData<StandardWell>>, Double>> standardResults = new HashMap<>(); Map<Integer, Double> intensityGroupMaximums = new HashMap<>(); for (AnalysisStep step : steps) { // There's no trace analysis to perform for non-sample steps. if (step.getKind() != AnalysisStep.KIND.SAMPLE) { continue; }//from ww w .ja v a2 s.co m Plate p = platesByBarcode.get(step.getPlateBarcode()); if (p == null) { p = Plate.getPlateByBarcode(db, step.getPlateBarcode()); if (p == null) { throw new IllegalArgumentException( String.format("Found invalid plate barcode '%s' for analysis component %d", step.getPlateBarcode(), step.getIndex())); } platesByBarcode.put(p.getBarcode(), p); platesById.put(p.getId(), p); } Pair<Integer, Integer> coords = Utils.parsePlateCoordinates(step.getPlateCoords()); List<Pair<String, Double>> searchMZs = Collections .singletonList(Pair.of("Configured m/z value", step.getExactMass())); Double maxIntesnsity = null; switch (p.getContentType()) { case LCMS: // We don't know which of the scans are positive samples and which are negatives, so call them all positive. List<LCMSWell> lcmsSamples = Collections.singletonList(LCMSWell.getInstance() .getByPlateIdAndCoordinates(db, p.getId(), coords.getLeft(), coords.getRight())); Pair<List<ScanData<LCMSWell>>, Double> lcmsScanData = AnalysisHelper.processScans(db, lcmsDir, searchMZs, ScanData.KIND.POS_SAMPLE, platesById, lcmsSamples, step.getUseFineGrainedMZTolerance(), SEARCH_IONS, EMPTY_SET, useSNR); lcmsResults.put(step.getIndex(), lcmsScanData); maxIntesnsity = lcmsScanData.getRight(); break; case STANDARD: List<StandardWell> standardSamples = Collections .singletonList(StandardWell.getInstance().getStandardWellsByPlateIdAndCoordinates(db, p.getId(), coords.getLeft(), coords.getRight())); Pair<List<ScanData<StandardWell>>, Double> standardScanData = AnalysisHelper.processScans(db, lcmsDir, searchMZs, ScanData.KIND.STANDARD, platesById, standardSamples, step.getUseFineGrainedMZTolerance(), SEARCH_IONS, EMPTY_SET, useSNR); standardResults.put(step.getIndex(), standardScanData); maxIntesnsity = standardScanData.getRight(); break; default: throw new IllegalArgumentException( String.format("Invalid plate content kind %s for plate %s in analysis component %d", p.getContentType(), p.getBarcode(), step.getIndex())); } Double existingMax = intensityGroupMaximums.get(step.getIntensityRangeGroup()); if (existingMax == null || existingMax < maxIntesnsity) { // TODO: is this the right max intensity? intensityGroupMaximums.put(step.getIntensityRangeGroup(), maxIntesnsity); } } // Prep the chart labels/types, write out the data, and plot the charts. File dataFile = new File(outputPrefix + ".data"); List<Gnuplotter.PlotConfiguration> plotConfigurations = new ArrayList<>(steps.size()); int numGraphs = 0; try (FileOutputStream fos = new FileOutputStream(dataFile)) { for (AnalysisStep step : steps) { if (step.getKind() == AnalysisStep.KIND.HEADER) { // TODO: change the Gnuplotter API to add headings and update this. plotConfigurations.add(new Gnuplotter.PlotConfiguration( Gnuplotter.PlotConfiguration.KIND.HEADER, step.getLabel(), null, null)); continue; } if (step.getKind() == AnalysisStep.KIND.SEPARATOR_LARGE || step.getKind() == AnalysisStep.KIND.SEPARATOR_SMALL) { // TODO: change the Gnuplotter API to add headings and update this. plotConfigurations.add(new Gnuplotter.PlotConfiguration( Gnuplotter.PlotConfiguration.KIND.SEPARATOR, "", null, null)); continue; } Plate p = platesByBarcode.get(step.getPlateBarcode()); Double maxIntensity = intensityGroupMaximums.get(step.getIntensityRangeGroup()); switch (p.getContentType()) { case LCMS: Pair<List<ScanData<LCMSWell>>, Double> lcmsPair = lcmsResults.get(step.getIndex()); if (lcmsPair.getLeft().size() > 1) { System.err.format("Found multiple scan files for LCMW well %s @ %s, using first\n", step.getPlateBarcode(), step.getPlateCoords()); } AnalysisHelper.writeScanData(fos, lcmsDir, maxIntensity, lcmsPair.getLeft().get(0), makeHeatmaps, false); break; case STANDARD: Pair<List<ScanData<StandardWell>>, Double> stdPair = standardResults.get(step.getIndex()); if (stdPair.getLeft().size() > 1) { System.err.format("Found multiple scan files for standard well %s @ %s, using first\n", step.getPlateBarcode(), step.getPlateCoords()); } AnalysisHelper.writeScanData(fos, lcmsDir, maxIntensity, stdPair.getLeft().get(0), makeHeatmaps, false); break; default: // This case represents a bug, so it's a RuntimeException. throw new RuntimeException( String.format("Found unexpected content type %s for plate %s on analysis step %d", p.getContentType(), p.getBarcode(), step.getIndex())); } plotConfigurations.add(new Gnuplotter.PlotConfiguration(Gnuplotter.PlotConfiguration.KIND.GRAPH, step.getLabel(), numGraphs, maxIntensity)); numGraphs++; } String fmt = "pdf"; File imgFile = new File(outputPrefix + "." + fmt); Gnuplotter plotter = fontScale == null ? new Gnuplotter() : new Gnuplotter(fontScale); if (makeHeatmaps) { plotter.plotHeatmap(dataFile.getAbsolutePath(), imgFile.getAbsolutePath(), fmt, null, null, plotConfigurations, imgFile + ".gnuplot"); } else { plotter.plot2D(dataFile.getAbsolutePath(), imgFile.getAbsolutePath(), "time", "intensity", fmt, null, null, plotConfigurations, imgFile + ".gnuplot"); } } }
From source file:com.streamsets.datacollector.event.handler.remote.TestRemoteStateEventListener.java
@Test public void testRemoteStateEventListener() throws Exception { RemoteStateEventListener remoteStateEventListener = new RemoteStateEventListener(new Configuration()); remoteStateEventListener.init();// www .ja va 2 s.c om Map<String, Object> attributes = new HashMap<>(); attributes.put(RemoteDataCollector.IS_REMOTE_PIPELINE, true); PipelineState pipelineState = new PipelineStateImpl("user", "name", "0", PipelineStatus.RUNNING, "msg", -1, attributes, ExecutionMode.STANDALONE, "", 1, -1); remoteStateEventListener.onStateChange(null, pipelineState, null, null, Collections.singletonMap(Source.POLL_SOURCE_OFFSET_KEY, "offset:1000")); Collection<Pair<PipelineState, Map<String, String>>> pipelineStateAndOffset = remoteStateEventListener .getPipelineStateEvents(); Assert.assertEquals(1, pipelineStateAndOffset.size()); Assert.assertEquals(PipelineStatus.RUNNING, pipelineStateAndOffset.iterator().next().getLeft().getStatus()); Assert.assertEquals("offset:1000", pipelineStateAndOffset.iterator().next().getRight().get(Source.POLL_SOURCE_OFFSET_KEY)); Assert.assertEquals(0, remoteStateEventListener.getPipelineStateEvents().size()); PipelineState pipelineStateDeleted = new PipelineStateImpl("user", "name", "0", PipelineStatus.DELETED, "msg", -1, attributes, ExecutionMode.STANDALONE, "", 1, -1); remoteStateEventListener.onStateChange(null, pipelineState, null, null, Collections.singletonMap(Source.POLL_SOURCE_OFFSET_KEY, "offset:old")); remoteStateEventListener.onStateChange(null, pipelineStateDeleted, null, null, Collections.singletonMap(Source.POLL_SOURCE_OFFSET_KEY, "offset:new")); pipelineStateAndOffset = remoteStateEventListener.getPipelineStateEvents(); Assert.assertEquals(2, pipelineStateAndOffset.size()); Iterator<Pair<PipelineState, Map<String, String>>> iterator = pipelineStateAndOffset.iterator(); iterator.next(); Pair<PipelineState, Map<String, String>> pair = iterator.next(); Assert.assertEquals(PipelineStatus.DELETED, pair.getLeft().getStatus()); Assert.assertEquals("offset:new", pair.getRight().get(Source.POLL_SOURCE_OFFSET_KEY)); Assert.assertEquals(0, remoteStateEventListener.getPipelineStateEvents().size()); }
From source file:com.github.steveash.jg2p.train.EncoderEval.java
private void printExamples() { for (Integer phoneEdit : examples.keySet()) { log.info(" ---- Examples with edit distance " + phoneEdit + " ----"); Iterable<Pair<InputRecord, List<PhoneticEncoder.Encoding>>> toPrint = limit(examples.get(phoneEdit), MAX_EXAMPLE_TO_PRINT);//from w w w.j av a2s. co m for (Pair<InputRecord, List<PhoneticEncoder.Encoding>> example : toPrint) { String got = "<null>"; if (example.getRight().size() > 0) { got = example.getRight().get(0).toString(); } log.info(" Got: " + got + " expected: " + example.getLeft().getRight().getAsSpaceString()); } } }
From source file:com.yahoo.pulsar.common.naming.NamespaceBundlesTest.java
private void assertBundles(NamespaceBundleFactory utilityFactory, NamespaceName nsname, NamespaceBundle bundle, Pair<NamespaceBundles, List<NamespaceBundle>> splitBundles, int numBundles) throws Exception { NamespaceBundle bundle1 = splitBundles.getRight().get(0); NamespaceBundle bundle2 = splitBundles.getRight().get(1); NamespaceBundles nspaceBundles = splitBundles.getLeft(); Pair<NamespaceBundles, List<NamespaceBundle>> bundle1Split = splitBundlesUtilFactory(utilityFactory, nsname, nspaceBundles, bundle1, numBundles); assertBundleDivideInTwo(bundle1, bundle1Split.getRight(), numBundles); Pair<NamespaceBundles, List<NamespaceBundle>> bundle2Split = splitBundlesUtilFactory(utilityFactory, nsname, nspaceBundles, bundle2, numBundles); assertBundleDivideInTwo(bundle2, bundle2Split.getRight(), numBundles); }
From source file:at.beris.virtualfile.shell.Shell.java
private void processCommand(Pair<Command, List<String>> cmd) throws IOException { switch (cmd.getLeft()) { case CD:/*from w ww . j a v a 2 s . c o m*/ change(cmd.getRight().get(0), false); break; case CON: connect(new URL(cmd.getRight().get(0))); break; case DIS: disconnect(); break; case GET: get(cmd.getRight().get(0)); break; case HELP: displayHelp(); break; case LCD: change(cmd.getRight().get(0), true); break; case LPWD: System.out.println(localFile.getPath()); break; case LLS: list(true); break; case LRM: remove(true, cmd.getRight().get(0)); break; case LS: list(false); break; case PUT: put(cmd.getRight().get(0)); break; case PWD: System.out.println(workingFile != null ? maskedUrlString(workingFile.getUrl()) : NOT_CONNECTED_MSG); break; case RM: remove(false, cmd.getRight().get(0)); break; case STAT: displayStatistics(); break; case QUIT: quit(); break; default: System.out.println("Unknown command."); } }
From source file:act.installer.pubchem.PubchemTTLMergerTest.java
public List<String> getValForKey( Pair<RocksDB, Map<PubchemTTLMerger.COLUMN_FAMILIES, ColumnFamilyHandle>> dbAndHandles, PubchemTTLMerger.COLUMN_FAMILIES columnFamily, String key) throws Exception { RocksDB db = dbAndHandles.getLeft(); String columnFamilyName = columnFamily.getName(); ColumnFamilyHandle cfh = dbAndHandles.getRight().get(columnFamily); byte[] keyBytes = key.getBytes(); byte[] valBytes = db.get(cfh, keyBytes); try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(valBytes))) { return (List<String>) ois.readObject(); }/*from w ww . j a va 2 s . co m*/ }
From source file:com.act.lcms.v2.TraceIndexAnalyzer.java
private void runExtraction(File rocksDBFile, File outputFile) throws RocksDBException, IOException { List<AnalysisResult> results = new ArrayList<>(); // Extract each target's trace, computing and saving stats as we go. This should fit in memory no problem. Iterator<Pair<Double, List<XZ>>> traceIterator = new TraceIndexExtractor() .getIteratorOverTraces(rocksDBFile); while (traceIterator.hasNext()) { Pair<Double, List<XZ>> targetAndTrace = traceIterator.next(); String label = String.format("%.6f", targetAndTrace.getLeft()); // Note: here we cheat by knowing how the MS1 class is going to use this incredibly complex container. MS1ScanForWellAndMassCharge scanForWell = new MS1ScanForWellAndMassCharge(); scanForWell.setMetlinIons(Collections.singletonList(label)); scanForWell.getIonsToSpectra().put(label, targetAndTrace.getRight()); Pair<List<XZ>, Map<Double, Double>> timeWindowsAndMaxes = WaveformAnalysis .compressIntensityAndTimeGraphsAndFindMaxIntensityInEveryTimeWindow(targetAndTrace.getRight(), WaveformAnalysis.COMPRESSION_CONSTANT); List<XZ> calledPeaks = WaveformAnalysis.detectPeaksInIntensityTimeWaveform( timeWindowsAndMaxes.getLeft(), WaveformAnalysis.PEAK_DETECTION_THRESHOLD); // Same as waveform analysis. for (XZ calledPeak : calledPeaks) { AnalysisResult result = new AnalysisResult(targetAndTrace.getLeft(), timeWindowsAndMaxes.getRight().get(calledPeak.getTime()), calledPeak.getTime()); results.add(result);/*from w ww . j a v a 2s. c o m*/ } } LOGGER.info("Writing window stats to JSON file"); try (FileOutputStream fos = new FileOutputStream(outputFile)) { OBJECT_MAPPER.writerWithDefaultPrettyPrinter().writeValue(fos, results); } }
From source file:it.polimi.diceH2020.SPACE4CloudWS.solvers.solversImpl.DagSimSolver.DagSimSolver.java
@Override protected Pair<Double, Boolean> run(Pair<List<File>, List<File>> pFiles, String remoteName, String remoteDirectory) throws Exception { if (pFiles.getLeft() == null || pFiles.getLeft().size() != 1) { throw new Exception("Model file missing"); }//from w w w . ja va 2 s . c o m if (pFiles.getRight() == null || pFiles.getRight().isEmpty()) { throw new Exception("Replayer files missing"); } double result = 0.; boolean success = false; List<String> remoteMsg = null; boolean stillNotOk = true; for (int i = 0; stillNotOk && i < MAX_ITERATIONS; ++i) { logger.info(remoteName + "-> Starting DagSim resolution on the server"); File modelFile = pFiles.getLeft().get(0); String fileName = modelFile.getName(); String remotePath = remoteDirectory + File.separator + fileName; List<File> workingFiles = pFiles.getRight(); workingFiles.add(modelFile); cleanRemoteSubDirectory(remoteDirectory); sendFiles(remoteDirectory, workingFiles); logger.debug(remoteName + "-> Working files sent"); logger.debug(remoteName + "-> Starting DagSim model..."); String command = String.format("%s %s", connSettings.getSolverPath(), remotePath); remoteMsg = connector.exec(command, getClass()); if (remoteMsg.contains("exit-status: 0")) { stillNotOk = false; logger.info(remoteName + "-> The remote simulation process completed correctly"); } else { logger.debug(remoteName + "-> Remote exit status: " + remoteMsg); } } if (stillNotOk) { logger.info(remoteName + "-> Error in remote simulation on DagSim"); throw new Exception("Error in the DagSim server"); } else { final String stdout = remoteMsg.get(0); final String stderr = remoteMsg.get(1); try (Scanner scanner = new Scanner(stdout)) { while (!success && scanner.hasNextLine()) { Matcher matcher = RESULT_LINE.matcher(scanner.nextLine()); if (matcher.find()) { result = Double.valueOf(matcher.group("avg")); success = true; } } } if (!success) { logger.error(String.format("%s -> Error in remote DagSim simulation", remoteName)); logger.error(String.format("%s -> stdout:\n%s", remoteName, stdout)); logger.error(String.format("%s -> stderr:\n%s", remoteName, stderr)); } } return Pair.of(result, !success); }