idx
int64
0
251k
question
stringlengths
53
3.53k
target
stringlengths
5
1.23k
len_question
int64
20
893
len_target
int64
3
238
2,800
def deny_role ( role ) : def processor ( action , argument ) : db . session . add ( ActionRoles . deny ( action , argument = argument , role_id = role . id ) ) return processor
Deny a role identified by an email address .
45
10
2,801
def process_deny_action ( processors , action , argument ) : for processor in processors : processor ( action , argument ) db . session . commit ( )
Process deny action .
33
4
2,802
def remove_global ( ) : def processor ( action , argument ) : ActionUsers . query_by_action ( action , argument = argument ) . filter ( ActionUsers . user_id . is_ ( None ) ) . delete ( synchronize_session = False ) return processor
Remove global action rule .
58
5
2,803
def remove_user ( user ) : def processor ( action , argument ) : ActionUsers . query_by_action ( action , argument = argument ) . filter ( ActionUsers . user_id == user . id ) . delete ( synchronize_session = False ) return processor
Remove a action for a user .
57
7
2,804
def remove_role ( role ) : def processor ( action , argument ) : ActionRoles . query_by_action ( action , argument = argument ) . filter ( ActionRoles . role_id == role . id ) . delete ( synchronize_session = False ) return processor
Remove a action for a role .
59
7
2,805
def process_remove_action ( processors , action , argument ) : for processor in processors : processor ( action , argument ) db . session . commit ( )
Process action removals .
32
6
2,806
def list_actions ( ) : for name , action in _current_actions . items ( ) : click . echo ( '{0}:{1}' . format ( name , '*' if hasattr ( action , 'argument' ) else '' ) )
List all registered actions .
55
5
2,807
def show_actions ( email , role ) : if email : actions = ActionUsers . query . join ( ActionUsers . user ) . filter ( User . email . in_ ( email ) ) . all ( ) for action in actions : click . secho ( 'user:{0}:{1}:{2}:{3}' . format ( action . user . email , action . action , '' if action . argument is None else action ....
Show all assigned actions .
240
5
2,808
def run_mhc_gene_assessment ( job , rsem_files , rna_haplotype , univ_options , reports_options ) : return job . addChildJobFn ( assess_mhc_genes , rsem_files [ 'rsem.genes.results' ] , rna_haplotype , univ_options , reports_options ) . rv ( )
A wrapper for assess_mhc_genes .
92
12
2,809
def parse_config_file ( job , config_file ) : job . fileStore . logToMaster ( 'Parsing config file' ) config_file = os . path . abspath ( config_file ) if not os . path . exists ( config_file ) : raise ParameterError ( 'The config file was not found at specified location. Please verify ' + 'and retry.' ) # Initialize v...
This module will parse the config file withing params and set up the variables that will be passed to the various tools in the pipeline .
753
27
2,810
def run_cutadapt ( job , fastqs , univ_options , cutadapt_options ) : job . fileStore . logToMaster ( 'Running cutadapt on %s' % univ_options [ 'patient' ] ) work_dir = job . fileStore . getLocalTempDir ( ) fq_extn = '.gz' if fastqs [ 'gzipped' ] else '' input_files = { 'rna_1.fastq' + fq_extn : fastqs [ 'tumor_rna' ] ...
This module runs cutadapt on the input RNA fastq files and then calls the RNA aligners .
450
20
2,811
def run_star ( job , fastqs , univ_options , star_options ) : assert star_options [ 'type' ] in ( 'star' , 'starlong' ) job . fileStore . logToMaster ( 'Running STAR on %s' % univ_options [ 'patient' ] ) work_dir = job . fileStore . getLocalTempDir ( ) input_files = { 'rna_cutadapt_1.fastq' : fastqs [ 'rna_cutadapt_1.f...
This module uses STAR to align the RNA fastqs to the reference
702
13
2,812
def run_bwa ( job , fastqs , sample_type , univ_options , bwa_options ) : job . fileStore . logToMaster ( 'Running bwa on %s:%s' % ( univ_options [ 'patient' ] , sample_type ) ) work_dir = job . fileStore . getLocalTempDir ( ) fq_extn = '.gz' if fastqs [ 'gzipped' ] else '' input_files = { 'dna_1.fastq' + fq_extn : fas...
This module aligns the SAMPLE_TYPE dna fastqs to the reference
538
16
2,813
def bam_conversion ( job , samfile , sample_type , univ_options ) : job . fileStore . logToMaster ( 'Running sam2bam on %s:%s' % ( univ_options [ 'patient' ] , sample_type ) ) work_dir = job . fileStore . getLocalTempDir ( ) input_files = { 'aligned.sam' : samfile } input_files = get_files_from_filestore ( job , input_...
This module converts SAMFILE from sam to bam
309
10
2,814
def fix_bam_header ( job , bamfile , sample_type , univ_options ) : job . fileStore . logToMaster ( 'Running reheader on %s:%s' % ( univ_options [ 'patient' ] , sample_type ) ) work_dir = job . fileStore . getLocalTempDir ( ) input_files = { 'aligned.bam' : bamfile } input_files = get_files_from_filestore ( job , input...
This module modified the header in BAMFILE
551
9
2,815
def run_rsem ( job , star_bams , univ_options , rsem_options ) : job . fileStore . logToMaster ( 'Running rsem index on %s' % univ_options [ 'patient' ] ) work_dir = job . fileStore . getLocalTempDir ( ) input_files = { 'star_transcriptome.bam' : star_bams [ 'rnaAligned.toTranscriptome.out.bam' ] , 'rsem_index.tar.gz' ...
This module will run rsem on the RNA Bam file .
329
12
2,816
def merge_radia ( job , perchrom_rvs ) : job . fileStore . logToMaster ( 'Running merge_radia' ) work_dir = job . fileStore . getLocalTempDir ( ) # We need to squash the input dict of dicts to a single dict such that it can be passed to # get_files_from_filestore input_files = { filename : jsid for perchrom_files in pe...
This module will merge the per - chromosome radia files created by spawn_radia into a genome vcf . It will make 2 vcfs one for PASSing non - germline calls and one for all calls .
577
45
2,817
def run_radia ( job , bams , univ_options , radia_options , chrom ) : job . fileStore . logToMaster ( 'Running radia on %s:%s' % ( univ_options [ 'patient' ] , chrom ) ) work_dir = job . fileStore . getLocalTempDir ( ) input_files = { 'rna.bam' : bams [ 'tumor_rna' ] , 'rna.bam.bai' : bams [ 'tumor_rnai' ] , 'tumor.bam...
This module will run radia on the RNA and DNA bams
765
13
2,818
def run_filter_radia ( job , bams , radia_file , univ_options , radia_options , chrom ) : job . fileStore . logToMaster ( 'Running filter-radia on %s:%s' % ( univ_options [ 'patient' ] , chrom ) ) work_dir = job . fileStore . getLocalTempDir ( ) input_files = { 'rna.bam' : bams [ 'tumor_rna' ] , 'rna.bam.bai' : bams [ ...
This module will run filterradia on the RNA and DNA bams .
817
15
2,819
def merge_mutect ( job , perchrom_rvs ) : job . fileStore . logToMaster ( 'Running merge_mutect' ) work_dir = job . fileStore . getLocalTempDir ( ) # We need to squash the input dict of dicts to a single dict such that it can be passed to # get_files_from_filestore input_files = { filename : jsid for perchrom_files in ...
This module will merge the per - chromosome mutect files created by spawn_mutect into a genome vcf . It will make 2 vcfs one for PASSing non - germline calls and one for all calls .
591
45
2,820
def run_mutect ( job , tumor_bam , normal_bam , univ_options , mutect_options , chrom ) : job . fileStore . logToMaster ( 'Running mutect on %s:%s' % ( univ_options [ 'patient' ] , chrom ) ) work_dir = job . fileStore . getLocalTempDir ( ) input_files = { 'tumor.bam' : tumor_bam [ 'tumor_dna_fix_pg_sorted.bam' ] , 'tum...
This module will run mutect on the DNA bams
796
11
2,821
def run_indel_caller ( job , tumor_bam , normal_bam , univ_options , indel_options ) : job . fileStore . logToMaster ( 'Running INDEL on %s' % univ_options [ 'patient' ] ) indel_file = job . fileStore . getLocalTempFile ( ) output_file = job . fileStore . writeGlobalFile ( indel_file ) return output_file
This module will run an indel caller on the DNA bams . This module will be implemented in the future .
98
23
2,822
def run_fusion_caller ( job , star_bam , univ_options , fusion_options ) : job . fileStore . logToMaster ( 'Running FUSION on %s' % univ_options [ 'patient' ] ) fusion_file = job . fileStore . getLocalTempFile ( ) output_file = job . fileStore . writeGlobalFile ( fusion_file ) return output_file
This module will run a fusion caller on DNA bams . This module will be implemented in the future .
91
21
2,823
def run_mutation_aggregator ( job , fusion_output , radia_output , mutect_output , indel_output , univ_options ) : job . fileStore . logToMaster ( 'Aggregating mutations for %s' % univ_options [ 'patient' ] ) work_dir = job . fileStore . getLocalTempDir ( ) input_files = { 'mutect.vcf' : mutect_output , 'radia.vcf' : r...
This module will aggregate all the mutations called in the previous steps and will then call snpeff on the results .
526
23
2,824
def run_snpeff ( job , merged_mutation_file , univ_options , snpeff_options ) : job . fileStore . logToMaster ( 'Running snpeff on %s' % univ_options [ 'patient' ] ) work_dir = job . fileStore . getLocalTempDir ( ) input_files = { 'merged_mutations.vcf' : merged_mutation_file , 'snpeff_index.tar.gz' : snpeff_options [ ...
This module will run snpeff on the aggregated mutation calls . Currently the only mutations called are SNPs hence SnpEff suffices . This node will be replaced in the future with another translator .
440
42
2,825
def run_transgene ( job , snpeffed_file , univ_options , transgene_options ) : job . fileStore . logToMaster ( 'Running transgene on %s' % univ_options [ 'patient' ] ) work_dir = job . fileStore . getLocalTempDir ( ) input_files = { 'snpeffed_muts.vcf' : snpeffed_file , 'pepts.fa' : transgene_options [ 'gencode_peptide...
This module will run transgene on the input vcf file from the aggregator and produce the peptides for MHC prediction
438
26
2,826
def run_phlat ( job , fastqs , sample_type , univ_options , phlat_options ) : job . fileStore . logToMaster ( 'Running phlat on %s:%s' % ( univ_options [ 'patient' ] , sample_type ) ) work_dir = job . fileStore . getLocalTempDir ( ) fq_extn = '.gz' if fastqs [ 'gzipped' ] else '' input_files = { 'input_1.fastq' + fq_ex...
This module will run PHLAT on SAMPLE_TYPE fastqs .
430
15
2,827
def merge_phlat_calls ( job , tumor_phlat , normal_phlat , rna_phlat ) : job . fileStore . logToMaster ( 'Merging Phlat calls' ) work_dir = job . fileStore . getLocalTempDir ( ) input_files = { 'tumor_dna' : tumor_phlat , 'normal_dna' : normal_phlat , 'tumor_rna' : rna_phlat } input_files = get_files_from_filestore ( j...
This module will merge the results form running PHLAT on the 3 input fastq pairs .
812
19
2,828
def boost_ranks ( job , isoform_expression , merged_mhc_calls , transgene_out , univ_options , rank_boost_options ) : job . fileStore . logToMaster ( 'Running boost_ranks on %s' % univ_options [ 'patient' ] ) work_dir = os . path . join ( job . fileStore . getLocalTempDir ( ) , univ_options [ 'patient' ] ) os . mkdir (...
This is the final module in the pipeline . It will call the rank boosting R script .
644
18
2,829
def get_files_from_filestore ( job , files , work_dir , cache = True , docker = False ) : for name in files . keys ( ) : outfile = job . fileStore . readGlobalFile ( files [ name ] , '/' . join ( [ work_dir , name ] ) , cache = cache ) # If the file pointed to a tarball, extract it to WORK_DIR if tarfile . is_tarfile (...
This is adapted from John Vivian s return_input_paths from the RNA - Seq pipeline .
430
22
2,830
def merge_vcfs ( vcf_file , merged_mut_file ) : mutect_keys = set ( vcf_file [ 'mutect' ] . keys ( ) ) radia_keys = set ( vcf_file [ 'radia' ] . keys ( ) ) common_keys = radia_keys . intersection ( mutect_keys ) # Open as append since the header is already written with open ( merged_mut_file , 'a' ) as outfile : for mu...
This module will accept the vcf files for mutect and radia read into memory in a dict object VCF_FILE and will merge the calls . Merged calls are printed to MERGED_MUT_FILE .
143
46
2,831
def docker_call ( tool , tool_parameters , work_dir , java_opts = None , outfile = None , dockerhub = 'aarjunrao' , interactive = False ) : # If an outifle has been provided, then ensure that it is of type file, it is writeable, and # that it is open. if outfile : assert isinstance ( outfile , file ) , 'outfile was not...
Makes subprocess call of a command to a docker container . work_dir MUST BE AN ABSOLUTE PATH or the call will fail . outfile is an open file descriptor to a writeable file .
679
42
2,832
def untargz ( input_targz_file , untar_to_dir ) : assert tarfile . is_tarfile ( input_targz_file ) , 'Not a tar file.' tarball = tarfile . open ( input_targz_file ) return_value = os . path . join ( untar_to_dir , tarball . getmembers ( ) [ 0 ] . name ) tarball . extractall ( path = untar_to_dir ) tarball . close ( ) r...
This module accepts a tar . gz archive and untars it .
116
14
2,833
def bam2fastq ( job , bamfile , univ_options ) : work_dir = os . path . split ( bamfile ) [ 0 ] base_name = os . path . split ( os . path . splitext ( bamfile ) [ 0 ] ) [ 1 ] parameters = [ 'SamToFastq' , '' . join ( [ 'I=' , docker_path ( bamfile ) ] ) , '' . join ( [ 'F=/data/' , base_name , '_1.fastq' ] ) , '' . joi...
split an input bam to paired fastqs .
279
10
2,834
def main ( ) : parser = argparse . ArgumentParser ( ) parser . add_argument ( '--config_file' , dest = 'config_file' , help = 'Config file to be used in the' + 'run.' , type = str , required = True , default = None ) Job . Runner . addToilOptions ( parser ) params = parser . parse_args ( ) START = Job . wrapJobFn ( par...
This is the main function for the UCSC Precision Immuno pipeline .
123
14
2,835
def run_strelka_with_merge ( job , tumor_bam , normal_bam , univ_options , strelka_options ) : spawn = job . wrapJobFn ( run_strelka , tumor_bam , normal_bam , univ_options , strelka_options , split = False ) . encapsulate ( ) job . addChild ( spawn ) return spawn . rv ( )
A wrapper for the the entire strelka sub - graph .
95
13
2,836
def run_strelka ( job , tumor_bam , normal_bam , univ_options , strelka_options , split = True ) : if strelka_options [ 'chromosomes' ] : chromosomes = strelka_options [ 'chromosomes' ] else : chromosomes = sample_chromosomes ( job , strelka_options [ 'genome_fai' ] ) num_cores = min ( len ( chromosomes ) , univ_option...
Run the strelka subgraph on the DNA bams . Optionally split the results into per - chromosome vcfs .
345
26
2,837
def run_strelka_full ( job , tumor_bam , normal_bam , univ_options , strelka_options ) : work_dir = os . getcwd ( ) input_files = { 'tumor.bam' : tumor_bam [ 'tumor_dna_fix_pg_sorted.bam' ] , 'tumor.bam.bai' : tumor_bam [ 'tumor_dna_fix_pg_sorted.bam.bai' ] , 'normal.bam' : normal_bam [ 'normal_dna_fix_pg_sorted.bam' ]...
Run strelka on the DNA bams .
608
10
2,838
def wrap_unmerge ( job , strelka_out , chromosomes , strelka_options , univ_options ) : return { 'snvs' : job . addChildJobFn ( unmerge , strelka_out [ 'snvs' ] , 'strelka/snv' , chromosomes , strelka_options , univ_options ) . rv ( ) , 'indels' : job . addChildJobFn ( unmerge , strelka_out [ 'indels' ] , 'strelka/inde...
A wwrapper to unmerge the strelka snvs and indels
145
16
2,839
def get_iso_time_str ( timestamp : Union [ int , float , str , datetime ] = None ) -> str : if isinstance ( timestamp , ( int , float ) ) : maya_dt = maya . MayaDT ( timestamp ) elif isinstance ( timestamp , str ) : maya_dt = maya . when ( timestamp ) elif timestamp is None : maya_dt = maya . now ( ) else : raise Value...
Get the ISO time string from a timestamp or date obj . Returns current time str if no timestamp is passed
125
21
2,840
def truncate ( value : Decimal , n_digits : int ) -> Decimal : return Decimal ( math . trunc ( value * ( 10 ** n_digits ) ) ) / ( 10 ** n_digits )
Truncates a value to a number of decimals places
49
13
2,841
def truncate_to ( value : Decimal , currency : str ) -> Decimal : decimal_places = DECIMALS . get ( currency . upper ( ) , 2 ) return truncate ( value , decimal_places )
Truncates a value to the number of decimals corresponding to the currency
47
16
2,842
def truncate_money ( money : Money ) -> Money : amount = truncate_to ( money . amount , money . currency ) return Money ( amount , money . currency )
Truncates money amount to the number of decimals corresponding to the currency
37
16
2,843
def spread_value ( value : Decimal , spread_p : Decimal ) -> Tuple [ Decimal , Decimal ] : upper = value * ( 1 + spread_p ) lower = value / ( 1 + spread_p ) return lower , upper
Returns a lower and upper value separated by a spread percentage
54
11
2,844
def spread_money ( money : Money , spread_p : Decimal ) -> Tuple [ Money , Money ] : upper , lower = spread_value ( money . amount , spread_p ) return Money ( upper , money . currency ) , Money ( lower , money . currency )
Returns a lower and upper money amount separated by a spread percentage
59
12
2,845
def check_valid_ad_range ( date ) : if date < values . START_EN_DATE or date > values . END_EN_DATE : raise ValueError ( "Date out of range" ) return True
Checks if the english date is in valid range for conversion
48
12
2,846
def check_valid_bs_range ( date ) : ERR_MSG = "%s out of range" % str ( date ) if date . year < values . START_NP_YEAR or date . year > values . END_NP_YEAR : raise ValueError ( ERR_MSG ) if date . month < 1 or date . month > 12 : raise ValueError ( ERR_MSG ) if date . day < 1 or date . day > values . NEPALI_MONTH_DAY_...
Checks if the nepali date is in valid range for conversion
138
13
2,847
def nepali_number ( number ) : nepnum = "" for n in str ( number ) : nepnum += values . NEPDIGITS [ int ( n ) ] return nepnum
Convert a number to nepali
42
7
2,848
def get_fields ( self ) : fields = super ( GeoModelSerializer , self ) . get_fields ( ) # Set the geometry field name when it's undeclared. if not self . Meta . geom_field : for name , field in fields . items ( ) : if isinstance ( field , GeometryField ) : self . Meta . geom_field = name break return fields
Returns a fields dict for this serializer with a geometry field added .
84
14
2,849
def run_muse_with_merge ( job , tumor_bam , normal_bam , univ_options , muse_options ) : spawn = job . wrapJobFn ( run_muse , tumor_bam , normal_bam , univ_options , muse_options , disk = '100M' ) . encapsulate ( ) merge = job . wrapJobFn ( merge_perchrom_vcfs , spawn . rv ( ) , disk = '100M' ) job . addChild ( spawn )...
A wrapper for the the entire MuSE sub - graph .
130
12
2,850
def run_muse ( job , tumor_bam , normal_bam , univ_options , muse_options ) : # Get a list of chromosomes to handle if muse_options [ 'chromosomes' ] : chromosomes = muse_options [ 'chromosomes' ] else : chromosomes = sample_chromosomes ( job , muse_options [ 'genome_fai' ] ) perchrom_muse = defaultdict ( ) for chrom i...
Spawn a MuSE job for each chromosome on the DNA bams .
317
14
2,851
def run_muse_perchrom ( job , tumor_bam , normal_bam , univ_options , muse_options , chrom ) : work_dir = os . getcwd ( ) input_files = { 'tumor.bam' : tumor_bam [ 'tumor_dna_fix_pg_sorted.bam' ] , 'tumor.bam.bai' : tumor_bam [ 'tumor_dna_fix_pg_sorted.bam.bai' ] , 'normal.bam' : normal_bam [ 'normal_dna_fix_pg_sorted....
Run MuSE call on a single chromosome in the input bams .
554
14
2,852
def run_muse_sump_perchrom ( job , muse_output , univ_options , muse_options , chrom ) : work_dir = os . getcwd ( ) input_files = { 'MuSE.txt' : muse_output , 'dbsnp_coding.vcf.gz' : muse_options [ 'dbsnp_vcf' ] , 'dbsnp_coding.vcf.gz.tbi.tmp' : muse_options [ 'dbsnp_tbi' ] } input_files = get_files_from_filestore ( jo...
Run MuSE sump on the MuSE call generated vcf .
504
14
2,853
def linear ( self , limits = None , k = 5 ) : start , stop = limits or ( self . minval , self . maxval ) return np . linspace ( start , stop , k )
Returns an ndarray of linear breaks .
44
9
2,854
def quantiles ( self , k = 5 ) : arr = self . array ( ) q = list ( np . linspace ( 0 , 100 , k ) ) return np . percentile ( arr . compressed ( ) , q )
Returns an ndarray of quantile breaks .
48
10
2,855
def to_python ( self , value ) : if not value : return [ ] return map ( super ( CommaSepFloatField , self ) . to_python , value . split ( ',' ) )
Normalize data to a list of floats .
43
9
2,856
def run_validators ( self , values ) : for val in values : super ( CommaSepFloatField , self ) . run_validators ( val )
Run validators for each item separately .
34
8
2,857
def to_python ( self , value ) : value = super ( BoundingBoxField , self ) . to_python ( value ) try : bbox = gdal . OGRGeometry . from_bbox ( value ) . geos except ( ValueError , AttributeError ) : return [ ] bbox . srid = self . srid return bbox
Returns a GEOS Polygon from bounding box values .
77
12
2,858
def run_mutect_with_merge ( job , tumor_bam , normal_bam , univ_options , mutect_options ) : spawn = job . wrapJobFn ( run_mutect , tumor_bam , normal_bam , univ_options , mutect_options ) . encapsulate ( ) merge = job . wrapJobFn ( merge_perchrom_vcfs , spawn . rv ( ) ) job . addChild ( spawn ) spawn . addChild ( merg...
A wrapper for the the entire MuTect sub - graph .
118
13
2,859
def run_mutect ( job , tumor_bam , normal_bam , univ_options , mutect_options ) : # Get a list of chromosomes to handle if mutect_options [ 'chromosomes' ] : chromosomes = mutect_options [ 'chromosomes' ] else : chromosomes = sample_chromosomes ( job , mutect_options [ 'genome_fai' ] ) perchrom_mutect = defaultdict ( )...
Spawn a MuTect job for each chromosome on the DNA bams .
273
15
2,860
def process_mutect_vcf ( job , mutect_vcf , work_dir , univ_options ) : mutect_vcf = job . fileStore . readGlobalFile ( mutect_vcf ) with open ( mutect_vcf , 'r' ) as infile , open ( mutect_vcf + 'mutect_parsed.tmp' , 'w' ) as outfile : for line in infile : line = line . strip ( ) if line . startswith ( '#' ) : print (...
Process the MuTect vcf for accepted calls .
171
11
2,861
def get_universe ( self , as_str = False ) : result = self . _iface . get_connected_universe ( ) if as_str : return Universe . get_alias ( result ) return result
Returns universe the client is connected to . See Universe .
47
11
2,862
def EXTRA_LOGGING ( self ) : input_text = get ( 'EXTRA_LOGGING' , '' ) modules = input_text . split ( ',' ) if input_text : modules = input_text . split ( ',' ) modules = [ x . split ( ':' ) for x in modules ] else : modules = [ ] return modules
lista modulos con los distintos niveles a logear y su nivel de debug
78
23
2,863
def from_ad_date ( cls , date ) : functions . check_valid_ad_range ( date ) days = values . START_EN_DATE - date # Add the required number of days to the start nepali date start_date = NepDate ( values . START_NP_YEAR , 1 , 1 ) # No need to update as addition already calls update return start_date + ( date - values . S...
Gets a NepDate object from gregorian calendar date
97
12
2,864
def from_bs_date ( cls , year , month , day ) : return NepDate ( year , month , day ) . update ( )
Create and update an NepDate object for bikram sambat date
31
15
2,865
def events_list ( self ) : evt = [ ] evt . extend ( events . NEPALI_EVENTS [ self . month , self . day ] ) evt . extend ( events . ENGLISH_EVENTS [ self . en_date . month , self . en_date . day ] ) return evt
Returns the events today
71
4
2,866
def update ( self ) : functions . check_valid_bs_range ( self ) # Here's a trick to find the gregorian date: # We find the number of days from earliest nepali date to the current # day. We then add the number of days to the earliest english date self . en_date = values . START_EN_DATE + ( self - NepDate ( values . STAR...
Updates information about the NepDate
98
7
2,867
def get_file_from_s3 ( job , s3_url , encryption_key = None , write_to_jobstore = True ) : work_dir = job . fileStore . getLocalTempDir ( ) filename = '/' . join ( [ work_dir , os . path . basename ( s3_url ) ] ) # This is common to encrypted and unencrypted downloads download_call = [ 'curl' , '-fs' , '--retry' , '5' ...
Downloads a supplied URL that points to an unencrypted unprotected file on Amazon S3 . The file is downloaded and a subsequently written to the jobstore and the return value is a the path to the file in the jobstore .
477
46
2,868
def filter_geometry ( queryset , * * filters ) : fieldname = geo_field ( queryset ) . name query = { '%s__%s' % ( fieldname , k ) : v for k , v in filters . items ( ) } return queryset . filter ( * * query )
Helper function for spatial lookups filters .
69
8
2,869
def geo_field ( queryset ) : for field in queryset . model . _meta . fields : if isinstance ( field , models . GeometryField ) : return field raise exceptions . FieldDoesNotExist ( 'No GeometryField found' )
Returns the GeometryField for a django or spillway GeoQuerySet .
56
16
2,870
def get_srid ( queryset ) : try : srid = list ( six . viewvalues ( queryset . query . annotations ) ) [ 0 ] . srid except ( AttributeError , IndexError ) : srid = None return srid or geo_field ( queryset ) . srid
Returns the GeoQuerySet spatial reference identifier .
67
9
2,871
def agg_dims ( arr , stat ) : axis = None if arr . ndim > 2 : axis = 1 arr = arr . reshape ( arr . shape [ 0 ] , - 1 ) module = np . ma if hasattr ( arr , 'mask' ) else np return getattr ( module , stat ) ( arr , axis )
Returns a 1D array with higher dimensions aggregated using stat fn .
72
14
2,872
def extent ( self , srid = None ) : expr = self . geo_field . name if srid : expr = geofn . Transform ( expr , srid ) expr = models . Extent ( expr ) clone = self . all ( ) name , val = clone . aggregate ( expr ) . popitem ( ) return val
Returns the GeoQuerySet extent as a 4 - tuple .
70
12
2,873
def pbf ( self , bbox , geo_col = None , scale = 4096 ) : col = geo_col or self . geo_field . name w , s , e , n = bbox . extent trans = self . _trans_scale ( col , - w , - s , scale / ( e - w ) , scale / ( n - s ) ) g = AsText ( trans ) return self . annotate ( pbf = g )
Returns tranlated and scaled geometries suitable for Mapbox vector tiles .
96
16
2,874
def tile ( self , bbox , z = 0 , format = None , clip = True ) : # Tile grid uses 3857, but GeoJSON coordinates should be in 4326. tile_srid = 3857 bbox = getattr ( bbox , 'geos' , bbox ) clone = filter_geometry ( self , intersects = bbox ) field = clone . geo_field srid = field . srid sql = field . name try : tilew = ...
Returns a GeoQuerySet intersecting a tile boundary .
298
11
2,875
def arrays ( self , field_name = None ) : fieldname = field_name or self . raster_field . name arrays = [ ] for obj in self : arr = getattr ( obj , fieldname ) if isinstance ( arr , np . ndarray ) : arrays . append ( arr ) else : arrays . append ( obj . array ( ) ) return arrays
Returns a list of ndarrays .
79
9
2,876
def aggregate_periods ( self , periods ) : try : fieldname = self . raster_field . name except TypeError : raise exceptions . FieldDoesNotExist ( 'Raster field not found' ) arrays = self . arrays ( fieldname ) arr = arrays [ 0 ] if len ( arrays ) > 1 : if getattr ( arr , 'ndim' , 0 ) > 2 : arrays = np . vstack ( arrays...
Returns list of ndarrays averaged to a given number of periods .
217
15
2,877
def raster_field ( self ) : for field in self . model . _meta . fields : if isinstance ( field , models . FileField ) : return field return False
Returns the raster FileField instance on the model .
37
11
2,878
def zipfiles ( self , path = None , arcdirname = 'data' ) : if path : fp = open ( path , 'w+b' ) else : prefix = '%s-' % arcdirname fp = tempfile . NamedTemporaryFile ( prefix = prefix , suffix = '.zip' ) with zipfile . ZipFile ( fp , mode = 'w' ) as zf : for obj in self : img = obj . image arcname = os . path . join (...
Returns a . zip archive of selected rasters .
200
10
2,879
def init ( self , app_id = None ) : self . set_app_id ( app_id ) err_msg = ( 'Unable to initialize. Check Steam client is running ' 'and Steam application ID is defined in steam_appid.txt or passed to Api.' ) if self . _lib . steam_init ( ) : try : _set_client ( self . _lib . Client ( ) ) self . utils = Utils ( ) self ...
Initializes Steam API library .
190
6
2,880
def get_files_from_filestore ( job , files , work_dir , docker = False ) : for name in files . keys ( ) : outfile = job . fileStore . readGlobalFile ( files [ name ] , '/' . join ( [ work_dir , name ] ) ) # If the files will be sent to docker, we will mount work_dir to the container as /data and # we want the /data pre...
Download a dict of files to the given directory and modify the path to a docker - friendly one if requested .
125
22
2,881
def gunzip ( input_gzip_file , block_size = 1024 ) : assert os . path . splitext ( input_gzip_file ) [ 1 ] == '.gz' assert is_gzipfile ( input_gzip_file ) with gzip . open ( input_gzip_file ) as infile : with open ( os . path . splitext ( input_gzip_file ) [ 0 ] , 'w' ) as outfile : while True : block = infile . read (...
Gunzips the input file to the same directory
136
10
2,882
def is_gzipfile ( filename ) : assert os . path . exists ( filename ) , 'Input {} does not ' . format ( filename ) + 'point to a file.' with open ( filename , 'rb' ) as in_f : start_of_file = in_f . read ( 3 ) if start_of_file == '\x1f\x8b\x08' : return True else : return False
Attempt to ascertain the gzip status of a file based on the magic signatures of the file .
93
19
2,883
def get_file_from_gdc ( job , gdc_url , gdc_download_token , write_to_jobstore = True ) : work_dir = job . fileStore . getLocalTempDir ( ) parsed_url = urlparse ( gdc_url ) assert parsed_url . scheme == 'gdc' , 'Unexpected url scheme: %s' % gdc_url file_dir = '/' . join ( [ work_dir , parsed_url . netloc ] ) # This is ...
Download a supplied URL that points to a file in the NCBI GDC database . The path to the gdc download token must be provided . The file is downloaded and written to the jobstore if requested .
460
42
2,884
def get_file_from_url ( job , any_url , encryption_key = None , per_file_encryption = True , write_to_jobstore = True ) : work_dir = job . fileStore . getLocalTempDir ( ) filename = '/' . join ( [ work_dir , str ( uuid . uuid4 ( ) ) ] ) url = any_url parsed_url = urlparse ( any_url ) try : response = urllib2 . urlopen ...
Download a supplied URL that points to a file on an http https or ftp server . If the file is found to be an https s3 link then the file is downloaded using get_file_from_s3 . The file is downloaded and written to the jobstore if requested . Encryption arguments are for passing to get_file_from_s3 if required .
269
76
2,885
def bam2fastq ( bamfile , univ_options , picard_options ) : work_dir = os . path . split ( bamfile ) [ 0 ] base_name = os . path . split ( os . path . splitext ( bamfile ) [ 0 ] ) [ 1 ] parameters = [ 'SamToFastq' , '' . join ( [ 'I=' , docker_path ( bamfile ) ] ) , '' . join ( [ 'F=/data/' , base_name , '_1.fastq' ] )...
Split an input bam to paired fastqs .
296
10
2,886
def export_results ( job , fsid , file_name , univ_options , subfolder = None ) : job . fileStore . logToMaster ( 'Exporting %s to output location' % fsid ) file_name = os . path . basename ( file_name ) try : assert univ_options [ 'output_folder' ] , 'Need a path to a folder to write out files' assert univ_options [ '...
Write out a file to a given location . The location can be either a directory on the local machine or a folder with a bucket on AWS .
482
29
2,887
def parse_chromosome_string ( job , chromosome_string ) : if chromosome_string is None : return [ ] else : assert isinstance ( chromosome_string , str ) chroms = [ c . strip ( ) for c in chromosome_string . split ( ',' ) ] if 'canonical' in chroms : assert 'canonical_chr' not in chroms , 'Cannot have canonical and cano...
Parse a chromosome string into a list .
357
9
2,888
def email_report ( job , univ_options ) : fromadd = "results@protect.cgl.genomics.ucsc.edu" msg = MIMEMultipart ( ) msg [ 'From' ] = fromadd if univ_options [ 'mail_to' ] is None : return else : msg [ 'To' ] = univ_options [ 'mail_to' ] msg [ 'Subject' ] = "Protect run for sample %s completed successfully." % univ_opti...
Send an email to the user when the run finishes .
267
11
2,889
def make_key_hippie ( obj , typed = True ) : ftype = type if typed else lambda o : None if is_hashable ( obj ) : ## DO NOT RETURN hash(obj), as hash collision would generate bad ## cache collisions. return obj , ftype ( obj ) ## should we try to convert to frozen{set,dict} to get the C ## hashing function speed ? But t...
Return hashable structure from non - hashable structure using hippie means
219
14
2,890
def undecorate ( func ) : orig_call_wrapper = lambda x : x for call_wrapper , unwrap in SUPPORTED_DECORATOR . items ( ) : if isinstance ( func , call_wrapper ) : func = unwrap ( func ) orig_call_wrapper = call_wrapper break return orig_call_wrapper , func
Returns the decorator and the undecorated function of given object .
73
15
2,891
def item ( ctx , appid , title ) : ctx . obj [ 'appid' ] = appid ctx . obj [ 'title' ] = title
Market - related commands .
36
5
2,892
def get_price ( ctx , currency ) : appid = ctx . obj [ 'appid' ] title = ctx . obj [ 'title' ] item_ = Item ( appid , title ) item_ . get_price_data ( currency ) click . secho ( 'Lowest price: %s %s' % ( item_ . price_lowest , item_ . price_currency ) , fg = 'green' )
Prints out market item price .
96
7
2,893
def get_cards ( ctx ) : appid = ctx . obj [ 'appid' ] app = Application ( appid ) click . secho ( 'Cards for `%s` [appid: %s]' % ( app . title , appid ) , fg = 'green' ) if not app . has_cards : click . secho ( 'This app has no cards.' , fg = 'red' , err = True ) return cards , booster = app . get_cards ( ) def get_lin...
Prints out cards available for application .
222
8
2,894
def get_card_prices ( ctx , currency ) : appid = ctx . obj [ 'appid' ] detailed = True appids = [ appid ] if ',' in appid : appids = [ appid . strip ( ) for appid in appid . split ( ',' ) ] detailed = False for appid in appids : print_card_prices ( appid , currency , detailed = detailed ) click . echo ( '' )
Prints out lowest card prices for an application . Comma - separated list of application IDs is supported .
99
21
2,895
def get_gems ( ctx ) : username = ctx . obj [ 'username' ] click . secho ( 'Total gems owned by `%s`: %d' % ( username , User ( username ) . gems_total ) , fg = 'green' )
Prints out total gems count for a Steam user .
60
11
2,896
def get_games ( ctx ) : username = ctx . obj [ 'username' ] games = User ( username ) . get_games_owned ( ) for game in sorted ( games . values ( ) , key = itemgetter ( 'title' ) ) : click . echo ( '%s [appid: %s]' % ( game [ 'title' ] , game [ 'appid' ] ) ) click . secho ( 'Total gems owned by `%s`: %d' % ( username ,...
Prints out games owned by a Steam user .
124
10
2,897
def get_booster_stats ( ctx , currency ) : username = ctx . obj [ 'username' ] inventory = User ( username ) . _get_inventory_raw ( ) boosters = { } for item in inventory [ 'rgDescriptions' ] . values ( ) : is_booster = False tags = item [ 'tags' ] for tag in tags : if tag [ 'internal_name' ] == TAG_ITEM_CLASS_BOOSTER ...
Prints out price stats for booster packs available in Steam user inventory .
227
14
2,898
def get_cards_stats ( ctx , currency , skip_owned , appid , foil ) : username = ctx . obj [ 'username' ] cards_by_app = defaultdict ( list ) inventory = User ( username ) . traverse_inventory ( item_filter = TAG_ITEM_CLASS_CARD ) for item in inventory : appid_ = item . app . appid if not appid or appid_ in appid : card...
Prints out price stats for cards available in Steam user inventory .
215
13
2,899
def run_radia_with_merge ( job , rna_bam , tumor_bam , normal_bam , univ_options , radia_options ) : spawn = job . wrapJobFn ( run_radia , rna_bam [ 'rna_genome' ] , tumor_bam , normal_bam , univ_options , radia_options , disk = '100M' , memory = '100M' ) . encapsulate ( ) merge = job . wrapJobFn ( merge_perchrom_vcfs ...
A wrapper for the the entire RADIA sub - graph .
172
12