plugins/base1/se.lu.onk/trunk/OneClass/src/oneclass/rankproduct/RankProduct.java

Code
Comments
Other
Rev Date Author Line
244 01 Mar 07 enell 1 /*
244 01 Mar 07 enell 2  $Id$
244 01 Mar 07 enell 3
244 01 Mar 07 enell 4  Copyright (C) 2006 Johan Enell
244 01 Mar 07 enell 5
244 01 Mar 07 enell 6  This file is part of BASE - BioArray Software Environment.
244 01 Mar 07 enell 7  Available at http://base.thep.lu.se/
244 01 Mar 07 enell 8
244 01 Mar 07 enell 9  BASE is free software; you can redistribute it and/or modify it
244 01 Mar 07 enell 10  under the terms of the GNU General Public License as published by
244 01 Mar 07 enell 11  the Free Software Foundation; either version 2 of the License, or
244 01 Mar 07 enell 12  (at your option) any later version.
244 01 Mar 07 enell 13
244 01 Mar 07 enell 14  BASE is distributed in the hope that it will be useful, but
244 01 Mar 07 enell 15  WITHOUT ANY WARRANTY; without even the implied warranty of
244 01 Mar 07 enell 16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
244 01 Mar 07 enell 17  General Public License for more details.
244 01 Mar 07 enell 18
244 01 Mar 07 enell 19  You should have received a copy of the GNU General Public License
244 01 Mar 07 enell 20  along with this program; if not, write to the Free Software
244 01 Mar 07 enell 21  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
244 01 Mar 07 enell 22  02111-1307, USA.
244 01 Mar 07 enell 23  */
244 01 Mar 07 enell 24 package oneclass.rankproduct;
244 01 Mar 07 enell 25
252 10 Apr 07 enell 26 import java.io.File;
252 10 Apr 07 enell 27 import java.io.IOException;
252 10 Apr 07 enell 28 import java.io.PrintWriter;
252 10 Apr 07 enell 29 import java.text.DecimalFormat;
244 01 Mar 07 enell 30 import java.util.Comparator;
252 10 Apr 07 enell 31 import java.util.List;
244 01 Mar 07 enell 32
252 10 Apr 07 enell 33 import basefile.BASEFile;
252 10 Apr 07 enell 34 import basefile.BASEFileAssaySection;
252 10 Apr 07 enell 35 import basefile.BASEFileException;
244 01 Mar 07 enell 36 import basefile.BASEFileSpotSection;
244 01 Mar 07 enell 37
244 01 Mar 07 enell 38 public class RankProduct
244 01 Mar 07 enell 39 {
252 10 Apr 07 enell 40   private final BASEFile<Reporter, Spot> basefile;
252 10 Apr 07 enell 41
252 10 Apr 07 enell 42   private final BASEFile<ReporterOut, SpotOut> basefileOut;
252 10 Apr 07 enell 43   
252 10 Apr 07 enell 44   private final BASEFileSpotSection<Reporter, Spot> bfss;
252 10 Apr 07 enell 45
252 10 Apr 07 enell 46   private final BASEFileSpotSection<ReporterOut, SpotOut> bfssOutDown;
252 10 Apr 07 enell 47   
252 10 Apr 07 enell 48   private final BASEFileSpotSection<ReporterOut, SpotOut> bfssOutUp;
252 10 Apr 07 enell 49   
252 10 Apr 07 enell 50   public RankProduct(BASEFile<Reporter, Spot> basefile) throws BASEFileException
244 01 Mar 07 enell 51   {
252 10 Apr 07 enell 52     this.basefile = basefile;
262 24 Apr 07 enell 53     bfss = this.basefile.getSpotSection();
252 10 Apr 07 enell 54     readAssaySection();
252 10 Apr 07 enell 55     readSpotSection();
252 10 Apr 07 enell 56     
252 10 Apr 07 enell 57     this.basefileOut = new BASEFile<ReporterOut, SpotOut>(new File("stdout.txt"), "rw");
252 10 Apr 07 enell 58     BASEFileAssaySection bfas = new BASEFileAssaySection();
252 10 Apr 07 enell 59     bfas.setAnnotationColumns("");
252 10 Apr 07 enell 60     bfas.setColumns("id", "name", "parents");
252 10 Apr 07 enell 61     bfas.setCount(2);
252 10 Apr 07 enell 62     String parents = bfss.findStringOpt("assays").replaceAll("\t", "/");
252 10 Apr 07 enell 63     bfas.addData("1", "RankProduct down", parents);
252 10 Apr 07 enell 64     bfas.addData("2", "RankProduct up", parents);
252 10 Apr 07 enell 65     basefileOut.setAssaySection(bfas);
252 10 Apr 07 enell 66     
252 10 Apr 07 enell 67     bfssOutDown = new BASEFileSpotSection<ReporterOut, SpotOut>();
252 10 Apr 07 enell 68     bfssOutDown.setChannels(2);
252 10 Apr 07 enell 69     bfssOutDown.setExtraFloats("JE_nbrOfElements", "JE_rank", "JE_rankProduct");
252 10 Apr 07 enell 70     bfssOutDown.setAssayFields("l2ratio1_2", "l10intgmean1_2", "JE_nbrOfElements", "JE_rank", "JE_rankProduct");
252 10 Apr 07 enell 71     bfssOutDown.setColumns("position", "reporter", "assayData");
252 10 Apr 07 enell 72     bfssOutDown.setAssays(1);
252 10 Apr 07 enell 73     bfssOutDown.setCount(bfss.getCount());
252 10 Apr 07 enell 74     basefileOut.addSpotSection(bfssOutDown);
252 10 Apr 07 enell 75     
252 10 Apr 07 enell 76     bfssOutUp = new BASEFileSpotSection<ReporterOut, SpotOut>(bfssOutDown);
252 10 Apr 07 enell 77     bfssOutUp.setAssays(2);
252 10 Apr 07 enell 78     basefileOut.addSpotSection(bfssOutUp);
252 10 Apr 07 enell 79   }
252 10 Apr 07 enell 80
252 10 Apr 07 enell 81   public void calculate() throws BASEFileException
252 10 Apr 07 enell 82   {
252 10 Apr 07 enell 83     ReporterComparator comp = new ReporterComparator(); 
252 10 Apr 07 enell 84     calculateRank(reverse(comp));
252 10 Apr 07 enell 85     calculateRankProduct(bfssOutDown);
252 10 Apr 07 enell 86     calculateRank(comp);
252 10 Apr 07 enell 87     calculateRankProduct(bfssOutUp);
252 10 Apr 07 enell 88   }
252 10 Apr 07 enell 89
252 10 Apr 07 enell 90   private void calculateRank(ReporterComparator comp)
252 10 Apr 07 enell 91   {
252 10 Apr 07 enell 92     for (int i = 0; i < bfss.getAssays().size(); ++i)
244 01 Mar 07 enell 93     {
252 10 Apr 07 enell 94       comp.setSpot(i);
252 10 Apr 07 enell 95       bfss.sortReporter(comp);
252 10 Apr 07 enell 96       int count = countAssay(bfss, i);
252 10 Apr 07 enell 97       int rank = 1;
252 10 Apr 07 enell 98       for (int j = 0; j < bfss.getHeight(); ++j)
252 10 Apr 07 enell 99       {
252 10 Apr 07 enell 100         Spot s = bfss.getReporter(j).getSpot(i);
252 10 Apr 07 enell 101         if (!Double.isNaN(s.getM()))
252 10 Apr 07 enell 102         {
252 10 Apr 07 enell 103           s.setRank((double) rank / (double) count);
252 10 Apr 07 enell 104           ++rank;
252 10 Apr 07 enell 105         }
252 10 Apr 07 enell 106         else
252 10 Apr 07 enell 107         {
252 10 Apr 07 enell 108           s.setRank(Double.NaN);
252 10 Apr 07 enell 109         }
252 10 Apr 07 enell 110       }
252 10 Apr 07 enell 111     }
252 10 Apr 07 enell 112   }
252 10 Apr 07 enell 113
252 10 Apr 07 enell 114   private void calculateRankProduct(BASEFileSpotSection<ReporterOut, SpotOut> bfssOut) throws BASEFileException
252 10 Apr 07 enell 115   {
252 10 Apr 07 enell 116     bfss.sortReporter(new Comparator<Reporter>()
252 10 Apr 07 enell 117     {
252 10 Apr 07 enell 118       public int compare(Reporter r1, Reporter r2)
252 10 Apr 07 enell 119       {
252 10 Apr 07 enell 120         return Double.compare(r1.getRankProduct(), r2.getRankProduct());
252 10 Apr 07 enell 121       }
252 10 Apr 07 enell 122     });
252 10 Apr 07 enell 123     for (int i = 0; i < bfss.getHeight(); ++i)
252 10 Apr 07 enell 124     {
252 10 Apr 07 enell 125       Reporter r = bfss.getReporter(i);
252 10 Apr 07 enell 126       SpotOut sOut = new SpotOut((float)r.getM(), (float)r.getM(), r.getSize(), i+1, (float)r.getRankProduct());
252 10 Apr 07 enell 127       ReporterOut rOut = new ReporterOut(r, sOut);
252 10 Apr 07 enell 128       bfssOut.addData(rOut, sOut);
252 10 Apr 07 enell 129     }
252 10 Apr 07 enell 130   }
255 13 Apr 07 enell 131   
255 13 Apr 07 enell 132   public void print(File dataFolder) throws BASEFileException
252 10 Apr 07 enell 133   {
252 10 Apr 07 enell 134     bfss.sortReporter(new Comparator<Reporter>()
252 10 Apr 07 enell 135     {
252 10 Apr 07 enell 136       public int compare(Reporter r1, Reporter r2)
252 10 Apr 07 enell 137       {
252 10 Apr 07 enell 138         return Double.compare(r1.getRankProduct(), r2.getRankProduct());
252 10 Apr 07 enell 139       }
252 10 Apr 07 enell 140     });
255 13 Apr 07 enell 141     
262 24 Apr 07 enell 142     printTab(0, new File(dataFolder, "rp_up.csv"));
262 24 Apr 07 enell 143     printTab(1, new File(dataFolder, "rp_down.csv"));
262 24 Apr 07 enell 144     printHTML(0, new File(dataFolder, "rp_up.html"));
262 24 Apr 07 enell 145     printHTML(1, new File(dataFolder, "rp_down.html"));
255 13 Apr 07 enell 146     printBASE();
255 13 Apr 07 enell 147   }
252 10 Apr 07 enell 148
255 13 Apr 07 enell 149   private void printTab(int section, File file) throws BASEFileException
252 10 Apr 07 enell 150   {
252 10 Apr 07 enell 151     try
252 10 Apr 07 enell 152     {
252 10 Apr 07 enell 153       PrintWriter tab = new PrintWriter(file);
246 13 Mar 07 enell 154       
252 10 Apr 07 enell 155       List<Integer> assays = this.bfss.getAssays();
252 10 Apr 07 enell 156       String[] tableRow = new String[8 + 2 * basefile.getAssaySection().getCount()];
252 10 Apr 07 enell 157       tableRow[0] = "Reporter"; 
252 10 Apr 07 enell 158       tableRow[1] = "GeneSymbol"; 
252 10 Apr 07 enell 159       tableRow[2] = "LocusLink";
252 10 Apr 07 enell 160       tableRow[3] = "AverageM";
252 10 Apr 07 enell 161       tableRow[4] = "up/down";
252 10 Apr 07 enell 162       tableRow[5] = "Rank";
252 10 Apr 07 enell 163       tableRow[6] = "Rank product"; 
252 10 Apr 07 enell 164       tableRow[7] = "NumberOfValues";
252 10 Apr 07 enell 165       for (int i = 0; i < assays.size(); ++i)
244 01 Mar 07 enell 166       {
252 10 Apr 07 enell 167         int assay = assays.get(i);
252 10 Apr 07 enell 168         tableRow[8 + i] = "log-ratio " + basefile.getAssaySection().getAssayName(assay);
252 10 Apr 07 enell 169         tableRow[8 + i + assays.size()] = "rank " + basefile.getAssaySection().getAssayName(assay);
252 10 Apr 07 enell 170       }
252 10 Apr 07 enell 171       tab.println(formatArray("", "", "\t", tableRow));
255 13 Apr 07 enell 172
255 13 Apr 07 enell 173       BASEFileSpotSection<ReporterOut, SpotOut> bfss = basefileOut.getSpotSection(section);
252 10 Apr 07 enell 174       for (int i = 0; i < bfss.getHeight(); i++)
252 10 Apr 07 enell 175       {
252 10 Apr 07 enell 176         ReporterOut r = bfss.getReporter(i);
252 10 Apr 07 enell 177         SpotOut s = r.getSpot();
252 10 Apr 07 enell 178         tableRow[0] = String.valueOf(r.getId());
252 10 Apr 07 enell 179         tableRow[1] = r.getSymbol();
252 10 Apr 07 enell 180         tableRow[2] = r.getLocusLink();
252 10 Apr 07 enell 181         tableRow[3] = String.valueOf(s.getM());
252 10 Apr 07 enell 182         tableRow[4] = s.getM() > 0 ? "+" : "-";
252 10 Apr 07 enell 183         tableRow[5] = String.valueOf(s.getRank());
252 10 Apr 07 enell 184         tableRow[6] = String.valueOf(s.getRankProduct());
252 10 Apr 07 enell 185         tableRow[7] = String.valueOf(s.getNbrOfElements());
252 10 Apr 07 enell 186         for (int j = 0; j < assays.size(); ++j)
244 01 Mar 07 enell 187         {
252 10 Apr 07 enell 188           Spot ss = r.getReporter().getSpot(j);
252 10 Apr 07 enell 189           tableRow[8 + j] = String.valueOf(ss.getM());
252 10 Apr 07 enell 190           tableRow[8 + j + assays.size()] = String.valueOf(ss.getRank());
244 01 Mar 07 enell 191         }
252 10 Apr 07 enell 192         tab.println(formatArray("", "", "\t", tableRow));
252 10 Apr 07 enell 193       }
252 10 Apr 07 enell 194       tab.close();
252 10 Apr 07 enell 195     }
252 10 Apr 07 enell 196     catch (IOException e)
252 10 Apr 07 enell 197     {
252 10 Apr 07 enell 198       throw new BASEFileException(e);
252 10 Apr 07 enell 199     }
252 10 Apr 07 enell 200   }
252 10 Apr 07 enell 201
255 13 Apr 07 enell 202   public void printHTML(int section, File file) throws BASEFileException
252 10 Apr 07 enell 203   {
252 10 Apr 07 enell 204     try
252 10 Apr 07 enell 205     {
252 10 Apr 07 enell 206       PrintWriter html = new PrintWriter(file);
252 10 Apr 07 enell 207       html.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">");
252 10 Apr 07 enell 208       html.println("<html>");
252 10 Apr 07 enell 209       html.println("<head>");
252 10 Apr 07 enell 210       html.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"base.css\" />");
252 10 Apr 07 enell 211       html.println("</head>");
252 10 Apr 07 enell 212       html.println("<table>");
244 01 Mar 07 enell 213       
252 10 Apr 07 enell 214       String[] tableRow = new String[8];
255 13 Apr 07 enell 215       tableRow[0] = "Reporter";
255 13 Apr 07 enell 216       tableRow[1] = "GeneSymbol";
252 10 Apr 07 enell 217       tableRow[2] = "LocusLink";
252 10 Apr 07 enell 218       tableRow[3] = "AverageM";
252 10 Apr 07 enell 219       tableRow[4] = "up/down";
252 10 Apr 07 enell 220       tableRow[5] = "Rank";
255 13 Apr 07 enell 221       tableRow[6] = "Rank product";
252 10 Apr 07 enell 222       tableRow[7] = "NumberOfValues";
252 10 Apr 07 enell 223       html.println("<tr>" + formatArray("<th>", "</th>", "", tableRow) + "</tr>");
252 10 Apr 07 enell 224
252 10 Apr 07 enell 225       DecimalFormat df = new DecimalFormat("#&nbsp;##0.000");
255 13 Apr 07 enell 226       BASEFileSpotSection<ReporterOut, SpotOut> bfss = basefileOut.getSpotSection(section);
252 10 Apr 07 enell 227       for (int i = 0; i < 1000 && i < bfss.getHeight(); i++)
244 01 Mar 07 enell 228       {
252 10 Apr 07 enell 229         ReporterOut r = bfss.getReporter(i);
252 10 Apr 07 enell 230         SpotOut s = r.getSpot();
252 10 Apr 07 enell 231         tableRow[0] = String.valueOf(r.getId());
252 10 Apr 07 enell 232         tableRow[1] = r.getSymbol();
252 10 Apr 07 enell 233         tableRow[2] = r.getLocusLink();
252 10 Apr 07 enell 234         tableRow[3] = df.format(s.getM());
252 10 Apr 07 enell 235         tableRow[4] = s.getM() > 0 ? "+" : "-";
252 10 Apr 07 enell 236         tableRow[5] = df.format(s.getRank());
252 10 Apr 07 enell 237         tableRow[6] = df.format(s.getRankProduct());
252 10 Apr 07 enell 238         tableRow[7] = df.format(s.getNbrOfElements());
252 10 Apr 07 enell 239         
252 10 Apr 07 enell 240         html.println("<tr class=\"row" + (i % 2 + 1) + "\">" + formatArray("<th>", "</th>", "", tableRow) + "</tr>");
252 10 Apr 07 enell 241       }
252 10 Apr 07 enell 242       html.println("</table>");
252 10 Apr 07 enell 243       html.print("</html>");
252 10 Apr 07 enell 244       html.close();
252 10 Apr 07 enell 245     }
252 10 Apr 07 enell 246     catch (IOException e)
252 10 Apr 07 enell 247     {
252 10 Apr 07 enell 248       throw new BASEFileException(e);
252 10 Apr 07 enell 249     }
252 10 Apr 07 enell 250   }
252 10 Apr 07 enell 251   
252 10 Apr 07 enell 252   public void printBASE() throws BASEFileException
252 10 Apr 07 enell 253   {
252 10 Apr 07 enell 254     basefileOut.write();
252 10 Apr 07 enell 255   }
252 10 Apr 07 enell 256   
252 10 Apr 07 enell 257   private int countAssay(BASEFileSpotSection<Reporter, Spot> bfss, int i)
252 10 Apr 07 enell 258   {
252 10 Apr 07 enell 259     int count = 0;
252 10 Apr 07 enell 260     for (int j = 0; j < bfss.getReporterSize(); ++j)
252 10 Apr 07 enell 261     {
252 10 Apr 07 enell 262       Spot s = bfss.getReporter(j).getSpot(i);
252 10 Apr 07 enell 263       if (!Double.isNaN(s.getM()))
252 10 Apr 07 enell 264       {
252 10 Apr 07 enell 265         ++count;
252 10 Apr 07 enell 266       }
252 10 Apr 07 enell 267     }
252 10 Apr 07 enell 268     return count;
252 10 Apr 07 enell 269   }
252 10 Apr 07 enell 270
252 10 Apr 07 enell 271   private static Object formatArray(String begin, String end, String del, String... array)
252 10 Apr 07 enell 272   {
252 10 Apr 07 enell 273     StringBuffer sb = new StringBuffer();
252 10 Apr 07 enell 274     if (array.length > 0)
252 10 Apr 07 enell 275     {
252 10 Apr 07 enell 276       sb.append(begin + array[0] + end);
252 10 Apr 07 enell 277       for (int i = 1; i < array.length; ++i)
252 10 Apr 07 enell 278       {
252 10 Apr 07 enell 279         sb.append(del);
252 10 Apr 07 enell 280         sb.append(begin);
252 10 Apr 07 enell 281         sb.append(array[i]);
252 10 Apr 07 enell 282         sb.append(end);
252 10 Apr 07 enell 283       }
252 10 Apr 07 enell 284     }
252 10 Apr 07 enell 285     return sb;
252 10 Apr 07 enell 286   }
252 10 Apr 07 enell 287
252 10 Apr 07 enell 288   private void readAssaySection() throws BASEFileException
252 10 Apr 07 enell 289   {
252 10 Apr 07 enell 290     //Read assay section
252 10 Apr 07 enell 291     basefile.setCurrentSection(basefile.getAssaySection());
252 10 Apr 07 enell 292     String[] data = basefile.readData();
252 10 Apr 07 enell 293     while (data != null)
252 10 Apr 07 enell 294     {
252 10 Apr 07 enell 295       basefile.getAssaySection().addData(data);
252 10 Apr 07 enell 296       data = basefile.readData();
252 10 Apr 07 enell 297     }
252 10 Apr 07 enell 298   }
252 10 Apr 07 enell 299   
252 10 Apr 07 enell 300   private void readSpotSection() throws BASEFileException
252 10 Apr 07 enell 301   {    
252 10 Apr 07 enell 302     //Read spot section
252 10 Apr 07 enell 303     int mCol = bfss.getAssayFieldsColIndex("l2ratio1_2");
252 10 Apr 07 enell 304     int aCol = bfss.getAssayFieldsColIndex("l10intgmean1_2");
252 10 Apr 07 enell 305     int repCol = bfss.getColumnsColIndex("reporter");
252 10 Apr 07 enell 306     int repidCol = bfss.getColumnsColIndex("reporterId");
252 10 Apr 07 enell 307     int symCol = bfss.getColumnsColIndex("geneSymbol");
252 10 Apr 07 enell 308     int llCol = bfss.getColumnsColIndex("locusLink");
252 10 Apr 07 enell 309     int assayDataCol = bfss.getColumnsColIndex("assayData");
252 10 Apr 07 enell 310     
252 10 Apr 07 enell 311     mCol += assayDataCol;
252 10 Apr 07 enell 312     aCol += assayDataCol;
252 10 Apr 07 enell 313
252 10 Apr 07 enell 314     int pos = 0;
252 10 Apr 07 enell 315     basefile.setCurrentSection(bfss);
252 10 Apr 07 enell 316     String[] data = basefile.readData();
252 10 Apr 07 enell 317     while (data != null)
252 10 Apr 07 enell 318     {
252 10 Apr 07 enell 319       double a = 0;
252 10 Apr 07 enell 320       int aCount = 0;
252 10 Apr 07 enell 321       Spot[] spots = new Spot[basefile.getAssaySection().getCount()];
252 10 Apr 07 enell 322       for (int i = 0; i < spots.length; i++)
252 10 Apr 07 enell 323       {
252 10 Apr 07 enell 324         int index = i * bfss.getAssayFields().size();
252 10 Apr 07 enell 325         Double m = Double.NaN;
252 10 Apr 07 enell 326         if (!data[mCol + index].equals(""))
244 01 Mar 07 enell 327         {
252 10 Apr 07 enell 328           m = new Double(data[mCol + index]);
244 01 Mar 07 enell 329         }
252 10 Apr 07 enell 330         if (!data[aCol + index].equals(""))
252 10 Apr 07 enell 331         {
252 10 Apr 07 enell 332           a += new Double(data[aCol + index]);
252 10 Apr 07 enell 333           ++aCount;
252 10 Apr 07 enell 334         }
252 10 Apr 07 enell 335         spots[i] = new Spot(m);
244 01 Mar 07 enell 336       }
252 10 Apr 07 enell 337       Reporter r = new Reporter(--pos, new Integer(data[repCol]), data[repidCol], data[symCol], data[llCol], a/aCount, spots);
252 10 Apr 07 enell 338       bfss.addData(r, spots);
252 10 Apr 07 enell 339       data = basefile.readData();
244 01 Mar 07 enell 340     }
252 10 Apr 07 enell 341     
252 10 Apr 07 enell 342     basefile.validate();
244 01 Mar 07 enell 343   }
252 10 Apr 07 enell 344
252 10 Apr 07 enell 345   private ReporterComparator reverse(ReporterComparator comp)
252 10 Apr 07 enell 346   {
252 10 Apr 07 enell 347     return new ReporterComparator()
252 10 Apr 07 enell 348     {
252 10 Apr 07 enell 349       @Override
252 10 Apr 07 enell 350       public int compare(Reporter r1, Reporter r2)
252 10 Apr 07 enell 351       {
252 10 Apr 07 enell 352         return super.compare(r2, r1);
252 10 Apr 07 enell 353       }
252 10 Apr 07 enell 354       
252 10 Apr 07 enell 355     };
252 10 Apr 07 enell 356   }
252 10 Apr 07 enell 357   
252 10 Apr 07 enell 358   private class ReporterComparator implements Comparator<Reporter>
252 10 Apr 07 enell 359   {
252 10 Apr 07 enell 360     int i;
252 10 Apr 07 enell 361
252 10 Apr 07 enell 362     public void setSpot(int i)
252 10 Apr 07 enell 363     {
252 10 Apr 07 enell 364       this.i = i;
252 10 Apr 07 enell 365     }
252 10 Apr 07 enell 366
252 10 Apr 07 enell 367     /*
252 10 Apr 07 enell 368      * Will sort the i'th assay with upregulated first. NaN is
252 10 Apr 07 enell 369      * always sorted last.
252 10 Apr 07 enell 370      */
252 10 Apr 07 enell 371     public int compare(Reporter r1, Reporter r2)
252 10 Apr 07 enell 372     {
252 10 Apr 07 enell 373       double s1 = r1.getSpot(i).getM();
252 10 Apr 07 enell 374       double s2 = r2.getSpot(i).getM();
252 10 Apr 07 enell 375
252 10 Apr 07 enell 376       int ret = 0;
252 10 Apr 07 enell 377       if (!Double.isNaN(s1) && !Double.isNaN(s2))
252 10 Apr 07 enell 378       {
252 10 Apr 07 enell 379         ret = Double.compare(s1, s2);
252 10 Apr 07 enell 380       }
252 10 Apr 07 enell 381       else if (Double.isNaN(s1) && Double.isNaN(s2)) ret = 0;
252 10 Apr 07 enell 382       else if (Double.isNaN(s1)) ret = 1;
252 10 Apr 07 enell 383       else if (Double.isNaN(s2)) ret = -1;
252 10 Apr 07 enell 384       
252 10 Apr 07 enell 385       return ret;
252 10 Apr 07 enell 386     }
252 10 Apr 07 enell 387   }
244 01 Mar 07 enell 388 }