-
Notifications
You must be signed in to change notification settings - Fork 21
/
methylate_reference.py
43 lines (36 loc) · 1.35 KB
/
methylate_reference.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
import sys
import argparse
from Bio import SeqIO
from Bio import Seq
from Bio.Seq import MutableSeq
description = """
Modify a reference genome to methylate positions according to the input recognition set
"""
parser = argparse.ArgumentParser(description=description, epilog='')
parser.add_argument('input', action='store', help='the input reference file')
parser.add_argument('--recognition', action='store', help='the recognition set')
args = parser.parse_args()
recognition_sites = list()
recognition_sites_methylated = list()
if args.recognition == "cpg":
recognition_sites = ["CG"]
recognition_sites_methylated = ["MG"]
elif args.recognition == "dam":
recognition_sites = ["GATC"]
recognition_sites_methylated = ["GMTC"]
elif args.recognition == "dcm":
recognition_sites = ["CCAGG", "CCTGG"]
recognition_sites_methylated = ["CMAGG", "CMTGG"]
else:
sys.stderr.write("unknown recognition: " + args.recognition)
sys.exit(1)
recognition_length = len(recognition_sites[0])
#
for rec in SeqIO.parse(args.input, "fasta"):
outseq = rec.seq.tomutable()
for bi in xrange(0, len(rec) - 1):
for s,m in zip(recognition_sites, recognition_sites_methylated):
if str(rec.seq[bi:bi + recognition_length]) == s:
outseq[bi:bi + recognition_length] = m
rec.seq = outseq
SeqIO.write(rec, sys.stdout, "fasta")