I have a file containing protein sequence information of 100 odd proteins. Each sequence starts with a header that looks like this:
>sp|Q9UDW1|QCR9_HUMAN Cytochrome b-c1 complex subunit 9 OS=Homo sapiens OX=9606 GN=UQCR10 PE=1 SV=3
I want to edit these header to look like this:
I have tried the following code:
import re with open ('WT.fasta', 'r+') as f: contents = f.readlines() for i in range(len(contents)-1): target = re.compile(r'>..\|(.*)\|.*', contents[i]) target.sub(r'\1', contents[i])
I think I am not being able to call the right methods to do this. I have been trying to read the documentation: https://docs.python.org/3/library/re.html. I am not been able to understand it and feeling overwhelmed by the details. I would really appreciate if anyone could help or point me in the right direction. Thanks!