annotate mutation_column_checker.py @ 79:98e3fecedd2b draft

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