Hello,
I have file 1 with this kind of information: Name Definition for about 2,000 names --> I have created a dictionary with this file (name:definition)
I have file 2 with this kind of information: >Name \n Information about name for the same 2,000 names
The goal is to add the definition of file 1 to the correct name in file 2: >Name Definition \n Information
I generated the code below where it is supposed to verify if the name is the same as in the dictionary:
if line(name) in dict.keys() and it doesn't seem to work. I have printed separately line(name) and dict.keys() and they are the same list of characters,except for that when I print the dictionary it adds brackets as in ['name'].
(I also know that I make my code more complicated than it should be ... I need to learn how to generate functions!)
I have file 1 with this kind of information: Name Definition for about 2,000 names --> I have created a dictionary with this file (name:definition)
I have file 2 with this kind of information: >Name \n Information about name for the same 2,000 names
The goal is to add the definition of file 1 to the correct name in file 2: >Name Definition \n Information
I generated the code below where it is supposed to verify if the name is the same as in the dictionary:
if line(name) in dict.keys() and it doesn't seem to work. I have printed separately line(name) and dict.keys() and they are the same list of characters,except for that when I print the dictionary it adds brackets as in ['name'].
(I also know that I make my code more complicated than it should be ... I need to learn how to generate functions!)
file1= open('c:/python27/annotation.txt', 'r') dict={} file2= open('c:/python27/protein_file.faa', 'r') outfile=open('c:/python27/proteinandannotation.faa', 'w') for line in file1: name=line.strip().split() dict={name[0]:name[1:]} for line in file2: if line.startswith('>'): # line=line.strip if line[1:28] in dict.keys(): line=line.strip('\n') outfile.write(line + dict.values() + '\n') else: outfile.write(line)