List of usage examples for com.mongodb DBCursor hasNext
@Override public boolean hasNext()
From source file:act.server.MongoDB.java
License:Open Source License
public List<Long> getRxnsWithEnzyme(String enzyme, Long org, List<Long> substrates) { BasicDBObject query = new BasicDBObject(); query.put("ecnum", enzyme); query.put("organisms.id", org); for (Long substrate : substrates) { BasicDBObject mainQuery = new BasicDBObject(); mainQuery.put("$ne", substrate); BasicDBList queryList = new BasicDBList(); BasicDBObject productQuery = new BasicDBObject(); productQuery.put("enz_summary.products.pubchem", mainQuery); BasicDBObject substrateQuery = new BasicDBObject(); substrateQuery.put("enz_summary.substrates.pubchem", mainQuery); queryList.add(substrateQuery);// w ww .j ava2 s. co m queryList.add(productQuery); query.put("$or", queryList); } DBCursor cur = this.dbReactions.find(query); List<Long> reactions = new ArrayList<Long>(); while (cur.hasNext()) { DBObject o = cur.next(); long id = (Integer) o.get("_id"); // checked: db type IS int reactions.add(id); } cur.close(); return reactions; }
From source file:act.server.MongoDB.java
License:Open Source License
public List<Long> getRxnsWithSubstrate(String enzyme, Long org, List<Long> substrates) { BasicDBObject query = new BasicDBObject(); query.put("organisms.id", org); BasicDBObject enzymeQuery = new BasicDBObject(); enzymeQuery.put("ecnum", enzyme); query.put("$ne", enzymeQuery); for (Long substrate : substrates) { BasicDBList queryList = new BasicDBList(); DBObject querySubstrate = new BasicDBObject(); querySubstrate.put("enz_summary.substrates.pubchem", substrate); DBObject queryProduct = new BasicDBObject(); queryProduct.put("enz_summary.products.pubchem", substrate); queryList.add(querySubstrate);//from w w w . j a va 2 s . c o m queryList.add(queryProduct); query.put("$or", queryList); } DBCursor cur = this.dbReactions.find(query); List<Long> reactions = new ArrayList<Long>(); while (cur.hasNext()) { DBObject o = cur.next(); long id = (Integer) o.get("_id"); // checked: db type IS int reactions.add(id); } cur.close(); return reactions; }
From source file:act.server.MongoDB.java
License:Open Source License
public List<Chemical> constructAllChemicalsFromActData(String field, Object val, BasicDBObject keys) { DBCursor cur = constructCursorForMatchingChemicals(field, val, keys); List<Chemical> chems = new ArrayList<Chemical>(); while (cur.hasNext()) chems.add(convertDBObjectToChemical(cur.next())); cur.close();//from ww w.ja va 2 s. c o m return chems; }
From source file:act.server.MongoDB.java
License:Open Source License
public Map<String, Long> constructAllInChIs() { Map<String, Long> chems = new HashMap<String, Long>(); BasicDBObject keys = new BasicDBObject(); keys.append("_id", true); keys.append("InChI", true); DBCursor cur = constructCursorForMatchingChemicals(null, null, keys); while (cur.hasNext()) { DBObject o = cur.next();/*from w w w . j a v a 2 s . c o m*/ long uuid = (Long) o.get("_id"); // checked: db type IS long String inchi = (String) o.get("InChI"); chems.put(inchi, uuid); } cur.close(); return chems; }
From source file:act.server.MongoDB.java
License:Open Source License
public void smartsMatchAllChemicals(String target) { Indigo indigo = new Indigo(); IndigoInchi inchi = new IndigoInchi(indigo); IndigoObject query = indigo.loadSmarts(target); query.optimize();/* w w w .j a v a2 s . com*/ DBCursor cur = constructCursorForAllChemicals(); IndigoObject mol = null, matcher; int cnt; while (cur.hasNext()) { Chemical c = convertDBObjectToChemical(cur.next()); try { mol = inchi.loadMolecule(c.getInChI()); } catch (IndigoException e) { if (e.getMessage().startsWith("core: Indigo-InChI: InChI loading failed:")) continue; // could not load } matcher = indigo.substructureMatcher(mol); if ((cnt = matcher.countMatches(query)) > 0) { // matches.add(c); memout's System.out.format("%d\t%s\n", c.getUuid(), c.getInChI()); } } cur.close(); }
From source file:act.server.MongoDB.java
License:Open Source License
public Set<Reaction> getReactionsConstrained(Map<String, Object> equalityCriteria) { BasicDBList andList = new BasicDBList(); for (String k : equalityCriteria.keySet()) { BasicDBObject query = new BasicDBObject(); query.put(k, equalityCriteria.get(k)); andList.add(query);// w w w .j a v a 2 s . co m } BasicDBObject query = new BasicDBObject(); query.put("$and", andList); DBCursor cur = this.dbReactions.find(query); Set<Reaction> results = new HashSet<Reaction>(); while (cur.hasNext()) { results.add(convertDBObjectToReaction(cur.next())); } return results; }
From source file:act.server.MongoDB.java
License:Open Source License
private List<Chemical> keywordInChemicals(String in_field, String keyword) { List<Chemical> chemicals = new ArrayList<Chemical>(); DBCursor cur = constructCursorForMatchingChemicals(in_field, keyword, null); while (cur.hasNext()) { DBObject o = cur.next();/*from w ww .ja va 2 s .c o m*/ chemicals.add(convertDBObjectToChemical(o)); } cur.close(); return chemicals; }
From source file:act.server.MongoDB.java
License:Open Source License
private List<Seq> keywordInSequence(String in_field, String keyword) { List<Seq> seqs = new ArrayList<Seq>(); BasicDBObject query = new BasicDBObject(); query.put(in_field, keyword);/*from www. ja v a2s . c o m*/ BasicDBObject keys = new BasicDBObject(); DBCursor cur = this.dbSeq.find(query, keys); while (cur.hasNext()) { DBObject o = cur.next(); seqs.add(convertDBObjectToSeq(o)); } cur.close(); return seqs; }
From source file:act.server.MongoDB.java
License:Open Source License
private List<DBObject> keywordInCascade(String in_field, String keyword) { List<DBObject> cascades = new ArrayList<DBObject>(); BasicDBObject query = new BasicDBObject(); query.put(in_field, keyword);/* w w w . j ava2s. c o m*/ BasicDBObject keys = new BasicDBObject(); DBCursor cur = this.dbCascades.find(query, keys); while (cur.hasNext()) { DBObject o = cur.next(); cascades.add(convertDBObjectToCascade(o)); } cur.close(); return cascades; }
From source file:act.server.MongoDB.java
License:Open Source License
private List<DBObject> keywordInWaterfall(String in_field, String keyword) { List<DBObject> waterfalls = new ArrayList<DBObject>(); BasicDBObject query = new BasicDBObject(); query.put(in_field, keyword);//from w ww . j a v a 2 s . co m BasicDBObject keys = new BasicDBObject(); DBCursor cur = this.dbWaterfalls.find(query, keys); while (cur.hasNext()) { DBObject o = cur.next(); waterfalls.add(convertDBObjectToWaterfall(o)); } cur.close(); return waterfalls; }