# HG changeset patch # User Jim Johnson # Date 1369745017 18000 # Node ID 9c0cd3b922957a22fe7ad47178f5fc2f781d2a65 # Parent 7238483c96fa800065128999808c987eeb4eec50 Fixes for metagenomics.py datatypes tahnks to Peter Briggs diff -r 7238483c96fa -r 9c0cd3b92295 mothur/lib/galaxy/datatypes/metagenomics.py --- a/mothur/lib/galaxy/datatypes/metagenomics.py Wed Feb 20 07:51:22 2013 -0600 +++ b/mothur/lib/galaxy/datatypes/metagenomics.py Tue May 28 07:43:37 2013 -0500 @@ -468,23 +468,32 @@ try: fh = open( filename ) count = 0 + line = fh.readline() + sequence_count = int(line.strip()) while True: line = fh.readline() line = line.strip() if not line: break #EOF if line: - if line[0] != '@': - linePieces = line.split('\t') - if len(linePieces) != 3: - return False - try: - check = float(linePieces[2]) - except ValueError: - return False - count += 1 - if count == 5: - return True + # Split into fields + linePieces = line.split('\t') + # Each line should have the same number of + # fields as the Python line index + linePieces = line.split('\t') + if len(linePieces) != (count + 1): + return False + # Distances should be floats + try: + for linePiece in linePieces[2:]: + check = float(linePiece) + except ValueError: + return False + # Increment line counter + count += 1 + # Only check first 5 lines + if count == 5: + return True fh.close() if count < 5 and count > 0: return True @@ -565,6 +574,7 @@ try: fh = open( filename ) count = 0 + all_ints = True while True: line = fh.readline() line = line.strip() @@ -577,14 +587,27 @@ return False try: check = float(linePieces[2]) + try: + # See if it's also an integer + check_int = int(linePieces[2]) + except ValueError: + # At least one value is not an + # integer + all_ints = False except ValueError: return False count += 1 if count == 5: - return True + if not all_ints: + return True + else: + return False fh.close() if count < 5 and count > 0: - return True + if not all_ints: + return True + else: + return False except: pass finally: @@ -910,10 +933,12 @@ line = line.strip() if line: fields = line.split('\t') - if 2 <= len(fields) <= 3: + if not (2 <= len(fields) <= 3): return False if not re.match(pat,fields[1]): return False + if len(fields) == 3: + check = int(fields[2]) count += 1 if count > 10: break @@ -1117,6 +1142,9 @@ fields = line.split('\t') if col_cnt == None: # ignore values in first line as they may be column headings col_cnt = len(fields) + # There should be at least 2 columns + if col_cnt < 2: + return False else: if len(fields) != col_cnt : return False