plugins/base1/se.lu.onk/trunk/Normalization/src/lowess/Lowess.java

Code
Comments
Other
Rev Date Author Line
114 16 Jun 06 enell 1 /*
114 16 Jun 06 enell 2  $Id$
114 16 Jun 06 enell 3
114 16 Jun 06 enell 4  Copyright (C) 2006 Johan Enell
114 16 Jun 06 enell 5
114 16 Jun 06 enell 6  This file is part of BASE - BioArray Software Environment.
114 16 Jun 06 enell 7  Available at http://base.thep.lu.se/
114 16 Jun 06 enell 8
114 16 Jun 06 enell 9  BASE is free software; you can redistribute it and/or modify it
114 16 Jun 06 enell 10  under the terms of the GNU General Public License as published by
114 16 Jun 06 enell 11  the Free Software Foundation; either version 2 of the License, or
114 16 Jun 06 enell 12  (at your option) any later version.
114 16 Jun 06 enell 13
114 16 Jun 06 enell 14  BASE is distributed in the hope that it will be useful, but
114 16 Jun 06 enell 15  WITHOUT ANY WARRANTY; without even the implied warranty of
114 16 Jun 06 enell 16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
114 16 Jun 06 enell 17  General Public License for more details.
114 16 Jun 06 enell 18
114 16 Jun 06 enell 19  You should have received a copy of the GNU General Public License
114 16 Jun 06 enell 20  along with this program; if not, write to the Free Software
114 16 Jun 06 enell 21  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
114 16 Jun 06 enell 22  02111-1307, USA.
114 16 Jun 06 enell 23  */
114 16 Jun 06 enell 24 package lowess;
114 16 Jun 06 enell 25
114 16 Jun 06 enell 26 import basefile.BASEFileException;
114 16 Jun 06 enell 27 import basefile.BASEFileReader;
114 16 Jun 06 enell 28 import basefile.BASEFileSection;
114 16 Jun 06 enell 29 import basefile.BASEFileSpotSection;
114 16 Jun 06 enell 30
114 16 Jun 06 enell 31 import java.io.File;
114 16 Jun 06 enell 32 import java.io.IOException;
114 16 Jun 06 enell 33 import java.util.List;
114 16 Jun 06 enell 34
130 09 Aug 06 enell 35 /**
130 09 Aug 06 enell 36  * This is the main class for Lowess normalization where the basefile is parsed
130 09 Aug 06 enell 37  * and each assay is normalized and written to file. The main method will try to
130 09 Aug 06 enell 38  * read from a file specified in the first argument or from the file 'stdin.txt'
130 09 Aug 06 enell 39  * in the execution directory.
130 09 Aug 06 enell 40  * 
130 09 Aug 06 enell 41  * @author Johan Enell, johan.enell@med.lu.se, Dept Oncology
130 09 Aug 06 enell 42  */
114 16 Jun 06 enell 43 public class Lowess
114 16 Jun 06 enell 44 {
114 16 Jun 06 enell 45
114 16 Jun 06 enell 46   /**
130 09 Aug 06 enell 47    * The main method will parse the basefile and normalize each spotsection found. 
130 09 Aug 06 enell 48    * 
114 16 Jun 06 enell 49    * @param args
130 09 Aug 06 enell 50    *        Either nothing or the path to a file. If nothing the program will
130 09 Aug 06 enell 51    *        read from the file 'stdin.txt' in the execution directory.
114 16 Jun 06 enell 52    */
114 16 Jun 06 enell 53   public static void main(String[] args)
114 16 Jun 06 enell 54     throws BASEFileException, IOException
114 16 Jun 06 enell 55   {
114 16 Jun 06 enell 56     BASEFileReader bfr;
114 16 Jun 06 enell 57     if (args.length == 1) bfr = new BASEFileReader(new File(args[0]));
114 16 Jun 06 enell 58     else bfr = new BASEFileReader(new File("stdin.txt"));
114 16 Jun 06 enell 59
114 16 Jun 06 enell 60     BASEFileSection bfs = bfr.readSection(true);
114 16 Jun 06 enell 61     if (!bfs.isType("settings"))
114 16 Jun 06 enell 62     {
114 16 Jun 06 enell 63       throw new BASEFileException("Can't find section settings");
114 16 Jun 06 enell 64     }
114 16 Jun 06 enell 65
114 16 Jun 06 enell 66     int groupSize = bfs.findIntOpt("block_group_size");
114 16 Jun 06 enell 67
130 09 Aug 06 enell 68     Normalizer norm = new Normalizer(
130 09 Aug 06 enell 69       bfs.findFloatOpt("fit_fraction"),
130 09 Aug 06 enell 70       bfs.findFloatOpt("min_x_step"),
130 09 Aug 06 enell 71       bfs.findIntOpt("n_iter"),
130 09 Aug 06 enell 72       bfs.findStringOpt("mode"),
130 09 Aug 06 enell 73       bfs.findStringOpts("reporters", "\\|"));
114 16 Jun 06 enell 74     System.out.println("BASEfile");
114 16 Jun 06 enell 75     BASEFileSpotSection<Reporter, Spot> bfss = bfr.readSpotSection();
114 16 Jun 06 enell 76     while (bfss != null)
114 16 Jun 06 enell 77     {
114 16 Jun 06 enell 78       List<String> columns = bfss.findFieldList("columns");
114 16 Jun 06 enell 79       List<String> assayFields = bfss.findFieldList("assayFields");
114 16 Jun 06 enell 80
114 16 Jun 06 enell 81       int posCol = columns.indexOf("position");
114 16 Jun 06 enell 82       int dataCol = columns.indexOf("assayData");
114 16 Jun 06 enell 83       int repCol = columns.indexOf("reporter");
114 16 Jun 06 enell 84       int repIdCol = columns.indexOf("reporterId");
114 16 Jun 06 enell 85       int mCol = assayFields.indexOf("l2ratio1_2") + dataCol;
114 16 Jun 06 enell 86       int aCol = assayFields.indexOf("l10intgmean1_2") + dataCol;
114 16 Jun 06 enell 87       int blockCol = assayFields.indexOf("block") + dataCol;
114 16 Jun 06 enell 88
114 16 Jun 06 enell 89       bfss.setDataMatrix(bfss.findIntOpt("count"), 1);
114 16 Jun 06 enell 90
114 16 Jun 06 enell 91       String[] data = bfr.readDataRow(6);
114 16 Jun 06 enell 92       while (data != null)
114 16 Jun 06 enell 93       {
114 16 Jun 06 enell 94         Reporter r = new Reporter(Integer.parseInt(data[posCol]), Integer.parseInt(data[repCol]), data[repIdCol]);
114 16 Jun 06 enell 95         Spot s;
114 16 Jun 06 enell 96         if (blockCol == -1)
114 16 Jun 06 enell 97         {
114 16 Jun 06 enell 98           s = new Spot(r, Float.parseFloat(data[mCol]), Float.parseFloat(data[aCol]));
114 16 Jun 06 enell 99         }
114 16 Jun 06 enell 100         else
114 16 Jun 06 enell 101         {
130 09 Aug 06 enell 102           s = new Spot(
130 09 Aug 06 enell 103             r,
130 09 Aug 06 enell 104             Float.parseFloat(data[mCol]),
130 09 Aug 06 enell 105             Float.parseFloat(data[aCol]),
114 16 Jun 06 enell 106             (int) Math.ceil(Float.parseFloat(data[blockCol]) / groupSize));
114 16 Jun 06 enell 107         }
114 16 Jun 06 enell 108         bfss.addData(r, s);
114 16 Jun 06 enell 109
114 16 Jun 06 enell 110         data = bfr.readDataRow(6);
114 16 Jun 06 enell 111       }
114 16 Jun 06 enell 112       norm.normalize(bfss);
114 16 Jun 06 enell 113
114 16 Jun 06 enell 114       bfss.setHeader("columns", "position", "reporter", "assayData");
114 16 Jun 06 enell 115       bfss.setHeader("assayFields", "l2ratio1_2", "l10intgmean1_2");
114 16 Jun 06 enell 116       System.out.println(bfss);
114 16 Jun 06 enell 117       for (int i = 0; i < bfss.getHeight(); i++)
114 16 Jun 06 enell 118       {
114 16 Jun 06 enell 119         System.out.println(bfss.getSpot(i).getReporter() + "\t" + bfss.getSpot(i));
114 16 Jun 06 enell 120       }
114 16 Jun 06 enell 121       System.out.println();
114 16 Jun 06 enell 122       bfss = bfr.readSpotSection();
114 16 Jun 06 enell 123     }
114 16 Jun 06 enell 124   }
114 16 Jun 06 enell 125 }