From 58bd714b241292bf82243e0cca463ffe96ebf58b Mon Sep 17 00:00:00 2001 From: fubar2 Date: Thu, 3 Oct 2024 11:30:54 +1000 Subject: [PATCH 1/4] Add required file for Pulsar deployments Bump to python3.12 from 3.7 --- tools/fasta_compute_length/fasta_compute_length.xml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/fasta_compute_length/fasta_compute_length.xml b/tools/fasta_compute_length/fasta_compute_length.xml index ca6a7243..26333166 100644 --- a/tools/fasta_compute_length/fasta_compute_length.xml +++ b/tools/fasta_compute_length/fasta_compute_length.xml @@ -1,8 +1,11 @@ - + - python + python + + + #if $ref.ref_source == 'dbkey': cp '${ref.index.fields.len_path}' '$output' From 635306a729feca8ee92911702f24ebbb5f510c4a Mon Sep 17 00:00:00 2001 From: fubar2 Date: Thu, 3 Oct 2024 11:43:02 +1000 Subject: [PATCH 2/4] fix flake complaint about missing new line add homepage_url to .shed.yml --- tools/fasta_compute_length/.shed.yml | 1 + tools/fasta_compute_length/fasta_compute_length.py | 1 + 2 files changed, 2 insertions(+) diff --git a/tools/fasta_compute_length/.shed.yml b/tools/fasta_compute_length/.shed.yml index 0b679384..43b850b3 100644 --- a/tools/fasta_compute_length/.shed.yml +++ b/tools/fasta_compute_length/.shed.yml @@ -9,4 +9,5 @@ long_description: | name: fasta_compute_length owner: devteam remote_repository_url: https://github.com/galaxyproject/tools-devteam/tree/master/tools/fasta_compute_length +homepage_url: https://github.com/galaxyproject/tools-devteam/tree/master/tools/fasta_compute_length type: unrestricted diff --git a/tools/fasta_compute_length/fasta_compute_length.py b/tools/fasta_compute_length/fasta_compute_length.py index 880c3699..46b822d2 100644 --- a/tools/fasta_compute_length/fasta_compute_length.py +++ b/tools/fasta_compute_length/fasta_compute_length.py @@ -4,6 +4,7 @@ """ import sys + from utils.fasta_to_len import compute_fasta_length From 7b525f615a33daabd5f96f9843bd088c1d3942dd Mon Sep 17 00:00:00 2001 From: Ross Lazarus Date: Thu, 3 Oct 2024 20:12:03 +1000 Subject: [PATCH 3/4] Update tools/fasta_compute_length/fasta_compute_length.xml Co-authored-by: Nicola Soranzo --- tools/fasta_compute_length/fasta_compute_length.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/fasta_compute_length/fasta_compute_length.xml b/tools/fasta_compute_length/fasta_compute_length.xml index 26333166..a54db09f 100644 --- a/tools/fasta_compute_length/fasta_compute_length.xml +++ b/tools/fasta_compute_length/fasta_compute_length.xml @@ -1,4 +1,4 @@ - + python From b5c102c0301d26d7750eae347a57e9d0bd669aa7 Mon Sep 17 00:00:00 2001 From: fubar2 Date: Thu, 3 Oct 2024 20:28:40 +1000 Subject: [PATCH 4/4] remove utils by consolidating into the single fasta_compute_length.py script to simplify Pulsar deployment --- .../fasta_compute_length.py | 42 +++++++++++++++-- tools/fasta_compute_length/utils/__init__.py | 0 .../utils/fasta_to_len.py | 47 ------------------- 3 files changed, 39 insertions(+), 50 deletions(-) delete mode 100644 tools/fasta_compute_length/utils/__init__.py delete mode 100644 tools/fasta_compute_length/utils/fasta_to_len.py diff --git a/tools/fasta_compute_length/fasta_compute_length.py b/tools/fasta_compute_length/fasta_compute_length.py index 46b822d2..3dc69d1d 100644 --- a/tools/fasta_compute_length/fasta_compute_length.py +++ b/tools/fasta_compute_length/fasta_compute_length.py @@ -1,11 +1,47 @@ #!/usr/bin/env python """ -Uses fasta_to_len converter code. +Input: fasta, int +Output: tabular +Return titles with lengths of corresponding seq """ import sys -from utils.fasta_to_len import compute_fasta_length +def compute_fasta_length(fasta_file, out_file, keep_first_char, keep_first_word=False): + keep_first_char = int(keep_first_char) + fasta_title = '' + seq_len = 0 -compute_fasta_length(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4] == 'id_only') + # number of char to keep in the title + if keep_first_char == 0: + keep_first_char = None + else: + keep_first_char += 1 + + first_entry = True + with open(fasta_file) as in_fh, open(out_file, 'w') as out_fh: + for line in in_fh: + line = line.strip() + if not line or line.startswith('#'): + continue + if line[0] == '>': + if first_entry is False: + if keep_first_word: + fasta_title = fasta_title.split()[0] + out_fh.write("%s\t%d\n" % (fasta_title[1:keep_first_char], seq_len)) + else: + first_entry = False + fasta_title = line + seq_len = 0 + else: + seq_len += len(line) + + # last fasta-entry + if keep_first_word: + fasta_title = fasta_title.split()[0] + out_fh.write("%s\t%d\n" % (fasta_title[1:keep_first_char], seq_len)) + + +if __name__ == "__main__": + compute_fasta_length(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4] == 'id_only') diff --git a/tools/fasta_compute_length/utils/__init__.py b/tools/fasta_compute_length/utils/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/tools/fasta_compute_length/utils/fasta_to_len.py b/tools/fasta_compute_length/utils/fasta_to_len.py deleted file mode 100644 index bb4c2f7c..00000000 --- a/tools/fasta_compute_length/utils/fasta_to_len.py +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env python -""" -Input: fasta, int -Output: tabular -Return titles with lengths of corresponding seq -""" - -import sys - - -def compute_fasta_length(fasta_file, out_file, keep_first_char, keep_first_word=False): - keep_first_char = int(keep_first_char) - fasta_title = '' - seq_len = 0 - - # number of char to keep in the title - if keep_first_char == 0: - keep_first_char = None - else: - keep_first_char += 1 - - first_entry = True - with open(fasta_file) as in_fh, open(out_file, 'w') as out_fh: - for line in in_fh: - line = line.strip() - if not line or line.startswith('#'): - continue - if line[0] == '>': - if first_entry is False: - if keep_first_word: - fasta_title = fasta_title.split()[0] - out_fh.write("%s\t%d\n" % (fasta_title[1:keep_first_char], seq_len)) - else: - first_entry = False - fasta_title = line - seq_len = 0 - else: - seq_len += len(line) - - # last fasta-entry - if keep_first_word: - fasta_title = fasta_title.split()[0] - out_fh.write("%s\t%d\n" % (fasta_title[1:keep_first_char], seq_len)) - - -if __name__ == "__main__": - compute_fasta_length(sys.argv[1], sys.argv[2], sys.argv[3], True)