Mercurial > repos > timpalpant > java_genomics_toolkit
diff src/edu/unc/genomics/AssemblyConverter.java @ 2:e16016635b2a
Uploaded
author | timpalpant |
---|---|
date | Mon, 13 Feb 2012 22:12:06 -0500 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/edu/unc/genomics/AssemblyConverter.java Mon Feb 13 22:12:06 2012 -0500 @@ -0,0 +1,43 @@ +package edu.unc.genomics; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.zip.DataFormatException; + +import com.beust.jcommander.IStringConverter; +import com.beust.jcommander.ParameterException; + +/** + * @author timpalpant + * + */ +public class AssemblyConverter implements IStringConverter<Assembly> { + + public static final Path ASSEMBLIES_DIR = Paths.get("resources", "assemblies"); + + @Override + public Assembly convert(String value) throws ParameterException { + // Look for the assembly in the resources/assemblies directory + Path p = ASSEMBLIES_DIR.resolve(value+".len"); + + // If it does not exist in the assemblies directory, check if it is a path to a file + if (!Files.isReadable(p)) { + PathConverter converter = new PathConverter(); + p = converter.convert(value); + // If it does not exist, then throw an exception that the assembly cannot be found + if (!Files.isReadable(p)) { + throw new ParameterException("Cannot find Assembly file: " + value); + } + } + + // Attempt to load the assembly from file + try { + return new Assembly(p); + } catch (IOException | DataFormatException e) { + throw new ParameterException("Error loading Assembly from file: " + p); + } + } + +}