src/core/net/sf/basedb/util/importer/spotdata/MAParser.java

Code
Comments
Other
Rev Date Author Line
5093 10 Sep 09 nicklas 1 /**
5093 10 Sep 09 nicklas 2   $Id$
5093 10 Sep 09 nicklas 3
5093 10 Sep 09 nicklas 4   Copyright (C) 2009 Nicklas Nordborg
5093 10 Sep 09 nicklas 5
5093 10 Sep 09 nicklas 6   This file is part of BASE - BioArray Software Environment.
5093 10 Sep 09 nicklas 7   Available at http://base.thep.lu.se/
5093 10 Sep 09 nicklas 8
5093 10 Sep 09 nicklas 9   BASE is free software; you can redistribute it and/or
5093 10 Sep 09 nicklas 10   modify it under the terms of the GNU General Public License
5093 10 Sep 09 nicklas 11   as published by the Free Software Foundation; either version 3
5093 10 Sep 09 nicklas 12   of the License, or (at your option) any later version.
5093 10 Sep 09 nicklas 13
5093 10 Sep 09 nicklas 14   BASE is distributed in the hope that it will be useful,
5093 10 Sep 09 nicklas 15   but WITHOUT ANY WARRANTY; without even the implied warranty of
5093 10 Sep 09 nicklas 16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
5093 10 Sep 09 nicklas 17   GNU General Public License for more details.
5093 10 Sep 09 nicklas 18
5093 10 Sep 09 nicklas 19   You should have received a copy of the GNU General Public License
5093 10 Sep 09 nicklas 20   along with BASE. If not, see <http://www.gnu.org/licenses/>.
5093 10 Sep 09 nicklas 21 */
5093 10 Sep 09 nicklas 22 package net.sf.basedb.util.importer.spotdata;
5093 10 Sep 09 nicklas 23
5093 10 Sep 09 nicklas 24 import java.util.List;
5093 10 Sep 09 nicklas 25
5096 14 Sep 09 nicklas 26 import net.sf.basedb.util.basefile.BaseFileParser;
5093 10 Sep 09 nicklas 27 import net.sf.basedb.util.parser.FlatFileParser;
5093 10 Sep 09 nicklas 28 import net.sf.basedb.util.parser.FlatFileParser.Data;
5093 10 Sep 09 nicklas 29
5093 10 Sep 09 nicklas 30 /**
5093 10 Sep 09 nicklas 31   Spot intensity parser implementation for 2-channel data 
5093 10 Sep 09 nicklas 32   that looks for M/A values in the spot data and converts them to ch1/ch2
5093 10 Sep 09 nicklas 33   intensity values. The required assay fields are:
5096 14 Sep 09 nicklas 34   l2ratio1_2 (M) and l10intgmean1_2 (A).
5096 14 Sep 09 nicklas 35   <p>
5096 14 Sep 09 nicklas 36   NOTE! The column names for the M/A values can be redefined by 
5096 14 Sep 09 nicklas 37   calling {@link BaseFileParser#setRedefinedColumnName(String, String, String)}.
5093 10 Sep 09 nicklas 38   
5093 10 Sep 09 nicklas 39   @author Nicklas
5093 10 Sep 09 nicklas 40   @version 2.14
5093 10 Sep 09 nicklas 41   @base.modified $Date$
5093 10 Sep 09 nicklas 42 */
5093 10 Sep 09 nicklas 43 public class MAParser
5093 10 Sep 09 nicklas 44   implements SpotIntensityParser
5093 10 Sep 09 nicklas 45 {
5093 10 Sep 09 nicklas 46
5093 10 Sep 09 nicklas 47   private int mIndex;
5093 10 Sep 09 nicklas 48   private int aIndex;
5093 10 Sep 09 nicklas 49   
5096 14 Sep 09 nicklas 50   private static final String mColumn = "l2ratio1_2";
5096 14 Sep 09 nicklas 51   private static final String aColumn = "l10intgmean1_2";
5096 14 Sep 09 nicklas 52   
5093 10 Sep 09 nicklas 53   /**
5093 10 Sep 09 nicklas 54     Creates a new MA-parser.
5093 10 Sep 09 nicklas 55   */
5093 10 Sep 09 nicklas 56   public MAParser()
5093 10 Sep 09 nicklas 57   {}
5093 10 Sep 09 nicklas 58   
5093 10 Sep 09 nicklas 59   /* 
5093 10 Sep 09 nicklas 60     From the SpotIntensityParser interface
5093 10 Sep 09 nicklas 61     --------------------------------------
5093 10 Sep 09 nicklas 62   */
5093 10 Sep 09 nicklas 63   @Override
5096 14 Sep 09 nicklas 64   public boolean hasRequiredAssayFields(BaseFileParser parser, FlatFileParser ffp,
5093 10 Sep 09 nicklas 65       List<String> assayFields)
5093 10 Sep 09 nicklas 66   {
5096 14 Sep 09 nicklas 67     int mIndex = assayFields.indexOf(parser.getRedefinedColumnName("spots", mColumn));
5096 14 Sep 09 nicklas 68     int aIndex = assayFields.indexOf(parser.getRedefinedColumnName("spots", aColumn));
5093 10 Sep 09 nicklas 69     return mIndex >= 0 && aIndex >= 0;
5093 10 Sep 09 nicklas 70   }
5093 10 Sep 09 nicklas 71   @Override
5096 14 Sep 09 nicklas 72   public void beginSection(BaseFileParser parser, FlatFileParser ffp, 
5096 14 Sep 09 nicklas 73       List<String> assayFields)
5093 10 Sep 09 nicklas 74   {
5096 14 Sep 09 nicklas 75     mIndex = assayFields.indexOf(parser.getRedefinedColumnName("spots", mColumn));
5096 14 Sep 09 nicklas 76     aIndex = assayFields.indexOf(parser.getRedefinedColumnName("spots", aColumn));
5093 10 Sep 09 nicklas 77   }
5093 10 Sep 09 nicklas 78
5093 10 Sep 09 nicklas 79   @Override
5093 10 Sep 09 nicklas 80   public boolean setIntensities(Data data, float[] intensities, int firstIndex)
5093 10 Sep 09 nicklas 81   {
7665 20 Mar 19 nicklas 82     Float m = data.getFloat(mIndex + firstIndex, null, true);
7665 20 Mar 19 nicklas 83     if (m == null) return false;
7665 20 Mar 19 nicklas 84     Float a = data.getFloat(aIndex + firstIndex, null, true);
7665 20 Mar 19 nicklas 85     if (a == null) return false;
5093 10 Sep 09 nicklas 86     // int2 = 10^a / 2^(0.5*m)
5093 10 Sep 09 nicklas 87     // int1 = int2 * 2^m
5093 10 Sep 09 nicklas 88     intensities[1] = (float)(Math.pow(10, a) / Math.pow(2, 0.5 * m));
5093 10 Sep 09 nicklas 89     intensities[0] = (float)(intensities[1] * Math.pow(2, m));
5093 10 Sep 09 nicklas 90     return true;
5093 10 Sep 09 nicklas 91   }
5093 10 Sep 09 nicklas 92   // ---------------------------------------
5093 10 Sep 09 nicklas 93
5093 10 Sep 09 nicklas 94 }