Commit 2ad7d54d authored by Mathieu Giraud's avatar Mathieu Giraud

ncbi.py, split-from-imgt.py: be more robust on non-found genes

parent 91adbc24
......@@ -50,12 +50,21 @@ def get_last_LocationHistType(gene):
xml = minidom.parseString(urllib.urlopen(API_GENE_ID_XML % gene).read())
locations = xml.getElementsByTagName('LocationHistType')
return xml_bang_one(locations[0])
if locations:
return xml_bang_one(locations[0])
else:
raise KeyError, gene
def get_gene_positions(gene):
'''
>>> get_gene_positions(6969)
(u'NC_000007.14', 38253428, 38253379)
>>> get_gene_positions('zoycooxz')
Traceback (most recent call last):
...
KeyError: 'zoycooxz'
'''
loc = get_last_LocationHistType(gene)
......
......@@ -107,9 +107,14 @@ def retrieve_genes(f, genes, tag, additional_length, gene_list):
if gene_id:
# gene_id is found, extract from chromosome
(target, start, end) = ncbi.get_gene_positions(gene_id)
print(coord, gene_id, target, start, end)
else:
try:
(target, start, end) = ncbi.get_gene_positions(gene_id)
print(coord, gene_id, target, start, end)
except KeyError:
print('! No positions for %s (%s)' % (gene_id, gene))
gene_id = None
if not gene_id:
# extract from gene
target = gene
start = coord['from']
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment