Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self):
from bioservices import EUtils
self.eutils = EUtils()
def get_lineage_from_taxons(self, taxons):
from bioservices import EUtils
e = EUtils()
res = e.EFetch("taxonomy", taxons)
self.xml = easyXML(res)
# There is one lineage per taxon so we can use the findAll
lineage = [x.text for x in self.xml.findAll("lineage")]
# We now want to get the scientific name for each taxon. Note,ever
# that there are several taxon children-tags within a taxon each hving
# a scientific name, so we first use getchildren() to make sure toloop
# over a the children only
scnames = []
for taxon in self.xml.root.getchildren():
name = taxon.findall("ScientificName")[0].text
scnames.append(name)
return lineage, scnames
def get_taxon_from_one_id(id_, eutils=None):
"""
"""
if eutils is None:
from bioservices import EUtils
eutils = EUtils()
ret = eutils.ELink("taxonomy", "nucleotide", [id_])
parsed = eutils.parse_xml(ret, 'EUtilsParser')
assert str(id_) == parsed.eLinkResult.LinkSet.IdList.Id
return parsed.eLinkResult.LinkSet.LinkSetDb.Link.Id
def get_taxon_from_ids(idlist):
from bioservices import EUtils
eutils = EUtils(cache=True)
pb = Progress(len(idlist))
taxons = []
for i, id_ in enumerate(idlist):
taxons.append(get_taxon_from_one_id(id_, eutils))
pb.animate(i+1)
return taxons
def __init__(self):
super(Taxon, self).__init__()
# self.df = pd.DataFrame(index=[], columns=["Taxon", "Scientific Name"])
self._eutils_service = EUtils()
self._ensembl_service = Ensembl() # there is a search by name, easier to use than EUtils
def find_taxon(self, taxid, mode="ncbi"):
taxid = str(taxid)
if mode == "ncbi":
from bioservices import EUtils
self.eutils = EUtils(verbose=False)
res = self.eutils.taxonomy_summary(taxid)
else:
res = self.ensembl.get_taxonomy_by_id(taxid)
return res
"""if "error" in res[taxid]:
print("not found in NCBI (EUtils)")