use of htsjdk.samtools.fastq.BasicFastqWriter in project gridss by PapenfussLab.
the class ExternalProcessStreamingAligner method ensureAligner.
private void ensureAligner() throws IOException {
if (aligner == null) {
log.info("Starting external aligner");
log.info(commandlinestr);
aligner = new ProcessBuilder(args).redirectInput(Redirect.PIPE).redirectOutput(Redirect.PIPE).redirectError(Redirect.INHERIT).start();
toExternalProgram = new BasicFastqWriter(new PrintStream(new BufferedOutputStream(aligner.getOutputStream())));
reader = new Thread(() -> readAllAlignments(readerFactory));
reader.setName("ExternalProcessStreamingAligner");
reader.start();
}
}
use of htsjdk.samtools.fastq.BasicFastqWriter in project jvarkit by lindenb.
the class FastqGrep method doWork.
@Override
public int doWork(List<String> args) {
BufferedReader in = null;
FastqWriter out = null;
try {
if (this.readNameFile != null) {
in = IOUtils.openFileForBufferedReading(this.readNameFile);
String line;
while ((line = in.readLine()) != null) {
line = line.trim();
if (line.isEmpty())
continue;
this.readNames.put(getReadName(line), 0);
}
in.close();
}
for (final String r : this.readNamesInput) {
this.readNames.put(getReadName(r), 0);
}
if (readNames.isEmpty()) {
LOG.warn("no read name found.");
}
if (this.outputFile != null) {
LOG.info("Writing to " + this.outputFile);
out = new BasicFastqWriter(this.outputFile);
} else {
LOG.info("Writing to stdout");
out = new BasicFastqWriter(stdout());
}
if (args.isEmpty()) {
LOG.info("Reading from stdin");
FastqReader fqR = new FourLinesFastqReader(System.in);
run(fqR, out);
fqR.close();
} else
for (String fname : args) {
File f = new File(fname);
LOG.info("Reading from " + f);
FastqReader fqR = new FourLinesFastqReader(f);
run(fqR, out);
fqR.close();
}
CloserUtil.close(out);
return 0;
} catch (Exception err) {
LOG.error(err);
return -1;
} finally {
CloserUtil.close(in);
}
}
use of htsjdk.samtools.fastq.BasicFastqWriter in project jvarkit by lindenb.
the class FastqJavascript method doWork.
private void doWork(final FastqReader r) throws IOException, ScriptException {
final FastqWriter[] fastqWriters = { null, null };
try {
if (!interleaved) {
if (this.R1FileOut != null || this.R2FileOut != null) {
throw new IllegalStateException("This is not an interleaved input but option R1FILEOUT / OPTION_R2FILEOUT were defined.");
}
if (this.outputFile == null) {
fastqWriters[0] = new BasicFastqWriter(new PrintStream(stdout()));
} else {
fastqWriters[0] = new BasicFastqWriter(outputFile);
}
fastqWriters[1] = fastqWriters[0];
} else /* interleaved */
{
if ((this.R1FileOut == null && this.R2FileOut != null) || (this.R1FileOut != null && this.R2FileOut == null)) {
throw new IllegalStateException("Option _R1FILEOUT / OPTION_R2FILEOUT must be both defined");
} else if (this.R1FileOut == null && this.R2FileOut == null) {
if (this.outputFile == null) {
fastqWriters[0] = new BasicFastqWriter(new PrintStream(stdout()));
} else {
fastqWriters[0] = new BasicFastqWriter(this.outputFile);
}
fastqWriters[1] = fastqWriters[0];
} else {
fastqWriters[0] = new BasicFastqWriter(this.R1FileOut);
fastqWriters[1] = new BasicFastqWriter(this.R2FileOut);
}
}
long count = 0L;
final Bindings bindings = this.script.getEngine().createBindings();
while (r.hasNext()) {
final Record record = new Record(r.next());
record.nLine = count;
if (this.interleaved) {
if (!r.hasNext())
throw new IOException("interleaved: mate missing");
final Record mate = new Record(r.next());
mate.nLine = count;
final Pair pair = new Pair(record, mate);
pair.nLine = count;
bindings.put("pair", pair);
if (!super.evalJavaScriptBoolean(this.script, bindings)) {
failing(pair.get(0));
failing(pair.get(1));
} else {
fastqWriters[0].write(pair.get(0).toFastqRecord());
fastqWriters[1].write(pair.get(1).toFastqRecord());
}
} else {
bindings.put("rec", record);
if (!super.evalJavaScriptBoolean(this.script, bindings)) {
failing(record);
} else {
fastqWriters[0].write(record.toFastqRecord());
}
}
++count;
if (this.LIMIT > 0L && count >= this.LIMIT)
break;
}
openFailing();
} finally {
CloserUtil.close(fastqWriters[0]);
CloserUtil.close(fastqWriters[1]);
}
}
use of htsjdk.samtools.fastq.BasicFastqWriter in project jvarkit by lindenb.
the class FastqShuffle method doWork.
@Override
public int doWork(final List<String> args) {
FastqReader r1 = null;
FastqReader r2 = null;
FastqWriter w = null;
try {
if (fileout == null) {
w = new BasicFastqWriter(stdout());
} else {
w = new BasicFastqWriter(this.fileout);
}
if (args.isEmpty()) {
LOG.info("Reading from stdin");
r1 = new FourLinesFastqReader(stdin());
if (interleaved_input) {
runPaired(r1, null, w);
} else {
runSingle(r1, w);
}
} else if (args.size() == 1) {
r1 = new FourLinesFastqReader(new File(args.get(0)));
if (interleaved_input) {
runPaired(r1, null, w);
} else {
runSingle(r1, w);
}
} else if (args.size() == 2) {
r1 = new FourLinesFastqReader(new File(args.get(0)));
r2 = new FourLinesFastqReader(new File(args.get(1)));
runPaired(r1, r2, w);
} else {
LOG.error("illegal.number.of.arguments");
return -1;
}
return 0;
} catch (final Exception err) {
LOG.error(err);
return -1;
} finally {
CloserUtil.close(r1);
CloserUtil.close(r2);
CloserUtil.close(w);
}
}
Aggregations