Search in sources :

Example 1 with GafRecord

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

the class FilterGaf method call.

@Override
public Integer call() throws Exception {
    int lineNumber = 0;
    BufferedReader reader = null;
    PrintWriter writer = null;
    try {
        reader = reader(inputGafFile);
        writer = writer(outputGafFile);
        while (reader.ready()) {
            String line = reader.readLine();
            GafRecord record = GafRecord.valueOf(line);
            lineNumber++;
            // write out record
            boolean pass = true;
            for (Filter filter : filters) {
                pass &= filter.accept(record);
            }
            if (pass) {
                writer.println(record.toString());
            }
        }
        return 0;
    } catch (Exception e) {
        throw new Exception("could not read record at line number " + lineNumber + ", caught" + e.getMessage(), e);
    } finally {
        try {
            reader.close();
        } catch (Exception e) {
        // empty
        }
        try {
            writer.close();
        } catch (Exception e) {
        // empty
        }
    }
}
Also used : BufferedReader(java.io.BufferedReader) GafRecord(org.dishevelled.bio.alignment.gaf.GafRecord) ScriptException(javax.script.ScriptException) CommandLineParseException(org.dishevelled.commandline.CommandLineParseException) PrintWriter(java.io.PrintWriter)

Example 2 with GafRecord

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

the class CompressGaf method call.

@Override
public Integer call() throws Exception {
    int lineNumber = 0;
    BufferedReader reader = null;
    PrintWriter writer = null;
    try {
        reader = reader(inputGafFile);
        writer = writer(outputGafFile);
        while (reader.ready()) {
            String line = reader.readLine();
            GafRecord record = GafRecord.valueOf(line);
            lineNumber++;
            writer.println(record.toString());
        }
        return 0;
    } catch (Exception e) {
        throw new Exception("could not read record at line number " + lineNumber + ", caught" + e.getMessage(), e);
    } finally {
        try {
            reader.close();
        } catch (Exception e) {
        // ignore
        }
        try {
            writer.close();
        } catch (Exception e) {
        // ignore
        }
    }
}
Also used : BufferedReader(java.io.BufferedReader) GafRecord(org.dishevelled.bio.alignment.gaf.GafRecord) CommandLineParseException(org.dishevelled.commandline.CommandLineParseException) PrintWriter(java.io.PrintWriter)

Example 3 with GafRecord

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

the class GenerateGaf method main.

public static void main(final String[] args) throws Exception {
    PrintWriter writer = null;
    try {
        writer = writer(null);
        for (int i = 0; i < 10_000_000; i++) {
            String queryName = "query";
            long queryLength = 1_000_000L;
            long queryStart = 20_000L;
            long queryEnd = 40_000L;
            char strand = '+';
            String pathName = "path";
            long pathLength = 20_000L;
            long pathStart = 2_000L;
            long pathEnd = 18_000L;
            long matches = 16_000L;
            long alignmentBlockLength = 16_000L;
            int mappingQuality = 60;
            ImmutableMap.Builder<String, Annotation> annotations = ImmutableMap.builder();
            annotations.put("cs", Annotation.valueOf("cs:Z:16000M"));
            writer.println(new GafRecord(queryName, queryLength, queryStart, queryEnd, strand, pathName, pathLength, pathStart, pathEnd, matches, alignmentBlockLength, mappingQuality, annotations.build()).toString());
        }
    } finally {
        try {
            writer.close();
        } catch (Exception e) {
        // empty
        }
    }
}
Also used : ImmutableMap(com.google.common.collect.ImmutableMap) Annotation(org.dishevelled.bio.annotation.Annotation) GafRecord(org.dishevelled.bio.alignment.gaf.GafRecord) PrintWriter(java.io.PrintWriter)

Example 4 with GafRecord

use of org.dishevelled.bio.alignment.gaf.GafRecord 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 5 with GafRecord

use of org.dishevelled.bio.alignment.gaf.GafRecord 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

GafRecord (org.dishevelled.bio.alignment.gaf.GafRecord)5 BufferedReader (java.io.BufferedReader)4 PrintWriter (java.io.PrintWriter)4 CommandLineParseException (org.dishevelled.commandline.CommandLineParseException)3 IOException (java.io.IOException)2 GafListener (org.dishevelled.bio.alignment.gaf.GafListener)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ScriptException (javax.script.ScriptException)1 Annotation (org.dishevelled.bio.annotation.Annotation)1