I've got two genetic datasets which have matching chromosome position IDs. I want to count how many times file 1's chromosome position IDs appear in file 2.
For example my data looks like:
File 1 (chromosome position is actually my 125th column, implied by the ...
):
Gene pval ... Chromosome position ID
ACE 0.002 ... 01:3290834_CT_C_1
NOS 0.01 ... 03:3304593_GA_G_1
BRCA 0.004 . ... 06:6265733_GA_G_1
CYP3 0.34 ... 09:9433933_GA_G_1
File 2 (chromosome position is my first column):
Chromosome position ID Gene pval
01:1243933_GA_G_1 ACE 0.002
03:3304593_GA_G_1 NOS 0.01
06:6265733_GA_G_1 BRCA 0.004
09:9433933_GA_G_1 CYP3 0.34
I've found a lot of questions giving extraction of matching lines, and applied code based off those questions, but I just want to get the count of matching chromosome positions between 2 files.
Currently I'm using:
awk -F'|' 'NR==FNR{c[$125]++;next};c[$125]' file2.csv file1.txt > file3.txt
wc -l file1.txt
wc -l file3.txt
The line count for files 1 and 3 doesn't exactly match as I'm expecting (I expect all of file 1 to be in file 2) and to be sure what's going on I need to find a way to perform a count of matching rows in the chromosome position column. If I can find a way to code 'does all of file 1 chromosome positions match/appear in file 3?' that would be ideal, but even just a count works for now.
So the output would be a number counting how many times chromosome position column $125 in file 1 has matches also with file 2 chromosome position column $1.
I am using Linux.
-F'|'
? Your files don't even contain any|
, at least none that you show. What defined a field in these files?-F
is setting the field delimiter, so when you use-F'|'
, it is expecting data separated into fields by a|
, likefoo|bar|baz
. What separates the fields in your files? Is it tabs? Spaces? Something else?