Changeset 17094

Show
Ignore:
Timestamp:
10/10/08 14:37:33 (3 months ago)
Author:
julie
Message:

Use actual class of object instead of LocatedSequenceFeature? otherwise the queries return the wrong totals. Fixes #1887. We need to find another way to speed up this widget though.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/bio/webapp/src/org/intermine/bio/web/widget/ChromosomeDistributionDataSetLdr.java

    r15898 r17094  
    1919 
    2020import org.flymine.model.genomic.Chromosome; 
    21 import org.flymine.model.genomic.LocatedSequenceFeature; 
    2221import org.flymine.model.genomic.Organism; 
    2322import org.intermine.bio.web.logic.BioUtil; 
     
    7978        chromosomeList = BioUtil.getChromosomes(os, Arrays.asList(organismName.toLowerCase()), 
    8079                                                false); 
    81  
     80        // used for not analysed figure 
    8281        calcTotal(bag, organismName); 
    8382 
    84         /* initialise results list - so all chromosomes are displayed */ 
     83        // initialise results list - so all chromosomes are displayed 
    8584        for (Iterator<String> chrIter = chromosomeList.iterator(); chrIter.hasNext();) { 
    8685            String chromosomeName = chrIter.next(); 
    8786            int[] count = new int[3]; 
    88             count[0] = 0;   // actual 
     87            count[0] = 0;   // actual - total in bag 
    8988            count[1] = 0;   // expected 
    90             count[2] = 0;   // total 
     89            count[2] = 0;   // total in database 
    9190            resultsTable.put(chromosomeName, count); 
    9291        } 
    9392 
     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 
    94163        Query q = getQuery(organismName, "actual", bag); 
    95  
    96         if (q == null) { 
    97             return; 
    98         } 
    99  
    100164        results = os.execute(q); 
    101165        results.setBatchSize(50000); 
     
    112176            String chromosome = (String) resRow.get(0); 
    113177            Long geneCount = (java.lang.Long) resRow.get(1); 
     178            // set the gene.count for genes in this bag with this chromosome 
    114179            (resultsTable.get(chromosome))[0] = geneCount.intValue(); 
     180            // increase total 
    115181            totalInBagWithLocation += geneCount.intValue(); 
    116182        } 
    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; 
    174184    } 
    175185 
     
    180190        QueryClass chromosomeQC = new QueryClass(Chromosome.class); 
    181191        Class<?> bagCls = Class.forName(model.getPackageName() + "." + bagType); 
    182         QueryClass featureQC; 
    183  
     192        QueryClass featureQC = new QueryClass(bagCls); 
     193 
     194        /* TODO we need to figure out another way to do this, this returns the wrong data */ 
    184195        // query LocatedSequenceFeature if possible for better chance of using precompute 
    185         if (LocatedSequenceFeature.class.isAssignableFrom(bagCls)) { 
    186             featureQC = new QueryClass(LocatedSequenceFeature.class); 
    187         } else { 
    188             featureQC = new QueryClass(bagCls); 
    189         } 
     196//        if (LocatedSequenceFeature.class.isAssignableFrom(bagCls)) { 
     197//            featureQC = new QueryClass(LocatedSequenceFeature.class); 
     198//        } else { 
     199//            featureQC = new QueryClass(bagCls); 
     200//        } 
    190201 
    191202        QueryField chromoQF = new QueryField(chromosomeQC, "primaryIdentifier");