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