Search in sources :

Example 1 with Gfa1Record

use of org.dishevelled.bio.assembly.gfa1.Gfa1Record in project dishevelled-bio by heuermh.

the class FilterRgfa method call.

@Override
public Integer call() throws Exception {
    PrintWriter writer = null;
    try {
        writer = writer(outputRgfaFile);
        final PrintWriter w = writer;
        Gfa1Reader.stream(reader(inputRgfaFile), new Gfa1Listener() {

            @Override
            public boolean record(final Gfa1Record record) {
                // write out record
                boolean pass = true;
                for (Filter filter : filters) {
                    pass &= filter.accept(record);
                }
                if (pass) {
                    Gfa1Writer.write(record, w);
                }
                return true;
            }
        });
        return 0;
    } finally {
        try {
            writer.close();
        } catch (Exception e) {
        // empty
        }
    }
}
Also used : Gfa1Record(org.dishevelled.bio.assembly.gfa1.Gfa1Record) Gfa1Listener(org.dishevelled.bio.assembly.gfa1.Gfa1Listener) ScriptException(javax.script.ScriptException) CommandLineParseException(org.dishevelled.commandline.CommandLineParseException) PrintWriter(java.io.PrintWriter)

Example 2 with Gfa1Record

use of org.dishevelled.bio.assembly.gfa1.Gfa1Record in project dishevelled-bio by heuermh.

the class TraversePaths method call.

@Override
public Integer call() throws Exception {
    BufferedReader reader = null;
    PrintWriter writer = null;
    try {
        reader = reader(inputGfa1File);
        writer = writer(outputGfa1File);
        final PrintWriter w = writer;
        Gfa1Reader.stream(reader, new Gfa1Listener() {

            @Override
            public boolean record(final Gfa1Record gfa1Record) {
                Gfa1Writer.write(gfa1Record, w);
                if (gfa1Record instanceof Path) {
                    Path path = (Path) gfa1Record;
                    int size = path.getSegments().size();
                    Reference source = null;
                    Reference target = null;
                    String overlap = null;
                    for (int i = 0; i < size; i++) {
                        target = path.getSegments().get(i);
                        if (i > 0) {
                            overlap = (path.getOverlaps() != null && path.getOverlaps().size() > i) ? path.getOverlaps().get(i - 1) : null;
                        }
                        if (source != null) {
                            Traversal traversal = new Traversal(path.getName(), i - 1, source, target, overlap, EMPTY_ANNOTATIONS);
                            Gfa1Writer.write(traversal, w);
                        }
                        source = target;
                    }
                }
                return true;
            }
        });
        return 0;
    } finally {
        try {
            reader.close();
        } catch (Exception e) {
        // ignore
        }
        try {
            writer.close();
        } catch (Exception e) {
        // ignore
        }
    }
}
Also used : Path(org.dishevelled.bio.assembly.gfa1.Path) Gfa1Record(org.dishevelled.bio.assembly.gfa1.Gfa1Record) Reference(org.dishevelled.bio.assembly.gfa1.Reference) BufferedReader(java.io.BufferedReader) Traversal(org.dishevelled.bio.assembly.gfa1.Traversal) Gfa1Listener(org.dishevelled.bio.assembly.gfa1.Gfa1Listener) CommandLineParseException(org.dishevelled.commandline.CommandLineParseException) PrintWriter(java.io.PrintWriter)

Example 3 with Gfa1Record

use of org.dishevelled.bio.assembly.gfa1.Gfa1Record in project dishevelled-bio by heuermh.

the class CompressGfa1 method call.

@Override
public Integer call() throws Exception {
    BufferedReader reader = null;
    PrintWriter writer = null;
    try {
        reader = reader(inputGfa1File);
        writer = writer(outputGfa1File);
        final PrintWriter w = writer;
        Gfa1Reader.stream(reader, new Gfa1Listener() {

            @Override
            public boolean record(final Gfa1Record gfa1Record) {
                Gfa1Writer.write(gfa1Record, w);
                return true;
            }
        });
        return 0;
    } finally {
        try {
            reader.close();
        } catch (Exception e) {
        // ignore
        }
        try {
            writer.close();
        } catch (Exception e) {
        // ignore
        }
    }
}
Also used : Gfa1Record(org.dishevelled.bio.assembly.gfa1.Gfa1Record) BufferedReader(java.io.BufferedReader) Gfa1Listener(org.dishevelled.bio.assembly.gfa1.Gfa1Listener) CommandLineParseException(org.dishevelled.commandline.CommandLineParseException) PrintWriter(java.io.PrintWriter)

Example 4 with Gfa1Record

use of org.dishevelled.bio.assembly.gfa1.Gfa1Record in project dishevelled-bio by heuermh.

the class CompressGfa1 method compress.

/**
 * Compress assembly in GFA 1.0 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;
        Gfa1Reader.stream(reader, new Gfa1Listener() {

            @Override
            public boolean record(final Gfa1Record gfa1Record) {
                Gfa1Writer.write(gfa1Record, w);
                return true;
            }
        });
    } finally {
        try {
            reader.close();
        } catch (Exception e) {
        // ignore
        }
        try {
            writer.close();
        } catch (Exception e) {
        // ignore
        }
    }
}
Also used : Gfa1Record(org.dishevelled.bio.assembly.gfa1.Gfa1Record) BufferedReader(java.io.BufferedReader) Gfa1Listener(org.dishevelled.bio.assembly.gfa1.Gfa1Listener) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Example 5 with Gfa1Record

use of org.dishevelled.bio.assembly.gfa1.Gfa1Record in project dishevelled-bio by heuermh.

the class CompressRgfa method call.

@Override
public Integer call() throws Exception {
    BufferedReader reader = null;
    PrintWriter writer = null;
    try {
        reader = reader(inputRgfaFile);
        writer = writer(outputRgfaFile);
        final PrintWriter w = writer;
        Gfa1Reader.stream(reader, new Gfa1Listener() {

            @Override
            public boolean record(final Gfa1Record rgfaRecord) {
                if (rgfaRecord instanceof Segment) {
                    Segment segment = (Segment) rgfaRecord;
                    // SN, SO, SR are required for rGFA segments
                    if (!segment.containsStableName()) {
                        throw new IllegalArgumentException("rGFA segment " + segment.getName() + " must contain SN tag");
                    }
                    if (!segment.containsStableOffset()) {
                        throw new IllegalArgumentException("rGFA segment " + segment.getName() + " must contain SO tag");
                    }
                    if (!segment.containsStableRank()) {
                        throw new IllegalArgumentException("rGFA segment " + segment.getName() + " must contain SR tag");
                    }
                }
                Gfa1Writer.write(rgfaRecord, w);
                return true;
            }
        });
        return 0;
    } finally {
        try {
            reader.close();
        } catch (Exception e) {
        // ignore
        }
        try {
            writer.close();
        } catch (Exception e) {
        // ignore
        }
    }
}
Also used : Gfa1Record(org.dishevelled.bio.assembly.gfa1.Gfa1Record) BufferedReader(java.io.BufferedReader) Gfa1Listener(org.dishevelled.bio.assembly.gfa1.Gfa1Listener) Segment(org.dishevelled.bio.assembly.gfa1.Segment) CommandLineParseException(org.dishevelled.commandline.CommandLineParseException) PrintWriter(java.io.PrintWriter)

Aggregations

PrintWriter (java.io.PrintWriter)9 Gfa1Listener (org.dishevelled.bio.assembly.gfa1.Gfa1Listener)9 Gfa1Record (org.dishevelled.bio.assembly.gfa1.Gfa1Record)9 CommandLineParseException (org.dishevelled.commandline.CommandLineParseException)8 BufferedReader (java.io.BufferedReader)7 Path (org.dishevelled.bio.assembly.gfa1.Path)3 Traversal (org.dishevelled.bio.assembly.gfa1.Traversal)3 ScriptException (javax.script.ScriptException)2 Reference (org.dishevelled.bio.assembly.gfa1.Reference)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Containment (org.dishevelled.bio.assembly.gfa1.Containment)1 Link (org.dishevelled.bio.assembly.gfa1.Link)1 Segment (org.dishevelled.bio.assembly.gfa1.Segment)1