idx
int64
0
63k
question
stringlengths
61
4.03k
target
stringlengths
6
1.23k
12,000
def beagle ( args ) : p = OptionParser ( beagle . __doc__ ) p . set_home ( "beagle" ) p . set_ref ( ) p . set_cpus ( ) opts , args = p . parse_args ( args ) if len ( args ) != 2 : sys . exit ( not p . print_help ( ) ) vcffile , chr = args pf = vcffile . rsplit ( "." , 1 ) [ 0 ] outpf = pf + ".beagle" outfile = outpf + ...
%prog beagle input . vcf 1
12,001
def impute ( args ) : from pyfaidx import Fasta p = OptionParser ( impute . __doc__ ) p . set_home ( "shapeit" ) p . set_home ( "impute" ) p . set_ref ( ) p . set_cpus ( ) opts , args = p . parse_args ( args ) if len ( args ) != 3 : sys . exit ( not p . print_help ( ) ) vcffile , fastafile , chr = args mm = MakeManager...
%prog impute input . vcf hs37d5 . fa 1
12,002
def summary ( args ) : p = OptionParser ( summary . __doc__ ) opts , args = p . parse_args ( args ) if len ( args ) != 2 : sys . exit ( not p . print_help ( ) ) gff_file , ref = args s = Fasta ( ref ) g = make_index ( gff_file ) geneseqs , exonseqs , intronseqs = [ ] , [ ] , [ ] for f in g . features_of_type ( "gene" )...
%prog summary gffile fastafile
12,003
def run ( self , clean = True ) : template = self . template parameters = self . parameters fw = must_open ( "tmp" , "w" ) path = fw . name fw . write ( template . safe_substitute ( ** parameters ) ) fw . close ( ) sh ( "Rscript %s" % path ) if clean : os . remove ( path ) rplotspdf = "Rplots.pdf" if op . exists ( rplo...
Create a temporary file and run it
12,004
def transitive_reduction ( G ) : H = G . copy ( ) for a , b , w in G . edges_iter ( data = True ) : H . remove_edge ( a , b ) if not nx . has_path ( H , a , b ) : H . add_edge ( a , b , w ) return H
Returns a transitive reduction of a graph . The original graph is not modified .
12,005
def merge_paths ( paths , weights = None ) : G = make_paths ( paths , weights = weights ) G = reduce_paths ( G ) return G
Zip together sorted lists .
12,006
def get_next ( self , tag = "<" ) : next , ntag = None , None L = self . outs if tag == "<" else self . ins if len ( L ) == 1 : e , = L if e . v1 . v == self . v : next , ntag = e . v2 , e . o2 ntag = "<" if ntag == ">" else ">" else : next , ntag = e . v1 , e . o1 if next : B = next . ins if ntag == "<" else next . ou...
This function is tricky and took me a while to figure out .
12,007
def dust2bed ( args ) : from jcvi . formats . base import read_block p = OptionParser ( dust2bed . __doc__ ) opts , args = p . parse_args ( args ) if len ( args ) != 1 : sys . exit ( not p . print_help ( ) ) fastafile , = args interval = fastafile + ".iv" if need_update ( fastafile , interval ) : cmd = "dustmasker -in ...
%prog dust2bed fastafile
12,008
def fasta2bed ( fastafile ) : dustfasta = fastafile . rsplit ( "." , 1 ) [ 0 ] + ".dust.fasta" for name , seq in parse_fasta ( dustfasta ) : for islower , ss in groupby ( enumerate ( seq ) , key = lambda x : x [ - 1 ] . islower ( ) ) : if not islower : continue ss = list ( ss ) ms , mn = min ( ss ) xs , xn = max ( ss )...
Alternative BED generation from FASTA file . Used for sanity check .
12,009
def circular ( args ) : from jcvi . assembly . goldenpath import overlap p = OptionParser ( circular . __doc__ ) p . add_option ( "--flip" , default = False , action = "store_true" , help = "Reverse complement the sequence" ) p . set_outfile ( ) opts , args = p . parse_args ( args ) if len ( args ) != 2 : sys . exit ( ...
%prog circular fastafile startpos
12,010
def dust ( args ) : p = OptionParser ( dust . __doc__ ) opts , args = p . parse_args ( args ) if len ( args ) != 1 : sys . exit ( not p . print_help ( ) ) fastafile , = args dustfastafile = fastafile . rsplit ( "." , 1 ) [ 0 ] + ".dust.fasta" if need_update ( fastafile , dustfastafile ) : cmd = "dustmasker -in {0}" . f...
%prog dust assembly . fasta
12,011
def dedup ( args ) : from jcvi . formats . blast import BlastLine p = OptionParser ( dedup . __doc__ ) p . set_align ( pctid = 0 , pctcov = 98 ) opts , args = p . parse_args ( args ) if len ( args ) != 2 : sys . exit ( not p . print_help ( ) ) blastfile , fastafile = args cov = opts . pctcov / 100. sizes = Sizes ( fast...
%prog dedup assembly . assembly . blast assembly . fasta
12,012
def build ( args ) : from jcvi . apps . cdhit import deduplicate from jcvi . apps . vecscreen import mask from jcvi . formats . fasta import sort p = OptionParser ( build . __doc__ ) p . add_option ( "--nodedup" , default = False , action = "store_true" , help = "Do not deduplicate [default: deduplicate]" ) opts , args...
%prog build current . fasta Bacteria_Virus . fasta prefix
12,013
def screen ( args ) : from jcvi . apps . align import blast from jcvi . formats . blast import covfilter p = OptionParser ( screen . __doc__ ) p . set_align ( pctid = 95 , pctcov = 50 ) p . add_option ( "--best" , default = 1 , type = "int" , help = "Get the best N hit [default: %default]" ) opts , args = p . parse_arg...
%prog screen scaffolds . fasta library . fasta
12,014
def scaffold ( args ) : from jcvi . formats . agp import bed , order_to_agp , build from jcvi . formats . bed import Bed p = OptionParser ( scaffold . __doc__ ) p . add_option ( "--prefix" , default = False , action = "store_true" , help = "Keep IDs with same prefix together [default: %default]" ) opts , args = p . par...
%prog scaffold ctgfasta agpfile
12,015
def overlapbatch ( args ) : p = OptionParser ( overlap . __doc__ ) opts , args = p . parse_args ( args ) if len ( args ) != 2 : sys . exit ( not p . print_help ( ) ) ctgfasta , poolfasta = args f = Fasta ( ctgfasta ) for k , rec in f . iteritems_ordered ( ) : fastafile = k + ".fasta" fw = open ( fastafile , "w" ) SeqIO...
%prog overlapbatch ctgfasta poolfasta
12,016
def array ( args ) : p = OptionParser ( array . __doc__ ) p . set_grid_opts ( array = True ) p . set_params ( prog = "grid" ) opts , args = p . parse_args ( args ) if len ( args ) != 1 : sys . exit ( not p . print_help ( ) ) cmds , = args fp = open ( cmds ) N = sum ( 1 for x in fp ) fp . close ( ) pf = cmds . rsplit ( ...
%prog array commands . list
12,017
def covlen ( args ) : import numpy as np import pandas as pd import seaborn as sns from jcvi . formats . base import DictFile p = OptionParser ( covlen . __doc__ ) p . add_option ( "--maxsize" , default = 1000000 , type = "int" , help = "Max contig size" ) p . add_option ( "--maxcov" , default = 100 , type = "int" , he...
%prog covlen covfile fastafile
12,018
def scaffold ( args ) : from jcvi . utils . iter import grouper p = OptionParser ( scaffold . __doc__ ) p . add_option ( "--cutoff" , type = "int" , default = 1000000 , help = "Plot scaffolds with size larger than [default: %default]" ) p . add_option ( "--highlights" , help = "A set of regions in BED format to highlig...
%prog scaffold scaffold . fasta synteny . blast synteny . sizes synteny . bed physicalmap . blast physicalmap . sizes physicalmap . bed
12,019
def A50 ( args ) : p = OptionParser ( A50 . __doc__ ) p . add_option ( "--overwrite" , default = False , action = "store_true" , help = "overwrite .rplot file if exists [default: %default]" ) p . add_option ( "--cutoff" , default = 0 , type = "int" , dest = "cutoff" , help = "use contigs above certain size [default: %d...
%prog A50 contigs_A . fasta contigs_B . fasta ...
12,020
def fromdelta ( args ) : p = OptionParser ( fromdelta . __doc__ ) opts , args = p . parse_args ( args ) if len ( args ) != 1 : sys . exit ( not p . print_help ( ) ) deltafile , = args coordsfile = deltafile . rsplit ( "." , 1 ) [ 0 ] + ".coords" cmd = "show-coords -rclH {0}" . format ( deltafile ) sh ( cmd , outfile = ...
%prog fromdelta deltafile
12,021
def sort ( args ) : import jcvi . formats . blast return jcvi . formats . blast . sort ( args + [ "--coords" ] )
%prog sort coordsfile
12,022
def coverage ( args ) : p = OptionParser ( coverage . __doc__ ) p . add_option ( "-c" , dest = "cutoff" , default = 0.5 , type = "float" , help = "only report query with coverage greater than [default: %default]" ) opts , args = p . parse_args ( args ) if len ( args ) != 1 : sys . exit ( not p . print_help ( ) ) coords...
%prog coverage coordsfile
12,023
def annotate ( args ) : p = OptionParser ( annotate . __doc__ . format ( ", " . join ( Overlap_types ) ) ) p . add_option ( "--maxhang" , default = 100 , type = "int" , help = "Max hang to call dovetail overlap [default: %default]" ) p . add_option ( "--all" , default = False , action = "store_true" , help = "Output al...
%prog annotate coordsfile
12,024
def summary ( args ) : from jcvi . formats . blast import AlignStats p = OptionParser ( summary . __doc__ ) p . add_option ( "-s" , dest = "single" , default = False , action = "store_true" , help = "provide stats per reference seq" ) opts , args = p . parse_args ( args ) if len ( args ) != 1 : sys . exit ( p . print_h...
%prog summary coordsfile
12,025
def bed ( args ) : p = OptionParser ( bed . __doc__ ) p . add_option ( "--query" , default = False , action = "store_true" , help = "print out query intervals rather than ref [default: %default]" ) p . add_option ( "--pctid" , default = False , action = "store_true" , help = "use pctid in score [default: %default]" ) p...
%prog bed coordsfile
12,026
def hits ( self ) : self . quality_sort ( ) hits = dict ( ( query , list ( blines ) ) for ( query , blines ) in groupby ( self , lambda x : x . query ) ) self . ref_sort ( ) return hits
returns a dict with query = > blastline
12,027
def best_hits ( self ) : self . quality_sort ( ) best_hits = dict ( ( query , next ( blines ) ) for ( query , blines ) in groupby ( self , lambda x : x . query ) ) self . ref_sort ( ) return best_hits
returns a dict with query = > best mapped position
12,028
def sh ( cmd , grid = False , infile = None , outfile = None , errfile = None , append = False , background = False , threaded = None , log = True , grid_opts = None , silent = False , shell = "/bin/bash" , check = False ) : if not cmd : return 1 if silent : outfile = errfile = "/dev/null" if grid : from jcvi . apps . ...
simple wrapper for system calls
12,029
def Popen ( cmd , stdin = None , stdout = PIPE , debug = False , shell = "/bin/bash" ) : from subprocess import Popen as P if debug : logging . debug ( cmd ) proc = P ( cmd , bufsize = 1 , stdin = stdin , stdout = stdout , shell = True , executable = shell ) return proc
Capture the cmd stdout output to a file handle .
12,030
def is_newer_file ( a , b ) : if not ( op . exists ( a ) and op . exists ( b ) ) : return False am = os . stat ( a ) . st_mtime bm = os . stat ( b ) . st_mtime return am > bm
Check if the file a is newer than file b
12,031
def need_update ( a , b ) : a = listify ( a ) b = listify ( b ) return any ( ( not op . exists ( x ) ) for x in b ) or all ( ( os . stat ( x ) . st_size == 0 for x in b ) ) or any ( is_newer_file ( x , y ) for x in a for y in b )
Check if file a is newer than file b and decide whether or not to update file b . Can generalize to two lists .
12,032
def debug ( level = logging . DEBUG ) : from jcvi . apps . console import magenta , yellow format = yellow ( "%(asctime)s [%(module)s]" ) format += magenta ( " %(message)s" ) logging . basicConfig ( level = level , format = format , datefmt = "%H:%M:%S" )
Turn on the debugging
12,033
def mdownload ( args ) : from jcvi . apps . grid import Jobs p = OptionParser ( mdownload . __doc__ ) opts , args = p . parse_args ( args ) if len ( args ) != 1 : sys . exit ( not p . print_help ( ) ) linksfile , = args links = [ ( x . strip ( ) , ) for x in open ( linksfile ) ] j = Jobs ( download , links ) j . run ( ...
%prog mdownload links . txt
12,034
def timestamp ( args ) : p = OptionParser ( timestamp . __doc__ ) opts , args = p . parse_args ( args ) if len ( args ) != 1 : sys . exit ( not p . print_help ( ) ) path , = args for root , dirs , files in os . walk ( path ) : for f in files : filename = op . join ( root , f ) atime , mtime = get_times ( filename ) pri...
%prog timestamp path > timestamp . info
12,035
def touch ( args ) : from time import ctime p = OptionParser ( touch . __doc__ ) opts , args = p . parse_args ( args ) if len ( args ) != 1 : sys . exit ( not p . print_help ( ) ) info , = args fp = open ( info ) for row in fp : path , atime , mtime = row . split ( ) atime = float ( atime ) mtime = float ( mtime ) curr...
%prog touch timestamp . info
12,036
def less ( args ) : from jcvi . formats . base import must_open p = OptionParser ( less . __doc__ ) opts , args = p . parse_args ( args ) if len ( args ) != 2 : sys . exit ( not p . print_help ( ) ) filename , pos = args fsize = getfilesize ( filename ) if pos == "all" : pos = [ x / 10. for x in range ( 0 , 10 ) ] else...
%prog less filename position | less
12,037
def pushover ( message , token , user , title = "JCVI: Job Monitor" , priority = 0 , timestamp = None ) : assert - 1 <= priority <= 2 , "Priority should be an int() between -1 and 2" if timestamp == None : from time import time timestamp = int ( time ( ) ) retry , expire = ( 300 , 3600 ) if priority == 2 else ( None , ...
pushover . net python API
12,038
def pushnotify ( subject , message , api = "pushover" , priority = 0 , timestamp = None ) : import types assert type ( priority ) is int and - 1 <= priority <= 2 , "Priority should be and int() between -1 and 2" cfgfile = op . join ( op . expanduser ( "~" ) , "pushnotify.ini" ) Config = ConfigParser ( ) if op . exists ...
Send push notifications using pre - existing APIs
12,039
def send_email ( fromaddr , toaddr , subject , message ) : from smtplib import SMTP from email . mime . text import MIMEText SERVER = "localhost" _message = MIMEText ( message ) _message [ 'Subject' ] = subject _message [ 'From' ] = fromaddr _message [ 'To' ] = ", " . join ( toaddr ) server = SMTP ( SERVER ) server . s...
Send an email message
12,040
def get_email_address ( whoami = "user" ) : if whoami == "user" : username = getusername ( ) domain = getdomainname ( ) myemail = "{0}@{1}" . format ( username , domain ) return myemail else : fromaddr = "notifier-donotreply@{0}" . format ( getdomainname ( ) ) return fromaddr
Auto - generate the FROM and TO email address
12,041
def notify ( args ) : from jcvi . utils . iter import flatten valid_notif_methods . extend ( available_push_api . keys ( ) ) fromaddr = get_email_address ( whoami = "notifier" ) p = OptionParser ( notify . __doc__ ) p . add_option ( "--method" , default = "email" , choices = valid_notif_methods , help = "Specify the mo...
%prog notify Message to be sent
12,042
def set_db_opts ( self , dbname = "mta4" , credentials = True ) : from jcvi . utils . db import valid_dbconn , get_profile self . add_option ( "--db" , default = dbname , dest = "dbname" , help = "Specify name of database to query [default: %default]" ) self . add_option ( "--connector" , default = "Sybase" , dest = "d...
Add db connection specific attributes
12,043
def set_image_options ( self , args = None , figsize = "6x6" , dpi = 300 , format = "pdf" , font = "Helvetica" , palette = "deep" , style = "darkgrid" , cmap = "jet" ) : from jcvi . graphics . base import ImageOptions , setup_theme allowed_format = ( "emf" , "eps" , "pdf" , "png" , "ps" , "raw" , "rgba" , "svg" , "svgz...
Add image format options for given command line programs .
12,044
def dedup ( args ) : from jcvi . formats . fasta import gaps from jcvi . apps . cdhit import deduplicate , ids p = OptionParser ( dedup . __doc__ ) p . set_align ( pctid = GoodPct ) p . set_mingap ( default = 10 ) opts , args = p . parse_args ( args ) if len ( args ) != 1 : sys . exit ( not p . print_help ( ) ) scaffol...
%prog dedup scaffolds . fasta
12,045
def blast ( args ) : from jcvi . apps . align import run_megablast p = OptionParser ( blast . __doc__ ) p . add_option ( "-n" , type = "int" , default = 2 , help = "Take best N hits [default: %default]" ) opts , args = p . parse_args ( args ) if len ( args ) != 2 : sys . exit ( not p . print_help ( ) ) allfasta , clone...
%prog blast allfasta clonename
12,046
def bes ( args ) : from jcvi . apps . align import run_blat p = OptionParser ( bes . __doc__ ) p . set_cpus ( ) opts , args = p . parse_args ( args ) if len ( args ) != 2 : sys . exit ( not p . print_help ( ) ) bacfasta , clonename = args entrez ( [ clonename , "--database=nucgss" , "--skipcheck" ] ) besfasta = clonena...
%prog bes bacfasta clonename
12,047
def flip ( args ) : p = OptionParser ( flip . __doc__ ) opts , args = p . parse_args ( args ) if len ( args ) != 1 : sys . exit ( not p . print_help ( ) ) fastafile , = args outfastafile = fastafile . rsplit ( "." , 1 ) [ 0 ] + ".flipped.fasta" fo = open ( outfastafile , "w" ) f = Fasta ( fastafile , lazy = True ) for ...
%prog flip fastafile
12,048
def batchoverlap ( args ) : p = OptionParser ( batchoverlap . __doc__ ) p . set_cpus ( ) opts , args = p . parse_args ( args ) if len ( args ) != 2 : sys . exit ( not p . print_help ( ) ) pairsfile , outdir = args fp = open ( pairsfile ) cmds = [ ] mkdir ( "overlaps" ) for row in fp : a , b = row . split ( ) [ : 2 ] oa...
%prog batchoverlap pairs . txt outdir
12,049
def certificate ( args ) : p = OptionParser ( certificate . __doc__ ) opts , args = p . parse_args ( args ) if len ( args ) != 2 : sys . exit ( not p . print_help ( ) ) tpffile , certificatefile = args fastadir = "fasta" tpf = TPF ( tpffile ) data = check_certificate ( certificatefile ) fw = must_open ( certificatefile...
%prog certificate tpffile certificatefile
12,050
def neighbor ( args ) : p = OptionParser ( neighbor . __doc__ ) opts , args = p . parse_args ( args ) if len ( args ) != 2 : sys . exit ( not p . print_help ( ) ) agpfile , componentID = args fastadir = "fasta" cmd = "grep" cmd += " --color -C2 {0} {1}" . format ( componentID , agpfile ) sh ( cmd ) agp = AGP ( agpfile ...
%prog neighbor agpfile componentID
12,051
def agp ( args ) : from jcvi . formats . base import DictFile p = OptionParser ( agp . __doc__ ) opts , args = p . parse_args ( args ) if len ( args ) != 3 : sys . exit ( not p . print_help ( ) ) tpffile , certificatefile , agpfile = args orientationguide = DictFile ( tpffile , valuepos = 2 ) cert = Certificate ( certi...
%prog agp tpffile certificatefile agpfile
12,052
def update_clr ( self , aclr , bclr ) : print ( aclr , bclr , file = sys . stderr ) otype = self . otype if otype == 1 : if aclr . orientation == '+' : aclr . end = self . qstop else : aclr . start = self . qstart if bclr . orientation == '+' : bclr . start = self . sstop + 1 else : bclr . end = self . sstart - 1 elif ...
Zip the two sequences together using left - greedy rule
12,053
def gcdepth ( args ) : import hashlib from jcvi . algorithms . formula import MAD_interval as confidence_interval from jcvi . graphics . base import latex , plt , savefig , set2 p = OptionParser ( gcdepth . __doc__ ) opts , args = p . parse_args ( args ) if len ( args ) != 2 : sys . exit ( not p . print_help ( ) ) samp...
%prog gcdepth sample_name tag
12,054
def exonunion ( args ) : p = OptionParser ( exonunion . __doc__ ) opts , args = p . parse_args ( args ) if len ( args ) != 1 : sys . exit ( not p . print_help ( ) ) gencodebed , = args beds = BedTool ( gencodebed ) for g , gb in groupby ( beds , key = lambda x : x . fields [ 3 ] ) : gb = BedTool ( gb ) sys . stdout . w...
%prog exonunion gencode . v26 . annotation . exon . bed
12,055
def summarycanvas ( args ) : p = OptionParser ( summarycanvas . __doc__ ) opts , args = p . parse_args ( args ) if len ( args ) < 1 : sys . exit ( not p . print_help ( ) ) for vcffile in args : counter = get_gain_loss_summary ( vcffile ) pf = op . basename ( vcffile ) . split ( "." ) [ 0 ] print ( pf + " " + " " . join...
%prog summarycanvas output . vcf . gz
12,056
def parse_segments ( vcffile ) : from cStringIO import StringIO from cyvcf2 import VCF output = StringIO ( ) for v in VCF ( vcffile ) : chrom = v . CHROM start = v . start end = v . INFO . get ( 'END' ) - 1 cn , = v . format ( 'CN' ) [ 0 ] print ( "\t" . join ( str ( x ) for x in ( chrom , start , end , cn ) ) , file =...
Extract all copy number segments from a CANVAS file
12,057
def counter_mean_and_median ( counter ) : if not counter : return np . nan , np . nan total = sum ( v for k , v in counter . items ( ) ) mid = total / 2 weighted_sum = 0 items_seen = 0 median_found = False for k , v in sorted ( counter . items ( ) ) : weighted_sum += k * v items_seen += v if not median_found and items_...
Calculate the mean and median value of a counter
12,058
def vcf_to_df_worker ( arg ) : canvasvcf , exonbed , i = arg logging . debug ( "Working on job {}: {}" . format ( i , canvasvcf ) ) samplekey = op . basename ( canvasvcf ) . split ( "." ) [ 0 ] . rsplit ( '_' , 1 ) [ 0 ] d = { 'SampleKey' : samplekey } exons = BedTool ( exonbed ) cn = parse_segments ( canvasvcf ) overl...
Convert CANVAS vcf to a dict single thread
12,059
def vcf_to_df ( canvasvcfs , exonbed , cpus ) : df = pd . DataFrame ( ) p = Pool ( processes = cpus ) results = [ ] args = [ ( x , exonbed , i ) for ( i , x ) in enumerate ( canvasvcfs ) ] r = p . map_async ( vcf_to_df_worker , args , callback = results . append ) r . wait ( ) for res in results : df = df . append ( re...
Compile a number of vcf files into tsv file for easy manipulation
12,060
def df_to_tsv ( df , tsvfile , suffix ) : tsvfile += suffix columns = [ "SampleKey" ] + sorted ( x for x in df . columns if x . endswith ( suffix ) ) tf = df . reindex_axis ( columns , axis = 'columns' ) tf . sort_values ( "SampleKey" ) tf . to_csv ( tsvfile , sep = '\t' , index = False , float_format = '%.4g' , na_rep...
Serialize the dataframe as a tsv
12,061
def plot ( args ) : from jcvi . graphics . base import savefig p = OptionParser ( plot . __doc__ ) opts , args , iopts = p . set_image_options ( args , figsize = "8x7" , format = "png" ) if len ( args ) != 3 : sys . exit ( not p . print_help ( ) ) workdir , sample_key , chrs = args chrs = chrs . split ( "," ) hmm = Cop...
%prog plot workdir sample chr1 chr2
12,062
def sweep ( args ) : p = OptionParser ( sweep . __doc__ ) opts , args = p . parse_args ( args ) if len ( args ) != 2 : sys . exit ( not p . print_help ( ) ) workdir , sample_key = args golden_ratio = ( 1 + 5 ** .5 ) / 2 cmd = "python -m jcvi.variation.cnv hmm {} {}" . format ( workdir , sample_key ) cmd += " --mu {:.5f...
%prog sweep workdir 102340_NA12878
12,063
def cib ( args ) : p = OptionParser ( cib . __doc__ ) p . add_option ( "--prefix" , help = "Report seqids with this prefix only" ) p . set_cpus ( ) opts , args = p . parse_args ( args ) if len ( args ) != 2 : sys . exit ( not p . print_help ( ) ) bamfile , samplekey = args mkdir ( samplekey ) bam = pysam . AlignmentFil...
%prog cib bamfile samplekey
12,064
def batchcn ( args ) : p = OptionParser ( batchcn . __doc__ ) p . add_option ( "--upload" , default = "s3://hli-mv-data-science/htang/ccn" , help = "Upload cn and seg results to s3" ) opts , args = p . parse_args ( args ) if len ( args ) != 2 : sys . exit ( not p . print_help ( ) ) workdir , samples = args upload = opt...
%prog batchcn workdir samples . csv
12,065
def hmm ( args ) : p = OptionParser ( hmm . __doc__ ) p . add_option ( "--mu" , default = .003 , type = "float" , help = "Transition probability" ) p . add_option ( "--sigma" , default = .1 , type = "float" , help = "Standard deviation of Gaussian emission distribution" ) p . add_option ( "--threshold" , default = 1 , ...
%prog hmm workdir sample_key
12,066
def batchccn ( args ) : p = OptionParser ( batchccn . __doc__ ) opts , args = p . parse_args ( args ) if len ( args ) != 1 : sys . exit ( not p . print_help ( ) ) csvfile , = args mm = MakeManager ( ) pf = op . basename ( csvfile ) . split ( "." ) [ 0 ] mkdir ( pf ) header = next ( open ( csvfile ) ) header = None if h...
%prog batchccn test . csv
12,067
def mergecn ( args ) : p = OptionParser ( mergecn . __doc__ ) opts , args = p . parse_args ( args ) if len ( args ) != 1 : sys . exit ( not p . print_help ( ) ) csvfile , = args samples = [ x . replace ( "-cn" , "" ) . strip ( ) . strip ( "/" ) for x in open ( csvfile ) ] betadir = "beta" mkdir ( betadir ) for seqid in...
%prog mergecn FACE . csv
12,068
def annotate_segments ( self , Z ) : P = Z . copy ( ) P [ ~ np . isfinite ( P ) ] = - 1 _ , mapping = np . unique ( np . cumsum ( P >= 0 ) , return_index = True ) dZ = Z . compressed ( ) uniq , idx = np . unique ( dZ , return_inverse = True ) segments = [ ] for i , mean_cn in enumerate ( uniq ) : if not np . isfinite (...
Report the copy number and start - end segment
12,069
def role ( args ) : src_acct , src_username , dst_acct , dst_role = "205134639408 htang 114692162163 mvrad-datasci-role" . split ( ) p = OptionParser ( role . __doc__ ) p . add_option ( "--profile" , default = "mvrad-datasci-role" , help = "Profile name" ) p . add_option ( '--device' , default = "arn:aws:iam::" + src_a...
%prog role htang
12,070
def query ( args ) : p = OptionParser ( query . __doc__ ) opts , args = p . parse_args ( args ) if len ( args ) != 2 : sys . exit ( not p . print_help ( ) ) locifile , contig = args idx = build_index ( locifile ) pos = idx [ contig ] logging . debug ( "Contig {0} found at pos {1}" . format ( contig , pos ) ) fp = open ...
%prog query out . loci contig
12,071
def synteny ( args ) : from jcvi . assembly . geneticmap import bed as geneticmap_bed from jcvi . apps . align import blat from jcvi . formats . blast import bed as blast_bed , best p = OptionParser ( synteny . __doc__ ) opts , args = p . parse_args ( args ) if len ( args ) != 3 : sys . exit ( not p . print_help ( ) ) ...
%prog synteny mstmap . out novo . final . fasta reference . fasta
12,072
def mstmap ( args ) : from jcvi . assembly . geneticmap import MSTMatrix p = OptionParser ( mstmap . __doc__ ) p . add_option ( "--population_type" , default = "RIL6" , help = "Type of population, possible values are DH and RILd" ) p . add_option ( "--missing_threshold" , default = .5 , help = "Missing threshold, .25 e...
%prog mstmap LMD50 . snps . genotype . txt
12,073
def count ( args ) : from jcvi . graphics . histogram import stem_leaf_plot from jcvi . utils . cbook import SummaryStats p = OptionParser ( count . __doc__ ) p . add_option ( "--csv" , help = "Write depth per contig to file" ) opts , args = p . parse_args ( args ) if len ( args ) != 1 : sys . exit ( not p . print_help...
%prog count cdhit . consensus . fasta
12,074
def novo ( args ) : from jcvi . assembly . kmer import jellyfish , histogram from jcvi . assembly . preprocess import diginorm from jcvi . formats . fasta import filter as fasta_filter , format from jcvi . apps . cdhit import filter as cdhit_filter p = OptionParser ( novo . __doc__ ) p . add_option ( "--technology" , c...
%prog novo reads . fastq
12,075
def novo2 ( args ) : p = OptionParser ( novo2 . __doc__ ) p . set_fastq_names ( ) p . set_align ( pctid = 95 ) opts , args = p . parse_args ( args ) if len ( args ) != 2 : sys . exit ( not p . print_help ( ) ) trimmed , pf = args pctid = opts . pctid reads , samples = scan_read_files ( trimmed , opts . names ) clustdir...
%prog novo2 trimmed projectname
12,076
def snpplot ( args ) : p = OptionParser ( snpplot . __doc__ ) opts , args , iopts = p . set_image_options ( args , format = "png" ) if len ( args ) != 1 : sys . exit ( not p . print_help ( ) ) datafile , = args fp = open ( datafile ) next ( fp ) next ( fp ) data = [ ] for row in fp : atoms = row . split ( ) [ 4 : ] nva...
%prog counts . cdt
12,077
def filterm4 ( args ) : p = OptionParser ( filterm4 . __doc__ ) p . add_option ( "--best" , default = 1 , type = "int" , help = "Only retain best N hits" ) p . set_outfile ( ) opts , args = p . parse_args ( args ) if len ( args ) != 1 : sys . exit ( not p . print_help ( ) ) m4file , = args best = opts . best fp = open ...
%prog filterm4 sample . m4 > filtered . m4
12,078
def spancount ( args ) : import json p = OptionParser ( spancount . __doc__ ) opts , args = p . parse_args ( args ) if len ( args ) != 1 : sys . exit ( not p . print_help ( ) ) fof , = args fp = open ( fof ) flist = [ row . strip ( ) for row in fp ] spanCount = "spanCount" avgSpanBases = "avgSpanBases" fw = open ( span...
%prog spancount list_of_fillingMetrics
12,079
def patch ( args ) : from jcvi . formats . base import write_file from jcvi . formats . fasta import format p = OptionParser ( patch . __doc__ ) p . add_option ( "--cleanfasta" , default = False , action = "store_true" , help = "Clean FASTA to remove description [default: %default]" ) p . add_option ( "--highqual" , de...
%prog patch reference . fasta reads . fasta
12,080
def isPlantOrigin ( taxid ) : assert isinstance ( taxid , int ) t = TaxIDTree ( taxid ) try : return "Viridiplantae" in str ( t ) except AttributeError : raise ValueError ( "{0} is not a valid ID" . format ( taxid ) )
Given a taxid this gets the expanded tree which can then be checked to see if the organism is a plant or not
12,081
def newick ( args ) : p = OptionParser ( newick . __doc__ ) opts , args = p . parse_args ( args ) if len ( args ) != 1 : sys . exit ( not p . print_help ( ) ) idsfile , = args mylist = [ x . strip ( ) for x in open ( idsfile ) if x . strip ( ) ] print ( get_taxids ( mylist ) ) t = TaxIDTree ( mylist ) print ( t )
%prog newick idslist
12,082
def fastq ( args ) : p = OptionParser ( fastq . __doc__ ) opts , args = p . parse_args ( args ) if len ( args ) != 2 : sys . exit ( not p . print_help ( ) ) bamfile , pf = args singletons = pf + ".se.fastq" a = pf + ".read1.fastq" b = pf + ".read2.fastq" cmd = "samtools collate -uOn 128 {} tmp-prefix" . format ( bamfil...
%prog fastq bamfile prefix
12,083
def mini ( args ) : p = OptionParser ( mini . __doc__ ) opts , args = p . parse_args ( args ) if len ( args ) != 2 : sys . exit ( not p . print_help ( ) ) bamfile , region = args get_minibam ( bamfile , region )
%prog mini bamfile region
12,084
def noclip ( args ) : p = OptionParser ( noclip . __doc__ ) opts , args = p . parse_args ( args ) if len ( args ) != 1 : sys . exit ( not p . print_help ( ) ) bamfile , = args noclipbam = bamfile . replace ( ".bam" , ".noclip.bam" ) cmd = "samtools view -h {} | awk -F '\t' '($6 !~ /H|S/)'" . format ( bamfile ) cmd += "...
%prog noclip bamfile
12,085
def append ( args ) : p = OptionParser ( append . __doc__ ) p . add_option ( "--prepend" , help = "Prepend string to read names" ) opts , args = p . parse_args ( args ) if len ( args ) != 1 : sys . exit ( not p . print_help ( ) ) bamfile , = args prepend = opts . prepend icmd = "samtools view -h {0}" . format ( bamfile...
%prog append bamfile
12,086
def bed ( args ) : p = OptionParser ( bed . __doc__ ) opts , args = p . parse_args ( args ) if len ( args ) < 2 : sys . exit ( not p . print_help ( ) ) bedfile = args [ 0 ] bamfiles = args [ 1 : ] for bamfile in bamfiles : cmd = "bamToBed -i {0}" . format ( bamfile ) sh ( cmd , outfile = bedfile , append = True )
%prog bed bedfile bamfiles
12,087
def merge ( args ) : from jcvi . apps . grid import MakeManager p = OptionParser ( merge . __doc__ ) p . set_sep ( sep = "_" , help = "Separator to group per prefix" ) opts , args = p . parse_args ( args ) if len ( args ) < 2 : sys . exit ( not p . print_help ( ) ) merged_bams = args [ 0 ] bamdirs = args [ 1 : ] mkdir ...
%prog merge merged_bams bams1_dir bams2_dir ...
12,088
def count ( args ) : p = OptionParser ( count . __doc__ ) p . add_option ( "--type" , default = "exon" , help = "Only count feature type" ) p . set_cpus ( cpus = 8 ) opts , args = p . parse_args ( args ) if len ( args ) != 2 : sys . exit ( not p . print_help ( ) ) bamfile , gtf = args cpus = opts . cpus pf = bamfile . ...
%prog count bamfile gtf
12,089
def coverage ( args ) : p = OptionParser ( coverage . __doc__ ) p . add_option ( "--format" , default = "bigwig" , choices = ( "bedgraph" , "bigwig" , "coverage" ) , help = "Output format" ) p . add_option ( "--nosort" , default = False , action = "store_true" , help = "Do not sort BAM" ) p . set_outfile ( ) opts , arg...
%prog coverage fastafile bamfile
12,090
def consensus ( args ) : p = OptionParser ( consensus . __doc__ ) p . add_option ( "--fasta" , default = False , action = "store_true" , help = "Generate consensus FASTA sequences [default: %default]" ) p . add_option ( "--mask" , default = 0 , type = "int" , help = "Mask bases with quality lower than" ) opts , args = ...
%prog consensus fastafile bamfile
12,091
def vcf ( args ) : from jcvi . apps . grid import Jobs valid_callers = ( "mpileup" , "freebayes" ) p = OptionParser ( vcf . __doc__ ) p . set_outfile ( outfile = "out.vcf.gz" ) p . add_option ( "--nosort" , default = False , action = "store_true" , help = "Do not sort the BAM files" ) p . add_option ( "--caller" , defa...
%prog vcf fastafile bamfiles > out . vcf . gz
12,092
def chimera ( args ) : import pysam from jcvi . utils . natsort import natsorted p = OptionParser ( chimera . __doc__ ) p . set_verbose ( ) opts , args = p . parse_args ( args ) if len ( args ) != 1 : sys . exit ( not p . print_help ( ) ) samfile , = args samfile = pysam . AlignmentFile ( samfile ) rstore = defaultdict...
%prog chimera bamfile
12,093
def pair ( args ) : p = OptionParser ( pair . __doc__ ) opts , args = p . parse_args ( args ) if len ( args ) != 1 : sys . exit ( p . print_help ( ) ) def callback ( s ) : print ( s . pairline ) Sam ( args [ 0 ] , callback = callback )
%prog pair samfile
12,094
def cigar_to_seq ( a , gap = '*' ) : seq , cigar = a . seq , a . cigar start = 0 subseqs = [ ] npadded = 0 if cigar is None : return None , npadded for operation , length in cigar : end = start if operation == 2 else start + length if operation == 0 : subseq = seq [ start : end ] elif operation == 1 : subseq = "" elif ...
Accepts a pysam row .
12,095
def dump ( args ) : p = OptionParser ( dump . __doc__ ) p . add_option ( "--dir" , help = "Working directory [default: %default]" ) p . add_option ( "--nosim" , default = False , action = "store_true" , help = "Do not simulate qual to 50 [default: %default]" ) opts , args = p . parse_args ( args ) if len ( args ) != 1 ...
%prog dump fastbfile
12,096
def fixpairs ( args ) : p = OptionParser ( fixpairs . __doc__ ) opts , args = p . parse_args ( args ) if len ( args ) != 3 : sys . exit ( not p . print_help ( ) ) pairsfile , sep , sd = args newpairsfile = pairsfile . rsplit ( "." , 1 ) [ 0 ] + ".new.pairs" sep = int ( sep ) sd = int ( sd ) p = PairsFile ( pairsfile ) ...
%prog fixpairs pairsfile sep sd
12,097
def fill ( args ) : p = OptionParser ( fill . __doc__ ) p . add_option ( "--stretch" , default = 3 , type = "int" , help = "MAX_STRETCH to pass to FillFragments [default: %default]" ) p . set_cpus ( ) opts , args = p . parse_args ( args ) if len ( args ) != 1 : sys . exit ( not p . print_help ( ) ) fastb , = args asser...
%prog fill frag_reads_corr . fastb
12,098
def extract_pairs ( fastqfile , p1fw , p2fw , fragsfw , p , suffix = False ) : fp = open ( fastqfile ) currentID = 0 npairs = nfrags = 0 for x , lib in izip ( p . r1 , p . libs ) : while currentID != x : fragsfw . writelines ( islice ( fp , 4 ) ) currentID += 1 nfrags += 1 a = list ( islice ( fp , 4 ) ) b = list ( isli...
Take fastqfile and array of pair ID extract adjacent pairs to outfile . Perform check on numbers when done . p1fw p2fw is a list of file handles each for one end . p is a Pairs instance .
12,099
def log ( args ) : from jcvi . algorithms . graph import nx , topological_sort p = OptionParser ( log . __doc__ ) opts , args = p . parse_args ( args ) if len ( args ) != 1 : sys . exit ( not p . print_help ( ) ) g = nx . DiGraph ( ) logfile , = args fp = open ( logfile ) row = fp . readline ( ) incalling = False based...
%prog log logfile