List of usage examples for java.util HashMap values
public Collection<V> values()
From source file:Main.java
public static void main(String[] args) { HashMap<String, String> hMap = new HashMap<String, String>(); hMap.put("1", "One"); hMap.put("2", "Two"); hMap.put("3", "Three"); Collection c = hMap.values(); Iterator itr = c.iterator();/*from ww w .j av a2 s . c om*/ while (itr.hasNext()) { System.out.println(itr.next()); } }
From source file:Main.java
public static void main(String[] a) { HashMap<String, String> map = new HashMap<String, String>(); map.put("key1", "value1"); map.put("key2", "value2"); map.put("key3", "value3"); Collection set = map.values(); Iterator iter = set.iterator(); while (iter.hasNext()) { System.out.println(iter.next()); }/*from w w w. j a v a 2s. c o m*/ }
From source file:Main.java
public static void main(String args[]) { HashMap<Integer, String> newmap = new HashMap<Integer, String>(); // populate hash map newmap.put(1, "tutorials"); newmap.put(2, "from"); newmap.put(3, "java2s.com"); System.out.println(newmap.values()); }
From source file:Main.java
public static void main(String[] args) throws IllegalAccessException { Class clazz = Color.class; Field[] colorFields = clazz.getDeclaredFields(); HashMap<String, Color> singleColors = new HashMap<String, Color>(); for (Field cf : colorFields) { int modifiers = cf.getModifiers(); if (!Modifier.isPublic(modifiers)) continue; Color c = (Color) cf.get(null); if (!singleColors.values().contains(c)) singleColors.put(cf.getName(), c); }// w w w. j a va 2 s . c om for (String k : singleColors.keySet()) { System.out.println(k + ": " + singleColors.get(k)); } }
From source file:Main.java
public static void main(String[] args) { HashMap<String, String> hashmap = new HashMap<String, String>(); hashmap.put("one", "1"); hashmap.put("two", "2"); hashmap.put("three", "3"); hashmap.put("four", "4"); hashmap.put("five", "5"); hashmap.put("six", "6"); Iterator<String> keyIterator = hashmap.keySet().iterator(); Iterator<String> valueIterator = hashmap.values().iterator(); while (keyIterator.hasNext()) { System.out.println("key: " + keyIterator.next()); }/*w w w . ja va 2 s . c o m*/ while (valueIterator.hasNext()) { System.out.println("value: " + valueIterator.next()); } }
From source file:ch.devmine.javaparser.Main.java
/** * Main function//from w w w . java2 s .co m * @param args * the path of the repository to parse */ public static void main(String[] args) { // parse one repository if (args.length != 1) { System.err.println( "usage : javaparser <path>\n" + "path : the path to the folder or the tar archive to parse"); return; } Project project = new Project(); Language language = defineJavaLang(); List<Language> languages = new ArrayList<>(); languages.add(language); project.setLanguages(languages); HashMap<String, Package> packs = new HashMap<>(); if (new File(args[0]).isDirectory()) { parseAsDirectory(project, packs, languages, language, args[0]); } else { parseAsTarArchive(project, packs, languages, language, args[0]); } List<Package> packages = new ArrayList<>(packs.values()); int projLoc = 0; for (Package pack : packages) { int packLoc = 0; for (SourceFile file : pack.getSourceFiles()) { packLoc += file.getLoc(); } pack.setLoc(packLoc); projLoc += packLoc; } project.setPackages(packages); project.setLoc(projLoc); Gson gson = GsonFactory.build(); String jsonProject = gson.toJson(project); // the result is written in the system output in order to be // used in chain with the source analyzer // see https://github.com/devmine/scranlzr System.out.println(jsonProject); }
From source file:mzmatch.ipeak.normalisation.VanDeSompele.java
public static void main(String args[]) { try {//from w ww. j a v a 2 s. c om Tool.init(); // parse the commandline options 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 { // if the output directories do not exist, create them if (options.output != null) Tool.createFilePath(options.output, true); } // load the data if (options.verbose) System.out.println("Loading data"); ParseResult result = PeakMLParser.parse(new FileInputStream(options.input), true); Header header = result.header; IPeakSet<IPeakSet<? extends IPeak>> peaksets = (IPeakSet<IPeakSet<? extends IPeak>>) result.measurement; int nrmeasurements = header.getNrMeasurementInfos(); // remove the stability factor annotation for (IPeak peak : peaksets) peak.removeAnnotation("stability factor"); // load the database if (options.verbose) System.out.println("Loading the molecule database"); HashMap<String, Molecule> database = MoleculeIO.parseXml(new FileInputStream(options.database)); // filter the set to include only identifiable metabolites if (options.verbose) System.out.println("Creating selection"); Vector<IPeakSet<? extends IPeak>> selection = new Vector<IPeakSet<? extends IPeak>>(); for (Molecule molecule : database.values()) { double mass = molecule.getMass(Mass.MONOISOTOPIC); double delta = PeriodicTable.PPM(mass, options.ppm); // get the most intense peak containing all the measurements Vector<IPeakSet<? extends IPeak>> neighbourhoud = peaksets.getPeaksInMassRange(mass - delta, mass + delta); Collections.sort(neighbourhoud, IPeak.sort_intensity_descending); for (IPeakSet<? extends IPeak> neighbour : neighbourhoud) if (count(neighbour) == nrmeasurements) { selection.add(neighbour); break; } } // calculate the stability factor for each peak in the selection if (options.verbose) System.out.println("Calculating stability factors"); for (int peakid1 = 0; peakid1 < selection.size(); ++peakid1) { double stddeviations[] = new double[selection.size()]; IPeakSet<? extends IPeak> peakset1 = selection.get(peakid1); for (int peakid2 = 0; peakid2 < selection.size(); ++peakid2) { IPeakSet<? extends IPeak> peakset2 = selection.get(peakid2); double values[] = new double[nrmeasurements]; for (int measurementid = 0; measurementid < nrmeasurements; ++measurementid) { int measurementid1 = peakset1.get(measurementid).getMeasurementID(); int setid1 = header.indexOfSetInfo(header.getSetInfoForMeasurementID(measurementid1)); int measurementid2 = peakset2.get(measurementid).getMeasurementID(); int setid2 = header.indexOfSetInfo(header.getSetInfoForMeasurementID(measurementid2)); if (setid1 != setid2 || measurementid1 != measurementid2) System.err.println("[WARNING]: differing setid or spectrumid for comparison"); values[measurementid] = Math.log(peakset1.get(measurementid).getIntensity() / peakset2.get(measurementid).getIntensity()) / Math.log(2); } stddeviations[peakid2] = Statistical.stddev(values); } peakset1.addAnnotation("stability factor", Statistical.mean(stddeviations)); } // sort on the stability factor Collections.sort(selection, new IPeak.AnnotationAscending("stability factor")); // take the top 10% and calculate the geometric mean if (options.verbose) System.out.println("Calculating normalisation factors"); int nrselected = (int) (0.1 * selection.size()); if (nrselected < 10) nrselected = (10 < selection.size() ? 10 : selection.size()); double normalization_factors[] = new double[nrmeasurements]; for (int measurementid = 0; measurementid < nrmeasurements; ++measurementid) { double values[] = new double[nrselected]; for (int i = 0; i < nrselected; ++i) { IPeak peak = selection.get(i).get(measurementid); values[i] = peak.getIntensity(); } normalization_factors[measurementid] = Statistical.geomean(values); } // scale the found normalization factors double maxnf = Statistical.max(normalization_factors); for (int sampleid = 0; sampleid < nrmeasurements; ++sampleid) normalization_factors[sampleid] /= maxnf; // write the selection if needed if (options.selection != null) { if (options.verbose) System.out.println("Writing original selection data"); PeakMLWriter.write(result.header, selection, null, new GZIPOutputStream(new FileOutputStream(options.selection)), null); } // normalize all the peaks if (options.verbose) System.out.println("Normalizing all the entries"); for (IPeakSet<? extends IPeak> peakset : peaksets) { for (int measurementid = 0; measurementid < nrmeasurements; ++measurementid) { // TODO why did I do this again ? int id = 0; int setid = 0; int spectrumid = 0; for (int i = 0; i < header.getNrSetInfos(); ++i) { SetInfo set = header.getSetInfos().get(i); if (id + set.getNrMeasurementIDs() > measurementid) { setid = i; spectrumid = measurementid - id; break; } else id += set.getNrMeasurementIDs(); } MassChromatogram<Peak> masschromatogram = null; for (IPeak p : peakset) { int mymeasurementid = p.getMeasurementID(); int mysetid = header.indexOfSetInfo(header.getSetInfoForMeasurementID(mymeasurementid)); if (mysetid == setid && mymeasurementid == spectrumid) { masschromatogram = (MassChromatogram<Peak>) p; break; } } if (masschromatogram == null) continue; for (IPeak peak : masschromatogram.getPeaks()) peak.setIntensity(peak.getIntensity() / normalization_factors[measurementid]); } } // write the selection if needed if (options.selection_normalized != null) { if (options.verbose) System.out.println("Writing the normalized selection data"); PeakMLWriter.write(result.header, selection, null, new GZIPOutputStream(new FileOutputStream(options.selection_normalized)), null); } // write the factors if needed if (options.factors != null) { if (options.verbose) System.out.println("Writing the normalization factors"); PrintStream out = new PrintStream(options.factors); for (int measurementid = 0; measurementid < nrmeasurements; ++measurementid) out.println(header.getMeasurementInfo(measurementid).getLabel() + "\t" + normalization_factors[measurementid]); } // write the plot if needed if (options.img != null) { if (options.verbose) System.out.println("Writing the graph"); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); JFreeChart linechart = ChartFactory.createLineChart(null, "measurement", "normalization factor", dataset, PlotOrientation.VERTICAL, false, // legend false, // tooltips false // urls ); CategoryPlot plot = (CategoryPlot) linechart.getPlot(); CategoryAxis axis = (CategoryAxis) plot.getDomainAxis(); axis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setSeriesShapesFilled(0, true); renderer.setSeriesShapesVisible(0, true); linechart.setBackgroundPaint(Color.WHITE); linechart.setBorderVisible(false); linechart.setAntiAlias(true); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinesVisible(true); // create the datasets for (int measurementid = 0; measurementid < nrmeasurements; ++measurementid) dataset.addValue(normalization_factors[measurementid], "", header.getMeasurementInfo(measurementid).getLabel()); JFreeChartTools.writeAsPDF(new FileOutputStream(options.img), linechart, 800, 500); } // write the normalized values if (options.verbose) System.out.println("Writing the normalized data"); PeakMLWriter.write(result.header, peaksets.getPeaks(), null, new GZIPOutputStream(new FileOutputStream(options.output)), null); } catch (Exception e) { Tool.unexpectedError(e, application); } }
From source file:it.iit.genomics.cru.structures.bridges.uniprot.UniprotkbUtils.java
/** * * @param args// w ww . j av a2s . c o m * @throws Exception */ public static void main(String[] args) throws Exception { ArrayList<String> acs = new ArrayList<>(); acs.add("P84022"); HashMap<String, MoleculeEntry> prots = UniprotkbUtils.getInstance("9606") .getUniprotEntriesFromUniprotAccessions(acs); for (MoleculeEntry entry : prots.values()) { System.out.println(entry); for (String pdb : entry.getPdbs()) { System.out.println("# " + pdb); for (ChainMapping chain : entry.getChains(pdb)) { System.out.println("- " + pdb + ": " + chain.getChain()); } } System.out.println("Diseases: " + StringUtils.join(entry.getDiseases(), ", ")); } }
From source file:nl.systemsgenetics.genenetworkbackend.hpo.ImproveHpoPredictionBasedOnChildTerms.java
/** * @param args the command line arguments * @throws java.lang.Exception/*from w ww .ja v a 2 s . c o m*/ */ public static void main(String[] args) throws Exception { final File predictionMatrixFile = new File( "C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\Data31995Genes05-12-2017\\PCA_01_02_2018\\predictions\\hpo_predictions.txt.gz"); final File annotationMatrixFile = new File( "C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\Data31995Genes05-12-2017\\PCA_01_02_2018\\PathwayMatrix\\ALL_SOURCES_ALL_FREQUENCIES_phenotype_to_genes.txt_matrix.txt.gz"); final File predictedHpoTermFile = new File( "C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\Data31995Genes05-12-2017\\PCA_01_02_2018\\predictions\\hpo_predictions_auc_bonferroni.txt"); // final File predictionMatrixFile = new File("C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\Data31995Genes05-12-2017\\PCA_01_02_2018\\predictions\\hpo_predictions_testSet.txt"); // final File annotationMatrixFile = new File("C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\Data31995Genes05-12-2017\\PCA_01_02_2018\\PathwayMatrix\\hpo_annotation_testSet.txt"); // final File predictedHpoTermFile = new File("C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\Data31995Genes05-12-2017\\PCA_01_02_2018\\predictions\\hpo_predictions_testSet_auc_bonferroni.txt"); final File hpoOboFile = new File("C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\HPO\\135\\hp.obo"); final File ouputLogFile = new File( "C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\Data31995Genes05-12-2017\\PCA_01_02_2018\\predictions\\hpo_predictions_improved.log"); final File updatedPredictionMatrixFile = new File( "C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\Data31995Genes05-12-2017\\PCA_01_02_2018\\predictions\\hpo_predictions_improved.txt.gz"); LinkedHashSet<String> predictedHpoTerms = readPredictedHpoTermFile(predictedHpoTermFile); DoubleMatrixDataset<String, String> predictionMatrixFull = DoubleMatrixDataset .loadDoubleData(predictionMatrixFile.getAbsolutePath()); DoubleMatrixDataset<String, String> annotationMatrixFull = DoubleMatrixDataset .loadDoubleData(annotationMatrixFile.getAbsolutePath()); DoubleMatrixDataset<String, String> predictionMatrixPredicted = predictionMatrixFull .viewColSelection(predictedHpoTerms); DoubleMatrixDataset<String, String> annotationMatrixPredicted = annotationMatrixFull .viewColSelection(predictedHpoTerms); Ontology hpoOntology = HpoFinder.loadHpoOntology(hpoOboFile); ImproveHpoPredictionBasedOnChildTerms improver = new ImproveHpoPredictionBasedOnChildTerms( predictionMatrixPredicted, annotationMatrixPredicted, hpoOntology); HashMap<String, UpdatedPredictionInfo> checkedHpoInfo = improver.run(); System.out.println("Done with improving"); CSVWriter writer = new CSVWriter(new FileWriter(ouputLogFile), '\t', '\0', '\0', "\n"); String[] outputLine = new String[11]; int c = 0; outputLine[c++] = "HPO"; outputLine[c++] = "Gene_count"; outputLine[c++] = "Origanl_AUC"; outputLine[c++] = "Orignal_Pvalue"; outputLine[c++] = "Updated_AUC"; outputLine[c++] = "Updated_Pvalue"; outputLine[c++] = "Is_significant"; outputLine[c++] = "Distance_to_top"; outputLine[c++] = "Number_of_child_terms"; outputLine[c++] = "Number_of_child_terms_used"; outputLine[c++] = "Child_terms_used"; writer.writeNext(outputLine); for (UpdatedPredictionInfo pi : checkedHpoInfo.values()) { c = 0; outputLine[c++] = pi.getHpo(); outputLine[c++] = String.valueOf(pi.getGeneCount()); outputLine[c++] = String.valueOf(pi.getOriginalAuc()); outputLine[c++] = String.valueOf(pi.getOriginalPvalue()); outputLine[c++] = String.valueOf(pi.getUpdatedAuc()); outputLine[c++] = String.valueOf(pi.getUpdatedPvalue()); outputLine[c++] = String.valueOf(pi.isIsSignificant()); outputLine[c++] = "-"; outputLine[c++] = String.valueOf(pi.getChildTermCount()); outputLine[c++] = String.valueOf(pi.getUsedChildTerms().size()); outputLine[c++] = String.join(";", pi.getUsedChildTerms()); writer.writeNext(outputLine); } writer.close(); improver.writeUpdatedMatrix(updatedPredictionMatrixFile); }
From source file:com.example.bigtable.simplecli.HBaseCLI.java
/** * The main method for the CLI. This method takes the command line * arguments and runs the appropriate commands. *//*w w w. j av a2 s . c o m*/ public static void main(String[] args) { // We use Apache commons-cli to check for a help option. Options options = new Options(); Option help = new Option("help", "print this message"); options.addOption(help); // create the parser CommandLineParser parser = new BasicParser(); CommandLine line = null; try { // parse the command line arguments line = parser.parse(options, args); } catch (ParseException exp) { // oops, something went wrong System.err.println(exp.getMessage()); usage(); System.exit(1); } // Create a list of commands that are supported. Each // command defines a run method and some methods for // printing help. // See the definition of each command below. HashMap<String, Command> commands = new HashMap<String, Command>(); commands.put("create", new CreateCommand("create")); commands.put("scan", new ScanCommand("scan")); commands.put("get", new GetCommand("get")); commands.put("put", new PutCommand("put")); commands.put("list", new ListCommand("list")); Command command = null; List<String> argsList = Arrays.asList(args); if (argsList.size() > 0) { command = commands.get(argsList.get(0)); } // Check for the help option and if it's there // display the appropriate help. if (line.hasOption("help")) { // If there is a command listed (e.g. create -help) // then show the help for that command if (command == null) { help(commands.values()); } else { help(command); } System.exit(0); } else if (command == null) { // No valid command was given so print the usage. usage(); System.exit(0); } try { Connection connection = ConnectionFactory.createConnection(); try { try { // Run the command with the arguments after the command name. command.run(connection, argsList.subList(1, argsList.size())); } catch (InvalidArgsException e) { System.out.println("ERROR: Invalid arguments"); usage(command); System.exit(0); } } finally { // Make sure the connection is closed even if // an exception occurs. connection.close(); } } catch (IOException e) { e.printStackTrace(); } }