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