Mercurial > repos > iuc > data_manager_snpeff
changeset 5:3d9dd4b9fb09 draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_snpeff commit 5c6d595ecbf2e4e39c25662a165c9e475e01ecd1-dirty
author | iuc |
---|---|
date | Tue, 18 Apr 2017 09:40:03 -0400 |
parents | 847b0f43c0e5 |
children | 2107b4f40945 |
files | data_manager/data_manager_snpEff_databases.py data_manager/data_manager_snpEff_databases.xml data_manager/data_manager_snpEff_download.py data_manager/data_manager_snpEff_download.xml data_manager_conf.xml tool_dependencies.xml |
diffstat | 6 files changed, 68 insertions(+), 164 deletions(-) [+] |
line wrap: on
line diff
--- a/data_manager/data_manager_snpEff_databases.py Tue Apr 04 18:14:37 2017 -0400 +++ b/data_manager/data_manager_snpEff_databases.py Tue Apr 18 09:40:03 2017 -0400 @@ -6,33 +6,20 @@ import sys -def stop_err(msg): - sys.stderr.write(msg) - sys.exit(1) - - -def fetch_databases(data_manager_dict, target_directory, jar_path): - (snpEff_dir, snpEff_jar) = os.path.split(jar_path) +def fetch_databases(data_manager_dict, target_directory): if not os.path.exists(target_directory): os.makedirs(target_directory) databases_path = os.path.join( target_directory, 'databases.out' ) databases_output = open(databases_path, 'w') - args = [ 'java', '-jar' ] - args.append( snpEff_jar ) - args.append( 'databases' ) - # tmp_stderr = tempfile.NamedTemporaryFile( prefix = "tmp-data-manager-snpEff-stderr" ) - # databases_output = open(databases_path) - # proc = subprocess.Popen( args=args, shell=False, cwd=snpEff_dir, stdout=databases_output.fileno(), stderr=tmp_stderr.fileno() ) - proc = subprocess.Popen( args=args, shell=False, cwd=snpEff_dir, stdout=databases_output.fileno() ) - return_code = proc.wait() + args = ['snpEff', 'databases'] + return_code = subprocess.call(args=args, shell=False, stdout=databases_output.fileno()) if return_code: sys.exit( return_code ) databases_output.close() data_manager_dict['data_tables'] = data_manager_dict.get( 'data_tables', {} ) data_manager_dict['data_tables']['snpeff4_databases'] = data_manager_dict['data_tables'].get( 'snpeff4_databases', [] ) data_table_entries = [] - try: - fh = open(databases_path, 'r') + with open(databases_path, 'r') as fh: for i, line in enumerate(fh): fields = line.split('\t') if len(fields) >= 2: @@ -45,17 +32,11 @@ description = fields[1].strip() + ' : ' + genome_version data_table_entries.append(dict(value=genome_version, name=description)) data_manager_dict['data_tables']['snpeff4_databases'] = data_table_entries - except Exception as e: - stop_err( 'Error parsing %s %s\n' % (databases_path, str( e )) ) - else: - fh.close() return data_manager_dict def main(): - # Parse Command Line parser = optparse.OptionParser() - parser.add_option( '-j', '--jar_path', dest='jar_path', action='store', type="string", default=None, help='snpEff.jar path' ) (options, args) = parser.parse_args() filename = args[0] @@ -66,7 +47,7 @@ data_manager_dict = {} # Create Defuse Reference Data - data_manager_dict = fetch_databases( data_manager_dict, target_directory, options.jar_path) + data_manager_dict = fetch_databases( data_manager_dict, target_directory) # save info to json file open( filename, 'wb' ).write( json.dumps( data_manager_dict ) )
--- a/data_manager/data_manager_snpEff_databases.xml Tue Apr 04 18:14:37 2017 -0400 +++ b/data_manager/data_manager_snpEff_databases.xml Tue Apr 18 09:40:03 2017 -0400 @@ -1,44 +1,33 @@ -<tool id="data_manager_snpeff_databases" name="SnpEff Databases" version="4.1.0" tool_type="manage_data"> - <description>Read the list of available snpEff databases</description> - <requirements> - <requirement type="package" version="4.1">snpEff</requirement> - </requirements> - <stdio> - <exit_code range=":-1" level="fatal" description="Error: Cannot open file" /> - <exit_code range="1:" level="fatal" description="Error" /> - </stdio> - <command interpreter="python"> - data_manager_snpEff_databases.py --jar_path "\$SNPEFF_JAR_PATH/snpEff.jar" "$out_file" - </command> - <inputs> - </inputs> - <outputs> - <data name="out_file" format="data_manager_json"/> - </outputs> - <tests> - <test> - <output name="out_file"> - <assert_contents> - <!-- Check that a genome was added --> - <has_text text="GRCh38.76" /> - </assert_contents> - </output> - </test> - </tests> - <help> +<tool id="data_manager_snpeff_databases" name="SnpEff Databases" version="4.3k" tool_type="manage_data"> + <description>Read the list of available SnpEff databases</description> + <requirements> + <requirement type="package" version="4.3k">snpeff</requirement> + </requirements> + <command detect_errors="exit_code"><![CDATA[ +python '$__tool_directory__/data_manager_snpEff_databases.py' '$out_file' + ]]></command> + <inputs> + </inputs> + <outputs> + <data name="out_file" format="data_manager_json"/> + </outputs> + <tests> + <test> + <output name="out_file"> + <assert_contents> + <!-- Check that a genome was added --> + <has_text text="GRCh38.76" /> + </assert_contents> + </output> + </test> + </tests> + <help><![CDATA[ +This tool updates the list of SnpEff databases for the SnpEff Download data manager. +It should only need to be run once for a SnpEff version, since it populates the SnpEff Download data manager from the SnpEff config file. -This tool updatess the list of SnpEff databases for the SnpEff Download data manager. -It should only need to be run once for a snpEff version, -since it populates the SnpEff Download data manager from the snpEff config file. - -For information about snpEff: http://snpEff.sourceforge.net - -Please cite: -"A program for annotating and predicting the effects of single nucleotide polymorphisms, SnpEff: SNPs in the genome of Drosophila melanogaster strain w1118; iso-2; iso-3.", Cingolani P, Platts A, Wang le L, Coon M, Nguyen T, Wang L, Land SJ, Lu X, Ruden DM. Fly (Austin). 2012 Apr-Jun;6(2):80-92. PMID: 22728672 [PubMed - in process] - - </help> - <citations> +For information about SnpEff: http://snpeff.sourceforge.net + ]]></help> + <citations> <citation type="doi">10.4161/fly.19695</citation> - </citations> + </citations> </tool> -
--- a/data_manager/data_manager_snpEff_download.py Tue Apr 04 18:14:37 2017 -0400 +++ b/data_manager/data_manager_snpEff_download.py Tue Apr 18 09:40:03 2017 -0400 @@ -1,5 +1,4 @@ #!/usr/bin/env python -import gzip import json import optparse import os @@ -13,19 +12,12 @@ sys.exit(1) -def fetch_databases(jar_path, genome_list=None): +def fetch_databases(genome_list=None): snpDBs = dict() - (snpEff_dir, snpEff_jar) = os.path.split(jar_path) databases_path = 'databases.out' databases_output = open(databases_path, 'w') - args = [ 'java', '-jar' ] - args.append( snpEff_jar ) - args.append( 'databases' ) - # tmp_stderr = tempfile.NamedTemporaryFile( prefix = "tmp-data-manager-snpEff-stderr" ) - # databases_output = open(databases_path) - # proc = subprocess.Popen( args=args, shell=False, cwd=snpEff_dir, stdout=databases_output.fileno(), stderr=tmp_stderr.fileno() ) - proc = subprocess.Popen( args=args, shell=False, cwd=snpEff_dir, stdout=databases_output.fileno() ) - return_code = proc.wait() + args = ['snpEff', 'databases'] + return_code = subprocess.call(args=args, shell=False, stdout=databases_output.fileno()) if return_code: sys.exit( return_code ) databases_output.close() @@ -48,28 +40,24 @@ return snpDBs -def getOrganismNames(jar_path, genomes, organisms): +def getOrganismNames(genomes, organisms): genome_list = genomes.split(',') organism_list = organisms.split(',') if organisms else [] if len(genome_list) != len(organism_list): descriptions = [] - snpDBdict = fetch_databases(jar_path, genome_list=genome_list) + snpDBdict = fetch_databases(genome_list=genome_list) for genome in snpDBdict: descriptions.append(snpDBdict[genome] if genome in snpDBdict else genome) return ','.join(descriptions) return organisms -def getSnpeffVersion(jar_path): +def getSnpeffVersion(): snpeff_version = 'SnpEff ?.?' - (snpEff_dir, snpEff_jar) = os.path.split(jar_path) stderr_path = 'snpeff.err' stderr_fh = open(stderr_path, 'w') - args = [ 'java', '-jar' ] - args.append( snpEff_jar ) - args.append( '-h' ) - proc = subprocess.Popen( args=args, shell=False, cwd=snpEff_dir, stderr=stderr_fh.fileno() ) - return_code = proc.wait() + args = ['snpEff', '-h'] + return_code = subprocess.call(args=args, shell=False, stderr=stderr_fh.fileno()) if return_code != 255: sys.exit( return_code ) stderr_fh.close() @@ -83,27 +71,6 @@ return snpeff_version -# Starting with SnpEff 4.1 the .bin files contain the SnpEff version: -# Example - the first 3 line of GRCh37.75/snpEffectPredictor.bin (uncompressed): -# -# SnpEff 4.1 -# CHROMOSOME 2 1 0 179197 GL000219.1 false -# CHROMOSOME 3 1 0 81347269 HSCHR17_1 false -def getSnpeffVersionFromFile(path): - snpeff_version = None - try: - fh = gzip.open(path, 'rb') - buf = fh.read(100) - lines = buf.splitlines() - m = re.match('^(SnpEff)\s+(\d+\.\d+).*$', lines[0].strip()) - if m: - snpeff_version = m.groups()[0] + m.groups()[1] - fh.close() - except Exception as e: - stop_err( 'Error parsing SnpEff version from: %s %s\n' % (path, str( e )) ) - return snpeff_version - - # Download human database 'hg19' # java -jar snpEff.jar download -v hg19 # @@ -112,36 +79,24 @@ # snpEffectPredictor.bin # regulation_HeLa-S3.bin # regulation_pattern = 'regulation_(.+).bin' -def download_database(data_manager_dict, target_directory, jar_path, config, genome_version, organism): +def download_database(data_manager_dict, target_directory, genome_version, organism): # get data_dir from config # --- # Databases are stored here # E.g.: Information for 'hg19' is stored in data_dir/hg19/ # # Note: Since version 2.1 you can use tilde ('~') as first character to refer to your home directory - # --- - # data_dir = ~/snpEff/data/ data_dir = target_directory - (snpEff_dir, snpEff_jar) = os.path.split(jar_path) - args = [ 'java', '-jar' ] - args.append( jar_path ) - args.append( 'download' ) - args.append( '-c' ) - args.append( config ) - args.append( '-dataDir' ) - args.append( data_dir ) - args.append( '-v' ) - args.append( genome_version ) - proc = subprocess.Popen( args=args, shell=False, cwd=snpEff_dir ) - return_code = proc.wait() + args = ['snpEff', 'download', '-dataDir', data_dir, '-v', genome_version] + return_code = subprocess.call(args=args, shell=False) if return_code: sys.exit( return_code ) # search data_dir/genome_version for files regulation_pattern = 'regulation_(.+).bin' - # annotation files that are included in snpEff by a flag - annotations_dict = {'nextProt.bin': '-nextprot', 'motif.bin': '-motif'} + # annotation files that are included in SnpEff by a flag + annotations_dict = {'nextProt.bin': '-nextprot', 'motif.bin': '-motif', 'interactions.bin': '-interaction'} genome_path = os.path.join(data_dir, genome_version) - snpeff_version = getSnpeffVersion(jar_path) + snpeff_version = getSnpeffVersion() key = snpeff_version + '_' + genome_version if os.path.isdir(genome_path): for root, dirs, files in os.walk(genome_path): @@ -149,7 +104,6 @@ if fname.startswith('snpEffectPredictor'): # if snpEffectPredictor.bin download succeeded name = genome_version + (' : ' + organism if organism else '') - # version = getSnpeffVersionFromFile(os.path.join(root,fname)) data_table_entry = dict(key=key, version=snpeff_version, value=genome_version, name=name, path=data_dir) _add_data_table_entry( data_manager_dict, 'snpeffv_genomedb', data_table_entry ) else: @@ -174,10 +128,7 @@ def main(): - # Parse Command Line parser = optparse.OptionParser() - parser.add_option( '-j', '--jar_path', dest='jar_path', action='store', type="string", default=None, help='snpEff.jar path' ) - parser.add_option( '-c', '--config', dest='config', action='store', type="string", default=None, help='snpEff.config path' ) parser.add_option( '-g', '--genome_version', dest='genome_version', action='store', type="string", default=None, help='genome_version' ) parser.add_option( '-o', '--organism', dest='organism', action='store', type="string", default=None, help='organism name' ) (options, args) = parser.parse_args() @@ -190,8 +141,8 @@ data_manager_dict = {} # Create SnpEff Reference Data - for genome_version, organism in zip(options.genome_version.split(','), getOrganismNames(options.jar_path, options.genome_version, options.organism).split(',')): - download_database( data_manager_dict, target_directory, options.jar_path, options.config, genome_version, organism ) + for genome_version, organism in zip(options.genome_version.split(','), getOrganismNames(options.genome_version, options.organism).split(',')): + download_database( data_manager_dict, target_directory, genome_version, organism ) # save info to json file open( filename, 'wb' ).write( json.dumps( data_manager_dict ) )
--- a/data_manager/data_manager_snpEff_download.xml Tue Apr 04 18:14:37 2017 -0400 +++ b/data_manager/data_manager_snpEff_download.xml Tue Apr 18 09:40:03 2017 -0400 @@ -1,25 +1,21 @@ -<tool id="data_manager_snpeff_download" name="SnpEff Download" version="4.1.0" tool_type="manage_data"> +<tool id="data_manager_snpeff_download" name="SnpEff Download" version="4.3k" tool_type="manage_data"> <description>Download a new database</description> <requirements> - <requirement type="package" version="4.1">snpEff</requirement> + <requirement type="package" version="4.3k">snpeff</requirement> </requirements> - <stdio> - <exit_code range=":-1" level="fatal" description="Error: Cannot open file" /> - <exit_code range="1:" level="fatal" description="Error" /> - </stdio> - <command interpreter="python"> - data_manager_snpEff_download.py --jar_path "\$SNPEFF_JAR_PATH/snpEff.jar" --config "\$SNPEFF_JAR_PATH/snpEff.config" - --genome_version "$genome_version" "$out_file" - </command> + <command detect_errors="exit_code"><![CDATA[ +python '$__tool_directory__/data_manager_snpEff_download.py' +--genome_version '$genome_version' +'$out_file' + ]]></command> <inputs> - <param name="genome_version" type="text" value="" label="Snpff Genome Version Name (e.g. GRCh38.76)"> - <help>https://snpeff-data.galaxyproject.org/databases/</help> + <param name="genome_version" type="text" value="" label="Snpff Genome Version Name (e.g. GRCh38.76)" help="https://snpeff-data.galaxyproject.org/databases/"> <validator type="regex" message="A genome version name is required">\S+</validator> </param> </inputs> <outputs> - <data name="out_file" format="data_manager_json" label="${tool.name}"/> + <data name="out_file" format="data_manager_json" label="${tool.name}"/> </outputs> <tests> <test> @@ -34,23 +30,16 @@ </output> </test> </tests> - <help> - -This tool downloads a SnpEff database and populates data tables: snpeffv_genomedb, snpeffv_regulationdb, and snpeffv_annotations. + <help><![CDATA[ +This tool downloads a SnpEff database and populates the data tables: snpeffv_genomedb, snpeffv_regulationdb, and snpeffv_annotations. To see the list of available SnpEff genomes run the "SnpEff Databases" data manager which records the available genome databases in data table: snpeff4_databases The SnpEff genome databases are at: http://sourceforge.net/projects/snpeff/files/databases/ - -For details about this tool, please go to http://snpEff.sourceforge.net - -Please cite: -"A program for annotating and predicting the effects of single nucleotide polymorphisms, SnpEff: SNPs in the genome of Drosophila melanogaster strain w1118; iso-2; iso-3.", Cingolani P, Platts A, Wang le L, Coon M, Nguyen T, Wang L, Land SJ, Lu X, Ruden DM. Fly (Austin). 2012 Apr-Jun;6(2):80-92. PMID: 22728672 [PubMed - in process] - - </help> - <citations> +For details about this tool, please go to http://snpeff.sourceforge.net + ]]></help> + <citations> <citation type="doi">10.4161/fly.19695</citation> - </citations> + </citations> </tool> -
--- a/data_manager_conf.xml Tue Apr 04 18:14:37 2017 -0400 +++ b/data_manager_conf.xml Tue Apr 18 09:40:03 2017 -0400 @@ -19,9 +19,9 @@ <column name="name" /> <!-- columns that are going to be specified by the Data Manager Tool --> <column name="path" output_ref="out_file" > <move type="directory" relativize_symlinks="True"> - <target base="${GALAXY_DATA_MANAGER_DATA_PATH}">snpEff/v4_1/data</target> + <target base="${GALAXY_DATA_MANAGER_DATA_PATH}">snpEff/v4_3/data</target> </move> - <value_translation>${GALAXY_DATA_MANAGER_DATA_PATH}/snpEff/v4_1/data</value_translation> + <value_translation>${GALAXY_DATA_MANAGER_DATA_PATH}/snpEff/v4_3/data</value_translation> <value_translation type="function">abspath</value_translation> </column> </output>
--- a/tool_dependencies.xml Tue Apr 04 18:14:37 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -<?xml version="1.0"?> -<tool_dependency> - <package name="snpEff" version="4.1"> - <repository changeset_revision="374c7f8421fb" name="package_snpeff_4_1" owner="iuc" toolshed="https://toolshed.g2.bx.psu.edu" /> - </package> -</tool_dependency>