I am wondering is there way to find out how many pair values(start, end) before I create a new file.txt. My goal here is to check if I start, end value more than one pair then I want to create separate file for each pair. If not then just leave it as is.
def searchPFAM(fname):
with open(fname,'rb') as f:
root = etree.parse(f)
for lcn in root.xpath("/protein/match[@dbname='PFAM']/lcn"):#find dbname =PFAM
try:
start = int(lcn.get("start"))#if it is PFAM then look for start value
end = int(lcn.get("end"))#if it is PFAM then also look for end value
yield start, end
except (TypeError , ValueError) as e:
pass
with open('newfile.txt','w') as fileinput:
for start, end in searchPFAM(fname):
print start, end
if start <= end:
text=''.join(makeList[(start-1):(end-1)])
fileinput.write(text)
If you want a file for each pair you can do something like this:
Hope this will help.