List of usage examples for java.util Vector add
public synchronized boolean add(E e)
From source file:gda.util.PackageMaker.java
/** * @param args//from w ww. j a va 2 s . c o m */ public static void main(String args[]) { String destDir = null; if (args.length == 0) return; String filename = args[0]; if (args.length > 1) destDir = args[1]; try { ClassParser cp = new ClassParser(filename); JavaClass classfile = cp.parse(); String packageName = classfile.getPackageName(); String apackageName = packageName.replace(".", File.separator); if (destDir != null) destDir = destDir + File.separator + apackageName; else destDir = apackageName; File destFile = new File(destDir); File existFile = new File(filename); File parentDir = new File(existFile.getAbsolutePath().substring(0, existFile.getAbsolutePath().lastIndexOf(File.separator))); String allFiles[] = parentDir.list(); Vector<String> selectedFiles = new Vector<String>(); String toMatch = existFile.getName().substring(0, existFile.getName().lastIndexOf(".")); for (int i = 0; i < allFiles.length; i++) { if (allFiles[i].startsWith(toMatch + "$")) selectedFiles.add(allFiles[i]); } FileUtils.copyFileToDirectory(existFile, destFile); Object[] filestoCopy = selectedFiles.toArray(); for (int i = 0; i < filestoCopy.length; i++) { FileUtils.copyFileToDirectory(new File((String) filestoCopy[i]), destFile); } } catch (IOException e) { e.printStackTrace(); } }
From source file:com.intel.cosbench.driver.generator.RangeIntGenerator.java
public static void main(String[] args) { final String pattern = "r(51,1000)"; final int all = 5; int i = 0;/* w ww. ja va2 s .com*/ Vector<TestThread> threads = new Vector<TestThread>(); RangeIntGenerator gen = RangeIntGenerator.parse(pattern); for (i = 0; i < all; i++) { TestThread thread = new TestThread(gen, i + 1, all); threads.add(thread); thread.start(); } try { for (i = 0; i < all; i++) { threads.elementAt(i).join(); } } catch (InterruptedException ie) { ie.printStackTrace(); } }
From source file:createSod.java
/** * @param args/*from w w w .j a v a 2 s. c o m*/ * @throws CMSException */ public static void main(String[] args) throws Exception { try { CommandLine options = verifyArgs(args); String privateKeyLocation = options.getOptionValue("privatekey"); String keyPassword = options.getOptionValue("keypass"); String certificate = options.getOptionValue("certificate"); String sodContent = options.getOptionValue("content"); String sod = ""; if (options.hasOption("out")) { sod = options.getOptionValue("out"); } // CHARGEMENT DU FICHIER PKCS#12 KeyStore ks = null; char[] password = null; Security.addProvider(new BouncyCastleProvider()); try { ks = KeyStore.getInstance("PKCS12"); // Password pour le fichier personnal_nyal.p12 password = keyPassword.toCharArray(); ks.load(new FileInputStream(privateKeyLocation), password); } catch (Exception e) { System.out.println("Erreur: fichier " + privateKeyLocation + " n'est pas un fichier pkcs#12 valide ou passphrase incorrect"); return; } // RECUPERATION DU COUPLE CLE PRIVEE/PUBLIQUE ET DU CERTIFICAT PUBLIQUE X509Certificate cert = null; PrivateKey privatekey = null; PublicKey publickey = null; try { Enumeration en = ks.aliases(); String ALIAS = ""; Vector vectaliases = new Vector(); while (en.hasMoreElements()) vectaliases.add(en.nextElement()); String[] aliases = (String[]) (vectaliases.toArray(new String[0])); for (int i = 0; i < aliases.length; i++) if (ks.isKeyEntry(aliases[i])) { ALIAS = aliases[i]; break; } privatekey = (PrivateKey) ks.getKey(ALIAS, password); cert = (X509Certificate) ks.getCertificate(ALIAS); publickey = ks.getCertificate(ALIAS).getPublicKey(); } catch (Exception e) { e.printStackTrace(); return; } // Chargement du certificat partir du fichier InputStream inStream = new FileInputStream(certificate); CertificateFactory cf = CertificateFactory.getInstance("X.509"); cert = (X509Certificate) cf.generateCertificate(inStream); inStream.close(); // Chargement du fichier qui va tre sign File file_to_sign = new File(sodContent); byte[] buffer = new byte[(int) file_to_sign.length()]; DataInputStream in = new DataInputStream(new FileInputStream(file_to_sign)); in.readFully(buffer); in.close(); // Chargement des certificats qui seront stocks dans le fichier .p7 // Ici, seulement le certificat personnal_nyal.cer sera associ. // Par contre, la chane des certificats non. ArrayList certList = new ArrayList(); certList.add(cert); CertStore certs = CertStore.getInstance("Collection", new CollectionCertStoreParameters(certList), "BC"); CMSSignedDataGenerator signGen = new CMSSignedDataGenerator(); // privatekey correspond notre cl prive rcupre du fichier PKCS#12 // cert correspond au certificat publique personnal_nyal.cer // Le dernier argument est l'algorithme de hachage qui sera utilis signGen.addSigner(privatekey, cert, CMSSignedDataGenerator.DIGEST_SHA1); signGen.addCertificatesAndCRLs(certs); CMSProcessable content = new CMSProcessableByteArray(buffer); // Generation du fichier CMS/PKCS#7 // L'argument deux permet de signifier si le document doit tre attach avec la signature // Valeur true: le fichier est attach (c'est le cas ici) // Valeur false: le fichier est dtach CMSSignedData signedData = signGen.generate(content, true, "BC"); byte[] signeddata = signedData.getEncoded(); // Ecriture du buffer dans un fichier. if (sod.equals("")) { System.out.print(signeddata.toString()); } else { FileOutputStream envfos = new FileOutputStream(sod); envfos.write(signeddata); envfos.close(); } } catch (OptionException oe) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(NAME, getOptions()); System.exit(-1); } catch (Exception e) { e.printStackTrace(); return; } }
From source file:gov.nih.nci.evs.reportwriter.utils.SimpleSearchUtils.java
public static void main(String[] args) { boolean searchExtensionAvaliable = isSearchExtensionAvaliable(); if (!searchExtensionAvaliable) { System.out.println("SearchExtension is not available."); System.exit(1);// w ww . j a v a2 s . c o m } SimpleSearchUtils test = new SimpleSearchUtils(); try { Vector<String> schemes = new Vector(); Vector<String> versions = new Vector(); schemes.add("NCI_Thesaurus"); versions.add(null); String matchText = "Tariquidar"; ResolvedConceptReferencesIteratorWrapper wrapper = test.search(schemes, versions, matchText, SimpleSearchUtils.BY_NAME, "contains"); if (wrapper != null) { ResolvedConceptReferencesIterator iterator = wrapper.getIterator(); if (iterator != null) { try { int numRemaining = iterator.numberRemaining(); System.out.println("Number of matches: " + numRemaining); dumpIterator(iterator); } catch (Exception ex) { ex.printStackTrace(); } } } else { System.out.println("wrapper is NULL??? " + matchText); } } catch (Exception ex) { ex.printStackTrace(); } }
From source file:gov.nih.nci.evs.browser.utils.SimpleSearchUtils.java
public static void main(String[] args) { boolean searchExtensionAvaliable = isSearchExtensionAvaliable(); if (!searchExtensionAvaliable) { System.out.println("SearchExtension is not available."); System.exit(1);/*from ww w.j av a 2s .com*/ } SimpleSearchUtils test = new SimpleSearchUtils(); try { Vector<String> schemes = new Vector(); Vector<String> versions = new Vector(); schemes.add("NCI_Thesaurus"); //versions.add("12.05d"); versions.add("13.03d"); schemes.add("NCI Metathesaurus"); versions.add("201105"); String matchText = "cell aging"; ResolvedConceptReferencesIteratorWrapper wrapper = test.search(schemes, versions, matchText, SimpleSearchUtils.BY_NAME, "contains"); if (wrapper != null) { ResolvedConceptReferencesIterator iterator = wrapper.getIterator(); if (iterator != null) { try { int numRemaining = iterator.numberRemaining(); System.out.println("Number of matches: " + numRemaining); dumpIterator(iterator); } catch (Exception ex) { ex.printStackTrace(); } } } else { System.out.println("wrapper is NULL??? " + matchText); } } catch (Exception ex) { ex.printStackTrace(); } }
From source file:BoxSample.java
public static void main(String args[]) { JButton button;//w w w . jav a2s . c o m Vector buttons = new Vector(); Dimension dim; JFrame frame = new JFrame("Box Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.X_AXIS)); JPanel topLeft = new JPanel(); topLeft.setLayout(new BoxLayout(topLeft, BoxLayout.X_AXIS)); topLeft.add(button = new JButton("One")); buttons.add(button); changeBoth(button); topLeft.add(button = new JButton("Two")); buttons.add(button); changeBoth(button); changeWidth(topLeft); JPanel bottomLeft = new JPanel(); bottomLeft.setLayout(new BoxLayout(bottomLeft, BoxLayout.X_AXIS)); bottomLeft.add(button = new JButton("Six")); buttons.add(button); changeBoth(button); bottomLeft.add(button = new JButton("Seven")); buttons.add(button); changeBoth(button); changeWidth(bottomLeft); JPanel left = new JPanel(); left.setLayout(new BoxLayout(left, BoxLayout.Y_AXIS)); left.add(topLeft); left.add(button = new JButton("Four")); buttons.add(button); changeBoth(button); left.add(bottomLeft); changeBoth(left); JPanel right = new JPanel(); right.setLayout(new BoxLayout(right, BoxLayout.Y_AXIS)); right.add(button = new JButton("Three")); buttons.add(button); changeWidth(button); right.add(button = new JButton("Five")); buttons.add(button); changeBoth(button); changeBoth(right); contentPane.add(left); contentPane.add(right); tweak(buttons); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { Vector<Double> doubleVector = new Vector<Double>(); Vector<Integer> integerVector = new Vector<Integer>(); Vector<Boolean> booleanVector = new Vector<Boolean>(); Vector<Icon> iconVector = new Vector<Icon>(); Icon icon1 = ((UIManager.getIcon("OptionPane.errorIcon"))); Icon icon2 = (UIManager.getIcon("OptionPane.informationIcon")); Icon icon3 = (UIManager.getIcon("OptionPane.warningIcon")); Icon icon4 = (UIManager.getIcon("OptionPane.questionIcon")); doubleVector.addElement(1.001);/*from ww w .ja v a2s . c o m*/ doubleVector.addElement(10.00); doubleVector.addElement(0.95); doubleVector.addElement(4.2); JComboBox comboBoxDouble = new JComboBox(doubleVector); integerVector.addElement(1); integerVector.addElement(2); integerVector.addElement(3); integerVector.addElement(4); JComboBox comboBoxInteger = new JComboBox(integerVector); booleanVector.add(Boolean.TRUE); booleanVector.add(Boolean.FALSE); JComboBox comboBoxBoolean = new JComboBox(booleanVector); iconVector.addElement(icon1); iconVector.addElement(icon2); iconVector.addElement(icon3); iconVector.addElement(icon4); JComboBox comboBoxIcon = new JComboBox(iconVector); JFrame frame = new JFrame(); frame.setLayout(new GridLayout(2, 2, 5, 5)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(comboBoxDouble); frame.add(comboBoxInteger); frame.add(comboBoxBoolean); frame.add(comboBoxIcon); frame.pack(); frame.setVisible(true); }
From source file:edu.ku.brc.specify.dbsupport.cleanuptools.FirstLastVerifier.java
/** * @param args/*from w w w . j a v a 2 s. c om*/ */ public static void main(String[] args) { if (true) { testLastNames(); return; } FirstLastVerifier flv = new FirstLastVerifier(); System.out.println(flv.isFirstName("Bill")); System.out.println(flv.isLastName("Bill")); System.out.println(flv.isFirstName("Johnson")); System.out.println(flv.isLastName("Johnson")); try { if (false) { for (String nm : new String[] { "firstnames", "lastnames" }) { File file = new File("/Users/rods/Downloads/" + nm + ".txt"); try { PrintWriter pw = new PrintWriter("/Users/rods/Downloads/" + nm + ".list"); for (String line : (List<String>) FileUtils.readLines(file)) { String[] toks = StringUtils.split(line, '\t'); if (toks != null && toks.length > 0) pw.println(toks[0]); } pw.close(); } catch (Exception e) { e.printStackTrace(); } } } Vector<String> lnames = new Vector<String>(); File file = XMLHelper.getConfigDir("lastnames.list"); if (false) { for (String name : (List<String>) FileUtils.readLines(file)) { if (flv.isFirstName(name)) { System.out.println(name + " is first."); } else { lnames.add(name); } } Collections.sort(lnames); FileUtils.writeLines(file, lnames); } lnames.clear(); file = XMLHelper.getConfigDir("firstnames.list"); for (String name : (List<String>) FileUtils.readLines(file)) { if (flv.isLastName(name)) { System.out.println(name + " is first."); } else { lnames.add(name); } } Collections.sort(lnames); //FileUtils.writeLines(file, lnames); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.seanmadden.fast.ldap.main.Main.java
/** * The Main Event./*from www . j a va 2s .c o m*/ * * @param args */ @SuppressWarnings("static-access") public static void main(String[] args) { BasicConfigurator.configure(); log.debug("System initializing"); try { Logger.getRootLogger().addAppender( new FileAppender(new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN), "log.log")); } catch (IOException e1) { log.error("Unable to open the log file..?"); } /* * Initialize the configuration engine. */ XMLConfiguration config = new XMLConfiguration(); config.setListDelimiter('|'); /* * Initialize the Command-Line parsing engine. */ CommandLineParser parser = new PosixParser(); Options opts = new Options(); opts.addOption(OptionBuilder.withLongOpt("config-file").hasArg() .withDescription("The configuration file to load").withArgName("config.xml").create("c")); opts.addOption(OptionBuilder.withLongOpt("profile").hasArg().withDescription("The profile to use") .withArgName("Default").create("p")); opts.addOption(OptionBuilder.withLongOpt("password").hasArg().withDescription("Password to connect with") .withArgName("password").create("P")); opts.addOption(OptionBuilder.withLongOpt("debug").hasArg(false).create('d')); opts.addOption(OptionBuilder.withLongOpt("verbose").hasArg(false).create('v')); File configurationFile = new File("config.xml"); try { // Parse the command-line options CommandLine cmds = parser.parse(opts, args); if (!cmds.hasOption('p')) { Logger.getRootLogger().addAppender(new GuiErrorAlerter(Level.ERROR)); } Logger.getRootLogger().setLevel(Level.ERROR); if (cmds.hasOption('v')) { Logger.getRootLogger().setLevel(Level.INFO); } if (cmds.hasOption('d')) { Logger.getRootLogger().setLevel(Level.DEBUG); } log.debug("Enabling configuration file parsing"); // The user has given us a file to parse. if (cmds.hasOption("c")) { configurationFile = new File(cmds.getOptionValue("c")); } log.debug("Config file: " + configurationFile); // Load the configuration file if (configurationFile.exists()) { config.load(configurationFile); } else { log.error("Cannot find config file"); } /* * Convert the profiles into memory */ Vector<ConnectionProfile> profs = new Vector<ConnectionProfile>(); List<?> profList = config.configurationAt("Profiles").configurationsAt("Profile"); for (Object p : profList) { SubnodeConfiguration profile = (SubnodeConfiguration) p; String name = profile.getString("[@name]"); String auth = profile.getString("LdapAuthString"); String server = profile.getString("LdapServerString"); String group = profile.getString("LdapGroupsLocation"); ConnectionProfile prof = new ConnectionProfile(name, server, auth, group); profs.add(prof); } ConnectionProfile prof = null; if (!cmds.hasOption('p')) { /* * Deploy the profile selector, to select a profile */ ProfileSelector profSel = new ProfileSelector(profs); prof = profSel.getSelection(); if (prof == null) { return; } /* * Empty the profiles and load a clean copy - then save it back * to the file */ config.clearTree("Profiles"); for (ConnectionProfile p : profSel.getProfiles()) { config.addProperty("Profiles.Profile(-1)[@name]", p.getName()); config.addProperty("Profiles.Profile.LdapAuthString", p.getLdapAuthString()); config.addProperty("Profiles.Profile.LdapServerString", p.getLdapServerString()); config.addProperty("Profiles.Profile.LdapGroupsLocation", p.getLdapGroupsString()); } config.save(configurationFile); } else { for (ConnectionProfile p : profs) { if (p.getName().equals(cmds.getOptionValue('p'))) { prof = p; break; } } } log.info("User selected " + prof); String password = ""; if (cmds.hasOption('P')) { password = cmds.getOptionValue('P'); } else { password = PasswordPrompter.promptForPassword("Password?"); } if (password.equals("")) { return; } LdapInterface ldap = new LdapInterface(prof.getLdapServerString(), prof.getLdapAuthString(), prof.getLdapGroupsString(), password); /* * Gather options information from the configuration engine for the * specified report. */ Hashtable<String, Hashtable<String, ReportOption>> reportDataStructure = new Hashtable<String, Hashtable<String, ReportOption>>(); List<?> repConfig = config.configurationAt("Reports").configurationsAt("Report"); for (Object p : repConfig) { SubnodeConfiguration repNode = (SubnodeConfiguration) p; // TODO Do something with the report profile. // Allowing the user to deploy "profiles" is a nice feature // String profile = repNode.getString("[@profile]"); String reportName = repNode.getString("[@report]"); Hashtable<String, ReportOption> reportOptions = new Hashtable<String, ReportOption>(); reportDataStructure.put(reportName, reportOptions); // Loop through the options and add each to the table. for (Object o : repNode.configurationsAt("option")) { SubnodeConfiguration option = (SubnodeConfiguration) o; String name = option.getString("[@name]"); String type = option.getString("[@type]"); String value = option.getString("[@value]"); ReportOption ro = new ReportOption(); ro.setName(name); if (type.toLowerCase().equals("boolean")) { ro.setBoolValue(Boolean.parseBoolean(value)); } else if (type.toLowerCase().equals("integer")) { ro.setIntValue(Integer.valueOf(value)); } else { // Assume a string type here then. ro.setStrValue(value); } reportOptions.put(name, ro); log.debug(ro); } } System.out.println(reportDataStructure); /* * At this point, we now need to deploy the reports window to have * the user pick a report and select some happy options to allow * that report to work. Let's go. */ /* * Deploy the Reports selector, to select a report */ Reports.getInstance().setLdapConnection(ldap); ReportsWindow reports = new ReportsWindow(Reports.getInstance().getAllReports(), reportDataStructure); Report report = reports.getSelection(); if (report == null) { return; } /* * Empty the profiles and load a clean copy - then save it back to * the file */ config.clearTree("Reports"); for (Report r : Reports.getInstance().getAllReports()) { config.addProperty("Reports.Report(-1)[@report]", r.getClass().getCanonicalName()); config.addProperty("Reports.Report[@name]", "Standard"); for (ReportOption ro : r.getOptions().values()) { config.addProperty("Reports.Report.option(-1)[@name]", ro.getName()); config.addProperty("Reports.Report.option[@type]", ro.getType()); config.addProperty("Reports.Report.option[@value]", ro.getStrValue()); } } config.save(configurationFile); ProgressBar bar = new ProgressBar(); bar.start(); report.execute(); ASCIIFormatter format = new ASCIIFormatter(); ReportResult res = report.getResult(); format.format(res, new File(res.getForName() + "_" + res.getReportName() + ".txt")); bar.stop(); JOptionPane.showMessageDialog(null, "The report is at " + res.getForName() + "_" + res.getReportName() + ".txt", "Success", JOptionPane.INFORMATION_MESSAGE); } catch (ParseException e) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("FAST Ldap Searcher", opts); } catch (ConfigurationException e) { e.printStackTrace(); log.fatal("OH EM GEES! Configuration errors."); } catch (Exception e) { e.printStackTrace(); } }
From source file:mzmatch.ipeak.align.CowCoda.java
@SuppressWarnings("unchecked") public static void main(String args[]) { final String lbl_mcq = "mcq"; try {// w ww .ja v a 2 s . c o m Tool.init(); // parse the commandline options final Options options = new Options(); CmdLineParser cmdline = new CmdLineParser(options); // check whether we need to show the help cmdline.parse(args); if (options.help) { Tool.printHeader(System.out, application, version); cmdline.printUsage(System.out, ""); return; } if (options.verbose) { Tool.printHeader(System.out, application, version); cmdline.printOptions(); } // check the command-line parameters int filetype = JFreeChartTools.PDF; { if (options.ppm == -1) { System.err.println("[ERROR]: the ppm-value needs to be set."); System.exit(0); } if (options.order == -1) { System.err.println("[ERROR]: the order for the polynomial fit needs to be set."); System.exit(0); } if (options.maxrt == -1) { System.err.println("[ERROR]: the maximum retention time shift is not set."); System.exit(0); } if (options.image != null) { String extension = options.image.substring(options.image.lastIndexOf('.') + 1); if (extension.toLowerCase().equals("png")) filetype = JFreeChartTools.PNG; else if (extension.toLowerCase().equals("pdf")) filetype = JFreeChartTools.PDF; else { System.err.println( "[ERROR]: file extension of the image file needs to be either PDF or PNG."); System.exit(0); } } // if the output directories do not exist, create them if (options.output != null) Tool.createFilePath(options.output, true); if (options.image != null) Tool.createFilePath(options.image, true); if (options.selection != null) Tool.createFilePath(options.selection, true); } // load the data if (options.verbose) System.out.println("Loading the data"); double maxrt = 0; Vector<ParseResult> data = new Vector<ParseResult>(); Vector<IPeakSet<IPeak>> matchdata = new Vector<IPeakSet<IPeak>>(); for (String file : options.input) { System.out.println("- " + new File(file).getName()); // load the mass chromatogram data ParseResult result = PeakMLParser.parse(new FileInputStream(file), true); data.add(result); // select the best mass chromatograms Vector<IPeak> selection = new Vector<IPeak>(); for (IPeak peak : (IPeakSet<IPeak>) result.measurement) { maxrt = Math.max(maxrt, maxRT(peak)); double mcq = codaDW(peak); peak.addAnnotation(lbl_mcq, Double.toString(mcq), Annotation.ValueType.DOUBLE); if (mcq >= options.codadw) selection.add(peak); } // keep track of the selected mass chromatograms int id = options.input.indexOf(file); IPeakSet<IPeak> peakset = new IPeakSet<IPeak>(selection); peakset.setMeasurementID(id); for (IPeak mc : peakset) mc.setMeasurementID(id); matchdata.add(peakset); } // match the selection together if (options.verbose) System.out.println("Matching the data"); Vector<IPeakSet<IPeak>> matches = IPeak.match((Vector) matchdata, options.ppm, new IPeak.MatchCompare<IPeak>() { public double distance(IPeak peak1, IPeak peak2) { double diff = Math.abs(peak1.getRetentionTime() - peak2.getRetentionTime()); if (diff > options.maxrt) return -1; Signal signal1 = new Signal(peak1.getSignal()); signal1.normalize(); Signal signal2 = new Signal(peak2.getSignal()); signal2.normalize(); double offset = bestOffSet(peak1, peak2, options.maxrt); for (int i = 0; i < signal2.getSize(); ++i) signal2.getX()[i] += offset; double correlation = signal2 .pearsonsCorrelation(signal1)[Statistical.PEARSON_CORRELATION]; if (correlation < 0.5) return -1; // the match-function optimizes toward 0 (it's a distance) return 1 - correlation; } }); // filter out all incomplete sets Vector<IPeakSet<IPeak>> valids = new Vector<IPeakSet<IPeak>>(); for (IPeakSet<IPeak> set : matches) { if (set.size() < options.input.size()) continue; valids.add((IPeakSet) set); } // calculate the alignment factors if (options.verbose) System.out.println("Calculating the alignment factors"); double medians[] = new double[valids.size() + 2]; DataFrame.Double dataframe = new DataFrame.Double(valids.size() + 2, options.input.size()); medians[0] = 0; medians[medians.length - 1] = maxrt; for (int i = 0; i < options.input.size(); ++i) { dataframe.set(0, i, 0.1); dataframe.set(dataframe.getNrRows() - 1, i, 0); } for (int matchid = 0; matchid < valids.size(); ++matchid) { IPeakSet<IPeak> match = valids.get(matchid); // find the most central double offsets[][] = new double[match.size()][match.size()]; for (int i = 0; i < match.size(); ++i) for (int j = i + 1; j < match.size(); ++j) { offsets[i][j] = bestOffSet(match.get(i), match.get(j), options.maxrt); offsets[j][i] = -offsets[i][j]; } int besti = 0; double bestabssum = Double.MAX_VALUE; for (int i = 0; i < match.size(); ++i) { double abssum = 0; for (int j = 0; j < match.size(); ++j) abssum += Math.abs(offsets[i][j]); if (abssum < bestabssum) { besti = i; bestabssum = abssum; } } for (int i = 0; i < match.size(); ++i) dataframe.set(matchid + 1, match.get(i).getMeasurementID(), (i == besti ? 0 : offsets[i][besti])); medians[matchid + 1] = match.get(besti).getRetentionTime(); dataframe.setRowName(matchid, Double.toString(match.get(besti).getRetentionTime())); } double minmedian = Statistical.min(medians); double maxmedian = Statistical.max(medians); // calculate for each profile the correction function PolynomialFunction functions[] = new PolynomialFunction[valids.size()]; for (int i = 0; i < options.input.size(); ++i) functions[i] = PolynomialFunction.fit(options.order, medians, dataframe.getCol(i)); // make a nice plot out of the whole thing if (options.verbose) System.out.println("Writing results"); if (options.image != null) { org.jfree.data.xy.XYSeriesCollection dataset = new org.jfree.data.xy.XYSeriesCollection(); JFreeChart linechart = ChartFactory.createXYLineChart(null, "Retention Time (seconds)", "offset", dataset, PlotOrientation.VERTICAL, true, // legend false, // tooltips false // urls ); // setup the colorkey Colormap colormap = new Colormap(Colormap.EXCEL); // get the structure behind the graph XYPlot plot = (XYPlot) linechart.getPlot(); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); // setup the plot area linechart.setBackgroundPaint(java.awt.Color.WHITE); linechart.setBorderVisible(false); linechart.setAntiAlias(true); plot.setBackgroundPaint(java.awt.Color.WHITE); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinesVisible(true); // create the datasets for (int i = 0; i < options.input.size(); ++i) { org.jfree.data.xy.XYSeries series = new org.jfree.data.xy.XYSeries(dataframe.getColName(i)); org.jfree.data.xy.XYSeries function = new org.jfree.data.xy.XYSeries( dataframe.getColName(i) + "-function"); dataset.addSeries(series); dataset.addSeries(function); renderer.setSeriesPaint(dataset.getSeriesCount() - 1, new java.awt.Color(colormap.getColor(i))); renderer.setSeriesPaint(dataset.getSeriesCount() - 2, new java.awt.Color(colormap.getColor(i))); renderer.setSeriesLinesVisible(dataset.getSeriesCount() - 2, false); renderer.setSeriesShapesVisible(dataset.getSeriesCount() - 2, true); // add the data-points for (int j = 0; j < valids.size(); ++j) series.add(medians[j], dataframe.get(j, i)); for (double x = minmedian; x < maxmedian; ++x) function.add(x, functions[i].getY(x)); } dataset.removeAllSeries(); for (int i = 0; i < options.input.size(); ++i) { Function function = functions[i]; org.jfree.data.xy.XYSeries series = new org.jfree.data.xy.XYSeries(dataframe.getColName(i)); dataset.addSeries(series); renderer.setSeriesPaint(i, new java.awt.Color(colormap.getColor(i))); renderer.setSeriesLinesVisible(i, false); renderer.setSeriesShapesVisible(i, true); // add the data-points for (int j = 0; j < valids.size(); ++j) series.add(medians[j], dataframe.get(j, i) - function.getY(medians[j])); } JFreeChartTools.writeAs(filetype, new FileOutputStream(options.image), linechart, 800, 500); } // save the selected if (options.selection != null) { Header header = new Header(); // set the number of peaks to be stored header.setNrPeaks(valids.size()); // create a set for the measurements SetInfo set = new SetInfo("", SetInfo.SET); header.addSetInfo(set); // create the measurement infos for (int i = 0; i < options.input.size(); ++i) { String file = options.input.get(i); // create the measurement info MeasurementInfo measurement = new MeasurementInfo(i, data.get(i).header.getMeasurementInfo(0)); measurement.addFileInfo(new FileInfo(file, file)); header.addMeasurementInfo(measurement); // add the file to the set set.addChild(new SetInfo(file, SetInfo.SET, i)); } // write the data PeakMLWriter.write(header, (Vector) valids, null, new GZIPOutputStream(new FileOutputStream(options.selection)), null); } // correct the values with the found function and save them for (int i = 0; i < options.input.size(); ++i) { Function function = functions[i]; ParseResult result = data.get(i); IPeakSet<MassChromatogram<Peak>> peakset = (IPeakSet<MassChromatogram<Peak>>) result.measurement; for (IPeak peak : peakset) align(peak, function); File filename = new File(options.input.get(i)); String name = filename.getName(); PeakMLWriter.write(result.header, (Vector) peakset.getPeaks(), null, new GZIPOutputStream(new FileOutputStream(options.output + "/" + name)), null); } } catch (Exception e) { Tool.unexpectedError(e, application); } }