List of usage examples for com.mongodb BasicDBList BasicDBList
BasicDBList
From source file:act.server.MongoDB.java
License:Open Source License
public BasicDBObject createCofactorDoc(Cofactor c, Long ID) { BasicDBObject doc = new BasicDBObject(); doc.put("_id", ID); doc.put("InChI", c.getInChI()); BasicDBList names = new BasicDBList(); names.addAll(c.getNames());/* ww w .j a v a 2s.c o m*/ doc.put("names", names); return doc; }
From source file:act.server.MongoDB.java
License:Open Source License
public static BasicDBObject createChemicalDoc(Chemical c, Long ID) { BasicDBObject doc = new BasicDBObject(); doc.put("_id", ID); doc.put("canonical", c.getCanon()); doc.put("SMILES", c.getSmiles()); doc.put("InChI", c.getInChI()); doc.put("InChIKey", c.getInChIKey()); doc.put("isCofactor", c.isCofactor()); doc.put("isNative", c.isNative()); BasicDBObject names = new BasicDBObject(); BasicDBList synonyms = new BasicDBList(); synonyms.addAll(c.getSynonyms());/* w w w . ja v a2s . c o m*/ names.put("synonyms", synonyms); BasicDBList pubchemNames = new BasicDBList(); for (String type : c.getPubchemNameTypes()) { String[] temp = c.getPubchemNames(type); BasicDBList dbNames = new BasicDBList(); for (String t : temp) { dbNames.add(t); } BasicDBObject dbNameObj = new BasicDBObject(); dbNameObj.put("type", type); dbNameObj.put("values", dbNames); pubchemNames.add(dbNameObj); } names.put("pubchem", pubchemNames); BasicDBList brendaNames = new BasicDBList(); // will really get its fields later if initial install brendaNames.addAll(c.getBrendaNames()); // but for cases where we call it post install, we construct full chem entry names.put("brenda", brendaNames); doc.put("names", names); BasicDBObject xrefs = new BasicDBObject(); xrefs.put("pubchem", c.getPubchemID()); int cnt = 0; for (REFS xrefTyp : Chemical.REFS.values()) { if (c.getRef(xrefTyp) != null) { xrefs.put(xrefTyp.name(), MongoDBToJSON.conv((JSONObject) c.getRef(xrefTyp))); cnt++; } } doc.put("xref", xrefs); doc.put("estimateEnergy", c.getEstimatedEnergy()); doc.put("keywords", c.getKeywords()); doc.put("keywords_case_insensitive", c.getCaseInsensitiveKeywords()); doc.put("csid", c.getChemSpiderID()); doc.put("num_vendors", c.getChemSpiderNumUniqueVendors()); doc.put("vendors", MongoDBToJSON.conv(c.getChemSpiderVendorXrefs())); return doc; }
From source file:act.server.MongoDB.java
License:Open Source License
public void updateChemicalWithRoBinningInformation(long id, List<Integer> matchedROs) { BasicDBObject query = new BasicDBObject("_id", id); BasicDBObject createDerivedDataContainer = new BasicDBObject("$set", new BasicDBObject("derived_data", new BasicDBObject())); this.dbChemicals.update(query, createDerivedDataContainer); BasicDBList listOfRos = new BasicDBList(); listOfRos.addAll(matchedROs);//from w w w . ja v a 2 s . c o m BasicDBObject updateDerivedDataContainerWithMatchedRos = new BasicDBObject("$set", new BasicDBObject("derived_data.matched_ros", listOfRos)); this.dbChemicals.update(query, updateDerivedDataContainerWithMatchedRos); }
From source file:act.server.MongoDB.java
License:Open Source License
public void updateStoichiometry(Reaction r) { BasicDBObject query = new BasicDBObject().append("_id", r.getUUID()); DBObject obj = this.dbReactions.findOne(query); DBObject enz_summary = (DBObject) obj.get("enz_summary"); BasicDBList substrates = (BasicDBList) enz_summary.get("substrates"); BasicDBList newSubstrates = new BasicDBList(); Set<Long> originalSubstrateIDs = new HashSet<Long>(); for (int i = 0; i < substrates.size(); i++) { DBObject substrate = (DBObject) substrates.get(i); Long substrateID = (Long) substrate.get("pubchem"); Boolean isForBalance = (Boolean) substrate.get("balance"); if (isForBalance != null && isForBalance) continue; originalSubstrateIDs.add(substrateID); substrate.put("coefficient", r.getSubstrateCoefficient(substrateID)); newSubstrates.add(substrate);//from w ww. jav a2 s .co m } Set<Long> substratesNew = r.getSubstrateIdsOfSubstrateCoefficients(); for (Long s : substratesNew) { if (originalSubstrateIDs.contains(s)) continue; if (r.getSubstrateCoefficient(s) == null) continue; DBObject substrate = new BasicDBObject(); substrate.put("pubchem", s); substrate.put("coefficient", r.getSubstrateCoefficient(s)); substrate.put("balance", true); newSubstrates.add(substrate); } BasicDBList products = (BasicDBList) enz_summary.get("products"); BasicDBList newProducts = new BasicDBList(); Set<Long> originalProductIDs = new HashSet<Long>(); for (int i = 0; i < products.size(); i++) { DBObject product = (DBObject) products.get(i); Long productID = (Long) product.get("pubchem"); Boolean isForBalance = (Boolean) product.get("balance"); if (isForBalance != null && isForBalance) continue; originalProductIDs.add(productID); product.put("coefficient", r.getProductCoefficient(productID)); newProducts.add(product); } Set<Long> productsNew = r.getProductIdsOfProductCoefficients(); for (Long p : productsNew) { if (originalProductIDs.contains(p)) continue; if (r.getProductCoefficient(p) == null) continue; DBObject product = new BasicDBObject(); product.put("pubchem", p); product.put("coefficient", r.getProductCoefficient(p)); product.put("balance", true); newProducts.add(product); } enz_summary.put("substrates", newSubstrates); enz_summary.put("products", newProducts); this.dbReactions.update(query, obj); }
From source file:act.server.MongoDB.java
License:Open Source License
public void updateReactionRefsOf(Seq seq) { BasicDBObject query = new BasicDBObject().append("_id", seq.getUUID()); DBObject obj = this.dbSeq.findOne(query); BasicDBList refs = new BasicDBList(); for (Long r : seq.getReactionsCatalyzed()) refs.add(r);//from w ww . j a v a 2 s .co m obj.put("rxn_refs", refs); this.dbSeq.update(query, obj); }
From source file:act.server.MongoDB.java
License:Open Source License
public static BasicDBObject createReactionDoc(Reaction r, int id) { BasicDBObject doc = new BasicDBObject(); doc.put("_id", id); doc.put("ecnum", r.getECNum()); doc.put("easy_desc", r.getReactionName()); BasicDBList substr = new BasicDBList(); Long[] ss = r.getSubstrates(); for (int i = 0; i < ss.length; i++) { DBObject o = getObject("pubchem", ss[i]); o.put("coefficient", r.getSubstrateCoefficient(ss[i])); substr.put(i, o);/* w ww. ja v a 2 s .co m*/ } BasicDBList prods = new BasicDBList(); Long[] pp = r.getProducts(); for (int i = 0; i < pp.length; i++) { DBObject o = getObject("pubchem", pp[i]); o.put("coefficient", r.getProductCoefficient(pp[i])); prods.put(i, o); } BasicDBList prodCofactors = new BasicDBList(); Long[] ppc = r.getProductCofactors(); for (int i = 0; i < ppc.length; i++) { DBObject o = getObject("pubchem", ppc[i]); prodCofactors.put(i, o); } BasicDBList substrCofactors = new BasicDBList(); Long[] ssc = r.getSubstrateCofactors(); for (int i = 0; i < ssc.length; i++) { DBObject o = getObject("pubchem", ssc[i]); substrCofactors.put(i, o); } BasicDBList coenzymes = new BasicDBList(); Long[] coenz = r.getCoenzymes(); for (int i = 0; i < coenz.length; i++) { DBObject o = getObject("pubchem", coenz[i]); coenzymes.put(i, o); } BasicDBObject enz = new BasicDBObject(); enz.put("products", prods); enz.put("substrates", substr); enz.put("product_cofactors", prodCofactors); enz.put("substrate_cofactors", substrCofactors); enz.put("coenzymes", coenzymes); doc.put("enz_summary", enz); doc.put("is_abstract", r.getRxnDetailType().name()); if (r.getDataSource() != null) doc.put("datasource", r.getDataSource().name()); if (r.getMechanisticValidatorResult() != null) { doc.put("mechanistic_validator_result", MongoDBToJSON.conv(r.getMechanisticValidatorResult())); } BasicDBList refs = new BasicDBList(); for (P<Reaction.RefDataSource, String> ref : r.getReferences()) { BasicDBObject refEntry = new BasicDBObject(); refEntry.put("src", ref.fst().toString()); refEntry.put("val", ref.snd()); refs.add(refEntry); } doc.put("references", refs); BasicDBList proteins = new BasicDBList(); for (JSONObject proteinData : r.getProteinData()) { proteins.add(MongoDBToJSON.conv(proteinData)); } doc.put("proteins", proteins); ConversionDirectionType cd = r.getConversionDirection(); doc.put("conversion_direction", cd == null ? null : cd.toString()); StepDirection psd = r.getPathwayStepDirection(); doc.put("pathway_step_direction", psd == null ? null : psd.toString()); return doc; }
From source file:act.server.MongoDB.java
License:Open Source License
public List<Reaction> getRxnsWithAll(List<Long> reactants, List<Long> products) { if (reactants.size() == 0 && products.size() == 0) { throw new IllegalArgumentException("Reactants and products both empty! Query would return entire DB."); }/* ww w . j ava2 s . c o m*/ BasicDBObject query = new BasicDBObject(); if (!reactants.isEmpty()) { BasicDBList substrateIds = new BasicDBList(); substrateIds.addAll(reactants); query.put("enz_summary.substrates.pubchem", new BasicDBObject("$all", substrateIds)); } if (!products.isEmpty()) { BasicDBList productIds = new BasicDBList(); productIds.addAll(products); query.put("enz_summary.products.pubchem", new BasicDBObject("$all", productIds)); } DBCursor cur = this.dbReactions.find(query); List<Reaction> reactions = new ArrayList<Reaction>(); try { while (cur.hasNext()) { DBObject o = cur.next(); reactions.add(convertDBObjectToReaction(o)); } } finally { cur.close(); } return reactions; }
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);//from w ww . j a va2 s . c o 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 v a2 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 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 {/*from 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; }