List of usage examples for com.mongodb BasicDBObject BasicDBObject
public BasicDBObject()
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);/*w ww.j ava2s . c om*/ 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 long getChemicalIDFromName(String chemName, boolean caseInsensitive) { BasicDBObject query = new BasicDBObject(); DBObject brenda = new BasicDBObject(); DBObject pubchem = new BasicDBObject(); DBObject synonyms = new BasicDBObject(); if (caseInsensitive) { String escapedName = Pattern.quote(chemName); Pattern regex = Pattern.compile("^" + escapedName + "$", Pattern.CASE_INSENSITIVE); brenda.put("names.brenda", regex); pubchem.put("names.pubchem.values", regex); synonyms.put("names.synonyms", regex); } else {// w w w. j a v a2s . c o m brenda.put("names.brenda", chemName); pubchem.put("names.pubchem.values", chemName); synonyms.put("names.synonyms", chemName); } BasicDBList ors = new BasicDBList(); ors.add(brenda); ors.add(pubchem); ors.add(synonyms); query.put("$or", ors); Long id; DBObject o = this.dbChemicals.findOne(query); if (o != null) id = (Long) o.get("_id"); // checked: db type IS Long else id = -1L; return id; }
From source file:act.server.MongoDB.java
License:Open Source License
public long getChemicalIDFromExactBrendaName(String chemName) { BasicDBObject query = new BasicDBObject(); query.put("names.brenda", chemName.toLowerCase()); Long id;// w w w.ja v a2s. co m DBObject o = this.dbChemicals.findOne(query); if (o != null) id = (Long) o.get("_id"); // checked: db type IS Long else id = -1L; return id; }
From source file:act.server.MongoDB.java
License:Open Source License
public String getChemicalDBJSON(Long uuid) { BasicDBObject query = new BasicDBObject(); query.put("_id", uuid); DBObject o = this.dbChemicals.findOne(query); if (o == null) return null; Set<String> keys = o.keySet(); String json = "{\n"; for (String key : keys) { json += "\t" + key + " : " + o.get(key) + ",\n"; }/*ww w.ja v a 2 s . co m*/ json += "}"; return json; }
From source file:act.server.MongoDB.java
License:Open Source License
public List<Chemical> getChemicalsThatHaveField(String field) { DBObject val = new BasicDBObject(); val.put("$exists", "true"); return constructAllChemicalsFromActData(field, val); }
From source file:act.server.MongoDB.java
License:Open Source License
public List<Chemical> getDrugbankChemicals() { DBObject val = new BasicDBObject(); val.put("$ne", null); String field = "xref.DRUGBANK"; return constructAllChemicalsFromActData(field, val); }
From source file:act.server.MongoDB.java
License:Open Source License
public List<Chemical> getSigmaChemicals() { DBObject val = new BasicDBObject(); val.put("$ne", null); String field = "xref.SIGMA"; return constructAllChemicalsFromActData(field, val); }
From source file:act.server.MongoDB.java
License:Open Source License
public List<Chemical> constructAllChemicalsFromActData(String field, Object val) { return constructAllChemicalsFromActData(field, val, new BasicDBObject()); }
From source file:act.server.MongoDB.java
License:Open Source License
public DBIterator getIdCursorForFakeChemicals() { DBObject fakeRegex = new BasicDBObject(); DBObject abstractInchi = new BasicDBObject(); fakeRegex.put(ChemicalKeywords.INCHI$.MODULE$.toString(), new BasicDBObject(MongoKeywords.REGEX$.MODULE$.toString(), "^InChI=/FAKE")); abstractInchi.put(ChemicalKeywords.INCHI$.MODULE$.toString(), new BasicDBObject(MongoKeywords.REGEX$.MODULE$.toString(), "^InChI=.*R.*")); BasicDBList conditionList = new BasicDBList(); conditionList.add(fakeRegex);// w ww.jav a2s . c om conditionList.add(abstractInchi); BasicDBObject conditions = new BasicDBObject(MongoKeywords.OR$.MODULE$.toString(), conditionList); return getIteratorOverChemicals(conditions, new BasicDBObject(ChemicalKeywords.ID$.MODULE$.toString(), true)); }
From source file:act.server.MongoDB.java
License:Open Source License
private DBCursor constructCursorForMatchingChemicals(String field, Object val, BasicDBObject keys) { DBCursor cur;/*from w w w .j a v a 2s . co m*/ if (field != null) { BasicDBObject query; query = new BasicDBObject(); query.put(field, val); if (keys == null) { cur = this.dbChemicals.find(query); } else { cur = this.dbChemicals.find(query, keys); } } else if (keys != null) { cur = this.dbChemicals.find(new BasicDBObject(), keys); } else { /* Ensure a default ordering when iterating over a whole collection. * This helps maintain result stability and should have minimal performance cost since we're iterating over * the primary keys in their natural order. */ cur = this.dbChemicals.find(DEFAULT_CURSOR_ORDER_BY_ID); } return cur; }