src/core/net/sf/basedb/util/importer/spotdata/ExtraFloatParser.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 net.sf.basedb.util.parser.FlatFileParser;
5093 10 Sep 09 nicklas 25
5093 10 Sep 09 nicklas 26 /**
5093 10 Sep 09 nicklas 27   Parser that is responsible for extracting extra float values
5093 10 Sep 09 nicklas 28   from the 'spot' section in a BASEfile. Extra value parsers
5093 10 Sep 09 nicklas 29   are created in the first pass and used in the second pass.
5093 10 Sep 09 nicklas 30
5093 10 Sep 09 nicklas 31   @author Nicklas
5093 10 Sep 09 nicklas 32   @version 2.14
5093 10 Sep 09 nicklas 33   @base.modified $Date$
5093 10 Sep 09 nicklas 34 */
5093 10 Sep 09 nicklas 35 public class ExtraFloatParser
5093 10 Sep 09 nicklas 36 {
5093 10 Sep 09 nicklas 37
5093 10 Sep 09 nicklas 38   private final String id;
5093 10 Sep 09 nicklas 39   private final int valueIndex;
5093 10 Sep 09 nicklas 40   
5093 10 Sep 09 nicklas 41   /**
5093 10 Sep 09 nicklas 42     Creates a new extra value parser.
5093 10 Sep 09 nicklas 43     @param id The external id of the extra value type
5093 10 Sep 09 nicklas 44     @param valueIndex The index of the extra value column
5093 10 Sep 09 nicklas 45       relative the first column of assay data
5093 10 Sep 09 nicklas 46   */
5093 10 Sep 09 nicklas 47   public ExtraFloatParser(String id, int valueIndex)
5093 10 Sep 09 nicklas 48   {
5093 10 Sep 09 nicklas 49     this.id = id;
5093 10 Sep 09 nicklas 50     this.valueIndex = valueIndex;
5093 10 Sep 09 nicklas 51   }
5093 10 Sep 09 nicklas 52   
5093 10 Sep 09 nicklas 53   /**
5093 10 Sep 09 nicklas 54     Get the external id of the extra value type.
5093 10 Sep 09 nicklas 55   */
5093 10 Sep 09 nicklas 56   public String getId()
5093 10 Sep 09 nicklas 57   {
5093 10 Sep 09 nicklas 58     return id;
5093 10 Sep 09 nicklas 59   }
5093 10 Sep 09 nicklas 60   
5093 10 Sep 09 nicklas 61   /**
5093 10 Sep 09 nicklas 62     Get the extra value from the data. If the section contains data for 
5093 10 Sep 09 nicklas 63     multiple bioassays (eg. a matrix BASEfile) this method is called multiple 
5093 10 Sep 09 nicklas 64     times (with different 'firstIndex' value) for each row.
5093 10 Sep 09 nicklas 65      
5093 10 Sep 09 nicklas 66     @param data The current data line
5093 10 Sep 09 nicklas 67     @param firstIndex The index of the first data column that contains data
5093 10 Sep 09 nicklas 68       for the current bioassay
5093 10 Sep 09 nicklas 69     @return The extracted float value, or Float.NaN if the
5093 10 Sep 09 nicklas 70       value is invalid (results in not inserting it)
5093 10 Sep 09 nicklas 71   */
5093 10 Sep 09 nicklas 72   public float getValue(FlatFileParser.Data data, int firstIndex)
5093 10 Sep 09 nicklas 73   {
7665 20 Mar 19 nicklas 74     Float f = data.getFloat(valueIndex + firstIndex, null, true);
7665 20 Mar 19 nicklas 75     return f == null ? Float.NaN : f;
5093 10 Sep 09 nicklas 76   }
5093 10 Sep 09 nicklas 77   
5093 10 Sep 09 nicklas 78 }