ensimpl_snps package¶
Submodules¶
ensimpl_snps.app module¶
-
ensimpl_snps.app.
create_app
(settings_override=None)¶ Create a Flask application using the app factory pattern.
Parameters: settings_override (dict) – A dict
which will override the default settings.Returns: The Flask application object. Return type: flask.Flask
-
ensimpl_snps.app.
error_templates
(app)¶ Register 0 or more custom error pages (mutates the app passed in).
Parameters: app (flask.Flask) – The Flask application object.
-
ensimpl_snps.app.
extensions
(app)¶ Register 0 or more extensions (mutates the app passed in).
Parameters: app (flask.Flask) – The Flask application object.
-
ensimpl_snps.app.
middleware
(app)¶ Register 0 or more middleware (mutates app that is passed in).
Parameters: app (flask.Flask) – The Flask application object.
ensimpl_snps.db_config module¶
-
ensimpl_snps.db_config.
get_all_ensimpl_snps_dbs
(top_dir)¶ Configure the list of ensimpl snp db files in directory. This will set values for
ENSIMPL_SNPS_DBS
andENSIMPL_SNPS_DBS_DICT
.Parameters: top_dir (str) – The directory path.
-
ensimpl_snps.db_config.
get_ensimpl_snp_db
(version, species)¶ Get the database based upon the version and species values which should represent the Ensembl reference number and species identifier.
Parameters: Returns: The database file.
Return type: Raises: ValueError
– If unable to find the version and species combination or if version is not a number.Examples
>>> get_ensimpl_snps_db(91, 'Mm') 'ensimpl_snps.91.Mm.db3'
-
ensimpl_snps.db_config.
init
(directory=None)¶ Initialize the configuration of the Ensimpl SNPs databases.
NOTE: This method is referenced from the
__init__.py
in this module.Parameters: directory (str, optional) – A directory that specifies where the ensimpl databases live. If None the environment variable ENSIMPL_SNPS_DIR
will be used.
ensimpl_snps.extensions module¶
ensimpl_snps.utils module¶
Useful generic utilities for the package.
-
class
ensimpl_snps.utils.
ReverseProxied
(app)¶ Bases:
object
Wrap the application in this middleware and configure the front-end server to add these headers, to let you quietly bind this to a URL other than / and to an HTTP scheme that is different than what is used locally.
Taken from: http://flask.pocoo.org/snippets/35/
Example
In Apache:
<Proxy http://server:port> Header add X_FORWADED_PATH "/myprefix" RequestHeader set X_FORWARDED_PATH "/myprefix" </Proxy> ProxyPass /myprefix http://server:port disablereuse=On ProxyPassReverse /myprefix http://server:port
In nginx:
location /myprefix { proxy_pass http://192.168.0.1:5001; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Scheme $scheme; proxy_set_header X-Script-Name /myprefix; }
-
ensimpl_snps.utils.
bins
(start, stop, fmt='gff', one=True)¶ Uses the definition of a “genomic bin” described in Fig 7 of http://genome.cshlp.org/content/12/6/996.abstract.
Parameters: - start (int) – start position
- stop (int) –
- fmt (str, optional) – Either
'gff'
or'bed'
. This specifies 1-based start coords (gff) or 0-based start coords (bed). - one (bool) – If
one=True
(default), then only return the smallest bin that completely contains these coordinates (useful for assigning a single bin). Ifone=False
, then return the set of all bins that overlap these coordinates (useful for looking for features that could intersect)
Returns: The calculated bin.
Return type:
-
ensimpl_snps.utils.
cmp
(value_1, value_2)¶ Compare two values. The return value will be
-1
if value_1 is less than value_2,0
if value_1 is equal to value_2, or1
if value_1 is greater than value_2.Parameters: - value_1 – The first value.
- value_2 – The second value.
Returns: -1
,0
, or1
Return type:
-
ensimpl_snps.utils.
configure_logging
(level=0)¶ Configure the logger with the specified level. Valid level values are:
level logging value 0 logging.WARNING is informational 1 logging.INFO is user debug 2+ logging.DEBUG is developer debug Anything greater than
2
is treated as2
.Parameters: level (int, optional) – The logging level; defaults to 0
.
-
ensimpl_snps.utils.
create_random_string
(size=6, chars='ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789')¶ Generate a random string of length size using the characters specified by chars.
Parameters: Returns: A random generated string.
Return type:
-
ensimpl_snps.utils.
delete_file
(file_name)¶ Delete specified file_name. This will fail silently.
Parameters: file_name (str) – The name of file to delete.
-
ensimpl_snps.utils.
dictify_cursor
(cursor)¶ All rows are converted into a
collections.OrderedDict
where keys are the column names.Parameters: cursor (sqlite3.Cursor) – The database cursor. Returns: A list
ofdicts
where eachdict's
key is a column name.Return type: list
-
ensimpl_snps.utils.
dictify_row
(cursor, row)¶ Turns the given row into a dictionary where the keys are the column names.
Parameters: - cursor (sqlite3.Cursor) – The database cursor.
- row (sqlite3.Row) – The current row.
Returns: A
dict
with keys as column names.Return type:
-
ensimpl_snps.utils.
format_time
(start, end)¶ Format length of time between start and end into a readable string.
Parameters: Returns: A formatted string of hours, minutes, and seconds.
Return type:
-
ensimpl_snps.utils.
get_file_name
(url, directory=None)¶ Get the file name of url. If directory has a value, return the name of the file with directory prepended.
Examples
>>> get_file_name('http://www.google.com/a/b/c/file.html', '/tmp') '/tmp/file.html
Parameters: Returns: The full path of file.
Return type:
-
ensimpl_snps.utils.
get_logger
()¶ Get the logger.
Returns: The logging object. Return type: logging.Logger
-
ensimpl_snps.utils.
is_url
(url)¶ Check if this is a URL or not by just checking the protocol.
Parameters: url (str) – A string in the form of a url. Returns: True
if url has a valid protocol,False
otherwise.Return type: bool
-
ensimpl_snps.utils.
merge_two_dicts
(x, y)¶ Given two dicts, merge them into a new dict as a shallow copy.
Parameters: Returns: The merged dictionary.
Return type:
-
ensimpl_snps.utils.
multikeysort
(items, columns)¶ Sort a
list
ofdicts
by multiple keys in ascending or descending order. To sort in descending order, prepend a ‘-‘ (minus sign) on the column name.Pulled from: https://stackoverflow.com/questions/1143671/python-sorting-list-of-dictionaries-by-multiple-keys
Examples
>>> my_list = [ {'name': 'apple', 'count': 10, 'price': 1.00}, {'name': 'banana', 'count': 5, 'price': 1.00}, {'name': 'orange', 'count': 20, 'price': 2.00}, ]
>>> multikeysort(my_list, ['-name', 'count']) [{'count': 20, 'name': 'orange', 'price': 2.0}, {'count': 5, 'name': 'banana', 'price': 1.0}, {'count': 10, 'name': 'apple', 'price': 1.0}]
>>> multikeysort(my_list, ['-price', 'count']) [{'count': 20, 'name': 'orange', 'price': 2.0}, {'count': 5, 'name': 'banana', 'price': 1.0}, {'count': 10, 'name': 'apple', 'price': 1.0}]
Parameters: Returns: The sorted
list
.Return type:
-
ensimpl_snps.utils.
open_resource
(resource, mode='rb')¶ Open different types of files and return a handle to that resource. Valid types of resources are gzipped and bzipped files along with URLs.
Parameters: Returns: A handle to the opened
resource
.
-
ensimpl_snps.utils.
str2bool
(val)¶ Convert a string into a boolean. Valid strings that return
True
are:true
,1
,t
,y
,yes
Canse-sensitivity does NOT matter.
yes
is the same asYeS
.Parameters: val (str) – A string representing the boolean value of True
.Returns: True
if val represents a booleanTrue
.Return type: bool
Module contents¶
Top-level package for Ensimpl SNPS.