List of usage examples for com.google.common.collect ArrayListMultimap create
public static <K, V> ArrayListMultimap<K, V> create()
From source file:ch.ethz.bsse.quasirecomb.model.Preprocessing.java
/** * Entry point. Forwards invokes of the specified workflow. * * @param input path to the fasta file//from w w w. j a v a2 s.com * @param Kmin minimal amount of generators * @param Kmax minimal amount of generators */ public static void workflow(String input, int Kmin, int Kmax) { Utils.mkdir(Globals.getINSTANCE().getSAVEPATH() + "support"); //parse file StatusUpdate.getINSTANCE().print("Parsing"); Read[] reads = Utils.parseInput(input); int L = fixAlignment(reads); if (L > 300 && Globals.getINSTANCE().getINTERPOLATE_MU() > 0) { Globals.getINSTANCE().setINTERPOLATE_MU(.5); } int[][] alignment = computeAlignment(reads, L); StatusUpdate.getINSTANCE().println("Paired reads\t" + Globals.getINSTANCE().getPAIRED_COUNT()); computeInsertDist(reads); StatusUpdate.getINSTANCE().println("Merged reads\t" + Globals.getINSTANCE().getMERGED() + "\n"); printAlignment(reads); circos(L, alignment); if (Globals.getINSTANCE().isDEBUG()) { new File(Globals.getINSTANCE().getSAVEPATH() + "support/log/").mkdirs(); } int n = countChars(reads); Globals.getINSTANCE().setTAU_OMEGA(reads, L); int N = 0; for (Read r : reads) { if (r.getWatsonLength() > 0) { N += r.getCount(); } } plot(); if (Globals.getINSTANCE().isBOOTSTRAP()) { String[] truth = FastaParser.parseFarFile(Globals.getINSTANCE().getPRIOR()); Multimap<Integer, Double> bics = ArrayListMultimap.create(); List<Read> readList = Lists.newArrayListWithExpectedSize(N); int x = 0; for (Read r : reads) { int count = r.getCount(); for (int i = 0; i < count; i++) { readList.add(new Read(r)); } // r.setCount(1); } // for (Read r : reads) { // Utils.appendFile(Globals.getINSTANCE().getSAVEPATH() + "pi_bootstrap_original.txt", + r.getCount() + "\n"); // } Read[] readArray = readList.toArray(new Read[readList.size()]); for (int i = 0; i < 100; i++) { StatusUpdate.getINSTANCE().println("Bootstrap " + i + "\n"); Map<Integer, Read> hashed = new HashMap<>(); Random rnd = new Random(); for (int y = 0; y < N; y++) { Read r = readArray[rnd.nextInt(N)]; int hash = r.hashCode(); if (hashed.containsKey(hash)) { hashed.get(hash).incCount(); } else { hashed.put(r.hashCode(), r); } } // for (Read r : reads) { // Utils.appendFile(Globals.getINSTANCE().getSAVEPATH() + "pi_bootstrap_" + i + ".txt", (hashed.get(r.hashCode()) == null ? 0 : hashed.get(r.hashCode()).getCount()) + "\n"); // } Read[] rs = hashed.values().toArray(new Read[hashed.size()]); ModelSelection ms = new ModelSelection(rs, Kmin, Kmax, L, n); OptimalResult or = ms.getOptimalResult(); double[] pi = new double[or.getPi()[0].length]; double piSum = 0; for (int j = 0; j < or.getPi().length; j++) { for (int k = 0; k < or.getPi()[j].length; k++) { pi[k] += or.getPi()[j][k]; piSum += or.getPi()[j][k]; } } StringBuilder piSB = new StringBuilder(); piSB.append(pi[0] / piSum); for (int k = 1; k < pi.length; k++) { piSB.append("\t"); piSB.append(pi[k] / piSum); } new File(Globals.getINSTANCE().getSAVEPATH() + i).mkdirs(); ModelSampling modelSampling = new ModelSampling(or, Globals.getINSTANCE().getSAVEPATH() + i + File.separator); modelSampling.save(); Map<String, Double> quasispecies = FastaParser.parseQuasispeciesFile( Globals.getINSTANCE().getSAVEPATH() + i + File.separator + "quasispecies.fasta"); double[] frequencies = new double[truth.length]; for (Map.Entry<String, Double> e : quasispecies.entrySet()) { int distance = Integer.MAX_VALUE; int index = -1; for (int t = 0; t < truth.length; t++) { int hamming = DistanceUtils.calcHamming(e.getKey(), truth[t]); if (hamming < distance) { index = t; distance = hamming; } } frequencies[index] += e.getValue(); } StringBuilder fSB = new StringBuilder(); fSB.append(frequencies[0]); for (int f = 1; f < frequencies.length; f++) { fSB.append("\t"); fSB.append(frequencies[f]); } Utils.appendFile(Globals.getINSTANCE().getSAVEPATH() + "bootstrap.txt", fSB.toString() + "\n"); Utils.appendFile(Globals.getINSTANCE().getSAVEPATH() + "pi_bootstrap.txt", piSB.toString() + "\n"); bics.putAll(ms.getMsTemp().getMaxBICs()); } System.exit(0); StringBuilder sb = new StringBuilder(); int bootstraps = bics.asMap().values().iterator().next().size(); Set<Integer> keySet = bics.keySet(); for (int i : keySet) { sb.append(i).append("\t"); } sb.setLength(sb.length() - 1); sb.append("\n"); for (int l = 0; l < bootstraps; l++) { for (int i : keySet) { ArrayList arrayList = new ArrayList(bics.get(i)); if (l < arrayList.size()) { sb.append(arrayList.get(l)); } sb.append("\t"); } sb.setLength(sb.length() - 1); sb.append("\n"); } Utils.saveFile(Globals.getINSTANCE().getSAVEPATH() + "support" + File.separator + "bics.txt", sb.toString()); StatusUpdate.getINSTANCE().println(""); ModelSelectionBootstrapStorage msbt = new ModelSelectionBootstrapStorage(bics); Kmin = msbt.getBestK(); Kmax = Kmin; Globals.getINSTANCE().setBOOTSTRAP(false); } ModelSelection ms = null; // if (Globals.getINSTANCE().isSUBSAMPLE()) { // shuffleArray(reads); // List<Read> subsample = new LinkedList<>(); // Map<String, Integer> generators = new HashMap<>(); // Globals.getINSTANCE().setDESIRED_REPEATS(0); // for (int i = 0; i < reads.length; i++) { // if (subsample.size() < reads.length / 10 || i + reads.length / 10 > reads.length) { // subsample.add(reads[i]); // } else { // Read[] readsSubsample = subsample.toArray(new Read[subsample.size()]); // ModelSelection msSubsample = new ModelSelection(readsSubsample, Kmin, Kmax, L, n); // subsample.clear(); // saveSubSample(msSubsample.getOptimalResult().getMu(), generators, L); // } // } // for (Map.Entry<String, Integer> e : generators.entrySet()) { // System.out.println(e.getValue() + "\t" + e.getKey()); // } // } else { ms = new ModelSelection(reads, Kmin, Kmax, L, n); if (!Globals.getINSTANCE().isNOSAMPLE()) { ModelSampling modelSampling = new ModelSampling(ms.getOptimalResult(), Globals.getINSTANCE().getSAVEPATH()); modelSampling.save(); System.out .println("\nQuasispecies saved: " + Globals.getINSTANCE().getSAVEPATH() + "quasispecies.fasta"); } if (!Globals.getINSTANCE().isDEBUG()) { deleteDirectory( new File(Globals.getINSTANCE().getSAVEPATH() + "support" + File.separator + "snapshots")); } // } // errorCorrection(ms, reads); }
From source file:com.google.template.soy.passes.CheckTemplateHeaderVarsPass.java
private void checkTemplate(TemplateNode node, TemplateRegistry templateRegistry) { if (node.isDeprecatedV1()) { return;/*from ww w. j av a 2s . c o m*/ } ListMultimap<String, SourceLocation> dataKeys = ArrayListMultimap.create(); for (VarRefNode varRefNode : SoyTreeUtils.getAllNodesOfType(node, VarRefNode.class)) { if (varRefNode.isPossibleHeaderVar()) { dataKeys.put(varRefNode.getName(), varRefNode.getSourceLocation()); } } IndirectParamsInfo ipi = new FindIndirectParamsVisitor(templateRegistry).exec(node); Set<String> allHeaderVarNames = new HashSet<>(); List<TemplateHeaderVarDefn> unusedParams = new ArrayList<>(); // Process @param header variables. for (TemplateParam param : node.getAllParams()) { allHeaderVarNames.add(param.name()); if (dataKeys.containsKey(param.name())) { // Good: Declared and referenced in template. We remove these from dataKeys so // that at the end of the for-loop, dataKeys will only contain the keys that are referenced // but not declared in SoyDoc. dataKeys.removeAll(param.name()); } else if (ipi.paramKeyToCalleesMultimap.containsKey(param.name()) || ipi.mayHaveIndirectParamsInExternalCalls || ipi.mayHaveIndirectParamsInExternalDelCalls) { // Good: Declared in SoyDoc and either (a) used in a call that passes all data or (b) used // in an external call or delcall that passes all data, which may need the param (we can't // verify). } else { // Bad: Declared in SoyDoc but not referenced in template. unusedParams.add(param); } } // Process @state header variables. List<TemplateHeaderVarDefn> unusedStateVars = new ArrayList<>(); for (TemplateStateVar stateVar : node.getStateVars()) { allHeaderVarNames.add(stateVar.name()); if (dataKeys.containsKey(stateVar.name())) { // Good: declared and referenced in the template. dataKeys.removeAll(stateVar.name()); } else { // Bad: declared in the header, but not used. unusedStateVars.add(stateVar); } } // At this point, the only keys left in dataKeys are undeclared. for (Entry<String, SourceLocation> undeclared : dataKeys.entries()) { String extraErrorMessage = SoyErrors.getDidYouMeanMessage(allHeaderVarNames, undeclared.getKey()); errorReporter.report(undeclared.getValue(), UNDECLARED_DATA_KEY, undeclared.getKey(), extraErrorMessage); } // Delegate templates can declare unused params because other implementations // of the same delegate may need to use those params. if (node instanceof TemplateBasicNode) { reportUnusedHeaderVars(errorReporter, unusedParams, UNUSED_PARAM); reportUnusedHeaderVars(errorReporter, unusedStateVars, UNUSED_STATE); } }
From source file:com.google.devtools.build.lib.analysis.constraints.TopLevelConstraintSemantics.java
/** * Checks that if this is an environment-restricted build, all top-level targets support expected * top-level environments. Expected top-level environments can be declared explicitly through * {@code --target_environment} or implicitly through {@code --auto_cpu_environment_group}. For * the latter, top-level targets must be compatible with the build's target configuration CPU. * * <p>If any target doesn't support an explicitly expected environment declared through {@link * BuildConfiguration.Options#targetEnvironments}, the entire build fails with an error. * * <p>If any target doesn't support an implicitly expected environment declared through {@link * BuildConfiguration.Options#autoCpuEnvironmentGroup}, the target is skipped during execution * while remaining targets execute as normal. * * @param topLevelTargets the build's top-level targets * @param packageManager object for retrieving loaded targets * @param eventHandler the build's event handler * @return the set of bad top-level targets. * @throws ViewCreationFailedException if any target doesn't support an explicitly expected * environment declared through {@link BuildConfiguration.Options#targetEnvironments} */// w w w . j a v a 2 s . c o m public static Set<ConfiguredTarget> checkTargetEnvironmentRestrictions( Iterable<ConfiguredTarget> topLevelTargets, PackageManager packageManager, ExtendedEventHandler eventHandler) throws ViewCreationFailedException, InterruptedException { ImmutableSet.Builder<ConfiguredTarget> badTargets = ImmutableSet.builder(); // Maps targets that are missing *explicitly* required environments to the set of environments // they're missing. These targets trigger a ViewCreationFailedException, which halts the build. // Targets with missing *implicitly* required environments don't belong here, since the build // continues while skipping them. Multimap<ConfiguredTarget, Label> exceptionInducingTargets = ArrayListMultimap.create(); for (ConfiguredTarget topLevelTarget : topLevelTargets) { BuildConfiguration config = topLevelTarget.getConfiguration(); boolean failBuildIfTargetIsBad = true; if (config == null) { // TODO(bazel-team): support file targets (they should apply package-default constraints). continue; } else if (!config.enforceConstraints()) { continue; } List<Label> targetEnvironments = config.getTargetEnvironments(); if (targetEnvironments.isEmpty()) { try { targetEnvironments = autoConfigureTargetEnvironments(config, config.getAutoCpuEnvironmentGroup(), packageManager, eventHandler); failBuildIfTargetIsBad = false; } catch (NoSuchPackageException | NoSuchTargetException | ConstraintSemantics.EnvironmentLookupException e) { throw new ViewCreationFailedException("invalid target environment", e); } } if (targetEnvironments.isEmpty()) { continue; } // Parse and collect this configuration's environments. EnvironmentCollection.Builder builder = new EnvironmentCollection.Builder(); for (Label envLabel : targetEnvironments) { try { Target env = packageManager.getTarget(eventHandler, envLabel); builder.put(ConstraintSemantics.getEnvironmentGroup(env), envLabel); } catch (NoSuchPackageException | NoSuchTargetException | ConstraintSemantics.EnvironmentLookupException e) { throw new ViewCreationFailedException("invalid target environment", e); } } EnvironmentCollection expectedEnvironments = builder.build(); // Now check the target against those environments. TransitiveInfoCollection asProvider; if (topLevelTarget instanceof OutputFileConfiguredTarget) { asProvider = ((OutputFileConfiguredTarget) topLevelTarget).getGeneratingRule(); } else { asProvider = topLevelTarget; } SupportedEnvironmentsProvider provider = Verify .verifyNotNull(asProvider.getProvider(SupportedEnvironmentsProvider.class)); Collection<Label> missingEnvironments = ConstraintSemantics .getUnsupportedEnvironments(provider.getRefinedEnvironments(), expectedEnvironments); if (!missingEnvironments.isEmpty()) { badTargets.add(topLevelTarget); if (failBuildIfTargetIsBad) { exceptionInducingTargets.putAll(topLevelTarget, missingEnvironments); } } } if (!exceptionInducingTargets.isEmpty()) { throw new ViewCreationFailedException(getBadTargetsUserMessage(exceptionInducingTargets)); } return ImmutableSet.copyOf(badTargets.build()); }
From source file:org.apache.cassandra.tools.SSTableExpiredBlockers.java
public static Multimap<SSTableReader, SSTableReader> checkForExpiredSSTableBlockers( Iterable<SSTableReader> sstables, int gcBefore) { Multimap<SSTableReader, SSTableReader> blockers = ArrayListMultimap.create(); for (SSTableReader sstable : sstables) { if (sstable.getSSTableMetadata().maxLocalDeletionTime < gcBefore) { for (SSTableReader potentialBlocker : sstables) { if (!potentialBlocker.equals(sstable) && potentialBlocker.getMinTimestamp() <= sstable.getMaxTimestamp() && potentialBlocker.getSSTableMetadata().maxLocalDeletionTime > gcBefore) blockers.put(potentialBlocker, sstable); }//w w w . j a va 2 s .c o m } } return blockers; }
From source file:org.codice.ddf.transformer.xml.streaming.lib.SaxEventToXmlElementConverter.java
private SaxEventToXmlElementConverter startConstructingElement(String uri, String localName, Attributes atts) throws XMLStreamException { Multimap<String, String> addedNamespaces = ArrayListMultimap.create(); if (scopeOfNamespacesAdded.peek() != null) { addedNamespaces.putAll(scopeOfNamespacesAdded.peek()); }//from w ww . ja va 2 s .co m scopeOfNamespacesAdded.push(addedNamespaces); // URI to prefix Map<String, String> scopedNamespaces = new HashMap<>(); Iterator<NamespaceMapping> iter = namespaceStack.descendingIterator(); while (iter.hasNext()) { NamespaceMapping tmpPair = iter.next(); // switch prefix and URI scopedNamespaces.put(tmpPair.getUri(), tmpPair.getPrefix()); } /* * Use the uri to look up the namespace prefix and append it and the localName to the start tag */ out.writeStartElement(scopedNamespaces.get(uri), localName, uri); if (!checkNamespaceAdded(uri, scopedNamespaces)) { out.writeNamespace(scopedNamespaces.get(uri), uri); addedNamespaces.put(uri, scopedNamespaces.get(uri)); } /* * Loop through the attributes and append them, prefixed with the proper namespace * We loop through the attributes twice to ensure all "xmlns" attributes are declared before * other attributes */ for (int i = 0; i < atts.getLength(); i++) { if (atts.getURI(i).isEmpty()) { out.writeAttribute(atts.getLocalName(i), atts.getValue(i)); } else { String attUri = atts.getURI(i); if (!checkNamespaceAdded(attUri, scopedNamespaces)) { out.writeNamespace(scopedNamespaces.get(attUri), attUri); addedNamespaces.put(attUri, scopedNamespaces.get(attUri)); } try { out.writeAttribute(scopedNamespaces.get(attUri), attUri, atts.getLocalName(i), atts.getValue(i)); /* * XML doesn't allow for duplicate attributes in an element, e.g. * no <element attribute=1 attribute=2> * no <element ns1:attribute=1 ns2:attribute=2 xlmns:ns1=foobar xlmns:ns2=foobar> * however - if one of the namespaces is the default namespace, this duplication is okay, * yes <element attribute=1 ns1:attribute=2 xlmns=foobar xmlns:ns1=foobar> * * This catch block handles this edge case */ } catch (XMLStreamException e) { /* * Get the first non-empty prefix that is associated with the URI (the other, non-default prefix) */ handleNamespaceDupes(atts, addedNamespaces, i, attUri); } } } return this; }
From source file:org.sonar.server.qualityprofile.ESActiveRule.java
public void bulkRegisterActiveRules() { SqlSession session = myBatis.openSession(); try {/* w w w . ja v a 2 s .com*/ StopWatch bulkWatch = startWatch(); List<ActiveRuleDto> activeRules = activeRuleDao.selectAll(session); List<ActiveRuleParamDto> activeRuleParams = activeRuleDao.selectAllParams(session); bulkWatch.stop(String.format("Loaded %d active rules from DB", activeRules.size())); Multimap<Integer, ActiveRuleParamDto> paramsByActiveRule = ArrayListMultimap.create(); for (ActiveRuleParamDto param : activeRuleParams) { paramsByActiveRule.put(param.getActiveRuleId(), param); } String[] ids = bulkIndexActiveRules(activeRules, paramsByActiveRule); removeDeletedActiveRules(ids); } finally { MyBatis.closeQuietly(session); } }
From source file:org.sosy_lab.cpachecker.util.StaticRefiner.java
/** * This method finds in a backwards search, starting from the target locations in the * CFA, the list of n assume edges preceeding each target node, where n equals the * maxBackscanPathAssumes option.//w w w . j a v a 2 s . c o m * * @return the mapping from target nodes to the corresponding preceeding assume edges */ protected ListMultimap<CFANode, AssumeEdge> getTargetLocationAssumes(Collection<CFANode> targetNodes) { ListMultimap<CFANode, AssumeEdge> result = ArrayListMultimap.create(); if (targetNodes.isEmpty()) { return result; } // backwards search to determine all relevant edges for (CFANode targetNode : targetNodes) { Deque<Pair<CFANode, Integer>> queue = new ArrayDeque<>(); queue.add(Pair.of(targetNode, 0)); Set<CFANode> explored = new HashSet<>(); while (!queue.isEmpty()) { // Take the next node that should be explored from the queue Pair<CFANode, Integer> v = queue.pop(); // Each node that enters node v for (CFAEdge e : CFAUtils.enteringEdges(v.getFirst())) { CFANode u = e.getPredecessor(); boolean isAssumeEdge = (e instanceof AssumeEdge); int depthIncrease = isAssumeEdge ? 1 : 0; if (isAssumeEdge) { AssumeEdge assume = (AssumeEdge) e; if (v.getSecond() < maxBackscanPathAssumes) { result.put(targetNode, assume); } else { continue; } } if (!explored.contains(u)) { queue.add(Pair.of(u, v.getSecond() + depthIncrease)); } } explored.add(v.getFirst()); } } return result; }
From source file:uk.ac.ebi.apps.benchmark.ChemicalNameSearch.java
public void testMultiple() { System.out.println("Testing multiple"); Map<Class, NameService> services = new LinkedHashMap<Class, NameService>(); StringBuilder sb = new StringBuilder("Combined: "); for (String serviceName : getCommandLine().getOptionValues("service")) { sb.append(serviceName).append(", "); NameService service = getNameService(serviceName); service.startup();/*from ww w .ja v a2 s . c o m*/ services.put(service.getIdentifier().getClass(), service); } boolean greedy = has("g"); Multimap<String, Identifier> results = ArrayListMultimap.create(); long searchStart = System.currentTimeMillis(); for (String name : names) { boolean foundHit = false; for (NameService service : services.values()) { Collection hits = service.searchName(name, has("a")); results.putAll(name, hits); if (!hits.isEmpty()) { if (!foundHit) { found++; foundHit = true; } if (!greedy) break; } } } long searchEnd = System.currentTimeMillis(); Long searchTime = (searchEnd - searchStart); Multimap<String, Set<String>> nameResults = ArrayListMultimap.create(); long resolveStart = System.currentTimeMillis(); for (Map.Entry<String, Identifier> e : results.entries()) { Identifier id = e.getValue(); nameResults.put(e.getKey(), new HashSet<String>(services.get(id.getClass()).getNames(id))); } long resolveEnd = System.currentTimeMillis(); Long resolveTime = resolveEnd - resolveStart; int trueFound = getRealScore(nameResults, new ChemicalFingerprintEncoder(), null); SummaryStatistics statistics = getHitIndices(nameResults, new ChemicalFingerprintEncoder()); String[] row = new String[] { sb.toString(), searchTime.toString(), resolveTime.toString(), Integer.toString(found), Integer.toString(trueFound), Double.toString(statistics.getMax()), Double.toString(statistics.getMean()), Double.toString(statistics.getStandardDeviation()) }; System.out.println(Joiner.on("\t").join(row)); }
From source file:ezbake.ezpurge.ServicePurgeClient.java
/** * retrieves a map of services to applications * @return Multimap containing the Applications as keys and a list of services as the value * @throws Exception for any zookeeper errors */// w w w . j ava 2s . c o m public Multimap<String, String> getPurgeServices() throws Exception { Multimap<String, String> purgeServices = ArrayListMultimap.create(); List<String> applications = zkClient.getChildren().forPath(""); for (String app : applications) { String path = ServiceDiscoveryClient.makeZKPath(app); List<String> services = zkClient.getChildren().forPath(path); purgeServices.putAll(app, services); } return purgeServices; }