Downloaders

class NetExplorer.models.downloaders.DownloadHandler

Class that handles downloadable files.

data_from_node (`dict` of `str`

fun): Class attribute, dictionary mapping data type keywords, to the methods that handle them.

Example:

dhandler = DownloadHandler()
the_file = dhandler.download_data(identifiers, database, data)
response = the_file.to_response()

Methods get_*_data returns a list of tuples, each tuple being a line, and each element of the tuple being a column.

_get_contig_data()

Function to return a line with the contig sequence.

Parameters

node (PlanarianContig) – PlanarianContig object.

Returns

List with data for a row in the downloadable
file. Contains:
  1. Contig symbol.

  2. Contig sequence.

  3. Contig database.

  4. Gene symbol (if available, otherwise “NA”).

Return type

list of tuple of str

_get_go_data()

Function to return line with GO for a contig.

Parameters

node (PlanarianContig) – PlanarianContig object.

Returns

List with data for a row in the downloadable
file. Contains:
  1. Contig symbol.

  2. Gene symbol (if available, otherwise “NA”).

  3. GO terms, in the form of (accession`=`domain`=`name), separated by ;.

Return type

list of tuple of str

_get_homology_data()

Function to return line with Homology data for a contig.

Parameters

node (PlanarianContig) – PlanarianContig object.

Returns

List with data for a row in the downloadable
file. Contains:
  1. Contig symbol.

  2. Gene symbol (if available, otherwise “NA”)..

  3. Homolog symbol (if available, otherwise “NA”).

  4. Blast E-Value (if available, otherwise “NA”).

  5. Blast Coverage (if available, otherwise “NA”).

  6. EggNOG HMMER E-Value (if available, otherwise “NA”).

  7. PFAM meta-alignment score (if available, otherwise “NA”).

Return type

list of tuple of str

_get_interactions_data()

Function to return several line with interactions for a contig.

Parameters

node (PlanarianContig) – PlanarianContig object.

Returns

List with data for a row in the downloadable
file. Contains:
  1. Contig symbol.

  2. Gene symbol (if available, otherwise “NA”).

  3. Interactor contig symbol.

  4. Interactor gene symbol (if available, otherwise “NA”).

  5. Interaction score (if available, otherwise “NA”)

Return type

list of tuple of str

_get_orf_data()

Function to return line with contig Open Reading Frame (ORF) and other data.

Parameters

node (PlanarianContig) – PlanarianContig object.

Returns

List with data for a row in the downloadable
file. Contains:
  1. Contig symbol.

  2. Contig ORF sequence.

  3. Contig database.

  4. Gene symbol (if available, otherwise “NA”).

Return type

list of tuple of str

_get_pfam_data()

Function to return line with PFAM domain data for a contig.

Parameters

node (PlanarianContig) – PlanarianContig object.

Returns

List with data for a row in the downloadable
file. Contains:
  1. Contig symbol.

  2. Gene symbol (if available, otherwise “NA”).

  3. PFAM domains, in the form of (accession:start-end), separated by ;.

Return type

list of tuple of str

data_from_node = {'contig': <function DownloadHandler._get_contig_data>, 'go': <function DownloadHandler._get_go_data>, 'homology': <function DownloadHandler._get_homology_data>, 'interactions': <function DownloadHandler._get_interactions_data>, 'orf': <function DownloadHandler._get_orf_data>, 'pfam': <function DownloadHandler._get_pfam_data>}
download_data(identifiers, database, data)

Creates file object with the specified data for the specified identifiers.

Parameters
  • identifiers (list of str) – List of gene/transcript identifiers.

  • database (str) – Database name of desired results to download.

  • data (str) – Desired data to download. Can be [‘contig’, ‘orf’, ‘homology’, ‘pfam’, ‘go’, ‘interactions’]

Returns

ServedFile object with the file ready to download.

Return type

ServedFile

get_filename(data)

Returns filename string.

Parameters

data (str) – Desired data to download. Can be [‘contig’, ‘orf’, ‘homology’, ‘pfam’, ‘go’, ‘interactions’]

Returns

String with filename according to the data to download.

Return type

str

get_header(data)

Returns header string.

Parameters

data (str) – Desired data to download. Can be [‘contig’, ‘orf’, ‘homology’, ‘pfam’, ‘go’, ‘interactions’]

Returns

String with first line (header) of the file.

Return type

str

class NetExplorer.models.downloaders.ServedFile(oname, fformat='csv', header=None)

Class of served files for download.

oname

String with output filename.

Type

str

fformat

String with file format, can be ‘csv’ or ‘fasta’.

Type

str

header

Bool describing if file should have a header.

Type

bool

filename

NamedTemporaryFile object.

Type

NamedTemporaryFile

elements

List of tuples. Each tuple contains the data for each line.

Type

list of tuple

written

Bool describing if the file has data on it or not.

Type

bool

Parameters
  • oname (str) – String with output filename.

  • fformat (str, optional) – String with file format, can be ‘csv’ or ‘fasta’. Defaults to ‘csv’.

  • header (str, optional) – Header string to write on the first line of the file. Defaults to None.

add_elements(elem)

Adds a register to the list of elements.

Parameters

elem (list of tuple) – List of tuples. Each tuple corresponds to a line.

to_response(what=None)

Creates a response object to be served to the user for download.

Parameters

what (None) – Nothing.

Returns

HttpResponse object with the file to be returned

in a request.

Return type

HttpResponse

write(what=None)

Writes to temp file.

Parameters

what (None) – Nothing.