How to rename first column of bedgraph file based on another reference table?
1
0
Entering edit mode
2.3 years ago
AA • 0

I have a bedgraph file that looks like this:

chr1    0   35  0
chr1    35  56  0.18636
chr3    56  73  0.37273
chr3    73  123 0.55909
chr4    123 142 0.37273
chr4    142 144 0.55909
chr5    144 161 0.37273

And I have another reference table in a tab delimited format that has alternative values for the first column:

chr1    scaffold_A
chr2    scaffold_B
chr3    scaffold_C
chr4    scaffold_D
chr5    scaffold_E

How can I take the values in the reference table to replace values in the first column of the bedgraph file so the final output is:

scaffold_A  0   35  0
scaffold_A  35  56  0.18636
scaffold_C  56  73  0.37273
scaffold_C  73  123 0.55909
scaffold_D  123 142 0.37273
scaffold_D  142 144 0.55909
scaffold_E  144 161 0.37273
ChIP-seq bedgraph • 660 views
ADD COMMENT
1
Entering edit mode
2.3 years ago

not tested, but it could be something like:

sed -f <(awk '{printf("s/^%s\t/%s\t/\n",$1,$2);}' file2.txt) file1.txt

or

join -t $'\t' -o '2.2,1.2,1.3,1.4' -1 1 -2 1 <(sort -t $'\t' -k1,1 file1.txt) <(sort -t $'\t' -k1,1 file2.txt)
ADD COMMENT

Login before adding your answer.

Traffic: 1916 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6