use of ambit2.base.relation.composition.CompositionRelation in project ambit-mirror by ideaconsult.
the class SubstanceCompositionResource method createQuery.
@Override
protected Q createQuery(Context context, Request request, Response response) throws ResourceException {
Form form = getRequest().getResourceRef().getQueryAsForm();
// i.e. hide hidden compositions , see 8.14 db schema
boolean showall = false;
try {
showall = Boolean.parseBoolean(form.getFirstValue("all"));
} catch (Exception x) {
showall = false;
}
Object key = request.getAttributes().get(SubstanceResource.idsubstance);
Object cmp = request.getAttributes().get(idcomposition);
if (key == null) {
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST);
} else {
CompositionRelation relation = null;
try {
if (cmp != null) {
STRUCTURE_RELATION srelation = STRUCTURE_RELATION.valueOf(cmp.toString());
relation = new CompositionRelation(null, null, srelation, null);
}
} catch (Exception x) {
}
ReadSubstanceComposition q = null;
try {
q = new ReadSubstanceComposition();
q.setExcludeHidden(!showall);
q.setFieldname(new SubstanceRecord(Integer.parseInt(key.toString())));
q.setValue(relation);
return (Q) q;
} catch (Exception x) {
int len = key.toString().trim().length();
if ((len > 40) && (len <= 45)) {
SubstanceRecord record = new SubstanceRecord();
record.setSubstanceUUID(key.toString());
q = new ReadSubstanceComposition();
q.setExcludeHidden(!showall);
q.setFieldname(record);
q.setValue(relation);
return (Q) q;
}
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST);
}
}
}
use of ambit2.base.relation.composition.CompositionRelation in project ambit-mirror by ideaconsult.
the class BucketDenormalised method composition2Buckets.
// TODO
protected Bucket composition2Buckets(SubstanceRecord record, CompositionRelation component, boolean suffix) {
Bucket bcomposition = new Bucket<>();
bcomposition.setHeaders(study_headers_combined);
bcomposition.put("type_s", "composition");
String ctype = component.getRelationType().name().replace("HAS_", "");
bcomposition.put(header_component, ctype);
bcomposition.put("COMPOSITION", component.getName());
if (component.getSecondStructure().getSmiles() != null)
bcomposition.put("SMILES_s", component.getSecondStructure().getSmiles());
if (component.getSecondStructure().getInchi() != null)
bcomposition.put("InChI_s", component.getSecondStructure().getInchi());
if (component.getSecondStructure().getInchiKey() != null)
bcomposition.put("InChIKey_s", component.getSecondStructure().getInchiKey());
for (Property p : component.getSecondStructure().getRecordProperties()) {
if (p.getLabel().indexOf("UUID") >= 0)
continue;
String label = String.format("%s_s", p.getLabel().replace("http://www.opentox.org/api/1.1#", ""));
String val = component.getSecondStructure().getRecordProperty(p).toString().trim();
if ("".equals(val))
continue;
bcomposition.put(label, val);
}
return bcomposition;
}
use of ambit2.base.relation.composition.CompositionRelation in project ambit-mirror by ideaconsult.
the class SubstanceRecord method addStructureRelation.
public IStructureRelation addStructureRelation(String compositionUUID, IStructureRecord record, STRUCTURE_RELATION relation, Proportion value) {
if (relatedStructures == null)
relatedStructures = new ArrayList<CompositionRelation>();
CompositionRelation r = new CompositionRelation(this, record, value);
r.setCompositionUUID(compositionUUID);
r.setRelationType(relation);
relatedStructures.add(r);
return r;
}
use of ambit2.base.relation.composition.CompositionRelation in project ambit-mirror by ideaconsult.
the class DBSubstanceWriter method importSubstanceRecord.
protected void importSubstanceRecord(SubstanceRecord substance) throws Exception {
try {
q.setObject(substance);
x.process(q);
} catch (Exception x) {
logger.log(Level.WARNING, q.getClass().getName(), x);
throw x;
}
try {
qids.setObject(substance);
x.process(qids);
} catch (Exception x) {
logger.log(Level.WARNING, qids.getClass().getName(), x);
}
importedRecord.setSubstanceUUID(substance.getSubstanceUUID());
importedRecord.setIdsubstance(substance.getIdsubstance());
String prefix = substance.getSubstanceUUID().substring(0, 4);
if (clearComposition)
try {
deleteComposition.setGroup(importedRecord);
x.process(deleteComposition);
} catch (Exception x) {
logger.log(Level.WARNING, x.getMessage());
}
if (substance.getRelatedStructures() != null) {
for (CompositionRelation rel : substance.getRelatedStructures()) {
// TODO !!!!!!!!!!!!!!
Object i5uuid = rel.getSecondStructure().getRecordProperty(Property.getI5UUIDInstance());
if (rel.getSecondStructure().getIdchemical() <= 0) {
if (i5mode) {
IStructureKey match = writer.getPropertyKey();
writer.setPropertyKey(componentsMatch);
writer.create(rel.getSecondStructure());
writer.setPropertyKey(match);
} else {
IStructureKey match = writer.getPropertyKey();
writer.setPropertyKey(match);
writer.create(rel.getSecondStructure());
writer.setPropertyKey(match);
}
}
rel.getSecondStructure().setRecordProperty(Property.getI5UUIDInstance(), i5uuid);
qr.setCompositionRelation(rel);
x.process(qr);
}
}
if (clearMeasurements)
try {
deleteStudy.setGroup(substance.getSubstanceUUID());
x.process(deleteStudy);
} catch (Exception x) {
logger.log(Level.WARNING, x.getMessage());
}
if (importBundles)
importBundles(substance);
}
use of ambit2.base.relation.composition.CompositionRelation in project ambit-mirror by ideaconsult.
the class ReadSubstanceComposition method readCompositionRelation.
public static CompositionRelation readCompositionRelation(CompositionRelation record, ResultSet rs, SubstanceEndpointsBundle bundle) throws AmbitException {
if (record == null)
record = new CompositionRelation(new SubstanceRecord(), new StructureRecord(), new Proportion());
else
record.clear();
try {
try {
String uuid = I5Utils.getPrefixedUUID(rs.getString("cmp_prefix"), rs.getString("cmp_huuid"));
record.setCompositionUUID(uuid);
} catch (Exception xx) {
record.setCompositionUUID(null);
}
record.setName(rs.getString("compositionname"));
try {
record.setHidden(rs.getBoolean("hidden"));
} catch (Exception x) {
record.setHidden(false);
}
record.getFirstStructure().setIdsubstance(rs.getInt("idsubstance"));
record.getSecondStructure().setIdchemical(rs.getInt("idchemical"));
try {
record.getSecondStructure().setInchi(rs.getString("inchi"));
record.getSecondStructure().setSmiles(rs.getString("smiles"));
record.getSecondStructure().setInchiKey(rs.getString("inchikey"));
record.getSecondStructure().setFormula(rs.getString("formula"));
} catch (Exception x) {
x.printStackTrace();
}
record.setRelationType(STRUCTURE_RELATION.valueOf(rs.getString("relation")));
record.getRelation().setFunction(rs.getString("function"));
record.getRelation().setTypical(rs.getString("proportion_typical"));
record.getRelation().setTypical_unit(rs.getString("proportion_typical_unit"));
record.getRelation().setTypical_value(rs.getDouble("proportion_typical_value"));
record.getRelation().setReal_lower(rs.getString("proportion_real_lower"));
record.getRelation().setReal_upper(rs.getString("proportion_real_upper"));
record.getRelation().setReal_unit(rs.getString("proportion_real_unit"));
record.getRelation().setReal_lowervalue(rs.getDouble("proportion_real_lower_value"));
record.getRelation().setReal_uppervalue(rs.getDouble("proportion_real_upper_value"));
try {
record.getSecondStructure().clearFacets();
if (bundle != null && bundle.getID() > 0) {
BundleRoleFacet facet = new BundleRoleFacet(null);
facet.setCount(1);
facet.setTag(rs.getString("tag"));
facet.setRemarks(rs.getString("remarks"));
facet.setValue(bundle);
record.getSecondStructure().addFacet(facet);
}
} catch (Exception x) {
}
try {
String uuid = I5Utils.getPrefixedUUID(rs.getString("refstruc"), rs.getString("refstrucuuid"));
record.setRecordProperty(Property.getI5UUIDInstance(), uuid);
} catch (Exception xx) {
record.removeRecordProperty(Property.getI5UUIDInstance());
}
} catch (Exception x) {
x.printStackTrace();
}
return record;
}
Aggregations