idx int64 0 63k | question stringlengths 61 4.03k | target stringlengths 6 1.23k |
|---|---|---|
29,500 | def index ( in_cram , config ) : out_file = in_cram + ".crai" if not utils . file_uptodate ( out_file , in_cram ) : with file_transaction ( config , in_cram + ".crai" ) as tx_out_file : tx_in_file = os . path . splitext ( tx_out_file ) [ 0 ] utils . symlink_plus ( in_cram , tx_in_file ) cmd = "samtools index {tx_in_fil... | Ensure CRAM file has a . crai index file . |
29,501 | def to_bam ( in_file , out_file , data ) : if not utils . file_uptodate ( out_file , in_file ) : with file_transaction ( data , out_file ) as tx_out_file : cmd = [ "samtools" , "view" , "-O" , "BAM" , "-o" , tx_out_file , in_file ] do . run ( cmd , "Convert CRAM to BAM" ) bam . index ( out_file , data [ "config" ] ) re... | Convert CRAM file into BAM . |
29,502 | def start ( parallel , items , config , dirs = None , name = None , multiplier = 1 , max_multicore = None ) : if name : checkpoint_dir = utils . safe_makedir ( os . path . join ( dirs [ "work" ] , "checkpoints_parallel" ) ) checkpoint_file = os . path . join ( checkpoint_dir , "%s.done" % name ) else : checkpoint_file ... | Start a parallel cluster or machines to be used for running remote functions . |
29,503 | def recalibrate_quality ( bam_file , sam_ref , dbsnp_file , picard_dir ) : cl = [ "picard_gatk_recalibrate.py" , picard_dir , sam_ref , bam_file ] if dbsnp_file : cl . append ( dbsnp_file ) subprocess . check_call ( cl ) out_file = glob . glob ( "%s*gatkrecal.bam" % os . path . splitext ( bam_file ) [ 0 ] ) [ 0 ] retur... | Recalibrate alignments with GATK and provide pdf summary . |
29,504 | def run_genotyper ( bam_file , ref_file , dbsnp_file , config_file ) : cl = [ "gatk_genotyper.py" , config_file , ref_file , bam_file ] if dbsnp_file : cl . append ( dbsnp_file ) subprocess . check_call ( cl ) | Perform SNP genotyping and analysis using GATK . |
29,505 | def _do_run ( paired ) : work_dir = _sv_workdir ( paired . tumor_data ) out = _get_battenberg_out ( paired , work_dir ) ignore_file = os . path . join ( work_dir , "ignore_chromosomes.txt" ) if len ( _missing_files ( out ) ) > 0 : ref_file = dd . get_ref_file ( paired . tumor_data ) bat_datadir = os . path . normpath (... | Perform Battenberg caling with the paired dataset . |
29,506 | def _make_ignore_file ( work_dir , ref_file , ignore_file , impute_file ) : gl_file = os . path . join ( work_dir , "gender_loci.txt" ) chroms = set ( [ ] ) with open ( impute_file ) as in_handle : for line in in_handle : chrom = line . split ( ) [ 0 ] chroms . add ( chrom ) if not chrom . startswith ( "chr" ) : chroms... | Create input files with chromosomes to ignore and gender loci . |
29,507 | def copy_flowcell ( dname , fastq_dir , sample_cfile , config ) : with utils . chdir ( dname ) : reports = reduce ( operator . add , [ glob . glob ( "*.xml" ) , glob . glob ( "Data/Intensities/BaseCalls/*.xml" ) , glob . glob ( "Data/Intensities/BaseCalls/*.xsl" ) , glob . glob ( "Data/Intensities/BaseCalls/*.htm" ) , ... | Copy required files for processing using rsync potentially to a remote server . |
29,508 | def _umis_cmd ( data ) : return "%s %s %s" % ( utils . locale_export ( ) , utils . get_program_python ( "umis" ) , config_utils . get_program ( "umis" , data [ "config" ] , default = "umis" ) ) | Return umis command line argument with correct python and locale . |
29,509 | def demultiplex_samples ( data ) : work_dir = os . path . join ( dd . get_work_dir ( data ) , "umis" ) sample_dir = os . path . join ( work_dir , dd . get_sample_name ( data ) ) demulti_dir = os . path . join ( sample_dir , "demultiplexed" ) files = data [ "files" ] if len ( files ) == 2 : logger . error ( "Sample demu... | demultiplex a fastqtransformed FASTQ file into separate sample barcode files |
29,510 | def split_demultiplexed_sampledata ( data , demultiplexed ) : datadicts = [ ] samplename = dd . get_sample_name ( data ) for fastq in demultiplexed : barcode = os . path . basename ( fastq ) . split ( "." ) [ 0 ] datadict = copy . deepcopy ( data ) datadict = dd . set_sample_name ( datadict , samplename + "-" + barcode... | splits demultiplexed samples into separate entries in the global sample datadict |
29,511 | def is_transformed ( fastq ) : with open_fastq ( fastq ) as in_handle : for line in islice ( in_handle , 400 ) : if "UMI_" in line : return True return False | check the first 100 reads to see if a FASTQ file has already been transformed by umis |
29,512 | def read ( self , filename , rowprefix = None , colprefix = None , delim = ":" ) : self . matrix = scipy . io . mmread ( filename ) with open ( filename + ".rownames" ) as in_handle : self . rownames = [ x . strip ( ) for x in in_handle ] if rowprefix : self . rownames = [ rowprefix + delim + x for x in self . rownames... | read a sparse matrix loading row and column name files . if specified will add a prefix to the row or column names |
29,513 | def write ( self , filename ) : if file_exists ( filename ) : return filename out_files = [ filename , filename + ".rownames" , filename + ".colnames" ] with file_transaction ( out_files ) as tx_out_files : with open ( tx_out_files [ 0 ] , "wb" ) as out_handle : scipy . io . mmwrite ( out_handle , scipy . sparse . csr_... | read a sparse matrix loading row and column name files |
29,514 | def sample_annotation ( data ) : names = data [ "rgnames" ] [ 'sample' ] tools = dd . get_expression_caller ( data ) work_dir = os . path . join ( dd . get_work_dir ( data ) , "mirbase" ) out_dir = os . path . join ( work_dir , names ) utils . safe_makedir ( out_dir ) out_file = op . join ( out_dir , names ) if dd . ge... | Annotate miRNAs using miRBase database with seqbuster tool |
29,515 | def _prepare_file ( fn , out_dir ) : atropos = _get_atropos ( ) cmd = "{atropos} trim --max-reads 500000 -u 22 -se {fn} -o {tx_file}" out_file = os . path . join ( out_dir , append_stem ( os . path . basename ( fn ) , "end" ) ) if file_exists ( out_file ) : return out_file with file_transaction ( out_file ) as tx_file ... | Cut the beginning of the reads to avoid detection of miRNAs |
29,516 | def _collapse ( in_file ) : seqcluster = op . join ( utils . get_bcbio_bin ( ) , "seqcluster" ) out_file = "%s.fastq" % utils . splitext_plus ( append_stem ( in_file , "_trimmed" ) ) [ 0 ] out_dir = os . path . dirname ( in_file ) if file_exists ( out_file ) : return out_file cmd = ( "{seqcluster} collapse -o {out_dir}... | Collpase reads into unique sequences with seqcluster |
29,517 | def _summary ( in_file ) : data = Counter ( ) out_file = in_file + "_size_stats" if file_exists ( out_file ) : return out_file with open ( in_file ) as in_handle : for line in in_handle : counts = int ( line . strip ( ) . split ( "_x" ) [ 1 ] ) line = next ( in_handle ) l = len ( line . strip ( ) ) next ( in_handle ) n... | Calculate size distribution after adapter removal |
29,518 | def _mirtop ( input_fn , sps , db , out_dir , config ) : hairpin = os . path . join ( db , "hairpin.fa" ) gtf = os . path . join ( db , "mirbase.gff3" ) if not file_exists ( hairpin ) or not file_exists ( gtf ) : logger . warning ( "%s or %s are not installed. Skipping." % ( hairpin , gtf ) ) return None out_gtf_fn = "... | Convert to GFF3 standard format |
29,519 | def _trna_annotation ( data ) : trna_ref = op . join ( dd . get_srna_trna_file ( data ) ) name = dd . get_sample_name ( data ) work_dir = utils . safe_makedir ( os . path . join ( dd . get_work_dir ( data ) , "trna" , name ) ) in_file = op . basename ( data [ "clean_fastq" ] ) tdrmapper = os . path . join ( os . path .... | use tDRmapper to quantify tRNAs |
29,520 | def _mint_trna_annotation ( data ) : trna_lookup = op . join ( dd . get_srna_mint_lookup ( data ) ) trna_space = op . join ( dd . get_srna_mint_space ( data ) ) trna_other = op . join ( dd . get_srna_mint_other ( data ) ) name = dd . get_sample_name ( data ) work_dir = utils . safe_makedir ( os . path . join ( dd . get... | use MINTmap to quantify tRNAs |
29,521 | def sequence_length ( fasta ) : sequences = SeqIO . parse ( fasta , "fasta" ) records = { record . id : len ( record ) for record in sequences } return records | return a dict of the lengths of sequences in a fasta file |
29,522 | def sequence_names ( fasta ) : sequences = SeqIO . parse ( fasta , "fasta" ) records = [ record . id for record in sequences ] return records | return a list of the sequence IDs in a FASTA file |
29,523 | def _prepare_inputs ( ma_fn , bam_file , out_dir ) : fixed_fa = os . path . join ( out_dir , "file_reads.fa" ) count_name = dict ( ) with file_transaction ( fixed_fa ) as out_tx : with open ( out_tx , 'w' ) as out_handle : with open ( ma_fn ) as in_handle : h = next ( in_handle ) for line in in_handle : cols = line . s... | Convert to fastq with counts |
29,524 | def _parse_novel ( csv_file , sps = "new" ) : read = 0 seen = set ( ) safe_makedir ( "novel" ) with open ( "novel/hairpin.fa" , "w" ) as fa_handle , open ( "novel/miRNA.str" , "w" ) as str_handle : with open ( csv_file ) as in_handle : for line in in_handle : if line . startswith ( "mature miRBase miRNAs detected by mi... | Create input of novel miRNAs from miRDeep2 |
29,525 | def _run_smoove ( full_bams , sr_bams , disc_bams , work_dir , items ) : batch = sshared . get_cur_batch ( items ) ext = "-%s-svs" % batch if batch else "-svs" name = "%s%s" % ( dd . get_sample_name ( items [ 0 ] ) , ext ) out_file = os . path . join ( work_dir , "%s-smoove.genotyped.vcf.gz" % name ) sv_exclude_bed = s... | Run lumpy - sv using smoove . |
29,526 | def _filter_by_support ( in_file , data ) : rc_filter = ( "FORMAT/SU < 4 || " "(FORMAT/SR == 0 && FORMAT/SU < 15 && ABS(SVLEN)>50000) || " "(FORMAT/SR == 0 && FORMAT/SU < 5 && ABS(SVLEN)<2000) || " "(FORMAT/SR == 0 && FORMAT/SU < 15 && ABS(SVLEN)<300)" ) return vfilter . cutoff_w_expression ( in_file , rc_filter , data... | Filter call file based on supporting evidence adding FILTER annotations to VCF . |
29,527 | def _filter_by_background ( base_name , back_samples , gt_vcfs , data ) : filtname = "InBackground" filtdoc = "Variant also present in background samples with same genotype" orig_vcf = gt_vcfs [ base_name ] out_file = "%s-backfilter.vcf" % ( utils . splitext_plus ( orig_vcf ) [ 0 ] ) if not utils . file_exists ( out_fi... | Filter base samples marking any also present in the background . |
29,528 | def _genotype_in_background ( rec , base_name , back_samples ) : def passes ( rec ) : return not rec . FILTER or len ( rec . FILTER ) == 0 return ( passes ( rec ) and any ( rec . genotype ( base_name ) . gt_alleles == rec . genotype ( back_name ) . gt_alleles for back_name in back_samples ) ) | Check if the genotype in the record of interest is present in the background records . |
29,529 | def run ( items ) : paired = vcfutils . get_paired ( items ) work_dir = _sv_workdir ( paired . tumor_data if paired and paired . tumor_data else items [ 0 ] ) previous_evidence = { } full_bams , sr_bams , disc_bams = [ ] , [ ] , [ ] for data in items : full_bams . append ( dd . get_align_bam ( data ) ) sr_bam , disc_ba... | Perform detection of structural variations with lumpy . |
29,530 | def _bedpes_from_cnv_caller ( data , work_dir ) : supported = set ( [ "cnvkit" ] ) cns_file = None for sv in data . get ( "sv" , [ ] ) : if sv [ "variantcaller" ] in supported and "cns" in sv and "lumpy_usecnv" in dd . get_tools_on ( data ) : cns_file = sv [ "cns" ] break if not cns_file : return None , None else : out... | Retrieve BEDPEs deletion and duplications from CNV callers . |
29,531 | def _prepend ( original , to_prepend ) : if to_prepend is None : return original sep = os . pathsep def split_path_value ( path_value ) : return [ ] if path_value == '' else path_value . split ( sep ) seen = set ( ) components = [ ] for path in split_path_value ( to_prepend ) + split_path_value ( original ) : if path n... | Prepend paths in a string representing a list of paths to another . |
29,532 | def remove_bcbiopath ( ) : to_remove = os . environ . get ( "BCBIOPATH" , utils . get_bcbio_bin ( ) ) + ":" if os . environ [ "PATH" ] . startswith ( to_remove ) : os . environ [ "PATH" ] = os . environ [ "PATH" ] [ len ( to_remove ) : ] | Remove bcbio internal path from first element in PATH . |
29,533 | def calculate_sv_bins ( * items ) : calcfns = { "cnvkit" : _calculate_sv_bins_cnvkit , "gatk-cnv" : _calculate_sv_bins_gatk } from bcbio . structural import cnvkit items = [ utils . to_single_data ( x ) for x in cwlutils . handle_combined_input ( items ) ] if all ( not cnvkit . use_general_sv_bins ( x ) for x in items ... | Determine bin sizes and regions to use for samples . |
29,534 | def _calculate_sv_bins_gatk ( data , cnv_group , size_calc_fn ) : if dd . get_background_cnv_reference ( data , "gatk-cnv" ) : target_bed = gatkcnv . pon_to_bed ( dd . get_background_cnv_reference ( data , "gatk-cnv" ) , cnv_group . work_dir , data ) else : target_bed = gatkcnv . prepare_intervals ( data , cnv_group . ... | Calculate structural variant bins using GATK4 CNV callers region or even intervals approach . |
29,535 | def calculate_sv_coverage ( data ) : calcfns = { "cnvkit" : _calculate_sv_coverage_cnvkit , "gatk-cnv" : _calculate_sv_coverage_gatk } from bcbio . structural import cnvkit data = utils . to_single_data ( data ) if not cnvkit . use_general_sv_bins ( data ) : out_target_file , out_anti_file = ( None , None ) else : work... | Calculate coverage within bins for downstream CNV calling . |
29,536 | def _calculate_sv_coverage_gatk ( data , work_dir ) : from bcbio . variation import coverage from bcbio . structural import annotate target_file = gatkcnv . collect_read_counts ( data , work_dir ) target_in = bedutils . clean_file ( tz . get_in ( [ "regions" , "bins" , "target" ] , data ) , data , bedprep_dir = work_di... | Calculate coverage in defined regions using GATK tools |
29,537 | def _calculate_sv_coverage_cnvkit ( data , work_dir ) : from bcbio . variation import coverage from bcbio . structural import annotate out_target_file = os . path . join ( work_dir , "%s-target-coverage.cnn" % dd . get_sample_name ( data ) ) out_anti_file = os . path . join ( work_dir , "%s-antitarget-coverage.cnn" % d... | Calculate coverage in an CNVkit ready format using mosdepth . |
29,538 | def normalize_sv_coverage ( * items ) : calcfns = { "cnvkit" : _normalize_sv_coverage_cnvkit , "gatk-cnv" : _normalize_sv_coverage_gatk } from bcbio . structural import cnvkit from bcbio . structural import shared as sshared items = [ utils . to_single_data ( x ) for x in cwlutils . handle_combined_input ( items ) ] if... | Normalize CNV coverage providing flexible point for multiple methods . |
29,539 | def _normalize_sv_coverage_gatk ( group_id , inputs , backgrounds , work_dir , back_files , out_files ) : input_backs = set ( filter ( lambda x : x is not None , [ dd . get_background_cnv_reference ( d , "gatk-cnv" ) for d in inputs ] ) ) if input_backs : assert len ( input_backs ) == 1 , "Multiple backgrounds in group... | Normalize CNV coverage using panel of normals with GATK s de - noise approaches . |
29,540 | def _normalize_sv_coverage_cnvkit ( group_id , inputs , backgrounds , work_dir , back_files , out_files ) : from bcbio . structural import cnvkit cnns = reduce ( operator . add , [ [ tz . get_in ( [ "depth" , "bins" , "target" ] , x ) , tz . get_in ( [ "depth" , "bins" , "antitarget" ] , x ) ] for x in backgrounds ] , ... | Normalize CNV coverage depths by GC repeats and background using CNVkit |
29,541 | def get_base_cnv_regions ( data , work_dir , genome_default = "transcripts1e4" , include_gene_names = True ) : cov_interval = dd . get_coverage_interval ( data ) base_regions = get_sv_bed ( data , include_gene_names = include_gene_names ) if not base_regions : if cov_interval == "genome" : base_regions = get_sv_bed ( d... | Retrieve set of target regions for CNV analysis . |
29,542 | def remove_exclude_regions ( orig_bed , base_file , items , remove_entire_feature = False ) : from bcbio . structural import shared as sshared out_bed = os . path . join ( "%s-noexclude.bed" % ( utils . splitext_plus ( base_file ) [ 0 ] ) ) if not utils . file_uptodate ( out_bed , orig_bed ) : exclude_bed = sshared . p... | Remove centromere and short end regions from an existing BED file of regions to target . |
29,543 | def get_sv_bed ( data , method = None , out_dir = None , include_gene_names = True ) : if method is None : method = ( tz . get_in ( [ "config" , "algorithm" , "sv_regions" ] , data ) or dd . get_variant_regions ( data ) or dd . get_sample_callable ( data ) ) gene_file = dd . get_gene_bed ( data ) if method and os . pat... | Retrieve a BED file of regions for SV and heterogeneity calling using the provided method . |
29,544 | def _group_coords ( rs ) : max_intron_size = 1e5 coords = [ ] for r in rs : coords . append ( r . start ) coords . append ( r . end ) coord_groups = [ ] cur_group = [ ] for coord in sorted ( coords ) : if not cur_group or coord - cur_group [ - 1 ] < max_intron_size : cur_group . append ( coord ) else : coord_groups . a... | Organize coordinate regions into groups for each transcript . |
29,545 | def _calc_sizes ( self , cnv_file , items ) : bp_per_bin = 100000 range_map = { "target" : ( 100 , 250 ) , "antitarget" : ( 10000 , 1000000 ) } target_bps = [ ] anti_bps = [ ] checked_beds = set ( [ ] ) for data in items : region_bed = tz . get_in ( [ "depth" , "variant_regions" , "regions" ] , data ) if region_bed and... | Retrieve target and antitarget bin sizes based on depth . |
29,546 | def phmmer ( ** kwargs ) : logging . debug ( kwargs ) args = { 'seq' : kwargs . get ( 'seq' ) , 'seqdb' : kwargs . get ( 'seqdb' ) } args2 = { 'output' : kwargs . get ( 'output' , 'json' ) , 'range' : kwargs . get ( 'range' ) } return _hmmer ( "http://hmmer.janelia.org/search/phmmer" , args , args2 ) | Search a protein sequence against a HMMER sequence database . |
29,547 | def scrnaseq_concatenate_metadata ( samples ) : barcodes = { } counts = "" metadata = { } has_sample_barcodes = False for sample in dd . sample_data_iterator ( samples ) : if dd . get_sample_barcodes ( sample ) : has_sample_barcodes = True with open ( dd . get_sample_barcodes ( sample ) ) as inh : for line in inh : col... | Create file same dimension than mtx . colnames with metadata and sample name to help in the creation of the SC object . |
29,548 | def rnaseq_variant_calling ( samples , run_parallel ) : samples = run_parallel ( "run_rnaseq_variant_calling" , samples ) variantcaller = dd . get_variantcaller ( to_single_data ( samples [ 0 ] ) ) if variantcaller and ( "gatk-haplotype" in variantcaller ) : out = [ ] for d in joint . square_off ( samples , run_paralle... | run RNA - seq variant calling using GATK |
29,549 | def run_rnaseq_variant_calling ( data ) : variantcaller = dd . get_variantcaller ( data ) if isinstance ( variantcaller , list ) and len ( variantcaller ) > 1 : logger . error ( "Only one variantcaller can be run for RNA-seq at " "this time. Post an issue here " "(https://github.com/bcbio/bcbio-nextgen/issues) " "if th... | run RNA - seq variant calling variation file is stored in vrn_file in the datadict |
29,550 | def run_rnaseq_ann_filter ( data ) : data = to_single_data ( data ) if dd . get_vrn_file ( data ) : eff_file = effects . add_to_vcf ( dd . get_vrn_file ( data ) , data ) [ 0 ] if eff_file : data = dd . set_vrn_file ( data , eff_file ) ann_file = population . run_vcfanno ( dd . get_vrn_file ( data ) , data ) if ann_file... | Run RNA - seq annotation and filtering . |
29,551 | def quantitate ( data ) : data = to_single_data ( to_single_data ( data ) ) data = generate_transcript_counts ( data ) [ 0 ] [ 0 ] data [ "quant" ] = { } if "sailfish" in dd . get_expression_caller ( data ) : data = to_single_data ( sailfish . run_sailfish ( data ) [ 0 ] ) data [ "quant" ] [ "tsv" ] = data [ "sailfish"... | CWL target for quantitation . |
29,552 | def quantitate_expression_parallel ( samples , run_parallel ) : data = samples [ 0 ] [ 0 ] samples = run_parallel ( "generate_transcript_counts" , samples ) if "cufflinks" in dd . get_expression_caller ( data ) : samples = run_parallel ( "run_cufflinks" , samples ) if "stringtie" in dd . get_expression_caller ( data ) ... | quantitate expression all programs run here should be multithreaded to take advantage of the threaded run_parallel environment |
29,553 | def quantitate_expression_noparallel ( samples , run_parallel ) : data = samples [ 0 ] [ 0 ] if "express" in dd . get_expression_caller ( data ) : samples = run_parallel ( "run_express" , samples ) if "dexseq" in dd . get_expression_caller ( data ) : samples = run_parallel ( "run_dexseq" , samples ) return samples | run transcript quantitation for algorithms that don t run in parallel |
29,554 | def generate_transcript_counts ( data ) : data [ "count_file" ] = featureCounts . count ( data ) if dd . get_fusion_mode ( data , False ) and not dd . get_fusion_caller ( data ) : oncofuse_file = oncofuse . run ( data ) if oncofuse_file : data = dd . set_oncofuse_file ( data , oncofuse_file ) if dd . get_transcriptome_... | Generate counts per transcript and per exon from an alignment |
29,555 | def run_dexseq ( data ) : if dd . get_dexseq_gff ( data , None ) : data = dexseq . bcbio_run ( data ) return [ [ data ] ] | Quantitate exon - level counts with DEXSeq |
29,556 | def combine_express ( samples , combined ) : if not combined : return None to_combine = [ dd . get_express_counts ( x ) for x in dd . sample_data_iterator ( samples ) if dd . get_express_counts ( x ) ] gtf_file = dd . get_gtf_file ( samples [ 0 ] [ 0 ] ) isoform_to_gene_file = os . path . join ( os . path . dirname ( c... | Combine tpm effective counts and fpkm from express results |
29,557 | def run_cufflinks ( data ) : if "cufflinks" in dd . get_tools_off ( data ) : return [ [ data ] ] work_bam = dd . get_work_bam ( data ) ref_file = dd . get_sam_ref ( data ) out_dir , fpkm_file , fpkm_isoform_file = cufflinks . run ( work_bam , ref_file , data ) data = dd . set_cufflinks_dir ( data , out_dir ) data = dd ... | Quantitate transcript expression with Cufflinks |
29,558 | def run ( data ) : name = dd . get_sample_name ( data ) in_bam = dd . get_transcriptome_bam ( data ) config = data [ 'config' ] if not in_bam : logger . info ( "Transcriptome-mapped BAM file not found, skipping eXpress." ) return data out_dir = os . path . join ( dd . get_work_dir ( data ) , "express" , name ) out_file... | Quantitaive isoforms expression by eXpress |
29,559 | def _get_column ( in_file , out_file , column , data = None ) : with file_transaction ( data , out_file ) as tx_out_file : with open ( in_file ) as in_handle : with open ( tx_out_file , 'w' ) as out_handle : for line in in_handle : cols = line . strip ( ) . split ( "\t" ) if line . find ( "eff_count" ) > 0 : continue n... | Subset one column from a file |
29,560 | def _prepare_bam_file ( bam_file , tmp_dir , config ) : sort_mode = _get_sort_order ( bam_file , config ) if sort_mode != "queryname" : bam_file = sort ( bam_file , config , "queryname" ) return bam_file | Pipe sort by name cmd in case sort by coordinates |
29,561 | def isoform_to_gene_name ( gtf_file , out_file , data ) : if not out_file : out_file = tempfile . NamedTemporaryFile ( delete = False ) . name if file_exists ( out_file ) : return out_file db = gtf . get_gtf_db ( gtf_file ) line_format = "{transcript}\t{gene}\n" with file_transaction ( data , out_file ) as tx_out_file ... | produce a table of isoform - > gene mappings for loading into EBSeq |
29,562 | def shared_variantcall ( call_fn , name , align_bams , ref_file , items , assoc_files , region = None , out_file = None ) : config = items [ 0 ] [ "config" ] if out_file is None : if vcfutils . is_paired_analysis ( align_bams , items ) : out_file = "%s-paired-variants.vcf.gz" % config [ "metdata" ] [ "batch" ] else : o... | Provide base functionality for prepping and indexing for variant calling . |
29,563 | def run_samtools ( align_bams , items , ref_file , assoc_files , region = None , out_file = None ) : return shared_variantcall ( _call_variants_samtools , "samtools" , align_bams , ref_file , items , assoc_files , region , out_file ) | Detect SNPs and indels with samtools mpileup and bcftools . |
29,564 | def _call_variants_samtools ( align_bams , ref_file , items , target_regions , tx_out_file ) : config = items [ 0 ] [ "config" ] mpileup = prep_mpileup ( align_bams , ref_file , config , target_regions = target_regions , want_bcf = True ) bcftools = config_utils . get_program ( "bcftools" , config ) samtools_version = ... | Call variants with samtools in target_regions . |
29,565 | def _convert_fastq ( srafn , outdir , single = False ) : "convert sra to fastq" cmd = "fastq-dump --split-files --gzip {srafn}" cmd = "%s %s" % ( utils . local_path_export ( ) , cmd ) sraid = os . path . basename ( utils . splitext_plus ( srafn ) [ 0 ] ) if not srafn : return None if not single : out_file = [ os . path... | convert sra to fastq |
29,566 | def check_and_postprocess ( args ) : with open ( args . process_config ) as in_handle : config = yaml . safe_load ( in_handle ) setup_local_logging ( config ) for dname in _find_unprocessed ( config ) : lane_details = nglims . get_runinfo ( config [ "galaxy_url" ] , config [ "galaxy_apikey" ] , dname , utils . get_in (... | Check for newly dumped sequencer output post - processing and transferring . |
29,567 | def _tweak_lane ( lane_details , dname ) : tweak_config_file = os . path . join ( dname , "lane_config.yaml" ) if os . path . exists ( tweak_config_file ) : with open ( tweak_config_file ) as in_handle : tweak_config = yaml . safe_load ( in_handle ) if tweak_config . get ( "uniquify_lanes" ) : out = [ ] for ld in lane_... | Potentially tweak lane information to handle custom processing reading a lane_config . yaml file . |
29,568 | def _remap_dirname ( local , remote ) : def do ( x ) : return x . replace ( local , remote , 1 ) return do | Remap directory names from local to remote . |
29,569 | def _find_unprocessed ( config ) : reported = _read_reported ( config [ "msg_db" ] ) for dname in _get_directories ( config ) : if os . path . isdir ( dname ) and dname not in reported : if _is_finished_dumping ( dname ) : yield dname | Find any finished directories that have not been processed . |
29,570 | def _is_finished_dumping ( directory ) : run_info = os . path . join ( directory , "RunInfo.xml" ) hi_seq_checkpoint = "Basecalling_Netcopy_complete_Read%s.txt" % _expected_reads ( run_info ) to_check = [ "Basecalling_Netcopy_complete_SINGLEREAD.txt" , "Basecalling_Netcopy_complete_READ2.txt" , hi_seq_checkpoint ] retu... | Determine if the sequencing directory has all files . |
29,571 | def _expected_reads ( run_info_file ) : reads = [ ] if os . path . exists ( run_info_file ) : tree = ElementTree ( ) tree . parse ( run_info_file ) read_elem = tree . find ( "Run/Reads" ) reads = read_elem . findall ( "Read" ) return len ( reads ) | Parse the number of expected reads from the RunInfo . xml file . |
29,572 | def _read_reported ( msg_db ) : reported = [ ] if os . path . exists ( msg_db ) : with open ( msg_db ) as in_handle : for line in in_handle : reported . append ( line . strip ( ) ) return reported | Retrieve a list of directories previous reported . |
29,573 | def get_files ( data ) : all_files = glob . glob ( os . path . normpath ( os . path . join ( os . path . dirname ( dd . get_ref_file ( data ) ) , os . pardir , "viral" , "*" ) ) ) return sorted ( all_files ) | Retrieve pre - installed viral reference files . |
29,574 | def gatk_splitreads ( data ) : broad_runner = broad . runner_from_config ( dd . get_config ( data ) ) ref_file = dd . get_ref_file ( data ) deduped_bam = dd . get_deduped_bam ( data ) base , ext = os . path . splitext ( deduped_bam ) split_bam = base + ".splitN" + ext if file_exists ( split_bam ) : data = dd . set_spli... | use GATK to split reads with Ns in the CIGAR string hard clipping regions that end up in introns |
29,575 | def _setup_variant_regions ( data , out_dir ) : vr_file = dd . get_variant_regions ( data ) if not vr_file : vr_file = regions . get_sv_bed ( data , "transcripts" , out_dir = out_dir ) contigs = set ( [ c . name for c in ref . file_contigs ( dd . get_ref_file ( data ) ) ] ) out_file = os . path . join ( utils . safe_ma... | Ensure we have variant regions for calling using transcript if not present . |
29,576 | def gatk_rnaseq_calling ( data ) : from bcbio . bam import callable data = utils . deepish_copy ( data ) tools_on = dd . get_tools_on ( data ) if not tools_on : tools_on = [ ] tools_on . append ( "gvcf" ) data = dd . set_tools_on ( data , tools_on ) data = dd . set_jointcaller ( data , [ "%s-joint" % v for v in dd . ge... | Use GATK to perform gVCF variant calling on RNA - seq data |
29,577 | def filter_junction_variants ( vrn_file , data ) : SJ_BP_MASK = 10 vrn_dir = os . path . dirname ( vrn_file ) splicebed = dd . get_junction_bed ( data ) if not file_exists ( splicebed ) : logger . info ( "Splice junction BED file not found, skipping filtering of " "variants closed to splice junctions." ) return vrn_fil... | filter out variants within 10 basepairs of a splice junction these are very prone to being false positives with RNA - seq data |
29,578 | def _clean_args ( sys_argv , args ) : base = [ x for x in sys_argv if x . startswith ( "-" ) or not args . datadir == os . path . abspath ( os . path . expanduser ( x ) ) ] base = [ x for x in base if x not in set ( [ "--minimize-disk" ] ) ] if "--nodata" in base : base . remove ( "--nodata" ) else : base . append ( "-... | Remove data directory from arguments to pass to upgrade function . |
29,579 | def setup_manifest ( datadir ) : manifest_dir = os . path . join ( datadir , "manifest" ) if not os . path . exists ( manifest_dir ) : os . makedirs ( manifest_dir ) | Create barebones manifest to be filled in during update |
29,580 | def write_system_config ( base_url , datadir , tooldir ) : out_file = os . path . join ( datadir , "galaxy" , os . path . basename ( base_url ) ) if not os . path . exists ( os . path . dirname ( out_file ) ) : os . makedirs ( os . path . dirname ( out_file ) ) if os . path . exists ( out_file ) : if tooldir is None : ... | Write a bcbio_system . yaml configuration file with tool information . |
29,581 | def check_dependencies ( ) : print ( "Checking required dependencies" ) for dep , msg in [ ( [ "git" , "--version" ] , "Git (http://git-scm.com/)" ) , ( [ "wget" , "--version" ] , "wget" ) , ( [ "bzip2" , "-h" ] , "bzip2" ) ] : try : p = subprocess . Popen ( dep , stderr = subprocess . STDOUT , stdout = subprocess . PI... | Ensure required tools for installation are present . |
29,582 | def process ( args ) : os . environ [ "LC_ALL" ] = "C" os . environ [ "LC" ] = "C" os . environ [ "LANG" ] = "C" setpath . prepend_bcbiopath ( ) try : fn = getattr ( multitasks , args . name ) except AttributeError : raise AttributeError ( "Did not find exposed function in bcbio.distributed.multitasks named '%s'" % arg... | Run the function in args . name given arguments in args . argfile . |
29,583 | def _cwlvar_to_wdl ( var ) : if isinstance ( var , ( list , tuple ) ) : return [ _cwlvar_to_wdl ( x ) for x in var ] elif isinstance ( var , dict ) : assert var . get ( "class" ) == "File" , var return var . get ( "path" ) or var [ "value" ] else : return var | Convert a CWL output object into a WDL output . |
29,584 | def _write_out_argfile ( argfile , out , fnargs , parallel , out_keys , input_files , work_dir ) : with open ( argfile , "w" ) as out_handle : if argfile . endswith ( ".json" ) : record_name , record_attrs = _get_record_attrs ( out_keys ) if record_name : if parallel in [ "multi-batch" ] : recs = _nested_cwl_record ( o... | Write output argfile preparing a CWL ready JSON or YAML representation of the world . |
29,585 | def _get_record_attrs ( out_keys ) : if len ( out_keys ) == 1 : attr = list ( out_keys . keys ( ) ) [ 0 ] if out_keys [ attr ] : return attr , out_keys [ attr ] return None , None | Check for records a single key plus output attributes . |
29,586 | def _add_resources ( data , runtime ) : if "config" not in data : data [ "config" ] = { } resources = data . get ( "resources" , { } ) or { } if isinstance ( resources , six . string_types ) and resources . startswith ( ( "{" , "[" ) ) : resources = json . loads ( resources ) data [ "resources" ] = resources assert isi... | Merge input resources with current CWL runtime parameters . |
29,587 | def _world_from_cwl ( fn_name , fnargs , work_dir ) : parallel = None output_cwl_keys = None runtime = { } out = [ ] data = { } passed_keys = [ ] for fnarg in fnargs : key , val = fnarg . split ( "=" ) if key == "ignore" : continue if key == "sentinel_parallel" : parallel = val continue if key == "sentinel_runtime" : r... | Reconstitute a bcbio world data object from flattened CWL - compatible inputs . |
29,588 | def _parse_output_keys ( val ) : out = { } for k in val . split ( "," ) : if ":" in k : name , attrs = k . split ( ":" ) out [ name ] = attrs . split ( ";" ) else : out [ k ] = None return out | Parse expected output keys from string handling records . |
29,589 | def _find_input_files ( var , out ) : if isinstance ( var , ( list , tuple ) ) : for x in var : out = _find_input_files ( x , out ) elif isinstance ( var , dict ) : if var . get ( "class" ) == "File" : out . append ( var [ "path" ] ) out = _find_input_files ( var . get ( "secondaryFiles" , [ ] ) , out ) for key , val i... | Find input files within the given CWL object . |
29,590 | def _read_from_cwlinput ( in_file , work_dir , runtime , parallel , input_order , output_cwl_keys ) : with open ( in_file ) as in_handle : inputs = json . load ( in_handle ) items_by_key = { } input_files = [ ] passed_keys = set ( [ ] ) for key , input_val in ( ( k , v ) for ( k , v ) in inputs . items ( ) if not k . s... | Read data records from a JSON dump of inputs . Avoids command line flattening of records . |
29,591 | def _maybe_nest_bare_single ( items_by_key , parallel ) : if ( parallel == "multi-parallel" and ( sum ( [ 1 for x in items_by_key . values ( ) if not _is_nested_item ( x ) ] ) >= sum ( [ 1 for x in items_by_key . values ( ) if _is_nested_item ( x ) ] ) ) ) : out = { } for k , v in items_by_key . items ( ) : out [ k ] =... | Nest single inputs to avoid confusing single items and lists like files . |
29,592 | def _check_for_single_nested ( target , items_by_key , input_order ) : out = utils . deepish_copy ( items_by_key ) for ( k , t ) in input_order . items ( ) : if t == "var" : v = items_by_key [ tuple ( k . split ( "__" ) ) ] if _is_nested_single ( v , target ) : out [ tuple ( k . split ( "__" ) ) ] = v [ 0 ] return out | Check for single nested inputs that match our target count and unnest . |
29,593 | def _concat_records ( items_by_key , input_order ) : all_records = [ ] for ( k , t ) in input_order . items ( ) : if t == "record" : all_records . append ( k ) out_items_by_key = utils . deepish_copy ( items_by_key ) out_input_order = utils . deepish_copy ( input_order ) if len ( all_records ) > 1 : final_k = all_recor... | Concatenate records into a single key to avoid merging . |
29,594 | def _nest_vars_in_rec ( var_items , rec_items , input_order , items_by_key , parallel ) : num_items = var_items var_items = list ( var_items ) [ 0 ] if rec_items : rec_items = list ( rec_items ) [ 0 ] if ( ( rec_items == 1 and var_items > 1 ) or parallel . startswith ( "batch" ) ) : num_items = set ( [ rec_items ] ) fo... | Nest multiple variable inputs into a single record or list of batch records . |
29,595 | def _expand_rec_to_vars ( var_items , rec_items , input_order , items_by_key , parallel ) : num_items = var_items var_items = list ( var_items ) [ 0 ] if rec_items : for rec_key in ( k for ( k , t ) in input_order . items ( ) if t == "record" ) : rec_vals = items_by_key [ rec_key ] if len ( rec_vals ) == 1 and var_item... | Expand record to apply to number of variants . |
29,596 | def _read_cwl_record ( rec ) : keys = set ( [ ] ) out = [ ] if isinstance ( rec , dict ) : is_batched = all ( [ isinstance ( v , ( list , tuple ) ) for v in rec . values ( ) ] ) cur = [ { } for _ in range ( len ( rec . values ( ) [ 0 ] ) if is_batched else 1 ) ] for k in rec . keys ( ) : keys . add ( k ) val = rec [ k ... | Read CWL records handling multiple nesting and batching cases . |
29,597 | def _finalize_cwl_in ( data , work_dir , passed_keys , output_cwl_keys , runtime ) : data [ "dirs" ] = { "work" : work_dir } if not tz . get_in ( [ "config" , "algorithm" ] , data ) : if "config" not in data : data [ "config" ] = { } data [ "config" ] [ "algorithm" ] = { } if "rgnames" not in data and "description" in ... | Finalize data object with inputs from CWL . |
29,598 | def _convert_value ( val ) : def _is_number ( x , op ) : try : op ( x ) return True except ValueError : return False if isinstance ( val , ( list , tuple ) ) : return [ _convert_value ( x ) for x in val ] elif val is None : return val elif _is_number ( val , int ) : return int ( val ) elif _is_number ( val , float ) : ... | Handle multiple input type values . |
29,599 | def _get_output_cwl_keys ( fnargs ) : for d in utils . flatten ( fnargs ) : if isinstance ( d , dict ) and d . get ( "output_cwl_keys" ) : return d [ "output_cwl_keys" ] raise ValueError ( "Did not find output_cwl_keys in %s" % ( pprint . pformat ( fnargs ) ) ) | Retrieve output_cwl_keys from potentially nested input arguments . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.