use of ambit2.db.readers.RetrieveStructure in project ambit-mirror by ideaconsult.
the class ARFFIterator method getIterator.
@Override
public Iterator<IStructureRecord> getIterator(File[] target) throws AmbitException {
try {
input = new BufferedReader(new FileReader(target[0]));
results = new BufferedReader(new FileReader(target[1]));
arffInput = new ArffReader(input, 1);
arffResults = new ArffReader(results, 1);
dataInput = arffInput.getStructure();
dataResults = arffResults.getStructure();
properties = new Property[dataResults.numAttributes()];
for (int i = 0; i < dataResults.numAttributes(); i++) {
Attribute attribute = dataResults.attribute(i);
RDFPropertyIterator reader = null;
Property p = null;
try {
reader = new RDFPropertyIterator(new Reference(attribute.name()), "arff");
reader.setBaseReference(baseReference);
while (reader.hasNext()) {
p = reader.next();
}
} catch (Exception x) {
p = null;
// p.setId((Integer)OpenTox.URI.feature.getId(attribute.name(), baseReference));
} finally {
try {
reader.close();
} catch (Exception x) {
}
}
properties[i] = p;
}
return new Iterator<IStructureRecord>() {
public boolean hasNext() {
try {
inputInstance = arffInput.readInstance(dataInput);
resultInstance = arffResults.readInstance(dataResults);
return (inputInstance != null) && (resultInstance != null);
} catch (Exception x) {
return false;
}
}
public IStructureRecord next() {
record.clear();
Object[] ids = OpenTox.URI.conformer.getIds(inputInstance.toString(0), baseReference);
if ((ids != null) && (ids[0] != null) && (ids[1] != null)) {
record.setIdchemical((Integer) ids[0]);
record.setIdstructure((Integer) ids[1]);
} else {
Object id = OpenTox.URI.compound.getId(inputInstance.toString(0), baseReference);
if (id != null) {
record.setIdchemical((Integer) id);
record.setIdstructure(-1);
} else {
// retrieveStructure(uris[index]);
}
}
for (int i = 0; i < properties.length; i++) if (properties[i] != null) {
if (dataResults.attribute(i).isNumeric())
record.setRecordProperty(properties[i], resultInstance.value(i));
else
record.setRecordProperty(properties[i], resultInstance.toString(i));
}
return record;
}
public void remove() {
}
};
} catch (FileNotFoundException x) {
throw new AmbitException(x);
} catch (Exception x) {
throw new AmbitException(x);
}
}
use of ambit2.db.readers.RetrieveStructure in project ambit-mirror by ideaconsult.
the class InChIChemicalsTableWriterTest method testProcess.
@Test
public void testProcess() throws Exception {
StructureNormalizer normalizer = new StructureNormalizer();
// no inchis as well
setUpDatabaseFromResource("ambit2/db/processors/test/dataset_nofp.xml");
IDatabaseConnection dbConnection = getConnection();
ITable chemicals = dbConnection.createQueryTable("EXPECTED_FP", "SELECT * FROM chemicals where inchi is null");
Assert.assertEquals(5, chemicals.getRowCount());
RepositoryReader reader = new RepositoryReader();
RetrieveStructure molReader = new RetrieveStructure(true);
reader.setConnection(dbConnection.getConnection());
InChIChemicalsWriter inchiWriter = new InChIChemicalsWriter();
inchiWriter.setConnection(dbConnection.getConnection());
inchiWriter.open();
reader.open();
int records = 0;
IStructureRecord o;
QueryExecutor<RetrieveStructure> exec = new QueryExecutor<RetrieveStructure>();
exec.setConnection(dbConnection.getConnection());
int errors = 0;
while (reader.hasNext()) {
o = reader.next();
String content = reader.getStructure(o.getIdstructure());
if (content == null)
continue;
molReader.setValue(o);
ResultSet rs = exec.process(molReader);
while (rs.next()) {
IStructureRecord record = molReader.getObject(rs);
try {
record = normalizer.process(record);
inchiWriter.process(record);
} catch (Exception x) {
errors++;
}
}
rs.close();
o.clear();
records++;
}
reader.close();
chemicals = dbConnection.createQueryTable("EXPECTED_FP", "SELECT count(*) as c FROM chemicals where inchi is not null");
Assert.assertEquals(new BigInteger("4"), chemicals.getValue(0, "c"));
inchiWriter.close();
}
use of ambit2.db.readers.RetrieveStructure in project ambit-mirror by ideaconsult.
the class Structure_crud_test method createVerify.
@Override
protected void createVerify(IQueryUpdate<Object, IStructureRecord> query) throws Exception {
IDatabaseConnection c = getConnection();
QueryStructure q = new QueryStructure();
q.setFieldname(ExactStructureSearchMode.idchemical);
q.setValue("10");
RetrieveStructure r = new RetrieveStructure();
// structure
r.setFieldname(false);
QueryExecutor execR = new QueryExecutor();
execR.setConnection(c.getConnection());
QueryExecutor exec = new QueryExecutor();
exec.setConnection(c.getConnection());
ResultSet rs = exec.process(q);
int count = 0;
while (rs.next()) {
IStructureRecord record = q.getObject(rs);
r.setValue(record);
ResultSet rs1 = execR.process(r);
while (rs1.next()) {
record = r.getObject(rs1);
if ("content".equals(record.getContent()))
count++;
}
execR.closeResults(rs1);
}
exec.closeResults(rs);
Assert.assertEquals(1, count);
c.close();
}
use of ambit2.db.readers.RetrieveStructure in project ambit-mirror by ideaconsult.
the class Structure_crud_test method createVerifyNew.
@Override
protected void createVerifyNew(IQueryUpdate<Object, IStructureRecord> query) throws Exception {
IDatabaseConnection c = getConnection();
ITable table = c.createQueryTable("EXPECTED", "SELECT idstructure,idchemical,type_structure FROM structure");
Assert.assertTrue(table.getRowCount() > 0);
RetrieveStructure r = new RetrieveStructure();
r.setPreferedStructure(false);
r.setFieldname(false);
QueryExecutor execR = new QueryExecutor();
execR.setConnection(c.getConnection());
int count = 0;
for (int i = 0; i < table.getRowCount(); i++) {
IStructureRecord record = new StructureRecord();
record.setIdstructure(Integer.parseInt(table.getValue(i, "idstructure").toString()));
try {
Object t = table.getValue(i, "type_structure");
for (STRUC_TYPE type : STRUC_TYPE.values()) if (type.toString().equals(t)) {
record.setType(type);
break;
}
} catch (Exception x) {
record.setType(STRUC_TYPE.NA);
}
r.setValue(record);
ResultSet rs1 = execR.process(r);
while (rs1.next()) {
record = r.getObject(rs1);
if ("content".equals(record.getContent()))
count++;
}
execR.closeResults(rs1);
}
Assert.assertEquals(1, count);
c.close();
}
use of ambit2.db.readers.RetrieveStructure in project ambit-mirror by ideaconsult.
the class StructureRecordXLSXReporter method configureProcessors.
@Override
protected void configureProcessors(String baseRef, boolean includeMol) {
if (includeMol) {
RetrieveStructure r = new RetrieveStructure();
r.setPage(0);
r.setPageSize(1);
getProcessors().add(new ProcessorStructureRetrieval(r));
}
configurePropertyProcessors();
getProcessors().add(new ProcessorStructureRetrieval(new QuerySmilesByID()));
// configureCollectionProcessors(baseRef);
getProcessors().add(new DefaultAmbitProcessor<IStructureRecord, IStructureRecord>() {
private static final long serialVersionUID = -7316415661186235101L;
@Override
public IStructureRecord process(IStructureRecord target) throws Exception {
processItem(target);
return target;
}
});
}
Aggregations