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