Mercurial > repos > galaxy-australia > alphafold2
annotate validate_fasta.py @ 7:eb085b3dbaf8 draft
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
author | galaxy-australia |
---|---|
date | Tue, 19 Apr 2022 00:39:29 +0000 |
parents | 04e95886cf24 |
children | ca90d17ff51b |
rev | line source |
---|---|
1
6c92e000d684
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
galaxy-australia
parents:
0
diff
changeset
|
1 """Validate input FASTA sequence.""" |
0
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
2 |
1
6c92e000d684
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
galaxy-australia
parents:
0
diff
changeset
|
3 import re |
6
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
4 import sys |
0
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
5 import argparse |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
6 from typing import List, TextIO |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
7 |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
8 |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
9 class Fasta: |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
10 def __init__(self, header_str: str, seq_str: str): |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
11 self.header = header_str |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
12 self.aa_seq = seq_str |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
13 |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
14 |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
15 class FastaLoader: |
1
6c92e000d684
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
galaxy-australia
parents:
0
diff
changeset
|
16 def __init__(self, fasta_path: str): |
6c92e000d684
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
galaxy-australia
parents:
0
diff
changeset
|
17 """Initialize from FASTA file.""" |
6c92e000d684
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
galaxy-australia
parents:
0
diff
changeset
|
18 self.fastas = [] |
6c92e000d684
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
galaxy-australia
parents:
0
diff
changeset
|
19 self.load(fasta_path) |
0
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
20 |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
21 def load(self, fasta_path: str): |
1
6c92e000d684
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
galaxy-australia
parents:
0
diff
changeset
|
22 """Load bare or FASTA formatted sequence.""" |
6c92e000d684
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
galaxy-australia
parents:
0
diff
changeset
|
23 with open(fasta_path, 'r') as f: |
6c92e000d684
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
galaxy-australia
parents:
0
diff
changeset
|
24 self.content = f.read() |
6c92e000d684
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
galaxy-australia
parents:
0
diff
changeset
|
25 |
6c92e000d684
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
galaxy-australia
parents:
0
diff
changeset
|
26 if "__cn__" in self.content: |
6c92e000d684
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
galaxy-australia
parents:
0
diff
changeset
|
27 # Pasted content with escaped characters |
6c92e000d684
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
galaxy-australia
parents:
0
diff
changeset
|
28 self.newline = '__cn__' |
6
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
29 self.read_caret = '__gt__' |
1
6c92e000d684
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
galaxy-australia
parents:
0
diff
changeset
|
30 else: |
6c92e000d684
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
galaxy-australia
parents:
0
diff
changeset
|
31 # Uploaded file with normal content |
6c92e000d684
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
galaxy-australia
parents:
0
diff
changeset
|
32 self.newline = '\n' |
6
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
33 self.read_caret = '>' |
1
6c92e000d684
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
galaxy-australia
parents:
0
diff
changeset
|
34 |
6c92e000d684
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
galaxy-australia
parents:
0
diff
changeset
|
35 self.lines = self.content.split(self.newline) |
6
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
36 |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
37 if not self.lines[0].startswith(self.read_caret): |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
38 # Fasta is headless, load as single sequence |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
39 self.update_fastas( |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
40 '', ''.join(self.lines) |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
41 ) |
1
6c92e000d684
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
galaxy-australia
parents:
0
diff
changeset
|
42 |
0
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
43 else: |
6
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
44 header = None |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
45 sequence = None |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
46 for line in self.lines: |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
47 if line.startswith(self.read_caret): |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
48 if header: |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
49 self.update_fastas(header, sequence) |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
50 header = '>' + self.strip_header(line) |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
51 sequence = '' |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
52 else: |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
53 sequence += line.strip('\n ') |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
54 self.update_fastas(header, sequence) |
1
6c92e000d684
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
galaxy-australia
parents:
0
diff
changeset
|
55 |
6c92e000d684
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
galaxy-australia
parents:
0
diff
changeset
|
56 def strip_header(self, line): |
6c92e000d684
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
galaxy-australia
parents:
0
diff
changeset
|
57 """Strip characters escaped with underscores from pasted text.""" |
6c92e000d684
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
galaxy-australia
parents:
0
diff
changeset
|
58 return re.sub(r'\_\_.{2}\_\_', '', line).strip('>') |
6c92e000d684
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
galaxy-australia
parents:
0
diff
changeset
|
59 |
0
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
60 def update_fastas(self, header: str, sequence: str): |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
61 # if we have a sequence |
1
6c92e000d684
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
galaxy-australia
parents:
0
diff
changeset
|
62 if sequence: |
0
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
63 # create generic header if not exists |
1
6c92e000d684
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
galaxy-australia
parents:
0
diff
changeset
|
64 if not header: |
0
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
65 fasta_count = len(self.fastas) |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
66 header = f'>sequence_{fasta_count}' |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
67 |
1
6c92e000d684
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
galaxy-australia
parents:
0
diff
changeset
|
68 # Create new Fasta |
0
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
69 self.fastas.append(Fasta(header, sequence)) |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
70 |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
71 |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
72 class FastaValidator: |
6
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
73 def __init__( |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
74 self, |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
75 fasta_list: List[Fasta], |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
76 min_length=None, |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
77 max_length=None): |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
78 self.min_length = min_length |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
79 self.max_length = max_length |
0
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
80 self.fasta_list = fasta_list |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
81 self.iupac_characters = { |
1
6c92e000d684
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
galaxy-australia
parents:
0
diff
changeset
|
82 'A', 'B', 'C', 'D', 'E', 'F', 'G', |
6c92e000d684
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
galaxy-australia
parents:
0
diff
changeset
|
83 'H', 'I', 'K', 'L', 'M', 'N', 'P', |
6c92e000d684
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
galaxy-australia
parents:
0
diff
changeset
|
84 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', |
0
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
85 'Y', 'Z', '-' |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
86 } |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
87 |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
88 def validate(self): |
7
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
89 """Perform FASTA validation.""" |
0
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
90 self.validate_num_seqs() |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
91 self.validate_length() |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
92 self.validate_alphabet() |
6
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
93 |
1
6c92e000d684
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
galaxy-australia
parents:
0
diff
changeset
|
94 # not checking for 'X' nucleotides at the moment. |
6c92e000d684
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
galaxy-australia
parents:
0
diff
changeset
|
95 # alphafold can throw an error if it doesn't like it. |
6
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
96 # self.validate_x() |
0
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
97 |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
98 def validate_num_seqs(self) -> None: |
6
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
99 """Assert that only one sequence has been provided.""" |
0
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
100 if len(self.fasta_list) > 1: |
7
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
101 raise ValueError( |
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
102 'Error encountered validating FASTA:\n' |
6
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
103 f' More than 1 sequence detected ({len(self.fasta_list)}).' |
7
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
104 ' Please use single FASTA sequence as input.') |
0
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
105 elif len(self.fasta_list) == 0: |
7
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
106 raise ValueError( |
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
107 'Error encountered validating FASTA:\n' |
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
108 ' input file has no FASTA sequences') |
0
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
109 |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
110 def validate_length(self): |
6
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
111 """Confirm whether sequence length is valid.""" |
0
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
112 fasta = self.fasta_list[0] |
6
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
113 if self.min_length: |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
114 if len(fasta.aa_seq) < self.min_length: |
7
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
115 raise ValueError( |
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
116 'Error encountered validating FASTA:\n Sequence too short' |
6
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
117 f' ({len(fasta.aa_seq)}AA).' |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
118 f' Minimum length is {self.min_length}AA.') |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
119 if self.max_length: |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
120 if len(fasta.aa_seq) > self.max_length: |
7
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
121 raise ValueError( |
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
122 'Error encountered validating FASTA:\n' |
6
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
123 f' Sequence too long ({len(fasta.aa_seq)}AA).' |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
124 f' Maximum length is {self.max_length}AA.') |
1
6c92e000d684
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
galaxy-australia
parents:
0
diff
changeset
|
125 |
0
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
126 def validate_alphabet(self): |
7
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
127 """Confirm whether the sequence conforms to IUPAC codes. |
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
128 |
6
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
129 If not, report the offending character and its position. |
1
6c92e000d684
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
galaxy-australia
parents:
0
diff
changeset
|
130 """ |
0
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
131 fasta = self.fasta_list[0] |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
132 for i, char in enumerate(fasta.aa_seq.upper()): |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
133 if char not in self.iupac_characters: |
7
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
134 raise ValueError( |
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
135 'Error encountered validating FASTA:\n Invalid amino acid' |
6
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
136 f' found at pos {i}: "{char}"') |
0
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
137 |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
138 def validate_x(self): |
6
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
139 """Check for X bases.""" |
0
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
140 fasta = self.fasta_list[0] |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
141 for i, char in enumerate(fasta.aa_seq.upper()): |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
142 if char == 'X': |
7
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
143 raise ValueError( |
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
144 'Error encountered validating FASTA:\n Unsupported AA code' |
6
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
145 f' "X" found at pos {i}') |
0
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
146 |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
147 |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
148 class FastaWriter: |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
149 def __init__(self) -> None: |
6
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
150 self.line_wrap = 60 |
0
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
151 |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
152 def write(self, fasta: Fasta): |
6
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
153 header = fasta.header |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
154 seq = self.format_sequence(fasta.aa_seq) |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
155 sys.stdout.write(header + '\n') |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
156 sys.stdout.write(seq) |
0
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
157 |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
158 def format_sequence(self, aa_seq: str): |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
159 formatted_seq = '' |
6
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
160 for i in range(0, len(aa_seq), self.line_wrap): |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
161 formatted_seq += aa_seq[i: i + self.line_wrap] + '\n' |
0
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
162 return formatted_seq |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
163 |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
164 |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
165 def main(): |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
166 # load fasta file |
7
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
167 try: |
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
168 args = parse_args() |
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
169 fas = FastaLoader(args.input) |
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
170 |
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
171 # validate |
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
172 fv = FastaValidator( |
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
173 fas.fastas, |
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
174 min_length=args.min_length, |
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
175 max_length=args.max_length, |
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
176 ) |
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
177 fv.validate() |
0
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
178 |
7
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
179 # write cleaned version |
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
180 fw = FastaWriter() |
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
181 fw.write(fas.fastas[0]) |
0
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
182 |
7
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
183 except ValueError as exc: |
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
184 sys.stderr.write(f"{exc}\n\n") |
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
185 raise exc |
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
186 |
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
187 except Exception as exc: |
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
188 sys.stderr.write( |
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
189 "Input error: FASTA input is invalid. Please check your input.\n\n" |
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
190 ) |
eb085b3dbaf8
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 8d9f0ae6af9e8d9313c6cdcc551b24c6c44ae341"
galaxy-australia
parents:
6
diff
changeset
|
191 raise exc |
0
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
192 |
1
6c92e000d684
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
galaxy-australia
parents:
0
diff
changeset
|
193 |
0
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
194 def parse_args() -> argparse.Namespace: |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
195 parser = argparse.ArgumentParser() |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
196 parser.add_argument( |
6
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
197 "input", |
1
6c92e000d684
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
galaxy-australia
parents:
0
diff
changeset
|
198 help="input fasta file", |
0
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
199 type=str |
1
6c92e000d684
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
galaxy-australia
parents:
0
diff
changeset
|
200 ) |
6
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
201 parser.add_argument( |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
202 "--min_length", |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
203 dest='min_length', |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
204 help="Minimum length of input protein sequence (AA)", |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
205 default=None, |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
206 type=int, |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
207 ) |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
208 parser.add_argument( |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
209 "--max_length", |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
210 dest='max_length', |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
211 help="Maximum length of input protein sequence (AA)", |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
212 default=None, |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
213 type=int, |
04e95886cf24
"planemo upload for repository https://github.com/usegalaxy-au/tools-au commit 724a7a389c878dded1c0332f3b6e507e0c4cd52a-dirty"
galaxy-australia
parents:
1
diff
changeset
|
214 ) |
0
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
215 return parser.parse_args() |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
216 |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
217 |
7ae9d78b06f5
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit 7b79778448363aa8c9b14604337e81009e461bd2-dirty"
galaxy-australia
parents:
diff
changeset
|
218 if __name__ == '__main__': |
1
6c92e000d684
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
galaxy-australia
parents:
0
diff
changeset
|
219 main() |