<s> """<STR_LIT>""" <EOL> import cPickle <EOL> import os <EOL> import os . path as op <EOL> import logging <EOL> import sys <EOL> from jcvi . formats . fasta import Fasta , SeqIO <EOL> from jcvi . formats . fastq import iter_fastq <EOL> from jcvi . formats . base import must_open , write_file <EOL> from jcvi . formats . sam import get_prefix <EOL> from jcvi . utils . counter import Counter <EOL> from jcvi . apps . cdhit import deduplicate <EOL> from jcvi . apps . gmap import check_index <EOL> from jcvi . apps . grid import MakeManager <EOL> from jcvi . graphics . base import plt , savefig , normalize_axes <EOL> from jcvi . apps . base import OptionParser , ActionDispatcher , need_update , sh , iglob , mkdir <EOL> speedupsh = r"""<STR_LIT>""" <EOL> def main ( ) : <EOL> actions = ( <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:count>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ) <EOL> p = ActionDispatcher ( actions ) <EOL> p . dispatch ( globals ( ) ) <EOL> def build_index ( locifile ) : <EOL> idxfile = locifile + "<STR_LIT>" <EOL> if need_update ( locifile , idxfile ) : <EOL> fp = open ( locifile ) <EOL> fw = open ( idxfile , "<STR_LIT:w>" ) <EOL> idx = { } <EOL> while True : <EOL> pos = fp . tell ( ) <EOL> line = fp . readline ( ) <EOL> if not line : <EOL> break <EOL> if not line . startswith ( "<STR_LIT>" ) : <EOL> continue <EOL> tag , contig = line . split ( ) [ : <NUM_LIT:2> ] <EOL> idx [ contig ] = pos <EOL> cPickle . dump ( idx , fw ) <EOL> fw . close ( ) <EOL> return idx <EOL> idx = cPickle . load ( open ( idxfile ) ) <EOL> return idx <EOL> def query ( args ) : <EOL> """<STR_LIT>""" <EOL> p = OptionParser ( query . __doc__ ) <EOL> opts , args = p . parse_args ( args ) <EOL> if len ( args ) != <NUM_LIT:2> : <EOL> sys . exit ( not p . print_help ( ) ) <EOL> locifile , contig = args <EOL> idx = build_index ( locifile ) <EOL> pos = idx [ contig ] <EOL> logging . debug ( "<STR_LIT>" . format ( contig , pos ) ) <EOL> fp = open ( locifile ) <EOL> fp . seek ( pos ) <EOL> section = [ ] <EOL> while True : <EOL> row = fp . readline ( ) <EOL> if row . startswith ( "<STR_LIT>" ) and row . split ( ) [ <NUM_LIT:1> ] != contig : <EOL> break <EOL> section . append ( row ) <EOL> print "<STR_LIT>" . join ( section ) <EOL> def synteny ( args ) : <EOL> """<STR_LIT>""" <EOL> from jcvi . assembly . geneticmap import bed as geneticmap_bed <EOL> from jcvi . apps . align import blat <EOL> from jcvi . formats . blast import bed as blast_bed , best <EOL> p = OptionParser ( synteny . __doc__ ) <EOL> opts , args = p . parse_args ( args ) <EOL> if len ( args ) != <NUM_LIT:3> : <EOL> sys . exit ( not p . print_help ( ) ) <EOL> mstmapout , novo , ref = args <EOL> pf = mstmapout . split ( "<STR_LIT:.>" ) [ <NUM_LIT:0> ] <EOL> rf = ref . split ( "<STR_LIT:.>" ) [ <NUM_LIT:0> ] <EOL> mstmapbed = geneticmap_bed ( [ mstmapout ] ) <EOL> cmd = "<STR_LIT>" . format ( mstmapbed ) <EOL> tmpbed = mstmapbed + "<STR_LIT>" <EOL> sh ( cmd , outfile = tmpbed ) <EOL> os . rename ( tmpbed , pf + "<STR_LIT>" ) <EOL> cmd = "<STR_LIT>" . format ( mstmapbed ) <EOL> idsfile = pf + "<STR_LIT>" <EOL> sh ( cmd , outfile = idsfile ) <EOL> fastafile = pf + "<STR_LIT>" <EOL> cmd = "<STR_LIT>" . format ( novo , idsfile , fastafile ) <EOL> sh ( cmd ) <EOL> blastfile = blat ( [ ref , fastafile ] ) <EOL> bestblastfile = best ( [ blastfile ] ) <EOL> blastbed = blast_bed ( [ bestblastfile ] ) <EOL> os . rename ( blastbed , rf + "<STR_LIT>" ) <EOL> anchorsfile = "<STR_LIT>" . format ( pf , rf ) <EOL> cmd = "<STR_LIT>" . format ( idsfile ) <EOL> sh ( cmd , outfile = anchorsfile ) <EOL> def mstmap ( args ) : <EOL> """<STR_LIT>""" <EOL> from jcvi . assembly . geneticmap import MSTMatrix <EOL> p = OptionParser ( mstmap . __doc__ ) <EOL> p . add_option ( "<STR_LIT>" , default = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> p . add_option ( "<STR_LIT>" , default = <NUM_LIT> , <EOL> help = "<STR_LIT>" ) <EOL> p . set_outfile ( ) <EOL> opts , args = p . parse_args ( args ) <EOL> if len ( args ) != <NUM_LIT:1> : <EOL> sys . exit ( not p . print_help ( ) ) <EOL> lmd , = args <EOL> fp = open ( lmd ) <EOL> fp . next ( ) <EOL> table = { "<STR_LIT:0>" : "<STR_LIT:->" , "<STR_LIT:1>" : "<STR_LIT:A>" , "<STR_LIT:2>" : "<STR_LIT:B>" , "<STR_LIT:3>" : "<STR_LIT:X>" } <EOL> mh = [ "<STR_LIT>" ] + fp . next ( ) . split ( ) [ <NUM_LIT:4> : ] <EOL> genotypes = [ ] <EOL> for row in fp : <EOL> atoms = row . split ( ) <EOL> chr , pos , ref , alt = atoms [ : <NUM_LIT:4> ] <EOL> locus_name = "<STR_LIT:.>" . join ( ( chr , pos ) ) <EOL> codes = [ table [ x ] for x in atoms [ <NUM_LIT:4> : ] ] <EOL> genotypes . append ( [ locus_name ] + codes ) <EOL> mm = MSTMatrix ( genotypes , mh , opts . population_type , opts . missing_threshold ) <EOL> mm . write ( opts . outfile , header = True ) <EOL> def weblogo ( args ) : <EOL> """<STR_LIT>""" <EOL> import numpy as np <EOL> from jcvi . utils . progressbar import ProgressBar , Percentage , Bar , ETA <EOL> p = OptionParser ( weblogo . __doc__ ) <EOL> p . add_option ( "<STR_LIT>" , default = <NUM_LIT:10> , type = "<STR_LIT:int>" , <EOL> help = "<STR_LIT>" ) <EOL> p . add_option ( "<STR_LIT>" , default = <NUM_LIT> , type = "<STR_LIT:int>" , <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> fastqfile , = args <EOL> N = opts . N <EOL> nreads = opts . nreads <EOL> pat = "<STR_LIT>" <EOL> L = np . zeros ( ( <NUM_LIT:4> , N ) , dtype = "<STR_LIT>" ) <EOL> R = np . zeros ( ( <NUM_LIT:4> , N ) , dtype = "<STR_LIT>" ) <EOL> p = dict ( ( a , i ) for ( i , a ) in enumerate ( pat ) ) <EOL> L4 , R3 = Counter ( ) , Counter ( ) <EOL> widgets = [ '<STR_LIT>' , Percentage ( ) , '<STR_LIT:U+0020>' , <EOL> Bar ( marker = '<STR_LIT:>>' , left = '<STR_LIT:[>' , right = '<STR_LIT:]>' ) , '<STR_LIT:U+0020>' , ETA ( ) ] <EOL> pr = ProgressBar ( maxval = nreads , term_width = <NUM_LIT> , widgets = widgets ) . start ( ) <EOL> k = <NUM_LIT:0> <EOL> fw_L = open ( "<STR_LIT>" , "<STR_LIT:w>" ) <EOL> fw_R = open ( "<STR_LIT>" , "<STR_LIT:w>" ) <EOL> fastq = fastqfile . endswith ( "<STR_LIT>" ) <EOL> it = iter_fastq ( fastqfile ) if fastq else SeqIO . parse ( must_open ( fastqfile ) , "<STR_LIT>" ) <EOL> for rec in it : <EOL> k += <NUM_LIT:1> <EOL> if k % <NUM_LIT:1000> == <NUM_LIT:0> : <EOL> pr . update ( k ) <EOL> if k > nreads : <EOL> break <EOL> if rec is None : <EOL> break <EOL> s = str ( rec . seq ) <EOL> for i , a in enumerate ( s [ : N ] ) : <EOL> if a in p : <EOL> a = p [ a ] <EOL> L [ a ] [ i ] += <NUM_LIT:1> <EOL> for j , a in enumerate ( s [ - N : ] [ : : - <NUM_LIT:1> ] ) : <EOL> if a in p : <EOL> a = p [ a ] <EOL> R [ a ] [ N - <NUM_LIT:1> - j ] += <NUM_LIT:1> <EOL> l4 , r3 = s [ : <NUM_LIT:4> ] , s [ - <NUM_LIT:3> : ] <EOL> L4 [ l4 ] += <NUM_LIT:1> <EOL> R3 [ r3 ] += <NUM_LIT:1> <EOL> print >> fw_L , "<STR_LIT>" . format ( k , s [ : N ] ) <EOL> print >> fw_R , "<STR_LIT>" . format ( k , s [ - N : ] ) <EOL> fw_L . close ( ) <EOL> fw_R . close ( ) <EOL> cmd = "<STR_LIT>" <EOL> cmd += "<STR_LIT>" <EOL> cmd += "<STR_LIT>" <EOL> sh ( cmd . format ( '<STR_LIT:L>' , "<STR_LIT>" ) ) <EOL> sh ( cmd . format ( '<STR_LIT:R>' , "<STR_LIT>" ) ) <EOL> np . savetxt ( "<STR_LIT>" . format ( pat ) , L , delimiter = '<STR_LIT:U+002C>' , fmt = "<STR_LIT>" ) <EOL> np . savetxt ( "<STR_LIT>" . format ( pat ) , R , delimiter = '<STR_LIT:U+002C>' , fmt = "<STR_LIT>" ) <EOL> fw = open ( "<STR_LIT>" , "<STR_LIT:w>" ) <EOL> for p , c in L4 . most_common ( N ) : <EOL> print >> fw , "<STR_LIT:\t>" . join ( ( p , str ( c ) ) ) <EOL> fw . close ( ) <EOL> fw = open ( "<STR_LIT>" , "<STR_LIT:w>" ) <EOL> for p , c in R3 . most_common ( N ) : <EOL> print >> fw , "<STR_LIT:\t>" . join ( ( p , str ( c ) ) ) <EOL> fw . close ( ) <EOL> def count ( args ) : <EOL> """<STR_LIT>""" <EOL> from jcvi . graphics . histogram import stem_leaf_plot <EOL> from jcvi . utils . cbook import SummaryStats <EOL> p = OptionParser ( count . __doc__ ) <EOL> p . add_option ( "<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> fastafile , = args <EOL> csv = open ( opts . csv , "<STR_LIT:w>" ) if opts . csv else None <EOL> f = Fasta ( fastafile , lazy = True ) <EOL> sizes = [ ] <EOL> for desc , rec in f . iterdescriptions_ordered ( ) : <EOL> if desc . startswith ( "<STR_LIT>" ) : <EOL> sizes . append ( <NUM_LIT:1> ) <EOL> continue <EOL> if "<STR_LIT>" in desc : <EOL> name , w , size , seqs = desc . split ( ) <EOL> if csv : <EOL> print >> csv , "<STR_LIT:\t>" . join ( str ( x ) for x in ( name , size , len ( rec ) ) ) <EOL> assert w == "<STR_LIT>" <EOL> sizes . append ( int ( size ) ) <EOL> else : <EOL> name , size , tail = desc . split ( "<STR_LIT:;>" ) <EOL> sizes . append ( int ( size . replace ( "<STR_LIT>" , "<STR_LIT>" ) ) ) <EOL> if csv : <EOL> csv . close ( ) <EOL> logging . debug ( "<STR_LIT>" . format ( opts . csv ) ) <EOL> s = SummaryStats ( sizes ) <EOL> print >> sys . stderr , s <EOL> stem_leaf_plot ( s . data , <NUM_LIT:0> , <NUM_LIT:100> , <NUM_LIT:20> , title = "<STR_LIT>" ) <EOL> def novo ( args ) : <EOL> """<STR_LIT>""" <EOL> from jcvi . assembly . kmer import jellyfish , histogram <EOL> from jcvi . assembly . preprocess import diginorm <EOL> from jcvi . formats . fasta import filter as fasta_filter , format <EOL> from jcvi . apps . cdhit import filter as cdhit_filter <EOL> p = OptionParser ( novo . __doc__ ) <EOL> p . add_option ( "<STR_LIT>" , choices = ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> default = "<STR_LIT>" , help = "<STR_LIT>" ) <EOL> p . set_depth ( depth = <NUM_LIT:50> ) <EOL> p . set_align ( pctid = <NUM_LIT> ) <EOL> p . set_home ( "<STR_LIT>" , default = "<STR_LIT>" ) <EOL> p . set_home ( "<STR_LIT>" , default = "<STR_LIT>" ) <EOL> p . set_home ( "<STR_LIT>" , default = "<STR_LIT>" ) <EOL> p . set_cpus ( ) <EOL> opts , args = p . parse_args ( args ) <EOL> if len ( args ) != <NUM_LIT:1> : <EOL> sys . exit ( not p . print_help ( ) ) <EOL> fastqfile , = args <EOL> cpus = opts . cpus <EOL> depth = opts . depth <EOL> pf , sf = fastqfile . rsplit ( "<STR_LIT:.>" , <NUM_LIT:1> ) <EOL> diginormfile = pf + "<STR_LIT>" + sf <EOL> if need_update ( fastqfile , diginormfile ) : <EOL> diginorm ( [ fastqfile , "<STR_LIT>" , "<STR_LIT>" . format ( depth ) ] ) <EOL> keepabund = fastqfile + "<STR_LIT>" <EOL> sh ( "<STR_LIT>" . format ( keepabund , diginormfile ) ) <EOL> jf = pf + "<STR_LIT>" <EOL> if need_update ( diginormfile , jf ) : <EOL> jellyfish ( [ diginormfile , "<STR_LIT>" . format ( pf ) , <EOL> "<STR_LIT>" . format ( cpus ) , <EOL> "<STR_LIT>" . format ( opts . jellyfish_home ) ] ) <EOL> genomesize = histogram ( [ jf , pf , "<STR_LIT>" ] ) <EOL> fiona = pf + "<STR_LIT>" <EOL> if need_update ( diginormfile , fiona ) : <EOL> cmd = op . join ( opts . fiona_home , "<STR_LIT>" ) <EOL> cmd += "<STR_LIT>" . format ( genomesize , cpus , opts . technology ) <EOL> cmd += "<STR_LIT>" . format ( diginormfile , fiona ) <EOL> logfile = pf + "<STR_LIT>" <EOL> sh ( cmd , outfile = logfile , errfile = logfile ) <EOL> dedup = "<STR_LIT>" <EOL> pctid = opts . pctid <EOL> cons = fiona + "<STR_LIT>" . format ( pctid , dedup ) <EOL> if need_update ( fiona , cons ) : <EOL> deduplicate ( [ fiona , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" . format ( pctid ) , <EOL> "<STR_LIT>" . format ( opts . cdhit_home ) ] ) <EOL> filteredfile = pf + "<STR_LIT>" <EOL> if need_update ( cons , filteredfile ) : <EOL> covfile = pf + "<STR_LIT>" <EOL> cdhit_filter ( [ cons , "<STR_LIT>" . format ( covfile ) , <EOL> "<STR_LIT>" . format ( depth / <NUM_LIT:5> ) ] ) <EOL> fasta_filter ( [ covfile , "<STR_LIT>" , "<STR_LIT>" . format ( filteredfile ) ] ) <EOL> finalfile = pf + "<STR_LIT>" <EOL> if need_update ( filteredfile , finalfile ) : <EOL> format ( [ filteredfile , finalfile , "<STR_LIT>" , <EOL> "<STR_LIT>" . format ( pf ) ] ) <EOL> def scan_read_files ( trimmed , patterns ) : <EOL> reads = iglob ( trimmed , patterns ) <EOL> samples = sorted ( set ( op . basename ( x ) . split ( "<STR_LIT:.>" ) [ <NUM_LIT:0> ] for x in reads ) ) <EOL> logging . debug ( "<STR_LIT>" . format ( len ( reads ) , len ( samples ) ) ) <EOL> return reads , samples <EOL> def novo2 ( args ) : <EOL> """<STR_LIT>""" <EOL> p = OptionParser ( novo2 . __doc__ ) <EOL> p . set_fastq_names ( ) <EOL> p . set_align ( pctid = <NUM_LIT> ) <EOL> opts , args = p . parse_args ( args ) <EOL> if len ( args ) != <NUM_LIT:2> : <EOL> sys . exit ( not p . print_help ( ) ) <EOL> trimmed , pf = args <EOL> pctid = opts . pctid <EOL> reads , samples = scan_read_files ( trimmed , opts . names ) <EOL> clustdir = "<STR_LIT>" <EOL> acdir = "<STR_LIT>" <EOL> for d in ( clustdir , acdir ) : <EOL> mkdir ( d ) <EOL> mm = MakeManager ( ) <EOL> clustfiles = [ ] <EOL> for s in samples : <EOL> flist = [ x for x in reads if op . basename ( x ) . split ( "<STR_LIT:.>" ) [ <NUM_LIT:0> ] == s ] <EOL> outfile = s + "<STR_LIT>" . format ( pctid ) <EOL> outfile = op . join ( clustdir , outfile ) <EOL> cmd = "<STR_LIT>" <EOL> cmd += "<STR_LIT>" . format ( s , "<STR_LIT:U+0020>" . join ( flist ) ) <EOL> cmd += "<STR_LIT>" . format ( clustdir ) <EOL> cmd += "<STR_LIT>" . format ( pctid ) <EOL> mm . add ( flist , outfile , cmd ) <EOL> clustfiles . append ( outfile ) <EOL> allcons = [ ] <EOL> for s , clustfile in zip ( samples , clustfiles ) : <EOL> outfile = s + "<STR_LIT>" . format ( pctid ) <EOL> outfile = op . join ( clustdir , outfile ) <EOL> cmd = "<STR_LIT>" <EOL> cmd += "<STR_LIT>" . format ( clustfile ) <EOL> mm . add ( clustfile , outfile , cmd ) <EOL> allcons . append ( outfile ) <EOL> clustSfile = pf + "<STR_LIT>" . format ( pctid ) <EOL> cmd = "<STR_LIT>" . format ( "<STR_LIT:U+0020>" . join ( allcons ) ) <EOL> cmd += "<STR_LIT>" . format ( pf ) <EOL> mm . add ( allcons , clustSfile , cmd ) <EOL> locifile = pf + "<STR_LIT>" . format ( pctid ) <EOL> cmd = "<STR_LIT>" . format ( "<STR_LIT:U+0020>" . join ( allcons ) ) <EOL> cmd += "<STR_LIT>" . format ( pf ) <EOL> mm . add ( allcons + [ clustSfile ] , locifile , cmd ) <EOL> mm . write ( ) <EOL> def snpflow ( args ) : <EOL> """<STR_LIT>""" <EOL> p = OptionParser ( snpflow . __doc__ ) <EOL> p . set_fastq_names ( ) <EOL> p . set_cpus ( ) <EOL> opts , args = p . parse_args ( args ) <EOL> if len ( args ) != <NUM_LIT:2> : <EOL> sys . exit ( not p . print_help ( ) ) <EOL> trimmed , ref = args <EOL> nseqs = len ( Fasta ( ref ) ) <EOL> supercat = nseqs >= <NUM_LIT:1000> <EOL> if supercat : <EOL> logging . debug ( "<STR_LIT>" . format ( nseqs , supercat ) ) <EOL> reads , samples = scan_read_files ( trimmed , opts . names ) <EOL> nativedir , countsdir = "<STR_LIT>" , "<STR_LIT>" <EOL> for d in ( nativedir , countsdir ) : <EOL> mkdir ( d ) <EOL> mm = MakeManager ( ) <EOL> db = op . join ( * check_index ( ref , supercat = supercat , go = False ) ) <EOL> cmd = "<STR_LIT>" . format ( ref ) <EOL> if supercat : <EOL> cmd += "<STR_LIT>" <EOL> coordsfile = db + "<STR_LIT>" <EOL> supercatfile = ref . rsplit ( "<STR_LIT:.>" , <NUM_LIT:1> ) [ <NUM_LIT:0> ] + "<STR_LIT>" <EOL> mm . add ( ref , ( db , coordsfile ) , cmd ) <EOL> else : <EOL> mm . add ( ref , db , cmd ) <EOL> allnatives = [ ] <EOL> allsamstats = [ ] <EOL> gmapdb = supercatfile if supercat else ref <EOL> for f in reads : <EOL> prefix = get_prefix ( f , ref ) <EOL> gsnapfile = op . join ( nativedir , prefix + "<STR_LIT>" ) <EOL> nativefile = op . join ( nativedir , prefix + "<STR_LIT>" ) <EOL> samstatsfile = op . join ( nativedir , prefix + "<STR_LIT>" ) <EOL> cmd = "<STR_LIT>" . format ( gmapdb , f ) <EOL> cmd += "<STR_LIT>" . format ( nativedir ) <EOL> mm . add ( ( f , db ) , nativefile , cmd ) <EOL> cmd = "<STR_LIT>" . format ( gsnapfile , gmapdb ) <EOL> mm . add ( nativefile , samstatsfile , cmd ) <EOL> allnatives . append ( nativefile ) <EOL> allsamstats . append ( samstatsfile ) <EOL> if supercat : <EOL> nativeconverted = nativedir + "<STR_LIT>" <EOL> mkdir ( nativeconverted ) <EOL> allnativesc = [ op . join ( nativeconverted , op . basename ( x ) ) for x in allnatives ] <EOL> cmd = "<STR_LIT>" <EOL> cmd += "<STR_LIT>" . format ( nativedir , nativeconverted ) <EOL> cmd += "<STR_LIT>" . format ( coordsfile ) <EOL> cmds = [ "<STR_LIT>" . format ( nativeconverted ) , cmd ] <EOL> mm . add ( allnatives + [ coordsfile ] , allnativesc , cmds ) <EOL> runfile = "<STR_LIT>" <EOL> write_file ( runfile , speedupsh . format ( nativeconverted , opts . cpus ) ) <EOL> nativedir = nativeconverted <EOL> allsnps = [ op . join ( nativedir , "<STR_LIT>" . format ( x ) ) for x in samples ] <EOL> mm . add ( allnativesc , allsnps , "<STR_LIT>" . format ( runfile ) ) <EOL> else : <EOL> for s in samples : <EOL> snpfile = op . join ( nativedir , "<STR_LIT>" . format ( s ) ) <EOL> cmd = "<STR_LIT>" <EOL> cmd += "<STR_LIT>" . format ( nativedir , s ) <EOL> cmd += "<STR_LIT>" . format ( snpfile ) <EOL> flist = [ x for x in allnatives if op . basename ( x ) . split ( "<STR_LIT:.>" ) [ <NUM_LIT:0> ] == s ] <EOL> mm . add ( flist , snpfile , cmd ) <EOL> allsnps = [ op . join ( nativedir , "<STR_LIT>" . format ( x ) ) for x in samples ] <EOL> for s in samples : <EOL> equalfile = op . join ( nativedir , "<STR_LIT>" . format ( s ) ) <EOL> cmd = "<STR_LIT>" <EOL> cmd += "<STR_LIT>" . format ( nativedir , s ) <EOL> cmd += "<STR_LIT>" . format ( nativedir , s ) <EOL> cmd += "<STR_LIT>" . format ( nativedir ) <EOL> cmd += "<STR_LIT>" . format ( ref , equalfile ) <EOL> mm . add ( allsnps , equalfile , cmd ) <EOL> allequals = [ op . join ( nativedir , "<STR_LIT>" . format ( x ) ) for x in samples ] <EOL> matrix = "<STR_LIT>" <EOL> cmd = "<STR_LIT>" <EOL> cmd += "<STR_LIT>" . format ( nativedir ) <EOL> cmd += "<STR_LIT>" . format ( ref , matrix ) <EOL> mm . add ( allsnps + allequals , matrix , cmd ) <EOL> allcounts = [ ] <EOL> for s in samples : <EOL> allele_counts = op . join ( countsdir , "<STR_LIT>" . format ( s ) ) <EOL> cmd = "<STR_LIT>" <EOL> cmd += "<STR_LIT>" . format ( s , nativedir ) <EOL> cmd += "<STR_LIT>" . format ( allele_counts ) <EOL> mm . add ( matrix , allele_counts , cmd ) <EOL> allcounts . append ( allele_counts ) <EOL> rawsnps = "<STR_LIT>" <EOL> cmd = "<STR_LIT>" <EOL> cmd += "<STR_LIT>" . format ( countsdir , rawsnps ) <EOL> cmds = [ "<STR_LIT>" . format ( rawsnps ) , cmd ] <EOL> mm . add ( allcounts , rawsnps , cmds ) <EOL> sam_summary = "<STR_LIT>" <EOL> cmd = "<STR_LIT>" <EOL> cmd += "<STR_LIT>" . format ( "<STR_LIT:U+0020>" . join ( allsamstats ) , sam_summary ) <EOL> mm . add ( allsamstats , sam_summary , cmd ) <EOL> native_summary = "<STR_LIT>" <EOL> cmd = "<STR_LIT>" <EOL> cmd += "<STR_LIT>" . format ( "<STR_LIT:U+0020>" . join ( allnatives ) , native_summary ) <EOL> mm . add ( allnatives , native_summary , cmd ) <EOL> mm . write ( ) <EOL> def snpplot ( args ) : <EOL> """<STR_LIT>""" <EOL> p = OptionParser ( snpplot . __doc__ ) <EOL> opts , args , iopts = p . set_image_options ( args , format = "<STR_LIT>" ) <EOL> if len ( args ) != <NUM_LIT:1> : <EOL> sys . exit ( not p . print_help ( ) ) <EOL> datafile , = args <EOL> fp = open ( datafile ) <EOL> fp . next ( ) ; fp . next ( ) <EOL> data = [ ] <EOL> for row in fp : <EOL> atoms = row . split ( ) [ <NUM_LIT:4> : ] <EOL> nval = len ( atoms ) <EOL> values = [ float ( x ) for x in atoms ] <EOL> values = [ x * <NUM_LIT:1.> / sum ( values ) for x in values ] <EOL> data . append ( values ) <EOL> pf = datafile . rsplit ( "<STR_LIT:.>" , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> fig = plt . figure ( <NUM_LIT:1> , ( iopts . w , iopts . h ) ) <EOL> root = fig . add_axes ( [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> ] ) <EOL> xmin , xmax = <NUM_LIT> , <NUM_LIT> <EOL> ymin , ymax = <NUM_LIT> , <NUM_LIT> <EOL> yinterval = ( ymax - ymin ) / len ( data ) <EOL> colors = "<STR_LIT>" if nval == <NUM_LIT:3> else [ "<STR_LIT>" ] + list ( "<STR_LIT>" ) <EOL> ystart = ymax <EOL> for d in data : <EOL> xstart = xmin <EOL> for dd , c in zip ( d , colors ) : <EOL> xend = xstart + ( xmax - xmin ) * dd <EOL> root . plot ( ( xstart , xend ) , ( ystart , ystart ) , "<STR_LIT:->" , color = c ) <EOL> xstart = xend <EOL> ystart -= yinterval <EOL> root . text ( <NUM_LIT> , <NUM_LIT> , "<STR_LIT>" . format ( len ( data ) ) , <EOL> ha = "<STR_LIT>" , va = "<STR_LIT>" , rotation = <NUM_LIT> , color = "<STR_LIT>" ) <EOL> for x , t , c in zip ( ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , "<STR_LIT>" ) : <EOL> root . text ( x , <NUM_LIT> , t , color = c , ha = "<STR_LIT>" , va = "<STR_LIT>" ) <EOL> normalize_axes ( root ) <EOL> image_name = pf + "<STR_LIT:.>" + iopts . format <EOL> savefig ( image_name , dpi = iopts . dpi , iopts = iopts ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
