From 6245c3f3f005e06873f7a6307c76bf518f1422a4 Mon Sep 17 00:00:00 2001 From: Sasha Sherstnev Date: Wed, 13 Nov 2013 14:18:33 +0000 Subject: [PATCH] Add still-not-working code for archiving jobs --- engine/compbio/engine/archive/Archive.java | 5 + engine/compbio/engine/archive/ArchiveManager.java | 133 +++++++++++++++++++++ engine/compbio/engine/archive/ArchivedJob.java | 44 +++++++ 3 files changed, 182 insertions(+) create mode 100644 engine/compbio/engine/archive/Archive.java create mode 100644 engine/compbio/engine/archive/ArchiveManager.java create mode 100644 engine/compbio/engine/archive/ArchivedJob.java diff --git a/engine/compbio/engine/archive/Archive.java b/engine/compbio/engine/archive/Archive.java new file mode 100644 index 0000000..2a1f410 --- /dev/null +++ b/engine/compbio/engine/archive/Archive.java @@ -0,0 +1,5 @@ +package compbio.engine.archive; + +public class Archive { + +} diff --git a/engine/compbio/engine/archive/ArchiveManager.java b/engine/compbio/engine/archive/ArchiveManager.java new file mode 100644 index 0000000..dabaf3a --- /dev/null +++ b/engine/compbio/engine/archive/ArchiveManager.java @@ -0,0 +1,133 @@ +package compbio.engine.archive; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.InputStream; +import java.util.Iterator; +import java.util.Scanner; + +//import compbio.util.Util; + +/** + * Manage files in ProteoCache Archive + * + * @author Alexander Sherstnev + * @version 1.0 November 2013 + * + */ +public class ArchiveManager implements Iterator { + Archive archive; + //private final Scanner input; + /** + * Delimiter for the scanner + */ + //private final String DELIM = ">"; + + /** + * Header data can contain non-ASCII symbols and read in UTF8 + * + * @param mainPath + * the absolute path to the ProteoCache job archive + * @throws FileNotFoundException + * if the input file is not found + * @throws IllegalStateException + * if the close method was called on this instance + * + */ + public ArchiveManager(final String mainPath) throws FileNotFoundException { + /* + input = new Scanner(new File(mainPath), "UTF8"); + input.useDelimiter(DELIM); + Runtime.getRuntime().addShutdownHook(new Thread() { + + @Override + public void run() { + if (input != null) { + input.close(); + } + } + }); + */ + } + + public ArchiveManager(Archive ar) { + archive = ar; + } + + + /** + * {@inheritDoc} + * + * @throws IllegalStateException + * if the close method was called on this instance + */ + @Override + public boolean hasNext() { + //return input.hasNext(); + return true; + } + + /** + * Reads the next FastaSequence from the input + * + * @throws AssertionError + * if the header or the sequence is missing + * @throws IllegalStateException + * if the close method was called on this instance + * @throws MismatchException + * - if there were no more FastaSequence's. + */ + @Override + public ArchivedJob next() { + String path = "bla-bla-bla"; + /* + String path = input.next(); + while (fastaHeader.indexOf("\n") < 0 && input.hasNext()) { + path = fastaHeader.concat(">"); + path = fastaHeader.concat(input.next()); + } + */ + return new ArchivedJob(path); + } + + /** + * Not implemented + */ + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + + /** + * Call this method to close the connection to the input file if you want to + * free up the resources. The connection will be closed on the JVM shutdown + * if this method was not called explicitly. No further reading on this + * instance of the FastaReader will be possible after calling this method. + */ + public void close() { + //input.close(); + } + + private static ArchivedJob toFastaSequence(final String singleFastaEntry) { + + // assert !Util.isEmpty(singleFastaEntry) : + // "Empty String where FASTA sequence is expected!"; + + int nlineidx = singleFastaEntry.indexOf("\n"); + if (nlineidx < 0) { + throw new AssertionError( + "The FASTA sequence must contain the header information" + + " separated by the new line from the sequence. Given sequence does not appear to " + + "contain the header! Given data:\n " + + singleFastaEntry); + } + String header = singleFastaEntry.substring(0, nlineidx); + + /* + * if (Util.isEmpty(sequence)) { throw new AssertionError( + * "Empty sequences are not allowed! Please make sure the " + + * " data is in the FASTA format! Given data:\n " + singleFastaEntry); } + */ + return new ArchivedJob(header); + } +} diff --git a/engine/compbio/engine/archive/ArchivedJob.java b/engine/compbio/engine/archive/ArchivedJob.java new file mode 100644 index 0000000..3f0f7d5 --- /dev/null +++ b/engine/compbio/engine/archive/ArchivedJob.java @@ -0,0 +1,44 @@ +package compbio.engine.archive; + +import java.io.FileOutputStream; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.nio.channels.Channels; +import java.nio.channels.ReadableByteChannel; +import java.util.List; + +public class ArchivedJob { + String path; + int filesize; + List files; + + ArchivedJob (String path) { + this.path = path; + } + + public boolean getArchiveFromWS() { + return false; + } + + + public boolean getArchiveFromWeb (String webpath) throws IOException, MalformedURLException { + URL website = new URL(webpath); + ReadableByteChannel rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(path); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + return true; + } + + + public int getSize() { + return filesize; + } + + public List unpack() { + if (null != files) { + + } + return files; + } +} -- 1.7.10.2