use of ambit2.base.data.study.Params 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.Params 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.Params 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.Params 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.Params in project ambit-mirror by ideaconsult.
the class CompoundLookup method createQuery.
/*
*/
@Override
protected IQueryRetrieval<IStructureRecord> createQuery(Context context, Request request, Response response) throws ResourceException {
// parse params
Object id = null;
try {
id = getRequest().getAttributes().get(resourceKey);
if (id == null)
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "No structure identifier");
text = Reference.decode(id.toString().trim());
if ("".equals(text))
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Empty query");
} catch (Exception x) {
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, String.format("Invalid structure identifier", id));
}
id = null;
try {
id = getRequest().getAttributes().get(representationKey);
if (id == null)
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "No structure representation");
rep_id = NCISearchProcessor.METHODS.valueOf(Reference.decode(id.toString()));
} catch (Exception x) {
rep_id = null;
}
Form form = getParams();
try {
Object bundleURI = OpenTox.params.bundle_uri.getFirstValue(form);
Integer idbundle = bundleURI == null ? null : getIdBundle(bundleURI, request);
SubstanceEndpointsBundle bundle = new SubstanceEndpointsBundle(idbundle);
bundles = new SubstanceEndpointsBundle[1];
bundles[0] = bundle;
} catch (Exception x) {
bundles = null;
}
try {
includeMol = "true".equals(form.getFirstValue("mol"));
} catch (Exception x) {
includeMol = false;
}
try {
headless = Boolean.parseBoolean(form.getFirstValue("headless"));
} catch (Exception x) {
headless = false;
}
boolean casesens = "true".equals(form.getFirstValue(QueryResource.caseSensitive)) ? true : false;
String scparam = form.getFirstValue(QueryResource.condition);
setCondition(StringCondition.C_EQ);
if (scparam != null)
for (STRING_CONDITION sc : STRING_CONDITION.values()) {
if (scparam.equals(sc.getSQL())) {
setCondition(sc.getSQL());
break;
}
}
boolean retrieveProperties = "true".equals(form.getFirstValue(QueryResource.returnProperties)) ? true : false;
String url = null;
IQueryRetrieval<IStructureRecord> query = null;
if (isInchiKey(text))
try {
String inchikey = getFirstParam(form);
if ((inchikey == null) || (inchikey.trim().length() != 27))
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Invalid InChI Key");
QueryStructure q = new QueryStructure();
q.setChemicalsOnly(true);
q.setFieldname(ExactStructureSearchMode.inchikey);
q.setValue(inchikey.trim());
searchType = _searchtype.inchikey;
query = q;
} catch (ResourceException x) {
throw x;
} catch (Exception x) {
throw new ResourceException(Status.SERVER_ERROR_BAD_GATEWAY, String.format("%s %s", url, x.getMessage()), x);
}
else if (isURL(text))
try {
url = getFirstParam(form);
if (url == null)
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "No search parameter!");
Object q = CallableQueryProcessor.getQueryObject(new Reference(url), getRequest().getRootRef(), getApplication().getContext(), getCookies(), getAgent(), getRequest().getResourceRef().toString());
if (q == null) {
throw new ResourceException(Status.SERVER_ERROR_NOT_IMPLEMENTED, "TODO: retrieve compounds from foreign urls");
} else if (q instanceof AbstractStructureQuery) {
query = (IQueryRetrieval<IStructureRecord>) q;
}
} catch (ResourceException x) {
throw x;
} catch (Exception x) {
throw new ResourceException(Status.SERVER_ERROR_BAD_GATEWAY, String.format("%s %s", url, x.getMessage()), x);
}
else {
if (isSearchParam(text)) {
text = getFirstParam(form);
text_multi = getValuesArray(form);
}
Object idcompound = isAmbitID(text);
// query
if (idcompound != null) {
switch(searchType) {
case ambitid:
IStructureRecord record = new StructureRecord();
record.setIdchemical(((Integer) idcompound).intValue());
QueryStructureByID q = new QueryStructureByID();
q.setPageSize(1);
q.setChemicalsOnly(true);
q.setValue(record);
query = q;
break;
case inchikey:
String inchikey = idcompound.toString();
if ((inchikey == null) || (inchikey.trim().length() != 27))
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Invalid InChI Key");
QueryStructure q1 = new QueryStructure();
q1.setChemicalsOnly(true);
q1.setFieldname(ExactStructureSearchMode.inchikey);
q1.setValue(inchikey.trim());
searchType = _searchtype.inchikey;
query = q1;
break;
default:
query = null;
break;
}
} else if ((text_multi != null) && (text_multi.length > 1)) {
query = getMultiTextQuery(null, casesens, retrieveProperties, text_multi);
} else if ((text == null) || "".equals(text)) {
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST);
} else if (CASProcessor.isValidFormat(text)) {
// number
if (CASNumber.isValid(text.trim())) {
searchType = _searchtype.cas;
query = getTextQuery(Property.getCASInstance(), casesens, retrieveProperties, text);
}
} else if (EINECS.isValidFormat(text)) {
// we'd better not search for invalid numbers
if (EINECS.isValid(text.trim())) {
searchType = _searchtype.einecs;
query = getTextQuery(Property.getEINECSInstance(), casesens, retrieveProperties, text);
}
} else {
if ("".equals(text)) {
// if inchi
} else if (isInChI(text)) {
QueryStructure q = new QueryStructure();
q.setChemicalsOnly(true);
q.setFieldname(ExactStructureSearchMode.inchi);
q.setValue(text);
query = q;
} else if (isMol(text)) {
String[] inchi = mol2inchi(text);
QueryStructure q = new QueryStructure();
q.setChemicalsOnly(true);
q.setFieldname(ExactStructureSearchMode.inchi);
// eventually search by inchikey?
q.setValue(inchi[0]);
query = q;
} else
try {
// inchi, inchikey
String[] inchi = smiles2inchi(text.trim());
QueryStructure q = new QueryStructure();
q.setChemicalsOnly(true);
q.setFieldname(ExactStructureSearchMode.inchi);
// eventually search by inchikey?
q.setValue(inchi[0]);
query = q;
} catch (InvalidSmilesException x) {
query = null;
// otherwise this was valid smiles, but inchi failed!
} catch (CDKException x) {
casesens = true;
query = null;
} catch (Exception x) {
casesens = true;
query = null;
}
}
}
if (query == null)
query = getTextQuery(null, casesens, retrieveProperties, text);
setPaging(form, query);
setTemplate(createTemplate(form));
setGroupProperties(context, request, response);
return query;
}
Aggregations