So I have file with about thousand line that look like this:
COADREAD ZNF271 Missense_Mutation TCGA-AA-3947 Q14591 A177T
COADREAD ZNF271 Missense_Mutation TCGA-AA-A00N Q14591 I26T
COADREAD ZNF271 Missense_Mutation TCGA-AG-A002 Q14591 M418T
I have code that look for 5th column for the id and grab the number between two letter.
Is there a way that I can also grab whole token after id in 5th column (or column 6th token).
I want to grab that token so I can write it on to another file.
Here is what I have so far( This code will give me number, but is there way to get both number to calculate and whole string of that token to print on to the output file):
For example, if I call lookup[Q14591] it give me [‘177′,’26’,418] but I also want A177T I26T and M418T
lookup = defaultdict(list)
mydata = open('summaryfile.txt')
for line in csv.reader(mydata, delimiter='\t'):
code = re.match('[a-z](\d+)[a-z]', line[-1], re.I)
if code:
lookup[line[-2]].append(code.group(1))
When using regular expressions,
group(0)should contain the whole matched string. So in your case:should contain the whole token. So if you modify your code to look like this:
Then you can access whole tokens like this:
or the sub-tokens like this: