| | 93 | // calculate chromsome, gene.count for genes in list |
|---|
| | 94 | int totalInBagWithLocation = addActual(resultsTable, organismName, bag); |
|---|
| | 95 | |
|---|
| | 96 | // calculate chromsome, gene.count for genes in database |
|---|
| | 97 | int totalInDBWithLocation = addExpected(resultsTable, organismName); |
|---|
| | 98 | |
|---|
| | 99 | // calculate expected gene.count for each chromosome |
|---|
| | 100 | for (String chromosome : resultsTable.keySet()) { |
|---|
| | 101 | double expectedValue = 0; |
|---|
| | 102 | double proportion = 0.0000000000; |
|---|
| | 103 | double totalInDBWithChromosome = (resultsTable.get(chromosome))[2]; |
|---|
| | 104 | |
|---|
| | 105 | if (totalInDBWithChromosome > 0) { |
|---|
| | 106 | proportion = totalInDBWithChromosome / totalInDBWithLocation; |
|---|
| | 107 | } |
|---|
| | 108 | expectedValue = totalInBagWithLocation * proportion; |
|---|
| | 109 | if (resultsTable.get(chromosome) != null) { |
|---|
| | 110 | (resultsTable.get(chromosome))[1] = (int) Math.round(expectedValue); |
|---|
| | 111 | } |
|---|
| | 112 | } |
|---|
| | 113 | |
|---|
| | 114 | // put all data in dataset rendered in graph |
|---|
| | 115 | dataSet = new DefaultCategoryDataset(); |
|---|
| | 116 | for (Iterator<String> iterator = resultsTable.keySet().iterator(); iterator.hasNext();) { |
|---|
| | 117 | String chromosome = iterator.next(); |
|---|
| | 118 | dataSet.addValue((resultsTable.get(chromosome))[0], "Actual", chromosome); |
|---|
| | 119 | dataSet.addValue((resultsTable.get(chromosome))[1], "Expected", chromosome); |
|---|
| | 120 | } |
|---|
| | 121 | } |
|---|
| | 122 | |
|---|
| | 123 | /** |
|---|
| | 124 | * {@inheritDoc} |
|---|
| | 125 | */ |
|---|
| | 126 | public CategoryDataset getDataSet() { |
|---|
| | 127 | return dataSet; |
|---|
| | 128 | } |
|---|
| | 129 | |
|---|
| | 130 | @SuppressWarnings("unchecked") |
|---|
| | 131 | private int addExpected(HashMap<String, int[]> resultsTable, String organismName) |
|---|
| | 132 | throws ClassNotFoundException { |
|---|
| | 133 | |
|---|
| | 134 | // get counts of gene in database for gene |
|---|
| | 135 | Query q = getQuery(organismName, "expected", null); |
|---|
| | 136 | if (q == null) { |
|---|
| | 137 | return 0; |
|---|
| | 138 | } |
|---|
| | 139 | Results res = os.execute(q); |
|---|
| | 140 | Iterator iter = res.iterator(); |
|---|
| | 141 | int grandTotal = 0; |
|---|
| | 142 | |
|---|
| | 143 | while (iter.hasNext()) { |
|---|
| | 144 | ResultsRow resRow = (ResultsRow) iter.next(); |
|---|
| | 145 | |
|---|
| | 146 | String chromosome = (String) resRow.get(0); // chromosome |
|---|
| | 147 | Long geneCount = (java.lang.Long) resRow.get(1); // genecount |
|---|
| | 148 | |
|---|
| | 149 | // record total number of genes for this chromosome |
|---|
| | 150 | (resultsTable.get(chromosome))[2] = geneCount.intValue(); |
|---|
| | 151 | // increase total amount of genes with chromosomes |
|---|
| | 152 | grandTotal += geneCount.intValue(); |
|---|
| | 153 | } |
|---|
| | 154 | |
|---|
| | 155 | return grandTotal; |
|---|
| | 156 | } |
|---|
| | 157 | |
|---|
| | 158 | @SuppressWarnings("unchecked") |
|---|
| | 159 | private int addActual(HashMap<String, int[]> resultsTable, String organismName, |
|---|
| | 160 | InterMineBag bag) |
|---|
| | 161 | throws ClassNotFoundException { |
|---|
| | 162 | // query for chromosome, gene.count for genes in list |
|---|
| 117 | | |
|---|
| 118 | | int grandTotal = addExpected(resultsTable, organismName); |
|---|
| 119 | | |
|---|
| 120 | | for (String chromosome : resultsTable.keySet()) { |
|---|
| 121 | | |
|---|
| 122 | | double expectedValue = 0; |
|---|
| 123 | | double proportion = 0.0000000000; |
|---|
| 124 | | double totalWithChromosome = (resultsTable.get(chromosome))[2]; |
|---|
| 125 | | |
|---|
| 126 | | if (totalWithChromosome > 0) { |
|---|
| 127 | | proportion = totalWithChromosome / grandTotal; |
|---|
| 128 | | } |
|---|
| 129 | | expectedValue = totalInBagWithLocation * proportion; |
|---|
| 130 | | if (resultsTable.get(chromosome) != null) { |
|---|
| 131 | | (resultsTable.get(chromosome))[1] = (int) Math.round(expectedValue); |
|---|
| 132 | | } |
|---|
| 133 | | } |
|---|
| 134 | | |
|---|
| 135 | | dataSet = new DefaultCategoryDataset(); |
|---|
| 136 | | for (Iterator<String> iterator = resultsTable.keySet().iterator(); iterator.hasNext();) { |
|---|
| 137 | | String chromosome = iterator.next(); |
|---|
| 138 | | dataSet.addValue((resultsTable.get(chromosome))[0], "Actual", chromosome); |
|---|
| 139 | | dataSet.addValue((resultsTable.get(chromosome))[1], "Expected", chromosome); |
|---|
| 140 | | } |
|---|
| 141 | | } |
|---|
| 142 | | |
|---|
| 143 | | /** |
|---|
| 144 | | * {@inheritDoc} |
|---|
| 145 | | */ |
|---|
| 146 | | public CategoryDataset getDataSet() { |
|---|
| 147 | | return dataSet; |
|---|
| 148 | | } |
|---|
| 149 | | |
|---|
| 150 | | @SuppressWarnings("unchecked") |
|---|
| 151 | | private int addExpected(HashMap<String, int[]> resultsTable, String organismName) |
|---|
| 152 | | throws ClassNotFoundException { |
|---|
| 153 | | |
|---|
| 154 | | // get counts of gene in database for gene |
|---|
| 155 | | Query q = getQuery(organismName, "expected", null); |
|---|
| 156 | | if (q == null) { |
|---|
| 157 | | return 0; |
|---|
| 158 | | } |
|---|
| 159 | | Results res = os.execute(q); |
|---|
| 160 | | Iterator iter = res.iterator(); |
|---|
| 161 | | int grandTotal = 0; |
|---|
| 162 | | |
|---|
| 163 | | while (iter.hasNext()) { |
|---|
| 164 | | ResultsRow resRow = (ResultsRow) iter.next(); |
|---|
| 165 | | |
|---|
| 166 | | String chromosome = (String) resRow.get(0); // chromosome |
|---|
| 167 | | Long geneCount = (java.lang.Long) resRow.get(1); // genecount |
|---|
| 168 | | |
|---|
| 169 | | (resultsTable.get(chromosome))[2] = geneCount.intValue(); |
|---|
| 170 | | grandTotal += geneCount.intValue(); |
|---|
| 171 | | } |
|---|
| 172 | | |
|---|
| 173 | | return grandTotal; |
|---|
| | 183 | return totalInBagWithLocation; |
|---|