<s> import pysam <EOL> import sys <EOL> from re import sub <EOL> if len ( sys . argv ) == <NUM_LIT:2> : <EOL> assert sys . argv [ <NUM_LIT:1> ] . endswith ( '<STR_LIT>' ) <EOL> outname = sub ( '<STR_LIT>' , '<STR_LIT>' , sys . argv [ <NUM_LIT:1> ] ) <EOL> print "<STR_LIT>" , outname <EOL> inbam = pysam . Samfile ( sys . argv [ <NUM_LIT:1> ] , '<STR_LIT:rb>' ) <EOL> outbam = pysam . Samfile ( outname , '<STR_LIT:wb>' , template = inbam ) <EOL> reads = { } <EOL> for read in inbam . fetch ( until_eof = True ) : <EOL> if read . qname in reads : <EOL> reads [ read . qname ] . append ( read ) <EOL> else : <EOL> reads [ read . qname ] = [ ] <EOL> reads [ read . qname ] . append ( read ) <EOL> if len ( reads [ read . qname ] ) == <NUM_LIT:2> : <EOL> for outread in reads [ read . qname ] : <EOL> outbam . write ( outread ) <EOL> del reads [ read . qname ] <EOL> inbam . close ( ) <EOL> outbam . close ( ) <EOL> else : <EOL> print "<STR_LIT>" , sys . argv [ <NUM_LIT:0> ] , "<STR_LIT>" </s>
