<s> """<STR_LIT>""" <EOL> import os <EOL> import sys <EOL> import logging <EOL> from Bio . Sequencing import Ace <EOL> from Bio import SeqIO <EOL> from Bio . Seq import Seq <EOL> from Bio . SeqRecord import SeqRecord <EOL> from jcvi . apps . base import OptionParser , ActionDispatcher <EOL> from jcvi . formats . base import must_open <EOL> def main ( ) : <EOL> actions = ( <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ) <EOL> p = ActionDispatcher ( actions ) <EOL> p . dispatch ( globals ( ) ) <EOL> def extract ( args ) : <EOL> """<STR_LIT>""" <EOL> p = OptionParser ( extract . __doc__ ) <EOL> p . add_option ( "<STR_LIT>" , default = False , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" + "<STR_LIT>" ) <EOL> p . add_option ( "<STR_LIT>" , default = False , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" + "<STR_LIT>" ) <EOL> p . set_sep ( sep = "<STR_LIT:|>" , help = "<STR_LIT>" ) <EOL> opts , args = p . parse_args ( args ) <EOL> if len ( args ) != <NUM_LIT:1> : <EOL> sys . exit ( not p . print_help ( ) ) <EOL> acefile , = args <EOL> ace = Ace . read ( must_open ( acefile ) ) <EOL> logging . debug ( '<STR_LIT>' . format ( acefile ) ) <EOL> fastafile = acefile . rsplit ( "<STR_LIT:.>" , <NUM_LIT:1> ) [ <NUM_LIT:0> ] + "<STR_LIT>" <EOL> fw = open ( fastafile , "<STR_LIT:w>" ) <EOL> for c in ace . contigs : <EOL> id = c . name <EOL> if opts . format : <EOL> id = opts . sep . join ( [ read . name for read in c . af ] ) <EOL> seqrec = SeqRecord ( Seq ( c . sequence ) , id = id , description = "<STR_LIT>" ) <EOL> SeqIO . write ( [ seqrec ] , fw , "<STR_LIT>" ) <EOL> if opts . singlets : <EOL> singletsfile = acefile . rsplit ( "<STR_LIT:.>" , <NUM_LIT:1> ) [ <NUM_LIT:0> ] + "<STR_LIT>" <EOL> if os . path . getsize ( singletsfile ) > <NUM_LIT:0> : <EOL> fp = SeqIO . parse ( must_open ( singletsfile ) , "<STR_LIT>" ) <EOL> for rec in fp : <EOL> SeqIO . write ( rec , fw , "<STR_LIT>" ) <EOL> fw . close ( ) <EOL> logging . debug ( '<STR_LIT>' . format ( fastafile ) ) <EOL> def report ( args ) : <EOL> """<STR_LIT>""" <EOL> from jcvi . utils . table import tabulate <EOL> p = OptionParser ( report . __doc__ ) <EOL> types = { "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> } <EOL> valid_types = tuple ( types . keys ( ) ) <EOL> p . add_option ( "<STR_LIT>" , default = "<STR_LIT>" , choices = valid_types , <EOL> help = "<STR_LIT>" ) <EOL> opts , args = p . parse_args ( args ) <EOL> if len ( args ) != <NUM_LIT:1> : <EOL> sys . exit ( not p . print_help ( ) ) <EOL> acefile , = args <EOL> ace = Ace . read ( must_open ( acefile ) ) <EOL> logging . debug ( '<STR_LIT>' . format ( acefile ) ) <EOL> for c in ace . contigs : <EOL> print c . name <EOL> table = dict ( ) <EOL> if opts . type == "<STR_LIT>" : <EOL> ps , pe = [ ] , [ ] <EOL> ps = [ read . padded_start for read in c . af ] <EOL> for i in xrange ( <NUM_LIT:1> , len ( ps ) ) : <EOL> pe . append ( ps [ i ] - ps [ i - <NUM_LIT:1> ] ) <EOL> pe . append ( c . nbases ) <EOL> map = dict ( zip ( ps , pe ) ) <EOL> for i , read in enumerate ( c . af ) : <EOL> values = [ str ( x ) for x in ( read . padded_start , map [ read . padded_start ] , read . coru ) ] <EOL> for i , label in enumerate ( types [ opts . type ] ) : <EOL> table [ ( str ( read . name ) , label ) ] = values [ i ] <EOL> elif opts . type == "<STR_LIT>" : <EOL> for read in c . bs : <EOL> values = [ str ( x ) for x in ( read . padded_start , read . padded_end ) ] <EOL> for i , label in enumerate ( types [ opts . type ] ) : <EOL> table [ ( str ( read . name ) , label ) ] = values [ i ] <EOL> elif opts . type == "<STR_LIT>" : <EOL> for read in c . reads : <EOL> ( r1 , r2 ) = ( read . rd , read . qa ) <EOL> values = [ str ( x ) for x in ( r2 . qual_clipping_start , r2 . qual_clipping_end , r2 . align_clipping_start , r2 . align_clipping_end ) ] <EOL> for i , label in enumerate ( types [ opts . type ] ) : <EOL> table [ ( str ( r1 . name ) , label ) ] = values [ i ] <EOL> print tabulate ( table ) , "<STR_LIT:\n>" <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
