Skip to content

Commit

Permalink
update monitor when iterating SMILES file
Browse files Browse the repository at this point in the history
  • Loading branch information
jonalv committed Jun 19, 2012
1 parent d824e08 commit a8b99e5
Showing 1 changed file with 41 additions and 3 deletions.
Expand Up @@ -1113,7 +1113,7 @@ private boolean isSMILESFile( IFile file ) {

if (isSMILESFile(file)) {
return new IteratingBioclipseSMILESReader(
file.getContents(),
file,
SilentChemObjectBuilder.getInstance(),
monitor );
}
Expand All @@ -1138,17 +1138,43 @@ public class IteratingBioclipseSMILESReader
BufferedReader reader;
String separator;
String[] headers;
private int lines;
private int readLines;
private long before = System.currentTimeMillis();

public IteratingBioclipseSMILESReader( InputStream contents,
public IteratingBioclipseSMILESReader( IFile file,
IChemObjectBuilder instance,
IProgressMonitor monitor) {

this.contents = contents;
this.moleculeBuilder = instance;
this.monitor = monitor;
try {
contents = file.getContents();
} catch ( CoreException e1 ) {
e1.printStackTrace();
}
this.reader = new BufferedReader(
new InputStreamReader(
new BufferedInputStream(contents) ) );
lines = 0;
try {
while (reader.readLine() != null) {
lines++;
}

} catch ( IOException e ) {
throw new RuntimeException(e);
}

try {
contents = file.getContents();
} catch ( CoreException e1 ) {
e1.printStackTrace();
}
this.reader = new BufferedReader(
new InputStreamReader(
new BufferedInputStream(contents) ) );

String firstLine = null;
try {
firstLine = reader.readLine();
Expand Down Expand Up @@ -1214,6 +1240,18 @@ private ICDKMolecule getNext() {
catch ( IOException e ) {
LogUtils.debugTrace( logger, e );
}
++readLines;
if ( lines > 10 && readLines % 10 == 0) {
monitor.subTask(
"Read molecule: " + readLines + "/" + lines
+ " (" + TimeCalculator.generateTimeRemainEst(
before, readLines, lines ) + ")" );
synchronized ( monitor ) {
if ( monitor.isCanceled() ) {
throw new OperationCanceledException();
}
}
}
return mol;
}

Expand Down

0 comments on commit a8b99e5

Please sign in to comment.