Search in sources :

Example 1 with CompositionRelation

use of ambit2.base.relation.composition.CompositionRelation in project ambit-mirror by ideaconsult.

the class SubstanceCompositionResource method createQuery.

@Override
protected Q createQuery(Context context, Request request, Response response) throws ResourceException {
    Form form = getRequest().getResourceRef().getQueryAsForm();
    // i.e. hide hidden compositions , see 8.14 db schema
    boolean showall = false;
    try {
        showall = Boolean.parseBoolean(form.getFirstValue("all"));
    } catch (Exception x) {
        showall = false;
    }
    Object key = request.getAttributes().get(SubstanceResource.idsubstance);
    Object cmp = request.getAttributes().get(idcomposition);
    if (key == null) {
        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST);
    } else {
        CompositionRelation relation = null;
        try {
            if (cmp != null) {
                STRUCTURE_RELATION srelation = STRUCTURE_RELATION.valueOf(cmp.toString());
                relation = new CompositionRelation(null, null, srelation, null);
            }
        } catch (Exception x) {
        }
        ReadSubstanceComposition q = null;
        try {
            q = new ReadSubstanceComposition();
            q.setExcludeHidden(!showall);
            q.setFieldname(new SubstanceRecord(Integer.parseInt(key.toString())));
            q.setValue(relation);
            return (Q) q;
        } catch (Exception x) {
            int len = key.toString().trim().length();
            if ((len > 40) && (len <= 45)) {
                SubstanceRecord record = new SubstanceRecord();
                record.setSubstanceUUID(key.toString());
                q = new ReadSubstanceComposition();
                q.setExcludeHidden(!showall);
                q.setFieldname(record);
                q.setValue(relation);
                return (Q) q;
            }
            throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST);
        }
    }
}
Also used : Form(org.restlet.data.Form) STRUCTURE_RELATION(ambit2.base.relation.STRUCTURE_RELATION) SubstanceRecord(ambit2.base.data.SubstanceRecord) ResourceException(org.restlet.resource.ResourceException) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) ResourceException(org.restlet.resource.ResourceException) ReadSubstanceComposition(ambit2.db.substance.relation.ReadSubstanceComposition) CompositionRelation(ambit2.base.relation.composition.CompositionRelation)

Example 2 with CompositionRelation

use of ambit2.base.relation.composition.CompositionRelation in project ambit-mirror by ideaconsult.

the class BucketDenormalised method composition2Buckets.

// TODO
protected Bucket composition2Buckets(SubstanceRecord record, CompositionRelation component, boolean suffix) {
    Bucket bcomposition = new Bucket<>();
    bcomposition.setHeaders(study_headers_combined);
    bcomposition.put("type_s", "composition");
    String ctype = component.getRelationType().name().replace("HAS_", "");
    bcomposition.put(header_component, ctype);
    bcomposition.put("COMPOSITION", component.getName());
    if (component.getSecondStructure().getSmiles() != null)
        bcomposition.put("SMILES_s", component.getSecondStructure().getSmiles());
    if (component.getSecondStructure().getInchi() != null)
        bcomposition.put("InChI_s", component.getSecondStructure().getInchi());
    if (component.getSecondStructure().getInchiKey() != null)
        bcomposition.put("InChIKey_s", component.getSecondStructure().getInchiKey());
    for (Property p : component.getSecondStructure().getRecordProperties()) {
        if (p.getLabel().indexOf("UUID") >= 0)
            continue;
        String label = String.format("%s_s", p.getLabel().replace("http://www.opentox.org/api/1.1#", ""));
        String val = component.getSecondStructure().getRecordProperty(p).toString().trim();
        if ("".equals(val))
            continue;
        bcomposition.put(label, val);
    }
    return bcomposition;
}
Also used : Bucket(net.idea.modbcum.i.bucket.Bucket) Property(ambit2.base.data.Property)

Example 3 with CompositionRelation

use of ambit2.base.relation.composition.CompositionRelation in project ambit-mirror by ideaconsult.

the class SubstanceRecord method addStructureRelation.

public IStructureRelation addStructureRelation(String compositionUUID, IStructureRecord record, STRUCTURE_RELATION relation, Proportion value) {
    if (relatedStructures == null)
        relatedStructures = new ArrayList<CompositionRelation>();
    CompositionRelation r = new CompositionRelation(this, record, value);
    r.setCompositionUUID(compositionUUID);
    r.setRelationType(relation);
    relatedStructures.add(r);
    return r;
}
Also used : ArrayList(java.util.ArrayList) CompositionRelation(ambit2.base.relation.composition.CompositionRelation)

Example 4 with CompositionRelation

use of ambit2.base.relation.composition.CompositionRelation in project ambit-mirror by ideaconsult.

the class DBSubstanceWriter method importSubstanceRecord.

protected void importSubstanceRecord(SubstanceRecord substance) throws Exception {
    try {
        q.setObject(substance);
        x.process(q);
    } catch (Exception x) {
        logger.log(Level.WARNING, q.getClass().getName(), x);
        throw x;
    }
    try {
        qids.setObject(substance);
        x.process(qids);
    } catch (Exception x) {
        logger.log(Level.WARNING, qids.getClass().getName(), x);
    }
    importedRecord.setSubstanceUUID(substance.getSubstanceUUID());
    importedRecord.setIdsubstance(substance.getIdsubstance());
    String prefix = substance.getSubstanceUUID().substring(0, 4);
    if (clearComposition)
        try {
            deleteComposition.setGroup(importedRecord);
            x.process(deleteComposition);
        } catch (Exception x) {
            logger.log(Level.WARNING, x.getMessage());
        }
    if (substance.getRelatedStructures() != null) {
        for (CompositionRelation rel : substance.getRelatedStructures()) {
            // TODO !!!!!!!!!!!!!!
            Object i5uuid = rel.getSecondStructure().getRecordProperty(Property.getI5UUIDInstance());
            if (rel.getSecondStructure().getIdchemical() <= 0) {
                if (i5mode) {
                    IStructureKey match = writer.getPropertyKey();
                    writer.setPropertyKey(componentsMatch);
                    writer.create(rel.getSecondStructure());
                    writer.setPropertyKey(match);
                } else {
                    IStructureKey match = writer.getPropertyKey();
                    writer.setPropertyKey(match);
                    writer.create(rel.getSecondStructure());
                    writer.setPropertyKey(match);
                }
            }
            rel.getSecondStructure().setRecordProperty(Property.getI5UUIDInstance(), i5uuid);
            qr.setCompositionRelation(rel);
            x.process(qr);
        }
    }
    if (clearMeasurements)
        try {
            deleteStudy.setGroup(substance.getSubstanceUUID());
            x.process(deleteStudy);
        } catch (Exception x) {
            logger.log(Level.WARNING, x.getMessage());
        }
    if (importBundles)
        importBundles(substance);
}
Also used : IStructureKey(ambit2.core.processors.structure.key.IStructureKey) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) DbAmbitException(net.idea.modbcum.i.exceptions.DbAmbitException) CompositionRelation(ambit2.base.relation.composition.CompositionRelation)

Example 5 with CompositionRelation

use of ambit2.base.relation.composition.CompositionRelation in project ambit-mirror by ideaconsult.

the class ReadSubstanceComposition method readCompositionRelation.

public static CompositionRelation readCompositionRelation(CompositionRelation record, ResultSet rs, SubstanceEndpointsBundle bundle) throws AmbitException {
    if (record == null)
        record = new CompositionRelation(new SubstanceRecord(), new StructureRecord(), new Proportion());
    else
        record.clear();
    try {
        try {
            String uuid = I5Utils.getPrefixedUUID(rs.getString("cmp_prefix"), rs.getString("cmp_huuid"));
            record.setCompositionUUID(uuid);
        } catch (Exception xx) {
            record.setCompositionUUID(null);
        }
        record.setName(rs.getString("compositionname"));
        try {
            record.setHidden(rs.getBoolean("hidden"));
        } catch (Exception x) {
            record.setHidden(false);
        }
        record.getFirstStructure().setIdsubstance(rs.getInt("idsubstance"));
        record.getSecondStructure().setIdchemical(rs.getInt("idchemical"));
        try {
            record.getSecondStructure().setInchi(rs.getString("inchi"));
            record.getSecondStructure().setSmiles(rs.getString("smiles"));
            record.getSecondStructure().setInchiKey(rs.getString("inchikey"));
            record.getSecondStructure().setFormula(rs.getString("formula"));
        } catch (Exception x) {
            x.printStackTrace();
        }
        record.setRelationType(STRUCTURE_RELATION.valueOf(rs.getString("relation")));
        record.getRelation().setFunction(rs.getString("function"));
        record.getRelation().setTypical(rs.getString("proportion_typical"));
        record.getRelation().setTypical_unit(rs.getString("proportion_typical_unit"));
        record.getRelation().setTypical_value(rs.getDouble("proportion_typical_value"));
        record.getRelation().setReal_lower(rs.getString("proportion_real_lower"));
        record.getRelation().setReal_upper(rs.getString("proportion_real_upper"));
        record.getRelation().setReal_unit(rs.getString("proportion_real_unit"));
        record.getRelation().setReal_lowervalue(rs.getDouble("proportion_real_lower_value"));
        record.getRelation().setReal_uppervalue(rs.getDouble("proportion_real_upper_value"));
        try {
            record.getSecondStructure().clearFacets();
            if (bundle != null && bundle.getID() > 0) {
                BundleRoleFacet facet = new BundleRoleFacet(null);
                facet.setCount(1);
                facet.setTag(rs.getString("tag"));
                facet.setRemarks(rs.getString("remarks"));
                facet.setValue(bundle);
                record.getSecondStructure().addFacet(facet);
            }
        } catch (Exception x) {
        }
        try {
            String uuid = I5Utils.getPrefixedUUID(rs.getString("refstruc"), rs.getString("refstrucuuid"));
            record.setRecordProperty(Property.getI5UUIDInstance(), uuid);
        } catch (Exception xx) {
            record.removeRecordProperty(Property.getI5UUIDInstance());
        }
    } catch (Exception x) {
        x.printStackTrace();
    }
    return record;
}
Also used : Proportion(ambit2.base.relation.composition.Proportion) StructureRecord(ambit2.base.data.StructureRecord) SubstanceRecord(ambit2.base.data.SubstanceRecord) BundleRoleFacet(ambit2.base.facet.BundleRoleFacet) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) CompositionRelation(ambit2.base.relation.composition.CompositionRelation)

Aggregations

CompositionRelation (ambit2.base.relation.composition.CompositionRelation)33 SubstanceRecord (ambit2.base.data.SubstanceRecord)17 IStructureRecord (ambit2.base.interfaces.IStructureRecord)14 StructureRecord (ambit2.base.data.StructureRecord)10 Proportion (ambit2.base.relation.composition.Proportion)10 ArrayList (java.util.ArrayList)10 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)10 ProtocolApplication (ambit2.base.data.study.ProtocolApplication)7 Property (ambit2.base.data.Property)5 ResourceException (org.restlet.resource.ResourceException)5 ExternalIdentifier (ambit2.base.data.substance.ExternalIdentifier)4 SubstanceEndpointsBundle (ambit2.base.data.substance.SubstanceEndpointsBundle)4 BundleRoleFacet (ambit2.base.facet.BundleRoleFacet)4 ReadChemIdentifiersByComposition (ambit2.db.substance.ids.ReadChemIdentifiersByComposition)4 ReadSubstanceComposition (ambit2.db.substance.relation.ReadSubstanceComposition)4 EffectRecord (ambit2.base.data.study.EffectRecord)3 IParams (ambit2.base.data.study.IParams)3 IValue (ambit2.base.data.study.IValue)3 Protocol (ambit2.base.data.study.Protocol)3 UpdateSubstanceRelation (ambit2.db.substance.relation.UpdateSubstanceRelation)3