1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/f36d5d615dd4/ changeset: f36d5d615dd4 user: jgoecks date: 2013-01-25 22:10:01 summary: Unify system genome builds, custom builds, build len files, and build two bit files into a single python structure. Add function to get genome builds with or without build length information, and fix bugs so that the full build set (system + custom) is available via the API and when adding datasets to libraries. affected #: 4 files diff -r 4a60baf34969dea43d30b4f18094dfd30c167b25 -r f36d5d615dd4775d71ee778f500bd0c1d3fdf68e lib/galaxy/visualization/genomes.py --- a/lib/galaxy/visualization/genomes.py +++ b/lib/galaxy/visualization/genomes.py @@ -1,7 +1,7 @@ import os, re, sys, glob, logging from bx.seq.twobit import TwoBitFile from galaxy.util.json import from_json_string -from galaxy import model +from galaxy import model, util from galaxy.util.bunch import Bunch log = logging.getLogger( __name__ ) @@ -50,8 +50,9 @@ """ Encapsulates information about a known genome/dbkey. """ - def __init__( self, key, len_file=None, twobit_file=None ): + def __init__( self, key, description, len_file=None, twobit_file=None ): self.key = key + self.description = description self.len_file = len_file self.twobit_file = twobit_file @@ -160,16 +161,19 @@ """ def __init__( self, app ): - # Create list of known genomes from len files. + # Create list of genomes from util.dbnames self.genomes = {} + for key, description in util.dbnames: + self.genomes[ key ] = Genome( key, description ) + + # Add len files to genomes. len_files = glob.glob( os.path.join( app.config.len_file_path, "*.len" ) ) for f in len_files: key = os.path.split( f )[1].split( ".len" )[0] - self.genomes[ key ] = Genome( key, len_file=f ) + if key in self.genomes: + self.genomes[ key ].len_file = f # Add genome data (twobit files) to genomes. - # FIXME: If a galaxy instance does not have ~/tool-data/twobit.loc file, the following error is thrown: - # IOError: [Errno 2] No such file or directory: '~/tool-data/twobit.loc' try: for line in open( os.path.join( app.config.tool_data_path, "twobit.loc" ) ): if line.startswith("#"): continue @@ -179,6 +183,7 @@ if key in self.genomes: self.genomes[ key ].twobit_file = path except IOError, e: + # Thrown if twobit.loc does not exist. log.exception( str( e ) ) def get_build( self, dbkey ): @@ -188,17 +193,30 @@ rval = self.genomes[ dbkey ] return rval - def get_dbkeys_with_chrom_info( self, trans ): - """ Returns all valid dbkeys that have chromosome information. """ + def get_dbkeys( self, trans, chrom_info=False ): + """ Returns all known dbkeys. If chrom_info is True, only dbkeys with + chromosome lengths are returned. """ + dbkeys = [] - # All user keys have a len file. - user_keys = {} + # Add user's custom keys to dbkeys. + user_keys_dict = {} user = trans.get_user() if 'dbkeys' in user.preferences: - user_keys = from_json_string( user.preferences['dbkeys'] ) + user_keys_dict = from_json_string( user.preferences[ 'dbkeys' ] ) + dbkeys.extend( [ (attributes[ 'name' ], key ) for key, attributes in user_keys_dict.items() ] ) - dbkeys = [ (v, k) for k, v in trans.db_builds if ( ( k in self.genomes and self.genomes[ k ].len_file ) or k in user_keys ) ] + # Add app keys to dbkeys. + + # If chrom_info is True, only include keys with len files (which contain chromosome info). + filter_fn = lambda b: True + if chrom_info: + filter_fn = lambda b: b.len_file is not None + + dbkeys.extend( [ ( genome.description, genome.key ) for key, genome in self.genomes.items() if filter_fn( genome ) ] ) + return dbkeys + #return [ (v, k) for k, v in trans.db_builds if ( ( k in self.genomes and self.genomes[ k ].len_file ) or k in user_keys ) ] + def chroms( self, trans, dbkey=None, num=None, chrom=None, low=None ): """ @@ -224,6 +242,7 @@ user_keys = from_json_string( dbkey_user.preferences['dbkeys'] ) if dbkey in user_keys: dbkey_attributes = user_keys[ dbkey ] + dbkey_name = dbkey_attributes[ 'name' ] if 'fasta' in dbkey_attributes: build_fasta = trans.sa_session.query( trans.app.model.HistoryDatasetAssociation ).get( dbkey_attributes[ 'fasta' ] ) len_file = build_fasta.get_converted_dataset( trans, 'len' ).file_name @@ -234,7 +253,7 @@ elif 'len' in dbkey_attributes: len_file = trans.sa_session.query( trans.app.model.HistoryDatasetAssociation ).get( user_keys[ dbkey ][ 'len' ] ).file_name if len_file: - genome = Genome( dbkey, len_file=len_file, twobit_file=twobit_file ) + genome = Genome( dbkey, dbkey_name, len_file=len_file, twobit_file=twobit_file ) # Look in system builds. @@ -243,7 +262,7 @@ if not len_ds: genome = self.genomes[ dbkey ] else: - genome = Genome( dbkey, len_file=len_ds.file_name ) + genome = Genome( dbkey, dbkey_name, len_file=len_ds.file_name ) return genome.to_dict( num=num, chrom=chrom, low=low ) @@ -294,9 +313,9 @@ user_keys = from_json_string( dbkey_user.preferences['dbkeys'] ) dbkey_attributes = user_keys[ dbkey ] fasta_dataset = trans.app.model.HistoryDatasetAssociation.get( dbkey_attributes[ 'fasta' ] ) - error = self._convert_dataset( trans, fasta_dataset, 'twobit' ) - if error: - return error + msg = fasta_dataset.convert_dataset( trans, 'twobit' ) + if msg: + return msg else: twobit_dataset = fasta_dataset.get_converted_dataset( trans, 'twobit' ) twobit_file_name = twobit_dataset.file_name @@ -309,31 +328,3 @@ return { 'dataset_type': 'refseq', 'data': seq_data } except IOError: return None - - ## FIXME: copied from tracks.py (tracks controller) - this should be consolidated when possible. - def _convert_dataset( self, trans, dataset, target_type ): - """ - Converts a dataset to the target_type and returns a message indicating - status of the conversion. None is returned to indicate that dataset - was converted successfully. - """ - - # Get converted dataset; this will start the conversion if necessary. - try: - converted_dataset = dataset.get_converted_dataset( trans, target_type ) - except NoConverterException: - return messages.NO_CONVERTER - except ConverterDependencyException, dep_error: - return { 'kind': messages.ERROR, 'message': dep_error.value } - - # Check dataset state and return any messages. - msg = None - if converted_dataset and converted_dataset.state == model.Dataset.states.ERROR: - job_id = trans.sa_session.query( trans.app.model.JobToOutputDatasetAssociation ) \ - .filter_by( dataset_id=converted_dataset.id ).first().job_id - job = trans.sa_session.query( trans.app.model.Job ).get( job_id ) - msg = { 'kind': messages.ERROR, 'message': job.stderr } - elif not converted_dataset or converted_dataset.state != model.Dataset.states.OK: - msg = messages.PENDING - - return msg \ No newline at end of file diff -r 4a60baf34969dea43d30b4f18094dfd30c167b25 -r f36d5d615dd4775d71ee778f500bd0c1d3fdf68e lib/galaxy/webapps/galaxy/api/genomes.py --- a/lib/galaxy/webapps/galaxy/api/genomes.py +++ b/lib/galaxy/webapps/galaxy/api/genomes.py @@ -20,7 +20,7 @@ GET /api/genomes: returns a list of installed genomes """ - return self.app.genomes.get_dbkeys_with_chrom_info( trans ) + return self.app.genomes.get_dbkeys( trans ) @web.json def show( self, trans, id, num=None, chrom=None, low=None, high=None, **kwd ): diff -r 4a60baf34969dea43d30b4f18094dfd30c167b25 -r f36d5d615dd4775d71ee778f500bd0c1d3fdf68e lib/galaxy/webapps/galaxy/controllers/library_common.py --- a/lib/galaxy/webapps/galaxy/controllers/library_common.py +++ b/lib/galaxy/webapps/galaxy/controllers/library_common.py @@ -944,7 +944,7 @@ # Send list of data formats to the upload form so the "extension" select list can be populated dynamically file_formats = trans.app.datatypes_registry.upload_file_formats - dbkeys = trans.app.genomes.get_dbkeys_with_chrom_info( trans ) + dbkeys = trans.app.genomes.get_dbkeys( trans ) # Send the current history to the form to enable importing datasets from history to library history = trans.get_history() if history is not None: diff -r 4a60baf34969dea43d30b4f18094dfd30c167b25 -r f36d5d615dd4775d71ee778f500bd0c1d3fdf68e lib/galaxy/webapps/galaxy/controllers/visualization.py --- a/lib/galaxy/webapps/galaxy/controllers/visualization.py +++ b/lib/galaxy/webapps/galaxy/controllers/visualization.py @@ -601,7 +601,7 @@ from the visualization title, but can be edited. This field must contain only lowercase letters, numbers, and the '-' character.""" ) - .add_select( "visualization_dbkey", "Visualization DbKey/Build", value=visualization_dbkey, options=trans.app.genomes.get_dbkeys_with_chrom_info( trans ), error=None) + .add_select( "visualization_dbkey", "Visualization DbKey/Build", value=visualization_dbkey, options=trans.app.genomes.get_dbkeys( trans, chrom_info=True ), error=None) .add_text( "visualization_annotation", "Visualization annotation", value=visualization_annotation, error=visualization_annotation_err, help="A description of the visualization; annotation is shown alongside published visualizations."), template="visualization/create.mako" ) @@ -683,7 +683,7 @@ Provide info necessary for creating a new trackster browser. """ return trans.fill_template( "tracks/new_browser.mako", - dbkeys=trans.app.genomes.get_dbkeys_with_chrom_info( trans ), + dbkeys=trans.app.genomes.get_dbkeys( trans, chrom_info=True ), default_dbkey=kwargs.get("default_dbkey", None) ) @web.expose Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.