src/core/net/sf/basedb/util/ma/MACalculator.java

Code
Comments
Other
Rev Date Author Line
6366 05 Dec 13 nicklas 1 /**
6366 05 Dec 13 nicklas 2   $Id$
6366 05 Dec 13 nicklas 3
6366 05 Dec 13 nicklas 4   Copyright (C) 2013 Nicklas Nordborg
6366 05 Dec 13 nicklas 5
6366 05 Dec 13 nicklas 6   This file is part of BASE - BioArray Software Environment.
6366 05 Dec 13 nicklas 7   Available at http://base.thep.lu.se/
6366 05 Dec 13 nicklas 8
6366 05 Dec 13 nicklas 9   BASE is free software; you can redistribute it and/or
6366 05 Dec 13 nicklas 10   modify it under the terms of the GNU General Public License
6366 05 Dec 13 nicklas 11   as published by the Free Software Foundation; either version 3
6366 05 Dec 13 nicklas 12   of the License, or (at your option) any later version.
6366 05 Dec 13 nicklas 13
6366 05 Dec 13 nicklas 14   BASE is distributed in the hope that it will be useful,
6366 05 Dec 13 nicklas 15   but WITHOUT ANY WARRANTY; without even the implied warranty of
6366 05 Dec 13 nicklas 16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
6366 05 Dec 13 nicklas 17   GNU General Public License for more details.
6366 05 Dec 13 nicklas 18
6366 05 Dec 13 nicklas 19   You should have received a copy of the GNU General Public License
6366 05 Dec 13 nicklas 20   along with BASE. If not, see <http://www.gnu.org/licenses/>.
6366 05 Dec 13 nicklas 21 */
6366 05 Dec 13 nicklas 22 package net.sf.basedb.util.ma;
6366 05 Dec 13 nicklas 23
6366 05 Dec 13 nicklas 24 /**
6366 05 Dec 13 nicklas 25   Calculates M and A values for 2-channel data. For "normal" intensity 
6366 05 Dec 13 nicklas 26   values M and A are defined as follows:
6366 05 Dec 13 nicklas 27   
6366 05 Dec 13 nicklas 28   M = log2(ch1/ch2)
6366 05 Dec 13 nicklas 29   A = log10(ch*ch2)/2
6366 05 Dec 13 nicklas 30   
6366 05 Dec 13 nicklas 31   Channel intensity corrections are used to calculate new
6366 05 Dec 13 nicklas 32   values for channel 1 and 2. For corrections that use M+A
6366 05 Dec 13 nicklas 33   values the corrections are usually calculated in log2-space
6366 05 Dec 13 nicklas 34   and the resulting equations are:
6366 05 Dec 13 nicklas 35
6366 05 Dec 13 nicklas 36   log2(newCh1) = log2(oldCh1) - factor
6366 05 Dec 13 nicklas 37   log2(newCh2) = log2(oldCh2) + factor
6366 05 Dec 13 nicklas 38   
6366 05 Dec 13 nicklas 39   Source data that has been transformed (eg. log2-transformed) must use
6366 05 Dec 13 nicklas 40   different equations to get the correct results.
6366 05 Dec 13 nicklas 41   
6366 05 Dec 13 nicklas 42   @author nicklas
6366 05 Dec 13 nicklas 43   @since 3.2.4
6366 05 Dec 13 nicklas 44 */
6366 05 Dec 13 nicklas 45 public class MACalculator 
6366 05 Dec 13 nicklas 46 {
6366 05 Dec 13 nicklas 47   static final double INV_LN2 = 1 / Math.log(2);
6366 05 Dec 13 nicklas 48   static final double INV_LN10x2 = 1 / (Math.log(10) * 2);
6366 05 Dec 13 nicklas 49
6366 05 Dec 13 nicklas 50   
6366 05 Dec 13 nicklas 51   public MACalculator()
6366 05 Dec 13 nicklas 52   {}
6366 05 Dec 13 nicklas 53   
6366 05 Dec 13 nicklas 54   /**
6366 05 Dec 13 nicklas 55     Calculate the M and A values from the ch1 and ch2 intensity values.
6366 05 Dec 13 nicklas 56     See class description for information about the definitions of M and A.
6366 05 Dec 13 nicklas 57     @return An array with [0] = M, [1] = A
6366 05 Dec 13 nicklas 58   */
6366 05 Dec 13 nicklas 59   public double[] MA(double ch1, double ch2) 
6366 05 Dec 13 nicklas 60   {
6366 05 Dec 13 nicklas 61     double lnCh1 = Math.log(ch1);
6366 05 Dec 13 nicklas 62     double lnCh2 = Math.log(ch2);
6366 05 Dec 13 nicklas 63     // M = log2(ch1)-log2(ch2) = (ln(ch1)-ln(ch2)) / ln(2)
6366 05 Dec 13 nicklas 64     // A = (log10(ch1)+log10(ch2))/2 = (ln(ch1)+ln(ch2))/(ln(10)*2)
6366 05 Dec 13 nicklas 65     double[] MA = { (lnCh1-lnCh2)*INV_LN2, (lnCh1+lnCh2)*INV_LN10x2 };
6366 05 Dec 13 nicklas 66     return MA;
6366 05 Dec 13 nicklas 67   }
6366 05 Dec 13 nicklas 68
6366 05 Dec 13 nicklas 69   /**
6366 05 Dec 13 nicklas 70     Apply a correction factor to the ch1 and ch2 intensity values.
6366 05 Dec 13 nicklas 71     @return An array with [0] = newCh1, [1] = newCh2
6366 05 Dec 13 nicklas 72   */
6366 05 Dec 13 nicklas 73   public double[] correct(double ch1, double ch2, double factor) 
6366 05 Dec 13 nicklas 74   {
6366 05 Dec 13 nicklas 75     factor = Math.pow(2, factor);
6366 05 Dec 13 nicklas 76     double[] result = {ch1 / factor , ch2 * factor};
6366 05 Dec 13 nicklas 77     return result;
6366 05 Dec 13 nicklas 78   }
6366 05 Dec 13 nicklas 79   
6366 05 Dec 13 nicklas 80
6366 05 Dec 13 nicklas 81 }