Search in sources :

Example 1 with ReliabilityParams._r_flags

use of ambit2.base.data.study.ReliabilityParams._r_flags 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 2 with ReliabilityParams._r_flags

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

the class StringArrayHeader method getExperiment.

protected ProtocolApplication<Protocol, IParams, String, IParams, String> getExperiment(CATEGORIES categories, SubstanceRecord record, Protocol protocol, ReliabilityParams reliability) {
    String experimentUUID = prefix + UUID.nameUUIDFromBytes((record.getSubstanceUUID() + lines[_lines.technology.ordinal()] + lines[_lines.endpoint.ordinal()]).getBytes());
    if (record.getMeasurements() != null)
        for (ProtocolApplication<Protocol, IParams, String, IParams, String> experiment : record.getMeasurements()) {
            if (experimentUUID.equals(experiment.getDocumentUUID()))
                return experiment;
        }
    ProtocolApplication<Protocol, IParams, String, IParams, String> experiment = new ProtocolApplication<Protocol, IParams, String, IParams, String>(protocol);
    experiment.setReliability(reliability);
    experiment.setParameters(new Params());
    experiment.getParameters().put("testmat_form", null);
    experiment.getParameters().put("Type of method", null);
    setCitation(experiment);
    experiment.setDocumentUUID(experimentUUID);
    return experiment;
}
Also used : ProtocolApplication(ambit2.base.data.study.ProtocolApplication) IParams(ambit2.base.data.study.IParams) Params(ambit2.base.data.study.Params) IParams(ambit2.base.data.study.IParams) ReliabilityParams(ambit2.base.data.study.ReliabilityParams) Protocol(ambit2.base.data.study.Protocol)

Example 3 with ReliabilityParams._r_flags

use of ambit2.base.data.study.ReliabilityParams._r_flags 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 4 with ReliabilityParams._r_flags

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

the class StudyFormatter method format.

public int format(final ProtocolApplication<Protocol, String, String, Object, String> pa, IStudyPrinter printer) throws Exception {
    _r_flags flag = null;
    try {
        for (_r_flags rf : _r_flags.values()) if (rf.toString().equals(pa.getReliability().getStudyResultType().toString())) {
            flag = rf;
            break;
        }
        ;
    } catch (Exception x) {
    }
    ObjectNode column = (ObjectNode) columns.get(pa.getProtocol().getCategory());
    // defaultColumn
    // TODO default column
    ObjectNode config = getGuidelineConfig(column);
    if (isVisible(config))
        try {
            printer.print(0, getColumn(config), getOrder(config), pa.getProtocol().getGuideline().get(0), false, flag);
        } catch (Exception x) {
            logger.log(Level.WARNING, x.getMessage());
        }
    config = getCitationConfig(column);
    if (isVisible(config))
        try {
            printer.print(0, getColumn(config), getOrder(config), pa.getReferenceYear(), false, flag);
        } catch (Exception x) {
            logger.log(Level.WARNING, x.getMessage());
        }
    config = getOwnerConfig(column);
    if (isVisible(config))
        printer.print(0, getColumn(config), getOrder(config), pa.getReferenceOwner(), false, flag);
    config = getInterpretationResultConfig(column);
    if (isVisible(config)) {
        printer.print(0, getColumn(config), getOrder(config), pa.getInterpretationResult(), true, flag);
    }
    config = getInterpretationResultCriteria(column);
    if (isVisible(config)) {
        printer.print(0, getColumn(config), getOrder(config), pa.getInterpretationCriteria(), false, flag);
    }
    try {
        JsonNode conditions = mapper.readTree(new StringReader(pa.getParameters()));
        if (conditions instanceof ObjectNode) {
            IParams params = SubstanceStudyParser.parseParams((ObjectNode) conditions);
            printConditions(0, params, getParametersConfig(column), printer, flag);
        }
    } catch (Exception x) {
    }
    /**
     * Effects
     */
    int row = 0;
    if (pa.getEffects() != null)
        for (EffectRecord<String, Object, String> effect : pa.getEffects()) {
            if (effect.getConditions() != null) {
                IParams params = SubstanceStudyParser.parseConditions(dx, effect.getConditions().toString());
                printConditions(row, params, getConditionsConfig(column), printer, flag);
            }
            config = getEndpointConfig(column);
            if (isVisible(config))
                printer.print(row, getColumn(config), getOrder(config), effect.getEndpoint(), false, flag);
            config = getResultConfig(column);
            if (isVisible(config))
                printer.print(row, getColumn(config), getOrder(config), formatValue(effect), true, flag);
            config = getTextResultConfig(column);
            if ((effect.getTextValue() != null) && isVisible(config))
                printer.print(row, getColumn(config), getOrder(config), effect.getTextValue().toString(), true, flag);
            row++;
        }
    return row + 1;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) EffectRecord(ambit2.base.data.study.EffectRecord) StringReader(java.io.StringReader) ReliabilityParams._r_flags(ambit2.base.data.study.ReliabilityParams._r_flags) IParams(ambit2.base.data.study.IParams) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 5 with ReliabilityParams._r_flags

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

the class ReadSubstanceStudy method getObject.

@Override
public PA getObject(ResultSet rs) throws AmbitException {
    if (record == null) {
        record = (PA) new ProtocolApplication<Protocol, String, String, IParams, String>(new Protocol(null));
    } else
        record.clear();
    try {
        Protocol protocol = new Protocol(rs.getString("endpoint"));
        protocol.addGuideline(rs.getString("guidance"));
        protocol.setCategory(rs.getString("endpointcategory"));
        protocol.setTopCategory(rs.getString("topcategory"));
        record.setProtocol(protocol);
        try {
            record.setDocumentUUID(I5Utils.getPrefixedUUID(rs.getString("document_prefix"), rs.getString("u")));
        } catch (Exception xx) {
            record.setDocumentUUID(null);
        }
        try {
            record.setSubstanceUUID(I5Utils.getPrefixedUUID(rs.getString("substance_prefix"), rs.getString("su")));
        } catch (Exception xx) {
            record.setSubstanceUUID(null);
        }
        record.setReference(rs.getString("reference"));
        try {
            record.setReferenceYear(Integer.toString(rs.getInt("reference_year")));
        } catch (Exception x) {
            record.setReferenceYear(null);
        }
        try {
            record.setReferenceOwner(rs.getString("reference_owner"));
        } catch (Exception x) {
            record.setReferenceOwner(null);
        }
        // parse json
        record.setParameters(rs.getString("params"));
        // parse
        record.setInterpretationCriteria(rs.getString("interpretation_criteria"));
        // json
        // parse
        record.setInterpretationResult(rs.getString("interpretation_result"));
        // json
        record.setCompanyName(rs.getString("owner_name"));
        try {
            record.setCompanyUUID(I5Utils.getPrefixedUUID(rs.getString("owner_prefix"), rs.getString("ou")));
        } catch (Exception xx) {
            record.setCompanyUUID(null);
        }
        try {
            record.setReferenceSubstanceUUID(I5Utils.getPrefixedUUID(rs.getString("rs_prefix"), rs.getString("rsu")));
        } catch (Exception xx) {
            record.setReferenceSubstanceUUID(null);
        }
        ReliabilityParams reliability = new ReliabilityParams();
        record.setReliability(reliability);
        try {
            reliability.setValue(rs.getString("reliability"));
        } catch (Exception x) {
        }
        try {
            reliability.setIsRobustStudy(rs.getBoolean("isRobustStudy"));
        } catch (Exception x) {
        }
        try {
            reliability.setIsUsedforClassification(rs.getBoolean("isUsedforClassification"));
        } catch (Exception x) {
        }
        try {
            reliability.setIsUsedforMSDS(rs.getBoolean("isUsedforMSDS"));
        } catch (Exception x) {
        }
        try {
            reliability.setPurposeFlag(rs.getString("purposeFlag"));
        } catch (Exception x) {
        }
        try {
            reliability.setStudyResultType(rs.getString("studyResultType"));
        } catch (Exception x) {
        }
        try {
            String iuuid = rs.getString("iuuid");
            record.setInvestigationUUID(iuuid);
        } catch (Exception x) {
            record.setInvestigationUUID((String) null);
        }
        try {
            String auuid = rs.getString("auuid");
            record.setAssayUUID(auuid);
        } catch (Exception x) {
            record.setAssayUUID((String) null);
        }
        try {
            record.setUpdated(new Date(rs.getTimestamp("updated").getTime()));
        } catch (Exception x) {
            record.setReferenceYear(null);
        }
    } catch (Exception x) {
        x.printStackTrace();
    }
    return record;
}
Also used : ProtocolApplication(ambit2.base.data.study.ProtocolApplication) ReliabilityParams(ambit2.base.data.study.ReliabilityParams) Protocol(ambit2.base.data.study.Protocol) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) Date(java.util.Date)

Aggregations

ReliabilityParams (ambit2.base.data.study.ReliabilityParams)3 IParams (ambit2.base.data.study.IParams)2 Protocol (ambit2.base.data.study.Protocol)2 ProtocolApplication (ambit2.base.data.study.ProtocolApplication)2 ReliabilityParams._r_flags (ambit2.base.data.study.ReliabilityParams._r_flags)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 IOException (java.io.IOException)2 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)2 Property (ambit2.base.data.Property)1 SubstanceRecord (ambit2.base.data.SubstanceRecord)1 EffectRecord (ambit2.base.data.study.EffectRecord)1 IValue (ambit2.base.data.study.IValue)1 MultiValue (ambit2.base.data.study.MultiValue)1 Params (ambit2.base.data.study.Params)1 SubstanceName (ambit2.base.data.substance.SubstanceName)1 SubstanceProperty (ambit2.base.data.substance.SubstanceProperty)1 SubstancePublicName (ambit2.base.data.substance.SubstancePublicName)1 CompositionRelation (ambit2.base.relation.composition.CompositionRelation)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 StringReader (java.io.StringReader)1