use of com.github.lindenb.jvarkit.util.picard.FourLinesFastqReader in project jvarkit by lindenb.
the class FastQName method countReads.
public long countReads() throws IOException {
if (nReads == null) {
long n = 0L;
FastqReader r = null;
try {
r = new FourLinesFastqReader(this.getFile());
r.setValidationStringency(ValidationStringency.LENIENT);
while (r.hasNext()) {
r.next();
++n;
}
} catch (Exception err) {
nReads = -1L;
throw new IOException(err);
} finally {
if (r != null)
r.close();
}
nReads = n;
}
return nReads;
}
use of com.github.lindenb.jvarkit.util.picard.FourLinesFastqReader in project jvarkit by lindenb.
the class FastqSplitInterleaved method doWork.
@Override
public int doWork(final List<String> args) {
final String[] fileout = { this.fileA, this.fileB };
FastqReader r1 = null;
FastqWriter[] writers = { null, null };
try {
if (args.isEmpty()) {
r1 = new FourLinesFastqReader(stdin());
} else if (args.size() == 1) {
r1 = new FourLinesFastqReader(new File(args.get(0)));
} else {
LOG.error("illegal.number.of.arguments");
return -1;
}
if (fileout[0] == null && fileout[1] == null) {
LOG.error("Both outputs are undefined.");
return -1;
}
for (int i = 0; i < 2; ++i) {
if (fileout[i] == null) {
writers[i] = new BasicFastqWriter(new PrintStream(new NullOuputStream()));
} else if (fileout[i].equals("-")) {
if (i == 1 && "-".equals(fileout[0])) {
writers[i] = writers[0];
} else {
writers[i] = new BasicFastqWriter(System.out);
}
} else {
if (i == 1 && fileout[1].equals(fileout[0])) {
writers[i] = writers[0];
} else {
writers[i] = new BasicFastqWriter(new File(fileout[i]));
}
}
}
FastqRecord[] records = { null, null };
while (r1.hasNext()) {
records[0] = r1.next();
if (!r1.hasNext()) {
r1.close();
r1 = null;
throw new IOException("fastq.paired.read.missing");
}
records[1] = r1.next();
for (int i = 0; i < 2; ++i) {
writers[i].write(records[i]);
}
}
if (r1.hasNext()) {
throw new IOException("Illegal number of reads in fastq");
}
return 0;
} catch (Exception err) {
LOG.error(err);
return -1;
} finally {
CloserUtil.close(r1);
CloserUtil.close(writers[0]);
CloserUtil.close(writers[1]);
}
}
use of com.github.lindenb.jvarkit.util.picard.FourLinesFastqReader in project jvarkit by lindenb.
the class ConvertPhred64toFastq33 method convert.
private void convert(InputStream in) throws IOException {
FastqReader r = new FourLinesFastqReader(in);
while (r.hasNext() && !pw.checkError()) {
final FastqRecord rec = r.next();
byte[] quals = rec.getBaseQualityString().getBytes();
for (int i = 0; i < quals.length; ++i) {
quals[i] = (byte) (quals[i] - 64 + 33);
if (quals[i] < 33 || quals[i] > 126) {
r.close();
throw new IOException("q=" + (int) quals[i]);
}
}
String name = rec.getReadName();
int diez = name.indexOf('#');
if (diez != -1)
name = name.substring(0, diez);
pw.print(FastqConstants.SEQUENCE_HEADER);
pw.println(name);
pw.println(rec.getReadString());
pw.print(FastqConstants.QUALITY_HEADER);
pw.println(rec.getBaseQualityHeader() == null || rec.getReadName().equals(rec.getBaseQualityHeader()) ? "" : rec.getBaseQualityHeader());
pw.println(new String(quals));
}
r.close();
}
use of com.github.lindenb.jvarkit.util.picard.FourLinesFastqReader in project jvarkit by lindenb.
the class FastqEntropy method convert.
private void convert(InputStream in) throws IOException {
FastqReader r = new FourLinesFastqReader(in);
while (r.hasNext()) {
FastqRecord rec = r.next();
BestCompressionOutputStream gzout = new BestCompressionOutputStream();
gzout.write(rec.getBaseQualityString().getBytes());
gzout.flush();
gzout.close();
this.length2count.incr(gzout.getByteWrittenCount());
}
r.close();
}
use of com.github.lindenb.jvarkit.util.picard.FourLinesFastqReader in project jvarkit by lindenb.
the class FastqRecordTreePack method doWork.
@Override
public int doWork(List<String> args) {
setDimension(this.dimensionStr);
FastqReader fqr = null;
try {
parseConfigFile();
if (super.nodeFactoryChain.next == null) {
LOG.error("no path defined");
return -1;
}
if (args.isEmpty()) {
LOG.info("Reading stdin");
fqr = new FourLinesFastqReader(stdin());
scan(fqr);
CloserUtil.close(fqr);
LOG.info("Done stdin");
} else {
for (final String filename : args) {
InputStream in = null;
LOG.info("Reading " + filename);
if (IOUtils.isRemoteURI(filename)) {
in = IOUtils.openURIForReading(filename);
fqr = new FourLinesFastqReader(in);
} else {
fqr = new FourLinesFastqReader(new File(filename));
}
scan(fqr);
LOG.info("Done " + filename);
CloserUtil.close(fqr);
CloserUtil.close(in);
}
}
this.layout();
this.svg(this.outputFile);
return RETURN_OK;
} catch (Exception e) {
LOG.error(e);
return -1;
} finally {
CloserUtil.close(fqr);
}
}
Aggregations