From 047c1bff2f9950d273bcac61c7b2eccefe2fd0fc Mon Sep 17 00:00:00 2001 From: Jeremy Goecks Date: Thu, 8 Mar 2012 11:09:14 -0500 Subject: [PATCH] Enable fasta_to_len conversion to use only first word in title; this is standards compliant and used by default for automatic conversion. --- lib/galaxy/datatypes/converters/fasta_to_len.py | 10 +++++++--- tools/fasta_tools/fasta_compute_length.py | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/galaxy/datatypes/converters/fasta_to_len.py b/lib/galaxy/datatypes/converters/fasta_to_len.py index 26f0856bd4e..d604d8dd101 100644 --- a/lib/galaxy/datatypes/converters/fasta_to_len.py +++ b/lib/galaxy/datatypes/converters/fasta_to_len.py @@ -9,7 +9,7 @@ import sys, os assert sys.version_info[:2] >= ( 2, 4 ) -def compute_fasta_length( fasta_file, out_file, keep_first_char ): +def compute_fasta_length( fasta_file, out_file, keep_first_char, keep_first_word=False ): infile = fasta_file out = open( out_file, 'w') @@ -32,6 +32,8 @@ def compute_fasta_length( fasta_file, out_file, keep_first_char ): continue if line[0] == '>': if first_entry == False: + if keep_first_word: + fasta_title = fasta_title.split()[0] out.write( "%s\t%d\n" % ( fasta_title[ 1:keep_first_char ], seq_len ) ) else: first_entry = False @@ -41,8 +43,10 @@ def compute_fasta_length( fasta_file, out_file, keep_first_char ): seq_len += len(line) # last fasta-entry + if keep_first_word: + fasta_title = fasta_title.split()[0] out.write( "%s\t%d\n" % ( fasta_title[ 1:keep_first_char ], seq_len ) ) out.close() -if __name__ == "__main__" : - compute_fasta_length( sys.argv[1], sys.argv[2], sys.argv[3] ) \ No newline at end of file +if __name__ == "__main__" : + compute_fasta_length( sys.argv[1], sys.argv[2], sys.argv[3], True ) \ No newline at end of file diff --git a/tools/fasta_tools/fasta_compute_length.py b/tools/fasta_tools/fasta_compute_length.py index 57a257bb7df..5080bd3ca26 100644 --- a/tools/fasta_tools/fasta_compute_length.py +++ b/tools/fasta_tools/fasta_compute_length.py @@ -6,4 +6,4 @@ Uses fasta_to_len converter code. import sys from galaxy.datatypes.converters.fasta_to_len import compute_fasta_length -compute_fasta_length( sys.argv[1], sys.argv[2], sys.argv[3]) \ No newline at end of file +compute_fasta_length( sys.argv[1], sys.argv[2], sys.argv[3], False ) \ No newline at end of file