src/core/net/sf/basedb/util/importer/spotdata/GenericIntensityParser.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   Generic spot intensity parser implementation that 
5093 10 Sep 09 nicklas 32   looks for 'intensity1', ..., 'intensityN' data columns for any
5093 10 Sep 09 nicklas 33   number of channels.
5093 10 Sep 09 nicklas 34   
5093 10 Sep 09 nicklas 35   @author Nicklas
5093 10 Sep 09 nicklas 36   @version 2.14
5093 10 Sep 09 nicklas 37   @base.modified $Date$
5093 10 Sep 09 nicklas 38 */
5093 10 Sep 09 nicklas 39 public class GenericIntensityParser
5093 10 Sep 09 nicklas 40   implements SpotIntensityParser
5093 10 Sep 09 nicklas 41 {
5093 10 Sep 09 nicklas 42   
5093 10 Sep 09 nicklas 43   private final int channels;
5093 10 Sep 09 nicklas 44   private int[] index;
5093 10 Sep 09 nicklas 45   
5093 10 Sep 09 nicklas 46   /**
5093 10 Sep 09 nicklas 47     Creates a new parser for the specified number of channels.
5093 10 Sep 09 nicklas 48   */
5093 10 Sep 09 nicklas 49   public GenericIntensityParser(int channels)
5093 10 Sep 09 nicklas 50   {
5093 10 Sep 09 nicklas 51     this.channels = channels;
5093 10 Sep 09 nicklas 52   }
5093 10 Sep 09 nicklas 53   
5093 10 Sep 09 nicklas 54   /* 
5093 10 Sep 09 nicklas 55     From the SpotIntensityParser interface
5093 10 Sep 09 nicklas 56     --------------------------------------
5093 10 Sep 09 nicklas 57   */
5093 10 Sep 09 nicklas 58   @Override
5096 14 Sep 09 nicklas 59   public boolean hasRequiredAssayFields(BaseFileParser parser, FlatFileParser ffp,
5093 10 Sep 09 nicklas 60       List<String> assayFields)
5093 10 Sep 09 nicklas 61   {
5093 10 Sep 09 nicklas 62     for (int i = 1; i <= channels; ++i)
5093 10 Sep 09 nicklas 63     {
5096 14 Sep 09 nicklas 64       int index = assayFields.indexOf(parser.getRedefinedColumnName("spots", "intensity" + i));
5093 10 Sep 09 nicklas 65       if (index < 0) return false;
5093 10 Sep 09 nicklas 66     }
5093 10 Sep 09 nicklas 67     return true;
5093 10 Sep 09 nicklas 68   }
5093 10 Sep 09 nicklas 69
5093 10 Sep 09 nicklas 70   @Override
5096 14 Sep 09 nicklas 71   public void beginSection(BaseFileParser parser, FlatFileParser ffp, 
5096 14 Sep 09 nicklas 72       List<String> assayFields)
5093 10 Sep 09 nicklas 73   {
5093 10 Sep 09 nicklas 74     index = new int[channels];
5093 10 Sep 09 nicklas 75     for (int i = 1; i <= channels; ++i)
5093 10 Sep 09 nicklas 76     {
5096 14 Sep 09 nicklas 77       index[i-1] = assayFields.indexOf(parser.getRedefinedColumnName("spots", "intensity" + i));
5093 10 Sep 09 nicklas 78     }
5093 10 Sep 09 nicklas 79   }
5093 10 Sep 09 nicklas 80
5093 10 Sep 09 nicklas 81   @Override
5093 10 Sep 09 nicklas 82   public boolean setIntensities(Data data, float[] intensities, int firstIndex)
5093 10 Sep 09 nicklas 83   {
5093 10 Sep 09 nicklas 84     for (int i = 0; i < channels; ++i)
5093 10 Sep 09 nicklas 85     {
7665 20 Mar 19 nicklas 86       Float value = data.getFloat(index[i] + firstIndex, null, true);
7665 20 Mar 19 nicklas 87       if (value == null) return false;
5093 10 Sep 09 nicklas 88       intensities[i] = value;
5093 10 Sep 09 nicklas 89     }
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 }