From 399fc2c051c81248e38b3b3e872df3122ac55450 Mon Sep 17 00:00:00 2001 From: Celine Mercier Date: Fri, 30 Sep 2016 17:49:37 +0200 Subject: [PATCH] Removed deprecated source files previously used for tests --- python/obitools3/obigrep.py | 51 ------ python/obitools3/obihead.py | 43 ----- python/obitools3/obiimport.py | 199 --------------------- python/obitools3/unit_tests.py | 311 --------------------------------- 4 files changed, 604 deletions(-) delete mode 100644 python/obitools3/obigrep.py delete mode 100644 python/obitools3/obihead.py delete mode 100644 python/obitools3/obiimport.py delete mode 100644 python/obitools3/unit_tests.py diff --git a/python/obitools3/obigrep.py b/python/obitools3/obigrep.py deleted file mode 100644 index b7f9cbf..0000000 --- a/python/obitools3/obigrep.py +++ /dev/null @@ -1,51 +0,0 @@ -import sys -import argparse - -from obitools3.obidms._obidms import OBIDMS - -if __name__ == '__main__': - - parser = argparse.ArgumentParser(description='Pseudo obigrep.') - - parser.add_argument('-V', '--view', dest='view', type=str, - help='Name of the view that should be considered') - - parser.add_argument('-N', '--new_view', dest='new_view', type=str, - help='Name of the new view that should be created') - -# parser.add_argument('-k', '--key', dest='key', type=str, -# help='Name of the key that should be considered') -# -# parser.add_argument('-c', '--comp', dest='comparison', type=int, -# help='Comparison to be made: -1:< ; 0:== ; 1:>') -# -# parser.add_argument('-v', '--value', dest='value', type=object, -# help='Value to be compared') - - args = parser.parse_args() - - d = OBIDMS('tdms') - - #condition = 1 - line_selec = [] - - v = d.open_view(args.view) - - i = 0 - for l in v : - if l['score'] > 350 : - line_selec.append(i) - i+=1 - - new_v = d.new_view(args.new_view, view_to_clone=v, line_selection=line_selec, view_type="NUC_SEQS_VIEW", comments="obigrep "+args.view+" to "+args.new_view) #args.key+" "+str(args.comparison)+" "+str(args.value)+" "+) - - print("\n") - print(new_v.__repr__()) - - v.save_and_close() - new_v.save_and_close() - - d.close() - - print("\nDone.") - \ No newline at end of file diff --git a/python/obitools3/obihead.py b/python/obitools3/obihead.py deleted file mode 100644 index 819d924..0000000 --- a/python/obitools3/obihead.py +++ /dev/null @@ -1,43 +0,0 @@ -import sys -import argparse - -from obitools3.obidms._obidms import OBIDMS - -if __name__ == '__main__': - - parser = argparse.ArgumentParser(description='Pseudo obihead.') - - parser.add_argument('-V', '--view', dest='view', type=str, - help='Name of the view that should be considered') - - parser.add_argument('-N', '--new_view', dest='new_view', type=str, - help='Name of the new view that should be created') - - parser.add_argument('-n', '--nb', dest='nb_lines', type=int, - help='Number of lines that should be taken') - - - args = parser.parse_args() - - d = OBIDMS('tdms') - - #condition = 1 - line_selec = [] - - v = d.open_view(args.view) - - for i in range(0, args.nb_lines) : - line_selec.append(i) - - new_v = d.new_view(args.new_view, view_to_clone=v, line_selection=line_selec, view_type="NUC_SEQS_VIEW", comments="obihead "+str(args.nb_lines)+", "+args.view+" to "+args.new_view) #args.key+" "+str(args.comparison)+" "+str(args.value)+" "+) - - print("\n") - print(new_v.__repr__()) - - v.save_and_close() - new_v.save_and_close() - - d.close() - - print("\nDone.") - \ No newline at end of file diff --git a/python/obitools3/obiimport.py b/python/obitools3/obiimport.py deleted file mode 100644 index a07362a..0000000 --- a/python/obitools3/obiimport.py +++ /dev/null @@ -1,199 +0,0 @@ -import sys -import argparse -import time - -from obitools3.obidms._obidms import OBIDMS - - -def bufferedRead(fileobj,size=209715200): ## 200 MB - buffer = fileobj.readlines(size) - while buffer: - for l in buffer: - yield l - buffer = fileobj.readlines(size) - - -if __name__ == '__main__': - - parser = argparse.ArgumentParser(description='Convert a fasta file in an OBIDMS.') - - parser.add_argument('-i', '--input', dest='input_file', type=str, - help='Name of the file containing the sequences') - - args = parser.parse_args() - - d = OBIDMS('tdms') - - view = d.new_view('uniq view', view_type="NUC_SEQS_VIEW") - -# for i in range(35000000) : -# if (not (i%500000)) : -# print(str(time.time())+'\t'+str(i)) -# id = "@HWI-D00405:142:C71BAANXX:4:1101:1234:2234_CONS_SUB_SUB_"+str(i) -# view[i].set_id(id) -# if id != view[i]["ID"] : -# print("nope", id, view[i]["ID"]) - - input_file = open(args.input_file, 'r') - input_file_buffered = bufferedRead(input_file) - -# -# if args.input_file[-1:] == "a" : -# -# i = 0 -# next = False -# first = True -# -# for line in input_file : -# -# if line[0] == ">" : -# -# if not first : -# # save seq -# #print(i, id, seq) -# view[i].set_sequence(seq) -# i+=1 -# -# first = False -# -# #id = line.split(" ", 1)[0][1:] -# #rest = (line[:-1].split(" ", 1)[1]).split(";") -# #view[i].set_id(id) -# -# # description = "" -# # for j in range(len(rest)) : -# # if "=" in rest[j] : -# # rest[j] = rest[j].strip() -# # rest[j] = rest[j].split("=", 1) -# # column_name = rest[j][0] -# # v = rest[j][1] -# # if ((not v.isalpha()) and (v.isalnum())) : -# # conv_v = int(v) -# # elif (v == "True") or (v == "False") : -# # conv_v = bool(v) -# # else : -# # f = True -# # for letter in v : -# # if ((not letter.isalnum()) or (letter != ".")) : -# # f = False -# # if f : -# # conv_v = float(v) -# # else : -# # conv_v = v -# # view[i][column_name] = conv_v -# # else : -# # description+=rest[j] -# # -# # if description != "" : -# # description = description.strip() -# # view[i].set_description(description) -# -# #print(id) -# #print(rest) -# #print(description) -# -# next = True -# -# elif next == True : -# -# # if not (i % 1E5) : -# # print(i) -# -# seq = line[:-1] -# next = False -# -# elif not next : -# -# seq += line[:-1] -# -# -# elif args.input_file[-1:] == "q" : -# -# i = 0 -# l = 0 -# next = False -# - l=0 - i=0 -# while (True): -# l+=1 -# line = input_file.readline() -# if line=="": -# break - for line in input_file_buffered : -# - #if i > 1E7 : -# # print('hmm?') -# -# if i == 6000000 : -# break -# - if l%4 == 0 : -# - if (not (i%500000)) : - print(str(time.time())+'\t'+str(i)) -# # -# # #print("header", line) -# # - id = line.split(" ", 1)[0][1:] -# print(id) -# # #rest = (line[:-1].split(" ", 1)[1]).split(";") - view[i].set_id(id) -# print(view[i]["ID"]) -# -# i+=1 - -# l+=1 -# -# # description = "" -# # for j in range(len(rest)) : -# # if "=" in rest[j] : -# # rest[j] = rest[j].strip() -# # rest[j] = rest[j].split("=", 1) -# # column_name = rest[j][0] -# # #print("COLUMN", column_name) -# # v = rest[j][1] -# # if (v == "") and (column_name in view) and (view[column_name].get_data_type() == "OBI_SEQ") : -# # #print(">>>>>>YUP") -# # conv_v = "aa" -# # else : -# # if ((not v.isalpha()) and (v.isalnum())) : -# # conv_v = int(v) -# # elif (v == "True") or (v == "False") : -# # conv_v = bool(v) -# # else : -# # f = True -# # for letter in v : -# # if ((not letter.isalnum()) or (letter != ".")) : -# # f = False -# # if f : -# # conv_v = float(v) -# # else : -# # conv_v = v -# # view[i][column_name] = conv_v -# # else : -# # description+=rest[j] -# # -# # if description != "" : -# # description = description.strip() -# # view[i].set_description(description) -# - elif l%4 == 1 : -# # - seq = line[:-1] -# #print("seq", seq) - view[i].set_sequence(seq) - i+=1 -# - l+=1 -# -# - input_file.close() - - #print(view) - print(view.__repr__()) - - view.save_and_close() - d.close() - - print("Done.") diff --git a/python/obitools3/unit_tests.py b/python/obitools3/unit_tests.py deleted file mode 100644 index 337b782..0000000 --- a/python/obitools3/unit_tests.py +++ /dev/null @@ -1,311 +0,0 @@ -import os -import sys -import shutil -import unittest -from random import randint, uniform, choice -import string - -from obitools3.obidms._obidms import OBIDMS - - -LINE_COUNT_FOR_TEST_COLUMN = 10000 # TODO randomize? -SMALLER_LINE_COUNT_FOR_TEST_COLUMN = 1000 # TODO randomize? -NB_ELEMENTS_PER_LINE = 10 # TODO randomize? -DMS_NAME = "unit_test_dms" - - -def create_test_obidms(): - dms_name = DMS_NAME - dms_dir_name = dms_name+'.obidms' - dms = OBIDMS(dms_name) - return (dms, dms_name, dms_dir_name) - - -def create_test_column(dms, data_type, multiple_elements_per_line=False): - - col_name = "unit_test_"+data_type - - if multiple_elements_per_line : - elts_names = elements_names() - col = dms.open_column(col_name, - create=True, - type=data_type, - nb_elements_per_line=NB_ELEMENTS_PER_LINE, - elements_names=elts_names) - return (col, col_name, elts_names) - - else : - col = dms.open_column(col_name, - create=True, - type=data_type) - return (col, col_name) - - -def elements_names(): - names = [str(i) for i in range(NB_ELEMENTS_PER_LINE)] - return names - - -def random_obivalue(data_type): - r = 1000000 - if data_type == "OBI_INT" : - return randint(-r,r) - elif data_type == "OBI_FLOAT" : - return uniform(-r,r) - elif data_type == "OBI_BOOL" : - return randint(0,1) - elif data_type == "OBI_CHAR" : - return choice(string.ascii_lowercase) - elif data_type == "OBI_STR" : - length = randint(1,200) - randoms = ''.join(choice(string.ascii_lowercase) for i in range(length)) - return randoms - elif data_type == "OBI_SEQ" : - length = randint(1,200) - randoms = ''.join(choice("atgcryswkmdbhvn") for i in range(length)) - return randoms - -class OBIDMS_Column_TestCase(unittest.TestCase): - def tearDown(self): - self.col.close() - self.dms.close() - shutil.rmtree(self.dms_dir_name, ignore_errors=True) - def test_OBIDMS_column_type(self): - assert self.col.get_data_type() == self.data_type, 'Wrong data type associated with column' - def test_OBIDMS_column_cloning(self): - for i in range(LINE_COUNT_FOR_TEST_COLUMN): - self.col[i]= random_obivalue(self.data_type) - self.col.close() - clone = self.dms.open_column(self.col_name, clone=True) - self.col = self.dms.open_column(self.col_name) - assert clone.get_nb_lines_used() == self.col.get_nb_lines_used(), "Cloned column doesn't have the same number of lines used" - i=0 - for i in range(clone.get_nb_lines_used()) : - assert clone[i] == self.col[i], "Different value in original column and cloned column" - assert clone[i] is not None, "None value" - clone.close() - def test_OBIDMS_column_set_and_get(self): - for i in range(LINE_COUNT_FOR_TEST_COLUMN): - v = random_obivalue(self.data_type) - self.col[i] = v - assert self.col[i] == v, "Different value than the set value" - assert self.col[i] is not None, "None value" - def test_OBIDMS_referring_column(self): - for i in range(LINE_COUNT_FOR_TEST_COLUMN): - self.col[i] = random_obivalue(self.data_type) - ref_col = self.dms.open_column(self.col_name, referring=True) - j = 0 - for i in range(LINE_COUNT_FOR_TEST_COLUMN): - if i%2 : # TODO randomize - ref_col.grep_line(i) - assert ref_col[j] == self.col[i], "Different value in original column and returned by referring column" - assert ref_col[j] is not None, "None value" - j+=1 - - -class OBIDMS_Column_multiple_elements_TestCase(OBIDMS_Column_TestCase): - def test_OBIDMS_column_cloning(self): - pass - for i in range(SMALLER_LINE_COUNT_FOR_TEST_COLUMN): - v = {} - for e in self.elts_names : - v[e] = random_obivalue(self.data_type) - self.col[i] = v - self.col.close() - clone = self.dms.open_column(self.col_name, clone=True) - self.col = self.dms.open_column(self.col_name) - assert clone.get_nb_lines_used() == self.col.get_nb_lines_used(), "Cloned column doesn't have the same number of lines used" - i=0 - for i in range(SMALLER_LINE_COUNT_FOR_TEST_COLUMN): - assert self.col[i] == clone[i], "Different value in original column and cloned column" - assert self.col[i] is not None, "None value" - clone.close() - def test_OBIDMS_column_set_and_get_with_elements_names(self): - for i in range(SMALLER_LINE_COUNT_FOR_TEST_COLUMN): - for e in range(NB_ELEMENTS_PER_LINE) : - v = random_obivalue(self.data_type) - self.col.set_item(i, self.elts_names[e], v) - assert self.col.get_item(i, self.elts_names[e]) == v, "Different value than the set value" - assert self.col.get_item(i, self.elts_names[e]) is not None, "None value" - def test_OBIDMS_column_set_and_get(self): - for i in range(SMALLER_LINE_COUNT_FOR_TEST_COLUMN): - v = {} - for e in self.elts_names : - v[e] = random_obivalue(self.data_type) - self.col[i] = v - assert self.col[i] == v, "Different value than the set value" - assert self.col[i] is not None, "None value" - def test_OBIDMS_referring_column(self): - for i in range(SMALLER_LINE_COUNT_FOR_TEST_COLUMN): - v = {} - for e in self.elts_names : - v[e] = random_obivalue(self.data_type) - self.col[i] = v - ref_col = self.dms.open_column(self.col_name, referring=True) - j = 0 - for i in range(SMALLER_LINE_COUNT_FOR_TEST_COLUMN): - if i%2 : # TODO randomize - ref_col.grep_line(i) - assert ref_col[j] == self.col[i], "Different value in original column and returned by referring column" - assert ref_col[j] is not None, "None value" - j+=1 - ref_col.close() - - -class OBIDMS_Column_OBI_INT_TestCase(OBIDMS_Column_TestCase): - def setUp(self): - self.data_type = 'OBI_INT' - self.dms, \ - self.dms_name, \ - self.dms_dir_name = create_test_obidms() - self.col, \ - self.col_name = create_test_column(self.dms, - self.data_type) - - -class OBIDMS_Column_OBI_INT_multiple_elements_TestCase(OBIDMS_Column_multiple_elements_TestCase): - def setUp(self): - self.data_type = 'OBI_INT' - self.dms, \ - self.dms_name, \ - self.dms_dir_name = create_test_obidms() - self.col, \ - self.col_name, \ - self.elts_names = create_test_column(self.dms, - self.data_type, - multiple_elements_per_line=True) - - -class OBIDMS_Column_OBI_FLOAT_TestCase(OBIDMS_Column_TestCase): - def setUp(self): - self.data_type = 'OBI_FLOAT' - self.dms, \ - self.dms_name, \ - self.dms_dir_name = create_test_obidms() - self.col, \ - self.col_name = create_test_column(self.dms, - self.data_type) - - -class OBIDMS_Column_OBI_FLOAT_multiple_elements_TestCase(OBIDMS_Column_multiple_elements_TestCase): - def setUp(self): - self.data_type = 'OBI_FLOAT' - self.dms, \ - self.dms_name, \ - self.dms_dir_name = create_test_obidms() - self.col, \ - self.col_name, \ - self.elts_names = create_test_column(self.dms, - self.data_type, - multiple_elements_per_line=True) - - -class OBIDMS_Column_OBI_BOOL_TestCase(OBIDMS_Column_TestCase): - def setUp(self): - self.data_type = 'OBI_BOOL' - self.dms, \ - self.dms_name, \ - self.dms_dir_name = create_test_obidms() - self.col, \ - self.col_name = create_test_column(self.dms, - self.data_type) - - -class OBIDMS_Column_OBI_BOOL_multiple_elements_TestCase(OBIDMS_Column_multiple_elements_TestCase): - def setUp(self): - self.data_type = 'OBI_BOOL' - self.dms, \ - self.dms_name, \ - self.dms_dir_name = create_test_obidms() - self.col, \ - self.col_name, \ - self.elts_names = create_test_column(self.dms, - self.data_type, - multiple_elements_per_line=True) - - -class OBIDMS_Column_OBI_CHAR_TestCase(OBIDMS_Column_TestCase): - def setUp(self): - self.data_type = 'OBI_CHAR' - self.dms, \ - self.dms_name, \ - self.dms_dir_name = create_test_obidms() - self.col, \ - self.col_name = create_test_column(self.dms, - self.data_type) - - -class OBIDMS_Column_OBI_CHAR_multiple_elements_TestCase(OBIDMS_Column_multiple_elements_TestCase): - def setUp(self): - self.data_type = 'OBI_CHAR' - self.dms, \ - self.dms_name, \ - self.dms_dir_name = create_test_obidms() - self.col, \ - self.col_name, \ - self.elts_names = create_test_column(self.dms, - self.data_type, - multiple_elements_per_line=True) - - -class OBIDMS_Column_OBI_STR_TestCase(OBIDMS_Column_TestCase): - def setUp(self): - self.data_type = 'OBI_STR' - self.dms, \ - self.dms_name, \ - self.dms_dir_name = create_test_obidms() - self.col, \ - self.col_name = create_test_column(self.dms, - self.data_type) - - -class OBIDMS_Column_OBI_STR_multiple_elements_TestCase(OBIDMS_Column_multiple_elements_TestCase): - def setUp(self): - self.data_type = 'OBI_STR' - self.dms, \ - self.dms_name, \ - self.dms_dir_name = create_test_obidms() - self.col, \ - self.col_name, \ - self.elts_names = create_test_column(self.dms, - self.data_type, - multiple_elements_per_line=True) - -class OBIDMS_Column_OBI_SEQ_TestCase(OBIDMS_Column_TestCase): - def setUp(self): - self.data_type = 'OBI_SEQ' - self.dms, \ - self.dms_name, \ - self.dms_dir_name = create_test_obidms() - self.col, \ - self.col_name = create_test_column(self.dms, - self.data_type) - - -class OBIDMS_Column_OBI_SEQ_multiple_elements_TestCase(OBIDMS_Column_multiple_elements_TestCase): - def setUp(self): - self.data_type = 'OBI_SEQ' - self.dms, \ - self.dms_name, \ - self.dms_dir_name = create_test_obidms() - self.col, \ - self.col_name, \ - self.elts_names = create_test_column(self.dms, - self.data_type, - multiple_elements_per_line=True) - -if __name__ == '__main__': - unittest.main(verbosity=2, defaultTest=["OBIDMS_Column_OBI_INT_TestCase", - "OBIDMS_Column_OBI_INT_multiple_elements_TestCase", - "OBIDMS_Column_OBI_FLOAT_TestCase", - "OBIDMS_Column_OBI_FLOAT_multiple_elements_TestCase", - "OBIDMS_Column_OBI_BOOL_TestCase", - "OBIDMS_Column_OBI_BOOL_multiple_elements_TestCase", - "OBIDMS_Column_OBI_CHAR_TestCase", - "OBIDMS_Column_OBI_CHAR_multiple_elements_TestCase", - "OBIDMS_Column_OBI_STR_TestCase", - "OBIDMS_Column_OBI_STR_multiple_elements_TestCase", - "OBIDMS_Column_OBI_SEQ_TestCase", - "OBIDMS_Column_OBI_SEQ_multiple_elements_TestCase"]) - -