annotate promer_substitutions.py @ 0:bca6b5cb87cd draft default tip

"planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
author nml
date Tue, 17 Dec 2019 15:55:27 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
1 #!/usr/bin/env python
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
2
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
3 import os
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
4 import subprocess
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
5 import sys
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
6
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
7 from Bio import SeqIO
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
8 from Bio.SeqIO import FastaIO
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
9
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
10 """
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
11 # =============================================================================
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
12 Copyright Government of Canada 2018
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
13 Written by: Eric Marinier, Public Health Agency of Canada,
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
14 National Microbiology Laboratory
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
15 Licensed under the Apache License, Version 2.0 (the "License"); you may not use
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
16 this file except in compliance with the License. You may obtain a copy of the
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
17 License at:
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
18 http://www.apache.org/licenses/LICENSE-2.0
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
19 Unless required by applicable law or agreed to in writing, software distributed
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
20 under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
21 CONDITIONS OF ANY KIND, either express or implied. See the License for the
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
22 specific language governing permissions and limitations under the License.
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
23 # =============================================================================
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
24 """
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
25
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
26 __version__ = '0.2.0'
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
27
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
28 FASTA_DIRECTORY = "fasta"
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
29
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
30 REF_START = 2
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
31 REF_END = 3
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
32
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
33 HEADER_ROW = "[P1]\t[SUB]\t[SUB]\t[P2]\t[BUFF]\t[DIST]\
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
34 \t[R]\t[Q]\t[FRM]\t[FRM]\t[TAG]\t[TAG]\n"
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
35
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
36
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
37 def reorient_file(fasta_location, start, end):
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
38
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
39 record = list(SeqIO.parse(fasta_location, "fasta"))[0]
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
40
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
41 # reversed
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
42 if start > end:
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
43 record.seq = record.seq[(end - 1):start].reverse_complement()
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
44
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
45 # same orientation
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
46 else:
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
47 record.seq = record.seq[(start - 1):end]
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
48
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
49 SeqIO.write(record, fasta_location, "fasta")
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
50
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
51
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
52 def promer(reference_location, query_location):
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
53
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
54 # promer
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
55 subprocess.check_output(
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
56 ['promer', reference_location, query_location],
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
57 universal_newlines=True)
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
58
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
59
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
60 # File locations from arguments:
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
61 reference_location = sys.argv[1]
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
62 query_location = sys.argv[2]
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
63
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
64 # Make directories:
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
65 if not os.path.exists(FASTA_DIRECTORY):
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
66 os.mkdir(FASTA_DIRECTORY)
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
67
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
68 # Read query FASTA:
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
69 query = list(SeqIO.parse(query_location, "fasta"))
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
70 fasta_locations = []
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
71
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
72 # Prepare final output:
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
73 snps_file = open("snps.tab", "w")
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
74 snps_file.write(HEADER_ROW)
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
75
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
76 # Split the query FASTA file into multiple files, each with one record:
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
77 # (This is done to work around a bug in promer.)
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
78 for record in query:
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
79
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
80 output_name = str(record.id) + ".fasta"
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
81 output_location = os.path.join(FASTA_DIRECTORY, output_name)
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
82
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
83 fasta_locations.append(output_location)
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
84 SeqIO.write(record, output_location, "fasta")
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
85
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
86 # Run promer on each (new) FASTA file:
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
87 for fasta_location in fasta_locations:
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
88
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
89 promer(reference_location, fasta_location)
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
90
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
91 # show-coords
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
92 output = subprocess.check_output(
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
93 ['show-coords', '-THrcl', 'out.delta'], universal_newlines=True)
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
94
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
95 if not output:
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
96 continue
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
97
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
98 ref_start = int(output.split()[REF_START])
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
99 ref_end = int(output.split()[REF_END])
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
100
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
101 reorient_file(fasta_location, ref_start, ref_end)
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
102 promer(reference_location, fasta_location)
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
103
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
104 # show snps
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
105 output = str(subprocess.check_output(
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
106 ['show-snps', '-T', '-q', 'out.delta'], universal_newlines=True))
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
107 output = output.split("\n")[4:]
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
108 output = "\n".join(output)
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
109
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
110 snps_file.write(output)
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
111
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
112 snps_file.close()
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
113
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
114 # Write all FASTA files into one output:
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
115 output_location = "contigs.fasta"
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
116 records = []
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
117
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
118 for fasta_location in fasta_locations:
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
119
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
120 record = list(SeqIO.parse(fasta_location, "fasta"))[0]
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
121 records.append(record)
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
122
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
123 contigs_file = open(output_location, 'w')
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
124 fasta_writer = FastaIO.FastaWriter(contigs_file, wrap=None)
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
125 fasta_writer.write_file(records)
bca6b5cb87cd "planemo upload for repository https://github.com/phac-nml/promer commit 09ae227a84e31c9c56f58815b1a0c8c0e0a7900e"
nml
parents:
diff changeset
126 contigs_file.close()