Skip to content

Commit

Permalink
Fix bug where FASTQ inflation caused crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Aiezza authored and Alex Aiezza committed May 3, 2016
1 parent b405289 commit 5b984ac
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/edu/rit/flick/genetics/FastFileDeflator.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public File deflate( final Configuration configuration, final File fileIn, final
} catch ( final Exception e )
{
if ( !interrupted )
e.printStackTrace();
System.err.println( e.getMessage() );
}
}, "Default_Deflation_Thread" );

Expand Down
42 changes: 32 additions & 10 deletions src/edu/rit/flick/genetics/FastFileInflator.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/
package edu.rit.flick.genetics;

import static edu.rit.flick.config.DefaultOptionSet.VERBOSE_FLAG;
import static edu.rit.flick.config.DefaultOptionSet.DELETE_FLAG;
import static edu.rit.flick.config.DefaultOptionSet.VERBOSE_FLAG;
import static org.apache.commons.io.FileUtils.getFile;

import java.io.File;
Expand Down Expand Up @@ -107,6 +107,9 @@ protected void beforeSequence() throws IOException

protected void close() throws IOException, InterruptedException
{
if ( fastOut == null )
return;

fastOut.close();
iupacfile.close();
datahcf.close();
Expand Down Expand Up @@ -227,7 +230,10 @@ protected Properties getProperties( final File propertiesFile ) throws IOExcepti
}

@Override
public File inflate( final Configuration configuration, final File fileIn, final File fileOut )
public synchronized File inflate(
final Configuration configuration,
final File fileIn,
final File fileOut )
{
assert fileIn.exists();

Expand Down Expand Up @@ -264,7 +270,7 @@ public File inflate( final Configuration configuration, final File fileIn, final
} catch ( final Exception e )
{
if ( !interrupted )
e.printStackTrace();
System.err.println( e.getMessage() );
}
}, "Default_Inflation_Thread" );

Expand All @@ -275,19 +281,32 @@ public File inflate( final Configuration configuration, final File fileIn, final
configuration.setFlag( DELETE_FLAG, false );
try
{
if ( inflateToDirectoryThread.isAlive() )
inflateToDirectoryThread.interrupt();

// Clean up IO
close();
System.gc();
Thread.sleep( 100 );

// Clean up temporary directory
FileUtils.deleteDirectory( tmpOutputDirectory );
// Clean up INCOMPLETE output file
FileUtils.deleteQuietly( fileOut );
synchronized ( this )
{
while ( inflateToDirectoryThread.isAlive() )
this.wait();
}

} catch ( final IOException | InterruptedException e )
{
e.printStackTrace();
} finally
{
// Clean up temporary directory
FileUtils.deleteQuietly( tmpOutputDirectory );
// Clean up INCOMPLETE output file
FileUtils.deleteQuietly( fileOut );
System.out.println();
}

}, "Inflation_Cleaning_Thread" );

cleanHookAtomic.set( cleanHook );
Expand Down Expand Up @@ -342,7 +361,8 @@ protected File inflateFromFile( final File fileIn, final File tmpOutputDirectory
zipFile.extractAll( tmpOutputDirectory.getPath() );
} catch ( final ZipException e )
{
e.printStackTrace();
if ( !interrupted )
System.err.println( e.getMessage() );
}

return tmpOutputDirectory;
Expand Down Expand Up @@ -423,7 +443,8 @@ protected final void writeNextHeader()
seqDnaPosition.set( 0 );
} catch ( final IOException e )
{
e.printStackTrace();
if ( !interrupted )
e.printStackTrace();
}
}

Expand Down Expand Up @@ -454,7 +475,8 @@ protected void writeNucleotide( final byte base )
fastOut.write( nucleotide );
} catch ( final IOException e )
{
e.printStackTrace();
if ( !interrupted )
System.err.println( e.getMessage() );
}
dnaPosition.increment();
}
Expand Down
3 changes: 2 additions & 1 deletion src/edu/rit/flick/genetics/FastaFileInflator.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ protected void afterWriteNucleotide()
protected void close() throws IOException, InterruptedException
{
super.close();
tandemFile.close();
if ( tandemFile != null )
tandemFile.close();
}

@SuppressWarnings ( "resource" )
Expand Down
9 changes: 6 additions & 3 deletions src/edu/rit/flick/genetics/FastqFileInflator.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ protected void beforeSequence() throws IOException
@Override
protected void close() throws IOException, InterruptedException
{
lengthfile.close();
commentsfile.close();
scorefile.close();
if ( lengthfile != null )
lengthfile.close();
if ( commentsfile != null )
commentsfile.close();
if ( scorefile != null )
scorefile.close();

scorefile = null;

Expand Down

0 comments on commit 5b984ac

Please sign in to comment.