Here you can find the source of substractBackground( final Map
Parameter | Description |
---|---|
concentrationToSampleReadings | a parameter |
concentrationToBackgroundReadings | a parameter |
private static Map<Double, Collection<double[]>> substractBackground( final Map<Double, Collection<double[]>> concentrationToSampleReadings, final Map<Double, Collection<double[]>> concentrationToBackgroundReadings)
//package com.java2s; /******************************************************************************* * Manchester Centre for Integrative Systems Biology * University of Manchester// w w w . j a v a2 s. c om * Manchester M1 7ND * United Kingdom * * Copyright (C) 2007 University of Manchester * * This program is released under the Academic Free License ("AFL") v3.0. * (http://www.opensource.org/licenses/academic.php) *******************************************************************************/ import java.util.*; public class Main { /** * * @param concentrationToSampleReadings * @param concentrationToBackgroundReadings * @return Map */ private static Map<Double, Collection<double[]>> substractBackground( final Map<Double, Collection<double[]>> concentrationToSampleReadings, final Map<Double, Collection<double[]>> concentrationToBackgroundReadings) { final double ZERO = 0.0; final Map<Double, Collection<double[]>> concentrationToSubtractedReadings = new TreeMap<>(); for (Iterator<Map.Entry<Double, Collection<double[]>>> iterator = concentrationToSampleReadings .entrySet().iterator(); iterator.hasNext();) { final Map.Entry<Double, Collection<double[]>> entry = iterator .next(); final Double concentration = entry.getKey(); final Collection<double[]> sampleReadings = entry.getValue(); final Collection<double[]> backgroundReadings = concentrationToBackgroundReadings .get(concentration); final Collection<double[]> subtractedReadings = new ArrayList<>(); for (Iterator<double[]> iterator2 = sampleReadings.iterator(); iterator2 .hasNext();) { final double[] sampleReading = iterator2.next(); final double[] subtratedReading = new double[sampleReading.length]; System.arraycopy(sampleReading, 0, subtratedReading, 0, sampleReading.length); // Remove background if present: if (backgroundReadings != null) { final double[] meanBackgroundReading = getMeanBackgroundReading(backgroundReadings); for (int j = 0; j < subtratedReading.length; j++) { subtratedReading[j] = Math.max(ZERO, subtratedReading[j] - meanBackgroundReading[j]); } } subtractedReadings.add(subtratedReading); } concentrationToSubtractedReadings.put(concentration, subtractedReadings); } return concentrationToSubtractedReadings; } /** * * @param backgroundReadings * @return double[] */ private static double[] getMeanBackgroundReading( final Collection<double[]> backgroundReadings) { final int numBackgroundReadings = backgroundReadings.size(); double[] meanBackgroundReading = null; for (Iterator<double[]> iterator = backgroundReadings.iterator(); iterator .hasNext();) { final double[] backgroundReading = iterator.next(); if (meanBackgroundReading == null) { meanBackgroundReading = backgroundReading; } else { for (int i = 0; i < backgroundReading.length; i++) { meanBackgroundReading[i] += backgroundReading[i]; } } } if (meanBackgroundReading != null) { for (int i = 0; i < meanBackgroundReading.length; i++) { meanBackgroundReading[i] /= numBackgroundReadings; } } return meanBackgroundReading; } }