Merge pull request #12280 from bernt-matthias/topic/mothur-tabular

This commit is contained in:
Nicola Soranzo
2021-09-13 17:33:57 +01:00
committed by GitHub
5 changed files with 30 additions and 17 deletions
+24 -12
View File
@@ -494,21 +494,33 @@ class PairwiseDistanceMatrix(DistanceMatrix, Tabular):
"""
headers = iter_headers(file_prefix, sep='\t')
count = 0
names = [False, False]
for line in headers:
if not line[0].startswith('@'):
if len(line) != 3:
return False
if line[0].startswith('@'):
continue
if len(line) != 3:
return False
# check if col3 contains distances (floats)
try:
float(line[2])
try:
float(line[2])
try:
# See if it's also an integer
int(line[2])
except ValueError:
# At least one value is not an integer
all_ints = False
# See if it's also an integer
int(line[2])
except ValueError:
return False
count += 1
# At least one value is not an integer
all_ints = False
except ValueError:
return False
count += 1
# check if col1 and col2 likely contain names
for c in [0, 1]:
try:
float(line[c])
except ValueError:
names[c] = True
if not names[0] or not names[1]:
return False
if count > 2:
return not all_ints
+1 -1
View File
@@ -270,7 +270,7 @@ def guess_ext(fname, sniff_order, is_binary=False):
>>> fname = get_test_fname('2.txt')
>>> guess_ext(fname, sniff_order)
'txt'
>>> fname = get_test_fname('2.tabular')
>>> fname = get_test_fname('test_tab2.tabular')
>>> guess_ext(fname, sniff_order)
'tabular'
>>> fname = get_test_fname('3.txt')
+1 -1
View File
@@ -719,7 +719,7 @@ class Pileup(Tabular):
>>> fname = get_test_fname( '2.txt' )
>>> Pileup().sniff( fname ) # 2.txt
False
>>> fname = get_test_fname( '2.tabular' )
>>> fname = get_test_fname( 'test_tab2.tabular' )
>>> Pileup().sniff( fname )
False
"""
-3
View File
@@ -1,3 +0,0 @@
a 2
c 1
d 0
+1
View File
@@ -0,0 +1 @@
../../../../test-data/2.tabular
@@ -0,0 +1,3 @@
a 2
c 1
d 0