diff --git a/.classpath b/.classpath index 1bfe994..da54680 100644 --- a/.classpath +++ b/.classpath @@ -1,14 +1,14 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/build.gradle b/build.gradle index c8bc4ae..b932a8f 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'java' apply plugin: 'eclipse' group = 'rit' -version = 0.3 +version = 0.4 jar.baseName = 'flick' // def uploadSite = 'ftp.bioinformatics.rit.edu' @@ -83,6 +83,7 @@ dependencies { compile 'com.google.guava:guava:18.0' compile 'net.lingala.zip4j:zip4j:1.3.2' compile 'it.unimi.dsi:dsiutils:2.2.4' + compile 'org.springframework:spring-context:4.2.5.RELEASE' testCompile 'junit:junit:4.+' testCompile 'junit-addons:junit-addons:1.+' diff --git a/src/edu/rit/flick/AbstractFlickFile.java b/src/edu/rit/flick/AbstractFlickFile.java index 8a66ecc..f4bee7b 100644 --- a/src/edu/rit/flick/AbstractFlickFile.java +++ b/src/edu/rit/flick/AbstractFlickFile.java @@ -20,6 +20,7 @@ import com.google.common.io.Files; import edu.rit.flick.config.Configuration; +import edu.rit.flick.config.FileArchiverExtensionRegistry; import net.lingala.zip4j.core.ZipFile; import net.lingala.zip4j.exception.ZipException; import net.lingala.zip4j.model.ZipParameters; @@ -31,19 +32,22 @@ */ public abstract class AbstractFlickFile implements FlickFile { - public static final String FILE_NOT_FOUND_EXCEPTION_MESSAGE = "file not found"; + public static final String FILE_NOT_FOUND_EXCEPTION_MESSAGE = "file not found"; - private static final String FILE_ALREADY_EXISTS_AS_DIRECTORY_EXCEPTION = "already exists as directory"; + private static final String FILE_ALREADY_EXISTS_AS_DIRECTORY_EXCEPTION = "already exists as directory"; - private static final String CANT_OVERWRITE_EXISTING_FILE_WITHOT_FORCE_FLAG = "\n can't overwrite existing file without --force flag"; + private static final String CANT_OVERWRITE_EXISTING_FILE_WITHOT_FORCE_FLAG = "\n can't overwrite existing file without --force flag"; - protected final File fileIn, fileOut; + protected final File fileIn, fileOut; - protected final Configuration configuration; + protected final Configuration configuration; - protected final ZipFile flickFile; + protected final ZipFile flickFile; - protected final ZipParameters zParams; + protected final ZipParameters zParams; + + protected final FileArchiverExtensionRegistry REGISTRY = FileArchiverExtensionRegistry + .getInstance(); public AbstractFlickFile( final Configuration configuration ) throws ZipException, @@ -52,8 +56,6 @@ public AbstractFlickFile( final Configuration configuration ) { this.configuration = configuration; - init(); - final String inputPath = (String) configuration.getOption( INPUT_PATH ); final Object outputPath = configuration.getOption( OUTPUT_PATH ); @@ -120,7 +122,4 @@ public String getFileOutPath() { return fileOut.getPath(); } - - protected void init() - {} } diff --git a/src/edu/rit/flick/DefaultFlickFile.java b/src/edu/rit/flick/DefaultFlickFile.java index f2e4aaa..1432108 100644 --- a/src/edu/rit/flick/DefaultFlickFile.java +++ b/src/edu/rit/flick/DefaultFlickFile.java @@ -24,17 +24,12 @@ import java.util.List; import java.util.concurrent.atomic.LongAdder; import java.util.stream.Collectors; -import java.util.stream.Stream; import org.apache.commons.io.FileUtils; import com.google.common.io.Files; import edu.rit.flick.config.Configuration; -import edu.rit.flick.genetics.FastaFileDeflator; -import edu.rit.flick.genetics.FastaFileInflator; -import edu.rit.flick.genetics.FastqFileDeflator; -import edu.rit.flick.genetics.FastqFileInflator; import net.lingala.zip4j.core.HeaderReader; import net.lingala.zip4j.exception.ZipException; import net.lingala.zip4j.model.CentralDirectory; @@ -60,10 +55,6 @@ public class DefaultFlickFile extends AbstractFlickFile private static final String FILE_COULD_NOT_BE_DELETED_WARNING_FORMAT = "File '%s' could not be deleted.%n"; - private List fileDeflators; - - private List fileInflators; - /** * @param configuration * @throws ZipException @@ -78,31 +69,6 @@ public DefaultFlickFile( final Configuration configuration ) super( configuration ); } - @Override - protected void init() - { - fileDeflators = new ArrayList(); - fileInflators = new ArrayList(); - - if ( configuration.getFlag( ARCHIVE_MODE ) == DEFLATION_ARCHIVE_MODE ) - addDefaultFileDeflators(); - else if ( configuration.getFlag( ARCHIVE_MODE ) == INFLATION_ARCHIVE_MODE ) - addDefaultFileInflators(); - } - - - private final void addDefaultFileDeflators() - { - registerFileDeflator( new FastaFileDeflator() ); - registerFileDeflator( new FastqFileDeflator() ); - } - - private final void addDefaultFileInflators() - { - registerFileInflator( new FastaFileInflator() ); - registerFileInflator( new FastqFileInflator() ); - } - private File archiveFile( final File file, final boolean onlyFile ) { double time = 0; @@ -112,32 +78,33 @@ private File archiveFile( final File file, final boolean onlyFile ) { final String fileExt = "." + Files.getFileExtension( file.getPath() ); - if ( getExtensions().contains( fileExt ) ) - if ( configuration.getFlag( ARCHIVE_MODE ) == DEFLATION_ARCHIVE_MODE && - !configuration.getFlag( NO_ZIP_FLAG ) ) + if ( configuration.getFlag( ARCHIVE_MODE ) == DEFLATION_ARCHIVE_MODE && + !configuration.getFlag( NO_ZIP_FLAG ) ) + { + final FileDeflator fileDeflator = REGISTRY.getFileDeflator( fileExt ); + if ( fileDeflator != null ) { - for ( final FileDeflator deflator : fileDeflators ) - if ( deflator.getExtensions().contains( fileExt ) ) - { - final long t1 = System.currentTimeMillis(); - if ( onlyFile && configuration.getOption( OUTPUT_PATH ) != null ) - archivedFile = deflator.deflate( configuration, file, - new File( (String) configuration.getOption( OUTPUT_PATH ) ) ); - else archivedFile = deflator.deflate( configuration, file ); - time = ( System.currentTimeMillis() - t1 ) / 1000d; - } - } else if ( configuration.getFlag( ARCHIVE_MODE ) == INFLATION_ARCHIVE_MODE && - !configuration.getFlag( KEEP_ZIPPED_FLAG ) ) - for ( final FileInflator inflator : fileInflators ) - if ( inflator.getExtensions().contains( fileExt ) ) - { - final long t1 = System.currentTimeMillis(); - if ( onlyFile && configuration.getOption( OUTPUT_PATH ) != null ) - archivedFile = inflator.inflate( configuration, file, - new File( (String) configuration.getOption( OUTPUT_PATH ) ) ); - else archivedFile = inflator.inflate( configuration, file ); - time = ( System.currentTimeMillis() - t1 ) / 1000d; - } + final long t1 = System.currentTimeMillis(); + if ( onlyFile && configuration.getOption( OUTPUT_PATH ) != null ) + archivedFile = fileDeflator.deflate( configuration, file, + new File( (String) configuration.getOption( OUTPUT_PATH ) ) ); + else archivedFile = fileDeflator.deflate( configuration, file ); + time = ( System.currentTimeMillis() - t1 ) / 1000d; + } + } else if ( configuration.getFlag( ARCHIVE_MODE ) == INFLATION_ARCHIVE_MODE && + !configuration.getFlag( KEEP_ZIPPED_FLAG ) ) + { + final FileInflator fileInflator = REGISTRY.getFileInflator( fileExt ); + if ( fileInflator != null ) + { + final long t1 = System.currentTimeMillis(); + if ( onlyFile && configuration.getOption( OUTPUT_PATH ) != null ) + archivedFile = fileInflator.inflate( configuration, file, + new File( (String) configuration.getOption( OUTPUT_PATH ) ) ); + else archivedFile = fileInflator.inflate( configuration, file ); + time = ( System.currentTimeMillis() - t1 ) / 1000d; + } + } if ( archivedFile != null ) if ( configuration.getFlag( VERBOSE_FLAG ) ) @@ -241,27 +208,16 @@ public String getDefaultDeflatedExtension() { final String fileExt = "." + Files.getFileExtension( fileIn.getPath() ); - if ( configuration.getFlag( ARCHIVE_MODE ) == DEFLATION_ARCHIVE_MODE ) - { - for ( final FileDeflator fd : fileDeflators ) - if ( fd.getExtensions().contains( fileExt ) ) - return fd.getDefaultDeflatedExtension(); - } else if ( configuration.getFlag( ARCHIVE_MODE ) == INFLATION_ARCHIVE_MODE ) - { - for ( final FileInflator fi : fileInflators ) - if ( fi.getExtensions().contains( fileExt ) ) - return Files.getFileExtension( - fileIn.getPath().replaceAll( fi.getDefaultDeflatedExtension(), "" ) ); - } + final String deflatedExtension = REGISTRY.getDeflatedExtension( fileExt ); - return DEFAULT_DEFLATED_EXTENSION; - } + if ( deflatedExtension != null ) + if ( configuration.getFlag( ARCHIVE_MODE ) == DEFLATION_ARCHIVE_MODE ) + return deflatedExtension; + else if ( configuration.getFlag( ARCHIVE_MODE ) == INFLATION_ARCHIVE_MODE ) + return Files + .getFileExtension( fileIn.getPath().replaceAll( deflatedExtension, "" ) ); - @Override - public List getExtensions() - { - return Stream.concat( fileInflators.stream(), fileDeflators.stream() ) - .flatMap( fA -> fA.getExtensions().stream() ).collect( Collectors.toList() ); + return DEFAULT_DEFLATED_EXTENSION; } @Override @@ -346,25 +302,4 @@ public File inflate( final Configuration configuration, final File fileIn, final return fileOut; } - - private void registerFileArchiver( - final F fileArchiver, - final List fileArchivers ) - { - if ( fileArchivers.contains( fileArchiver ) ) - // TODO nope - return; - - fileArchivers.add( fileArchiver ); - } - - public void registerFileDeflator( final FileDeflator fileDeflator ) - { - registerFileArchiver( fileDeflator, fileDeflators ); - } - - public void registerFileInflator( final FileInflator fileInflator ) - { - registerFileArchiver( fileInflator, fileInflators ); - } } diff --git a/src/edu/rit/flick/FileArchiver.java b/src/edu/rit/flick/FileArchiver.java index f48e06b..7a18f66 100644 --- a/src/edu/rit/flick/FileArchiver.java +++ b/src/edu/rit/flick/FileArchiver.java @@ -6,8 +6,6 @@ */ package edu.rit.flick; -import java.util.List; - /** * @author Alex Aiezza * @@ -15,6 +13,4 @@ public interface FileArchiver { public String getDefaultDeflatedExtension(); - - public List getExtensions(); } diff --git a/src/edu/rit/flick/RegisterFileDeflatorInflator.java b/src/edu/rit/flick/RegisterFileDeflatorInflator.java new file mode 100644 index 0000000..14a63ea --- /dev/null +++ b/src/edu/rit/flick/RegisterFileDeflatorInflator.java @@ -0,0 +1,34 @@ +/** + * COPYRIGHT (C) 2015 Alex Aiezza. All Rights Reserved. + * + * See the LICENSE for the specific language governing permissions and + * limitations under the License provided with this project. + */ +package edu.rit.flick; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import edu.rit.flick.config.DeflationOptionSet; +import edu.rit.flick.config.InflationOptionSet; + +/** + * @author Alex Aiezza + * + * + */ +@Retention ( RetentionPolicy.RUNTIME ) +public @interface RegisterFileDeflatorInflator +{ + String [] inflatedExtensions(); + + String deflatedExtension() default "flick"; + + Class fileDeflator() default FlickFile.class; + + Class fileInflator() default FlickFile.class; + + Class fileDeflatorOptionSet(); + + Class fileInflatorOptionSet(); +} diff --git a/src/edu/rit/flick/config/DeflationConfiguration.java b/src/edu/rit/flick/config/DeflationConfiguration.java index 122d28a..3b0495c 100644 --- a/src/edu/rit/flick/config/DeflationConfiguration.java +++ b/src/edu/rit/flick/config/DeflationConfiguration.java @@ -6,8 +6,8 @@ */ package edu.rit.flick.config; -import edu.rit.flick.genetics.config.FastaDeflationOptionSet; -import edu.rit.flick.genetics.config.FastqDeflationOptionSet; +import static edu.rit.flick.config.DefaultOptionSet.ARCHIVE_MODE; +import static edu.rit.flick.config.DefaultOptionSet.DEFLATION_ARCHIVE_MODE; /** * @author Alex Aiezza @@ -16,10 +16,13 @@ public class DeflationConfiguration extends AbstractConfiguration { { + for ( final DeflationOptionSet dos : FileArchiverExtensionRegistry.getInstance() + .getDeflationOptionSets() ) + registerOptionSet( dos ); + registerOptionSet( new DeflationOptionSet() ); - registerOptionSet( new FastaDeflationOptionSet() ); - registerOptionSet( new FastqDeflationOptionSet() ); + setFlag( ARCHIVE_MODE, DEFLATION_ARCHIVE_MODE ); } } diff --git a/src/edu/rit/flick/config/FileArchiverExtensionRegistry.java b/src/edu/rit/flick/config/FileArchiverExtensionRegistry.java new file mode 100644 index 0000000..e796049 --- /dev/null +++ b/src/edu/rit/flick/config/FileArchiverExtensionRegistry.java @@ -0,0 +1,189 @@ +/** + * COPYRIGHT (C) 2015 Alex Aiezza. All Rights Reserved. + * + * See the LICENSE for the specific language governing permissions and + * limitations under the License provided with this project. + */ +package edu.rit.flick.config; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; +import org.springframework.core.type.filter.AnnotationTypeFilter; + +import edu.rit.flick.FileArchiver; +import edu.rit.flick.FileDeflator; +import edu.rit.flick.FileInflator; +import edu.rit.flick.RegisterFileDeflatorInflator; + +/** + * A singleton helper class for registering and storing mappings of file + * extensions to file archivers. + * + * @author Alex Aiezza + * + */ +public final class FileArchiverExtensionRegistry +{ + // Singleton + private static FileArchiverExtensionRegistry FILE_ARCHIVER_REGISTRY; + + /** + * Retrieve the registry. + * + * @return The single existing instance of the FileArchiverExtensionRegistry + */ + public static synchronized FileArchiverExtensionRegistry getInstance() + { + if ( FILE_ARCHIVER_REGISTRY == null ) + FILE_ARCHIVER_REGISTRY = new FileArchiverExtensionRegistry(); + return FILE_ARCHIVER_REGISTRY; + } + + private final Map registry; + + private final List deflationOptionSets; + private final List inflationOptionSets; + + /** + * Constructs the file archiver extension registry and scans for + * FileArchiver classes. + */ + private FileArchiverExtensionRegistry() + { + registry = new HashMap(); + deflationOptionSets = new ArrayList(); + inflationOptionSets = new ArrayList(); + + final ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider( + false ) + { + @Override + protected boolean isCandidateComponent( AnnotatedBeanDefinition beanDefinition ) + { + return beanDefinition.getMetadata().isIndependent(); + } + }; + + scanner.addIncludeFilter( new AnnotationTypeFilter( RegisterFileDeflatorInflator.class ) ); + + for ( final BeanDefinition bd : scanner.findCandidateComponents( "*" ) ) + { + try + { + final Class cl = Class.forName( bd.getBeanClassName() ); + final RegisterFileDeflatorInflator fileDIP = cl + .getAnnotation( RegisterFileDeflatorInflator.class ); + if ( fileDIP != null ) + registerFileArchiverExtensions( fileDIP ); + } catch ( Exception e ) + {} + } + } + + public FileDeflator getFileDeflator( final String extension ) + { + final FileDeflatorInflator fileDIP = registry.get( extension ); + if ( fileDIP != null ) + return fileDIP.fileDeflator; + + return null; + } + + public FileInflator getFileInflator( final String extension ) + { + final Optional fileDIo = registry.values().stream().filter( + fileDI -> fileDI.fileInflator.getDefaultDeflatedExtension().equals( extension ) ) + .findFirst(); + return fileDIo.isPresent() ? fileDIo.get().fileInflator : null; + } + + public String getDeflatedExtension( final String extension ) + { + final FileDeflatorInflator fileDIP = registry.get( extension ); + if ( fileDIP != null ) + return fileDIP.fileDeflator.getDefaultDeflatedExtension(); + + return null; + } + + public List getExtensions( final FileArchiver fileArchiver ) + { + final Optional fileDIPo = registry.values().stream() + .filter( fileDIP -> fileDIP.fileDeflator.equals( fileArchiver ) || + fileDIP.fileInflator.equals( fileArchiver ) ) + .findFirst(); + return fileDIPo.isPresent() ? fileDIPo.get().extensions : null; + } + + public List getExtensions( final Class fileArchiver ) + { + final Optional fileDIPo = registry.values().stream() + .filter( + fileDIP -> fileArchiver.isAssignableFrom( fileDIP.fileDeflator.getClass() ) || + fileArchiver.isAssignableFrom( fileDIP.fileInflator.getClass() ) ) + .findFirst(); + return fileDIPo.isPresent() ? fileDIPo.get().extensions : null; + } + + public List getDeflationOptionSets() + { + return deflationOptionSets; + } + + public List getInflationOptionSets() + { + return inflationOptionSets; + } + + public synchronized void registerFileArchiverExtensions( + final RegisterFileDeflatorInflator fileDIP ) + throws InstantiationException, IllegalAccessException + { + final List extensions = Arrays.asList( fileDIP.inflatedExtensions() ); + + for ( int e = 0; e < extensions.size(); e++ ) + { + String extension = extensions.get( e ); + if ( !extension.startsWith( "." ) ) + extension = "." + extension; + if ( extension.matches( "\\.{2,}.+" ) ) + extension = extension.replaceFirst( "\\.{2,}", "." ); + + extensions.set( e, extension ); + } + + for ( final String extension : extensions ) + { + registry.put( extension, new FileDeflatorInflator( fileDIP.fileDeflator().newInstance(), + fileDIP.fileInflator().newInstance(), extensions ) ); + } + + deflationOptionSets.add( fileDIP.fileDeflatorOptionSet().newInstance() ); + inflationOptionSets.add( fileDIP.fileInflatorOptionSet().newInstance() ); + } + + private class FileDeflatorInflator + { + private final FileDeflator fileDeflator; + private final FileInflator fileInflator; + private final List extensions; + + private FileDeflatorInflator( + final FileDeflator fileDeflator, + final FileInflator fileInflator, + final List extensions ) + { + this.fileDeflator = fileDeflator; + this.fileInflator = fileInflator; + this.extensions = extensions; + } + } +} diff --git a/src/edu/rit/flick/config/InflationConfiguration.java b/src/edu/rit/flick/config/InflationConfiguration.java index 8a01124..1c3a7ce 100644 --- a/src/edu/rit/flick/config/InflationConfiguration.java +++ b/src/edu/rit/flick/config/InflationConfiguration.java @@ -6,8 +6,8 @@ */ package edu.rit.flick.config; -import edu.rit.flick.genetics.config.FastaInflationOptionSet; -import edu.rit.flick.genetics.config.FastqInflationOptionSet; +import static edu.rit.flick.config.DefaultOptionSet.ARCHIVE_MODE; +import static edu.rit.flick.config.DefaultOptionSet.INFLATION_ARCHIVE_MODE; /** * @author Alex Aiezza @@ -16,9 +16,12 @@ public class InflationConfiguration extends AbstractConfiguration { { + for ( final InflationOptionSet ios : FileArchiverExtensionRegistry.getInstance() + .getInflationOptionSets() ) + registerOptionSet( ios ); + registerOptionSet( new InflationOptionSet() ); - registerOptionSet( new FastaInflationOptionSet() ); - registerOptionSet( new FastqInflationOptionSet() ); + setFlag( ARCHIVE_MODE, INFLATION_ARCHIVE_MODE ); } } diff --git a/src/edu/rit/flick/genetics/FastaFileArchiver.java b/src/edu/rit/flick/genetics/FastaFileArchiver.java index b85dbb2..b23d741 100644 --- a/src/edu/rit/flick/genetics/FastaFileArchiver.java +++ b/src/edu/rit/flick/genetics/FastaFileArchiver.java @@ -8,10 +8,22 @@ import static java.lang.String.format; +import edu.rit.flick.RegisterFileDeflatorInflator; +import edu.rit.flick.genetics.config.FastaDeflationOptionSet; +import edu.rit.flick.genetics.config.FastaInflationOptionSet; + /** * @author Alex Aiezza * */ +@RegisterFileDeflatorInflator ( + deflatedExtension = FastaFileArchiver.DEFAULT_DEFLATED_FASTA_EXTENSION, + inflatedExtensions = +{ "fna", "fa", "fasta" }, + fileDeflator = FastaFileDeflator.class, + fileInflator = FastaFileInflator.class, + fileDeflatorOptionSet = FastaDeflationOptionSet.class, + fileInflatorOptionSet = FastaInflationOptionSet.class ) public interface FastaFileArchiver extends FastFileArchiver { public final static int DEFAULT_FASTA_SEQUENCE_LINE_SIZE = 80; @@ -25,8 +37,6 @@ public interface FastaFileArchiver extends FastFileArchiver public static final byte SEQUENCE_ID_START = '>'; - public static final String FASTA_EXTENSION = ".fna"; - public static final String DEFAULT_DEFLATED_FASTA_EXTENSION = ".flickfa"; @Override diff --git a/src/edu/rit/flick/genetics/FastaFileDeflator.java b/src/edu/rit/flick/genetics/FastaFileDeflator.java index 2ea7f3e..3258273 100644 --- a/src/edu/rit/flick/genetics/FastaFileDeflator.java +++ b/src/edu/rit/flick/genetics/FastaFileDeflator.java @@ -14,7 +14,6 @@ import java.nio.channels.FileChannel; import java.nio.channels.FileChannel.MapMode; import java.util.Arrays; -import java.util.Collections; import java.util.List; import edu.rit.flick.genetics.util.ByteBufferOutputStream; @@ -115,12 +114,6 @@ protected void createOutputFiles( final File fastaFile, final String tempOutputD } - @Override - public List getExtensions() - { - return Collections.singletonList( FASTA_EXTENSION ); - } - @Override public int getFastaSequenceLineSize() { diff --git a/src/edu/rit/flick/genetics/FastaFileInflator.java b/src/edu/rit/flick/genetics/FastaFileInflator.java index 44b5fe7..62310a5 100644 --- a/src/edu/rit/flick/genetics/FastaFileInflator.java +++ b/src/edu/rit/flick/genetics/FastaFileInflator.java @@ -10,8 +10,6 @@ import java.io.File; import java.io.IOException; -import java.util.Collections; -import java.util.List; import java.util.Scanner; import java.util.StringTokenizer; @@ -68,12 +66,6 @@ protected void createOutputFiles( final String tempOutputDirectory, final File f .useDelimiter( "\\" + PIPE ); } - @Override - public List getExtensions() - { - return Collections.singletonList( DEFAULT_DEFLATED_FASTA_EXTENSION ); - } - @Override public int getFastaSequenceLineSize() { diff --git a/src/edu/rit/flick/genetics/FastqFileArchiver.java b/src/edu/rit/flick/genetics/FastqFileArchiver.java index a2a61f8..3439e30 100644 --- a/src/edu/rit/flick/genetics/FastqFileArchiver.java +++ b/src/edu/rit/flick/genetics/FastqFileArchiver.java @@ -8,10 +8,22 @@ import static java.lang.String.format; +import edu.rit.flick.RegisterFileDeflatorInflator; +import edu.rit.flick.genetics.config.FastqDeflationOptionSet; +import edu.rit.flick.genetics.config.FastqInflationOptionSet; + /** * @author Alex Aiezza * */ +@RegisterFileDeflatorInflator ( + deflatedExtension = FastqFileArchiver.DEFAULT_DEFLATED_FASTQ_EXTENSION, + inflatedExtensions = +{ "fq", "fastq" }, + fileDeflator = FastqFileDeflator.class, + fileInflator = FastqFileInflator.class, + fileDeflatorOptionSet = FastqDeflationOptionSet.class, + fileInflatorOptionSet = FastqInflationOptionSet.class ) public interface FastqFileArchiver extends FastFileArchiver { public static final String SEQUENCE_SCORE_FILE = "Scores.txt"; @@ -21,8 +33,6 @@ public interface FastqFileArchiver extends FastFileArchiver public static final byte SEQUENCE_ID_START = '@'; public static final byte COMMENT_START = '+'; - public static final String FASTQ_EXTENSION = ".fq"; - public static final String DEFAULT_DEFLATED_FASTQ_EXTENSION = ".flickfq"; public static final String META_COMMENT_SAME_AS_SEQUENCE_ID = "commentSameAsSequenceId"; diff --git a/src/edu/rit/flick/genetics/FastqFileDeflator.java b/src/edu/rit/flick/genetics/FastqFileDeflator.java index 5825450..afd3ec3 100644 --- a/src/edu/rit/flick/genetics/FastqFileDeflator.java +++ b/src/edu/rit/flick/genetics/FastqFileDeflator.java @@ -15,7 +15,6 @@ import java.nio.channels.FileChannel; import java.nio.channels.FileChannel.MapMode; import java.util.Arrays; -import java.util.Collections; import java.util.List; import edu.rit.flick.genetics.util.ByteBufferOutputStream; @@ -63,12 +62,6 @@ protected void createOutputFiles( final File fastqFile, final String tempOutputD new FileOutputStream( tempOutputDirectory + COMMENTS_FILE ), DEFAULT_BUFFER ); } - @Override - public List getExtensions() - { - return Collections.singletonList( FASTQ_EXTENSION ); - } - @Override protected List getSequenceEscapes() { diff --git a/src/edu/rit/flick/genetics/FastqFileInflator.java b/src/edu/rit/flick/genetics/FastqFileInflator.java index ad2edd4..8e1e026 100644 --- a/src/edu/rit/flick/genetics/FastqFileInflator.java +++ b/src/edu/rit/flick/genetics/FastqFileInflator.java @@ -12,8 +12,6 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; -import java.util.Collections; -import java.util.List; import java.util.Scanner; import it.unimi.dsi.io.ByteBufferInputStream; @@ -86,12 +84,6 @@ public synchronized int read() throws IOException scoreFis.close(); } - @Override - public List getExtensions() - { - return Collections.singletonList( DEFAULT_DEFLATED_FASTQ_EXTENSION ); - } - public void getNextLength() throws IOException { if ( lengthfile.available() > 0 ) diff --git a/src/edu/rit/flick/util/Flick.java b/src/edu/rit/flick/util/Flick.java index a663a1b..49137c2 100644 --- a/src/edu/rit/flick/util/Flick.java +++ b/src/edu/rit/flick/util/Flick.java @@ -6,8 +6,6 @@ */ package edu.rit.flick.util; -import static edu.rit.flick.config.DefaultOptionSet.ARCHIVE_MODE; -import static edu.rit.flick.config.DefaultOptionSet.DEFLATION_ARCHIVE_MODE; import static edu.rit.flick.config.DefaultOptionSet.HELP_FLAG; import java.io.BufferedReader; @@ -39,15 +37,12 @@ public class Flick Flick.class.getClassLoader().getResourceAsStream( FLICK_USAGE_FILE ) ) ); br.lines().forEach( line -> usage.append( line ).append( "\n" ) ); USAGE_FORMAT = usage.toString(); - - // TODO Map file extensions to deflators. } public static void main( final String... args ) { final Configuration configuration = new DeflationConfiguration(); ConfigurationProcessor.processConfiguration( configuration, args ); - configuration.setFlag( ARCHIVE_MODE, DEFLATION_ARCHIVE_MODE ); if ( args.length <= 0 || configuration.getFlag( HELP_FLAG ) ) { diff --git a/src/edu/rit/flick/util/Unflick.java b/src/edu/rit/flick/util/Unflick.java index 4193211..6d9895e 100644 --- a/src/edu/rit/flick/util/Unflick.java +++ b/src/edu/rit/flick/util/Unflick.java @@ -6,9 +6,7 @@ */ package edu.rit.flick.util; -import static edu.rit.flick.config.DefaultOptionSet.ARCHIVE_MODE; import static edu.rit.flick.config.DefaultOptionSet.HELP_FLAG; -import static edu.rit.flick.config.DefaultOptionSet.INFLATION_ARCHIVE_MODE; import java.io.BufferedReader; import java.io.InputStreamReader; @@ -45,7 +43,6 @@ public static void main( final String... args ) { final Configuration configuration = new InflationConfiguration(); ConfigurationProcessor.processConfiguration( configuration, args ); - configuration.setFlag( ARCHIVE_MODE, INFLATION_ARCHIVE_MODE ); if ( args.length <= 0 || configuration.getFlag( HELP_FLAG ) ) { diff --git a/test/edu/rit/flick/util/FlickTest.java b/test/edu/rit/flick/util/FlickTest.java index 64eda11..6f3b532 100644 --- a/test/edu/rit/flick/util/FlickTest.java +++ b/test/edu/rit/flick/util/FlickTest.java @@ -43,6 +43,7 @@ import edu.rit.flick.AbstractFlickFile; import edu.rit.flick.DefaultFlickFile; +import edu.rit.flick.config.FileArchiverExtensionRegistry; import edu.rit.flick.genetics.FastaFileArchiver; import edu.rit.flick.genetics.FastqFileArchiver; import it.unimi.dsi.io.ByteBufferInputStream; @@ -54,26 +55,29 @@ */ public class FlickTest { - private static final String VERBOSE_FLAG = "--verbose"; + private static final String VERBOSE_FLAG = "--verbose"; - private static final String HELP_FLAG = "--help"; + private static final String HELP_FLAG = "--help"; - private static final String FILES_DO_NOT_MATCH_ERROR_FORMAT = "%n File '%s' is different from%n file '%s'%n at byte# %d%n"; + private static final String FILES_DO_NOT_MATCH_ERROR_FORMAT = "%n File '%s' is different from%n file '%s'%n at byte# %d%n"; - private static final String TEST_RESOURCES_FOLDER = "test_resources" + + private static final String TEST_RESOURCES_FOLDER = "test_resources" + File.separator; - private static final String RESOURCES_FOLDER = "resources" + + private static final String RESOURCES_FOLDER = "resources" + File.separator; - private static final String FULL_FASTA_EXTENSION = ".fasta"; + private static final String FULL_FASTA_EXTENSION = ".fasta"; - private static final String FULL_FASTQ_EXTENSION = ".fastq"; + private static final String FULL_FASTQ_EXTENSION = ".fastq"; - private static final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); - private static final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); + private static final FileArchiverExtensionRegistry REGISTRY = FileArchiverExtensionRegistry + .getInstance(); - private static PrintStream oldOut, oldErr; + private static final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); + private static final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); + + private static PrintStream oldOut, oldErr; @AfterClass public static void cleanUpStreams() throws IOException @@ -258,9 +262,10 @@ public void testDirectory( final String directory ) private final void testFASTAfile( final String fileBase ) { originalFile = getFile( TEST_RESOURCES_FOLDER, - fileBase + FastaFileArchiver.FASTA_EXTENSION ); - flickedFile = getFile( TEST_RESOURCES_FOLDER, fileBase + FastaFileArchiver.FASTA_EXTENSION + - FastaFileArchiver.DEFAULT_DEFLATED_FASTA_EXTENSION ); + fileBase + REGISTRY.getExtensions( FastaFileArchiver.class ).get( 0 ) ); + flickedFile = getFile( TEST_RESOURCES_FOLDER, + fileBase + REGISTRY.getExtensions( FastaFileArchiver.class ).get( 0 ) + + FastaFileArchiver.DEFAULT_DEFLATED_FASTA_EXTENSION ); unflickedFile = getFile( TEST_RESOURCES_FOLDER, fileBase + FULL_FASTA_EXTENSION ); try @@ -275,9 +280,10 @@ private final void testFASTAfile( final String fileBase ) private final void testFASTQfile( final String fileBase ) { originalFile = getFile( TEST_RESOURCES_FOLDER, - fileBase + FastqFileArchiver.FASTQ_EXTENSION ); - flickedFile = getFile( TEST_RESOURCES_FOLDER, fileBase + FastqFileArchiver.FASTQ_EXTENSION + - FastqFileArchiver.DEFAULT_DEFLATED_FASTQ_EXTENSION ); + fileBase + REGISTRY.getExtensions( FastqFileArchiver.class ).get( 0 ) ); + flickedFile = getFile( TEST_RESOURCES_FOLDER, + fileBase + REGISTRY.getExtensions( FastqFileArchiver.class ).get( 0 ) + + FastqFileArchiver.DEFAULT_DEFLATED_FASTQ_EXTENSION ); unflickedFile = getFile( TEST_RESOURCES_FOLDER, fileBase + FULL_FASTQ_EXTENSION ); try