Utils

class modules.gemtractor.utils.Utils[source]

Bases: object

some utils that may make life easier

static _Utils__cleanup(root_dir, max_age)

get rid of old stuff

will remove cached and unused file in a certain directory

Parameters:
  • root_dir (str) – the directory to traverse
  • max_age (int) – the max age of files that will survive
static _Utils__collect_stats(root_dir)

collect some stats about the files below root_dir

Parameters:root_dir (str) – the root directory
Returns:tupel of number of files and the sum of their sizes
Return type:typel of ints
_Utils__logger = <Logger modules.gemtractor.utils (INFO)>
static _create_dir(d)[source]

create some directory (recursively) the pythonic way

Parameters:d (str) – the directories to create
static _get_bigg_model_base_path(model_id)[source]

get the path at which we would store a BiGG model

Parameters:model_id (str) – the model’s id
Returns:the path to the cached BiGG model
Return type:str
static _get_biomodel_base_path(model_id)[source]

get the path at which we would store a biomodels model

Parameters:model_id (str) – the model’s id
Returns:the path to the cached model from biomodels
Return type:str
static add_model_note(model, filter_species, filter_reactions, filter_enzymes, filter_enzyme_complexes, remove_reaction_enzymes_removed, remove_ghost_species, discard_fake_enzymes, remove_reaction_missing_species, removing_enzyme_removes_complex)[source]

‘ annotate the model to indicate that is has been generated using the GEMtractor

adds a note to the model note..

Parameters:
  • model (libsbml:Model) – the SBML model
  • filter_species (list of str) – species identifiers to get rid of
  • filter_reactions (list of str) – reaction identifiers to get rid of
  • filter_enzymes (list of str) – enzyme identifiers to get rid of
  • filter_enzyme_complexes (list of str) – enzyme-complex identifiers to get rid of, every list-item should be of format: ‘A + B + gene42’
  • remove_reaction_enzymes_removed (bool) – should we remove a reaction if all it’s genes were removed?
  • remove_ghost_species (bool) – should species be removed, that do not participate in any reaction anymore - even though they might be required in other entities?
  • discard_fake_enzymes (bool) – should fake enzymes (implicitly assumes enzymes, if no enzymes are annotated to a reaction) be removed?
  • remove_reaction_missing_species (bool) – remove a reaction if one of the participating genes was removed?
  • removing_enzyme_removes_complex (bool) – if an enzyme is removed, should also all enzyme complexes be removed in which it participates?
static cleanup()[source]

get rid of old stuff

will remove cached and unused file for the whole instance

static collect_stats(response_obj)[source]

collect some health stats about this instance

will check cached and uploaded files and their sizes

Parameters:response_obj (dict) – the response object to attach the information to
static create_generated_file_web(sessionid)[source]

get a file to generate something for the user

Parameters:sessionid (str) – the users’ session id
Returns:path to a file that is safe for the user
Return type:str
static del_session_key(request, context, key)[source]

delete a certain session key as requested by the user

Parameters:
  • request (django:HttpRequest) – django’s HTTP request object
  • context (dict) – the context object
  • key (str) – the key to delete
static get_bigg_model(model_id, force=False)[source]

Retrieve a specific model from BiGG

uses _get_bigg_model_base_path() to determine the path to the model

Parameters:
  • model_id (str) – the model’s id
  • force (bool) – should the cache be renewed even if it’s not too old?
Returns:

the path to the model

Return type:

str

Raises:
  • HTTPError – if there was a problem contacting BiGG
  • URLError – if there was a problem contacting BiGG
static get_bigg_models(force=False)[source]

Retrieve the list of models from BiGG

Parameters:

force (bool) – should the cache be renewed even if it’s not too old?

Returns:

the list of models at BiGG

Return type:

json object

Raises:
  • HTTPError – if there was a problem contacting BiGG
  • URLError – if there was a problem contacting BiGG
  • JSONDecodeError – if the BiGG answer is no proper JSON
static get_biomodel(model_id, force=False)[source]

Retrieve a specific model from biomodels

uses _get_biomodel_base_path() to determine the path to the model

Parameters:
  • model_id (str) – the model’s id
  • force (bool) – should the cache be renewed even if it’s not too old?
Returns:

the path to the model

Return type:

str

Raises:
  • HTTPError – if there was a problem contacting biomodels
  • URLError – if there was a problem contacting biomodels
static get_biomodels(force=False)[source]

Retrieve the list of models from Biomodels

Parameters:

force (bool) – should the cache be renewed even if it’s not too old?

Returns:

the list of models for our search at Biomodels

Return type:

json object

Raises:
  • HTTPError – if there was a problem contacting Biomodels
  • URLError – if there was a problem contacting Biomodels
  • JSONDecodeError – if the Biomodels answer is no proper JSON
static get_model_path(model_type, model_id, sessionid)[source]

get the path to a model

depending on how the model was obtained (downloaded from BiGG/biomodels or uploaded) the path may differ

Parameters:
  • model_type (str) – the obtain type (see constants.Constants)
  • model_id (str) – the model’s id
  • sessionid (str) – the user’s session id - only relevant if the model was uploaded
Returns:

the path to the model

Return type:

str

static get_upload_path(sessionid)[source]

get a file to upload something for the user

Parameters:sessionid (str) – the users’ session id
Returns:path to a file that is safe for the user
Return type:str
static human_readable_bytes(byt)[source]

convert a size in bytes to a human readable string

Parameters:byt (int) – the byte size
Returns:the human readable size (such as 1 MB or 2.7 TB)
Return type:str
static rm_cached_bigg_model(model_id)[source]

remove a cached BiGG model

uses _get_bigg_model_base_path() to determine the path to the model

Parameters:model_id (str) – the model’s id
static rm_cached_biomodel(model_id)[source]

remove a cached model from biomodels

uses _get_biomodel_base_path() to determine the path to the model

Parameters:model_id (str) – the model’s id
static serve_file(file_path, file_name, file_type)[source]

deliver a file to the user

Parameters:
  • file_path (str) – the path to the file to deliver
  • file_name (str) – the name to suggest to the client (browser)
  • file_type (str) – the mime type to suggest to the client (browser)