Changeset 246
- Timestamp:
- Mar 13, 2007, 4:20:05 PM (17 years ago)
- Location:
- trunk/se/lu/onk/OneClass/src/oneclass/rankproduct
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/se/lu/onk/OneClass/src/oneclass/rankproduct/RankProduct.java
r244 r246 24 24 package oneclass.rankproduct; 25 25 26 import java.util.Arrays;27 26 import java.util.Comparator; 28 27 … … 31 30 public class RankProduct 32 31 { 33 public void calculate(BASEFileSpotSection<Reporter, Spot> bfss )32 public void calculate(BASEFileSpotSection<Reporter, Spot> bfss, boolean up) 34 33 { 35 // Calucalte assay sizes36 int[] assaySizes = new int[bfss.getWidth()];37 Arrays.fill(assaySizes, bfss.getHeight());38 for (int i = 0; i < bfss.getHeight(); ++i)39 {40 for (int j = 0; j < bfss.getWidth(); ++j)41 {42 if (Double.isNaN(bfss.getSpot(i + j).getM()))43 {44 --assaySizes[j];45 }46 }47 }48 49 34 for (int i = 0; i < bfss.getWidth(); ++i) 50 35 { 51 36 // to be able use i in the comparator it has to be final 52 37 final int finali = i; 38 final boolean finalup = up; 39 53 40 bfss.sortReporter(new Comparator<Reporter>() 54 41 { 55 42 public int compare(Reporter r1, Reporter r2) 56 43 { 57 double s1 = r1.getSpot s()[finali].getM();58 double s2 = r2.getSpot s()[finali].getM();44 double s1 = r1.getSpot(finali).getM(); 45 double s2 = r2.getSpot(finali).getM(); 59 46 60 return Double.compare(s1, s2); 47 int ret = 0; 48 if (!Double.isNaN(s1) && !Double.isNaN(s2)) 49 { 50 ret = Double.compare(s1, s2); 51 if (finalup) 52 ret *= -1; 53 } 54 else if (Double.isNaN(s1) && Double.isNaN(s2)) 55 ret = 0; 56 else if (Double.isNaN(s1)) 57 ret = 1; 58 else if (Double.isNaN(s2)) 59 ret = -1; 60 return ret; 61 61 } 62 62 }); 63 63 64 for (int j = 0; j < assaySizes[i]; ++j) 64 // set the rank 65 for (int j = 0; j < bfss.getHeight(); ++j) 65 66 { 66 Reporter r = bfss.getReporter(j); 67 r.addRank((j+1.0) / assaySizes[i]); 68 if (r.getRankProduct() > 1) 67 Spot s = bfss.getReporter(j).getSpot(i); 68 if (!Double.isNaN(s.getM())) 69 69 { 70 System.err.println(j + " " + assaySizes[i]); 71 System.exit(0); 70 s.setRank(j+1); 72 71 } 73 72 } 74 73 } 75 76 // Calculate M and "size" for each reporter77 for (int i = 0; i < bfss.getHeight(); ++i)78 {79 Reporter r = bfss.getReporter(i);80 double avg = 0;81 int size = 0;82 for (int j = 0; j < bfss.getWidth(); ++j)83 {84 if (!Double.isNaN(r.getSpots()[j].getM()))85 {86 avg = r.getSpots()[j].getM();87 ++size;88 }89 }90 r.setM(avg / size);91 r.setSize(size);92 }93 74 } 94 75 } -
trunk/se/lu/onk/OneClass/src/oneclass/rankproduct/Reporter.java
r244 r246 31 31 private final int id; 32 32 private final Spot[] spots; 33 private double rankProduct = 1;34 33 private double a; 35 private double m ;36 private int size ;34 private double m = 0; 35 private int size = 0;; 37 36 38 37 public Reporter(int id, String reporter, String symbol, String locusLink, double a, Spot ... spots) … … 44 43 this.a = a; 45 44 this.spots = spots; 45 46 for (Spot s : spots) 47 { 48 if (!Double.isNaN(s.getM())) 49 { 50 m += s.getM(); 51 ++size; 52 } 53 } 54 m = m/size; 46 55 } 47 56 … … 68 77 public final double getRankProduct() 69 78 { 70 return rankProduct; 79 double rankProduct = 1; 80 81 for (Spot s : spots) 82 { 83 if (!Double.isNaN(s.getM())) 84 { 85 rankProduct *= s.getRank(); 86 } 87 } 88 89 return Math.pow(rankProduct, 1.0/getSize()); 71 90 } 72 91 … … 74 93 { 75 94 return reporter; 95 } 96 97 public final Spot getSpot(int i) 98 { 99 return spots[i]; 76 100 } 77 101 … … 86 110 } 87 111 88 public void setSize(int size)89 {90 this.size = size;91 }92 93 112 public int getSize() 94 113 { 95 114 return size; 96 115 } 97 98 public final void setM(double m)99 {100 this.m = m;101 }102 103 public void addRank(double rank)104 {105 rankProduct *= rank;106 }107 116 } -
trunk/se/lu/onk/OneClass/src/oneclass/rankproduct/Spot.java
r244 r246 28 28 private double m; 29 29 30 private int rank = -1; 31 30 32 public Spot(Double m) 31 33 { … … 38 40 } 39 41 42 public final int getRank() 43 { 44 return rank; 45 } 46 47 public final void setRank(int rank) 48 { 49 this.rank = rank; 50 } 51 40 52 @Override 41 53 public String toString() -
trunk/se/lu/onk/OneClass/src/oneclass/rankproduct/Start.java
r244 r246 103 103 data = bfr.readDataRow(dataLength); 104 104 } 105 rankproduct.calculate(bfss); 106 bfss.sortReporter(new Comparator<Reporter>() 107 { 108 109 public int compare(Reporter r1, Reporter r2) 110 { 111 if (r1.getRankProduct() < r2.getRankProduct()) return -1; 112 else if (r1.getRankProduct() == r2.getRankProduct()) return 0; 113 else return 1; 114 } 115 }); 116 print(bfss); 117 } 118 catch (FileNotFoundException e) 119 { 120 System.err.println("Can't find the file " + (args.length == 1 ? args[0] : "stdin.txt")); 121 } 122 catch (BadFormatException e) 123 { 124 System.err.println((args.length == 1 ? args[0] : "stdin.txt") + " is not a basefile"); 125 } 126 catch (IOException e) 127 { 128 System.err.println("An error when reading file " + (args.length == 1 ? args[0] : "stdin.txt")); 129 e.printStackTrace(); 130 } 131 catch (BASEFileException e) 132 { 133 e.printStackTrace(); 134 } 135 } 136 137 private static void print(BASEFileSpotSection<Reporter, Spot> bfss) 138 { 139 140 try 141 { 142 XYSeries oSeries = new XYSeries("Observed"); 143 XYSeries eSeries = new XYSeries("Expected"); 144 XYSeries fdrSeries = new XYSeries("FDR"); 145 HistogramDataset mHist = new HistogramDataset("M", 0.1); 146 147 PrintWriter html = new PrintWriter(new File("index.html")); 148 PrintWriter tab = new PrintWriter(new File("result.tsv")); 149 int maxRank = bfss.getHeight(); 150 151 Object[] tableRow = {"Reporter","GeneSymbol","LocusLink","AverageM","up/down","Rank","Rank product","NumberOfValues"}; 152 105 153 106 System.out.println("BASEfile"); 154 107 System.out.println("section\tassays"); … … 157 110 System.out.println("count\t1"); 158 111 System.out.println("%"); 159 System.out.println("1\tztest\t"+bfss.findStringOpt("assays").replaceAll("\t", "/")); 112 System.out.println("1\tRankProduct down\t"+bfss.findStringOpt("assays").replaceAll("\t", "/")); 113 System.out.println("2\tRankProduct up\t"+bfss.findStringOpt("assays").replaceAll("\t", "/")); 160 114 System.out.println(); 115 116 rankproduct.calculate(bfss, false); 117 161 118 System.out.println("section\tspots"); 162 119 System.out.println("channels\t2"); … … 167 124 System.out.println("count\t"+bfss.getReporterSize()); 168 125 System.out.println("%"); 126 127 print(bfss, "down"); 128 129 rankproduct.calculate(bfss, true); 130 131 System.out.println("section\tspots"); 132 System.out.println("channels\t2"); 133 System.out.println("setExtraFloats\tJE_nbrOfElements\tJE_rank\tJE_rankProduct"); 134 System.out.println("assayFields\tl2ratio1_2\tl10intgmean1_2\tJJE_nbrOfElements\tJE_rank\tE_rankProduct"); 135 System.out.println("columns\tposition\treporter\tassayData"); 136 System.out.println("assays\t2"); 137 System.out.println("count\t"+bfss.getReporterSize()); 138 System.out.println("%"); 139 140 print(bfss, "up"); 141 142 } 143 catch (FileNotFoundException e) 144 { 145 System.err.println("Can't find the file " + (args.length == 1 ? args[0] : "stdin.txt")); 146 } 147 catch (BadFormatException e) 148 { 149 System.err.println((args.length == 1 ? args[0] : "stdin.txt") + " is not a basefile"); 150 } 151 catch (IOException e) 152 { 153 System.err.println("An error when reading file " + (args.length == 1 ? args[0] : "stdin.txt")); 154 e.printStackTrace(); 155 } 156 catch (BASEFileException e) 157 { 158 e.printStackTrace(); 159 } 160 } 161 162 private static void print(BASEFileSpotSection<Reporter, Spot> bfss, String prefix) 163 { 164 try 165 { 166 bfss.sortReporter(new Comparator<Reporter>() 167 { 168 public int compare(Reporter r1, Reporter r2) 169 { 170 return Double.compare(r1.getRankProduct(), r2.getRankProduct()); 171 } 172 }); 173 XYSeries oSeries = new XYSeries("Observed"); 174 XYSeries eSeries = new XYSeries("Expected"); 175 XYSeries fdrSeries = new XYSeries("FDR"); 176 HistogramDataset mHist = new HistogramDataset("M", 0.1); 177 178 PrintWriter html = new PrintWriter(new File(prefix+"index.html")); 179 PrintWriter tab = new PrintWriter(new File(prefix+"result.tsv")); 180 181 Object[] tableRow = {"Reporter","GeneSymbol","LocusLink","AverageM","up/down","Rank","Rank product","NumberOfValues"}; 182 169 183 170 184 html.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">"); … … 184 198 int rank = i + 1; 185 199 Reporter r = bfss.getReporter(i); 186 double rankProduct = r.getRankProduct() * maxRank;200 double rankProduct = r.getRankProduct(); 187 201 188 202 System.out.printf("%d\t%d\t", (-1*rank), r.getId()); … … 221 235 tab.close(); 222 236 223 Plot.plotFDR(fdrSeries);224 Plot.plotOE(oSeries, eSeries);225 Plot.plotOE_FDR(oSeries, eSeries, fdrSeries);237 // Plot.plotFDR(fdrSeries); 238 // Plot.plotOE(oSeries, eSeries); 239 // Plot.plotOE_FDR(oSeries, eSeries, fdrSeries); 226 240 // Plot.plotMHist(mHist, ztest.getTotalMean(), ztest.getTotalSD()); 227 241 }
Note: See TracChangeset
for help on using the changeset viewer.