Merge our 2 fastq writers into 1: incorporate Kiran's secondary-base file writer into the fasta/fastq writers
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1423 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
843d7e6c8f
commit
4b6ddc55bd
|
|
@ -1,74 +0,0 @@
|
||||||
package org.broadinstitute.sting.playground.gatk.walkers;
|
|
||||||
|
|
||||||
import org.broadinstitute.sting.gatk.walkers.ReadWalker;
|
|
||||||
import org.broadinstitute.sting.utils.cmdLine.Argument;
|
|
||||||
import net.sf.samtools.SAMRecord;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
|
|
||||||
public class SAMToFastqAndSqWalker extends ReadWalker<Integer, Integer> {
|
|
||||||
@Argument(fullName="FASTQFILE", doc="Output path for Fastq file")
|
|
||||||
public File FASTQFILE;
|
|
||||||
|
|
||||||
@Argument(fullName="SQFILE", shortName="SQ", doc="Output path for secondary quality map (readName => SAM SQ field)", required=false)
|
|
||||||
public File SQFILE;
|
|
||||||
|
|
||||||
private PrintWriter fastqbw;
|
|
||||||
private PrintWriter sqbw;
|
|
||||||
|
|
||||||
private boolean ready = false;
|
|
||||||
|
|
||||||
public Integer map(char[] ref, SAMRecord read) {
|
|
||||||
if (!ready) {
|
|
||||||
try {
|
|
||||||
fastqbw = new PrintWriter(FASTQFILE);
|
|
||||||
|
|
||||||
if (SQFILE != null) {
|
|
||||||
sqbw = new PrintWriter(SQFILE);
|
|
||||||
}
|
|
||||||
|
|
||||||
ready = true;
|
|
||||||
} catch (IOException e) {
|
|
||||||
err.println("Unable to open output files.");
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String bases = read.getReadString();
|
|
||||||
String quals = read.getBaseQualityString();
|
|
||||||
byte[] sqs = (byte[]) read.getAttribute("SQ");
|
|
||||||
|
|
||||||
fastqbw.println("@" + read.getReadName());
|
|
||||||
fastqbw.println(bases);
|
|
||||||
|
|
||||||
fastqbw.println("+" + read.getReadName());
|
|
||||||
fastqbw.println(quals);
|
|
||||||
|
|
||||||
if (sqbw != null && sqs != null) {
|
|
||||||
sqbw.print(read.getReadName() + "\t" + "SQ:H:");
|
|
||||||
|
|
||||||
for (byte sq : sqs) {
|
|
||||||
sqbw.printf("%02X", sq);
|
|
||||||
}
|
|
||||||
sqbw.println();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer reduceInit() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer reduce(Integer value, Integer sum) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onTraversalDone(Integer sum) {
|
|
||||||
fastqbw.close();
|
|
||||||
|
|
||||||
if (sqbw != null) {
|
|
||||||
sqbw.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -6,6 +6,8 @@ import org.broadinstitute.sting.utils.BaseUtils;
|
||||||
import org.broadinstitute.sting.utils.cmdLine.Argument;
|
import org.broadinstitute.sting.utils.cmdLine.Argument;
|
||||||
import net.sf.samtools.SAMRecord;
|
import net.sf.samtools.SAMRecord;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
|
||||||
// create a fastq file from a bam file
|
// create a fastq file from a bam file
|
||||||
|
|
||||||
@WalkerName("BamToFastq")
|
@WalkerName("BamToFastq")
|
||||||
|
|
@ -14,6 +16,21 @@ public class BamToFastqWalker extends ReadWalker<Integer, Integer> {
|
||||||
@Argument(fullName="re_reverse", shortName="reverse", doc="re-reverse bases and quals of reads from the negative strand", required=false)
|
@Argument(fullName="re_reverse", shortName="reverse", doc="re-reverse bases and quals of reads from the negative strand", required=false)
|
||||||
private Boolean RE_REVERSE = false;
|
private Boolean RE_REVERSE = false;
|
||||||
|
|
||||||
|
@Argument(fullName="SQFile", shortName="SQ", doc="Output path for secondary quality map (readName => SAM SQ field)", required=false)
|
||||||
|
String SQFile = null;
|
||||||
|
|
||||||
|
private PrintWriter sqbw = null;
|
||||||
|
|
||||||
|
public void initialize() {
|
||||||
|
if ( SQFile != null ) {
|
||||||
|
try {
|
||||||
|
sqbw = new PrintWriter(SQFile);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("Unable to open sq output file: " + SQFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Integer map(char[] ref, SAMRecord read) {
|
public Integer map(char[] ref, SAMRecord read) {
|
||||||
out.println("@" + read.getReadName());
|
out.println("@" + read.getReadName());
|
||||||
if ( !RE_REVERSE || !read.getReadNegativeStrandFlag() ) {
|
if ( !RE_REVERSE || !read.getReadNegativeStrandFlag() ) {
|
||||||
|
|
@ -26,6 +43,17 @@ public class BamToFastqWalker extends ReadWalker<Integer, Integer> {
|
||||||
out.println(BaseUtils.reverse(read.getBaseQualityString()));
|
out.println(BaseUtils.reverse(read.getBaseQualityString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( sqbw != null ) {
|
||||||
|
byte[] sqs = (byte[])read.getAttribute("SQ");
|
||||||
|
if ( sqs != null ) {
|
||||||
|
sqbw.print(read.getReadName() + "\t" + "SQ:H:");
|
||||||
|
for ( byte sq : sqs ) {
|
||||||
|
sqbw.printf("%02X", sq);
|
||||||
|
}
|
||||||
|
sqbw.println();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -38,6 +66,8 @@ public class BamToFastqWalker extends ReadWalker<Integer, Integer> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onTraversalDone(Integer sum) {
|
public void onTraversalDone(Integer sum) {
|
||||||
|
if ( sqbw != null )
|
||||||
|
sqbw.close();
|
||||||
logger.info("Number of reads converted: " + sum);
|
logger.info("Number of reads converted: " + sum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue