Updated obi test to test NUC_SEQS views and the taxonomy API
This commit is contained in:
@ -1,7 +1,9 @@
|
|||||||
from obitools3.apps.progress cimport ProgressBar # TODO I absolutely don't understand why it doesn't work without that line
|
from obitools3.apps.progress cimport ProgressBar # TODO I absolutely don't understand why it doesn't work without that line
|
||||||
from obitools3.dms.view.view import View, Line_selection
|
from obitools3.dms.view.view import View, Line_selection
|
||||||
|
from obitools3.dms.view.typed_view.view_NUC_SEQS import View_NUC_SEQS
|
||||||
from obitools3.dms.dms import DMS
|
from obitools3.dms.dms import DMS
|
||||||
from obitools3.dms.column import Column
|
from obitools3.dms.column import Column
|
||||||
|
from obitools3.dms.taxo.taxo import OBI_Taxonomy
|
||||||
from obitools3.utils cimport str2bytes
|
from obitools3.utils cimport str2bytes
|
||||||
|
|
||||||
import shutil
|
import shutil
|
||||||
@ -9,7 +11,7 @@ import string
|
|||||||
import random
|
import random
|
||||||
|
|
||||||
|
|
||||||
VIEW_TYPES = [""] #, "NUC_SEQS_VIEW"]
|
VIEW_TYPES = ["", "NUC_SEQS_VIEW"]
|
||||||
#COL_TYPES = ["OBI_BOOL", "OBI_CHAR", "OBI_FLOAT", "OBI_INT", "OBI_SEQ", "OBI_STR"]
|
#COL_TYPES = ["OBI_BOOL", "OBI_CHAR", "OBI_FLOAT", "OBI_INT", "OBI_SEQ", "OBI_STR"]
|
||||||
COL_TYPES = [1, 2, 3, 4, 6, 7]
|
COL_TYPES = [1, 2, 3, 4, 6, 7]
|
||||||
NUC_SEQUENCE_COLUMN = "NUC_SEQ"
|
NUC_SEQUENCE_COLUMN = "NUC_SEQ"
|
||||||
@ -18,6 +20,8 @@ DEFINITION_COLUMN = "DEFINITION"
|
|||||||
QUALITY_COLUMN = "QUALITY"
|
QUALITY_COLUMN = "QUALITY"
|
||||||
SPECIAL_COLUMNS = [NUC_SEQUENCE_COLUMN, ID_COLUMN, DEFINITION_COLUMN, QUALITY_COLUMN]
|
SPECIAL_COLUMNS = [NUC_SEQUENCE_COLUMN, ID_COLUMN, DEFINITION_COLUMN, QUALITY_COLUMN]
|
||||||
|
|
||||||
|
#TAXDUMP = "" TODO path=?
|
||||||
|
TAXTEST = "taxtest"
|
||||||
|
|
||||||
NAME_MAX_LEN = 200
|
NAME_MAX_LEN = 200
|
||||||
COL_COMMENTS_MAX_LEN = 2048
|
COL_COMMENTS_MAX_LEN = 2048
|
||||||
@ -31,6 +35,27 @@ default_config = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def test_taxo(config, infos):
|
||||||
|
tax1 = OBI_Taxonomy.open(infos['dms'], config['obi']['taxo'], taxdump=True)
|
||||||
|
tax1.write(TAXTEST)
|
||||||
|
tax2 = OBI_Taxonomy.open(infos['dms'], TAXTEST, taxdump=False)
|
||||||
|
assert len(tax1) == len(tax2), "Length of written taxonomy != length of read taxdump : "+str(len(tax2))+" != "+str(len(tax1))
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
for x in range(config['test']['nbtests']):
|
||||||
|
idx = random.randint(0, len(tax1)-1)
|
||||||
|
t1 = tax1.get_taxon_by_idx(idx)
|
||||||
|
t2 = tax2.get_taxon_by_idx(idx)
|
||||||
|
assert t1 == t2, "Taxon gotten from written taxonomy != taxon read from taxdump : "+str(t2)+" != "+str(t1)
|
||||||
|
i+=1
|
||||||
|
if (i%(config['test']['nbtests']/10)) == 0 :
|
||||||
|
print("Testing taxonomy functions......"+str(i*100/config['test']['nbtests'])+"%")
|
||||||
|
|
||||||
|
tax1.close()
|
||||||
|
tax2.close()
|
||||||
|
|
||||||
|
|
||||||
def random_length(max_len):
|
def random_length(max_len):
|
||||||
return random.randint(1, max_len)
|
return random.randint(1, max_len)
|
||||||
|
|
||||||
@ -245,7 +270,10 @@ def random_new_view(config, infos, first=False):
|
|||||||
elif v_to_clone is not None :
|
elif v_to_clone is not None :
|
||||||
infos['view'] = v_to_clone.clone(random_unique_name(infos), comments=random_str_with_max_len(config['test']['commentsmaxlen']))
|
infos['view'] = v_to_clone.clone(random_unique_name(infos), comments=random_str_with_max_len(config['test']['commentsmaxlen']))
|
||||||
else :
|
else :
|
||||||
infos['view'] = View.new(infos['dms'], random_unique_name(infos), comments=random_str_with_max_len(config['test']['commentsmaxlen'])) # TODO random view class
|
if v_type == "NUC_SEQS_VIEW" :
|
||||||
|
infos['view'] = View_NUC_SEQS.new(infos['dms'], random_unique_name(infos), comments=random_str_with_max_len(config['test']['commentsmaxlen'])) # TODO quality column
|
||||||
|
else :
|
||||||
|
infos['view'] = View.new(infos['dms'], random_unique_name(infos), comments=random_str_with_max_len(config['test']['commentsmaxlen'])) # TODO quality column
|
||||||
|
|
||||||
print_test(config, repr(infos['view']))
|
print_test(config, repr(infos['view']))
|
||||||
if v_to_clone is not None :
|
if v_to_clone is not None :
|
||||||
@ -281,6 +309,13 @@ def addOptions(parser):
|
|||||||
help="Name of the default DMS for reading and writing data. "
|
help="Name of the default DMS for reading and writing data. "
|
||||||
"Default: /tmp/test_dms")
|
"Default: /tmp/test_dms")
|
||||||
|
|
||||||
|
group.add_argument('--taxo','-t',
|
||||||
|
action="store", dest="obi:taxo",
|
||||||
|
metavar='<TAXDUMP PATH>',
|
||||||
|
type=str,
|
||||||
|
help="Path to a taxdump to test the taxonomy.") # TODO
|
||||||
|
|
||||||
|
|
||||||
group=parser.add_argument_group('obi test specific options')
|
group=parser.add_argument_group('obi test specific options')
|
||||||
|
|
||||||
group.add_argument('--nb_tests','-n',
|
group.add_argument('--nb_tests','-n',
|
||||||
@ -299,7 +334,7 @@ def addOptions(parser):
|
|||||||
help="Maximum length of DNA sequences. "
|
help="Maximum length of DNA sequences. "
|
||||||
"Default: 200")
|
"Default: 200")
|
||||||
|
|
||||||
group.add_argument('--str_max_len','-t',
|
group.add_argument('--str_max_len','-r',
|
||||||
action="store", dest="test:strmaxlen",
|
action="store", dest="test:strmaxlen",
|
||||||
metavar='<STR_MAX_LEN>',
|
metavar='<STR_MAX_LEN>',
|
||||||
default=200,
|
default=200,
|
||||||
@ -384,6 +419,8 @@ def run(config):
|
|||||||
|
|
||||||
#print(infos)
|
#print(infos)
|
||||||
|
|
||||||
|
test_taxo(config, infos)
|
||||||
|
|
||||||
infos['view'].close()
|
infos['view'].close()
|
||||||
infos['dms'].close()
|
infos['dms'].close()
|
||||||
shutil.rmtree(config['obi']['defaultdms']+'.obidms', ignore_errors=True)
|
shutil.rmtree(config['obi']['defaultdms']+'.obidms', ignore_errors=True)
|
||||||
|
Reference in New Issue
Block a user