Search in sources :

Example 1 with GafListener

use of org.dishevelled.bio.alignment.gaf.GafListener in project dishevelled-bio by heuermh.

the class CompressGaf method compress.

/**
 * Compress alignments in GAF format on HDFS to splittable bgzf or bzip2 compression codecs.
 *
 * @param inputPath input path, must not be null
 * @param outputPath output path, must not be null
 * @param conf configuration, must not be null
 * @throws IOException if an I/O error occurs
 */
public static void compress(final String inputPath, final String outputPath, final Configuration conf) throws IOException {
    checkNotNull(inputPath);
    checkNotNull(outputPath);
    checkNotNull(conf);
    BufferedReader reader = null;
    PrintWriter writer = null;
    try {
        reader = reader(inputPath, conf);
        writer = writer(outputPath, conf);
        final PrintWriter w = writer;
        GafReader.stream(reader, new GafListener() {

            @Override
            public boolean record(final GafRecord gafRecord) {
                GafWriter.write(gafRecord, w);
                return true;
            }
        });
    } finally {
        try {
            reader.close();
        } catch (Exception e) {
        // ignore
        }
        try {
            writer.close();
        } catch (Exception e) {
        // ignore
        }
    }
}
Also used : BufferedReader(java.io.BufferedReader) GafListener(org.dishevelled.bio.alignment.gaf.GafListener) GafRecord(org.dishevelled.bio.alignment.gaf.GafRecord) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Example 2 with GafListener

use of org.dishevelled.bio.alignment.gaf.GafListener in project dishevelled-bio by heuermh.

the class SplitGaf method call.

@Override
public Integer call() throws Exception {
    BufferedReader reader = null;
    try {
        reader = reader(inputFile);
        GafReader.stream(reader, new GafListener() {

            private long r = 0L;

            private int files = 0;

            private CountingWriter writer;

            @Override
            public boolean record(final GafRecord record) {
                if (writer == null) {
                    writer = createCountingWriter(files);
                }
                GafWriter.write(record, writer.asPrintWriter());
                try {
                    writer.flush();
                } catch (IOException e) {
                // ignore
                }
                r++;
                if (r >= records || writer.getCount() >= bytes) {
                    r = 0L;
                    files++;
                    try {
                        writer.close();
                    } catch (Exception e) {
                    // ignore
                    } finally {
                        writer = null;
                    }
                }
                return true;
            }
        });
        return 0;
    } finally {
        try {
            reader.close();
        } catch (Exception e) {
        // ignore
        }
        closeWriters();
    }
}
Also used : BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) GafListener(org.dishevelled.bio.alignment.gaf.GafListener) GafRecord(org.dishevelled.bio.alignment.gaf.GafRecord) IOException(java.io.IOException) CommandLineParseException(org.dishevelled.commandline.CommandLineParseException)

Aggregations

BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 GafListener (org.dishevelled.bio.alignment.gaf.GafListener)2 GafRecord (org.dishevelled.bio.alignment.gaf.GafRecord)2 PrintWriter (java.io.PrintWriter)1 CommandLineParseException (org.dishevelled.commandline.CommandLineParseException)1