Search in sources :

Example 1 with IValue

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

the class ARFFReporter method processItem.

@Override
public Object processItem(IStructureRecord item) throws AmbitException {
    try {
        Writer writer = tmpWriter;
        writeHeader(writer);
        int i = 0;
        String uri = null;
        if (item instanceof SubstanceRecord) {
            uri = String.format("%s/substance/%s", urlPrefix, ((SubstanceRecord) item).getSubstanceUUID());
        } else {
            uri = String.format("%s/compound/%d", urlPrefix, item.getIdchemical());
            if (item.getIdstructure() > 0)
                uri = String.format("%s/conformer/%d", uri, item.getIdstructure());
        }
        // output.append(delimiter);
        // output.append(uri);
        delimiter = ",";
        writer.write(uri);
        for (Property p : header) {
            Object value = item.getRecordProperty(p);
            if (value instanceof MultiValue) {
                MultiValue<IValue> mv = (MultiValue<IValue>) value;
                for (IValue m : mv) {
                    writer.write(String.format(",%s", m.getLoValue()));
                    break;
                }
            } else {
                if ((value != null) && p.isNominal()) {
                    p.addAllowedValue(value.toString());
                }
                if (p.isNominal())
                    writer.write(String.format(",%s", (value == null) || (IQueryRetrieval.NaN.equals(value.toString())) ? "?" : value));
                else if (p.getClazz() == Number.class) {
                    writer.write(String.format(",%s", (value == null) || (value instanceof String) || (IQueryRetrieval.NaN.equals(value.toString())) ? "?" : value));
                } else
                    writer.write(String.format(",%s%s%s", value == null ? "" : "\"", value == null ? "?" : value.toString().replace("\n", "").replace("\r", ""), value == null ? "" : "\""));
            }
            i++;
        }
        writer.write('\n');
    } catch (Exception x) {
        logger.log(java.util.logging.Level.SEVERE, x.getMessage(), x);
    }
    return null;
}
Also used : IValue(ambit2.base.data.study.IValue) SubstanceRecord(ambit2.base.data.SubstanceRecord) Property(ambit2.base.data.Property) BufferedWriter(java.io.BufferedWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer) MultiValue(ambit2.base.data.study.MultiValue) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) DbAmbitException(net.idea.modbcum.i.exceptions.DbAmbitException) IOException(java.io.IOException)

Example 2 with IValue

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

the class ReadChemPropertiesByComposition method processDetail.

/**
 * Hack for merging dataset properties with substances; This is not
 * necessarily correct, as the substance may have many components!
 *
 * @param target
 * @param detail
 * @return
 * @throws Exception
 */
public SubstanceRecord processDetail(SubstanceRecord target, IStructureRecord detail) throws Exception {
    for (Property p : detail.getRecordProperties()) {
        if (p.getName().indexOf("#explanation") > 0)
            continue;
        else if (p.getName().indexOf("Error") >= 0)
            continue;
        else if (p.getName().indexOf("Alert for") == 0)
            continue;
        else if (p.getName().indexOf("For a better assessment") >= 0)
            continue;
        Protocol._categories category = Protocol._categories.SUPPORTING_INFO_SECTION;
        if (p.getLabel().endsWith("Carcinogenicity"))
            category = Protocol._categories.TO_CARCINOGENICITY_SECTION;
        else if (p.getLabel().endsWith("Mutagenicity"))
            category = Protocol._categories.TO_GENETIC_IN_VITRO_SECTION;
        else if (p.getLabel().endsWith("Dissociation_constant_pKa"))
            category = Protocol._categories.PC_DISSOCIATION_SECTION;
        else if (p.getLabel().endsWith("Octanol-water_partition_coefficient_Kow"))
            category = Protocol._categories.PC_PARTITION_SECTION;
        else if (p.getLabel().endsWith("Acute_toxicity_to_fish_lethality"))
            category = Protocol._categories.EC_FISHTOX_SECTION;
        else if (p.getLabel().endsWith("Eye_irritation_corrosion"))
            category = Protocol._categories.TO_EYE_IRRITATION_SECTION;
        else if (p.getLabel().endsWith("SkinIrritationCorrosion"))
            category = Protocol._categories.TO_SKIN_IRRITATION_SECTION;
        else if (p.getLabel().endsWith("SkinSensitisation"))
            category = Protocol._categories.TO_SENSITIZATION_SECTION;
        else if (p.getLabel().endsWith("PersistenceBiodegradation"))
            category = Protocol._categories.TO_BIODEG_WATER_SCREEN_SECTION;
        else if (p.getLabel().endsWith("Genotoxicity"))
            category = Protocol._categories.TO_GENETIC_IN_VITRO_SECTION;
        else if (p.getLabel().endsWith("ReproductiveToxicity"))
            category = Protocol._categories.TO_REPRODUCTION_SECTION;
        else if (p.getLabel().endsWith("DevelopmentalToxicity"))
            category = Protocol._categories.TO_DEVELOPMENTAL_SECTION;
        else if (p.getLabel().endsWith("Sensitisation"))
            category = Protocol._categories.TO_SENSITIZATION_SECTION;
        else if (p.getLabel().endsWith("Respiratory_sensitisation"))
            category = Protocol._categories.TO_REPEATED_INHAL_SECTION;
        SubstanceProperty sp = new SubstanceProperty("TOX", category.name().replace("_SECTION", ""), p.getName(), p.getUnits(), p.getReference());
        sp.setEnabled(true);
        if (p.getReference().getType().equals(_type.Dataset))
            sp.setStudyResultType(_r_flags.experimentalresult);
        else
            sp.setStudyResultType(_r_flags.estimatedbycalculation);
        if (detail.getRecordProperty(p) != null) {
            target.setRecordProperty(sp, detail.getRecordProperty(p));
        /*
				 * Object value = target.getProperty(sp); if (value == null)
				 * target.setProperty(sp, detail.getProperty(p)); else { if
				 * (value instanceof MultiValue) { IValue v = new
				 * Value(detail.getProperty(p)); ((MultiValue) value).add(v); }
				 * else { MultiValue v = new MultiValue(); IValue vo = new
				 * Value(value); v.add(vo); vo = new
				 * Value(detail.getProperty(p)); v.add(vo);
				 * target.setProperty(sp, v); }
				 * 
				 * }
				 */
        }
    }
    return target;
}
Also used : SubstanceProperty(ambit2.base.data.substance.SubstanceProperty) Protocol(ambit2.base.data.study.Protocol) SubstanceProperty(ambit2.base.data.substance.SubstanceProperty) Property(ambit2.base.data.Property)

Example 3 with IValue

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

the class ConditionJsonParser method getDescriptorValueCondition.

public static IDescriptorValueCondition getDescriptorValueCondition(JsonNode node) throws Exception {
    StringBuffer errors = new StringBuffer();
    String descrName = JSONParsingUtils.extractStringKeyword(node, "DESCRIPTOR", true);
    String descrRelationStr = JSONParsingUtils.extractStringKeyword(node, "RELATION", true);
    IValue.Relation relation = Relation.getRelationFromString(descrRelationStr);
    Double descrValue = JSONParsingUtils.extractDoubleKeyword(node, "VALUE", true);
    if (errors.toString().isEmpty()) {
        IValue val = new Value();
        val.setValue(descrValue);
        val.setRelation(relation);
        IDescriptorValueCondition dvc = new DescriptorValueCondition(val, null, descrName);
        return dvc;
    } else
        throw new Exception("Errors in DescriptorValueCondition: " + errors.toString());
}
Also used : IDescriptorValueCondition(ambit2.rules.conditions.IDescriptorValueCondition) Relation(ambit2.rules.conditions.value.IValue.Relation) IValue(ambit2.rules.conditions.value.IValue) DescriptorValueCondition(ambit2.rules.conditions.DescriptorValueCondition) IDescriptorValueCondition(ambit2.rules.conditions.IDescriptorValueCondition) Value(ambit2.rules.conditions.value.Value) IValue(ambit2.rules.conditions.value.IValue)

Example 4 with IValue

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

the class StructureRecordXLSXReporter method processItem.

@Override
public Object processItem(IStructureRecord item) throws Exception {
    Row row = sheet.createRow(rowIndex);
    row.setHeightInPoints(new Float(d.getHeight() + 2 * offset));
    int r = 0;
    if (item instanceof SubstanceRecord) {
        SubstanceRecord record = (SubstanceRecord) item;
        Cell cell = row.createCell(_columns.tag.ordinal());
        cell.setCellType(CellType.NUMERIC);
        cell.setCellStyle(style);
        cell.setCellValue(rowIndex);
        cell = row.createCell(_columns.name.ordinal());
        cell.setCellType(CellType.STRING);
        cell.setCellStyle(style);
        try {
            Object name = record.getRecordProperty(new SubstancePublicName());
            cell.setCellValue(name == null ? record.getRecordProperty(new SubstanceName()).toString() : name.toString());
        } catch (Exception x) {
        }
        for (Property p : record.getRecordProperties()) if (p.getLabel().startsWith(prefix)) {
            Integer colIndex = mergedProperties.get(p.getLabel());
            if (colIndex == null) {
                int last = mergedProperties.size();
                mergedProperties.put(p.getLabel(), last);
                colIndex = last;
            }
            Cell pcell = row.getCell(colIndex + _columns.component.ordinal() + 1);
            if (pcell == null) {
                pcell = row.createCell(colIndex + _columns.component.ordinal() + 1);
                pcell.setCellStyle(blueStyle);
                pcell.setCellType(CellType.STRING);
                Cell hcell = sheet.getRow(0).createCell(colIndex + _columns.component.ordinal() + 1);
                hcell.setCellType(CellType.STRING);
                hcell.setCellStyle(hstyle);
                String h = p.getLabel().replace(prefix, "");
                try {
                    Protocol._categories c = Protocol._categories.valueOf(h + "_SECTION");
                    hcell.setCellValue(c.getNumber() + ". " + c.toString());
                } catch (Exception x) {
                    hcell.setCellValue(h);
                }
                if (isAutosizeColumns())
                    sheet.autoSizeColumn(hcell.getColumnIndex(), true);
                sheet.setColumnHidden(hcell.getColumnIndex(), false);
            }
            Object value = record.getRecordProperty(p);
            try {
                String cellvalue = formatter.format((SubstanceProperty) p, value);
                if (cellvalue == null || "".equals(cellvalue.trim())) {
                // do nothing
                } else {
                    _r_flags studyResultType = ((SubstanceProperty) p).getStudyResultType();
                    String flag = "";
                    Font font = redFont;
                    if (studyResultType != null)
                        switch(studyResultType) {
                            case experimentalresult:
                                {
                                    font = blueFont;
                                    break;
                                }
                            case other:
                                {
                                    font = blackFont;
                                    break;
                                }
                            case unsupported:
                                {
                                    font = blackFont;
                                    break;
                                }
                            case NOTSPECIFIED:
                                {
                                    font = blackFont;
                                    break;
                                }
                            case nodata:
                                {
                                    font = blackFont;
                                    break;
                                }
                            default:
                                {
                                    font = redFont;
                                    flag = studyResultType.getIdentifier() + ": ";
                                }
                        }
                    RichTextString rtvalue = pcell.getRichStringCellValue();
                    if (rtvalue == null || rtvalue.length() == 0 || "".equals(rtvalue.getString().trim())) {
                        pcell.setCellValue(createRichTextString(flag + cellvalue, font));
                    } else {
                        if (rtvalue instanceof XSSFRichTextString) {
                            ((XSSFRichTextString) rtvalue).append("\n" + flag + cellvalue, (XSSFFont) font);
                        } else {
                            pcell.setCellValue(createRichTextString(pcell.getStringCellValue() + "\n" + flag + cellvalue, font));
                        }
                    }
                    if (isAutosizeColumns())
                        sheet.autoSizeColumn(pcell.getColumnIndex(), true);
                }
            } catch (Exception x) {
                if (value instanceof IValue) {
                    value = p.getName() + "=" + ((IValue) value).toHumanReadable() + ((p.getUnits() != null) ? p.getUnits() : "") + (p.getReference().getURL() != null ? ("[" + p.getReference().getURL() + "]") : "");
                } else if (value instanceof MultiValue) {
                    StringBuilder b = new StringBuilder();
                    for (int i = 0; i < ((MultiValue) value).size(); i++) {
                        if (i > 0)
                            b.append("\n");
                        b.append(p.getName());
                        b.append("=");
                        b.append(((IValue) ((MultiValue) value).get(i)).toHumanReadable());
                        if (p.getUnits() != null)
                            b.append(p.getUnits());
                    }
                    if (p.getReference().getURL() != null) {
                        b.append(" [");
                        b.append(p.getReference().getURL());
                        b.append("]");
                    }
                    value = b.toString();
                } else {
                    value = p.getName() + "=" + value.toString() + ((p.getUnits() != null) ? p.getUnits() : "") + (p.getReference().getURL() != null ? ("[" + p.getReference().getURL() + "]") : "");
                }
                pcell.setCellValue(String.format("%s%s%s", pcell.getStringCellValue() == null ? "" : pcell.getStringCellValue(), pcell.getStringCellValue() == null ? "" : "\n", value.toString()));
            }
        }
        // 
        if (record.getRelatedStructures() != null) {
            for (CompositionRelation relation : record.getRelatedStructures()) {
                Row structure = (r == 0) ? row : sheet.createRow((short) (rowIndex + r));
                try {
                    structure.setHeightInPoints(new Float(d.getHeight() + 2 * offset));
                    addPicture(relation.getSecondStructure(), structure.getRowNum(), _columns.diagram.ordinal());
                } catch (Exception x) {
                    x.printStackTrace();
                }
                Cell cellStruc = structure.createCell(_columns.component.ordinal());
                cellStruc.setCellStyle(style);
                cellStruc.setCellValue(relation.getRelationType().toHumanReadable());
                r++;
            }
        }
    }
    if (r > 1) {
        for (int c = 0; c < mergedProperties.size(); c++) {
            sheet.addMergedRegion(new CellRangeAddress(rowIndex, rowIndex + r - 1, c + _columns.component.ordinal() + 1, c + _columns.component.ordinal() + 1));
        }
        rowIndex += r;
    } else
        rowIndex++;
    return item;
}
Also used : SubstanceName(ambit2.base.data.substance.SubstanceName) SubstanceRecord(ambit2.base.data.SubstanceRecord) RichTextString(org.apache.poi.ss.usermodel.RichTextString) XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) RichTextString(org.apache.poi.ss.usermodel.RichTextString) XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) DbAmbitException(net.idea.modbcum.i.exceptions.DbAmbitException) IOException(java.io.IOException) XSSFFont(org.apache.poi.xssf.usermodel.XSSFFont) Font(org.apache.poi.ss.usermodel.Font) XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) IValue(ambit2.base.data.study.IValue) XSSFFont(org.apache.poi.xssf.usermodel.XSSFFont) ReliabilityParams._r_flags(ambit2.base.data.study.ReliabilityParams._r_flags) SubstanceProperty(ambit2.base.data.substance.SubstanceProperty) Row(org.apache.poi.ss.usermodel.Row) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) Cell(org.apache.poi.ss.usermodel.Cell) Property(ambit2.base.data.Property) SubstanceProperty(ambit2.base.data.substance.SubstanceProperty) SubstancePublicName(ambit2.base.data.substance.SubstancePublicName) MultiValue(ambit2.base.data.study.MultiValue) CompositionRelation(ambit2.base.relation.composition.CompositionRelation)

Example 5 with IValue

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

the class CompoundJSONReporter method processItem.

@Override
public Object processItem(IStructureRecord item) throws AmbitException {
    try {
        Writer writer = getOutput();
        writeHeader(writer);
        append2header(writer, item);
        int i = 0;
        String uri = getURI(item);
        StringBuilder builder = new StringBuilder();
        if (comma != null)
            builder.append(comma);
        builder.append("\n\t{\n");
        builder.append(String.format("\t\"%s\":{\n", jsonCompound.compound.jsonname()));
        builder.append(String.format("\t\t\"%s\":\"%s\",\n", jsonCompound.URI.jsonname(), uri));
        builder.append(String.format("\t\t\"%s\":\"%s\",\n", jsonCompound.structype.jsonname(), item.getType().name()));
        if (includeMol)
            if (item.getContent() == null)
                builder.append(String.format("\t\t\"%s\":null,\n", jsonCompound.mol.jsonname()));
            else
                builder.append(String.format("\t\t\"%s\":\"%s\",\n", jsonCompound.mol.jsonname(), JSONUtils.jsonEscape(getSDFContent(item))));
        // similarity
        Object similarityValue = null;
        for (Property p : item.getRecordProperties()) if ("metric".equals(p.getName())) {
            similarityValue = item.getRecordProperty(p);
            break;
        }
        builder.append(String.format("\t\t\"metric\":%s,\n", similarityValue));
        // placeholders
        builder.append(String.format("\t\t\"%s\":\"\",\n", "name"));
        builder.append(String.format("\t\t\"%s\":\"\",\n", "cas"));
        builder.append(String.format("\t\t\"%s\":\"\"\n", "einecs"));
        if (item.getInchiKey() != null)
            builder.append(String.format(",\t\t\"%s\":\"%s\"\n", "inchikey", item.getInchiKey()));
        if (item.getInchi() != null)
            builder.append(String.format(",\t\t\"%s\":\"%s\"\n", "inchi", JSONUtils.jsonEscape(item.getInchi())));
        if (item.getFormula() != null)
            builder.append(String.format(",\t\t\"%s\":\"%s\"", "formula", JSONUtils.jsonEscape(item.getFormula())));
        builder.append("\n\t\t},\n");
        builder.append(String.format("\t\"%s\":{\n", jsonCompound.values.jsonname()));
        String comma1 = null;
        for (int j = 0; j < header.size(); j++) {
            Property p = header.get(j);
            Object value = item.getRecordProperty(p);
            String key = propertyJSONReporter.getURI(p);
            if (key.contains("cdk:Title") || key.contains("cdk:Formula"))
                continue;
            if (key.contains("SMARTSProp"))
                continue;
            if (value == null) {
                // builder.append(String.format("\t\t\"%s\":null",key));
                continue;
            }
            if (comma1 != null) {
                builder.append(comma1);
                builder.append("\n");
            }
            if (value instanceof Double) {
                if (((Double) value).isNaN())
                    builder.append(String.format(Locale.ENGLISH, "\t\t\"%s\":null", key));
                else
                    builder.append(String.format(Locale.ENGLISH, "\t\t\"%s\":%6.3f", key, (Double) value));
            } else if (value instanceof Integer)
                builder.append(String.format("\t\t\"%s\":%d", key, (Integer) value));
            else if (value instanceof Long)
                builder.append(String.format("\t\t\"%s\":%l", key, (Long) value));
            else if (value instanceof IValue)
                builder.append(String.format("\t\t\"%s\":%s", key, ((IValue) value)).toString());
            else if (value instanceof MultiValue) {
                StringBuilder b = new StringBuilder();
                String delimiter = "[";
                for (IValue v : (MultiValue<IValue>) value) {
                    b.append(delimiter);
                    b.append(v.toString());
                    delimiter = ",";
                }
                b.append("]\n");
                builder.append(String.format("\t\t\"%s\":%s", key, b.toString()));
            } else
                builder.append(String.format("\t\t\"%s\":\"%s\"", key, JSONUtils.jsonEscape(value.toString().replace("\n", "|"))));
            i++;
            comma1 = ",";
        }
        builder.append("\n\t\t},\n");
        builder.append(String.format("\t\"%s\":[\n", jsonCompound.facets.jsonname()));
        Iterable<IFacet> facets = item.getFacets();
        String delimiter = "";
        if (facets != null)
            for (IFacet facet : facets) {
                if (facet instanceof BundleRoleFacet)
                    continue;
                if (facet.getValue() == null)
                    continue;
                builder.append(delimiter);
                builder.append(String.format("\t\t{\"%s\":%d}", facet.getValue() == null ? "" : facet.getValue(), facet.getCount()));
                delimiter = ",";
            }
        builder.append("\n\t\t],");
        if ((item instanceof SubstanceRecord) && ((SubstanceRecord) item).getRelatedStructures() != null) {
            SubstanceRecord substance = (SubstanceRecord) item;
            builder.append(String.format("\n\t%s:[\n", JSONUtils.jsonQuote(jsonCompound.composition.jsonname())));
            List<CompositionRelation> composition = substance.getRelatedStructures();
            for (int j = 0; j < composition.size(); j++) {
                CompositionRelation cr = composition.get(j);
                if (j > 0)
                    builder.append(",\n");
                String component = "{}";
                if (cr.getSecondStructure() != null && cr.getSecondStructure().getIdchemical() > 0) {
                    // StringBuilder bundles = new StringBuilder();
                    // printBundles(cr.getSecondStructure().getFacets(),
                    // bundles);
                    Writer o = getOutput();
                    String savecomma = comma;
                    StringWriter w = new StringWriter();
                    setOutput(w);
                    setComma(null);
                    processItem(cr.getSecondStructure());
                    setOutput(o);
                    setComma(savecomma);
                    // System.out.println(w);
                    component = w.toString();
                /*
						 * component = String.format(
						 * "{\"compound\":{\"URI\":\"%s/compound/%d\",\n\t%s}}",
						 * urlPrefix
						 * ,cr.getSecondStructure().getIdchemical(),bundles
						 * .toString());
						 */
                }
                builder.append(cr.toJSON(uri, component));
            }
            builder.append("\n\t\t],");
        }
        printBundles(item.getFacets(), builder);
        builder.append("\n\t}");
        writer.write(builder.toString());
        comma = ",";
    } catch (Exception x) {
        logger.log(java.util.logging.Level.SEVERE, x.getMessage(), x);
    }
    return item;
}
Also used : SubstanceRecord(ambit2.base.data.SubstanceRecord) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) IOException(java.io.IOException) IValue(ambit2.base.data.study.IValue) StringWriter(java.io.StringWriter) IFacet(net.idea.modbcum.i.facet.IFacet) BundleRoleFacet(ambit2.base.facet.BundleRoleFacet) Property(ambit2.base.data.Property) SDFWriter(org.openscience.cdk.io.SDFWriter) StringWriter(java.io.StringWriter) Writer(java.io.Writer) MultiValue(ambit2.base.data.study.MultiValue) CompositionRelation(ambit2.base.relation.composition.CompositionRelation)

Aggregations

Property (ambit2.base.data.Property)4 IValue (ambit2.base.data.study.IValue)4 SubstanceRecord (ambit2.base.data.SubstanceRecord)3 MultiValue (ambit2.base.data.study.MultiValue)3 CompositionRelation (ambit2.base.relation.composition.CompositionRelation)3 IOException (java.io.IOException)3 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)3 SubstanceProperty (ambit2.base.data.substance.SubstanceProperty)2 BundleRoleFacet (ambit2.base.facet.BundleRoleFacet)2 Writer (java.io.Writer)2 DbAmbitException (net.idea.modbcum.i.exceptions.DbAmbitException)2 IFacet (net.idea.modbcum.i.facet.IFacet)2 EffectRecord (ambit2.base.data.study.EffectRecord)1 IParams (ambit2.base.data.study.IParams)1 Protocol (ambit2.base.data.study.Protocol)1 ProtocolApplication (ambit2.base.data.study.ProtocolApplication)1 ReliabilityParams._r_flags (ambit2.base.data.study.ReliabilityParams._r_flags)1 ExternalIdentifier (ambit2.base.data.substance.ExternalIdentifier)1 SubstanceEndpointsBundle (ambit2.base.data.substance.SubstanceEndpointsBundle)1 SubstanceName (ambit2.base.data.substance.SubstanceName)1