Mercurial > repos > stephenshank > abayesqr
comparison parse_output.py @ 0:598c3e720567 draft default tip
planemo upload commit 4a2876135fca2f46ffa6451e463eb167a0b51b65
author | stephenshank |
---|---|
date | Thu, 21 Mar 2019 12:47:00 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:598c3e720567 |
---|---|
1 import os | |
2 | |
3 from Bio.Seq import Seq | |
4 from Bio.SeqRecord import SeqRecord | |
5 from Bio import SeqIO | |
6 | |
7 | |
8 def parse_abayesqr_output(input_text, output_fasta): | |
9 wd = os.path.join(os.getcwd()) | |
10 with open(os.path.join(wd, input_text)) as input_file: | |
11 lines = input_file.readlines() | |
12 records = [] | |
13 for i, line in enumerate(lines): | |
14 if i % 2 == 0: | |
15 freq = float(line.split()[-1]) | |
16 number = int(i/2)+1 | |
17 header = 'haplotype-%d_freq-%f' % (number, freq) | |
18 else: | |
19 seq = Seq(line.strip()) | |
20 record = SeqRecord(seq, id=header, description='') | |
21 records.append(record) | |
22 SeqIO.write(records, os.path.join(wd, output_fasta), 'fasta') | |
23 | |
24 | |
25 if __name__ == '__main__': | |
26 parse_abayesqr_output("test_ViralSeq.txt", "haplotypes.fasta") | |
27 |