Module Expr Str Import alias Import alias identifier Import alias FunctionDef arguments args NameParam defaults NameLoad body Expr Str If UnaryOpNot NameLoad body Assign NameStore AttributeLoad NameLoad attr Assign NameStore Call AttributeLoad NameLoad attr keyword Str keyword SubscriptLoad Call NameLoad Index Str Expr Call AttributeLoad NameLoad attr Str Str keyword Str keyword Str keyword Str Expr Call AttributeLoad NameLoad attr Str Str keyword Str keyword Str keyword Str keyword Str Expr Call AttributeLoad NameLoad attr Str Str keyword Str keyword Str keyword Str keyword Str Expr Call AttributeLoad NameLoad attr Str Str keyword Str keyword Str keyword Str keyword Str Assign TupleStore NameStore NameStore Call AttributeLoad NameLoad attr NameLoad keyword NameLoad keyword NameLoad If CompareNotEq AttributeLoad NameLoad attr Str body Raise Call NameLoad Str If BoolOpAnd CompareEq AttributeLoad NameLoad attr Str CompareEq AttributeLoad NameLoad attr Str body Raise Call NameLoad Str Assign NameStore Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr Str Assign TupleStore NameStore NameStore NameStore TupleLoad Dict Dict Dict Assign NameStore Num For NameStore Call AttributeLoad NameLoad attr body If AttributeLoad NameLoad attr body Assign NameStore Call NameLoad AttributeLoad NameLoad attr Assign TupleStore NameStore NameStore NameStore TupleLoad NameLoad NameLoad AttributeLoad NameLoad attr If CompareEq SubscriptLoad NameLoad Index Str Str body Assign NameStore NameLoad Assign SubscriptStore NameLoad Index NameLoad Num If CompareIn Str NameLoad body If CompareEq SubscriptLoad NameLoad Index Str Num body Assign NameStore NameLoad Assign SubscriptStore NameLoad Index NameLoad Num If BoolOpOr CompareIs NameLoad NameLoad CompareIs NameLoad NameLoad body Assign SubscriptStore NameLoad Index NameLoad Num AugAssignAdd NameStore Num Expr Call AttributeLoad NameLoad attr Assign NameStore BinOpDiv NameLoad Num Expr Call AttributeLoad NameLoad attr BinOpMod Str NameLoad If CompareNotEq AttributeLoad NameLoad attr Str body Expr Call AttributeLoad NameLoad attr Str FunctionDef arguments args NameParam NameParam defaults NameLoad body Assign TupleStore NameStore NameStore NameLoad Assign NameStore Call NameLoad Call AttributeLoad NameLoad attr Assign NameStore BinOpMult BinOpDiv Call NameLoad NameLoad NameLoad Num Assign NameStore BinOpMod Str TupleLoad NameLoad NameLoad NameLoad Return NameLoad decorator_list Assign NameStore Call AttributeLoad Str attr ListLoad Str Str Str With Call NameLoad AttributeLoad NameLoad attr Str NameStore body Expr Call AttributeLoad NameLoad attr BinOpAdd NameLoad Str For NameStore ListLoad TupleLoad Str NameLoad TupleLoad Str NameLoad TupleLoad Str NameLoad body Expr Call AttributeLoad NameLoad attr BinOpAdd Call NameLoad NameLoad Str If CompareNotEq AttributeLoad NameLoad attr Str body Expr Call AttributeLoad NameLoad attr BinOpMod Str AttributeLoad NameLoad attr Assign NameStore Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr Str Assign NameStore Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr Str keyword NameLoad For NameStore Call AttributeLoad NameLoad attr body If AttributeLoad NameLoad attr body If CompareIn AttributeLoad NameLoad attr NameLoad body Expr Call AttributeLoad NameLoad attr NameLoad Expr Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr decorator_list If CompareEq NameLoad Str body Expr Call AttributeLoad NameLoad attr Call NameLoad AttributeLoad NameLoad attr
N/A N/A bam2UniquePairs.py - filter/report uniquely mapped read pairs from a (bwa!) bam-file
======================================================================================

:Author: Steve Sansom
:Release: $Id$
:Date: |today|
:Tags: Genomics NGS

Purpose
-------

Utility script to report and/or filter out "uniquely mapped" properly
paired reads

Reports:

1. The percentage of properly mapped read pairs with at least one
   uniquely mapped (XT=U) read

2. The percentage of properly mapped read pairs with at least one best
   mapped (X0-1) read

3. The percentage of properly mapped read pairs with at least one
   uniquely or best mapped (X0-1) read

If outfile is specified, reads are emitted when they are properly
paired and the pair has at least one read that is either best or
uniquely mapped.

Duplication is ignored.

Only BWA is supported.

TODO: cache and emit reads rather than iterating over the samfile twice...

 N/A sys N/A CGAT.Experiment E N/A pysam main N/A N/A argv N/A None N/A N/A script main.

    parses command line options in sys.argv, unless *argv* is given.
     N/A N/A argv N/A N/A argv N/A sys argv N/A parser N/A N/A E OptionParser version %prog version: $Id: cgat_script_template.py 2871 2010-03-03 10:20:44Z andreas $ usage N/A N/A globals N/A __doc__ N/A N/A N/A parser add_option -f --filename dest filename type string help bamfile N/A N/A N/A parser add_option -a --aligner dest aligner type string help bamfile default bwa N/A N/A N/A parser add_option -r --output-report type string dest report help bamfile default N/A N/A N/A parser add_option -o --outfile dest outfile type string help bamfile default N/A N/A options args N/A N/A E Start parser argv argv add_output_options True N/A N/A N/A options aligner bwa N/A N/A N/A ValueError Currently only bwa is supported as aligner specific flags are used N/A N/A N/A N/A options report N/A N/A options outfile N/A N/A N/A ValueError Nothing to do N/A samfile N/A N/A pysam Samfile N/A options filename rb N/A N/A uniq_map best_map uORb_map N/A N/A N/A N/A N/A properly_paired 0 N/A read N/A N/A samfile fetch N/A N/A N/A read is_proper_pair N/A N/A tagd N/A dict N/A read tags N/A N/A u b key N/A False False N/A read qname N/A N/A N/A tagd N/A XT U N/A N/A u True N/A N/A uniq_map N/A key 1 N/A N/A X0 tagd N/A N/A N/A N/A tagd N/A X0 1 N/A N/A b True N/A N/A best_map N/A key 1 N/A N/A N/A u True N/A b True N/A N/A N/A uORb_map N/A key 1 N/A properly_paired 1 N/A N/A N/A samfile close N/A npp N/A properly_paired 2 N/A N/A N/A E info N/A No proper pairs: %s npp N/A N/A N/A options report N/A N/A N/A N/A E info Writing report on no. proper pairs with unique/best reads _row N/A N/A x npp N/A npp N/A N/A N/A name d x N/A n N/A len N/A N/A d keys N/A pc N/A N/A N/A float n npp 100 N/A line N/A %s	%i	%.2f N/A name n pc N/A line N/A N/A header N/A N/A join N/A pair_criteria n_proper_pairs percent_proper_pairs N/A N/A open N/A options report w report N/A N/A N/A N/A report write N/A header N/A x N/A N/A unique uniq_map N/A best best_map N/A unique_or_best uORb_map N/A N/A N/A N/A report write N/A N/A _row x N/A N/A N/A options outfile N/A N/A N/A N/A E info N/A Writing proper pairs with unique or best read to %s N/A options outfile N/A samfile N/A N/A pysam Samfile N/A options filename rb N/A outbam N/A N/A pysam Samfile N/A options outfile wb template samfile N/A read N/A N/A samfile fetch N/A N/A N/A read is_proper_pair N/A N/A N/A N/A read qname uORb_map N/A N/A N/A N/A outbam write read N/A N/A N/A samfile close N/A N/A N/A outbam close N/A N/A N/A __name__ __main__ N/A N/A N/A N/A sys exit N/A main N/A sys argv