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
}
}
}
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
}
}
}
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
}
}
}
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
}
}
}
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
}
}
}
Aggregations