use of ambit2.base.data.StructureRecord 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.StructureRecord in project ambit-mirror by ideaconsult.
the class PropertyValueResource method createQuery.
@Override
protected IQueryRetrieval<T> createQuery(Context context, Request request, Response response) throws ResourceException {
RetrieveFieldPropertyValue field = new RetrieveFieldPropertyValue();
field.setSearchByAlias(true);
IStructureRecord record = new StructureRecord();
try {
record.setIdchemical(Integer.parseInt(Reference.decode(request.getAttributes().get(DataResources.idcompound_resource).toString())));
} catch (NumberFormatException x) {
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, String.format("Invalid resource id %d", request.getAttributes().get(DataResources.idcompound_resource)), x);
}
try {
record.setIdstructure(Integer.parseInt(Reference.decode(request.getAttributes().get(DataResources.idconformer_resource).toString())));
field.setChemicalsOnly(false);
} catch (Exception x) {
field.setChemicalsOnly(true);
} finally {
field.setValue(record);
}
try {
field.setFieldname(null);
Object name = request.getAttributes().get("name");
if (name != null) {
name = Reference.decode(name.toString());
field.setFieldname(Property.getInstance(name.toString(), LiteratureEntry.getInstance()));
}
} catch (Exception x) {
field.setFieldname(null);
}
return (IQueryRetrieval) field;
}
use of ambit2.base.data.StructureRecord in project ambit-mirror by ideaconsult.
the class ConformerResource method createQuery.
@Override
protected QueryStructureByID createQuery(Context context, Request request, Response response) throws ResourceException {
media = getMediaParameter(request);
Form form = request.getResourceRef().getQueryAsForm();
try {
headless = Boolean.parseBoolean(form.getFirstValue("headless"));
} catch (Exception x) {
headless = false;
}
try {
includeMol = "true".equals(form.getFirstValue("mol"));
} catch (Exception x) {
includeMol = false;
}
try {
setTemplate(createTemplate(context, request, response));
IStructureRecord record = new StructureRecord();
try {
record.setIdchemical(Integer.parseInt(Reference.decode(request.getAttributes().get(DataResources.idcompound_resource).toString())));
} catch (NumberFormatException x) {
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Invalid resource id", x);
}
QueryStructureByID query = new QueryStructureByID();
query.setPageSize(-1);
Object idconformer = request.getAttributes().get(DataResources.idconformer_resource);
try {
record.setIdstructure(Integer.parseInt(Reference.decode(idconformer.toString())));
query.setChemicalsOnly(false);
} catch (Exception x) {
record.setIdstructure(-1);
query.setChemicalsOnly(true);
query.setPageSize(-1);
query.setValue(record);
}
query.setValue(record);
return query;
} catch (Exception x) {
throw new ResourceException(Status.SERVER_ERROR_INTERNAL, "Invalid resource id", x);
}
}
use of ambit2.base.data.StructureRecord in project ambit-mirror by ideaconsult.
the class DatasetsByStructureResource method createQuery.
@Override
protected IQueryRetrieval<SourceDataset> createQuery(Context context, Request request, Response response) throws ResourceException {
try {
Form form = request.getResourceRef().getQueryAsForm();
headless = Boolean.parseBoolean(form.getFirstValue("headless"));
} catch (Exception x) {
headless = false;
}
int idcompound = -1;
int idstructure = -1;
try {
idcompound = OpenTox.URI.compound.getIntValue(getRequest());
try {
idstructure = OpenTox.URI.conformer.getIntValue(getRequest());
} catch (Exception x) {
idstructure = -1;
}
} catch (Exception x) {
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, OpenTox.URI.compound.getKey());
}
IStructureRecord record = new StructureRecord(idcompound, idstructure, null, null);
RetrieveDatasets q = new RetrieveDatasets();
q.setFieldname(record);
return q;
}
use of ambit2.base.data.StructureRecord in project ambit-mirror by ideaconsult.
the class CallableCompoundBundle method getTarget.
@Override
protected IStructureRecord getTarget(Form input) throws Exception {
if (Method.POST.equals(method)) {
IStructureRecord record = new StructureRecord();
parseForm(input, record);
command = update_command.add;
return record;
} else if (Method.PUT.equals(method)) {
command = null;
IStructureRecord record = new StructureRecord();
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);
}
Aggregations