I have specific pattern at the beginning of each line. I want to delete that particular pattern not the complete line in python. My data looks like after retrieving from the actual file
>homo_seg-Val-abc-1-1
>homo_seg-Beg-cdf-2-1
>homo_seg-Try-gfh-3-2
>homo_seg-Fuss-cdh-3-1
Here I want to delete the ">homo_seg-" from the dataset and retains only following
Val-abc-1-1
Beg-cdf-2-1
Try-gfh-3-2
Fuss-cdh-3-1
I can do this in perl
$new =~s/homo_seg-//g;
My code is:
import sys
inFile = sys.argv[1]
with open(inFile) as fasta:
for line in fasta:
if line.startswith('>'):
header = line.split()
t = header[0]
import re # from below answer
regex = r">homo_seg-"
subst = ""
result = re.sub(regex, subst, t, 0, re.MULTILINE)
print(result)
This code just giving output of last line. I know its some minor error but not able to pick it up.