1 package compbio.engine.archive;
3 import java.io.FileNotFoundException;
5 import java.util.Iterator;
7 //import compbio.util.Util;
10 * Manage files in ProteoCache Archive
12 * @author Alexander Sherstnev
13 * @version 1.0 November 2013
16 public class ArchiveManager implements Iterator<ArchivedJob> {
19 // private final Scanner input;
21 * Delimiter for the scanner
23 // private final String DELIM = ">";
26 * Header data can contain non-ASCII symbols and read in UTF8
29 * the absolute path to the ProteoCache job archive
30 * @throws FileNotFoundException
31 * if the input file is not found
32 * @throws IllegalStateException
33 * if the close method was called on this instance
36 public ArchiveManager(final String mainPath) throws FileNotFoundException {
38 * input = new Scanner(new File(mainPath), "UTF8");
39 * input.useDelimiter(DELIM); Runtime.getRuntime().addShutdownHook(new
42 * @Override public void run() { if (input != null) { input.close(); } }
47 public ArchiveManager(Archive ar) {
54 * @throws IllegalStateException
55 * if the close method was called on this instance
58 public boolean hasNext() {
59 // return input.hasNext();
64 * Reads the next FastaSequence from the input
66 * @throws AssertionError
67 * if the header or the sequence is missing
68 * @throws IllegalStateException
69 * if the close method was called on this instance
70 * @throws MismatchException
71 * - if there were no more FastaSequence's.
74 public ArchivedJob next() {
75 String path = "bla-bla-bla";
77 * String path = input.next(); while (fastaHeader.indexOf("\n") < 0 &&
78 * input.hasNext()) { path = fastaHeader.concat(">"); path =
79 * fastaHeader.concat(input.next()); }
81 return new ArchivedJob(path);
88 public void remove() {
89 throw new UnsupportedOperationException();
93 * Call this method to close the connection to the input file if you want to
94 * free up the resources. The connection will be closed on the JVM shutdown
95 * if this method was not called explicitly. No further reading on this
96 * instance of the FastaReader will be possible after calling this method.
102 private static ArchivedJob toFastaSequence(final String singleFastaEntry) {
104 // assert !Util.isEmpty(singleFastaEntry) :
105 // "Empty String where FASTA sequence is expected!";
107 int nlineidx = singleFastaEntry.indexOf("\n");
109 throw new AssertionError("The FASTA sequence must contain the header information"
110 + " separated by the new line from the sequence. Given sequence does not appear to "
111 + "contain the header! Given data:\n " + singleFastaEntry);
113 String header = singleFastaEntry.substring(0, nlineidx);
116 * if (Util.isEmpty(sequence)) { throw new AssertionError(
117 * "Empty sequences are not allowed! Please make sure the " +
118 * " data is in the FASTA format! Given data:\n " + singleFastaEntry); }
120 return new ArchivedJob(header);