Cython API: URI decoding now returns the character string with the
object path if it could not be opened
This commit is contained in:
@ -9,6 +9,7 @@ from obitools3.parsers.fasta import fastaNucIterator
|
||||
from obitools3.parsers.fastq import fastqIterator
|
||||
from obitools3.parsers.tab import tabIterator
|
||||
from obitools3.parsers.ngsfilter import ngsfilterIterator
|
||||
from obitools3.parsers.embl import emblIterator
|
||||
from obitools3.parsers.universal import entryIteratorFactory
|
||||
|
||||
from obitools3.dms.obiseq import Nuc_Seq
|
||||
@ -66,18 +67,20 @@ def open_dms_element(DMS dms, bytes path,
|
||||
if not path:
|
||||
return (dms,dms)
|
||||
|
||||
# TODO SHOULD READ AND RETURN PREFIX TO NEW TAXO WITHOUT CREATING ANYTHING
|
||||
# The URI targets a taxonomy
|
||||
# dms:dmspath/taxonomy/taxoname[/taxid]
|
||||
if path_parts[0]==b"taxonomy":
|
||||
if len(path_parts) > 1:
|
||||
taxo = Taxonomy.open(dms,path_parts[1])
|
||||
if len(path_parts) == 3:
|
||||
taxon=taxo[int(path_parts[2])]
|
||||
return (dms,taxon)
|
||||
elif len(path_parts) > 3:
|
||||
raise MalformedURIException('Malformed Taxonomy URI')
|
||||
return (dms,taxo)
|
||||
if Taxonomy.exists(dms, path_parts[1]):
|
||||
taxo = Taxonomy.open(dms, path_parts[1])
|
||||
if len(path_parts) == 3:
|
||||
taxon=taxo[int(path_parts[2])]
|
||||
return (dms, taxon)
|
||||
elif len(path_parts) > 3:
|
||||
raise MalformedURIException('Malformed Taxonomy URI')
|
||||
else:
|
||||
return (dms, path_parts[1]) # return prefix for creation eventually
|
||||
return (dms, taxo)
|
||||
|
||||
# The URI targets a view
|
||||
# dms:dmspath/viewname[/columnname|#line|*[/#line|columnname|*[/subcolumn]]]
|
||||
@ -165,7 +168,7 @@ def open_uri(uri,
|
||||
create=not input
|
||||
|
||||
scheme = urip.scheme
|
||||
|
||||
|
||||
error = None
|
||||
|
||||
if scheme==b"" or scheme==b"dms" :
|
||||
@ -199,18 +202,19 @@ def open_uri(uri,
|
||||
error=e
|
||||
|
||||
if scheme==b"dms" :
|
||||
logger('error','cannot open DMS: %s', uri)
|
||||
logger('Error','cannot open DMS: %s', uri)
|
||||
raise FileNotFoundError('uri')
|
||||
|
||||
if not urip.scheme:
|
||||
urib=b"file:"+urib
|
||||
#if not urip.scheme: # TODO not sure what it was supposed to do but not working as intended
|
||||
# urib=b"file:"+urib
|
||||
|
||||
try:
|
||||
file = uopen(tostr(urib))
|
||||
logger('info','Opened file : %s', tostr(urib))
|
||||
except Exception as e:
|
||||
file = None
|
||||
error=e
|
||||
file = uopen(urib)
|
||||
logger('info','Opened file: %s', tostr(urib))
|
||||
except Exception as e: # TODO discuss: if can't open file, return the character string itself
|
||||
file = urib
|
||||
iseq = urib
|
||||
objclass = bytes
|
||||
|
||||
if file is not None:
|
||||
qualifiers=parse_qs(urip.query)
|
||||
@ -384,6 +388,10 @@ def open_uri(uri,
|
||||
only=only,
|
||||
offset=offset,
|
||||
noquality=noquality)
|
||||
elif format==b"embl":
|
||||
iseq = emblIterator(file,
|
||||
skip=skip,
|
||||
only=only)
|
||||
else:
|
||||
raise NotImplementedError('Sequence file format not implemented')
|
||||
elif seqtype==b"prot":
|
||||
@ -410,25 +418,22 @@ def open_uri(uri,
|
||||
skip = skip,
|
||||
only = only)
|
||||
else:
|
||||
iseq,objclass = entryIteratorFactory(file,
|
||||
skip, only,
|
||||
seqtype,
|
||||
offset,
|
||||
noquality,
|
||||
skiperror,
|
||||
header,
|
||||
sep,
|
||||
dec,
|
||||
nastring,
|
||||
stripwhite,
|
||||
blanklineskip,
|
||||
commentchar)
|
||||
iseq, objclass = entryIteratorFactory(file,
|
||||
skip, only,
|
||||
seqtype,
|
||||
offset,
|
||||
noquality,
|
||||
skiperror,
|
||||
header,
|
||||
sep,
|
||||
dec,
|
||||
nastring,
|
||||
stripwhite,
|
||||
blanklineskip,
|
||||
commentchar)
|
||||
|
||||
#tmpdms = get_temp_dms()
|
||||
|
||||
return (file, iseq, objclass, urib)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user