1 package compbio.engine.archive;
4 import java.io.FileNotFoundException;
5 import java.io.InputStream;
6 import java.util.Iterator;
7 import java.util.Scanner;
9 //import compbio.util.Util;
12 * Manage files in ProteoCache Archive
14 * @author Alexander Sherstnev
15 * @version 1.0 November 2013
18 public class ArchiveManager implements Iterator<ArchivedJob> {
20 //private final Scanner input;
22 * Delimiter for the scanner
24 //private final String DELIM = ">";
27 * Header data can contain non-ASCII symbols and read in UTF8
30 * the absolute path to the ProteoCache job archive
31 * @throws FileNotFoundException
32 * if the input file is not found
33 * @throws IllegalStateException
34 * if the close method was called on this instance
37 public ArchiveManager(final String mainPath) throws FileNotFoundException {
39 input = new Scanner(new File(mainPath), "UTF8");
40 input.useDelimiter(DELIM);
41 Runtime.getRuntime().addShutdownHook(new Thread() {
53 public ArchiveManager(Archive ar) {
61 * @throws IllegalStateException
62 * if the close method was called on this instance
65 public boolean hasNext() {
66 //return input.hasNext();
71 * Reads the next FastaSequence from the input
73 * @throws AssertionError
74 * if the header or the sequence is missing
75 * @throws IllegalStateException
76 * if the close method was called on this instance
77 * @throws MismatchException
78 * - if there were no more FastaSequence's.
81 public ArchivedJob next() {
82 String path = "bla-bla-bla";
84 String path = input.next();
85 while (fastaHeader.indexOf("\n") < 0 && input.hasNext()) {
86 path = fastaHeader.concat(">");
87 path = fastaHeader.concat(input.next());
90 return new ArchivedJob(path);
97 public void remove() {
98 throw new UnsupportedOperationException();
102 * Call this method to close the connection to the input file if you want to
103 * free up the resources. The connection will be closed on the JVM shutdown
104 * if this method was not called explicitly. No further reading on this
105 * instance of the FastaReader will be possible after calling this method.
107 public void close() {
111 private static ArchivedJob toFastaSequence(final String singleFastaEntry) {
113 // assert !Util.isEmpty(singleFastaEntry) :
114 // "Empty String where FASTA sequence is expected!";
116 int nlineidx = singleFastaEntry.indexOf("\n");
118 throw new AssertionError(
119 "The FASTA sequence must contain the header information"
120 + " separated by the new line from the sequence. Given sequence does not appear to "
121 + "contain the header! Given data:\n "
124 String header = singleFastaEntry.substring(0, nlineidx);
127 * if (Util.isEmpty(sequence)) { throw new AssertionError(
128 * "Empty sequences are not allowed! Please make sure the " +
129 * " data is in the FASTA format! Given data:\n " + singleFastaEntry); }
131 return new ArchivedJob(header);