use of ambit2.core.io.RawIteratingMOLReader in project ambit-mirror by ideaconsult.
the class RawIteratingFolderReader method getItemReader.
protected IRawReader<IStructureRecord> getItemReader(int index) throws Exception {
String name = files[index].getName().toLowerCase();
if (name.endsWith(FileInputState._FILE_TYPE.SDF_INDEX.getExtension())) {
RawIteratingSDFReader r = new RawIteratingSDFReader(new FileReader(files[index]));
r.setReference(LiteratureEntry.getInstance(files[index].getName(), "file:///" + files[index].getAbsolutePath()));
return (IRawReader<IStructureRecord>) r;
} else if (name.endsWith(FileInputState._FILE_TYPE.MOL_INDEX.getExtension())) {
RawIteratingMOLReader r = new RawIteratingMOLReader(new FileReader(files[index]));
r.setReference(LiteratureEntry.getInstance(files[index].getName(), "file:///" + files[index].getAbsolutePath()));
return (IRawReader<IStructureRecord>) r;
} else if (name.endsWith(FileInputState._FILE_TYPE.I5D_INDEX.getExtension())) {
IIteratingChemObjectReader r = FileInputState.getI5DReader(files[index]);
if (r instanceof ICiteable) {
((ICiteable) r).setReference(LiteratureEntry.getI5UUIDReference());
}
return (IRawReader<IStructureRecord>) r;
} else if (name.endsWith(FileInputState._FILE_TYPE.ZIP_INDEX.getExtension())) {
return new ZipReader(files[index]);
} else if (name.endsWith(FileInputState._FILE_TYPE.GZ_INDEX.getExtension())) {
// assuming gzipped sdf only...
InputStreamReader reader = new InputStreamReader(new GZIPInputStream(new FileInputStream(files[index])));
return new RawIteratingSDFReader(reader);
} else
throw new Exception("Unsupported format " + name);
}
use of ambit2.core.io.RawIteratingMOLReader in project ambit-mirror by ideaconsult.
the class BatchDBProcessor method getIterator.
public Iterator<ITEMTYPE> getIterator(IInputState target) throws AmbitException {
if (target instanceof FileInputState)
try {
File _file = ((FileInputState) target).getFile();
if (_file.isDirectory()) {
FilenameFilter filter = new FilenameFilter() {
public boolean accept(File dir, String name) {
return !name.startsWith(".");
}
};
return new RawIteratingFolderReader(_file.listFiles(filter));
} else {
InputStream stream = null;
String filename = _file.getName();
if (filename.endsWith(_FILE_TYPE.GZ_INDEX.getExtension())) {
String uncompressed = filename.replaceAll(_FILE_TYPE.GZ_INDEX.getExtension(), "");
try {
stream = new GZIPInputStream(new FileInputStream(_file));
filename = uncompressed;
} catch (IOException x) {
throw new AmbitIOException(x);
}
} else
stream = new FileInputStream(_file);
if (FileInputState._FILE_TYPE.SDF_INDEX.hasExtension(filename)) {
RawIteratingSDFReader reader = new RawIteratingSDFReader(new InputStreamReader(stream));
if (getReference() == null)
reader.setReference(LiteratureEntry.getInstance(filename, _file.getAbsolutePath()));
else
reader.setReference(getReference());
return reader;
} else if (FileInputState._FILE_TYPE.MOL_INDEX.hasExtension(filename)) {
RawIteratingMOLReader reader = new RawIteratingMOLReader(new InputStreamReader(stream));
if (getReference() == null)
reader.setReference(LiteratureEntry.getInstance(filename, _file.getAbsolutePath()));
else
reader.setReference(getReference());
return reader;
/* TEST and replace the wrapper with this */
} else if (FileInputState._FILE_TYPE.CSV_INDEX.hasExtension(filename)) {
RawIteratingCSVReader reader = new RawIteratingCSVReader(new InputStreamReader(stream), CSVFormat.EXCEL);
configureReader(reader, target, _file);
return reader;
} else if (FileInputState._FILE_TYPE.TXT_INDEX.hasExtension(filename)) {
RawIteratingCSVReader reader = new RawIteratingCSVReader(new InputStreamReader(stream), CSVFormat.TDF.withCommentMarker('#'));
configureReader(reader, target, _file);
return reader;
} else {
IIteratingChemObjectReader ir = FileInputState.getReader(stream, filename);
if (ir == null)
throw new AmbitException("Unsupported format " + filename);
else {
if (ir instanceof RawIteratingCSVReader) {
configureReader(((RawIteratingCSVReader) ir), target, _file);
}
RawIteratingWrapper reader = new RawIteratingWrapper(ir);
if (getReference() == null)
reader.setReference(LiteratureEntry.getInstance(filename, _file.getAbsolutePath()));
else
reader.setReference(getReference());
return reader;
}
}
}
} catch (IOException x) {
throw new AmbitIOException(x);
} catch (Exception x) {
throw new AmbitException(x);
}
else
throw new AmbitException("Not a file");
}
Aggregations