Changeset 197
 Timestamp:
 Nov 21, 2006, 1:53:52 PM (15 years ago)
 Location:
 trunk/se/lu/onk/ZTest/src/ztest
 Files:

 4 edited
Legend:
 Unmodified
 Added
 Removed

trunk/se/lu/onk/ZTest/src/ztest/Reporter.java
r187 r197 30 30 private double m; 31 31 private double p; 32 private int size; 32 33 33 34 … … 61 62 return m; 62 63 } 64 65 public void setSize(int size) 66 { 67 this.size = size; 68 } 69 70 public int getSize() 71 { 72 return size; 73 } 63 74 } 
trunk/se/lu/onk/ZTest/src/ztest/Spot.java
r187 r197 26 26 public class Spot 27 27 { 28 floatm;28 double m; 29 29 30 public Spot( floatm)30 public Spot(Double m) 31 31 { 32 32 this.m = m; 33 33 } 34 34 35 public final floatgetM()35 public final double getM() 36 36 { 37 37 return m; 38 38 } 39 39 40 @Override 41 public String toString() 42 { 43 return "["+m+"]"; 44 } 45 40 46 41 47 } 
trunk/se/lu/onk/ZTest/src/ztest/Start.java
r187 r197 73 73 { 74 74 int index = mCol + i * assayFields.size(); 75 float m = Float.NaN;75 Double m = Double.NaN; 76 76 if (!data[index].equals("")) 77 77 { 78 m = new Float(data[index]);78 m = new Double(data[index]); 79 79 } 80 80 spots[i] = new Spot(m); … … 130 130 out.println("<meta httpequiv=\"ContentType\" content=\"text/html; charset=ISO88591\" />"); 131 131 out.println("<title>BASE 1.2.16dev  Experiment Enell:Enell Plugin</title>"); 132 out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"base.css\" />"); 132 133 out.println("</head>"); 133 134 out.println("<table>"); 134 out.println("<tr><th>Reporter</th><th>M</th><th>p</th><th>Rank</th><th>Number of expected</th><th>Ratio between expected and observed</th></tr>"); 135 out.println("<tr><th>Reporter</th><th>Average M</th><th>P</th><th>Number of values</th><th>Rank</th<th>Expected</th><th>FDR</th></tr>"); 136 135 137 for (int i = 0; i < bfss.getReporterSize() && i < 100; i++) 136 138 { 139 int rank = i + 1; 137 140 Reporter r = bfss.getReporter(i); 138 int numExpected = (int) (r.getP() * numOfReporters);139 double ratio = numExpected / (i + 1.0);140 141 out.print("<tr >");141 double numExpected = r.getP() * numOfReporters; 142 double fdr = (numExpected / rank); 143 144 out.print("<tr class=\"row"+(i%2+1)+"\">"); 142 145 out.printf( 143 "<td>%1$d</td><td>%2$g</td><td>%3$g</td><td>%4$d</td><td>%5$d</td><td>%6$g</td>", 146 "<td>%d</td>" + 147 "<td>%f</td>" + 148 "<td>%f</td>" + 149 "<td>%d</td>" + 150 "<td>%d</td>" + 151 "<td>%f</td>" + 152 "<td>%.2f</td>", 144 153 r.getReporter(), 145 154 r.getM(), 146 155 r.getP(), 147 i + 1, 156 r.getSize(), 157 rank, 148 158 numExpected, 149 ratio);159 fdr); 150 160 out.println("</tr>"); 151 161 } 
trunk/se/lu/onk/ZTest/src/ztest/ZTest.java
r187 r197 24 24 package ztest; 25 25 26 import java.util.Arrays;27 26 import java.util.HashMap; 28 27 import java.util.List; … … 32 31 public class ZTest 33 32 { 34 33 private int precision = (int) Math.pow(10, 6); 34 35 private int depth = 6; 36 37 private double[] normsdistV; 38 35 39 public void calculate(BASEFileSpotSection<Reporter, Spot> bfss) 36 40 { 41 normsdistV = new double[(precision * depth) + 1]; 37 42 List<Integer> assays = bfss.findFieldIntList("assays"); 38 HashMap<Integer, Float> means = getAssayMeans(bfss, assays); 39 HashMap<Integer, Float> sds = getAssaySDS(bfss, assays, means); 40 43 HashMap<Integer, Double> means = getAssayMeans(bfss, assays); 44 HashMap<Integer, Double> sds = getAssaySDS(bfss, assays, means); 45 46 fillNormsdist(); 47 41 48 for (int i = 0; i < bfss.getReporterSize(); i++) 42 49 { … … 48 55 for (int j = 0; j < assays.size(); j++) 49 56 { 50 double m = bfss.getSpot( i+ j).getM();57 double m = bfss.getSpot((i*assays.size()) + j).getM(); 51 58 if (!Double.isNaN(m)) 52 59 { … … 57 64 } 58 65 } 59 popSD = popSD/ popSize;66 popSD = Math.sqrt(popSD) / popSize; 60 67 popMean = popMean / popSize; 61 68 meanM = meanM / popSize; 62 69 63 70 double z = z(meanM, popMean, popSD); 71 64 72 double normsdist = normsdist(Math.abs(z)); 65 73 double p = p(normsdist); 66 67 bfss.getReporter(i).setP(p); 68 bfss.getReporter(i).setM(meanM); 74 75 Reporter r = bfss.getReporter(i); 76 r.setP(p); 77 r.setM(meanM); 78 r.setSize(popSize); 69 79 } 70 80 } … … 72 82 private double p(double normsdist) 73 83 { 74 return 2 * (1 /normsdist);84 return 2 * (1  normsdist); 75 85 } 76 86 77 87 private double normsdist(double z) 78 88 { 79 return 1 / Math.sqrt(2 * Math.PI) * Math.pow(Math.E, 0.5 * Math.pow(z, 2)); 89 int zz = (int) Math.abs(Math.round(z * precision)); 90 double value; 91 if (z < 0) throw new IllegalArgumentException("normsdist cant handle a negative z score"); 92 else if (z <= (depth  1)) value = normsdistV[zz]; 93 else 94 { 95 value = 1; 96 } 97 return value; 98 } 99 100 private double distribution(double t) 101 { 102 return Math.pow(Math.E, 0.5 * Math.pow(t, 2)) / Math.sqrt(2 * Math.PI); 80 103 } 81 104 … … 84 107 return (x  popMean) / popSD; 85 108 } 109 110 private void fillNormsdist() 111 { 112 normsdistV[0] = 0.5; 113 for (int i = 0; i < normsdistV.length1; i++) 114 { 115 double w = (double)i/precision; 116 normsdistV[i+1] = normsdistV[i] + distribution(w)/precision; 117 } 118 } 86 119 87 private HashMap<Integer, Float> getAssaySDS(BASEFileSpotSection<Reporter, Spot> bfss, List<Integer> assays, HashMap<Integer, Float> means)120 private HashMap<Integer, Double> getAssaySDS(BASEFileSpotSection<Reporter, Spot> bfss, List<Integer> assays, HashMap<Integer, Double> means) 88 121 { 89 int[] size = new int[assays.size()]; 90 float[] sqrSum = new float[assays.size()]; 91 Arrays.fill(sqrSum, 0); 92 93 int count = bfss.findIntOpt("count"); 94 for (int i = 0; i < count; i += assays.size()) 122 HashMap<Integer, Double> sds = new HashMap<Integer, Double>(); 123 for (int i = 0; i < assays.size(); i++) 95 124 { 96 for (int j = 0; j < assays.size(); j++) 125 int size = 0; 126 double sqrSum = 0; 127 for (int j = 0; j < bfss.getSpotSize(); j += assays.size()) 97 128 { 98 floatm = bfss.getSpot(i + j).getM();99 if (! Float.isNaN(m))129 double m = bfss.getSpot(i + j).getM(); 130 if (!Double.isNaN(m)) 100 131 { 101 sqrSum [j] += Math.pow(m  means.get(assays.get(j)), 2);102 size [j]++;132 sqrSum += Math.pow(m  means.get(assays.get(i)), 2); 133 size++; 103 134 } 104 135 } 105 } 106 HashMap<Integer, Float> sds = new HashMap<Integer, Float>(); 107 for (int i = 0; i < assays.size(); i++) 108 { 109 sds.put(assays.get(i), sqrSum[i] / size[i]); 136 sds.put(assays.get(i), Math.sqrt(sqrSum / size)); 110 137 } 111 138 … … 113 140 } 114 141 115 private HashMap<Integer, Float> getAssayMeans(BASEFileSpotSection<Reporter, Spot> bfss, List<Integer> assays)142 private HashMap<Integer, Double> getAssayMeans(BASEFileSpotSection<Reporter, Spot> bfss, List<Integer> assays) 116 143 { 117 int[] size = new int[assays.size()]; 118 float[] sum = new float[assays.size()]; 119 Arrays.fill(sum, 0); 120 121 int count = bfss.findIntOpt("count"); 122 for (int i = 0; i < count; i += assays.size()) 144 HashMap<Integer, Double> means = new HashMap<Integer, Double>(); 145 for (int i = 0; i < assays.size(); i++) 123 146 { 124 for (int j = 0; j < assays.size(); j++) 147 int size = 0; 148 double sum = 0; 149 for (int j = 0; j < bfss.getSpotSize(); j += assays.size()) 125 150 { 126 floatm = bfss.getSpot(i + j).getM();127 if (! Float.isNaN(m))151 double m = bfss.getSpot(i + j).getM(); 152 if (!Double.isNaN(m)) 128 153 { 129 sum [j]+= m;130 size [j]++;154 sum += m; 155 size++; 131 156 } 132 157 } 158 means.put(assays.get(i), sum / size); 133 159 } 134 HashMap<Integer, Float> means = new HashMap<Integer, Float>();135 for (int i = 0; i < assays.size(); i++)136 {137 means.put(assays.get(i), sum[i] / size[i]);138 }139 140 160 return means; 141 161 }
Note: See TracChangeset
for help on using the changeset viewer.