use of htsjdk.samtools.fastq.FastqRecord in project jvarkit by lindenb.
the class FourLinesFastqReaderTest method test1.
@Test(dataProvider = "src1")
public void test1(final String input) throws IOException {
final FourLinesFastqReader r = new FourLinesFastqReader(new File(input));
while (r.hasNext()) {
FastqRecord rec = r.next();
Assert.assertNotNull(rec);
}
r.close();
}
use of htsjdk.samtools.fastq.FastqRecord 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 htsjdk.samtools.fastq.FastqRecord 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 htsjdk.samtools.fastq.FastqRecord 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 htsjdk.samtools.fastq.FastqRecord in project jvarkit by lindenb.
the class FastqRecordTreePack method scan.
private void scan(FastqReader iter) {
while (iter.hasNext()) {
final FastqRecord rec = iter.next();
super.bindings.put("record", rec);
super.nodeFactoryChain.watch(rootNode, rec);
}
}
Aggregations