annotate java-genomics-toolkit/gui/edu/unc/genomics/AssemblyManager.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.DirectoryStream;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
5 import java.nio.file.Files;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
6 import java.nio.file.Path;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
7 import java.nio.file.Paths;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
8 import java.util.ArrayList;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
9 import java.util.List;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
10 import java.util.zip.DataFormatException;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
11
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
12 import org.apache.log4j.Logger;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
13
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
14 /**
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
15 * Suite of static methods for managing the built-in assemblies in the resources dir
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
16 * as well as keeping track of the last used assembly
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
17 *
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
18 * @author timpalpant
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
19 *
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
20 */
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
21 public class AssemblyManager {
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
22
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
23 private static final Logger log = Logger.getLogger(AssemblyManager.class);
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
24
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
25 /**
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
26 * The last used Assembly
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
27 */
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
28 private static Assembly lastUsed;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
29
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
30 /**
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
31 * Returns all available assemblies in the resources directory
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
32 * @return the assemblies available in the resources directory
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
33 */
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
34 public static List<Assembly> getAvailableAssemblies() {
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
35 List<Assembly> assemblies = new ArrayList<>();
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
36
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
37 try (DirectoryStream<Path> stream = Files.newDirectoryStream(ResourceManager.getAssembliesDirectory(), "*.{len}")) {
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
38 for (Path entry : stream) {
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
39 log.debug("Loading assembly: " + entry);
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
40 try {
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
41 Assembly a = new Assembly(entry);
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
42 assemblies.add(a);
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
43 } catch (IOException | DataFormatException e1) {
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
44 log.warn("Error loading assembly: " + entry);
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
45 }
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
46 }
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
47 } catch (IOException e) {
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
48 log.error("Error listing assemblies");
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
49 e.printStackTrace();
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
50 }
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
51
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
52 return assemblies;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
53 }
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
54
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
55 public static void deleteAssembly(Assembly a) throws IOException {
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
56 Files.deleteIfExists(a.getPath());
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
57 }
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
58
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
59 public static Assembly loadCustomAssembly(Path assemblyFile) throws IOException, DataFormatException {
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
60 log.debug("Loading custom assembly from file: " + assemblyFile);
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
61 Assembly a = new Assembly(assemblyFile);
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
62
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
63 // TODO: Warn if this assembly is already loaded
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
64
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
65 // Copy the assembly file into the built-in assemblies directory
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
66 Files.copy(assemblyFile, ResourceManager.getAssembliesDirectory().resolve(assemblyFile.getFileName()));
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
67 return a;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
68 }
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
69
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
70 /**
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
71 * @return the lastUsed
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
72 */
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
73 public static Assembly getLastUsed() {
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
74 return lastUsed;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
75 }
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
76
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
77 /**
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
78 * @param lastUsed the lastUsed to set
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
79 */
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
80 public static void setLastUsed(Assembly lastUsed) {
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
81 AssemblyManager.lastUsed = lastUsed;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
82 }
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
83 }