Search in sources :

Example 1 with ProtocolApplication

use of ambit2.base.data.study.ProtocolApplication in project ambit-mirror by ideaconsult.

the class SubstanceStudyReporterTest method main.

public static void main(String[] args) {
    Substance2BucketJsonReporter reporter = new Substance2BucketJsonReporter(null, null, Substance2BucketJsonReporter._JSON_MODE.substance, null, null, null);
    Reader in = null;
    try {
        OutputStreamWriter writer;
        if (args.length < 2)
            writer = new OutputStreamWriter(System.out);
        else
            writer = new OutputStreamWriter(new FileOutputStream(new File(args[1])));
        reporter.setOutput(writer);
        in = new FileReader(new File(args[0]));
        RawIteratingCSVReader reader = new RawIteratingCSVReader(in, CSVFormat.TDF) {

            protected SubstanceRecord prevrecord = null;

            protected String getRecordid(CSVRecord record) {
                return record.get(0);
            }

            protected String getExternalId(CSVRecord record) {
                return record.get(1);
            }

            protected String getExternalIdSystem(CSVRecord record) {
                return record.get(5);
            }

            protected String getAssayid(CSVRecord record) {
                return record.get(6);
            }

            protected String getSummaryActivity(CSVRecord record) {
                return record.get(3);
            }

            protected double getActivityValue(CSVRecord record) throws NumberFormatException {
                return Double.parseDouble(record.get(4));
            }

            protected String getOrthologgroup(CSVRecord record) {
                return record.get(9);
            }

            protected String getGeneSymbol(CSVRecord record) {
                return record.get(8);
            }

            protected String getSpecies(CSVRecord record) {
                return record.get(7);
            }

            @Override
            protected IStructureRecord transform(CSVRecord record) {
                SubstanceRecord substance = prevrecord;
                String id = getRecordid(record);
                if (prevrecord == null || !id.equals(prevrecord.getSubstanceName())) {
                    substance = new SubstanceRecord();
                    substance.setContent(null);
                    // substance.setSubstancetype("standardized");
                    substance.setSubstanceUUID(I5Utils.getPrefixedUUID("PC", UUID.nameUUIDFromBytes(id.getBytes())));
                    substance.setSubstanceName(id);
                    prevrecord = substance;
                }
                structureRecord = substance;
                String externalid = getExternalId(record);
                String externaldb = getExternalIdSystem(record);
                ExternalIdentifier eid = new ExternalIdentifier(externaldb, externalid);
                boolean newid = true;
                if (substance.getExternalids() == null)
                    substance.setExternalids(new ArrayList<ExternalIdentifier>());
                else
                    for (ExternalIdentifier e : substance.getExternalids()) if (e.getSystemDesignator().equals(eid.getSystemDesignator()) && e.getSystemIdentifier().equals(eid.getSystemIdentifier())) {
                        newid = false;
                        break;
                    }
                if (newid)
                    substance.getExternalids().add(eid);
                String assayid = getAssayid(record);
                Protocol p = new Protocol(String.format("%s", externalid));
                p.setTopCategory(null);
                p.setCategory(null);
                // p.addGuideline(String.format("%s_AID%s", externaldb,assayid));
                ProtocolApplication<Protocol, IParams, String, IParams, String> papp = new ProtocolApplication<Protocol, IParams, String, IParams, String>(p);
                // papp.setDocumentUUID(I5Utils.getPrefixedUUID("PC",UUID.nameUUIDFromBytes(p.getEndpoint().getBytes())));
                papp.setDocumentUUID(null);
                papp.setInterpretationResult(getSummaryActivity(record));
                papp.setReference(String.format("AID%s", assayid));
                papp.setReferenceOwner(externaldb);
                IParams params = new Params();
                params.put("gene", getGeneSymbol(record));
                params.put("taxid", "TaxId:" + getSpecies(record));
                // params.put("OG_GENE", String.format("OG%s_%s", record.get(9),	record.get(8)));
                params.put("og", "OG" + getOrthologgroup(record));
                params.put("ez", "entrez:" + record.get(2));
                papp.setParameters(params);
                try {
                    EffectRecord<String, IParams, String> effect = new EffectRecord<String, IParams, String>();
                    effect.setEndpoint("pXC50");
                    effect.setIdresult(1);
                    double value = getActivityValue(record);
                    effect.setLoValue(value);
                    effect.setUnit("nM");
                    papp.addEffect(effect);
                } catch (Exception x) {
                // x.printStackTrace();
                }
                substance.addMeasurement(papp);
                return structureRecord;
            }
        };
        int n = 0;
        IStructureRecord prevrecord = null;
        reporter.header(writer, null);
        while (reader.hasNext()) {
            IStructureRecord record = reader.nextRecord();
            if (prevrecord != null && (prevrecord != record)) {
                reporter.processItem((SubstanceRecord) prevrecord);
                writer.flush();
            }
            n++;
            prevrecord = record;
            if ((n % 100000) == 0) {
                System.err.println();
                System.err.print(n);
            } else if ((n % 10000) == 0)
                System.err.print(".");
        }
        reporter.processItem((SubstanceRecord) prevrecord);
        reporter.footer(writer, null);
        writer.flush();
    } catch (Exception x) {
        x.printStackTrace();
    } finally {
        try {
            in.close();
        } catch (Exception x) {
        }
        try {
            reporter.close();
        } catch (Exception x) {
        }
    }
}
Also used : RawIteratingCSVReader(ambit2.core.io.RawIteratingCSVReader) ExternalIdentifier(ambit2.base.data.substance.ExternalIdentifier) ArrayList(java.util.ArrayList) RawIteratingCSVReader(ambit2.core.io.RawIteratingCSVReader) Reader(java.io.Reader) FileReader(java.io.FileReader) SubstanceRecord(ambit2.base.data.SubstanceRecord) IParams(ambit2.base.data.study.IParams) Params(ambit2.base.data.study.Params) IStructureRecord(ambit2.base.interfaces.IStructureRecord) ProtocolApplication(ambit2.base.data.study.ProtocolApplication) EffectRecord(ambit2.base.data.study.EffectRecord) FileOutputStream(java.io.FileOutputStream) Substance2BucketJsonReporter(ambit2.rest.substance.study.Substance2BucketJsonReporter) IParams(ambit2.base.data.study.IParams) OutputStreamWriter(java.io.OutputStreamWriter) FileReader(java.io.FileReader) CSVRecord(org.apache.commons.csv.CSVRecord) Protocol(ambit2.base.data.study.Protocol) File(java.io.File)

Example 2 with ProtocolApplication

use of ambit2.base.data.study.ProtocolApplication in project ambit-mirror by ideaconsult.

the class BucketDenormalised method effectrecord2bucket.

protected void effectrecord2bucket(ProtocolApplication papp, EffectRecord<String, Object, String> e, Bucket bucket, boolean suffix) {
    if (papp.getInvestigationUUID() != null)
        bucket.put(ns("investigation_uuid", suffix, "_s"), papp.getInvestigationUUID());
    if (papp.getAssayUUID() != null)
        bucket.put(ns("assay_uuid", suffix, "_s"), papp.getAssayUUID());
    if (e.getEndpoint() != null)
        bucket.put(ns("effectendpoint", suffix, "_s"), e.getEndpoint().toUpperCase());
    String[] terms = annotator.annotateEndpoint(e.getEndpoint());
    if (terms != null) {
        bucket.put(ns("effectendpoint_synonym", suffix, "_ss"), Arrays.asList(terms));
    }
    if (e.getEndpointType() != null)
        bucket.put(ns("effectendpoint_type", suffix, "_s"), e.getEndpointType().toUpperCase());
    if (e.getEndpointGroup() != null)
        bucket.put(ns("effectendpoint_group", suffix, "_s"), e.getEndpointGroup());
    bucket.put(ns("unit", suffix, "_s"), e.getUnit() == null ? "" : e.getUnit());
    if (e.getLoValue() != null || e.getUpValue() != null) {
        if (e.getLoQualifier() != null && !"".equals(e.getLoQualifier()))
            bucket.put(ns("loQualifier", suffix, "_s"), e.getLoQualifier());
        if (e.getLoValue() != null)
            bucket.put(ns("loValue", suffix, "_d"), e.getLoValue());
        if (e.getUpQualifier() != null && !"".equals(e.getUpQualifier()))
            bucket.put(ns("upQualifier", suffix, "_s"), e.getUpQualifier());
        if (e.getUpValue() != null)
            bucket.put(ns("upValue", suffix, "_d"), e.getUpValue());
        if (e.getErrQualifier() != null && !"".equals(e.getErrQualifier()))
            bucket.put(ns("errQualifier", suffix, "_s"), e.getErrQualifier());
        if (e.getErrorValue() != null && !"".equals(e.getErrorValue()))
            bucket.put(ns("err", suffix, "_d"), e.getErrorValue());
    }
    final String catchall4search = "_text_";
    if (e.getTextValue() != null) {
        if (e.getTextValue().toString().startsWith("{")) {
            IParams nonzero = SubstanceStudyParser.parseTextValueProteomics(dx, e.getTextValue().toString());
            bucket.put(catchall4search, nonzero);
        } else {
            bucket.put(ns("textValue", suffix, "_s"), e.getTextValue());
        }
    }
// condition2bucket(e,bucket,"condition.");
}
Also used : IParams(ambit2.base.data.study.IParams)

Example 3 with ProtocolApplication

use of ambit2.base.data.study.ProtocolApplication in project ambit-mirror by ideaconsult.

the class SubstanceStudyResource method createQuery.

@Override
protected Q createQuery(Context context, Request request, Response response) throws ResourceException {
    Object key = request.getAttributes().get(SubstanceResource.idsubstance);
    if (key == null) {
        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST);
    } else {
        substanceUUID = key.toString();
        try {
            Form form = getRequest().getResourceRef().getQueryAsForm();
            String topCategory = form.getFirstValue("top");
            String category = form.getFirstValue("category");
            String property = form.getFirstValue("property");
            String property_uri = form.getFirstValue("property_uri");
            String document_uuid = form.getFirstValue("document_uuid");
            String investigation_uuid = form.getFirstValue("investigation");
            ReadSubstanceStudy q = new ReadSubstanceStudy();
            q.setFieldname(substanceUUID);
            if (topCategory != null || category != null || property != null || property_uri != null || investigation_uuid != null || document_uuid != null) {
                Protocol p = new ambit2.base.data.study.Protocol("");
                p.setTopCategory(topCategory);
                p.setCategory(category);
                ProtocolApplication papp = new ProtocolApplication(p);
                papp.setDocumentUUID(document_uuid);
                papp.setInvestigationUUID(investigation_uuid);
                if (property_uri != null)
                    try {
                        // not nice REST style, but easiest to parse the URI
                        // not nice REST style, but easiest to parse the URI
                        Reference puri = new Reference(property_uri.endsWith("/") ? property_uri.substring(0, property_uri.length() - 2) : property_uri);
                        // the very last segment denotes protocol, then study type, then one is the endpoint hash
                        if (// this is the protocol
                        puri.getSegments().get(puri.getSegments().size() - 1).indexOf("-") > 0)
                            property = puri.getSegments().get(puri.getSegments().size() - 3);
                        else
                            property = puri.getSegments().get(puri.getSegments().size() - 2);
                        if (property.length() != 40)
                            property = null;
                    } catch (Exception x) {
                    }
                if (property != null) {
                    EffectRecord effect = new EffectRecord();
                    effect.setSampleID(property);
                    papp.addEffect(effect);
                }
                q.setValue(papp);
            }
            // q.setFieldname(relation);
            return (Q) q;
        } catch (Exception x) {
            throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST);
        }
    }
}
Also used : Form(org.restlet.data.Form) Reference(org.restlet.data.Reference) ReadSubstanceStudy(ambit2.db.substance.study.ReadSubstanceStudy) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) ResourceException(org.restlet.resource.ResourceException) ProtocolApplication(ambit2.base.data.study.ProtocolApplication) EffectRecord(ambit2.base.data.study.EffectRecord) ResourceException(org.restlet.resource.ResourceException) Protocol(ambit2.base.data.study.Protocol)

Example 4 with ProtocolApplication

use of ambit2.base.data.study.ProtocolApplication in project ambit-mirror by ideaconsult.

the class ProtocolApplicationTestFactory method initpa.

public static ProtocolApplication initpa() {
    Protocol protocol = new Protocol("Short-term toxicity to fish, IUC4#53/Ch.4.1");
    protocol.setCategory("EC_FISHTOX_SECTION");
    protocol.addGuideline("Method: other: acute toxicity test; \"static bioassay\"");
    ProtocolApplication papp = new ProtocolApplication<Protocol, IParams, String, IParams, String>(protocol);
    IParams params = new Params();
    params.put("Test organism", "Lepomis cyanellus");
    papp.setParameters(params);
    papp.setReference("reference");
    papp.setDocumentUUID("IUC4-7adb0d03-f69b-32a9-9efe-86b4a8577893");
    EffectRecord record = new EffectRecord<String, IParams, String>();
    params = new Params();
    params.put("Exposure", "96");
    record.setConditions(params);
    record.setEndpoint("LC50");
    record.setUnit("mg/L");
    record.setLoValue(83.1);
    papp.addEffect(record);
    papp.setUpdated(getTimeStamp());
    return papp;
}
Also used : ProtocolApplication(ambit2.base.data.study.ProtocolApplication) EffectRecord(ambit2.base.data.study.EffectRecord) IParams(ambit2.base.data.study.IParams) Params(ambit2.base.data.study.Params) IParams(ambit2.base.data.study.IParams) Protocol(ambit2.base.data.study.Protocol)

Example 5 with ProtocolApplication

use of ambit2.base.data.study.ProtocolApplication in project ambit-mirror by ideaconsult.

the class ProtocolApplicationTestFactory method initacutetox.

public static ProtocolApplication initacutetox() {
    Protocol protocol = new Protocol("Acute toxicity: oral, IUC4#2/Ch.5.1.1");
    protocol.setCategory("TO_ACUTE_ORAL_SECTION");
    protocol.addGuideline("Method: other: no data");
    ProtocolApplication papp = new ProtocolApplication<Protocol, IParams, String, IParams, String>(protocol);
    IParams params = new Params();
    papp.setParameters(params);
    papp.setReference("Smyth, H. F. Seaton J., and Fischer L. (1941).|The single dose toxicity of some glycols and derivatives.|J. Ind. Hyg. Toxicol. 23, 259-268");
    params.put("Species", "rat");
    params.put("Sex", "male/female");
    papp.setDocumentUUID("IUC4-ae64fc3b-22a4-3173-9362-9cce1ff622ae");
    EffectRecord record = new EffectRecord<String, IParams, String>();
    params = new Params();
    params.put("Temperature", "25 \u2103C");
    params.put("Sex", "male");
    record.setConditions(params);
    record.setEndpoint("LD50");
    record.setLoValue(260);
    record.setUpValue(320);
    record.setUnit("mg/kg bw");
    papp.addEffect(record);
    papp.setUpdated(getTimeStamp());
    return papp;
}
Also used : ProtocolApplication(ambit2.base.data.study.ProtocolApplication) EffectRecord(ambit2.base.data.study.EffectRecord) IParams(ambit2.base.data.study.IParams) Params(ambit2.base.data.study.Params) IParams(ambit2.base.data.study.IParams) Protocol(ambit2.base.data.study.Protocol)

Aggregations

ProtocolApplication (ambit2.base.data.study.ProtocolApplication)30 Protocol (ambit2.base.data.study.Protocol)19 EffectRecord (ambit2.base.data.study.EffectRecord)15 IParams (ambit2.base.data.study.IParams)13 SubstanceRecord (ambit2.base.data.SubstanceRecord)11 Params (ambit2.base.data.study.Params)8 CompositionRelation (ambit2.base.relation.composition.CompositionRelation)8 ArrayList (java.util.ArrayList)7 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)7 IStructureRecord (ambit2.base.interfaces.IStructureRecord)6 ExternalIdentifier (ambit2.base.data.substance.ExternalIdentifier)4 List (java.util.List)4 ReliabilityParams (ambit2.base.data.study.ReliabilityParams)3 SubstanceEndpointsBundle (ambit2.base.data.substance.SubstanceEndpointsBundle)3 UpdateEffectRecords (ambit2.db.substance.study.UpdateEffectRecords)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 Form (org.restlet.data.Form)3 ResourceException (org.restlet.resource.ResourceException)3 StructureRecord (ambit2.base.data.StructureRecord)2