Exacting lines containing Id from one file from ID from other file.
2
0
Entering edit mode
3.2 years ago

Hellow,

I want to extract the lines containing ID from my GFF file using ID fom other file.

My GFF file:

st00    PGSC0003DMC400069336    5046482 5046991
st00    PGSC0003DMC400069337    35003649    35012075
st00    PGSC0003DMC400069343    7843951 7845166
st00    PGSC0003DMC400069373    9133414 9134204
st00    PGSC0003DMC400069455    5268379 5270012
st1 PGSC0003DMC400000001    71267700    71268573
st1 PGSC0003DMC400000002    71267700    71269327
st1 PGSC0003DMC400000003    71268310    71268573
st1 PGSC0003DMC400000004    71271492    71272645

File containing IDs:

PGSC0003DMC400001685
PGSC0003DMC400001686
PGSC0003DMC400004210
PGSC0003DMC400004304
PGSC0003DMC400004305
PGSC0003DMC400004307
PGSC0003DMC400004308
PGSC0003DMC400004309
PGSC0003DMC400004310
PGSC0003DMC400005061
PGSC0003DMC400005062
PGSC0003DMC400005063

I have tried using various command:

ruby -pe 'File.open("blastid.txt").each { |i| puts i if i =~ /\$_/ }' uniqueCDS.txt > finaltry.txt

awk -F '\t' 'NR==FNR {id[$1]; next} $1 in id' blastid.txt uniqueCDS.txt

xargs -I {} grep "^{}" uniqueCDS.txt < blastid.txt

But nothing is working.

I need help

Thank you

Extracting line id • 717 views
ADD COMMENT
0
Entering edit mode

you want linux join. https://linux.die.net/man/1/join

ADD REPLY
0
Entering edit mode

This code is not working.

ADD REPLY
0
Entering edit mode

Unless you show us the code how can we tell you why it is not working.

ADD REPLY
0
Entering edit mode

https://meta.stackexchange.com/questions/147616/ What Do You Mean “It Doesn't Work”?

ADD REPLY
0
Entering edit mode

Sorry, I have tried join by using this command:

join -t$'\t' <(sort -d blastid.txt) <(sort -d -t$'\t' -k2,1 uniqueCDS.txt) > output.txt

but my output is:

join: /dev/fd/62:13435: is not sorted: st1 PGSC0003DMC400000001 71267700 71268573

ADD REPLY
5
Entering edit mode
3.2 years ago

try

join -t $'\t' -1 1 -2 2 <(sort -k1,1 blastid.txt) <(sort  -t $'\t' -k2,2 uniqueCDS.txt) > output.txt
ADD COMMENT
0
Entering edit mode

Thank you, It worked.

ADD REPLY
0
Entering edit mode

If an answer was helpful you should upvote it, if the answer resolved your question you should mark it as accepted.

Upvote|Bookmark|Accept

ADD REPLY
3
Entering edit mode
3.2 years ago
$ grep -wFf ids.txt annotations.gff > answer.txt
ADD COMMENT

Login before adding your answer.

Traffic: 2380 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