Mercurial > repos > timpalpant > java_genomics_toolkit
comparison java-genomics-toolkit/src/edu/unc/genomics/AssemblyConverter.java @ 0:1daf3026d231
Upload alpha version
author | timpalpant |
---|---|
date | Mon, 13 Feb 2012 21:55:55 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:1daf3026d231 |
---|---|
1 package edu.unc.genomics; | |
2 | |
3 import java.io.IOException; | |
4 import java.nio.file.Files; | |
5 import java.nio.file.Path; | |
6 import java.nio.file.Paths; | |
7 import java.util.zip.DataFormatException; | |
8 | |
9 import com.beust.jcommander.IStringConverter; | |
10 import com.beust.jcommander.ParameterException; | |
11 | |
12 /** | |
13 * @author timpalpant | |
14 * | |
15 */ | |
16 public class AssemblyConverter implements IStringConverter<Assembly> { | |
17 | |
18 public static final Path ASSEMBLIES_DIR = Paths.get("resources", "assemblies"); | |
19 | |
20 @Override | |
21 public Assembly convert(String value) throws ParameterException { | |
22 // Look for the assembly in the resources/assemblies directory | |
23 Path p = ASSEMBLIES_DIR.resolve(value+".len"); | |
24 | |
25 // If it does not exist in the assemblies directory, check if it is a path to a file | |
26 if (!Files.isReadable(p)) { | |
27 PathConverter converter = new PathConverter(); | |
28 p = converter.convert(value); | |
29 // If it does not exist, then throw an exception that the assembly cannot be found | |
30 if (!Files.isReadable(p)) { | |
31 throw new ParameterException("Cannot find Assembly file: " + value); | |
32 } | |
33 } | |
34 | |
35 // Attempt to load the assembly from file | |
36 try { | |
37 return new Assembly(p); | |
38 } catch (IOException | DataFormatException e) { | |
39 throw new ParameterException("Error loading Assembly from file: " + p); | |
40 } | |
41 } | |
42 | |
43 } |