Example usage for com.mongodb DBObject get

List of usage examples for com.mongodb DBObject get

Introduction

In this page you can find the example usage for com.mongodb DBObject get.

Prototype

Object get(String key);

Source Link

Document

Gets a field from this object by a given name.

Usage

From source file:act.server.MongoDB.java

License:Open Source License

public Iterator<String> getIteratorOverInchis(BasicDBObject matchCriterion) {
    BasicDBObject keys = new BasicDBObject(ChemicalKeywords.INCHI$.MODULE$.toString(), true);
    final DBIterator iter = getIteratorOverChemicals(matchCriterion, keys);

    return new Iterator<String>() {
        @Override/*from   w  w  w .ja  v a 2  s.com*/
        public boolean hasNext() {
            boolean hasNext = iter.hasNext();
            if (!hasNext)
                iter.close();
            return hasNext;
        }

        @Override
        public String next() {
            DBObject o = iter.next();
            return (String) o.get("InChI");
        }
    };
}

From source file:act.server.MongoDB.java

License:Open Source License

public Reaction convertDBObjectToReaction(DBObject o) {
    long uuid = (Integer) o.get("_id"); // checked: db type IS int
    String ecnum = (String) o.get("ecnum");
    String name_field = (String) o.get("easy_desc");
    Reaction.RxnDetailType type = Reaction.RxnDetailType.valueOf((String) o.get("is_abstract"));
    BasicDBList substrates = (BasicDBList) ((DBObject) o.get("enz_summary")).get("substrates");
    BasicDBList products = (BasicDBList) ((DBObject) o.get("enz_summary")).get("products");
    BasicDBList substrateCofactors = (BasicDBList) ((DBObject) o.get("enz_summary")).get("substrate_cofactors");
    BasicDBList productCofactors = (BasicDBList) ((DBObject) o.get("enz_summary")).get("product_cofactors");
    BasicDBList coenzymes = (BasicDBList) ((DBObject) o.get("enz_summary")).get("coenzymes");
    BasicDBList refs = (BasicDBList) (o.get("references"));
    BasicDBList proteins = (BasicDBList) (o.get("proteins"));
    DBObject mechanisticValidatorResults = (DBObject) (o.get("mechanistic_validator_result"));

    BasicDBList keywords = (BasicDBList) (o.get("keywords"));
    BasicDBList cikeywords = (BasicDBList) (o.get("keywords_case_insensitive"));

    List<Long> substr = new ArrayList<Long>();
    List<Long> prod = new ArrayList<Long>();
    List<Long> substrCofact = new ArrayList<Long>();
    List<Long> prodCofact = new ArrayList<Long>();
    List<Long> coenz = new ArrayList<Long>();

    String conversionDirectionString = (String) o.get("conversion_direction");
    ConversionDirectionType conversionDirection = conversionDirectionString == null ? null
            : ConversionDirectionType.valueOf(conversionDirectionString);

    String pathwayStepDirectionString = (String) o.get("pathway_step_direction");
    StepDirection pathwayStepDirection = pathwayStepDirectionString == null ? null
            : StepDirection.valueOf(pathwayStepDirectionString);

    for (int i = 0; i < substrates.size(); i++) {
        Boolean forBalance = (Boolean) ((DBObject) substrates.get(i)).get("balance");
        if (forBalance != null && forBalance)
            continue;
        substr.add(getEnzSummaryIDAsLong(substrates, i));
    }//from   w w w . ja  va2 s . c  o m
    for (int i = 0; i < products.size(); i++) {
        Boolean forBalance = (Boolean) ((DBObject) products.get(i)).get("balance");
        if (forBalance != null && forBalance)
            continue;
        prod.add(getEnzSummaryIDAsLong(products, i));
    }
    for (int i = 0; i < substrateCofactors.size(); i++) {
        substrCofact.add(getEnzSummaryIDAsLong(substrateCofactors, i));
    }
    for (int i = 0; i < productCofactors.size(); i++) {
        prodCofact.add(getEnzSummaryIDAsLong(productCofactors, i));
    }
    for (int i = 0; i < coenzymes.size(); i++) {
        coenz.add(getEnzSummaryIDAsLong(coenzymes, i));
    }

    Reaction result = new Reaction(uuid, (Long[]) substr.toArray(new Long[0]),
            (Long[]) prod.toArray(new Long[0]), (Long[]) substrCofact.toArray(new Long[0]),
            (Long[]) prodCofact.toArray(new Long[0]), (Long[]) coenz.toArray(new Long[0]), ecnum,
            conversionDirection, pathwayStepDirection, name_field, type);

    for (int i = 0; i < substrates.size(); i++) {
        Integer c = (Integer) ((DBObject) substrates.get(i)).get("coefficient");
        if (c != null)
            result.setSubstrateCoefficient(getEnzSummaryIDAsLong(substrates, i), c);
    }
    for (int i = 0; i < products.size(); i++) {
        Integer c = (Integer) ((DBObject) products.get(i)).get("coefficient");
        if (c != null)
            result.setProductCoefficient(getEnzSummaryIDAsLong(products, i), c);
    }

    Double estimatedEnergy = (Double) o.get("estimateEnergy");
    result.setEstimatedEnergy(estimatedEnergy);

    String datasrc = (String) o.get("datasource");
    if (datasrc != null && !datasrc.equals(""))
        result.setDataSource(Reaction.RxnDataSource.valueOf(datasrc));

    if (mechanisticValidatorResults != null) {
        result.setMechanisticValidatorResult(MongoDBToJSON.conv(mechanisticValidatorResults));
    }

    if (refs != null) {
        for (Object oo : refs) {
            DBObject ref = (DBObject) oo;
            Reaction.RefDataSource src = Reaction.RefDataSource.valueOf((String) ref.get("src"));
            String val = (String) ref.get("val");
            result.addReference(src, val);
        }
    }

    if (proteins != null) {
        for (Object oo : proteins) {
            result.addProteinData(MongoDBToJSON.conv((DBObject) oo));
        }
    }

    if (keywords != null)
        for (Object k : keywords)
            result.addKeyword((String) k);

    if (cikeywords != null)
        for (Object k : cikeywords)
            result.addCaseInsensitiveKeyword((String) k);

    return result;
}

From source file:act.server.MongoDB.java

License:Open Source License

public Cofactor convertDBObjectToCofactor(DBObject o) {
    long uuid = (Long) o.get("_id");
    String inchi = (String) o.get("InChI");
    BasicDBList ns = (BasicDBList) o.get("names");
    List<String> names = new ArrayList<>();
    if (ns != null) {
        for (Object n : ns) {
            names.add((String) n);
        }//from   w  w w  . ja  v  a2 s .  c  o m
    }
    Cofactor cofactor = new Cofactor(uuid, inchi, names);

    return cofactor;
}

From source file:act.server.MongoDB.java

License:Open Source License

public List<Long> getAllCollectionUUIDs(DBCollection collection) {

    List<Long> ids = new ArrayList<Long>();

    BasicDBObject query = new BasicDBObject();
    BasicDBObject keys = new BasicDBObject();
    keys.put("_id", 1); // 0 means exclude, rest are included
    DBCursor cur = collection.find(query, keys);

    while (cur.hasNext()) {
        DBObject o = cur.next();
        long uuid = (Integer) o.get("_id"); // checked: db type IS int
        ids.add(uuid);/*from ww  w .ja v  a 2 s . co  m*/
    }
    cur.close();

    return ids;
}

From source file:act.server.MongoDB.java

License:Open Source License

public Seq convertDBObjectToSeq(DBObject o) {
    long id = (Integer) o.get("_id"); // checked: db type IS int
    String ecnum = (String) o.get("ecnum");
    String org_name = (String) o.get("org");
    Long org_id = (Long) o.get("org_id");
    String aa_seq = (String) o.get("seq");
    String srcdb = (String) o.get("src");

    BasicDBList refs = (BasicDBList) o.get("references");
    DBObject meta = (DBObject) o.get("metadata");
    BasicDBList rxn_refs = (BasicDBList) (o.get("rxn_refs"));

    if (srcdb == null)
        srcdb = Seq.AccDB.swissprot.name();
    Seq.AccDB src = Seq.AccDB.valueOf(srcdb); // genbank | uniprot | trembl | embl | swissprot

    List<JSONObject> references = new ArrayList<>();
    if (refs != null)
        for (Object r : refs)
            references.add(MongoDBToJSON.conv((DBObject) r));

    String dummyString = ""; // for type differentiation in overloaded method
    Long dummyLong = 0L; // for type differentiation in overloaded method

    Set<Long> rxns_catalyzed = from_dblist(rxn_refs, dummyLong);

    return Seq.rawInit(id, ecnum, org_id, org_name, aa_seq, references, meta, src,
            // the rest of the params are the ones that are typically
            // "constructed". But since we are reading from the DB, we manually init
            rxns_catalyzed);//from w  w  w .  j a  v a 2s.  c  o m
}

From source file:act.server.MongoDB.java

License:Open Source License

public Organism convertDBObjectToOrg(DBObject o) {
    Long id = (long) o.get("org_id");
    String name = (String) o.get("name");

    return new Organism(id, name);
}

From source file:act.server.MongoDB.java

License:Open Source License

public String getOrganismNameFromId(Long id) {
    BasicDBObject query = new BasicDBObject();
    query.put("org_id", id);
    BasicDBObject keys = new BasicDBObject();
    keys.put("name", 1);

    if (this.dbOrganismNames != null) {
        DBObject cur = this.dbOrganismNames.findOne(query, keys);
        if (cur == null) {
            //System.out.println("Did not find in organismnames: " + name);
            return null;
        }/*from ww  w.  j ava2 s .com*/
        return (String) cur.get("name");
    } else {
        //System.out.println("no organism names collection");
    }
    return null;
}

From source file:act.server.MongoDB.java

License:Open Source License

public long getOrganismId(String name) {
    BasicDBObject query = new BasicDBObject();
    query.put("name", name);
    BasicDBObject keys = new BasicDBObject();
    keys.put("org_id", 1);

    if (this.dbOrganismNames != null) {
        DBObject cur = this.dbOrganismNames.findOne(query, keys);
        if (cur == null) {
            //System.out.println("Did not find in organismnames: " + name);
            return -1;
        }// w w  w . ja  va  2 s . c o  m
        return (Long) cur.get("org_id"); // checked: db type IS long
    } else {
        //System.out.println("no organism names collection");
    }
    return -1;
}

From source file:act.server.MongoDB.java

License:Open Source License

public Set<Long> getOrganismIDs() {
    DBIterator iterator = getIteratorOverReactions(new BasicDBObject(), null);
    Set<Long> ids = new HashSet<Long>();
    while (iterator.hasNext()) {
        DBObject r = iterator.next();
        BasicDBList orgs = (BasicDBList) r.get("organisms");
        for (Object o : orgs) {
            ids.add((Long) ((DBObject) o).get("id")); // checked: db type IS Long
        }/*from  w ww .j a va2  s . c  o m*/
    }
    return ids;
}

From source file:act.server.MongoDB.java

License:Open Source License

public Set<Long> getOrganismIDs(Long reactionID) {
    if (reactionID < 0) {
        reactionID = Reaction.reverseID(reactionID);
    }// w ww  .  ja  v a 2  s  . co m
    DBObject query = new BasicDBObject();
    query.put("_id", reactionID);
    Set<Long> ids = new HashSet<Long>();
    DBObject reaction = this.dbReactions.findOne(query);
    if (reaction != null) {
        BasicDBList orgs = (BasicDBList) reaction.get("organisms");
        for (Object o : orgs) {
            ids.add((Long) ((DBObject) o).get("id")); // checked: db type IS long
        }
    }
    return ids;
}