API Documentation

Here follow the classes and functions that are utilized internally by Kiwi.

classes

class kiwi.classes.Gene(name)

An object of class Gene represents a gene to which statistics can be assigned.

addGeneStats(p, FC)

It adds p-value and fold-change statistics as gene attributes.

Parameters:
  • p (float) – the gene p-value.
  • FC (float) – the gene fold-change.
class kiwi.classes.Genome

An object of class Genome is a list of Gene objects.

addGene(gene)

It adds a Gene object to the list of gene in the Genome.

Parameters:gene (a Gene object.) – a gene.
getGene(name)

Given a gene name, it returns the corresponding Gene object. If no object is found with that name, it returns an empty list.

Parameters:name (string) – a gene name.
Returns:a Gene object that matches the name or an empty list if no match was found.
size()

It returns the number of Gene objects.

class kiwi.classes.Metabolite(name)

An object of class Metabolite represents a metabolite to which gene-set statistics can be assigned and genes be associated.

addGene(gene)

It adds a Gene object to the gene list associated with the metabolite.

Parameters:gene (a Gene object.) – a gene associated with the metabolite.
addGeneSetStats(stats, header, adj)

It adds gene-set statistics as attributes. The statistics values are contained in stats and the mapping to the correct attribute is enforced by the header that matches stats. It supports the use of adjusted statistics.

Parameters:
  • stats (a numerical array) – a list of gene-set statistics.
  • header (a string array) – a list of names that correspond to the different statistics in stats.
  • adj (string) – either empty or “adj” if adjusted statistics should be used.
class kiwi.classes.Metabolome

An object of class Metabolome contains a list of Metabolite objects.

addMetabolite(metabolite)

It adds a Metabolite object to the Metabolome.

Parameters:metabolite (a Metabolite object) – the metabolite to be added.
getMetabolite(name)

Given a metabolite name, it returns the corresponding Metabolite object. If no object is found with that name, it returns an empty list.

Parameters:name (string) – a metabolite name.
Returns:a Metabolite object that matches the name or an empty list if no match was found.
removeHighDegreeMetabolites(MN, degreecutoff)

It removes all Metabolite objects if the degree as nodes in the input metabolic network Graph is higher than degreecutoff.

Parameters:
  • MN (a networkx Graph object.) – a graph that contains Metabolite objects as nodes.
  • degreecutoff (float) – a minimum threshold for the degree of a metabolite in the metabolic graph.
removeMetabolite(metabolite)

It removes a Metabolite object to the Metabolome.

Parameters:metabolite (a Metabolite object) – the metabolite to be removed.
removeMetabolitesNotInMetNet(MN)

It removes all Metabolite objects that are not nodes in the input metabolic network Graph.

Parameters:MN (a networkx Graph object.) – a graph that contains Metabolite objects as nodes.
removeNotSignificantMetabolites(pcutoff, nonPiano)

It removes all Metabolite objects whose pNonDirectional attribute is above pcutoff.

Parameters:
  • pcutoff (float) – a minimum threshold for the pNonDirectional or pValue.
  • nonPiano (logical) – a logical to determine whether to use pNonDirectional or pValue.
size()

It returns the number of Metabolite objects.

functions

kiwi.functions.convertGeneNames(geneList, fromtype, totype, species, keepFirst=False)

It uses information for gene and species annotations from mygene.info to convert a list of gene names in a different annotation. I{e.g. fromtype=“‘ensembl.gene’, totype = “‘symbol’”, species=”human” converts the gene IDs from ENSEMBL ID to Official Gene Symbol for human genes.} The returned converted list of gene names is ordered according to the input list. NOTE: if no hit is found, the original gene name is returned; if multiple hits are found, only the first hit is returned.

Parameters:
  • geneList (list) – a list of gene names.
  • fromtype (string) – the annotation source for the genes in each Metabolite object in the graph. It should match the name in mygene.info.
  • totype (string) – the annotation source preferred to be shown in the heatmap for the genes in each Metabolite object in the graph. It should match the name in mygene.info.
  • species (string) – the species the gene names refer to. It should match the name in mygene.info.
Returns:

an ordered list of gene names that match the input gene list.

kiwi.functions.drawHeatmap(PG, hmType, filename, pzero, convertGeneNamesFromType='', convertGeneNamesToType='', convertGeneNamesSpecies='')

Given an object of class Graph where nodes are of class Metabolite, it constructs and display a matrix where rows are the metabolites and the columns are the overall set of genes associated with the metabolites. Each entry indicates if the gene is associated with the metabolites. The entry can be binary if hmType = “Binary”, otherwise it gets the -log10 value for the attribute p of the gene. In the latter case, the minimum value the logarithm can get is set by pzero. The matrix is displayed as a heatmap, where rows and columns are hierarchically clustered. Gene labels can be interconverted using different annotation sources.

Parameters:
  • PG (an Graph() object from the networkx module) – a graph that contains Metabolite objects as nodes.
  • hmType (string) – either “Binary” or “Numeric”, according to whether the heatmap entries are binary or -log10(p) of each gene.
  • filename (string) – the name of the output figure.
  • pzero (float) – the minimum value the logarithm can accept.
  • convertGeneNamesFromType (string) – the annotation source for the genes in each Metabolite object in the graph. It should match the name in mygene.info. Default: “”.
  • convertGeneNamesToType (string) – the annotation source preferred to be shown in the heatmap for the genes in each Metabolite object in the graph. It should match the name in mygene.info. Default: “”.
  • convertGeneNamesSpecies (string) – the species the gene names refer to. It should match the name in mygene.info. Default: “”.
kiwi.functions.getEdgeProperty(G, eprop)

Given an object of class Graph, it returns an ordered array of edge property values.

Parameters:
  • G (an Graph() object from the networkx module) – a graph that contains at least one edge.
  • eprop (string) – a property of the edges in the graph.
Returns:

a list of ordered edge property values.

kiwi.functions.updateLabel(metabolite)

Given an object of class Metabolite, it updates the attribute label. If updated for the first time, it adds the suffix “*2”; otherwise, it adds +1 to the numeric part of the suffix.

Parameters:metabolite (a Metabolite() object) – a metabolite.
_images/kiwi_logo.png