本文整理汇总了Python中bcftbx.TabFile类的典型用法代码示例。如果您正苦于以下问题:Python TabFile类的具体用法?Python TabFile怎么用?Python TabFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TabFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_append_line_as_data
def test_append_line_as_data(self):
"""Append a line to a file with data supplied as a list
"""
tabfile = TabFile('test',self.fp,first_line_is_header=True,delimiter=',')
data = ['chr3','10','9','8']
tabfile.append(data=data)
self.assertEqual(str(tabfile[-1]),','.join([str(x) for x in data]))
示例2: test_append_line
def test_append_line(self):
"""Append a line to a file
"""
tabfile = TabFile('test',self.fp,first_line_is_header=True,delimiter=',')
line = 'chr3,10,9,8'
tabfile.append(tabdata=line)
self.assertEqual(str(tabfile[-1]),line)
示例3: test_transpose_tab_file
def test_transpose_tab_file(self):
"""Test transposing TabFile
"""
tabfile1 = TabFile('test',self.fp,first_line_is_header=False)
tabfile2 = tabfile1.transpose()
self.assertEqual(len(tabfile1),tabfile2.nColumns())
self.assertEqual(len(tabfile2),tabfile1.nColumns())
示例4: test_write_data
def test_write_data(self):
"""Write data to file-like object
"""
tabfile = TabFile('test',self.fp)
fp = cStringIO.StringIO()
tabfile.write(fp=fp)
self.assertEqual(fp.getvalue(),self.data)
fp.close()
示例5: test_reverse_sort_on_column
def test_reverse_sort_on_column(self):
"""Sort data on a numerical column into (reverse) descending order
"""
tabfile = TabFile('test',self.fp,first_line_is_header=True)
tabfile.sort(lambda line: line['data'],reverse=True)
sorted_data = [6.8,5.7,3.4]
for i in range(len(tabfile)):
self.assertEqual(tabfile[i]['data'],sorted_data[i])
示例6: test_add_tab_data_to_new_tabfile
def test_add_tab_data_to_new_tabfile(self):
"""Test adding data as a tab-delimited line to a new empty TabFile
"""
data = 'chr1\t10000\t20000\t+'
tabfile = TabFile()
tabfile.append(tabdata=data)
self.assertEqual(len(tabfile),1,"TabFile should now have one line")
self.assertEqual(str(tabfile[0]),data)
示例7: test_write_data_with_header
def test_write_data_with_header(self):
"""Write data to file-like object including a header line
"""
tabfile = TabFile('test',self.fp,first_line_is_header=True,delimiter=',')
fp = cStringIO.StringIO()
tabfile.write(fp=fp,include_header=True)
self.assertEqual(fp.getvalue(),self.header.replace('\t',',')+self.data.replace('\t',','))
fp.close()
示例8: test_convert_values_to_type_append_tabdata
def test_convert_values_to_type_append_tabdata(self):
"""Convert input values to appropriate types (e.g. integer) when appending tabdata
"""
tabfile = TabFile('test',self.fp,first_line_is_header=True)
tabfile.append(tabdata="chr3\t5678\t7.9")
for line in tabfile:
self.assertTrue(isinstance(line[0],str))
self.assertTrue(isinstance(line[1],(int,long)))
self.assertTrue(isinstance(line[2],float))
示例9: test_convert_values_to_str_append_tabdata
def test_convert_values_to_str_append_tabdata(self):
"""Convert all input values to strings when appending tabdata
"""
tabfile = TabFile('test',self.fp,first_line_is_header=True,
convert=False)
tabfile.append(tabdata="chr3\t5678\t7.9")
for line in tabfile:
for value in line:
self.assertTrue(isinstance(value,str))
示例10: test_load_data_with_header
def test_load_data_with_header(self):
"""Create and load Tabfile using first line as header
"""
tabfile = TabFile('test',self.fp,first_line_is_header=True)
self.assertEqual(len(tabfile),3,"Input has 3 lines of data")
self.assertEqual(tabfile.header(),['chr','start','end','data'],"Wrong header")
self.assertEqual(str(tabfile[0]),"chr1\t1\t234\t4.6","Incorrect string representation")
self.assertEqual(tabfile[2]['chr'],'chr2',"Incorrect data")
self.assertEqual(tabfile.nColumns(),4)
示例11: test_add_data_to_new_tabfile
def test_add_data_to_new_tabfile(self):
"""Test adding data as a list of items to a new empty TabFile
"""
data = ['chr1',10000,20000,'+']
tabfile = TabFile()
tabfile.append(data=data)
self.assertEqual(len(tabfile),1,"TabFile should now have one line")
for i in range(len(data)):
self.assertEqual(tabfile[0][i],data[i])
示例12: test_unexpected_uncommented_header
def test_unexpected_uncommented_header(self):
"""Test reading in a tab file with an unexpected uncommented header
"""
tabfile = TabFile('test',self.fp)
self.assertEqual(len(tabfile),4,"Input has 4 lines of data")
self.assertEqual(tabfile.header(),[],"Wrong header")
self.assertEqual(str(tabfile[0]),"chr\tstart\tend\tdata","Incorrect string representation")
self.assertRaises(KeyError,tabfile[3].__getitem__,'chr')
self.assertEqual(tabfile.nColumns(),4)
示例13: test_expected_uncommented_header
def test_expected_uncommented_header(self):
"""Test reading in a tab file with an expected uncommented header
"""
tabfile = TabFile('test',self.fp,first_line_is_header=True)
self.assertEqual(len(tabfile),3,"Input has 3 lines of data")
self.assertEqual(tabfile.header(),['chr','start','end','data'],"Wrong header")
self.assertEqual(str(tabfile[0]),"chr1\t1\t234\t4.6","Incorrect string representation")
self.assertEqual(tabfile[2]['chr'],'chr2',"Incorrect data")
self.assertEqual(tabfile.nColumns(),4)
示例14: test_load_data
def test_load_data(self):
"""Create and load new TabFile instance
"""
tabfile = TabFile('test',self.fp,delimiter=',')
self.assertEqual(len(tabfile),3,"Input has 3 lines of data")
self.assertEqual(tabfile.header(),[],"Header should be empty")
self.assertEqual(str(tabfile[0]),"chr1,1,234,4.6","Incorrect string representation")
self.assertEqual(tabfile[2][0],'chr2',"Incorrect data")
self.assertEqual(tabfile.nColumns(),4)
self.assertEqual(tabfile.filename(),'test')
示例15: test_insert_line_with_tab_data
def test_insert_line_with_tab_data(self):
"""Insert line into a TabFile populated from tabbed data
"""
data = 'chr1\t10000\t20000\t+'
tabfile = TabFile('test',self.fp)
self.assertEqual(len(tabfile),3)
line = tabfile.insert(2,tabdata=data)
self.assertEqual(len(tabfile),4)
# Check new line is correct
self.assertTrue(str(line) == data)