List of usage examples for com.google.common.collect ArrayListMultimap create
public static <K, V> ArrayListMultimap<K, V> create()
From source file:it.iit.genomics.cru.simsearch.bundle.utils.PantherBridge.java
public static Collection<String[]> getEnrichment(String organism, String fileName, double threshold) { ArrayList<String[]> results = new ArrayList<>(); ArrayListMultimap<String, String> genes = ArrayListMultimap.create(); ArrayListMultimap<Double, String> pvalues = ArrayListMultimap.create(); HashSet<String> uniqueGenes = new HashSet<>(); try {// w w w . jav a 2 s . c o m String[] enrichmentTypes = { "process", "pathway" }; for (String enrichmentType : enrichmentTypes) { HttpClient client = new HttpClient(); MultipartPostMethod method = new MultipartPostMethod( "http://pantherdb.org/webservices/garuda/tools/enrichment/VER_2/enrichment.jsp?"); // Define name-value pairs to set into the QueryString method.addParameter("organism", organism); method.addParameter("type", "enrichment"); method.addParameter("enrichmentType", enrichmentType); // "function", // "process", // "cellular_location", // "protein_class", // "pathway" File inputFile = new File(fileName); method.addPart(new FilePart("geneList", inputFile, "text/plain", "ISO-8859-1")); // PANTHER does not use the ID type // method.addParameter("IdType", "UniProt"); // Execute and print response client.executeMethod(method); String response = method.getResponseBodyAsString(); for (String line : response.split("\n")) { if (false == "".equals(line.trim())) { String[] row = line.split("\t"); // Id Name GeneId P-value if ("Id".equals(row[0])) { // header continue; } // if (row.length > 1) { String name = row[1]; String gene = row[2]; Double pvalue = Double.valueOf(row[3]); uniqueGenes.add(gene); if (pvalue < threshold) { if (false == genes.containsKey(name)) { pvalues.put(pvalue, name); } genes.put(name, gene); } // } else { // System.out.println("oups: " + row[0]); // } } } method.releaseConnection(); } ArrayList<Double> pvalueList = new ArrayList<>(); Collections.sort(pvalueList); pvalueList.addAll(pvalues.keySet()); Collections.sort(pvalueList); int numGenes = uniqueGenes.size(); for (Double pvalue : pvalueList) { for (String name : pvalues.get(pvalue)) { String geneList = String.join(",", genes.get(name)); String result[] = { name, "" + pvalue, genes.get(name).size() + "/" + numGenes, geneList }; results.add(result); } } } catch (IOException e) { e.printStackTrace(); } return results; }
From source file:org.crypto.sse.Partition.java
public static Multimap<Integer, String> partitioning(Multimap<String, String> lookup) { // Partitions Creation Set<String> keys = lookup.keySet(); int partitionId = 0; Multimap<Integer, String> partitions = ArrayListMultimap.create(); int counter2 = 0; for (String key : keys) { Set<Integer> keys2 = partitions.keySet(); List<String> inter = (List<String>) lookup.get(key); List<String> interTMP = new ArrayList<String>(inter); Printer.debugln("Step number: " + counter2++ + "Number of keywords " + keys.size()); Set<String> set = new HashSet<String>(interTMP); Multimap<Integer, String> partitionsTMP = ArrayListMultimap.create(); for (Integer key2 : keys2) { if (!set.isEmpty()) { Set<String> tmp = new HashSet<String>(partitions.get(key2)); Set<String> intersection = Sets.intersection(tmp, set); Set<String> difference; if (intersection.isEmpty()) { difference = tmp;//from w ww. j ava2 s . c o m } else { difference = Sets.difference(tmp, intersection); set = Sets.difference(set, intersection); } if (!difference.isEmpty()) { partitionId = partitionId + 1; partitionsTMP.putAll(partitionId, difference); } if (!intersection.isEmpty()) { partitionId = partitionId + 1; partitionsTMP.putAll(partitionId, intersection); } } else { partitionId = partitionId + 1; partitionsTMP.putAll(partitionId, new HashSet<String>(partitions.get(key2))); } } interTMP = new ArrayList<String>(set); if (!interTMP.isEmpty()) { partitionId = partitionId + 1; partitionsTMP.putAll(partitionId, interTMP); } partitions = ArrayListMultimap.create(partitionsTMP); partitionsTMP.clear(); interTMP.clear(); } Printer.debugln("Partitions size " + partitions.keySet().size()); Printer.debugln("\n"); return partitions; }
From source file:com.resultset.listmm.ResultSetToListMultiMap.java
/** * Converts ResultSet to ListMultiMap/* ww w .j a v a2s .c o m*/ * * @param resultSet * @return */ public ListMultimap<String, String> resultSetToListMultiMap(ResultSet resultSet) { ListMultimap<String, String> multimap = null; try { multimap = ArrayListMultimap.create(); ResultSetMetaData rsmd = resultSet.getMetaData(); int columnCount = rsmd.getColumnCount(); List<String> s1 = new ArrayList<String>(); for (int i = 1; i < columnCount + 1; i++) { s1.add(rsmd.getColumnName(i)); } while (resultSet.next()) { for (int i = 0; i < s1.size(); i++) { multimap.put(s1.get(i), resultSet.getString(s1.get(i))); } } } catch (Exception e) { e.printStackTrace(); } return multimap; }
From source file:prm4jeval.dataanalysis.TableParser1.java
public TableParser1(String filePath) { super(filePath); result = ArrayListMultimap.create(); parseFile(); }
From source file:com.cisco.oss.foundation.tools.simulator.rest.startup.SingleRestSimulatorStartup.java
public static void startServer() { try {// w w w .ja v a 2 s .c o m ListMultimap<String, Servlet> servlets = ArrayListMultimap.create(); ListMultimap<String, Filter> filters = ArrayListMultimap.create(); // Set the init params Map<String, String> initParams = new HashMap<String, String>(); initParams.put("com.sun.jersey.config.property.packages", "com.cisco.oss.foundation.tools"); // Create the servlet ResourceConfig resourceConfig = new ResourceConfig(); resourceConfig.packages("com.cisco.oss.foundation.tools"); ServletContainer resourceServlet = new ServletContainer(resourceConfig); servlets.put("/*", resourceServlet); XmlWebApplicationContext webConfig = new XmlWebApplicationContext(); webConfig.setConfigLocation("classpath:META-INF/restSimulatorContext.xml"); webConfig.registerShutdownHook(); List<EventListener> eventListeners = new ArrayList<EventListener>(); eventListeners.add(new ContextLoaderListener(webConfig)); eventListeners.add(new RequestContextListener()); JettyHttpServerFactory.INSTANCE.startHttpServer(SINGLE_REST_SIMULATOR, servlets, filters, eventListeners, initParams); // ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( // "META-INF/applicationContext.xml"); // server = (Server) applicationContext.getBean("restSimJettyServer"); // // server.start(); } catch (Exception ex) { logger.error("Error Starting REST Simulator" + ex); } }
From source file:com.github.jasonruckman.sidney.ext.guava.MultimapSerializer.java
public static void registerMaps(AbstractSid sid) { sid.addSerializer(Multimap.class, MultimapSerializer.class); sid.addInstanceFactory(ArrayListMultimap.class, new InstanceFactory<ArrayListMultimap>() { @Override//from w ww . j av a2 s .c om public ArrayListMultimap newInstance() { return ArrayListMultimap.create(); } }); sid.addInstanceFactory(LinkedListMultimap.class, new InstanceFactory<LinkedListMultimap>() { @Override public LinkedListMultimap newInstance() { return LinkedListMultimap.create(); } }); sid.addInstanceFactory(LinkedHashMultimap.class, new InstanceFactory<LinkedHashMultimap>() { @Override public LinkedHashMultimap newInstance() { return LinkedHashMultimap.create(); } }); sid.addInstanceFactory(TreeMultimap.class, new InstanceFactory<TreeMultimap>() { @Override public TreeMultimap newInstance() { return TreeMultimap.create(); } }); sid.addInstanceFactory(HashMultimap.class, new InstanceFactory<HashMultimap>() { @Override public HashMultimap newInstance() { return HashMultimap.create(); } }); }
From source file:gobblin.util.PublisherUtils.java
/** * Creates a {@link Multimap} that maps {@link Extract} to their corresponds {@link WorkUnitState}s. * * @see Multimap//from w w w . j a v a2s. c o m */ public static Multimap<Extract, WorkUnitState> createExtractToWorkUnitStateMap( Collection<? extends WorkUnitState> workUnitStates) { Multimap<Extract, WorkUnitState> extractToWorkUnitStateMap = ArrayListMultimap.create(); for (WorkUnitState workUnitState : workUnitStates) { extractToWorkUnitStateMap.put(workUnitState.getExtract(), workUnitState); } return extractToWorkUnitStateMap; }
From source file:sql.CreateTable.java
ListMultimap<String, String> Create(String... s) throws Exception { int i = 0, j = 0, k, m = 0; StringBuilder path = new StringBuilder("C:\\Users"); ListMultimap<String, String> map = ArrayListMultimap.create(); for (i = 3; s[i] != null; i += 2) { /*if (i == 3) {//from w ww . j ava 2s . c o m s[3] = s[3].substring(1, s[3].length()); }*/ if (s[i + 1].toLowerCase().contains("varchar") || s[i + 1].toLowerCase().contains("int")) { map.put("attribute", s[i] + "-" + s[i + 1]); map.put(s[i], null); } else { map.clear(); throw new Exception("SQL Syntax error! Unknown type..."); } //System.out.println("attribute: "+s[i]); } /* for (String value : myMultimap.values()) { System.out.println(value); }*/ //System.out.println(i); List<String> Values = map.get("attribute"); System.out.println(Values); return map; }
From source file:org.apache.beam.runners.core.InMemoryMultimapSideInputView.java
/** * Creates a {@link MultimapView} from the provided values. The provided {@link Coder} is used to * guarantee structural equality for keys instead of assuming Java object equality. *//*from w w w .j a va 2 s . co m*/ public static <K, V> MultimapView<K, V> fromIterable(Coder<K> keyCoder, Iterable<KV<K, V>> values) { // We specifically use an array list multimap to allow for: // * null keys // * null values // * duplicate values Multimap<Object, Object> multimap = ArrayListMultimap.create(); for (KV<K, V> value : values) { multimap.put(keyCoder.structuralValue(value.getKey()), value.getValue()); } return new InMemoryMultimapSideInputView(keyCoder, Multimaps.unmodifiableMultimap(multimap)); }
From source file:com.eincs.decanter.container.simple.route.SimpleRouteService.java
/** * /* ww w.ja va 2s . c o m*/ * @param serviceObj * @return * @throws RouteReflectException */ public static Multimap<SimpleRouteServiceId, SimpleRouteService> createServices(Object serviceObj) throws RouteReflectException { Multimap<SimpleRouteServiceId, SimpleRouteService> result = ArrayListMultimap.create(); FastClass clazz = FastClass.create(serviceObj.getClass()); // extract serviceId and method from serviceObj for (MethodRouteInfo methodInfo : MethodExtractor.extract(serviceObj)) { FastMethod method = clazz.getMethod(methodInfo.getMethod()); Class<?>[] parameters = method.getParameterTypes(); // check paramters of the method if (!ArrayUtils.isEquals(METHOD_PARAMTER, parameters)) { throw new RouteReflectException(String.format("method(%s) is not applicable for SimpleRouteService", Arrays.asList(parameters))); } // create service object and add to the result multimap SimpleRouteService service = new SimpleRouteService(serviceObj, method); List<SimpleRouteServiceId> serviceIds = SimpleRouteServiceId.create(methodInfo); for (SimpleRouteServiceId serviceId : serviceIds) { result.put(serviceId, service); } } return result; }