List of usage examples for com.google.common.collect Multimaps index
public static <K, V> ImmutableListMultimap<K, V> index(Iterator<V> values, Function<? super V, K> keyFunction)
From source file:uk.ac.ebi.atlas.model.baseline.ExperimentalFactors.java
public Multimap<FactorGroup, String> getAssayGroupIdsGroupedByNonDefaultFactors( Iterable<String> assayGroupIds) { Function<String, FactorGroup> groupByFunction = new Function<String, FactorGroup>() { @Nullable/*from www. ja v a 2 s . c o m*/ @Override public FactorGroup apply(@Nullable String assayGroupId) { return getNonDefaultFactors(assayGroupId); } }; return Multimaps.index(assayGroupIds, groupByFunction); }
From source file:eu.itesla_project.online.tools.RunImpactAnalysisOnStateTool.java
@Override public void run(CommandLine line) throws Exception { String workflowId = line.getOptionValue("workflow"); Integer stateId = Integer.valueOf(line.getOptionValue("state")); Set<String> contingencyIds = null; if (line.hasOption("contingencies")) { contingencyIds = Sets.newHashSet(line.getOptionValue("contingencies").split(",")); }//from www. j a va 2 s .c o m System.out.println("loading state " + stateId + " of workflow " + workflowId + " from the online db ..."); OnlineConfig config = OnlineConfig.load(); OnlineDb onlinedb = config.getOnlineDbFactoryClass().newInstance().create(); // load the network Network network = onlinedb.getState(workflowId, stateId); if (network != null) { ComputationManager computationManager = new LocalComputationManager(); ContingenciesAndActionsDatabaseClient contingencyDb = config.getContingencyDbClientFactoryClass() .newInstance().create(); SimulatorFactory simulatorFactory = config.getSimulatorFactoryClass().newInstance(); Stabilization stabilization = simulatorFactory.createStabilization(network, computationManager, 0); ImpactAnalysis impactAnalysis = simulatorFactory.createImpactAnalysis(network, computationManager, 0, contingencyDb); Map<String, Object> initContext = new HashMap<>(); SimulationParameters simulationParameters = SimulationParameters.load(); stabilization.init(simulationParameters, initContext); impactAnalysis.init(simulationParameters, initContext); System.out.println("running stabilization simulation..."); StabilizationResult sr = stabilization.run(); System.out.println("stabilization status: " + sr.getStatus()); if (sr.getStatus() == StabilizationStatus.COMPLETED) { System.out.println("running impact analysis..."); ImpactAnalysisResult iar = impactAnalysis.run(sr.getState(), contingencyIds); Table table = new Table(1 + SecurityIndexType.values().length, BorderStyle.CLASSIC_WIDE); table.addCell("Contingency"); for (SecurityIndexType securityIndexType : SecurityIndexType.values()) { table.addCell(securityIndexType.toString()); } Multimap<String, SecurityIndex> securityIndexesPerContingency = Multimaps .index(iar.getSecurityIndexes(), new Function<SecurityIndex, String>() { @Override public String apply(SecurityIndex securityIndex) { return securityIndex.getId().getContingencyId(); } }); for (Map.Entry<String, Collection<SecurityIndex>> entry : securityIndexesPerContingency.asMap() .entrySet()) { String contingencyId = entry.getKey(); table.addCell(contingencyId); Map<SecurityIndexType, Boolean> ok = new EnumMap<>(SecurityIndexType.class); for (SecurityIndex securityIndex : entry.getValue()) { ok.put(securityIndex.getId().getSecurityIndexType(), securityIndex.isOk()); } for (SecurityIndexType securityIndexType : SecurityIndexType.values()) { Boolean b = ok.get(securityIndexType); String str; if (b == null) { str = "NA"; } else { str = b ? "OK" : "NOK"; } table.addCell(str); } } System.out.println(table.render()); } else { System.out.println("Error running stabilization - metrics = " + sr.getMetrics()); } } else { System.out.println("no state " + stateId + " of workflow " + workflowId + " stored in the online db"); } onlinedb.close(); }
From source file:com.twitter.aurora.scheduler.storage.mem.MemTaskStore.java
private Multimap<IJobKey, String> taskIdsByJobKey(Iterable<Task> toIndex) { return Multimaps.transformValues( Multimaps.index(toIndex, Functions.compose(Tasks.SCHEDULED_TO_JOB_KEY, TO_SCHEDULED)), TO_ID); }
From source file:com.b2international.snowowl.snomed.api.impl.SnomedBrowserAxiomService.java
@Override public Collection<? extends ISnomedBrowserConcept> expandAxioms( final Collection<? extends ISnomedBrowserConcept> concepts, final String branchPath, final List<ExtendedLocale> locales) { final Set<String> conceptIds = concepts.stream().map(ISnomedBrowserConcept::getConceptId) .collect(Collectors.toSet()); final SnomedReferenceSetMembers axiomMembers = SnomedRequests.prepareSearchMember().all() .filterByRefSet(Sets.newHashSet(Concepts.REFSET_OWL_AXIOM)).filterByReferencedComponent(conceptIds) .build(SnomedDatastoreActivator.REPOSITORY_UUID, branchPath).execute(getBus()).getSync(); if (axiomMembers.getItems().isEmpty()) { return concepts; }// w w w. j a v a 2 s . c o m final AxiomRelationshipConversionService conversionService = getConversionService(branchPath); final Multimap<String, SnomedReferenceSetMember> membersByReferencedComponentId = Multimaps .index(axiomMembers, input -> input.getReferencedComponentId()); final Set<String> idsToFetch = newHashSet(); for (final ISnomedBrowserConcept concept : concepts) { final List<ISnomedBrowserAxiom> additionalAxioms = newArrayList(); final List<ISnomedBrowserAxiom> gciAxioms = newArrayList(); final Collection<SnomedReferenceSetMember> conceptAxiomMembers = membersByReferencedComponentId .get(concept.getId()); if (!CompareUtils.isEmpty(conceptAxiomMembers)) { try { for (final SnomedReferenceSetMember axiomMember : conceptAxiomMembers) { final String owlExpression = (String) axiomMember.getProperties() .get(SnomedRf2Headers.FIELD_OWL_EXPRESSION); final Long conceptId = Long.valueOf(concept.getId()); final AxiomRepresentation axiomRepresentation = conversionService .convertAxiomToRelationships(conceptId, owlExpression); if (axiomRepresentation != null) {// Will be null if the axiom is an Ontology Axiom for example a property chain or transitive axiom rather than an Additional Axiom or GCI. if (conceptId.equals(axiomRepresentation.getLeftHandSideNamedConcept())) { // Concept ID on the left means it's an additional axiom additionalAxioms .add(convertToBrowserAxiom(axiomMember, axiomRepresentation.isPrimitive(), axiomRepresentation.getRightHandSideRelationships())); } else if (conceptId.equals(axiomRepresentation.getRightHandSideNamedConcept())) { // Concept ID on the right means it's a GCI axiom gciAxioms.add(convertToBrowserAxiom(axiomMember, axiomRepresentation.isPrimitive(), axiomRepresentation.getLeftHandSideRelationships())); } } } } catch (ConversionException | NumberFormatException e) { LOGGER.error("Failed to deserialise concept axioms for conept {}.", concept.getId(), e); } } if (!additionalAxioms.isEmpty()) { ((SnomedBrowserConcept) concept).setAdditionalAxioms(additionalAxioms); additionalAxioms.stream().map(axiom -> axiom.getRelationships()).flatMap(List::stream) .forEach(relationship -> { idsToFetch.add(relationship.getType().getConceptId()); idsToFetch.add(relationship.getTarget().getConceptId()); }); } if (!gciAxioms.isEmpty()) { ((SnomedBrowserConcept) concept).setGciAxioms(gciAxioms); gciAxioms.stream().map(axiom -> axiom.getRelationships()).flatMap(List::stream) .forEach(relationship -> { idsToFetch.add(relationship.getType().getConceptId()); idsToFetch.add(relationship.getTarget().getConceptId()); }); } } if (!idsToFetch.isEmpty()) { final SnomedConcepts conceptsFromStore = SnomedRequests.prepareSearchConcept().all().setLocales(locales) .setExpand("fsn()").filterByIds(idsToFetch) .build(SnomedDatastoreActivator.REPOSITORY_UUID, branchPath).execute(getBus()).getSync(); final Map<String, SnomedConcept> idToConceptMap = conceptsFromStore.getItems().stream() .collect(Collectors.toMap(SnomedConcept::getId, concept -> concept)); for (final ISnomedBrowserConcept concept : concepts) { concept.getAdditionalAxioms().stream().map(axiom -> axiom.getRelationships()).flatMap(List::stream) .forEach(relationship -> updateRelationshipAttributes(relationship, idToConceptMap, branchPath)); concept.getGciAxioms().stream().map(axiom -> axiom.getRelationships()).flatMap(List::stream) .forEach(relationship -> updateRelationshipAttributes(relationship, idToConceptMap, branchPath)); } } return concepts; }
From source file:org.obm.push.calendar.ConsistencyEventChangesLogger.java
private ListMultimap<EventObmId, DeletedEvent> buildDeletionsMultimap(EventChanges changes) { return Multimaps.index(changes.getDeletedEvents(), new Function<DeletedEvent, EventObmId>() { @Override// w w w. j av a 2 s . c om public EventObmId apply(DeletedEvent input) { return input.getId(); } }); }
From source file:org.mskcc.shenkers.control.track.gene.GTFGeneModelProvider.java
private void createGtfBgz(File gtf_file, File gtf_bgz_file) throws IOException { logger.info("reading {}", gtf_file.getAbsolutePath()); AbstractFeatureReader<GTFContext, LineIterator> afr = AbstractFeatureReader .getFeatureReader(gtf_file.getAbsolutePath(), codec, false); CloseableTribbleIterator<GTFContext> iterator = afr.iterator(); List<GTFContext> gtf = new ArrayList<>(); while (iterator.hasNext()) { GTFContext next = iterator.next(); gtf.add(next);/*from w w w . java 2 s.c o m*/ } ImmutableListMultimap<String, GTFContext> transcript_id_multimap = Multimaps.index(gtf.iterator(), GTFContext::getTranscriptId); logger.info("adding transcript ranges"); gtf.addAll(transcript_id_multimap.keySet().stream().map(key -> { System.out.println(key); ImmutableList<GTFContext> contexts = transcript_id_multimap.get(key); Range<Integer> span = contexts.stream().map(c -> Range.closed(c.getStart(), c.getEnd())) .collect(new RangeSetCollector()).span(); GTFContext context = new GTFContext(contexts.get(0).getChr(), span.lowerEndpoint(), span.upperEndpoint()); context.setFeature("transcript"); context.setFrame("."); context.setName("."); context.setScore("."); context.setSource("."); context.setStrand('.'); context.setAttributes(String.format("transcript_id \"%s\";", key)); return context; }).collect(Collectors.toList())); logger.info("sorting"); Collections.sort(gtf, new CoordinateOrderComparator()); logger.info("writing to compressed output stream"); BlockCompressedOutputStream os = new BlockCompressedOutputStream(gtf_bgz_file); Writer w = new OutputStreamWriter(os); for (GTFContext feature : gtf) { w.write(codec.encodeToString(feature)); } w.close(); }
From source file:com.yodle.vantage.component.dao.IssueDao.java
public Map<String, Collection<Issue>> getIssuesTransitivelyAffectingVersions(String component) { List<Map<String, Object>> rs = jdbcTemplate.queryForList("MATCH (c_par:Component {name:{1}})" + "<-[:VERSION_OF]-(v_par:Version)" + "-[:DEPENDS_ON]->(v:Version)" + "<-[:PRECEDES|:AFFECTS*]-(i:Issue)" + "MATCH (v)-[:VERSION_OF]->(c:Component)" + "MATCH (i)-[:AFFECTS]->(av:Version)" + "WHERE NOT (v)<-[:PRECEDES|:FIXED_BY*]-(i) " + "OPTIONAL MATCH (i)-[:FIXED_BY]->(fv:Version)" + "RETURN v_par.version, i.id, i.level, i.message, av.version, fv.version, c.name, v.version", component);/*www. ja v a 2 s . c o m*/ ImmutableListMultimap<String, Map<String, Object>> grouped = Multimaps.index(rs, (row -> (String) row.get("v_par.version"))); return Multimaps.transformValues(grouped, (this::toIssue)).asMap(); }
From source file:com.todoroo.astrid.service.StartupService.java
private void removeDuplicateTagMetadata(String uuid) { Criterion fullCriterion = Criterion.and(Metadata.KEY.eq(TaskToTagMetadata.KEY), TaskToTagMetadata.TAG_UUID.eq(uuid), Metadata.DELETION_DATE.eq(0)); List<Metadata> metadatas = metadataDao.toList(fullCriterion); ImmutableListMultimap<Long, Metadata> metadataByTask = Multimaps.index(metadatas, Metadata::getTask); for (Long key : metadataByTask.keySet()) { ImmutableList<Metadata> tagData = metadataByTask.get(key); for (int i = 1; i < tagData.size(); i++) { metadataDao.delete(tagData.get(i).getId()); }//from w w w . j a v a 2s . com } }
From source file:de.adrodoc55.minecraft.mpl.compilation.MplCompiler.java
public static MplProgram assembleProgram(File programFile) throws IOException, CompilationFailedException { MplCompiler compiler = new MplCompiler(); MplProgram program = compiler.assemble(programFile); List<CompilerException> exceptions = program.getExceptions(); if (!exceptions.isEmpty()) { ImmutableListMultimap<File, CompilerException> index = Multimaps.index(exceptions, ex -> ex.getSource().file); throw new CompilationFailedException(index); }/* ww w.ja v a 2 s.c om*/ return program; }
From source file:org.obiba.opal.web.gwt.app.client.magma.view.SummaryTabView.java
private void renderContinuousSummary(SummaryStatisticsDto dto) { ContinuousSummaryDto continuous = dto .getExtension(ContinuousSummaryDto.SummaryStatisticsDtoExtensions.continuous).cast(); final double[] totals = { 0d, 0d }; ImmutableListMultimap<Boolean, FrequencyDto> frequenciesByMissing = Multimaps.index( JsArrays.toIterable(continuous.getFrequenciesArray()), new Function<FrequencyDto, Boolean>() { @Nullable/*w ww . ja v a 2 s. c o m*/ @Override public Boolean apply(@Nullable FrequencyDto input) { // when boolean, is missing is not set if (input != null && !input.getMissing()) { totals[0] += input.getFreq(); return false; } totals[1] += input == null ? 0 : input.getFreq(); return true; } }); summary.add(new ContinuousSummaryView(continuous, frequenciesByMissing.get(false), frequenciesByMissing.get(true), totals[0], totals[1])); }