Question: Any tool to output unmapped or mapped_with_clips reads from a BAM to two fastq files for PE data?
2
gravatar for chen
2.4 years ago by
chen1.9k
OpenGene
chen1.9k wrote:

Hi,

I am processing pair-end sequencing data. I want to output the reads that are unmapped to reference genome or mapped with soft/hard clips, to two fastq files (say R1.fq, R2.fq).

Is there any existing tool available to do this? If not, I will have to develop it by myself.

fastq bam unmapped • 971 views
ADD COMMENTlink modified 2.4 years ago by Pierre Lindenbaum125k • written 2.4 years ago by chen1.9k
0
gravatar for Devon Ryan
2.4 years ago by
Devon Ryan93k
Freiburg, Germany
Devon Ryan93k wrote:

Unmapped reads can be found with samtools view -f 4. If you need those with soft/hard clipping then use pysam and parse the cigartuples item.

ADD COMMENTlink written 2.4 years ago by Devon Ryan93k

But this only output the single reads, not the pair.

For pair-end data, if any read of a pair is unmapped or mapped with clips, I'd like to output both reads of this pair.

ADD REPLYlink written 2.4 years ago by chen1.9k

Use -f 5 then. It will give you unmapped but paired reads. You can play around with the flags, using this tool.

ADD REPLYlink written 2.4 years ago by ATpoint28k

You'll need to do two passes, where you make a hash of the read names in the first pass and then output them in the second. You can do that in python with pysam, C with htslib, or java with htsjdk. I would suggest using python, it'll be quicker to write.

ADD REPLYlink written 2.4 years ago by Devon Ryan93k
0
gravatar for Pierre Lindenbaum
2.4 years ago by
France/Nantes/Institut du Thorax - INSERM UMR1087
Pierre Lindenbaum125k wrote:

select unmappeds read or clipped reads with , say samjdk http://lindenb.github.io/jvarkit/SamJdk.html (many other solutions are available, search biostars.org)

java -jar dist/samjdk.jar -o out.bam -e 'return record.getReadUnmappedFlag() || record.getCigar().getCigarElements().stream().anyMatch(C->C.getOperator().isClipping());'  in.bam

then use picard SamToFastq to convert back to fastq

http://broadinstitute.github.io/picard/command-line-overview.html#SamToFastq

ADD COMMENTlink modified 2.4 years ago • written 2.4 years ago by Pierre Lindenbaum125k

I'd like to output both reads of this pair.

more complicated: You need to get the names of the reads after filtering (with samtools view + cut) , and then use http://broadinstitute.github.io/picard/command-line-overview.html#FilterSamReads + READ_LIST_FILE to get the read with the same names.

ADD REPLYlink written 2.4 years ago by Pierre Lindenbaum125k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1558 users visited in the last hour