annotate mutation_column_checker.py @ 3:dced6d52d218 draft

"planemo upload commit bdfa4424496371fbea3edd3de07d8be9d0bad432"
author rhpvorderman
date Mon, 15 Nov 2021 11:35:18 +0000
parents 64d74ba01a7c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
64d74ba01a7c "planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff changeset
1 import re
64d74ba01a7c "planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff changeset
2
64d74ba01a7c "planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff changeset
3 mutationMatcher = re.compile("^([nactg])(\d+).([nactg]),?[ ]?([A-Z])?(\d+)?[>]?([A-Z;])?(.*)?")
64d74ba01a7c "planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff changeset
4
64d74ba01a7c "planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff changeset
5 with open("7_V-REGION-mutation-and-AA-change-table.txt", 'r') as file_handle:
64d74ba01a7c "planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff changeset
6 first = True
64d74ba01a7c "planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff changeset
7 fr3_index = -1
64d74ba01a7c "planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff changeset
8 for i, line in enumerate(file_handle):
64d74ba01a7c "planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff changeset
9 line_split = line.split("\t")
64d74ba01a7c "planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff changeset
10 if first:
64d74ba01a7c "planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff changeset
11 fr3_index = line_split.index("FR3-IMGT")
64d74ba01a7c "planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff changeset
12 first = False
64d74ba01a7c "planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff changeset
13 continue
64d74ba01a7c "planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff changeset
14
64d74ba01a7c "planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff changeset
15 if len(line_split) < fr3_index:
64d74ba01a7c "planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff changeset
16 continue
64d74ba01a7c "planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff changeset
17
64d74ba01a7c "planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff changeset
18 fr3_data = line_split[fr3_index]
64d74ba01a7c "planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff changeset
19 if len(fr3_data) > 5:
64d74ba01a7c "planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff changeset
20 try:
64d74ba01a7c "planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff changeset
21 test = [mutationMatcher.match(x).groups() for x in fr3_data.split("|") if x]
64d74ba01a7c "planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff changeset
22 except:
64d74ba01a7c "planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff changeset
23 print((line_split[1]))
64d74ba01a7c "planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff changeset
24 print(("Something went wrong at line {line} with:".format(line=line_split[0])))
64d74ba01a7c "planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff changeset
25 #print([x for x in fr3_data.split("|") if not mutationMatcher.match(x)])
64d74ba01a7c "planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff changeset
26 if i % 100000 == 0:
64d74ba01a7c "planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
rhpvorderman
parents:
diff changeset
27 print(i)