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