getting a list of alignment with a particular bam tag from a bam file
2
0
Entering edit mode
3.1 years ago

I have a list of values for a bam tag called XC (say needed.txt). I would like to extract the alignments which have these values from a bam file (say bamfile.bam). I would like to use pysam to do this, but could not figure out from the documentation how to modify the samfile.fetch command for this. Could you help me the modification needed to read in the required list from needed.txt and extract the alignments. Thanks

alignment • 1.2k views
ADD COMMENT
0
Entering edit mode
3.1 years ago

You don't need to modify samfile.fetch(), instead you parse the resulting reads and then use the .get_tag() accessor to check the value of the XC tag.

ADD COMMENT
0
Entering edit mode
3.1 years ago

not pysam.

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

 java -jar dist/samjdk.jar --body \
     -e 'Set<String> xc = null;  public Object apply( SAMRecord R) { if(xc==null) try {xc=new HashSet<>(IOUtil.slurpLines(new java.io.File("needed.txt")));} catch(Exception e) {throw new RuntimeIOException(e);} String att= R.getStringAttribute("XC"); return att!=null && xc.contains(att);}' \
input.bam
ADD COMMENT

Login before adding your answer.

Traffic: 1069 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6