mgkit.snps.mapper module

Mapping functions for SNPs - Should be move into an ‘iterator’ package to be shared with other modules?

mgkit.snps.mapper.map_gene_id(gene_id, gene_map=None)[source]

Returns an iterator for all the values of a dictionary. if gene_id is not found in the gene_map, an empty iterator is returned.

Parameters
  • gene_id (immutable) – gene_id or any other dictionary key.

  • gene_map (dict) – a dictionary in the form key->[v1, v2, .. vN]

Returns

iterator (empty if gene_id is not in gene_map) with the values

Return type

generator

mgkit.snps.mapper.map_taxon_id_to_ancestor(taxon_id, anc_ids=None, func=None)[source]

Given a taxon_id and a list of ancestors IDs, returns an iterator with the IDs that are ancestors of taxon_id.

Parameters
  • taxon_id (int) – taxon ID to be mapped

  • anc_ids (iterable) – taxon IDs to check for ancestry

  • func – function used to check for ancestry - partial function for mgkit.taxon.is_ancestor() that accepts taxon_id and anc_id

Returns

iterator with the values or empty

Return type

generator

Note

check mgkit.filter.taxon.filter_taxon_by_id_list() for examples on using func

mgkit.snps.mapper.map_taxon_id_to_rank(taxon_id, rank=None, taxonomy=None, include_higher=False)[source]

Given a taxon_id, returns an iterator with only the element that correspond to the requested rank. If the taxon returned by mgkit.taxon.Taxonomy.get_ranked_taxon has a different rank than requested, the iterator will be empty if include_higher is False and the returned taxon ID if True.

Parameters
  • taxon_id (int) – taxon ID to be mapped

  • rank (str) – taxon rank used (mgkit.taxon.TAXON_RANKS)

  • include_higher (bool) – determines if a rank higher than the one requested is to be returned

Returns

iterator with the values or empty

Return type

generator