Hey guys,
I'm new with python so I'm really struggling in making a script.
So, what I need is to make a comparison between two files. One file contains all proteins of some data base, the other contain only some of the proteins presents in the other file, because it belongs to a organism. So I need to know which proteins of this data base is present in my organism. For that I want to build a output like a matrix, with 0 and 1 referring to every protein present in the data base that may or may not be in my organism.
Does anybody have any idea of how could I do that?
I'm thinking of something like this
f1 = open('file1.txt', 'r')
f2 = open('file2.txt', 'r')
FO = open('output.txt', 'w')
for line1 in file1:
for line2 in file2:
if line1 == line2:
FO.write("%d" %(1))
FO.close()
file1.close()
file2.close()
But there's a problem, that script will only add if the lines are totally equal and that will not work because I only need that one word (the protein) be the same.
Could anybody please help me?
Thanks so far.
0 answers
No answers yet.
Log in to answer this question.
Why don't you use the linux diff command
This command will only compares line by line and won't make a output with 0 and 1 which is what I need
Why don't you use the linux comm command ?
This command will only compares line by line and won't make a output with 0 and 1 which is what I need
Can you post a few lines of the database and your file?
comparing with
just an example
Can you use "in" instead of "==" (http://www.tutorialspoint.com/python/membership_operators_example.htm)?
Otherwise, you can use regular expression.
Can you show a few lines of each file and how you want the comparison done?
Hello naiannegri!
We believe that this post does not fit the main topic of this site.
not related to bioinformatics. Just basic python/linux, no bio-thing inside
For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.
If you disagree please tell us why in a reply below, we'll be happy to talk about it.
Cheers!
Actually I'm trying to make this script because I need a file like a matrix that tells me wich proteins are present in a proteome when comparing to all pfam database.
Hi Pierre,
I think you should make a decision whether to close the question or to answer it, but not both....
you're right: I moved my answer to a comment.