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
}
}
}
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();
}
}
Aggregations