f = open("PRM2-61.fas") f1=open("61-qian.fas","a") f2=open("61-hou.fas","a") m=144 n=306 seq = {} for line in f: if line.startswith('>'): name=line.replace('>','').split()[0] seq[name]='' else: seq[name]+=line.replace('\n','').strip() f.close() #print(seq.keys()) species=seq.keys() #print(species) for ecsh_spe in species: line1=seq[ecsh_spe][0:m] line2=seq[ecsh_spe][m:n] #print(line1) f1.write('>'+ecsh_spe+"\n"+line1+"\n") #print(line2) f2.write('>'+ecsh_spe+"\n"+line2+"\n") f.close()