-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreplace_fasta.py
More file actions
30 lines (24 loc) · 998 Bytes
/
replace_fasta.py
File metadata and controls
30 lines (24 loc) · 998 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python
#proximate_snps.py
#Determines number of flanking snps within a specified window
#Determines closest SNP
from pyfaidx import Fasta
import sys
import re
import argparse
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-i', '--input', dest="input", required=True, help="Input FASTA file")
parser.add_argument('-p', '--positions', dest="positions", required=True, help="File with CHR and SNP positions")
parser.add_argument('-a', '--allele', type=str, dest="allele", required=True, help= "Letter used to replace positions")
args = parser.parse_args()
num_lines = sum(1 for line in open(args.positions))
print("Replacing fasta positions: "),
print(num_lines)
with open(args.positions) as mut_table:
with Fasta(args.input, mutable=True) as fasta:
for line in mut_table:
pos, base = line.rstrip().split()
base=(int(base)-1)
fasta[pos][base] = args.allele
print("Done")