Search in sources :

Example 1 with Node

use of ambit2.smarts.Node in project ambit-mirror by ideaconsult.

the class SubstanceLookupTest method verifyResponseJSON.

public boolean verifyResponseJSON(String uri, MediaType media, InputStreamReader reader) throws Exception {
    // JsonNode node = parseResponseJSON(uri, media, in);
    SubstanceStudyParser p = new SubstanceStudyParser(reader);
    int i = 0;
    while (p.hasNext()) {
        Object o = p.next();
        Assert.assertTrue(o instanceof SubstanceRecord);
        Assert.assertEquals(testUUID, ((SubstanceRecord) o).getSubstanceUUID());
        System.out.println(o);
        i++;
    }
    return i == 1;
}
Also used : SubstanceRecord(ambit2.base.data.SubstanceRecord) SubstanceStudyParser(ambit2.core.io.json.SubstanceStudyParser)

Example 2 with Node

use of ambit2.smarts.Node in project ambit-mirror by ideaconsult.

the class SubstanceDatasetResource method getPropertyProcessors.

protected IProcessor getPropertyProcessors(final boolean removeIdentifiers, final boolean removeStringProperties) {
    IQueryRetrieval<ProtocolEffectRecord<String, String, String>> queryP = getEffectQuery();
    MasterDetailsProcessor<SubstanceRecord, ProtocolEffectRecord<String, String, String>, IQueryCondition> effectReader = new MasterDetailsProcessor<SubstanceRecord, ProtocolEffectRecord<String, String, String>, IQueryCondition>(queryP) {

        /**
         */
        private static final long serialVersionUID = -7354966336095750101L;

        ProtocolEffectRecord2SubstanceProperty processor = new ProtocolEffectRecord2SubstanceProperty();

        @Override
        public SubstanceRecord process(SubstanceRecord target) throws Exception {
            if (target == null || target.getSubstanceUUID() == null)
                return target;
            else
                return super.process(target);
        }

        @Override
        protected SubstanceRecord processDetail(SubstanceRecord master, ProtocolEffectRecord<String, String, String> detail) throws Exception {
            if (master.getIdsubstance() <= 0)
                return master;
            if (detail != null) {
                if (detail.getTextValue() != null && detail.getTextValue().toString().startsWith("{")) {
                    JsonNode node = dx.readTree(new StringReader(detail.getTextValue().toString()));
                    List<String> guideline = detail.getProtocol().getGuideline();
                    ILiteratureEntry ref = LiteratureEntry.getInstance(guideline == null ? null : guideline.size() == 0 ? null : guideline.get(0), guideline == null ? null : guideline.size() == 0 ? null : guideline.get(0));
                    Iterator<Entry<String, JsonNode>> i = node.fields();
                    while (i.hasNext()) {
                        Entry<String, JsonNode> val = i.next();
                        SubstanceProperty key = new SubstanceProperty(detail.getProtocol().getTopCategory(), detail.getProtocol().getCategory(), val.getKey(), detail.getUnit(), ref);
                        try {
                            key.setStudyResultType(_r_flags.valueOf(detail.getStudyResultType().replace(":", "").replace("_", "").replace(" ", "").replace("-", "").replace(")", "").replace("(", "")));
                        } catch (Exception x) {
                            key.setStudyResultType(null);
                        }
                        key.setExtendedURI(true);
                        key.setIdentifier(detail.getSampleID() + "/" + val.getKey());
                        groupProperties.add(key);
                        if (val.getValue().get(EffectRecord._fields.loValue.name()) != null) {
                            Number num = val.getValue().get(EffectRecord._fields.loValue.name()).asDouble();
                            master.setRecordProperty(key, num);
                            key.setClazz(Number.class);
                        } else {
                            master.setRecordProperty(key, val.getValue().textValue());
                            key.setClazz(String.class);
                        }
                    }
                } else {
                    boolean isTextValue = ((detail.getLoValue() == null) && (detail.getUpValue() == null));
                    if (isTextValue && removeStringProperties)
                        return master;
                    /*
						 * JsonNode conditions = detail.getConditions() == null
						 * ? null : dx.readTree(new StringReader(
						 * detail.getConditions()));
						 * 
						 * PropertyAnnotations ann = new PropertyAnnotations();
						 * 
						 * Iterator<Entry<String, JsonNode>> i = conditions ==
						 * null ? null : conditions.getFields();
						 * 
						 * if (i != null) while (i.hasNext()) { Entry<String,
						 * JsonNode> val = i.next(); if (val.getValue()
						 * instanceof NullNode) continue;
						 * 
						 * if (val.getValue().getTextValue() == null) try {
						 * PropertyAnnotation a = new PropertyAnnotation();
						 * String unit =
						 * val.getValue().get(EffectRecord._fields.unit.name())
						 * == null ? null :
						 * val.getValue().get(EffectRecord._fields
						 * .unit.name()).asText(); a.setPredicate(val.getKey());
						 * if (unit == null)
						 * a.setObject(val.getValue().get(EffectRecord
						 * ._fields.loValue.name()) .asText()); else {
						 * a.setObject(String.format("%s %s",
						 * val.getValue().get(
						 * EffectRecord._fields.loValue.name()).asText(),
						 * unit)); } ann.add(a); } catch (Exception x) { } else
						 * { PropertyAnnotation a = new PropertyAnnotation();
						 * a.setPredicate(val.getKey());
						 * a.setObject(val.getValue().getTextValue());
						 * ann.add(a); }
						 * 
						 * }
						 */
                    ProtocolEffectRecord<String, IParams, String> effect = new ProtocolEffectRecord<String, IParams, String>();
                    ProtocolEffectRecord2SubstanceProperty.copyEffectRecordValues(detail, effect);
                    try {
                        JsonNode conditions = detail.getConditions() == null ? null : dx.readTree(new StringReader(detail.getConditions()));
                        if (conditions instanceof ObjectNode) {
                            effect.setConditions(SubstanceStudyParser.parseParams((ObjectNode) conditions));
                        }
                    } catch (Exception x) {
                        logger.log(Level.FINE, x.getMessage());
                    }
                    SubstanceProperty key = processor.process(effect);
                    key.setIdentifier(key.createHashedIdentifier(effect.getConditions()));
                    Object oldValue = master.getRecordProperty(key);
                    groupProperties.add(key);
                    /*
						 * if (isTextValue) { //textvalue if (oldValue == null)
						 * master.setProperty(key, detail.getTextValue()); else
						 * { master.setProperty(key, String.format( "%s, %s",
						 * oldValue instanceof Number ? nf.format((Number)
						 * oldValue) : oldValue .toString(),
						 * detail.getTextValue())); }
						 * key.setClazz(String.class); } else { //numeric
						 */
                    Value value = processValue(detail, isTextValue);
                    if (value != null)
                        ProtocolEffectRecord2SubstanceProperty.addValues(master, key, value, oldValue);
                // }
                }
            }
            return master;
        }
    };
    return effectReader;
}
Also used : IQueryCondition(net.idea.modbcum.i.IQueryCondition) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ProtocolEffectRecord2SubstanceProperty(ambit2.core.io.study.ProtocolEffectRecord2SubstanceProperty) ILiteratureEntry(ambit2.base.data.ILiteratureEntry) SubstanceRecord(ambit2.base.data.SubstanceRecord) JsonNode(com.fasterxml.jackson.databind.JsonNode) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) ResourceException(org.restlet.resource.ResourceException) LiteratureEntry(ambit2.base.data.LiteratureEntry) Entry(java.util.Map.Entry) ILiteratureEntry(ambit2.base.data.ILiteratureEntry) ProtocolEffectRecord(ambit2.base.data.study.ProtocolEffectRecord) MasterDetailsProcessor(net.idea.modbcum.p.MasterDetailsProcessor) StringReader(java.io.StringReader) Value(ambit2.base.data.study.Value) IParams(ambit2.base.data.study.IParams) ProtocolEffectRecord2SubstanceProperty(ambit2.core.io.study.ProtocolEffectRecord2SubstanceProperty) SubstanceProperty(ambit2.base.data.substance.SubstanceProperty)

Example 3 with Node

use of ambit2.smarts.Node in project ambit-mirror by ideaconsult.

the class SubstanceStudyParser method parseReliability.

// ProtocolApplicationAnnotated
protected void parseReliability(ObjectNode node, ProtocolApplication record) {
    if (node == null)
        return;
    ReliabilityParams reliability = new ReliabilityParams();
    JsonNode jn = node.get(_FIELDS_RELIABILITY.r_isUsedforMSDS.name());
    try {
        reliability.setIsUsedforMSDS(jn.asBoolean());
    } catch (Exception x) {
    }
    jn = node.get(_FIELDS_RELIABILITY.r_isRobustStudy.name());
    try {
        reliability.setIsRobustStudy(jn.asBoolean());
    } catch (Exception x) {
    }
    jn = node.get(_FIELDS_RELIABILITY.r_isUsedforClassification.name());
    try {
        reliability.setIsUsedforClassification(jn.asBoolean());
    } catch (Exception x) {
    }
    jn = node.get(_FIELDS_RELIABILITY.r_purposeFlag.name());
    try {
        reliability.setPurposeFlag(jn.textValue());
    } catch (Exception x) {
    }
    jn = node.get(_FIELDS_RELIABILITY.r_studyResultType.name());
    try {
        reliability.setStudyResultType(jn.textValue());
    } catch (Exception x) {
    }
    jn = node.get(_FIELDS_RELIABILITY.r_value.name());
    try {
        reliability.setValue(jn.textValue());
    } catch (Exception x) {
    }
    record.setReliability(reliability);
}
Also used : ReliabilityParams(ambit2.base.data.study.ReliabilityParams) JsonNode(com.fasterxml.jackson.databind.JsonNode) CDKException(org.openscience.cdk.exception.CDKException) IOException(java.io.IOException)

Example 4 with Node

use of ambit2.smarts.Node in project ambit-mirror by ideaconsult.

the class SubstanceStudyParser method parseTextValueProteomics.

public static IParams parseTextValueProteomics(ObjectMapper dx, String t) {
    IParams nonzero = null;
    if (t != null && t.startsWith("{")) {
        IParams proteomics = SubstanceStudyParser.parseConditions(dx, t.toString());
        Iterator i = proteomics.keySet().iterator();
        nonzero = new Params();
        while (i.hasNext()) {
            Object p = i.next();
            try {
                Value node = (Value) proteomics.get(p);
                if (node != null && (node.getLoValue() != null) && (node.getLoValue() instanceof Double) && ((Double) node.getLoValue()) > 0) {
                    nonzero.put(p, node.getLoValue());
                }
            } catch (Exception x) {
                x.printStackTrace();
            }
        }
    }
    return nonzero;
}
Also used : Iterator(java.util.Iterator) Value(ambit2.base.data.study.Value) IParams(ambit2.base.data.study.IParams) IParams(ambit2.base.data.study.IParams) Params(ambit2.base.data.study.Params) ReliabilityParams(ambit2.base.data.study.ReliabilityParams) CDKException(org.openscience.cdk.exception.CDKException) IOException(java.io.IOException)

Example 5 with Node

use of ambit2.smarts.Node in project ambit-mirror by ideaconsult.

the class SubstanceStudyParser method parseSubstance.

public SubstanceRecord parseSubstance(JsonNode node) {
    if (node == null)
        return null;
    SubstanceRecord record = new SubstanceRecord();
    record.setSubstanceName(node.get(SubstanceRecord.jsonSubstance.name.name()).textValue());
    record.setSubstanceUUID(node.get(SubstanceRecord.jsonSubstance.i5uuid.name()).textValue());
    record.setOwnerName(node.get(SubstanceRecord.jsonSubstance.ownerName.name()).textValue());
    record.setOwnerUUID(node.get(SubstanceRecord.jsonSubstance.ownerUUID.name()).textValue());
    record.setPublicName(node.get(SubstanceRecord.jsonSubstance.publicname.name()).textValue());
    record.setSubstancetype(node.get(SubstanceRecord.jsonSubstance.substanceType.name()).textValue());
    record.setFormat(node.get(SubstanceRecord.jsonSubstance.format.name()).textValue());
    JsonNode subnode = node.get(SubstanceRecord.jsonSubstance.externalIdentifiers.name());
    if (subnode instanceof ArrayNode) {
        ArrayNode ids = (ArrayNode) subnode;
        List<ExternalIdentifier> extids = new ArrayList<ExternalIdentifier>();
        record.setExternalids(extids);
        for (int i = 0; i < ids.size(); i++) {
            if (ids.get(i) instanceof ObjectNode) {
                extids.add(new ExternalIdentifier(((ObjectNode) ids.get(i)).get("type").textValue(), ((ObjectNode) ids.get(i)).get("id").textValue()));
            }
        }
    }
    subnode = node.get(SubstanceRecord.jsonSubstance.referenceSubstance.name());
    if (subnode != null) {
        record.setReferenceSubstanceUUID(subnode.get(SubstanceRecord.jsonSubstance.i5uuid.name()).textValue());
    }
    return record;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ExternalIdentifier(ambit2.base.data.substance.ExternalIdentifier) ArrayList(java.util.ArrayList) SubstanceRecord(ambit2.base.data.SubstanceRecord) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)18 ArrayList (java.util.ArrayList)13 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)7 IAtom (org.openscience.cdk.interfaces.IAtom)7 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)6 Node (ambit2.smarts.Node)5 StructureRecord (ambit2.base.data.StructureRecord)4 IParams (ambit2.base.data.study.IParams)4 Value (ambit2.base.data.study.Value)4 QuerySequenceElement (ambit2.smarts.QuerySequenceElement)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)4 IOException (java.io.IOException)4 ILiteratureEntry (ambit2.base.data.ILiteratureEntry)3 SubstanceRecord (ambit2.base.data.SubstanceRecord)3 Params (ambit2.base.data.study.Params)3 ReliabilityParams (ambit2.base.data.study.ReliabilityParams)3 EmptyMoleculeException (ambit2.base.exceptions.EmptyMoleculeException)3 PKANode (ambit2.descriptors.PKANode)3 ReactionDataBase (ambit2.reactions.ReactionDataBase)3 Reactor (ambit2.reactions.reactor.Reactor)3