List of usage examples for com.google.common.collect Range contains
public boolean contains(C value)
From source file:io.github.msdk.id.localdatabasesearch.LocalDatabaseSearchMethod.java
/** {@inheritDoc} */ @Override//from ww w. j a va 2 s . c o m public Void execute() throws MSDKException { totalFeatures = featureTable.getRows().size(); FeatureTableColumn<List<IonAnnotation>> ionAnnotationColumn = featureTable .getColumn(ColumnName.IONANNOTATION, null); // Create ion annotation column if it is not present in the table if (ionAnnotationColumn == null) { ionAnnotationColumn = MSDKObjectBuilder.getIonAnnotationFeatureTableColumn(); featureTable.addColumn(ionAnnotationColumn); } // Loop through all features in the feature table for (FeatureTableRow row : featureTable.getRows()) { final Double mz = row.getMz(); final ChromatographyInfo rt = row.getChromatographyInfo(); if ((mz == null) || (rt == null)) continue; // Row values Range<Double> mzRange = mzTolerance.getToleranceRange(mz); Range<Double> rtRange = rtTolerance.getToleranceRange(rt.getRetentionTime()); List<IonAnnotation> rowIonAnnotations = row.getData(ionAnnotationColumn); // Empty rowIonAnnotations if (rowIonAnnotations == null) rowIonAnnotations = new ArrayList<IonAnnotation>(); // Loop through all ion annotations from the local database for (IonAnnotation ionAnnotation : ionAnnotations) { // Ion values final Double ionMz = ionAnnotation.getExpectedMz(); final ChromatographyInfo ionChromInfo = ionAnnotation.getChromatographyInfo(); if ((ionMz == null) || (ionChromInfo == null)) continue; // Convert from seconds to minutes double ionRt = ionChromInfo.getRetentionTime() / 60.0; final boolean mzMatch = mzRange.contains(ionMz); final boolean rtMatch = rtRange.contains(ionRt); // If match, add the ion annotation to the list if (mzMatch && rtMatch) { // If first ion annotation is empty then remove it if (rowIonAnnotations.size() > 0) { IonAnnotation firstionAnnotation = rowIonAnnotations.get(0); if (firstionAnnotation.isNA()) rowIonAnnotations.remove(0); } // Only add annotation if it is not already present boolean addIon = true; for (IonAnnotation ionAnnotations : rowIonAnnotations) { if (ionAnnotations.compareTo(ionAnnotation) == 0) addIon = false; } if (addIon) rowIonAnnotations.add(ionAnnotation); } } // Update the ion annotations of the feature row.setData(ionAnnotationColumn, rowIonAnnotations); if (canceled) return null; processedFeatures++; } return null; }
From source file:net.sf.mzmine.modules.peaklistmethods.peakpicking.deconvolution.centwave.CentWaveDetector.java
@Override public Feature[] resolvePeaks(final Feature chromatogram, final int[] scanNumbers, final double[] retentionTimes, final double[] intensities, final ParameterSet parameters, RSessionWrapper rSession) throws RSessionWrapperException { // Call findPeaks.centWave. double[][] peakMatrix = null; peakMatrix = centWave(rSession, retentionTimes, intensities, chromatogram.getMZ(), parameters.getParameter(SN_THRESHOLD).getValue(), parameters.getParameter(PEAK_SCALES).getValue(), parameters.getParameter(INTEGRATION_METHOD).getValue()); final List<ResolvedPeak> resolvedPeaks; if (peakMatrix == null) { resolvedPeaks = new ArrayList<ResolvedPeak>(0); } else {//w ww . ja va2 s .com LOG.finest("Processing peak matrix..."); final Range<Double> peakDuration = parameters.getParameter(PEAK_DURATION).getValue(); // Process peak matrix. resolvedPeaks = new ArrayList<ResolvedPeak>(peakMatrix.length); for (final double[] peakRow : peakMatrix) { // Get peak start and end. final int peakLeft = findRTIndex(retentionTimes, peakRow[4]); final int peakRight = findRTIndex(retentionTimes, peakRow[5]); // Partition into sections bounded by null data points, creating // a peak for each. for (int start = peakLeft; start < peakRight; start++) { if (chromatogram.getDataPoint(scanNumbers[start]) != null) { int end = start; while (end < peakRight && chromatogram.getDataPoint(scanNumbers[end + 1]) != null) { end++; } if ((end > start) && (peakDuration.contains(retentionTimes[end] - retentionTimes[start]))) { resolvedPeaks.add(new ResolvedPeak(chromatogram, start, end)); } start = end; } } } } return resolvedPeaks.toArray(new ResolvedPeak[resolvedPeaks.size()]); }
From source file:net.sf.mzmine.modules.peaklistmethods.peakpicking.deconvolution.noiseamplitude.NoiseAmplitudePeakDetector.java
@Override public Feature[] resolvePeaks(final Feature chromatogram, final int[] scanNumbers, final double[] retentionTimes, final double[] intensities, ParameterSet parameters, RSessionWrapper rSession) {/*from w w w . jav a 2s . c om*/ final double amplitudeOfNoise = parameters.getParameter(NOISE_AMPLITUDE).getValue(); // This treeMap stores the score of frequency of intensity ranges final TreeMap<Integer, Integer> binsFrequency = new TreeMap<Integer, Integer>(); double maxIntensity = 0.0; double avgIntensity = 0.0; for (final double intensity : intensities) { addNewIntensity(intensity, binsFrequency, amplitudeOfNoise); maxIntensity = Math.max(maxIntensity, intensity); avgIntensity += intensity; } final int scanCount = scanNumbers.length; avgIntensity /= (double) scanCount; final List<ResolvedPeak> resolvedPeaks = new ArrayList<ResolvedPeak>(2); // If the current chromatogram has characteristics of background or just // noise. if (avgIntensity <= maxIntensity / 2.0) { final double noiseThreshold = getNoiseThreshold(binsFrequency, maxIntensity, amplitudeOfNoise); boolean activePeak = false; final Range<Double> peakDuration = parameters.getParameter(PEAK_DURATION).getValue(); final double minimumPeakHeight = parameters.getParameter(MIN_PEAK_HEIGHT).getValue(); // Index of starting region of the current peak. int currentPeakStart = 0; for (int i = 0; i < scanCount; i++) { if (intensities[i] > noiseThreshold && !activePeak) { currentPeakStart = i; activePeak = true; } if (intensities[i] <= noiseThreshold && activePeak) { int currentPeakEnd = i; // If the last data point is zero, ignore it. if (intensities[currentPeakEnd] == 0.0) { currentPeakEnd--; } if (currentPeakEnd - currentPeakStart > 0) { final ResolvedPeak peak = new ResolvedPeak(chromatogram, currentPeakStart, currentPeakEnd); if (peakDuration.contains(RangeUtils.rangeLength(peak.getRawDataPointsRTRange())) && peak.getHeight() >= minimumPeakHeight) { resolvedPeaks.add(peak); } } activePeak = false; } } } return resolvedPeaks.toArray(new ResolvedPeak[resolvedPeaks.size()]); }
From source file:com.nimbits.server.io.BlobStoreImpl.java
@Override public List<Value> getDataSegment(final Entity entity, final Range<Date> timespan) { PersistenceManager pm = persistenceManagerFactory.getPersistenceManager(); try {/*from w w w.j a va2s . c o m*/ final List<Value> retObj = new ArrayList<Value>(); final Query q = pm.newQuery(ValueBlobStoreEntity.class); q.setFilter("entity == k && minTimestamp <= et && maxTimestamp >= st "); q.declareParameters("String k, Long et, Long st"); q.setOrdering("minTimestamp desc"); final Iterable<ValueBlobStore> result = (Iterable<ValueBlobStore>) q.execute(entity.getKey(), timespan.upperEndpoint().getTime(), timespan.lowerEndpoint().getTime()); for (final ValueBlobStore e : result) { //todo break out of loop when range is met if (validateOwnership(entity, e)) { List<Value> values = readValuesFromFile(e.getBlobKey()); for (final Value vx : values) { if (timespan.contains(vx.getTimestamp())) { retObj.add(vx); } } } } return retObj; } finally { pm.close(); } }
From source file:io.github.mzmine.util.jfreechart.IntelligentItemLabelGenerator.java
/** * @see org.jfree.chart.labels.XYItemLabelGenerator#generateLabel(org.jfree.data.xy.XYDataset, * int, int)/*from w w w .j a va 2s . com*/ */ public String generateLabel(XYDataset currentDataset, int currentSeries, int currentItem) { XYPlot plot = chartNode.getChart().getXYPlot(); // X and Y values of the current data point final double currentXValue = currentDataset.getXValue(currentSeries, currentItem); final double currentYValue = currentDataset.getYValue(currentSeries, currentItem); // Calculate X axis span of 1 screen pixel final double xLength = plot.getDomainAxis().getRange().getLength(); final double pixelX = xLength / chartNode.getWidth(); // Calculate the distance from the current point where labels might // overlap final double dangerZoneX = (reservedPixels / 2) * pixelX; // Range on X axis that we're going to check for higher data points. If // a higher data point is found, we don't place a label on this one. final Range<Double> dangerZoneRange = Range.closed(currentXValue - dangerZoneX, currentXValue + dangerZoneX); // Iterate through data sets for (int datasetIndex = 0; datasetIndex < plot.getDatasetCount(); datasetIndex++) { XYDataset dataset = plot.getDataset(datasetIndex); // Some data sets could have been removed if (dataset == null) continue; final int seriesCount = dataset.getSeriesCount(); // Iterate through series for (int seriesIndex = 0; seriesIndex < seriesCount; seriesIndex++) { final int itemCount = dataset.getItemCount(seriesIndex); // Find the index of a data point that is closest to // currentXValue int closestValueIndex; if (dataset == currentDataset && seriesIndex == currentSeries) { closestValueIndex = currentItem; } else { closestValueIndex = findClosestXIndex(dataset, seriesIndex, currentXValue, 0, itemCount - 1); } // Search to the left of the closest data point for (int i = closestValueIndex; (i >= 0) && (dangerZoneRange.contains(dataset.getX(seriesIndex, i).doubleValue())); i--) { if (dataset.getYValue(seriesIndex, i) > currentYValue) return null; // In the case there are equal values, only place the label // on the leftmost value if (dataset.getYValue(seriesIndex, i) == currentYValue && (dataset.getXValue(seriesIndex, i) < currentXValue)) return null; } // Search to the right of the closest data point for (int i = closestValueIndex + 1; (i < itemCount) && (dangerZoneRange.contains(dataset.getX(seriesIndex, i).doubleValue())); i++) { if (dataset.getYValue(seriesIndex, i) > currentYValue) return null; } } } // If no higher data point was found, create the label String label = underlyingGenerator.generateLabel(currentDataset, currentSeries, currentItem); return label; }
From source file:net.sf.mzmine.modules.peaklistmethods.peakpicking.deconvolution.baseline.BaselinePeakDetector.java
@Override public Feature[] resolvePeaks(final Feature chromatogram, final int[] scanNumbers, final double[] retentionTimes, final double[] intensities, ParameterSet parameters, RSessionWrapper rSession) {/*from ww w .j av a 2 s . c o m*/ // Get parameters. final double minimumPeakHeight = parameters.getParameter(MIN_PEAK_HEIGHT).getValue(); final double baselineLevel = parameters.getParameter(BASELINE_LEVEL).getValue(); final Range<Double> durationRange = parameters.getParameter(PEAK_DURATION).getValue(); final List<ResolvedPeak> resolvedPeaks = new ArrayList<ResolvedPeak>(2); // Current region is a region of consecutive scans which all have // intensity above baseline level. final int scanCount = scanNumbers.length; for (int currentRegionStart = 0; currentRegionStart < scanCount; currentRegionStart++) { // Find a start of the region. final DataPoint startPeak = chromatogram.getDataPoint(scanNumbers[currentRegionStart]); if (startPeak != null && startPeak.getIntensity() >= baselineLevel) { double currentRegionHeight = startPeak.getIntensity(); // Search for end of the region int currentRegionEnd; for (currentRegionEnd = currentRegionStart + 1; currentRegionEnd < scanCount; currentRegionEnd++) { final DataPoint endPeak = chromatogram.getDataPoint(scanNumbers[currentRegionEnd]); if (endPeak == null || endPeak.getIntensity() < baselineLevel) { break; } currentRegionHeight = Math.max(currentRegionHeight, endPeak.getIntensity()); } // Subtract one index, so the end index points at the last data // point of current region. currentRegionEnd--; // Check current region, if it makes a good peak. if (durationRange.contains(retentionTimes[currentRegionEnd] - retentionTimes[currentRegionStart]) && currentRegionHeight >= minimumPeakHeight) { // Create a new ResolvedPeak and add it. resolvedPeaks.add(new ResolvedPeak(chromatogram, currentRegionStart, currentRegionEnd)); } // Find next peak region, starting from next data point. currentRegionStart = currentRegionEnd; } } return resolvedPeaks.toArray(new ResolvedPeak[resolvedPeaks.size()]); }
From source file:com.bigdata.dastor.service.StorageService.java
/** return a token to which if a node bootstraps it will get about 1/2 of this node's range */ public Token getBootstrapToken() { Range range = getLocalPrimaryRange(); List<DecoratedKey> keys = new ArrayList<DecoratedKey>(); for (ColumnFamilyStore cfs : ColumnFamilyStore.all()) { for (IndexSummary.KeyPosition info : cfs.allIndexPositions()) { if (range.contains(info.key.token)) keys.add(info.key);// w ww. j a va 2 s . co m } } FBUtilities.sortSampledKeys(keys, range); if (keys.size() < 3) return partitioner_.midpoint(range.left, range.right); else return keys.get(keys.size() / 2).token; }
From source file:com.haulmont.yarg.formatters.impl.XlsxFormatter.java
protected void updateMergeRegions() { for (Range templateRange : rangeDependencies.templates()) { Worksheet templateSheet = template.getSheetByName(templateRange.getSheet()); Worksheet resultSheet = result.getSheetByName(templateRange.getSheet()); if (templateSheet.getMergeCells() != null) { if (resultSheet.getMergeCells() == null) { CTMergeCells resultMergeCells = new CTMergeCells(); resultMergeCells.setParent(resultSheet); resultSheet.setMergeCells(resultMergeCells); }//from w w w . j a v a2s . c o m } for (Range resultRange : rangeDependencies.resultsForTemplate(templateRange)) { if (templateSheet.getMergeCells() != null && templateSheet.getMergeCells().getMergeCell() != null) { for (CTMergeCell templateMergeRegion : templateSheet.getMergeCells().getMergeCell()) { Range mergeRange = Range.fromRange(templateRange.getSheet(), templateMergeRegion.getRef()); if (templateRange.contains(mergeRange)) { Offset offset = calculateOffset(templateRange, resultRange); Range resultMergeRange = mergeRange.copy().shift(offset.downOffset, offset.rightOffset); CTMergeCell resultMergeRegion = new CTMergeCell(); resultMergeRegion.setRef(resultMergeRange.toRange()); resultMergeRegion.setParent(resultSheet.getMergeCells()); resultSheet.getMergeCells().getMergeCell().add(resultMergeRegion); } } } } } }
From source file:net.sf.mzmine.modules.visualization.ida.IDADataSet.java
/** * Highlights all MS/MS spots for which a peak is found in the MS/MS * spectrum with the m/z value/*from w w w . jav a2s . c om*/ * * @param mz * m/z. * @param ppm * ppm value. * @param neutralLoss * true or false. * @param c * color. * */ public void highlightSpectra(double mz, MZTolerance searchMZTolerance, double minIntensity, boolean neutralLoss, Color c) { // mzRange searchMZTolerance.getToleranceRange(mz); Range<Double> precursorMZRange = searchMZTolerance.getToleranceRange(mz); // Loop through all scans for (int row = 0; row < scanNumbers.length; row++) { Scan msscan = rawDataFile.getScan(scanNumbers[row]); // Get total intensity of all peaks in MS/MS scan if (scanNumbers[row] > 0) { DataPoint scanDataPoints[] = msscan.getDataPoints(); double selectedIons[] = new double[scanDataPoints.length]; int ions = 0; boolean colorSpectra = false; // Search for neutral loss in ms/ms spectrum if (neutralLoss) { for (int x = 0; x < scanDataPoints.length; x++) { if (scanDataPoints[x].getIntensity() > minIntensity) { selectedIons[ions] = scanDataPoints[x].getMZ(); ions++; } } if (ions > 1) { double ionDiff[][] = new double[ions][ions]; for (int x = 0; x < ions; x++) { for (int y = 0; y < ions; y++) { ionDiff[x][y] = Math.abs(selectedIons[x] - selectedIons[y]); } } for (int x = 0; x < ions; x++) { for (int y = 0; y < ions; y++) { if (precursorMZRange.contains(ionDiff[x][y])) { colorSpectra = true; break; } } } } } // Search for specific ion in ms/ms spectrum else { for (int x = 0; x < scanDataPoints.length; x++) { if (precursorMZRange.contains(scanDataPoints[x].getMZ()) && scanDataPoints[x].getIntensity() > minIntensity) { colorSpectra = true; break; } } } if (colorSpectra) { // If color is red green or blue then use toning from // current color int rgb = getColor(0, row).getRed(); if (c == Color.red) { setColor(0, row, new Color(255, rgb, rgb)); } else if (c == Color.green) { setColor(0, row, new Color(rgb, 255, rgb)); } else if (c == Color.blue) { setColor(0, row, new Color(rgb, rgb, 255)); } else { setColor(0, row, c); } } } } fireDatasetChanged(); }
From source file:com.bigdata.dastor.service.StorageService.java
/** * @return list of Tokens (_not_ keys!) breaking up the data this node is responsible for into pieces of roughly keysPerSplit *//*from w w w .java 2 s . c o m*/ public List<Token> getSplits(Range range, int keysPerSplit) { List<Token> tokens = new ArrayList<Token>(); // we use the actual Range token for the first and last brackets of the splits to ensure correctness tokens.add(range.left); List<DecoratedKey> keys = new ArrayList<DecoratedKey>(); for (ColumnFamilyStore cfs : ColumnFamilyStore.all()) { for (IndexSummary.KeyPosition info : cfs.allIndexPositions()) { if (range.contains(info.key.token)) keys.add(info.key); } } FBUtilities.sortSampledKeys(keys, range); int splits = keys.size() * DatabaseDescriptor.getIndexInterval() / keysPerSplit; if (keys.size() >= splits) { for (int i = 1; i < splits; i++) { int index = i * (keys.size() / splits); tokens.add(keys.get(index).token); } } tokens.add(range.right); return tokens; }