This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to get ungapped single-end reads from the STAR output bam file?

Hello,

After mapping with STAR, I would like to remove all reads (single-end) from my Bam file, which show a gap in their alignment. Can this be done with samtools somehow?

rna-seq star ungapped single-end

Are deletions OK or do you want them filtered too?

I would like to remove deletions as well

GAP = single nucleotide variation + indels ?

I mean the remaining reads should be only continiously mapped to the reference genome, without a gap in their alignment, through splicing or deletions. The occurrence of SNPs was allowed during mapping and should be disregarded at this step.

Edit: Sry, with gap, I meant a splice junction in the reads alignment

1 answer

using samjdk: http://lindenb.github.io/jvarkit/SamJdk.html

$ java -jar dist/samjdk.jar -e 'return !record.getReadUnmappedFlag() && record.getCigar()!=null && record.getCigar().getCigarElements().stream().map(C->C.getOperator()).noneMatch(OP->OP.equals(CigarOperator.N) || OP.equals(CigarOperator.D));'  in.bam
  • !record.getReadUnmappedFlag() read must be mapped
  • record.getCigar()!=null read has cigar
  • record.getCigar().getCigarElements().stream(). get a stream of cigar componenets
  • map(C->C.getOperator()) map to the cigar operator
  • noneMatch(OP->OP.equals(CigarOperator.N) || OP.equals(CigarOperator.D)); no operator can be 'N' or 'D'

Thank you very much! This is a very interesting tool and it seems to work.

Edit: It definitly worked right away

Log in to answer this question.