Changeset 20773

Show
Ignore:
Timestamp:
03/03/10 10:57:35 (6 months ago)
Author:
julie
Message:

restore optimised method

Files:

Legend:

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

    r20767 r20773  
    2121import org.intermine.api.profile.Profile; 
    2222import org.intermine.api.query.PathQueryExecutor; 
     23import org.intermine.api.query.WebResultsExecutor; 
    2324import org.intermine.api.results.ExportResultsIterator; 
    2425import org.intermine.api.results.ResultElement; 
     
    2829import org.intermine.objectstore.ObjectStoreException; 
    2930import org.intermine.pathquery.Constraints; 
     31import org.intermine.pathquery.Path; 
     32import org.intermine.pathquery.PathException; 
    3033import org.intermine.pathquery.PathQuery; 
    3134import org.intermine.web.logic.bag.BagConverter; 
    3235import org.intermine.web.logic.config.WebConfig; 
     36import org.intermine.web.logic.pathqueryresult.PathQueryResultHelper; 
    3337 
    3438/** 
     
    176180    @Override 
    177181    public WebResults getConvertedObjects(Profile profile, List<Integer> fromList, String type, 
    178             String parameters) { 
    179         // TODO Auto-generated method stub 
    180         return null; 
     182            String parameters) throws ObjectStoreException, PathException { 
     183 
     184        PathQuery q = new PathQuery(model); 
     185        List<Path> view = PathQueryResultHelper.getDefaultView(type, model, webConfig, 
     186                "Gene.homologues.homologue", false); 
     187        view = getFixedView(view); 
     188        q.setViewPaths(view); 
     189 
     190        List<InterMineObject> objectList = im.getObjectStore().getObjectsByIds(fromList); 
     191 
     192        // gene 
     193        q.addConstraint("Gene", Constraints.in(objectList)); 
     194 
     195        // organism 
     196        q.addConstraint("Gene.homologues.homologue.organism", Constraints.lookup(parameters)); 
     197 
     198        // homologue.type = "orthologue" 
     199        q.addConstraint("Gene.homologues.type", Constraints.eq("orthologue")); 
     200 
     201        q.setConstraintLogic("A and B and C"); 
     202        q.syncLogicExpression("and"); 
     203        WebResultsExecutor executor = im.getWebResultsExecutor(profile); 
     204 
     205        return executor.execute(q); 
     206    } 
     207     
     208    /** 
     209     *If view contains joined organism, this will make sure, that 
     210     * organism is joined as a inner join. Else constraint on organism doesn't work. 
     211     * @param pathQuery 
     212     * @param joinPath 
     213     * @throws PathException 
     214     * */ 
     215    private List<Path> getFixedView(List<Path> view) throws PathException { 
     216        String invalidPath = "Gene.homologues.homologue:organism"; 
     217        String validPath = "Gene.homologues.homologue.organism"; 
     218        List<Path> ret = new ArrayList<Path>(); 
     219        for (Path path : view) { 
     220            if (path.toString().contains(invalidPath)) { 
     221                String newPathString = path.toString().replace(invalidPath, validPath); 
     222                path = new Path(path.getModel(), newPathString); 
     223            } 
     224            ret.add(path); 
     225        } 
     226        return ret; 
    181227    } 
    182228}