use of ambit2.base.data.substance.SubstanceProperty in project ambit-mirror by ideaconsult.
the class SubstancePropertyresourceTest method testCreateEntry2.
@Test
public void testCreateEntry2() throws Exception {
EffectRecord<String, IParams, String> effect = new EffectRecord<String, IParams, String>();
effect.setConditions(new Params());
effect.setEndpoint("EC10");
effect.setUnit("mg/L");
IParams conditions = new Params();
effect.setConditions(conditions);
/*
Value v = new Value();
v.setUnits("h");
v.setLoValue(48.0);
effect.getConditions().put("EC_DAPHNIATOX",v);
*/
// System.out.println(effect);
SubstanceProperty prop = new SubstanceProperty(null, null, effect.getEndpoint(), effect.getUnit(), null);
String key = prop.createHashedIdentifier(effect.getConditions());
UUID protocol_uuid = UUID.nameUUIDFromBytes("http://localhost:8080/ambit2/dataset/Method%3A+other%3A+Am.+Soc.+Test.+Mater.+%281980%29+and+U.S.+EPA+%281975%29".getBytes());
URL url = getClass().getClassLoader().getResource("feature.rdf");
FileRepresentation rep = new FileRepresentation(url.getFile(), MediaType.APPLICATION_RDF_XML, 0);
testAsyncPoll(new Reference(getTestURI()), MediaType.TEXT_URI_LIST, rep, Method.POST, new Reference(String.format("http://localhost:%d/property/ECOTOX/EC_DAPHNIATOX_SECTION/EC10/%s/NOTSPECIFIED/%s", port, key.toUpperCase(), protocol_uuid)));
}
use of ambit2.base.data.substance.SubstanceProperty in project ambit-mirror by ideaconsult.
the class CallableEndpointsBundle method getTarget.
@Override
protected SubstanceProperty getTarget(Form input) throws Exception {
if (Method.POST.equals(method)) {
SubstanceProperty record = new SubstanceProperty(null, null, null, "Default");
parseForm(input, record);
command = update_command.add;
return record;
} else if (Method.PUT.equals(method)) {
command = null;
SubstanceProperty record = new SubstanceProperty(null, null, null, "Default");
parseForm(input, record);
if (command != null)
return record;
else
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST);
}
throw new ResourceException(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
}
use of ambit2.base.data.substance.SubstanceProperty 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;
}
use of ambit2.base.data.substance.SubstanceProperty in project ambit-mirror by ideaconsult.
the class CallableSubstancePropertyCreator method parseForm.
protected SubstanceProperty parseForm(Form form) throws ResourceException {
String topCategory = null;
ProtocolEffectRecord<String, IParams, String> detail = new ProtocolEffectRecord<String, IParams, String>();
String endpointcategory = form.getFirstValue(_param_endpointcategory);
try {
topCategory = Protocol._categories.valueOf(endpointcategory.trim()).getTopCategory();
} catch (Exception x) {
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Unsupported endpoint category");
}
detail.setEndpoint(form.getFirstValue(_param_name));
if (detail.getEndpoint() == null)
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Unsupported name");
detail.setUnit(form.getFirstValue(_param_units));
try {
String p_conditions = form.getFirstValue(_param_conditions);
if (p_conditions != null) {
JsonNode conditions = mapper.readTree(new StringReader(p_conditions));
if (conditions instanceof ObjectNode) {
detail.setConditions(SubstanceStudyParser.parseParams((ObjectNode) conditions));
}
}
} catch (Exception x) {
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "conditions: unexpected format");
}
String guideline = form.getFirstValue(_param_protocol);
if (guideline == null)
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "protocol: undefined");
Protocol protocol = new Protocol(guideline);
// protocol.addGuideline("Method: other: see below");
protocol.setCategory(endpointcategory);
protocol.setTopCategory(topCategory);
detail.setProtocol(protocol);
try {
SubstanceProperty p = processor.process(detail);
p.setIdentifier(p.createHashedIdentifier(detail.getConditions()));
return p;
} catch (ResourceException x) {
throw x;
} catch (Exception x) {
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, x.getMessage(), x);
}
}
use of ambit2.base.data.substance.SubstanceProperty 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;
}
Aggregations