annotate src/edu/unc/genomics/AssemblyConverter.java @ 2:e16016635b2a

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