Java Code Examples for org.apache.commons.lang3.tuple.ImmutablePair#of()
The following examples show how to use
org.apache.commons.lang3.tuple.ImmutablePair#of() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CoverageModelEMWorkspace.java From gatk-protected with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Fetches the maximum likelihood estimate of copy ratios and their precisions from compute blocks. * The result is output as a pair of target-by-sample matrices. * * @param logScale if true, the max likelihood estimate is reported in natural log scale * @return a pair of {@link INDArray} */ private ImmutablePair<INDArray, INDArray> fetchCopyRatioMaxLikelihoodEstimateData(final boolean logScale) { final INDArray M_Psi_inv_st = fetchFromWorkers(CoverageModelEMComputeBlock.CoverageModelICGCacheNode.M_Psi_inv_st, 1); final INDArray log_n_st = fetchFromWorkers(CoverageModelEMComputeBlock.CoverageModelICGCacheNode.log_n_st, 1); final INDArray m_t = fetchFromWorkers(CoverageModelEMComputeBlock.CoverageModelICGCacheNode.m_t, 1); /* calculate the required quantities */ final INDArray copyRatioMaxLikelihoodEstimate; if (biasCovariatesEnabled) { final INDArray Wz_st = fetchFromWorkers(CoverageModelEMComputeBlock.CoverageModelICGCacheNode.Wz_st, 1); copyRatioMaxLikelihoodEstimate = log_n_st.sub(Wz_st).subiRowVector(m_t).subiColumnVector(sampleMeanLogReadDepths); } else { copyRatioMaxLikelihoodEstimate = log_n_st.subRowVector(m_t).subiColumnVector(sampleMeanLogReadDepths); } if (!logScale) { Transforms.exp(copyRatioMaxLikelihoodEstimate, false); } return ImmutablePair.of(copyRatioMaxLikelihoodEstimate.transpose(), M_Psi_inv_st.transpose()); }
Example 2
Source File: RandomValueGenerator.java From fredbet with Creative Commons Attribution Share Alike 4.0 International | 6 votes |
public ImmutablePair<Country, Country> generateTeamPair() { List<Country> availCountries = countryService.getAllCountriesWithoutNoneEntry(); if (CollectionUtils.isEmpty(availCountries)) { return null; } Country countryOne = generateRandomCountry(availCountries); availCountries.remove(countryOne); if (CollectionUtils.isEmpty(availCountries)) { return ImmutablePair.of(countryOne, countryOne); } Country countryTwo = generateRandomCountry(availCountries); availCountries.remove(countryTwo); return ImmutablePair.of(countryOne, countryTwo); }
Example 3
Source File: TargetCoverageSexGenotypeCalculator.java From gatk-protected with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Processes raw read counts and targets: * <dl> * <dt> If more than one sample is present in the collection, filters out fully uncovered targets * from read counts and removes the uncovered targets from the target list</dt> * * <dt> Otherwise, does nothing and warns the user * </dt> * </dl> * * @param rawReadCounts raw read count collection * @param targetList user provided target list * @return pair of processed read counts and targets */ private ImmutablePair<ReadCountCollection, List<Target>> processReadCountsAndTargets( @Nonnull final ReadCountCollection rawReadCounts, @Nonnull final List<Target> targetList) { final ReadCountCollection finalReadCounts; final List<Target> finalTargetList; /* remove totally uncovered targets */ if (rawReadCounts.columnNames().size() > 1) { finalReadCounts = ReadCountCollectionUtils.removeTotallyUncoveredTargets(rawReadCounts, logger); final Set<Target> targetSetFromProcessedReadCounts = new HashSet<>(finalReadCounts.targets()); finalTargetList = targetList.stream() .filter(targetSetFromProcessedReadCounts::contains) .collect(Collectors.toList()); } else { final long numUncoveredTargets = rawReadCounts.records().stream() .filter(rec -> (int)rec.getDouble(0) == 0).count(); final long numAllTargets = rawReadCounts.targets().size(); logger.info("Since only one sample is given for genotyping, the user is responsible for asserting" + " the aptitude of targets. Fully uncovered (irrelevant) targets can not be automatically" + " identified (total targets: " + numAllTargets + ", uncovered targets: " + numUncoveredTargets + ")"); finalReadCounts = rawReadCounts; finalTargetList = targetList; } return ImmutablePair.of(finalReadCounts, finalTargetList); }
Example 4
Source File: SchedulerManager.java From pulsar with Apache License 2.0 | 6 votes |
private Pair<List<Function.Instance>, List<Assignment>> getUnassignedFunctionInstances( Map<String, Map<String, Assignment>> currentAssignments, Map<String, Function.Instance> functionInstances) { List<Function.Instance> unassignedFunctionInstances = new LinkedList<>(); List<Assignment> heartBeatAssignments = Lists.newArrayList(); Map<String, Assignment> assignmentMap = new HashMap<>(); for (Map<String, Assignment> entry : currentAssignments.values()) { assignmentMap.putAll(entry); } for (Map.Entry<String, Function.Instance> instanceEntry : functionInstances.entrySet()) { String fullyQualifiedInstanceId = instanceEntry.getKey(); Function.Instance instance = instanceEntry.getValue(); String heartBeatWorkerId = checkHeartBeatFunction(instance); if (heartBeatWorkerId != null) { heartBeatAssignments .add(Assignment.newBuilder().setInstance(instance).setWorkerId(heartBeatWorkerId).build()); continue; } if (!assignmentMap.containsKey(fullyQualifiedInstanceId)) { unassignedFunctionInstances.add(instance); } } return ImmutablePair.of(unassignedFunctionInstances, heartBeatAssignments); }
Example 5
Source File: GeoWaveInputKey.java From geowave with Apache License 2.0 | 6 votes |
public Pair<byte[], byte[]> getPartitionAndSortKey(final Index index) { final int partitionKeyLength = index.getIndexStrategy().getPartitionKeyLength(); final int indexIdLength = StringUtils.stringToBinary(index.getName()).length; if (dataId.getBytes().length < (indexIdLength + partitionKeyLength)) { return null; } else { final byte[] partitionKey = Arrays.copyOfRange(dataId.getBytes(), indexIdLength, indexIdLength + partitionKeyLength); final byte[] sortKey = Arrays.copyOfRange( dataId.getBytes(), indexIdLength + partitionKeyLength, dataId.getBytes().length); return ImmutablePair.of(partitionKey, sortKey); } }
Example 6
Source File: MNVDetector.java From hmftools with GNU General Public License v3.0 | 5 votes |
@VisibleForTesting static Pair<PotentialMNVRegion, Optional<PotentialMNVRegion>> addMnvToRegion(@NotNull final PotentialMNVRegion potentialMnvRegion, @NotNull final VariantContext variant, final int gapSize) { if (variantFitsRegion(potentialMnvRegion, variant, gapSize)) { return ImmutablePair.of(PotentialMNVRegion.addVariant(potentialMnvRegion, variant, gapSize), Optional.empty()); } else { return ImmutablePair.of(PotentialMNVRegion.fromVariant(variant), Optional.of(potentialMnvRegion)); } }
Example 7
Source File: ImapRequestLineReader.java From james-project with Apache License 2.0 | 5 votes |
/** * @return the literal data and its expected size */ public ImmutablePair<Integer, InputStream> consumeLiteral(boolean extraCRLF) throws DecodingException { // The 1st character must be '{' consumeChar('{'); StringBuilder digits = new StringBuilder(); char next = nextChar(); while (next != '}' && next != '+') { digits.append(next); consume(); next = nextChar(); } // If the number is *not* suffixed with a '+', we *are* using a // synchronized literal, and we need to send command continuation // request before reading data. boolean synchronizedLiteral = true; // '+' indicates a non-synchronized literal (no command continuation // request) if (next == '+') { synchronizedLiteral = false; consumeChar('+'); } // Consume the '}' and the newline consumeChar('}'); consumeCRLF(); if (synchronizedLiteral) { commandContinuationRequest(); } int size = Integer.parseInt(digits.toString()); return ImmutablePair.of(size, read(size, extraCRLF)); }
Example 8
Source File: ConfidenceLevelUtils.java From onetwo with Apache License 2.0 | 5 votes |
/*** * (μ-Ζα/2σ , μ+Ζα/2σ) * 置信区间 * @param avg * @param stdDeviation 标准差 * @param zscore * @return */ public static ImmutablePair<BigDecimal, BigDecimal> calcConfidenceSection(BigDecimal avg, BigDecimal stdDeviation, double zscore){ avg = avg.setScale(2, RoundingMode.HALF_UP); BigDecimal zscoreDecimal = BigDecimal.valueOf(zscore); BigDecimal start = avg.subtract(stdDeviation.multiply(zscoreDecimal)); if(start.doubleValue()<0){ start = BigDecimal.ZERO; } BigDecimal end = avg.add(stdDeviation.multiply(zscoreDecimal)); ImmutablePair<BigDecimal, BigDecimal> pair = ImmutablePair.of(start, end); return pair; }
Example 9
Source File: OrientationBiasReadCountsUnitTest.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
private Pair<VariantContext, AlleleLikelihoods<GATKRead, Allele>> makeReads(int alt_F1R2, int alt_F2R1, int ref_F1R2, int ref_F2R1, Allele refAllele, Allele altAllele, List<Allele> alleles, Genotype g) { final List<GATKRead> altReads = Stream.concat(IntStream.range(0, alt_F1R2).mapToObj(i -> makeRead(false, true, i)), IntStream.range(0, alt_F2R1).mapToObj(i -> makeRead(false, false, i))).collect(Collectors.toList()); final List<GATKRead> refReads = Stream.concat(IntStream.range(0, ref_F1R2).mapToObj(i -> makeRead(true, true, i)), IntStream.range(0, ref_F2R1).mapToObj(i -> makeRead(true, false, i))).collect(Collectors.toList()); final GATKRead badRead = ArtificialReadUtils.createArtificialRead(TextCigarCodec.decode(10 + "M")); badRead.setMappingQuality(20); final AlleleLikelihoods<GATKRead, Allele> likelihoods = ArtificialAnnotationUtils.makeLikelihoods(sample1, refReads, altReads, Arrays.asList(badRead), -100.0, -10.0, -1.1, refAllele, altAllele); return ImmutablePair.of(new VariantContextBuilder("test", "20", 10003, 10003, alleles).genotypes(Arrays.asList(g)).make(), likelihoods); }
Example 10
Source File: CustomBoltDeclarer.java From bullet-storm with Apache License 2.0 | 5 votes |
@Override public BoltDeclarer fieldsGrouping(String componentId, String streamId, Fields fields) { Pair<String, String> key = ImmutablePair.of(componentId, streamId); List<Fields> existing = fieldsGroupings.get(key); if (existing == null) { existing = new ArrayList<>(); } existing.add(fields); fieldsGroupings.put(key, existing); return this; }
Example 11
Source File: CoverageModelEMWorkspace.java From gatk-protected with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Converts a list of copy ratio posteriors into a pair of INDArrays (log_c_st, var_log_c_st) * * @param copyRatioExpectationsList a list of {@link CopyRatioExpectations} * @return a pair of INDArrays (log_c_st, var_log_c_st) */ private ImmutablePair<INDArray, INDArray> convertCopyRatioLatentPosteriorExpectationsToNDArray( @Nonnull final List<CopyRatioExpectations> copyRatioExpectationsList) { final INDArray log_c_st = Nd4j.create(numSamples, numTargets); final INDArray var_log_c_st = Nd4j.create(numSamples, numTargets); for (int si = 0; si < numSamples; si++) { final CopyRatioExpectations res = copyRatioExpectationsList.get(si); log_c_st.getRow(si).assign(Nd4j.create(res.getLogCopyRatioMeans(), new int[] {1, numTargets})); var_log_c_st.getRow(si).assign(Nd4j.create(res.getLogCopyRatioVariances(), new int[] {1, numTargets})); } return ImmutablePair.of(log_c_st, var_log_c_st); }
Example 12
Source File: S3ProtocolResolver.java From genie with Apache License 2.0 | 5 votes |
/** * TODO: It would be nice to use Spring's HttpRange for this parsing, but this module does not * currently depend on spring-web. And this class cannot be moved to genie-web since it is used by * {@link S3ProtocolResolver} which is shared with the genie-agent module. */ static Pair<Integer, Integer> parseRangeHeader(@Nullable final String rangeHeader) { if (StringUtils.isBlank(rangeHeader)) { return NULL_RANGE; } final Matcher matcher = RANGE_HEADER_PATTERN.matcher(rangeHeader); if (!matcher.matches()) { return NULL_RANGE; } final String rangeStartString = matcher.group(1); final String rangeEndString = matcher.group(2); Integer rangeStart = null; Integer rangeEnd = null; if (!StringUtils.isBlank(rangeStartString)) { rangeStart = Integer.parseInt(rangeStartString); } if (!StringUtils.isBlank(rangeEndString)) { rangeEnd = Integer.parseInt(rangeEndString); } return ImmutablePair.of(rangeStart, rangeEnd); }
Example 13
Source File: PipelineTest.java From Alink with Apache License 2.0 | 5 votes |
/** * Create a mocked estimator and model pair. The mocked model will return the input identically. * * @param name name postfix of estimator. * @return mocked estimator and model pair. */ private static Pair<EstimatorBase, ModelBase> mockEstimator(String name) { ModelBase model = mock(ModelBase.class, "model_" + name); EstimatorBase estimator = mock(EstimatorBase.class, "estimator_" + name); when(estimator.fit(any(BatchOperator.class))).thenReturn(model); when(estimator.fit(any(StreamOperator.class))).thenReturn(model); when(model.transform(any(BatchOperator.class))) .thenAnswer(invocationOnMock -> invocationOnMock.getArgument(0)); when(model.transform(any(StreamOperator.class))) .thenAnswer(invocationOnMock -> invocationOnMock.getArgument(0)); return ImmutablePair.of(estimator, model); }
Example 14
Source File: KeyspaceStatePool.java From geowave with Apache License 2.0 | 5 votes |
public synchronized KeyspaceState getCachedState( final String contactPoints, final String keyspace) { final Pair<String, String> key = ImmutablePair.of(contactPoints, keyspace); KeyspaceState state = keyspaceStateCache.get(key); if (state == null) { state = new KeyspaceState(); keyspaceStateCache.put(key, state); } return state; }
Example 15
Source File: DeployOvfTemplateService.java From cs-actions with Apache License 2.0 | 5 votes |
protected ImmutablePair<ManagedObjectReference, OvfCreateImportSpecResult> createLeaseSetup( final ConnectionResources connectionResources, final VmInputs vmInputs, final String templatePath, final Map<String, String> ovfNetworkMap, final Map<String, String> ovfPropertyMap) throws Exception { final ManagedObjectReference ovfManager = getOvfManager(connectionResources); final VmUtils vmUtils = new VmUtils(); final ManagedObjectReference resourcePool; if (StringUtilities.isBlank(vmInputs.getClusterName())) { resourcePool = vmUtils.getMorResourcePool(vmInputs.getResourcePool(), connectionResources); } else { ManagedObjectReference clusterMor = new MorObjectHandler().getSpecificMor(connectionResources, connectionResources.getMorRootFolder(), ClusterParameter.CLUSTER_COMPUTE_RESOURCE.getValue(), vmInputs.getClusterName()); resourcePool = vmUtils.getMorResourcePoolFromCluster(connectionResources, clusterMor, vmInputs.getResourcePool()); } final ManagedObjectReference hostMor = vmUtils.getMorHost(vmInputs.getHostname(), connectionResources, null); final ManagedObjectReference datastoreMor = vmUtils.getMorDataStore(vmInputs.getDataStore(), connectionResources, null, vmInputs); final ManagedObjectReference folderMor = vmUtils.getMorFolder(vmInputs.getFolderName(), connectionResources); final List<OvfNetworkMapping> ovfNetworkMappings = getOvfNetworkMappings(ovfNetworkMap, connectionResources); final List<KeyValue> ovfPropertyMappings = getOvfPropertyMappings(ovfPropertyMap); final OvfCreateImportSpecResult importSpecResult = connectionResources.getVimPortType() .createImportSpec(ovfManager, getOvfTemplateAsString(templatePath), resourcePool, datastoreMor, getOvfCreateImportSpecParams(vmInputs, hostMor, ovfNetworkMappings, ovfPropertyMappings)); checkImportSpecResultForErrors(importSpecResult); final ManagedObjectReference httpNfcLease = OvfUtils.getHttpNfcLease(connectionResources, importSpecResult.getImportSpec(), resourcePool, hostMor, folderMor); return ImmutablePair.of(httpNfcLease, importSpecResult); }
Example 16
Source File: HyperParamResultManager.java From laozhongyi with MIT License | 4 votes |
public static synchronized void putResult(final Map<String, String> hyperParams, final int triedTimes, final float result) { final Pair<Map<String, String>, Integer> pair = ImmutablePair.of(hyperParams, triedTimes); mResults.put(pair, result); }
Example 17
Source File: JpaOrmEntityListenerOperationsImpl.java From gvnix with GNU General Public License v3.0 | 4 votes |
/** * Gets or creates a xml element (with tag-name <code>elementName</code>) on * <code>parent</code>. * <p/> * If <code>attributeValue</code> is provided will be used to search and * applied to the creation. * * @param document xml document instance * @param parent node to add the new xml element * @param elementName new xml tag name * @param attributeValue (optional) attribute name + attribute value * @return Element found; true if element is new */ private Pair<Element, Boolean> getOrCreateElement(Document document, Element parent, String elementName, Pair<String, String> attributeValue) { boolean changed = false; // prepare xpath expression to search for element StringBuilder sbXpath = new StringBuilder(); sbXpath.append(elementName); if (attributeValue != null) { sbXpath.append("[@"); sbXpath.append(attributeValue.getKey()); sbXpath.append("='"); sbXpath.append(attributeValue.getValue()); sbXpath.append("']"); } String xpath = sbXpath.toString(); // Search for element Element targetElement = XmlUtils.findFirstElement(xpath, parent); if (targetElement == null) { // Not found: create it targetElement = document.createElement(elementName); if (attributeValue != null) { targetElement.setAttribute(attributeValue.getKey(), attributeValue.getValue()); } parent.appendChild(targetElement); // search again targetElement = XmlUtils.findFirstElement(xpath, parent); if (targetElement == null) { // something went worng throw new IllegalStateException("Can't create ".concat(xpath) .concat(" element")); } changed = true; } return ImmutablePair.of(targetElement, changed); }
Example 18
Source File: Fragment.java From gatk with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static Fragment create(final List<GATKRead> reads) { Utils.validateArg(reads.size() <= 2, "Cannot construct fragment from more than two reads"); Utils.validateArg(!reads.isEmpty(), "Need one or two reads to construct a fragment"); return reads.size() == 1 ? new Fragment(reads.get(0)) : new Fragment(ImmutablePair.of(reads.get(0), reads.get(1))); }
Example 19
Source File: BoardData.java From mylizzie with GNU General Public License v3.0 | 4 votes |
public BoardData(Stone[] stonesOnBoard, int[] lastMove, Stone lastMoveColor, boolean blackToPlay, Zobrist zobrist, int moveNumber, int[] moveNumberListOnBoard, MutableSet<Coordinates> removedEnemyStoneIndexes, int blackPrisonersCount, int whitePrisonersCount) { this(ImmutablePair.of(19, 19), stonesOnBoard, lastMove, lastMoveColor, blackToPlay, zobrist, moveNumber, moveNumberListOnBoard, null, removedEnemyStoneIndexes, blackPrisonersCount, whitePrisonersCount); }
Example 20
Source File: CoverageModelEMWorkspace.java From gatk-protected with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Stack a list of (1 x T INDArray, 1 x T INDArray) pairs along the 0th axis of each INDArray * and returns a (STATE x T INDArray, STATE x T INDArray) pair * * @param perSampleData a list of (1 x T INDArray, 1 x T INDArray) pairs * @return a (STATE x T INDArray, STATE x T INDArray) pair */ private static ImmutablePair<INDArray, INDArray> stackCopyRatioPosteriorDataForAllSamples( final List<ImmutablePair<INDArray, INDArray>> perSampleData) { return ImmutablePair.of(Nd4j.vstack(perSampleData.stream().map(p -> p.left).collect(Collectors.toList())), Nd4j.vstack(perSampleData.stream().map(p -> p.right).collect(Collectors.toList()))); }