This is a test version of Biostars. For the public version, visit https://www.biostars.org.
compare two gene lists

Hi All, Merry Christmas, I have two gene list, for example, file1

A
B
C
D

file2

B
C
D
E
F
G
H

I want to compare them which IDs is different and same? Thanks,

genome

I'm having a similar issue, albeit a more complex example, and have an ongoing question on Stack Overflow where grep -h -w -f file2 file1 should work but for unknown reasons is not working. I would appreciate it if someone could take a look at this and suggest a solution.

I think you forgot to include a link to SO.

Indeed I did facepalm, edited the post to include it now

join -j 1 file1 file2 seems to work for what you want (where the first column is the numbers in your example).

Sadly this does not work even on numerically sorted ASCII text files

$ more f2
10047140
100913206
10092617
10190704
10190704
103471987
103471997
103472005
103472005
105990514
110047138
110047139
45006951
45006986
45006986
45007007
45007007
4501883
4501887
94721250
94721261
9558733
9845516
98986457
98986457
98986464
99028871
9910242
9951915
9966805
9966827
9966867
9994185

$ more n1
1000004 XCC3444
110047138       LOC110047138
110047139       LOC110047139
110047140       LOC110047140
9951915         LOAG_14435
9951916         LOAG_14436
9951918         LOAG_14436
999998          ptr1
999999          gndA

$ join -j 1 f2 n1
110047138 LOC110047138
110047139 LOC110047139
9951915 LOAG_14435

Hello fufuyou!

We believe that this post does not fit the main topic of this site.

Not bioinformatics, simple unix

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!

3 answers

Common genes:

grep -h -w -f file2 file1

Genes in file1 not in file2:

grep -h -v -w -f file2 file1

Genes in file2 not in file1:

grep -h -v -w -f file1 file2

Thanks. It works well. But it is very slow.

$ more f1
A
B
C
D
F
G
$ more f2
B
C
D
E
F
J
K
L

The comm utility reads file1 and file2, which should be sorted lexically, and produces three text columns as output: lines only in file1; lines only in file2; and lines in both files.

$ comm <(sort f1) <(sort f2)
A
        B
        C
        D
    E
        F
G
    J
    K
    L

This is work well fast.

You can use http://bioinfogp.cnb.csic.es/tools/venny/

This can not handle lots of data. I tried it.

Log in to answer this question.