Changeset 20762


Ignore:
Timestamp:
02/03/10 12:47:01 (2 years ago)
Author:
julie
Message:

fix query for local orthologues

Location:
trunk/bio
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/bio/tools/main/.classpath

    r16977 r20762  
    88    <classpathentry combineaccessrules="false" kind="src" path="/intermine-web"/> 
    99    <classpathentry kind="lib" path="/intermine-web/lib/struts.jar"/> 
     10    <classpathentry combineaccessrules="false" kind="src" path="/intermine-api-main"/> 
    1011    <classpathentry kind="output" path="bin"/> 
    1112</classpath> 
  • trunk/bio/tools/main/src/org/intermine/bio/logic/OrthologueLinkManager.java

    r20728 r20762  
    2626import org.apache.commons.lang.StringUtils; 
    2727import org.apache.log4j.Logger; 
     28import org.intermine.api.InterMineAPI; 
     29import org.intermine.model.bio.DataSet; 
     30import org.intermine.model.bio.Gene; 
     31import org.intermine.model.bio.Homologue; 
     32import org.intermine.model.bio.Organism; 
     33import org.intermine.objectstore.query.ConstraintOp; 
     34import org.intermine.objectstore.query.ConstraintSet; 
     35import org.intermine.objectstore.query.ContainsConstraint; 
     36import org.intermine.objectstore.query.Query; 
     37import org.intermine.objectstore.query.QueryClass; 
     38import org.intermine.objectstore.query.QueryCollectionReference; 
     39import org.intermine.objectstore.query.QueryField; 
     40import org.intermine.objectstore.query.QueryObjectReference; 
     41import org.intermine.objectstore.query.Results; 
     42import org.intermine.objectstore.query.ResultsRow; 
    2843import org.intermine.util.PropertiesUtil; 
    2944 
     
    5671    private static final String WEB_SERVICE_CONSTRAINT = 
    5772        "constraint1=Gene.primaryIdentifier&op1=eq&value1=*"; 
     73    private static InterMineAPI im = null; 
    5874 
    5975/** 
    6076 * @param webProperties the web properties 
    6177 */ 
    62     public OrthologueLinkManager(Properties webProperties) { 
    63  
     78    public OrthologueLinkManager(InterMineAPI im, Properties webProperties) { 
     79        this.im = im; 
    6480        String localMineName = webProperties.getProperty("project.title"); 
    6581 
     
    7490     * @return OrthologueLinkManager the link manager 
    7591     */ 
    76     public static synchronized OrthologueLinkManager getInstance(Properties webProperties) { 
     92    public static synchronized OrthologueLinkManager getInstance(InterMineAPI im, 
     93            Properties webProperties) { 
    7794        if (orthologueLinkManager == null) { 
    78             orthologueLinkManager = new OrthologueLinkManager(webProperties); 
     95            orthologueLinkManager = new OrthologueLinkManager(im, webProperties); 
    7996        } 
    8097        primeCache(); 
     
    87104    public static synchronized void primeCache() { 
    88105        long timeSinceLastRefresh = System.currentTimeMillis() - lastCacheRefresh; 
    89         // TODO hardcoded for testing. 
     106        // FIXME hardcoded for testing. 
     107        // if release version is different, update homologue mappings in cache 
    90108        if (timeSinceLastRefresh > ONE_HOUR || DEBUG) { 
    91             // if release version is different, update homologue mappings in cache 
     109            lastCacheRefresh = System.currentTimeMillis(); 
    92110            updateMaps(); 
    93             lastCacheRefresh = System.currentTimeMillis(); 
    94111        } 
    95112    } 
     
    175192        // check if local mine has orthologues for genes in this remote mine 
    176193        // has to be done last so we know which genes to check for 
    177         checkLocalOrthologues(mine); 
     194        getLocalOrthologues(mine); 
    178195    } 
    179196 
     
    217234                localMine.setUrl(url); 
    218235                localMine.setLogo(logo); 
    219 //                setOrganisms(localMine); 
    220                 setOrthologues(localMine); 
     236                setLocalOrthologues(); 
    221237                // skip, this is the local intermine. 
    222238                continue; 
     
    265281        mine.setOrganisms(names); 
    266282        return !names.isEmpty(); 
     283    } 
     284 
     285    private static void setLocalOrthologues() { 
     286 
     287            Map<String, Map<String, Set[]>> orthologues = null; 
     288 
     289            Query q = new Query(); 
     290 
     291            QueryClass qcGene = new QueryClass(Gene.class); 
     292            QueryClass qcOrganism = new QueryClass(Organism.class); 
     293            QueryClass qcHomologue = new QueryClass(Homologue.class); 
     294            QueryClass qcHomologueOrganism = new QueryClass(Organism.class); 
     295            QueryClass qcDataset = new QueryClass(DataSet.class); 
     296 
     297            QueryField qfGeneOrganismName = new QueryField(qcOrganism, "shortName"); 
     298            QueryField qfDataset = new QueryField(qcDataset, "title"); 
     299            QueryField qfHomologueOrganismName = new QueryField(qcHomologueOrganism, "shortName"); 
     300 
     301            q.setDistinct(true); 
     302 
     303            q.addToSelect(qfGeneOrganismName); 
     304            q.addToSelect(qfDataset); 
     305            q.addToOrderBy(qfHomologueOrganismName); 
     306 
     307            q.addFrom(qcGene); 
     308            q.addFrom(qcHomologue); 
     309            q.addFrom(qcOrganism); 
     310            q.addFrom(qcHomologueOrganism); 
     311            q.addFrom(qcDataset); 
     312 
     313            ConstraintSet cs = new ConstraintSet(ConstraintOp.AND); 
     314 
     315            // gene.organism.name 
     316            QueryObjectReference c1 = new QueryObjectReference(qcGene, "organism"); 
     317            cs.addConstraint(new ContainsConstraint(c1, ConstraintOp.CONTAINS, qcOrganism)); 
     318 
     319            // gene.homologues.homologue 
     320            QueryCollectionReference c2 = new QueryCollectionReference(qcGene, "homologues"); 
     321            cs.addConstraint(new ContainsConstraint(c2, ConstraintOp.CONTAINS, qcHomologue)); 
     322 
     323            // gene.homologues.homologue.datasets.title 
     324            QueryCollectionReference c3 = new QueryCollectionReference(qcHomologue, "dataSets"); 
     325            cs.addConstraint(new ContainsConstraint(c3, ConstraintOp.CONTAINS, qcDataset)); 
     326 
     327            // gene.homologues.homologue.organism.shortName 
     328            QueryObjectReference c4 = new QueryObjectReference(qcHomologue, "organism"); 
     329            cs.addConstraint(new ContainsConstraint(c4, ConstraintOp.CONTAINS, 
     330                    qcHomologueOrganism)); 
     331 
     332            q.setConstraint(cs); 
     333 
     334            Results results = im.getObjectStore().execute(q); 
     335            Iterator it = results.iterator(); 
     336            while (it.hasNext()) { 
     337 
     338                ResultsRow row = (ResultsRow) it.next(); 
     339 
     340                String geneOrganismName = (String) row.get(0); 
     341                String dataset = (String) row.get(1); 
     342                String homologueOrganismName = (String) row.get(1); 
     343 
     344                /** 
     345                 * gene --> homologue --> datasets 
     346                 * 
     347                 * D. rerio | H. sapiens        |   treefam 
     348                 *          |                   |   inparanoid 
     349                 *          | C. elegans        |   treefam 
     350                 */ 
     351 
     352                // gene --> homologue|dataset 
     353                Map<String, Set[]> homologueMapping = orthologues.get(geneOrganismName); 
     354                if (homologueMapping == null) { 
     355                    homologueMapping = new HashMap(); 
     356                    orthologues.put(geneOrganismName, homologueMapping); 
     357                } 
     358 
     359                // homologue --> datasets 
     360                Set[] datasets = homologueMapping.get(homologueOrganismName); 
     361                if (datasets == null) { 
     362                    datasets = new HashSet[2]; 
     363                    datasets[1] = new HashSet(); 
     364                    homologueMapping.put(homologueOrganismName, datasets); 
     365                } 
     366                datasets[1].add(dataset); 
     367            } 
     368            localMine.setOrthologues(orthologues); 
    267369    } 
    268370 
     
    415517     * NB this assumes the remote mine has its orthologues populated already 
    416518     */ 
    417     private static void checkLocalOrthologues(Mine mine) { 
     519    private static void getLocalOrthologues(Mine mine) { 
    418520 
    419521        // list of organisms for which this mine has genes. 
  • trunk/bio/webapp/src/org/intermine/bio/web/OrthologueLinkController.java

    r20698 r20762  
    6161         
    6262        OrthologueLinkManager orthologueLinkManager 
    63         = OrthologueLinkManager.getInstance(webProperties); 
     63        = OrthologueLinkManager.getInstance(im, webProperties); 
    6464        Collection<String> organismNamesInBag = BioUtil.getOrganisms(im.getObjectStore(), bag,  
    6565                false, "shortName"); 
Note: See TracChangeset for help on using the changeset viewer.