idx int64 0 63k | question stringlengths 61 4.03k | target stringlengths 6 1.23k |
|---|---|---|
29,400 | def _infer_record_outputs ( inputs , unlist , file_vs , std_vs , parallel , to_include = None , exclude = None ) : fields = [ ] unlist = set ( [ _get_string_vid ( x ) for x in unlist ] ) input_vids = set ( [ _get_string_vid ( v ) for v in _handle_special_inputs ( inputs , file_vs ) ] ) to_include = set ( [ _get_string_... | Infer the outputs of a record from the original inputs |
29,401 | def _create_variable ( orig_v , step , variables ) : try : v = _get_variable ( orig_v [ "id" ] , variables ) except ValueError : v = copy . deepcopy ( orig_v ) if not isinstance ( v [ "id" ] , six . string_types ) : v [ "id" ] = _get_string_vid ( v [ "id" ] ) for key , val in orig_v . items ( ) : if key not in [ "id" ,... | Create a new output variable potentially over - writing existing or creating new . |
29,402 | def _merge_variables ( new , cur ) : new_added = set ( [ ] ) out = [ ] for cur_var in cur : updated = False for new_var in new : if get_base_id ( new_var [ "id" ] ) == get_base_id ( cur_var [ "id" ] ) : out . append ( new_var ) new_added . add ( new_var [ "id" ] ) updated = True break if not updated : out . append ( cu... | Add any new variables to the world representation in cur . |
29,403 | def split ( * items ) : out = [ ] for data in [ x [ 0 ] for x in items ] : dis_orgs = data [ "config" ] [ "algorithm" ] . get ( "disambiguate" ) if dis_orgs : if not data . get ( "disambiguate" , None ) : data [ "disambiguate" ] = { "genome_build" : data [ "genome_build" ] , "base" : True } out . append ( [ data ] ) if... | Split samples into all possible genomes for alignment . |
29,404 | def resolve ( items , run_parallel ) : out = [ ] to_process = collections . defaultdict ( list ) for data in [ x [ 0 ] for x in items ] : if "disambiguate" in data : split_part = tuple ( [ int ( x ) for x in data [ "align_split" ] . split ( "-" ) ] ) if data . get ( "combine" ) else None to_process [ ( dd . get_sample_... | Combine aligned and split samples into final set of disambiguated reads . |
29,405 | def merge_extras ( items , config ) : final = { } for extra_name in items [ 0 ] [ "disambiguate" ] . keys ( ) : in_files = [ ] for data in items : in_files . append ( data [ "disambiguate" ] [ extra_name ] ) out_file = "%s-allmerged%s" % os . path . splitext ( in_files [ 0 ] ) if in_files [ 0 ] . endswith ( ".bam" ) : ... | Merge extra disambiguated reads into a final BAM file . |
29,406 | def _merge_summary ( in_files , out_file , data ) : if not utils . file_exists ( out_file ) : with file_transaction ( data , out_file ) as tx_out_file : with open ( tx_out_file , "w" ) as out_handle : for i , in_file in enumerate ( in_files ) : with open ( in_file ) as in_handle : for j , line in enumerate ( in_handle ... | Create one big summary file for disambiguation from multiple splits . |
29,407 | def _run_python ( work_bam_a , work_bam_b , out_dir , aligner , prefix , items ) : Args = collections . namedtuple ( "Args" , "A B output_dir intermediate_dir " "no_sort prefix aligner" ) args = Args ( work_bam_a , work_bam_b , out_dir , out_dir , True , "" , aligner ) disambiguate_main ( args ) | Run python version of disambiguation |
29,408 | def run ( args ) : dirs , config , run_info_yaml = run_info . prep_system ( args . sample_config , args . systemconfig ) integrations = args . integrations if hasattr ( args , "integrations" ) else { } world = run_info . organize ( dirs , config , run_info_yaml , is_cwl = True , integrations = integrations ) create . f... | Run a CWL preparation pipeline . |
29,409 | def assign_interval ( data ) : if not dd . get_coverage_interval ( data ) : vrs = dd . get_variant_regions_merged ( data ) callable_file = dd . get_sample_callable ( data ) if vrs : callable_size = pybedtools . BedTool ( vrs ) . total_coverage ( ) else : callable_size = pybedtools . BedTool ( callable_file ) . total_co... | Identify coverage based on percent of genome covered and relation to targets . |
29,410 | def calculate ( bam_file , data , sv_bed ) : params = { "min" : dd . get_coverage_depth_min ( data ) } variant_regions = dd . get_variant_regions_merged ( data ) if not variant_regions : variant_regions = _create_genome_regions ( data ) callable_file = os . path . join ( utils . safe_makedir ( os . path . join ( dd . g... | Calculate coverage in parallel using mosdepth . |
29,411 | def _create_genome_regions ( data ) : work_dir = utils . safe_makedir ( os . path . join ( dd . get_work_dir ( data ) , "coverage" , dd . get_sample_name ( data ) ) ) variant_regions = os . path . join ( work_dir , "target-genome.bed" ) with file_transaction ( data , variant_regions ) as tx_variant_regions : with open ... | Create whole genome contigs we want to process only non - alts . |
29,412 | def _subset_to_variant_regions ( callable_file , variant_regions , data ) : out_file = "%s-vrsubset.bed" % utils . splitext_plus ( callable_file ) [ 0 ] if not utils . file_uptodate ( out_file , callable_file ) : with file_transaction ( data , out_file ) as tx_out_file : with utils . open_gzipsafe ( callable_file ) as ... | Subset output callable file to only variant regions of interest . |
29,413 | def _average_genome_coverage ( data , bam_file ) : total = sum ( [ c . size for c in ref . file_contigs ( dd . get_ref_file ( data ) , data [ "config" ] ) ] ) read_counts = sum ( x . aligned for x in bam . idxstats ( bam_file , data ) ) with pysam . Samfile ( bam_file , "rb" ) as pysam_bam : read_size = np . median ( l... | Quickly calculate average coverage for whole genome files using indices . |
29,414 | def regions_coverage ( bed_file , target_name , data ) : ready_bed = tz . get_in ( [ "depth" , target_name , "regions" ] , data ) if ready_bed : return ready_bed else : return run_mosdepth ( data , target_name , bed_file ) . regions | Generate coverage over regions of interest using mosdepth . |
29,415 | def coverage_region_detailed_stats ( target_name , bed_file , data , out_dir ) : if bed_file and utils . file_exists ( bed_file ) : ready_depth = tz . get_in ( [ "depth" , target_name ] , data ) if ready_depth : cov_file = ready_depth [ "regions" ] dist_file = ready_depth [ "dist" ] thresholds_file = ready_depth . get ... | Calculate coverage at different completeness cutoff for region in coverage option . |
29,416 | def get_coords ( data ) : for category , vtypes in [ ( "LOH" , { "LOSS" , "HETEROZYGOSITY" } ) , ( "amplification" , { "AMPLIFICATION" } ) ] : out = tz . get_in ( [ category , dd . get_genome_build ( data ) ] , _COORDS , { } ) priority_file = dd . get_svprioritize ( data ) if priority_file : if os . path . basename ( p... | Retrieve coordinates of genes of interest for prioritization . |
29,417 | def _civic_regions ( civic_file , variant_types = None , diseases = None , drugs = None ) : if isinstance ( diseases , six . string_types ) : diseases = [ diseases ] with utils . open_gzipsafe ( civic_file ) as in_handle : reader = csv . reader ( in_handle , delimiter = "\t" ) for chrom , start , end , info_str in read... | Retrieve gene regions and names filtered by variant_types and diseases . |
29,418 | def summary_status ( call , data ) : out_file = None if call . get ( "vrn_file" ) and os . path . exists ( call . get ( "vrn_file" ) ) : out_file = os . path . join ( os . path . dirname ( call [ "vrn_file" ] ) , "%s-%s-lohsummary.yaml" % ( dd . get_sample_name ( data ) , call [ "variantcaller" ] ) ) if not utils . fil... | Retrieve status in regions of interest along with heterogeneity metrics . |
29,419 | def _check_copy_number_changes ( svtype , cn , minor_cn , data ) : if svtype == "LOH" and minor_cn == 0 : return svtype elif svtype == "amplification" and cn > dd . get_ploidy ( data ) : return svtype else : return "std" | Check if copy number changes match the expected svtype . |
29,420 | def _titancna_summary ( call , data ) : out = { } for svtype , coords in get_coords ( data ) : cur_calls = { k : collections . defaultdict ( int ) for k in coords . keys ( ) } with open ( call [ "subclones" ] ) as in_handle : header = in_handle . readline ( ) . strip ( ) . split ( ) for line in in_handle : val = dict (... | Summarize purity ploidy and LOH for TitanCNA . |
29,421 | def _purecn_summary ( call , data ) : out = { } for svtype , coords in get_coords ( data ) : cur_calls = { k : collections . defaultdict ( int ) for k in coords . keys ( ) } with open ( call [ "loh" ] ) as in_handle : in_handle . readline ( ) for line in in_handle : _ , chrom , start , end , _ , cn , minor_cn = line . ... | Summarize purity ploidy and LOH for PureCN . |
29,422 | def fix_vcf_line ( parts , ref_base ) : swap = { "1/1" : "0/0" , "0/1" : "0/1" , "0/0" : "1/1" , "./." : "./." } complements = { "G" : "C" , "A" : "T" , "C" : "G" , "T" : "A" , "N" : "N" } varinfo , genotypes = fix_line_problems ( parts ) ref , var = varinfo [ 3 : 5 ] if ref_base in [ None , "N" ] or set ( genotypes ) ... | Orient VCF allele calls with respect to reference base . |
29,423 | def fix_nonref_positions ( in_file , ref_file ) : ignore_chrs = [ "." ] ref2bit = twobit . TwoBitFile ( open ( ref_file ) ) out_file = in_file . replace ( "-raw.vcf" , ".vcf" ) with open ( in_file ) as in_handle : with open ( out_file , "w" ) as out_handle : for line in in_handle : if line . startswith ( "#" ) : out_ha... | Fix Genotyping VCF positions where the bases are all variants . |
29,424 | def run ( items , background = None ) : if not background : background = [ ] names = [ tz . get_in ( [ "rgnames" , "sample" ] , x ) for x in items + background ] work_bams = [ x [ "align_bam" ] for x in items + background ] if len ( items + background ) < 2 : raise ValueError ( "cn.mops only works on batches with multi... | Detect copy number variations from batched set of samples using cn . mops . |
29,425 | def _combine_out_files ( chr_files , work_dir , data ) : out_file = "%s.bed" % sshared . outname_from_inputs ( chr_files ) if not utils . file_exists ( out_file ) : with file_transaction ( data , out_file ) as tx_out_file : with open ( tx_out_file , "w" ) as out_handle : for chr_file in chr_files : with open ( chr_file... | Concatenate all CNV calls into a single file . |
29,426 | def _prep_sample_cnvs ( cnv_file , data ) : import pybedtools sample_name = tz . get_in ( [ "rgnames" , "sample" ] , data ) def make_names ( name ) : return re . sub ( "[^\w.]" , '.' , name ) def matches_sample_name ( feat ) : return ( feat . name == sample_name or feat . name == "X%s" % sample_name or feat . name == m... | Convert a multiple sample CNV file into a single BED file for a sample . |
29,427 | def _run_on_chrom ( chrom , work_bams , names , work_dir , items ) : local_sitelib = utils . R_sitelib ( ) batch = sshared . get_cur_batch ( items ) ext = "-%s-cnv" % batch if batch else "-cnv" out_file = os . path . join ( work_dir , "%s%s-%s.bed" % ( os . path . splitext ( os . path . basename ( work_bams [ 0 ] ) ) [... | Run cn . mops on work BAMs for a specific chromosome . |
29,428 | def _get_regional_bed_file ( data ) : variant_regions = bedutils . merge_overlaps ( tz . get_in ( [ "config" , "algorithm" , "variant_regions" ] , data ) , data ) is_genome = data [ "config" ] [ "algorithm" ] . get ( "coverage_interval" , "exome" ) . lower ( ) in [ "genome" ] if variant_regions and utils . file_exists ... | If we are running a non - genome analysis pull the regional file for analysis . |
29,429 | def _population_load_script ( work_bams , names , chrom , pairmode , items ) : bed_file = _get_regional_bed_file ( items [ 0 ] ) if bed_file : return _population_prep_targeted . format ( bam_file_str = "," . join ( work_bams ) , names_str = "," . join ( names ) , chrom = chrom , num_cores = 0 , pairmode = pairmode , be... | Prepare BAMs for assessing CNVs in a population . |
29,430 | def tobam_cl ( data , out_file , is_paired = False ) : do_dedup = _check_dedup ( data ) umi_consensus = dd . get_umi_consensus ( data ) with file_transaction ( data , out_file ) as tx_out_file : if not do_dedup : yield ( sam_to_sortbam_cl ( data , tx_out_file ) , tx_out_file ) elif umi_consensus : yield ( _sam_to_group... | Prepare command line for producing de - duplicated sorted output . |
29,431 | def _get_cores_memory ( data , downscale = 2 ) : resources = config_utils . get_resources ( "samtools" , data [ "config" ] ) num_cores = data [ "config" ] [ "algorithm" ] . get ( "num_cores" , 1 ) max_mem = config_utils . adjust_memory ( resources . get ( "memory" , "2G" ) , downscale , "decrease" ) . upper ( ) return ... | Retrieve cores and memory using samtools as baseline . |
29,432 | def sam_to_sortbam_cl ( data , tx_out_file , name_sort = False ) : samtools = config_utils . get_program ( "samtools" , data [ "config" ] ) cores , mem = _get_cores_memory ( data , downscale = 2 ) tmp_file = "%s-sorttmp" % utils . splitext_plus ( tx_out_file ) [ 0 ] sort_flag = "-n" if name_sort else "" return ( "{samt... | Convert to sorted BAM output . |
29,433 | def samblaster_dedup_sort ( data , tx_out_file , tx_sr_file , tx_disc_file ) : samblaster = config_utils . get_program ( "samblaster" , data [ "config" ] ) samtools = config_utils . get_program ( "samtools" , data [ "config" ] ) tmp_prefix = "%s-sorttmp" % utils . splitext_plus ( tx_out_file ) [ 0 ] tobam_cmd = ( "{sam... | Deduplicate and sort with samblaster produces split read and discordant pair files . |
29,434 | def _biobambam_dedup_sort ( data , tx_out_file ) : samtools = config_utils . get_program ( "samtools" , data [ "config" ] ) cores , mem = _get_cores_memory ( data , downscale = 2 ) tmp_file = "%s-sorttmp" % utils . splitext_plus ( tx_out_file ) [ 0 ] if data . get ( "align_split" ) : sort_opt = "-n" if data . get ( "al... | Perform streaming deduplication and sorting with biobambam s bamsormadup |
29,435 | def _sam_to_grouped_umi_cl ( data , umi_consensus , tx_out_file ) : tmp_file = "%s-sorttmp" % utils . splitext_plus ( tx_out_file ) [ 0 ] jvm_opts = _get_fgbio_jvm_opts ( data , os . path . dirname ( tmp_file ) , 1 ) cores , mem = _get_cores_memory ( data ) bamsormadup = config_utils . get_program ( "bamsormadup" , dat... | Mark duplicates on aligner output and convert to grouped UMIs by position . |
29,436 | def umi_consensus ( data ) : align_bam = dd . get_work_bam ( data ) umi_method , umi_tag = _check_umi_type ( align_bam ) f1_out = "%s-cumi-1.fq.gz" % utils . splitext_plus ( align_bam ) [ 0 ] f2_out = "%s-cumi-2.fq.gz" % utils . splitext_plus ( align_bam ) [ 0 ] avg_coverage = coverage . get_average_coverage ( "rawumi"... | Convert UMI grouped reads into fastq pair for re - alignment . |
29,437 | def _get_fgbio_options ( data , estimated_defaults , umi_method ) : group_opts = [ "--edits" , "--min-map-q" ] cons_opts = [ "--min-input-base-quality" ] if umi_method != "paired" : cons_opts += [ "--min-reads" , "--max-reads" ] filter_opts = [ "--min-reads" , "--min-base-quality" , "--max-base-error-rate" ] defaults =... | Get adjustable through resources or default options for fgbio . |
29,438 | def _check_dedup ( data ) : if dd . get_analysis ( data ) . lower ( ) in [ "rna-seq" , "smallrna-seq" ] or not dd . get_aligner ( data ) : dup_param = utils . get_in ( data , ( "config" , "algorithm" , "mark_duplicates" ) , False ) else : dup_param = utils . get_in ( data , ( "config" , "algorithm" , "mark_duplicates" ... | Check configuration for de - duplication . |
29,439 | def dedup_bam ( in_bam , data ) : if _check_dedup ( data ) : out_file = os . path . join ( utils . safe_makedir ( os . path . join ( os . getcwd ( ) , "align" , dd . get_sample_name ( data ) ) ) , "%s-dedup%s" % utils . splitext_plus ( os . path . basename ( in_bam ) ) ) if not utils . file_exists ( out_file ) : with t... | Perform non - stream based deduplication of BAM input files using biobambam . |
29,440 | def _finalize_sv ( solution_file , data ) : out = { "variantcaller" : "titancna" } with open ( solution_file ) as in_handle : solution = dict ( zip ( in_handle . readline ( ) . strip ( "\r\n" ) . split ( "\t" ) , in_handle . readline ( ) . strip ( "\r\n" ) . split ( "\t" ) ) ) if solution . get ( "path" ) : out [ "puri... | Add output files from TitanCNA calling optional solution . |
29,441 | def _should_run ( het_file ) : has_hets = False with open ( het_file ) as in_handle : for i , line in enumerate ( in_handle ) : if i > 1 : has_hets = True break return has_hets | Check for enough input data to proceed with analysis . |
29,442 | def _titan_cn_file ( cnr_file , work_dir , data ) : out_file = os . path . join ( work_dir , "%s.cn" % ( utils . splitext_plus ( os . path . basename ( cnr_file ) ) [ 0 ] ) ) support_cols = { "cnvkit" : [ "chromosome" , "start" , "end" , "log2" ] , "gatk-cnv" : [ "CONTIG" , "START" , "END" , "LOG2_COPY_RATIO" ] } cols ... | Convert CNVkit or GATK4 normalized input into TitanCNA ready format . |
29,443 | def to_vcf ( in_file , caller , header_fn , vcf_fn , data , sep = "\t" ) : out_file = "%s.vcf" % utils . splitext_plus ( in_file ) [ 0 ] if not utils . file_exists ( out_file + ".gz" ) and not utils . file_exists ( out_file ) : with file_transaction ( data , out_file ) as tx_out_file : with open ( in_file ) as in_handl... | Convert output TitanCNA segs file into bgzipped VCF . |
29,444 | def run ( items ) : assert len ( items ) == 1 , "Expect one input to MetaSV ensemble calling" data = items [ 0 ] work_dir = _sv_workdir ( data ) out_file = os . path . join ( work_dir , "variants.vcf.gz" ) cmd = _get_cmd ( ) + [ "--sample" , dd . get_sample_name ( data ) , "--reference" , dd . get_ref_file ( data ) , "... | Run MetaSV if we have enough supported callers adding output to the set of calls . |
29,445 | def combine_count_files ( files , out_file = None , ext = ".fpkm" ) : files = list ( files ) if not files : return None assert all ( [ file_exists ( x ) for x in files ] ) , "Some count files in %s do not exist." % files for f in files : assert file_exists ( f ) , "%s does not exist or is empty." % f col_names = [ os .... | combine a set of count files into a single combined file |
29,446 | def nf_step_to_process ( step , out_handle ) : pprint . pprint ( step ) directives = [ ] for req in step [ "task_definition" ] [ "requirements" ] : if req [ "requirement_type" ] == "docker" : directives . append ( "container '%s'" % req [ "value" ] ) elif req [ "requirement_type" ] == "cpu" : directives . append ( "cpu... | Convert CWL step into a nextflow process . |
29,447 | def nf_input_to_cl ( inp ) : sep = " " if inp . get ( "separate" ) else "" val = "'%s'" % inp . get ( "default" ) if inp . get ( "default" ) else "$%s" % inp [ "name" ] return "%s%s%s" % ( inp [ "prefix" ] , sep , val ) | Convert an input description into command line argument . |
29,448 | def _wf_to_dict ( wf ) : inputs , outputs = _get_wf_inout ( wf ) out = { "name" : _id_to_name ( wf . tool [ "id" ] ) . replace ( "-" , "_" ) , "inputs" : inputs , "outputs" : outputs , "steps" : [ ] , "subworkflows" : [ ] , "requirements" : [ ] } for step in wf . steps : inputs , outputs = _get_step_inout ( step ) inpu... | Parse a workflow into cwl2wdl style dictionary . |
29,449 | def _get_validate ( data ) : if data . get ( "vrn_file" ) and tz . get_in ( [ "config" , "algorithm" , "validate" ] , data ) : return utils . deepish_copy ( data ) elif "group_orig" in data : for sub in multi . get_orig_items ( data ) : if "validate" in sub [ "config" ] [ "algorithm" ] : sub_val = utils . deepish_copy ... | Retrieve items to validate from single samples or from combined joint calls . |
29,450 | def normalize_input_path ( x , data ) : if x is None : return None elif os . path . isabs ( x ) : return os . path . normpath ( x ) else : for d in [ data [ "dirs" ] . get ( "fastq" ) , data [ "dirs" ] . get ( "work" ) ] : if d : cur_x = os . path . normpath ( os . path . join ( d , x ) ) if os . path . exists ( cur_x ... | Normalize path for input files handling relative paths . Looks for non - absolute paths in local and fastq directories |
29,451 | def _get_caller_supplement ( caller , data ) : if caller == "mutect" : icaller = tz . get_in ( [ "config" , "algorithm" , "indelcaller" ] , data ) if icaller : caller = "%s/%s" % ( caller , icaller ) return caller | Some callers like MuTect incorporate a second caller for indels . |
29,452 | def _pick_lead_item ( items ) : paired = vcfutils . get_paired ( items ) if paired : return paired . tumor_data else : return list ( items ) [ 0 ] | Choose lead item for a set of samples . |
29,453 | def _normalize_cwl_inputs ( items ) : with_validate = { } vrn_files = [ ] ready_items = [ ] batch_samples = [ ] for data in ( cwlutils . normalize_missing ( utils . to_single_data ( d ) ) for d in items ) : batch_samples . append ( dd . get_sample_name ( data ) ) if tz . get_in ( [ "config" , "algorithm" , "validate" ]... | Extract variation and validation data from CWL input list of batched samples . |
29,454 | def compare_to_rm ( data ) : if isinstance ( data , ( list , tuple ) ) and cwlutils . is_cwl_run ( utils . to_single_data ( data [ 0 ] ) ) : data = _normalize_cwl_inputs ( data ) toval_data = _get_validate ( data ) toval_data = cwlutils . unpack_tarballs ( toval_data , toval_data ) if toval_data : caller = _get_caller ... | Compare final variant calls against reference materials of known calls . |
29,455 | def _annotate_validations ( eval_files , data ) : for key in [ "tp" , "tp-calls" , "fp" , "fn" ] : if eval_files . get ( key ) : eval_files [ key ] = annotation . add_genome_context ( eval_files [ key ] , data ) return eval_files | Add annotations about potential problem regions to validation VCFs . |
29,456 | def _setup_call_false ( vrn_file , rm_bed , base_dir , data , call_type ) : out_file = os . path . join ( base_dir , "%s.vcf.gz" % call_type ) if not utils . file_exists ( out_file ) : with file_transaction ( data , out_file ) as tx_out_file : if not vrn_file . endswith ( ".gz" ) : vrn_file = vcfutils . bgzip_and_index... | Create set of false positives or ngatives for inputs with empty truth sets . |
29,457 | def _rtg_add_summary_file ( eval_files , base_dir , data ) : out_file = os . path . join ( base_dir , "validate-summary.csv" ) if not utils . file_uptodate ( out_file , eval_files . get ( "tp" , eval_files . get ( "fp" , eval_files [ "fn" ] ) ) ) : with file_transaction ( data , out_file ) as tx_out_file : with open ( ... | Parse output TP FP and FN files to generate metrics for plotting . |
29,458 | def _prepare_inputs ( vrn_file , rm_file , rm_interval_file , base_dir , data ) : if not rm_file . endswith ( ".vcf.gz" ) or not os . path . exists ( rm_file + ".tbi" ) : rm_file = vcfutils . bgzip_and_index ( rm_file , data [ "config" ] , out_dir = base_dir ) if len ( vcfutils . get_samples ( vrn_file ) ) > 1 : base =... | Prepare input VCF and BED files for validation . |
29,459 | def _pick_best_quality_score ( vrn_file ) : if not vcfutils . vcf_has_variants ( vrn_file ) : return "DP" to_check = 25 scores = collections . defaultdict ( int ) try : in_handle = VariantFile ( vrn_file ) except ValueError : raise ValueError ( "Failed to parse input file in preparation for validation: %s" % vrn_file )... | Flexible quality score selection picking the best available . |
29,460 | def _get_merged_intervals ( rm_interval_file , vrn_file , base_dir , data ) : a_intervals = get_analysis_intervals ( data , vrn_file , base_dir ) if a_intervals : final_intervals = shared . remove_lcr_regions ( a_intervals , [ data ] ) if rm_interval_file : caller = _get_caller ( data ) sample = dd . get_sample_name ( ... | Retrieve intervals to run validation on merging reference and callable BED files . |
29,461 | def _callable_from_gvcf ( data , vrn_file , out_dir ) : methods = { "freebayes" : "freebayes" , "platypus" : "platypus" , "gatk-haplotype" : "gatk" } gvcf_type = methods . get ( dd . get_variantcaller ( data ) ) if gvcf_type : out_file = os . path . join ( out_dir , "%s-gcvf-coverage.bed" % utils . splitext_plus ( os .... | Retrieve callable regions based on ref call regions in gVCF . |
29,462 | def get_analysis_intervals ( data , vrn_file , base_dir ) : from bcbio . bam import callable if vrn_file and vcfutils . is_gvcf_file ( vrn_file ) : callable_bed = _callable_from_gvcf ( data , vrn_file , base_dir ) if callable_bed : return callable_bed if data . get ( "ensemble_bed" ) : return data [ "ensemble_bed" ] el... | Retrieve analysis regions for the current variant calling pipeline . |
29,463 | def _get_location_list ( interval_bed ) : import pybedtools regions = collections . OrderedDict ( ) for region in pybedtools . BedTool ( interval_bed ) : regions [ str ( region . chrom ) ] = None return regions . keys ( ) | Retrieve list of locations to analyze from input BED file . |
29,464 | def _run_bcbio_variation ( vrn_file , rm_file , rm_interval_file , base_dir , sample , caller , data ) : val_config_file = _create_validate_config_file ( vrn_file , rm_file , rm_interval_file , base_dir , data ) work_dir = os . path . join ( base_dir , "work" ) out = { "summary" : os . path . join ( work_dir , "validat... | Run validation of a caller against the truth set using bcbio . variation . |
29,465 | def _create_validate_config ( vrn_file , rm_file , rm_interval_file , base_dir , data ) : ref_call = { "file" : str ( rm_file ) , "name" : "ref" , "type" : "grading-ref" , "fix-sample-header" : True , "remove-refcalls" : True } a_intervals = get_analysis_intervals ( data , vrn_file , base_dir ) if a_intervals : a_inter... | Create a bcbio . variation configuration input for validation . |
29,466 | def summarize_grading ( samples , vkey = "validate" ) : samples = list ( utils . flatten ( samples ) ) if not _has_grading_info ( samples , vkey ) : return [ [ d ] for d in samples ] validate_dir = utils . safe_makedir ( os . path . join ( samples [ 0 ] [ "dirs" ] [ "work" ] , vkey ) ) header = [ "sample" , "caller" , ... | Provide summaries of grading results across all samples . |
29,467 | def _summarize_combined ( samples , vkey ) : validate_dir = utils . safe_makedir ( os . path . join ( samples [ 0 ] [ "dirs" ] [ "work" ] , vkey ) ) combined , _ = _group_validate_samples ( samples , vkey , [ [ "metadata" , "validate_combine" ] ] ) for vname , vitems in combined . items ( ) : if vname : cur_combined = ... | Prepare summarized CSV and plot files for samples to combine together . |
29,468 | def combine_validations ( items , vkey = "validate" ) : csvs = set ( [ ] ) pngs = set ( [ ] ) for v in [ x . get ( vkey ) for x in items ] : if v and v . get ( "grading_summary" ) : csvs . add ( v . get ( "grading_summary" ) ) if v and v . get ( "grading_plots" ) : pngs |= set ( v . get ( "grading_plots" ) ) if len ( c... | Combine multiple batch validations into validation outputs . |
29,469 | def freq_summary ( val_file , call_file , truth_file , target_name ) : out_file = "%s-freqs.csv" % utils . splitext_plus ( val_file ) [ 0 ] truth_freqs = _read_truth_freqs ( truth_file ) call_freqs = _read_call_freqs ( call_file , target_name ) with VariantFile ( val_file ) as val_in : with open ( out_file , "w" ) as o... | Summarize true and false positive calls by variant type and frequency . |
29,470 | def _read_call_freqs ( in_file , sample_name ) : from bcbio . heterogeneity import bubbletree out = { } with VariantFile ( in_file ) as call_in : for rec in call_in : if rec . filter . keys ( ) == [ "PASS" ] : for name , sample in rec . samples . items ( ) : if name == sample_name : alt , depth , freq = bubbletree . sa... | Identify frequencies for calls in the input file . |
29,471 | def _read_truth_freqs ( in_file ) : out = { } with VariantFile ( in_file ) as bcf_in : for rec in bcf_in : freq = float ( rec . info . get ( "VAF" , 1.0 ) ) out [ _get_key ( rec ) ] = freq return out | Read frequency of calls from truth VCF . |
29,472 | def to_rec ( samples , default_keys = None ) : recs = samples_to_records ( [ normalize_missing ( utils . to_single_data ( x ) ) for x in samples ] , default_keys ) return [ [ x ] for x in recs ] | Convert inputs into CWL records useful for single item parallelization . |
29,473 | def to_rec_single ( samples , default_keys = None ) : out = [ ] for data in samples : recs = samples_to_records ( [ normalize_missing ( utils . to_single_data ( data ) ) ] , default_keys ) assert len ( recs ) == 1 out . append ( recs [ 0 ] ) return out | Convert output into a list of single CWL records . |
29,474 | def handle_combined_input ( args ) : cur_args = args [ : ] while len ( cur_args ) == 1 and isinstance ( cur_args [ 0 ] , ( list , tuple ) ) : cur_args = cur_args [ 0 ] return cur_args | Check for cases where we have a combined input nested list . |
29,475 | def normalize_missing ( xs ) : if isinstance ( xs , dict ) : for k , v in xs . items ( ) : xs [ k ] = normalize_missing ( v ) elif isinstance ( xs , ( list , tuple ) ) : xs = [ normalize_missing ( x ) for x in xs ] elif isinstance ( xs , six . string_types ) : if xs . lower ( ) in [ "none" , "null" ] : xs = None elif x... | Normalize missing values to avoid string None inputs . |
29,476 | def unpack_tarballs ( xs , data , use_subdir = True ) : if isinstance ( xs , dict ) : for k , v in xs . items ( ) : xs [ k ] = unpack_tarballs ( v , data , use_subdir ) elif isinstance ( xs , ( list , tuple ) ) : xs = [ unpack_tarballs ( x , data , use_subdir ) for x in xs ] elif isinstance ( xs , six . string_types ) ... | Unpack workflow tarballs into ready to use directories . |
29,477 | def _get_all_cwlkeys ( items , default_keys = None ) : if default_keys : default_keys = set ( default_keys ) else : default_keys = set ( [ "metadata__batch" , "config__algorithm__validate" , "config__algorithm__validate_regions" , "config__algorithm__validate_regions_merged" , "config__algorithm__variant_regions" , "va... | Retrieve cwlkeys from inputs handling defaults which can be null . |
29,478 | def split_data_cwl_items ( items , default_keys = None ) : key_lens = set ( [ ] ) for data in items : key_lens . add ( len ( _get_all_cwlkeys ( [ data ] , default_keys ) ) ) extra_key_len = min ( list ( key_lens ) ) if len ( key_lens ) > 1 else None data_out = [ ] extra_out = [ ] for data in items : if extra_key_len an... | Split a set of CWL output dictionaries into data samples and CWL items . |
29,479 | def samples_to_records ( samples , default_keys = None ) : from bcbio . pipeline import run_info RECORD_CONVERT_TO_LIST = set ( [ "config__algorithm__tools_on" , "config__algorithm__tools_off" , "reference__genome_context" ] ) all_keys = _get_all_cwlkeys ( samples , default_keys ) out = [ ] for data in samples : for ra... | Convert samples into output CWL records . |
29,480 | def assign_complex_to_samples ( items ) : extract_fns = { ( "variants" , "samples" ) : _get_vcf_samples , ( "align_bam" , ) : _get_bam_samples } complex = { k : { } for k in extract_fns . keys ( ) } for data in items : for k in complex : v = tz . get_in ( k , data ) if v is not None : for s in extract_fns [ k ] ( v , i... | Assign complex inputs like variants and align outputs to samples . |
29,481 | def _normalize_vc_input ( data ) : if data . get ( "ensemble" ) : for k in [ "batch_samples" , "validate" , "vrn_file" ] : data [ k ] = data [ "ensemble" ] [ k ] data [ "config" ] [ "algorithm" ] [ "variantcaller" ] = "ensemble" data [ "metadata" ] = { "batch" : data [ "ensemble" ] [ "batch_id" ] } return data | Normalize different types of variant calling inputs . |
29,482 | def _get_orig_items ( data ) : if isinstance ( data , dict ) : if dd . get_align_bam ( data ) and tz . get_in ( [ "metadata" , "batch" ] , data ) and "group_orig" in data : return vmulti . get_orig_items ( data ) else : return [ data ] else : return data | Retrieve original items in a batch handling CWL and standard cases . |
29,483 | def _symlink_to_workdir ( data , key ) : orig_file = tz . get_in ( key , data ) if orig_file and not orig_file . startswith ( dd . get_work_dir ( data ) ) : variantcaller = genotype . get_variantcaller ( data , require_bam = False ) if not variantcaller : variantcaller = "precalled" out_file = os . path . join ( dd . g... | For CWL support symlink files into a working directory if in read - only imports . |
29,484 | def _get_batch_representative ( items , key ) : if isinstance ( items , dict ) : return items , items else : vals = set ( [ ] ) out = [ ] for data in items : if key in data : vals . add ( data [ key ] ) out . append ( data ) if len ( vals ) != 1 : raise ValueError ( "Incorrect values for %s: %s" % ( key , list ( vals )... | Retrieve a representative data item from a batch . |
29,485 | def _get_storage_manager ( resource ) : for manager in ( AmazonS3 , ArvadosKeep , SevenBridges , DNAnexus , AzureBlob , GoogleCloud , RegularServer ) : if manager . check_resource ( resource ) : return manager ( ) raise ValueError ( "Unexpected object store %(resource)s" % { "resource" : resource } ) | Return a storage manager which can process this resource . |
29,486 | def default_region ( fname ) : manager = _get_storage_manager ( fname ) if hasattr ( manager , "get_region" ) : return manager . get_region ( ) raise NotImplementedError ( "Unexpected object store %s" % fname ) | Return the default region for the received resource . |
29,487 | def blob_properties ( self ) : if not self . _blob_properties : self . _blob_properties = self . _blob_service . get_blob_properties ( container_name = self . _container_name , blob_name = self . _blob_name ) return self . _blob_properties | Returns all user - defined metadata standard HTTP properties and system properties for the blob . |
29,488 | def _chunk_offsets ( self ) : index = 0 blob_size = self . blob_properties . get ( 'content-length' ) while index < blob_size : yield index index = index + self . _chunk_size | Iterator over chunk offests . |
29,489 | def _chunk_iter ( self ) : for chunk_offset in self . _chunk_offsets ( ) : yield self . _download_chunk ( chunk_offset = chunk_offset , chunk_size = self . _chunk_size ) | Iterator over the blob file . |
29,490 | def parse_remote ( cls , filename ) : parts = filename . split ( "//" ) [ - 1 ] . split ( "/" , 1 ) bucket , key = parts if len ( parts ) == 2 else ( parts [ 0 ] , None ) if bucket . find ( "@" ) > 0 : bucket , region = bucket . split ( "@" ) else : region = None return cls . _REMOTE_FILE ( "s3" , bucket , key , region... | Parses a remote filename into bucket and key information . |
29,491 | def _cl_aws_cli ( cls , file_info , region ) : s3file = cls . _S3_FILE % { "bucket" : file_info . bucket , "key" : file_info . key , "region" : "" } command = [ os . path . join ( os . path . dirname ( sys . executable ) , "aws" ) , "s3" , "cp" , "--region" , region , s3file ] return ( command , "awscli" ) | Command line required for download using the standard AWS command line interface . |
29,492 | def _cl_gof3r ( file_info , region ) : command = [ "gof3r" , "get" , "--no-md5" , "-k" , file_info . key , "-b" , file_info . bucket ] if region != "us-east-1" : command += [ "--endpoint=s3-%s.amazonaws.com" % region ] return ( command , "gof3r" ) | Command line required for download using gof3r . |
29,493 | def get_region ( cls , resource = None ) : if resource : resource_info = cls . parse_remote ( resource ) if resource_info . region : return resource_info . region return os . environ . get ( "AWS_DEFAULT_REGION" , cls . _DEFAULT_REGION ) | Retrieve region from standard environmental variables or file name . |
29,494 | def connect ( cls , resource ) : import boto return boto . s3 . connect_to_region ( cls . get_region ( resource ) ) | Connect to this Region s endpoint . |
29,495 | def open ( cls , filename ) : import boto file_info = cls . parse_remote ( filename ) connection = cls . connect ( filename ) try : s3_bucket = connection . get_bucket ( file_info . bucket ) except boto . exception . S3ResponseError as error : if error . status == 403 : s3_bucket = connection . get_bucket ( file_info .... | Return a handle like object for streaming from S3 . |
29,496 | def parse_remote ( cls , filename ) : blob_file = cls . _URL_FORMAT . search ( filename ) return cls . _REMOTE_FILE ( "blob" , storage = blob_file . group ( "storage" ) , container = blob_file . group ( "container" ) , blob = blob_file . group ( "blob" ) ) | Parses a remote filename into blob information . |
29,497 | def connect ( cls , resource ) : from azure import storage as azure_storage file_info = cls . parse_remote ( resource ) return azure_storage . BlobService ( file_info . storage ) | Returns a connection object pointing to the endpoint associated to the received resource . |
29,498 | def open ( cls , filename ) : file_info = cls . parse_remote ( filename ) blob_service = cls . connect ( filename ) return BlobHandle ( blob_service = blob_service , container = file_info . container , blob = file_info . blob , chunk_size = cls . _BLOB_CHUNK_DATA_SIZE ) | Provide a handle - like object for streaming . |
29,499 | def compress ( in_bam , data ) : out_dir = utils . safe_makedir ( os . path . join ( dd . get_work_dir ( data ) , "archive" ) ) out_file = os . path . join ( out_dir , "%s.cram" % os . path . splitext ( os . path . basename ( in_bam ) ) [ 0 ] ) cores = dd . get_num_cores ( data ) ref_file = dd . get_ref_file ( data ) i... | Compress a BAM file to CRAM providing indexed CRAM file . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.