use of ambit2.base.data.substance.ExternalIdentifier 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.substance.ExternalIdentifier in project ambit-mirror by ideaconsult.
the class SubstanceCSVReporter method processItem.
@Override
public Object processItem(SubstanceRecord item) throws AmbitException {
try {
Writer writer = getOutput();
if (item.getSubstanceName() != null)
writer.write(JSONUtils.jsonQuote(item.getSubstanceName()));
writer.write(comma);
writer.write(item.getSubstanceUUID());
writer.write(comma);
writer.write(JSONUtils.jsonQuote(item.getSubstancetype()));
writer.write(comma);
if (item.getPublicName() != null)
writer.write(JSONUtils.jsonQuote(item.getPublicName()));
writer.write(comma);
if (item.getReferenceSubstanceUUID() != null)
writer.write(JSONUtils.jsonQuote(item.getReferenceSubstanceUUID()));
writer.write(comma);
writer.write(JSONUtils.jsonQuote(item.getOwnerName()));
writer.write(comma);
if (item.getOwnerUUID() != null)
writer.write(item.getOwnerUUID());
writer.write(comma);
if (item.getExternalids() != null) {
for (ExternalIdentifier id : item.getExternalids()) {
writer.write(id.getSystemDesignator());
writer.write(":");
writer.write(id.getSystemIdentifier());
writer.write(" ");
}
} else
writer.write(" ");
writer.write("\n");
} catch (Exception x) {
logger.log(java.util.logging.Level.SEVERE, x.getMessage(), x);
}
return item;
}
use of ambit2.base.data.substance.ExternalIdentifier in project ambit-mirror by ideaconsult.
the class BucketDenormalised method substance2Bucket.
protected void substance2Bucket(SubstanceRecord record, Bucket bucket, boolean hasSuffix, String suffix) {
if (record == null)
return;
bucket.put(ns("name", hasSuffix, suffix), record.getSubstanceName());
bucket.put(ns("publicname", hasSuffix, suffix), record.getPublicName());
if (!"".equals(record.getOwnerName()))
bucket.put(ns("owner_name", hasSuffix, suffix), record.getOwnerName());
bucket.put(ns("s_uuid", hasSuffix, suffix), record.getSubstanceUUID());
bucket.put(ns("substanceType", hasSuffix, suffix), record.getSubstancetype());
bucket.put("type_s", "substance");
bucket.put("id", record.getSubstanceUUID());
if (record.getExternalids() != null) {
for (ExternalIdentifier id : record.getExternalids()) if ("NM code".equals(id.getSystemDesignator())) {
bucket.put(ns("nmcode", hasSuffix, suffix), id.getSystemIdentifier());
}
}
String[] terms_substance = annotator.annotateSubstance(record);
if (terms_substance != null) {
String key = ns("substance_annotation", hasSuffix, suffix + "s");
bucket.put(key, Arrays.asList(terms_substance));
}
// bucket.put(ns("content", hasSuffix, suffix), record.getContent());
}
use of ambit2.base.data.substance.ExternalIdentifier in project ambit-mirror by ideaconsult.
the class SubstanceStudyParser method parseSubstance.
public SubstanceRecord parseSubstance(JsonNode node) {
if (node == null)
return null;
SubstanceRecord record = new SubstanceRecord();
record.setSubstanceName(node.get(SubstanceRecord.jsonSubstance.name.name()).textValue());
record.setSubstanceUUID(node.get(SubstanceRecord.jsonSubstance.i5uuid.name()).textValue());
record.setOwnerName(node.get(SubstanceRecord.jsonSubstance.ownerName.name()).textValue());
record.setOwnerUUID(node.get(SubstanceRecord.jsonSubstance.ownerUUID.name()).textValue());
record.setPublicName(node.get(SubstanceRecord.jsonSubstance.publicname.name()).textValue());
record.setSubstancetype(node.get(SubstanceRecord.jsonSubstance.substanceType.name()).textValue());
record.setFormat(node.get(SubstanceRecord.jsonSubstance.format.name()).textValue());
JsonNode subnode = node.get(SubstanceRecord.jsonSubstance.externalIdentifiers.name());
if (subnode instanceof ArrayNode) {
ArrayNode ids = (ArrayNode) subnode;
List<ExternalIdentifier> extids = new ArrayList<ExternalIdentifier>();
record.setExternalids(extids);
for (int i = 0; i < ids.size(); i++) {
if (ids.get(i) instanceof ObjectNode) {
extids.add(new ExternalIdentifier(((ObjectNode) ids.get(i)).get("type").textValue(), ((ObjectNode) ids.get(i)).get("id").textValue()));
}
}
}
subnode = node.get(SubstanceRecord.jsonSubstance.referenceSubstance.name());
if (subnode != null) {
record.setReferenceSubstanceUUID(subnode.get(SubstanceRecord.jsonSubstance.i5uuid.name()).textValue());
}
return record;
}
use of ambit2.base.data.substance.ExternalIdentifier in project ambit-mirror by ideaconsult.
the class BucketDenormalised method externalids2Bucket.
protected void externalids2Bucket(ExternalIdentifier id, Bucket bucket, String key, String prefix) {
TreeSet<String> keys = new TreeSet<String>();
IParams ids = (IParams) bucket.get(key);
if (ids == null) {
ids = new Params();
bucket.put(key, ids);
keys.add(key);
}
ids.put(id.getSystemDesignator(), id.getSystemIdentifier());
}
Aggregations