use of ambit2.base.data.study.Value 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.study.Value 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) {
}
}
}
use of ambit2.base.data.study.Value in project ambit-mirror by ideaconsult.
the class CallableSubstancePropertyCreatorTest method testCreateSubstanceProperty.
@Test
public void testCreateSubstanceProperty() throws Exception {
Form form = new Form();
form.add("endpointcategory", Protocol._categories.ZETA_POTENTIAL_SECTION.name());
form.add("name", "ZETA POTENTIAL");
form.add("unit", "mV");
form.add("protocol", "Method: other: no data");
Params p = new Params();
Value v = new Value();
v.setLoValue(4.26);
p.put("pH", v);
Assert.assertEquals("{\"pH\":{\"loValue\":4.26}}", p.toString());
try {
PropertyURIReporter reporter = new PropertyURIReporter(new Reference("http://localhost:8081/ambit2"));
CallableSubstancePropertyCreator callable = new CallableSubstancePropertyCreator(reporter, Method.POST, form, null, null);
TaskResult task = callable.call();
Assert.assertTrue(task.getUri().startsWith("http://localhost:8081/ambit2/property/P-CHEM/ZETA_POTENTIAL_SECTION/ZETA+POTENTIAL/A597EBC063D7A5A605B9535656E09149A72F0C23"));
// "http://localhost:8081/ambit2/property/P-CHEM/ZETA_POTENTIAL_SECTION/ZETA+POTENTIAL/945DEEC24F876DEE6116F92646EF729107F5B5FD"
} catch (Exception x) {
throw x;
} finally {
}
}
use of ambit2.base.data.study.Value in project ambit-mirror by ideaconsult.
the class CallableSubstancePropertyCreatorTest method testCreateSubstanceProperty_TO_BIODEG_WATER_SCREEN_SECTION.
/**
* @throws Exception
*/
@Test
public void testCreateSubstanceProperty_TO_BIODEG_WATER_SCREEN_SECTION() throws Exception {
Form form = new Form();
form.add("endpointcategory", Protocol._categories.TO_BIODEG_WATER_SCREEN_SECTION.name());
form.add("name", "% Degradation");
form.add("unit", "%");
form.add("protocol", "Method: other: no data");
Params p = new Params();
Value v = new Value();
v.setUnits("d");
v.setLoValue(7.0);
p.put("Sampling time", v);
form.add("conditions", p.toString());
Assert.assertEquals("{\"Sampling time\":{\"loValue\":7,\"unit\":\"d\"}}", p.toString());
try {
PropertyURIReporter reporter = new PropertyURIReporter(new Reference("http://localhost:8081/ambit2"));
CallableSubstancePropertyCreator callable = new CallableSubstancePropertyCreator(reporter, Method.POST, form, null, null);
TaskResult task = callable.call();
Assert.assertTrue(task.getUri().startsWith("http://localhost:8081/ambit2/property/ENV+FATE/TO_BIODEG_WATER_SCREEN_SECTION/%25+Degradation/3CF77D9EFE4E74744E691BF4880B4EF728B16FAE"));
// /d4cd0dab-cf4c-3a22-ad92-fab40844c786
/*
* "http://localhost:8080/ambit2/property/ENV+FATE/TO_BIODEG_WATER_SCREEN_SECTION/%25+Degradation/5FA6EFD4E83BEC47B626C6149DBBD3907084187F/1f255895-eb7d-37dc-8eb8-bc9580d8be25"
* :{
*
* "type":"Feature", "title":"% Degradation", "units":"%",
* "isNominal":false, "isNumeric":false, "isMultiValue":true,
* "sameAs"
* :"http://www.opentox.org/echaEndpoints.owl#TO_BIODEG_WATER_SCREEN"
* , "isModelPredictionFeature":false,
* "creator":"Method: other: see below", "order":1087, "source":{
* "URI"
* :"http://localhost:8080/ambit2/dataset/Method%3A+other%3A+see+below"
* , "type":"Dataset" }, "annotation":[ { "p" : "Sampling time", "o"
* : "7.0 d"}]
*
* },
*/
// http://localhost:8081/ambit2/property/P-CHEM/TO_BIODEG_WATER_SCREEN_SECTION/%25+Degradation/8C9DF1AF60CA3D8706C0156361E97E0DF4391C10/1f255895-eb7d-37dc-8eb8-bc9580d8be25
} catch (Exception x) {
throw x;
} finally {
}
}
use of ambit2.base.data.study.Value in project ambit-mirror by ideaconsult.
the class CompoundResourceTest method testCreateEntryFromSmilesWebForm.
@Test
public void testCreateEntryFromSmilesWebForm() throws Exception {
OTClient otclient = new OTClient();
CompoundClient cli = otclient.getCompoundClient();
Compound substance = new Compound();
substance.setName("warfarin");
String inchi = "InChI=1S/C19H16O4/c1-12(20)11-15(13-7-3-2-4-8-13)17-18(21)14-9-5-6-10-16(14)23-19(17)22/h2-10,15,21H,11H2,1H3";
String smiles = "CC(=O)CC(c1ccccc1)c2c(c3ccccc3oc2=O)O";
substance.setInChI(inchi);
substance.setSMILES(smiles);
URL serviceRoot = new URL(String.format("http://localhost:%d/", port));
RemoteTask task = cli.registerSubstanceAsync(serviceRoot, substance, null, null);
task.waitUntilCompleted(500);
otclient.close();
Assert.assertEquals(HttpStatus.SC_OK, task.getStatus());
Assert.assertNull(task.getError());
System.out.println(task.getResult());
IDatabaseConnection c = getConnection();
ITable table = c.createQueryTable("EXPECTED", "SELECT * FROM property_string where value = 'CC(=O)CC(c1ccccc1)c2c(c3ccccc3oc2=O)O'");
Assert.assertEquals(0, table.getRowCount());
table = c.createQueryTable("EXPECTED", "SELECT * FROM structure");
Assert.assertEquals(6, table.getRowCount());
table = c.createQueryTable("EXPECTED", "SELECT * FROM chemicals where inchikey = 'PJVWKTKQMONHTI-UHFFFAOYSA-N'");
Assert.assertEquals(1, table.getRowCount());
table = c.createQueryTable("EXPECTED", "SELECT * FROM chemicals where inchi = '" + inchi + "'");
Assert.assertEquals(1, table.getRowCount());
c.close();
}
Aggregations