idx int64 0 63k | question stringlengths 61 4.03k | target stringlengths 6 1.23k |
|---|---|---|
29,300 | def index ( in_bam , config , check_timestamp = True ) : assert is_bam ( in_bam ) , "%s in not a BAM file" % in_bam index_file = "%s.bai" % in_bam alt_index_file = "%s.bai" % os . path . splitext ( in_bam ) [ 0 ] if check_timestamp : bai_exists = utils . file_uptodate ( index_file , in_bam ) or utils . file_uptodate ( ... | Index a BAM file skipping if index present . |
29,301 | def remove ( in_bam ) : if utils . file_exists ( in_bam ) : utils . remove_safe ( in_bam ) if utils . file_exists ( in_bam + ".bai" ) : utils . remove_safe ( in_bam + ".bai" ) | remove bam file and the index if exists |
29,302 | def idxstats ( in_bam , data ) : index ( in_bam , data [ "config" ] , check_timestamp = False ) AlignInfo = collections . namedtuple ( "AlignInfo" , [ "contig" , "length" , "aligned" , "unaligned" ] ) samtools = config_utils . get_program ( "samtools" , data [ "config" ] ) idxstats_out = subprocess . check_output ( [ s... | Return BAM index stats for the given file using samtools idxstats . |
29,303 | def fai_from_bam ( ref_file , bam_file , out_file , data ) : contigs = set ( [ x . contig for x in idxstats ( bam_file , data ) ] ) if not utils . file_uptodate ( out_file , bam_file ) : with open ( ref . fasta_idx ( ref_file , data [ "config" ] ) ) as in_handle : with file_transaction ( data , out_file ) as tx_out_fil... | Create a fai index with only contigs in the input BAM file . |
29,304 | def ref_file_from_bam ( bam_file , data ) : new_ref = os . path . join ( utils . safe_makedir ( os . path . join ( dd . get_work_dir ( data ) , "inputs" , "ref" ) ) , "%s-subset.fa" % dd . get_genome_build ( data ) ) if not utils . file_exists ( new_ref ) : with file_transaction ( data , new_ref ) as tx_out_file : cont... | Subset a fasta input file to only a fraction of input contigs . |
29,305 | def get_downsample_pct ( in_bam , target_counts , data ) : total = sum ( x . aligned for x in idxstats ( in_bam , data ) ) with pysam . Samfile ( in_bam , "rb" ) as work_bam : n_rgs = max ( 1 , len ( work_bam . header . get ( "RG" , [ ] ) ) ) rg_target = n_rgs * target_counts if total > rg_target : pct = float ( rg_tar... | Retrieve percentage of file to downsample to get to target counts . |
29,306 | def downsample ( in_bam , data , target_counts , work_dir = None ) : index ( in_bam , data [ "config" ] , check_timestamp = False ) ds_pct = get_downsample_pct ( in_bam , target_counts , data ) if ds_pct : out_file = "%s-downsample%s" % os . path . splitext ( in_bam ) if work_dir : out_file = os . path . join ( work_di... | Downsample a BAM file to the specified number of target counts . |
29,307 | def get_maxcov_downsample_cl ( data , in_pipe = None ) : max_cov = _get_maxcov_downsample ( data ) if dd . get_aligner ( data ) not in [ "snap" ] else None if max_cov : if in_pipe == "bamsormadup" : prefix = "level=0" elif in_pipe == "samtools" : prefix = "-l 0" else : prefix = "" core_arg = "" return ( "%s | variant -... | Retrieve command line for max coverage downsampling fitting into bamsormadup output . |
29,308 | def _get_maxcov_downsample ( data ) : from bcbio . bam import ref from bcbio . ngsalign import alignprep , bwa from bcbio . variation import coverage fastq_file = data [ "files" ] [ 0 ] params = alignprep . get_downsample_params ( data ) if params : num_reads = alignprep . total_reads_from_grabix ( fastq_file ) if num_... | Calculate maximum coverage downsampling for whole genome samples . |
29,309 | def check_header ( in_bam , rgnames , ref_file , config ) : _check_bam_contigs ( in_bam , ref_file , config ) _check_sample ( in_bam , rgnames ) | Ensure passed in BAM header matches reference file and read groups names . |
29,310 | def _check_sample ( in_bam , rgnames ) : with pysam . Samfile ( in_bam , "rb" ) as bamfile : rg = bamfile . header . get ( "RG" , [ { } ] ) msgs = [ ] warnings = [ ] if len ( rg ) > 1 : warnings . append ( "Multiple read groups found in input BAM. Expect single RG per BAM." ) if len ( rg ) == 0 : msgs . append ( "No re... | Ensure input sample name matches expected run group names . |
29,311 | def _check_bam_contigs ( in_bam , ref_file , config ) : allowed_outoforder = [ "chrM" , "MT" ] ref_contigs = [ c . name for c in ref . file_contigs ( ref_file , config ) ] with pysam . Samfile ( in_bam , "rb" ) as bamfile : bam_contigs = [ c [ "SN" ] for c in bamfile . header [ "SQ" ] ] extra_bcs = [ x for x in bam_con... | Ensure a pre - aligned BAM file matches the expected reference genome . |
29,312 | def sort ( in_bam , config , order = "coordinate" , out_dir = None ) : assert is_bam ( in_bam ) , "%s in not a BAM file" % in_bam if bam_already_sorted ( in_bam , config , order ) : return in_bam sort_stem = _get_sort_stem ( in_bam , order , out_dir ) sort_file = sort_stem + ".bam" if not utils . file_exists ( sort_fil... | Sort a BAM file skipping if already present . |
29,313 | def aligner_from_header ( in_bam ) : from bcbio . pipeline . alignment import TOOLS with pysam . Samfile ( in_bam , "rb" ) as bamfile : for pg in bamfile . header . get ( "PG" , [ ] ) : for ka in TOOLS . keys ( ) : if pg . get ( "PN" , "" ) . lower ( ) . find ( ka ) >= 0 : return ka | Identify aligner from the BAM header ; handling pre - aligned inputs . |
29,314 | def sample_name ( in_bam ) : with pysam . AlignmentFile ( in_bam , "rb" , check_sq = False ) as in_pysam : try : if "RG" in in_pysam . header : return in_pysam . header [ "RG" ] [ 0 ] [ "SM" ] except ValueError : return None | Get sample name from BAM file . |
29,315 | def filter_primary ( bam_file , data ) : stem , ext = os . path . splitext ( bam_file ) out_file = stem + ".primary" + ext if not utils . file_exists ( out_file ) : with file_transaction ( data , out_file ) as tx_out_file : cores = dd . get_num_cores ( data ) cmd = ( "samtools view -@ {cores} -F 2304 -b {bam_file} > {t... | Filter reads to primary only BAM . |
29,316 | def estimate_max_mapq ( in_bam , nreads = 1e6 ) : with pysam . Samfile ( in_bam , "rb" ) as work_bam : reads = tz . take ( int ( nreads ) , work_bam ) return max ( [ x . mapq for x in reads if not x . is_unmapped ] ) | Guess maximum MAPQ in a BAM file of reads with alignments |
29,317 | def convert_cufflinks_mapq ( in_bam , out_bam = None ) : CUFFLINKSMAPQ = 255 if not out_bam : out_bam = os . path . splitext ( in_bam ) [ 0 ] + "-cufflinks.bam" if utils . file_exists ( out_bam ) : return out_bam maxmapq = estimate_max_mapq ( in_bam ) if maxmapq == CUFFLINKSMAPQ : return in_bam logger . info ( "Convert... | Cufflinks expects the not - valid 255 MAPQ for uniquely mapped reads . This detects the maximum mapping quality in a BAM file and sets reads with that quality to be 255 |
29,318 | def get_gatk_annotations ( config , include_depth = True , include_baseqranksum = True , gatk_input = True ) : broad_runner = broad . runner_from_config ( config ) anns = [ "MappingQualityRankSumTest" , "MappingQualityZero" , "QualByDepth" , "ReadPosRankSumTest" , "RMSMappingQuality" ] if include_baseqranksum : anns +=... | Retrieve annotations to use for GATK VariantAnnotator . |
29,319 | def finalize_vcf ( in_file , variantcaller , items ) : out_file = "%s-annotated%s" % utils . splitext_plus ( in_file ) if not utils . file_uptodate ( out_file , in_file ) : header_cl = _add_vcf_header_sample_cl ( in_file , items , out_file ) contig_cl = _add_contig_cl ( in_file , items , out_file ) cls = [ x for x in (... | Perform cleanup and dbSNP annotation of the final VCF . |
29,320 | def _add_vcf_header_sample_cl ( in_file , items , base_file ) : paired = vcfutils . get_paired ( items ) if paired : toadd = [ "##SAMPLE=<ID=%s,Genomes=Tumor>" % paired . tumor_name ] if paired . normal_name : toadd . append ( "##SAMPLE=<ID=%s,Genomes=Germline>" % paired . normal_name ) toadd . append ( "##PEDIGREE=<De... | Add phenotype information to a VCF header . |
29,321 | def _update_header ( orig_vcf , base_file , new_lines , chrom_process_fn = None ) : new_header = "%s-sample_header.txt" % utils . splitext_plus ( base_file ) [ 0 ] with open ( new_header , "w" ) as out_handle : chrom_line = None with utils . open_gzipsafe ( orig_vcf ) as in_handle : for line in in_handle : if line . st... | Fix header with additional lines and remapping of generic sample names . |
29,322 | def _add_dbsnp ( orig_file , dbsnp_file , data , out_file = None , post_cl = None ) : orig_file = vcfutils . bgzip_and_index ( orig_file , data [ "config" ] ) if out_file is None : out_file = "%s-wdbsnp.vcf.gz" % utils . splitext_plus ( orig_file ) [ 0 ] if not utils . file_uptodate ( out_file , orig_file ) : with file... | Annotate a VCF file with dbSNP . |
29,323 | def get_context_files ( data ) : ref_file = dd . get_ref_file ( data ) all_files = [ ] for ext in [ ".bed.gz" ] : all_files += sorted ( glob . glob ( os . path . normpath ( os . path . join ( os . path . dirname ( ref_file ) , os . pardir , "coverage" , "problem_regions" , "*" , "*%s" % ext ) ) ) ) return sorted ( all_... | Retrieve pre - installed annotation files for annotating genome context . |
29,324 | def add_genome_context ( orig_file , data ) : out_file = "%s-context.vcf.gz" % utils . splitext_plus ( orig_file ) [ 0 ] if not utils . file_uptodate ( out_file , orig_file ) : with file_transaction ( data , out_file ) as tx_out_file : config_file = "%s.toml" % ( utils . splitext_plus ( tx_out_file ) [ 0 ] ) with open ... | Annotate a file with annotations of genome context using vcfanno . |
29,325 | def _submit_and_wait ( cmd , cores , config , output_dir ) : batch_script = "submit_bcl2fastq.sh" if not os . path . exists ( batch_script + ".finished" ) : if os . path . exists ( batch_script + ".failed" ) : os . remove ( batch_script + ".failed" ) with open ( batch_script , "w" ) as out_handle : out_handle . write (... | Submit command with batch script specified in configuration wait until finished |
29,326 | def _prep_items_from_base ( base , in_files , metadata , separators , force_single = False ) : details = [ ] in_files = _expand_dirs ( in_files , KNOWN_EXTS ) in_files = _expand_wildcards ( in_files ) ext_groups = collections . defaultdict ( list ) for ext , files in itertools . groupby ( in_files , lambda x : KNOWN_EX... | Prepare a set of configuration items for input files . |
29,327 | def _find_glob_matches ( in_files , metadata ) : reg_files = copy . deepcopy ( in_files ) glob_files = [ ] for glob_search in [ x for x in metadata . keys ( ) if "*" in x ] : cur = [ ] for fname in in_files : if fnmatch . fnmatch ( fname , "*/%s" % glob_search ) : cur . append ( fname ) reg_files . remove ( fname ) ass... | Group files that match by globs for merging rather than by explicit pairs . |
29,328 | def name_to_config ( template ) : if objectstore . is_remote ( template ) : with objectstore . open_file ( template ) as in_handle : config = yaml . safe_load ( in_handle ) with objectstore . open_file ( template ) as in_handle : txt_config = in_handle . read ( ) elif os . path . isfile ( template ) : if template . end... | Read template file into a dictionary to use as base for all samples . |
29,329 | def _write_config_file ( items , global_vars , template , project_name , out_dir , remotes ) : config_dir = utils . safe_makedir ( os . path . join ( out_dir , "config" ) ) out_config_file = os . path . join ( config_dir , "%s.yaml" % project_name ) out = { "fc_name" : project_name , "upload" : { "dir" : "../final" } ,... | Write configuration file adding required top level attributes . |
29,330 | def _set_global_vars ( metadata ) : fnames = collections . defaultdict ( list ) for sample in metadata . keys ( ) : for k , v in metadata [ sample ] . items ( ) : if isinstance ( v , six . string_types ) and os . path . isfile ( v ) : v = _expand_file ( v ) metadata [ sample ] [ k ] = v fnames [ v ] . append ( k ) glob... | Identify files used multiple times in metadata and replace with global variables |
29,331 | def _clean_string ( v , sinfo ) : if isinstance ( v , ( list , tuple ) ) : return [ _clean_string ( x , sinfo ) for x in v ] else : assert isinstance ( v , six . string_types ) , v try : if hasattr ( v , "decode" ) : return str ( v . decode ( "ascii" ) ) else : return str ( v . encode ( "ascii" ) . decode ( "ascii" ) )... | Test for and clean unicode present in template CSVs . |
29,332 | def _parse_metadata ( in_handle ) : metadata = { } reader = csv . reader ( in_handle ) while 1 : header = next ( reader ) if not header [ 0 ] . startswith ( "#" ) : break keys = [ x . strip ( ) for x in header [ 1 : ] ] for sinfo in ( x for x in reader if x and not x [ 0 ] . startswith ( "#" ) ) : sinfo = [ _strip_and_... | Reads metadata from a simple CSV structured input file . |
29,333 | def _pname_and_metadata ( in_file ) : if os . path . isfile ( in_file ) : with open ( in_file ) as in_handle : md , global_vars = _parse_metadata ( in_handle ) base = os . path . splitext ( os . path . basename ( in_file ) ) [ 0 ] md_file = in_file elif objectstore . is_remote ( in_file ) : with objectstore . open_file... | Retrieve metadata and project name from the input metadata CSV file . |
29,334 | def _handle_special_yaml_cases ( v ) : if "::" in v : out = { } for part in v . split ( "::" ) : k_part , v_part = part . split ( ":" ) out [ k_part ] = v_part . split ( ";" ) v = out elif ";" in v : v = [ x for x in v . split ( ";" ) if x != "" ] elif isinstance ( v , list ) : v = v else : try : v = int ( v ) except V... | Handle values that pass integer boolean list or dictionary values . |
29,335 | def _add_ped_metadata ( name , metadata ) : ignore = set ( [ "-9" , "undefined" , "unknown" , "." ] ) def _ped_mapping ( x , valmap ) : try : x = int ( x ) except ValueError : x = - 1 for k , v in valmap . items ( ) : if k == x : return v return None def _ped_to_gender ( x ) : return _ped_mapping ( x , { 1 : "male" , 2... | Add standard PED file attributes into metadata if not present . |
29,336 | def _add_metadata ( item , metadata , remotes , only_metadata = False ) : for check_key in [ item [ "description" ] ] + _get_file_keys ( item ) + _get_vrn_keys ( item ) : item_md = metadata . get ( check_key ) if item_md : break if not item_md : item_md = _find_glob_metadata ( item [ "files" ] , metadata ) if remotes .... | Add metadata information from CSV file to current item . |
29,337 | def _retrieve_remote ( fnames ) : for fname in fnames : if objectstore . is_remote ( fname ) : inputs = [ ] regions = [ ] remote_base = os . path . dirname ( fname ) for rfname in objectstore . list ( remote_base ) : if rfname . endswith ( tuple ( KNOWN_EXTS . keys ( ) ) ) : inputs . append ( rfname ) elif rfname . end... | Retrieve remote inputs found in the same bucket as the template or metadata files . |
29,338 | def _convert_to_relpaths ( data , work_dir ) : work_dir = os . path . abspath ( work_dir ) data [ "files" ] = [ os . path . relpath ( f , work_dir ) for f in data [ "files" ] ] for topk in [ "metadata" , "algorithm" ] : for k , v in data [ topk ] . items ( ) : if isinstance ( v , six . string_types ) and os . path . is... | Convert absolute paths in the input data to relative paths to the work directory . |
29,339 | def _check_all_metadata_found ( metadata , items ) : for name in metadata : seen = False for sample in items : check_file = sample [ "files" ] [ 0 ] if sample . get ( "files" ) else sample [ "vrn_file" ] if isinstance ( name , ( tuple , list ) ) : if check_file . find ( name [ 0 ] ) > - 1 : seen = True elif check_file ... | Print warning if samples in CSV file are missing in folder |
29,340 | def _copy_to_configdir ( items , out_dir , args ) : out = [ ] for item in items : ped_file = tz . get_in ( [ "metadata" , "ped" ] , item ) if ped_file and os . path . exists ( ped_file ) : ped_config_file = os . path . join ( out_dir , "config" , os . path . basename ( ped_file ) ) if not os . path . exists ( ped_confi... | Copy configuration files like PED inputs to working config directory . |
29,341 | def load_system_config ( config_file = None , work_dir = None , allow_missing = False ) : docker_config = _get_docker_config ( ) if config_file is None : config_file = "bcbio_system.yaml" if not os . path . exists ( config_file ) : base_dir = get_base_installdir ( ) test_config = os . path . join ( base_dir , "galaxy" ... | Load bcbio_system . yaml configuration file handling standard defaults . |
29,342 | def _merge_system_configs ( host_config , container_config , out_file = None ) : out = copy . deepcopy ( container_config ) for k , v in host_config . items ( ) : if k in set ( [ "galaxy_config" ] ) : out [ k ] = v elif k == "resources" : for pname , resources in v . items ( ) : if not isinstance ( resources , dict ) a... | Create a merged system configuration from external and internal specification . |
29,343 | def merge_resources ( args ) : docker_config = _get_docker_config ( ) if not docker_config : return args else : def _update_resources ( config ) : config [ "resources" ] = _merge_system_configs ( config , docker_config ) [ "resources" ] return config return _update_config ( args , _update_resources , allow_missing = Tr... | Merge docker local resources and global resource specification in a set of arguments . |
29,344 | def load_config ( config_file ) : with open ( config_file ) as in_handle : config = yaml . safe_load ( in_handle ) config = _expand_paths ( config ) if 'resources' not in config : config [ 'resources' ] = { } newr = { } for k , v in config [ "resources" ] . items ( ) : if k . lower ( ) != k : newr [ k . lower ( ) ] = v... | Load YAML config file replacing environmental variables . |
29,345 | def get_resources ( name , config ) : return tz . get_in ( [ "resources" , name ] , config , tz . get_in ( [ "resources" , "default" ] , config , { } ) ) | Retrieve resources for a program pulling from multiple config sources . |
29,346 | def get_program ( name , config , ptype = "cmd" , default = None ) : config = config . get ( "config" , config ) try : pconfig = config . get ( "resources" , { } ) [ name ] except KeyError : pconfig = { } old_config = config . get ( "program" , { } ) . get ( name , None ) if old_config : for key in [ "dir" , "cmd" ] : ... | Retrieve program information from the configuration . |
29,347 | def _get_program_cmd ( name , pconfig , config , default ) : if pconfig is None : return name elif isinstance ( pconfig , six . string_types ) : return pconfig elif "cmd" in pconfig : return pconfig [ "cmd" ] elif default is not None : return default else : return name | Retrieve commandline of a program . |
29,348 | def get_jar ( base_name , dname ) : jars = glob . glob ( os . path . join ( expand_path ( dname ) , "%s*.jar" % base_name ) ) if len ( jars ) == 1 : return jars [ 0 ] elif len ( jars ) > 1 : raise ValueError ( "Found multiple jars for %s in %s. Need single jar: %s" % ( base_name , dname , jars ) ) else : raise ValueErr... | Retrieve a jar in the provided directory |
29,349 | def get_algorithm_config ( xs ) : if isinstance ( xs , dict ) : xs = [ xs ] for x in xs : if is_std_config_arg ( x ) : return x [ "algorithm" ] elif is_nested_config_arg ( x ) : return x [ "config" ] [ "algorithm" ] elif isinstance ( x , ( list , tuple ) ) and is_nested_config_arg ( x [ 0 ] ) : return x [ 0 ] [ "config... | Flexibly extract algorithm configuration for a sample from any function arguments . |
29,350 | def get_dataarg ( args ) : for i , arg in enumerate ( args ) : if is_nested_config_arg ( arg ) : return i , arg elif is_std_config_arg ( arg ) : return i , { "config" : arg } elif isinstance ( arg , ( list , tuple ) ) and is_nested_config_arg ( arg [ 0 ] ) : return i , arg [ 0 ] raise ValueError ( "Did not find configu... | Retrieve the world data argument from a set of input parameters . |
29,351 | def add_cores_to_config ( args , cores_per_job , parallel = None ) : def _update_cores ( config ) : config [ "algorithm" ] [ "num_cores" ] = int ( cores_per_job ) if parallel : parallel . pop ( "view" , None ) config [ "parallel" ] = parallel return config return _update_config ( args , _update_cores ) | Add information about available cores for a job to configuration . Ugly hack to update core information in a configuration dictionary . |
29,352 | def _update_config ( args , update_fn , allow_missing = False ) : new_i = None for i , arg in enumerate ( args ) : if ( is_std_config_arg ( arg ) or is_nested_config_arg ( arg ) or ( isinstance ( arg , ( list , tuple ) ) and is_nested_config_arg ( arg [ 0 ] ) ) ) : new_i = i break if new_i is None : if allow_missing : ... | Update configuration nested in argument list with the provided update function . |
29,353 | def convert_to_bytes ( mem_str ) : if str ( mem_str ) [ - 1 ] . upper ( ) . endswith ( "G" ) : return int ( round ( float ( mem_str [ : - 1 ] ) * 1024 * 1024 ) ) elif str ( mem_str ) [ - 1 ] . upper ( ) . endswith ( "M" ) : return int ( round ( float ( mem_str [ : - 1 ] ) * 1024 ) ) else : return int ( round ( float ( ... | Convert a memory specification potentially with M or G into bytes . |
29,354 | def adjust_memory ( val , magnitude , direction = "increase" , out_modifier = "" , maximum = None ) : modifier = val [ - 1 : ] amount = float ( val [ : - 1 ] ) if direction == "decrease" : new_amount = amount / float ( magnitude ) if new_amount < 1 or ( out_modifier . upper ( ) . startswith ( "M" ) and modifier . upper... | Adjust memory based on number of cores utilized . |
29,355 | def adjust_opts ( in_opts , config ) : memory_adjust = config [ "algorithm" ] . get ( "memory_adjust" , { } ) out_opts = [ ] for opt in in_opts : if opt . startswith ( "-Xmx" ) or ( opt . startswith ( "-Xms" ) and memory_adjust . get ( "direction" ) == "decrease" ) : arg = opt [ : 4 ] opt = "{arg}{val}" . format ( arg ... | Establish JVM opts adjusting memory for the context if needed . |
29,356 | def use_vqsr ( algs , call_file = None ) : from bcbio . variation import vcfutils vqsr_callers = set ( [ "gatk" , "gatk-haplotype" ] ) vqsr_sample_thresh = 50 vqsr_supported = collections . defaultdict ( int ) coverage_intervals = set ( [ ] ) for alg in algs : callers = alg . get ( "variantcaller" ) if isinstance ( cal... | Processing uses GATK s Variant Quality Score Recalibration . |
29,357 | def use_bcbio_variation_recall ( algs ) : for alg in algs : jointcaller = alg . get ( "jointcaller" , [ ] ) if not isinstance ( jointcaller , ( tuple , list ) ) : jointcaller = [ jointcaller ] for caller in jointcaller : if caller not in set ( [ "gatk-haplotype-joint" , None , False ] ) : return True return False | Processing uses bcbio - variation - recall . Avoids core requirement if not used . |
29,358 | def program_installed ( program , data ) : try : path = get_program ( program , data ) except CmdNotFound : return False return True | returns True if the path to a program can be found |
29,359 | def samtools ( items ) : samtools = config_utils . get_program ( "samtools" , items [ 0 ] [ "config" ] ) p = subprocess . Popen ( [ samtools , "sort" , "-h" ] , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) output , stderr = p . communicate ( ) p . stdout . close ( ) p . stderr . close ( ) if str ( output )... | Ensure samtools has parallel processing required for piped analysis . |
29,360 | def _needs_java ( data ) : vc = dd . get_variantcaller ( data ) if isinstance ( vc , dict ) : out = { } for k , v in vc . items ( ) : if not isinstance ( v , ( list , tuple ) ) : v = [ v ] out [ k ] = v vc = out elif not isinstance ( vc , ( list , tuple ) ) : vc = [ vc ] if "mutect" in vc or ( "somatic" in vc and "mute... | Check if a caller needs external java for MuTect . |
29,361 | def java ( items ) : if any ( [ _needs_java ( d ) for d in items ] ) : min_version = "1.7" max_version = "1.8" with setpath . orig_paths ( ) : java = utils . which ( "java" ) if not java : return ( "java not found on PATH. Java %s required for MuTect and GATK < 3.6." % min_version ) p = subprocess . Popen ( [ java , "-... | Check for presence of external Java 1 . 7 for tools that require it . |
29,362 | def upgrade_bcbio ( args ) : print ( "Upgrading bcbio" ) args = add_install_defaults ( args ) if args . upgrade in [ "stable" , "system" , "deps" , "development" ] : if args . upgrade == "development" : anaconda_dir = _update_conda_devel ( ) _check_for_conda_problems ( ) print ( "Upgrading bcbio-nextgen to latest devel... | Perform upgrade of bcbio to latest release or from GitHub development version . |
29,363 | def _pip_safe_ssl ( cmds , anaconda_dir ) : try : for cmd in cmds : subprocess . check_call ( cmd ) except subprocess . CalledProcessError : _set_pip_ssl ( anaconda_dir ) for cmd in cmds : subprocess . check_call ( cmd ) | Run pip retrying with conda SSL certificate if global certificate fails . |
29,364 | def _set_pip_ssl ( anaconda_dir ) : if anaconda_dir : cert_file = os . path . join ( anaconda_dir , "ssl" , "cert.pem" ) if os . path . exists ( cert_file ) : os . environ [ "PIP_CERT" ] = cert_file | Set PIP SSL certificate to installed conda certificate to avoid SSL errors |
29,365 | def _set_matplotlib_default_backend ( ) : if _matplotlib_installed ( ) : import matplotlib matplotlib . use ( 'Agg' , force = True ) config = matplotlib . matplotlib_fname ( ) if os . access ( config , os . W_OK ) : with file_transaction ( config ) as tx_out_file : with open ( config ) as in_file , open ( tx_out_file ,... | matplotlib will try to print to a display if it is available but don t want to run it in interactive mode . we tried setting the backend to Agg before importing but it was still resulting in issues . we replace the existing backend with agg in the default matplotlibrc . This is a hack until we can find a better solutio... |
29,366 | def _symlink_bcbio ( args , script = "bcbio_nextgen.py" , env_name = None , prefix = None ) : if env_name : bcbio_anaconda = os . path . join ( os . path . dirname ( os . path . dirname ( os . path . realpath ( sys . executable ) ) ) , "envs" , env_name , "bin" , script ) else : bcbio_anaconda = os . path . join ( os .... | Ensure a bcbio - nextgen script symlink in final tool directory . |
29,367 | def _install_container_bcbio_system ( datadir ) : base_file = os . path . join ( datadir , "config" , "bcbio_system.yaml" ) if not os . path . exists ( base_file ) : return expose_file = os . path . join ( datadir , "galaxy" , "bcbio_system.yaml" ) expose = set ( [ "memory" , "cores" , "jvm_opts" ] ) with open ( base_f... | Install limited bcbio_system . yaml file for setting core and memory usage . |
29,368 | def _check_for_conda_problems ( ) : conda_bin = _get_conda_bin ( ) channels = _get_conda_channels ( conda_bin ) lib_dir = os . path . join ( os . path . dirname ( conda_bin ) , os . pardir , "lib" ) for l in [ "libgomp.so.1" , "libquadmath.so" ] : if not os . path . exists ( os . path . join ( lib_dir , l ) ) : subproc... | Identify post - install conda problems and fix . |
29,369 | def _update_bcbiovm ( ) : print ( "## CWL support with bcbio-vm" ) python_env = "python=3" conda_bin , env_name = _add_environment ( "bcbiovm" , python_env ) channels = _get_conda_channels ( conda_bin ) base_cmd = [ conda_bin , "install" , "--yes" , "--name" , env_name ] + channels subprocess . check_call ( base_cmd + ... | Update or install a local bcbiovm install with tools and dependencies . |
29,370 | def _get_conda_channels ( conda_bin ) : channels = [ "bioconda" , "conda-forge" ] out = [ ] config = yaml . safe_load ( subprocess . check_output ( [ conda_bin , "config" , "--show" ] ) ) for c in channels : present = False for orig_c in config . get ( "channels" ) or [ ] : if orig_c . endswith ( ( c , "%s/" % c ) ) : ... | Retrieve default conda channels checking if they are pre - specified in config . |
29,371 | def _update_conda_packages ( ) : conda_bin = _get_conda_bin ( ) channels = _get_conda_channels ( conda_bin ) assert conda_bin , ( "Could not find anaconda distribution for upgrading bcbio.\n" "Using python at %s but could not find conda." % ( os . path . realpath ( sys . executable ) ) ) req_file = "bcbio-update-requir... | If installed in an anaconda directory upgrade conda packages . |
29,372 | def _update_conda_devel ( ) : conda_bin = _get_conda_bin ( ) channels = _get_conda_channels ( conda_bin ) assert conda_bin , "Could not find anaconda distribution for upgrading bcbio" subprocess . check_call ( [ conda_bin , "install" , "--quiet" , "--yes" ] + channels + [ "bcbio-nextgen>=%s" % version . __version__ . r... | Update to the latest development conda package . |
29,373 | def get_genome_dir ( gid , galaxy_dir , data ) : if galaxy_dir : refs = genome . get_refs ( gid , None , galaxy_dir , data ) seq_file = tz . get_in ( [ "fasta" , "base" ] , refs ) if seq_file and os . path . exists ( seq_file ) : return os . path . dirname ( os . path . dirname ( seq_file ) ) else : gdirs = glob . glob... | Return standard location of genome directories . |
29,374 | def _prepare_cwl_tarballs ( data_dir ) : for dbref_dir in filter ( os . path . isdir , glob . glob ( os . path . join ( data_dir , "genomes" , "*" , "*" ) ) ) : base_dir , dbref = os . path . split ( dbref_dir ) for indexdir in TARBALL_DIRECTORIES : cur_target = os . path . join ( dbref_dir , indexdir ) if os . path . ... | Create CWL ready tarballs for complex directories . |
29,375 | def _upgrade_genome_resources ( galaxy_dir , base_url ) : import requests for dbkey , ref_file in genome . get_builds ( galaxy_dir ) : remote_url = base_url % dbkey requests . packages . urllib3 . disable_warnings ( ) r = requests . get ( remote_url , verify = False ) if r . status_code == requests . codes . ok : local... | Retrieve latest version of genome resource YAML configuration files . |
29,376 | def _upgrade_snpeff_data ( galaxy_dir , args , remotes ) : snpeff_version = effects . snpeff_version ( args ) if not snpeff_version : return for dbkey , ref_file in genome . get_builds ( galaxy_dir ) : resource_file = os . path . join ( os . path . dirname ( ref_file ) , "%s-resources.yaml" % dbkey ) if os . path . exi... | Install or upgrade snpEff databases localized to reference directory . |
29,377 | def _is_old_database ( db_dir , args ) : snpeff_version = effects . snpeff_version ( args ) if LooseVersion ( snpeff_version ) >= LooseVersion ( "4.1" ) : pred_file = os . path . join ( db_dir , "snpEffectPredictor.bin" ) if not utils . file_exists ( pred_file ) : return True with utils . open_gzipsafe ( pred_file , is... | Check for old database versions supported in snpEff 4 . 1 . |
29,378 | def _get_biodata ( base_file , args ) : with open ( base_file ) as in_handle : config = yaml . safe_load ( in_handle ) config [ "install_liftover" ] = False config [ "genome_indexes" ] = args . aligners ann_groups = config . pop ( "annotation_groups" , { } ) config [ "genomes" ] = [ _setup_genome_annotations ( g , args... | Retrieve biodata genome targets customized by install parameters . |
29,379 | def _setup_genome_annotations ( g , args , ann_groups ) : available_anns = g . get ( "annotations" , [ ] ) + g . pop ( "annotations_available" , [ ] ) anns = [ ] for orig_target in args . datatarget : if orig_target in ann_groups : targets = ann_groups [ orig_target ] else : targets = [ orig_target ] for target in targ... | Configure genome annotations to install based on datatarget . |
29,380 | def upgrade_thirdparty_tools ( args , remotes ) : cbl = get_cloudbiolinux ( remotes ) if args . toolconf and os . path . exists ( args . toolconf ) : package_yaml = args . toolconf else : package_yaml = os . path . join ( cbl [ "dir" ] , "contrib" , "flavor" , "ngs_pipeline_minimal" , "packages-conda.yaml" ) sys . path... | Install and update third party tools used in the pipeline . |
29,381 | def _install_toolplus ( args ) : manifest_dir = os . path . join ( _get_data_dir ( ) , "manifest" ) toolplus_manifest = os . path . join ( manifest_dir , "toolplus-packages.yaml" ) system_config = os . path . join ( _get_data_dir ( ) , "galaxy" , "bcbio_system.yaml" ) if not os . path . exists ( system_config ) : docke... | Install additional tools we cannot distribute updating local manifest . |
29,382 | def _install_gatk_jar ( name , fname , manifest , system_config , toolplus_dir ) : if not fname . endswith ( ".jar" ) : raise ValueError ( "--toolplus argument for %s expects a jar file: %s" % ( name , fname ) ) version = get_gatk_jar_version ( name , fname ) store_dir = utils . safe_makedir ( os . path . join ( toolpl... | Install a jar for GATK or associated tools like MuTect . |
29,383 | def _update_manifest ( manifest_file , name , version ) : if os . path . exists ( manifest_file ) : with open ( manifest_file ) as in_handle : manifest = yaml . safe_load ( in_handle ) else : manifest = { } manifest [ name ] = { "name" : name , "version" : version } with open ( manifest_file , "w" ) as out_handle : yam... | Update the toolplus manifest file with updated name and version |
29,384 | def _update_system_file ( system_file , name , new_kvs ) : if os . path . exists ( system_file ) : bak_file = system_file + ".bak%s" % datetime . datetime . now ( ) . strftime ( "%Y-%m-%d-%H-%M-%S" ) shutil . copyfile ( system_file , bak_file ) with open ( system_file ) as in_handle : config = yaml . safe_load ( in_han... | Update the bcbio_system . yaml file with new resource information . |
29,385 | def _install_kraken_db ( datadir , args ) : import requests kraken = os . path . join ( datadir , "genomes/kraken" ) url = "https://ccb.jhu.edu/software/kraken/dl/minikraken.tgz" compress = os . path . join ( kraken , os . path . basename ( url ) ) base , ext = utils . splitext_plus ( os . path . basename ( url ) ) db ... | Install kraken minimal DB in genome folder . |
29,386 | def _get_install_config ( ) : try : data_dir = _get_data_dir ( ) except ValueError : return None config_dir = utils . safe_makedir ( os . path . join ( data_dir , "config" ) ) return os . path . join ( config_dir , "install-params.yaml" ) | Return the YAML configuration file used to store upgrade information . |
29,387 | def save_install_defaults ( args ) : install_config = _get_install_config ( ) if install_config is None : return if utils . file_exists ( install_config ) : with open ( install_config ) as in_handle : cur_config = yaml . safe_load ( in_handle ) else : cur_config = { } if args . tooldir : cur_config [ "tooldir" ] = args... | Save installation information to make future upgrades easier . |
29,388 | def add_install_defaults ( args ) : if len ( args . genomes ) > 0 or len ( args . aligners ) > 0 or len ( args . datatarget ) > 0 : args . install_data = True install_config = _get_install_config ( ) if install_config is None or not utils . file_exists ( install_config ) : default_args = { } else : with open ( install_... | Add any saved installation defaults to the upgrade . |
29,389 | def _datatarget_defaults ( args , default_args ) : default_data = default_args . get ( "datatarget" , [ ] ) for x in default_args . get ( "toolplus" , [ ] ) : val = None if x == "data" : val = "gemini" elif x in [ "cadd" , "dbnsfp" , "dbscsnv" , "kraken" , "gnomad" ] : val = x if val and val not in default_data : defau... | Set data installation targets handling defaults . |
29,390 | def _merge_wf_inputs ( new , out , wf_outputs , to_ignore , parallel , nested_inputs ) : internal_generated_ids = [ ] for vignore in to_ignore : vignore_id = _get_string_vid ( vignore ) if vignore_id not in [ v [ "id" ] for v in wf_outputs ] : internal_generated_ids . append ( vignore_id ) ignore_ids = set ( internal_g... | Merge inputs for a sub - workflow adding any not present inputs in out . |
29,391 | def _merge_wf_outputs ( new , cur , parallel ) : new_ids = set ( [ ] ) out = [ ] for v in new : outv = { } outv [ "source" ] = v [ "id" ] outv [ "id" ] = "%s" % get_base_id ( v [ "id" ] ) outv [ "type" ] = v [ "type" ] if "secondaryFiles" in v : outv [ "secondaryFiles" ] = v [ "secondaryFiles" ] if tz . get_in ( [ "out... | Merge outputs for a sub - workflow replacing variables changed in later steps . |
29,392 | def _extract_from_subworkflow ( vs , step ) : substep_ids = set ( [ x . name for x in step . workflow ] ) out = [ ] for var in vs : internal = False parts = var [ "id" ] . split ( "/" ) if len ( parts ) > 1 : if parts [ 0 ] in substep_ids : internal = True if not internal : var . pop ( "source" , None ) out . append ( ... | Remove internal variable names when moving from sub - workflow to main . |
29,393 | def is_cwl_record ( d ) : if isinstance ( d , dict ) : if d . get ( "type" ) == "record" : return d else : recs = list ( filter ( lambda x : x is not None , [ is_cwl_record ( v ) for v in d . values ( ) ] ) ) return recs [ 0 ] if recs else None else : return None | Check if an input is a CWL record from any level of nesting . |
29,394 | def _get_step_inputs ( step , file_vs , std_vs , parallel_ids , wf = None ) : inputs = [ ] skip_inputs = set ( [ ] ) for orig_input in [ _get_variable ( x , file_vs ) for x in _handle_special_inputs ( step . inputs , file_vs ) ] : inputs . append ( orig_input ) if not any ( is_cwl_record ( x ) for x in inputs ) : input... | Retrieve inputs for a step from existing variables . |
29,395 | def _nest_variable ( v , check_records = False ) : if ( check_records and is_cwl_record ( v ) and len ( v [ "id" ] . split ( "/" ) ) > 1 and v . get ( "type" , { } ) . get ( "type" ) == "array" ) : return v else : v = copy . deepcopy ( v ) v [ "type" ] = { "type" : "array" , "items" : v [ "type" ] } return v | Nest a variable when moving from scattered back to consolidated . |
29,396 | def _clean_output ( v ) : out = copy . deepcopy ( v ) outb = out . pop ( "outputBinding" , { } ) if "secondaryFiles" in outb : out [ "secondaryFiles" ] = outb [ "secondaryFiles" ] return out | Remove output specific variables to allow variables to be inputs to next steps . |
29,397 | def _get_variable ( vid , variables ) : if isinstance ( vid , six . string_types ) : vid = get_base_id ( vid ) else : vid = _get_string_vid ( vid ) for v in variables : if vid == get_base_id ( v [ "id" ] ) : return copy . deepcopy ( v ) raise ValueError ( "Did not find variable %s in \n%s" % ( vid , pprint . pformat ( ... | Retrieve an input variable from our existing pool of options . |
29,398 | def _handle_special_inputs ( inputs , variables ) : from bcbio import structural optional = [ [ "config" , "algorithm" , "coverage" ] , [ "config" , "algorithm" , "variant_regions" ] , [ "config" , "algorithm" , "sv_regions" ] , [ "config" , "algorithm" , "validate" ] , [ "config" , "algorithm" , "validate_regions" ] ]... | Adjust input variables based on special cases . |
29,399 | def _create_record ( name , field_defs , step_name , inputs , unlist , file_vs , std_vs , parallel ) : if field_defs : fields = [ ] inherit = [ ] inherit_all = False inherit_exclude = [ ] for fdef in field_defs : if not fdef . get ( "type" ) : if fdef [ "id" ] == "inherit" : inherit_all = True inherit_exclude = fdef . ... | Create an output record by rearranging inputs . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.