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