Extract Sequence From Fasta File Using Ids From a separate txt File in linux
2
0
Entering edit mode
6.1 years ago

Hi everyone,

I have two files a fasta file and a txt file containing a list of sequence ID.

I would like to exclude the list of sequence ID ( text file) from fasta file. I have tried this command :

seqtk subseq input.fasta list_ids.txt > output.fasta

But it gives me an output with a fasta file containing only the list ofID sequences . I want a output ( fasta) without the sequence ID. if you could explain any answers in detail, I would be highly grateful

rna-seq • 6.5k views
ADD COMMENT
3
Entering edit mode

This question has been asked a gazillon times on biostars.org . What did you find so far ?

ADD REPLY
0
Entering edit mode

Pierre, i saw similiar questions.. but most of them are about a " different output".. i want a output without the list of ID... I saw a command line in seqtk, pyton, and someothers, but none of them worked for what i want. do u have another alternative ?

ADD REPLY
1
Entering edit mode

Using seqtk and unix tools:

grep ">" input.fasta | tr -d ">" | grep -v -w -f list_ids.txt > list_ids_2.txt
seqtk subseq input.fasta list_ids_2.txt > output.fasta

Or in one line:

seqtk subseq input.fasta $(grep ">" input.fasta | tr -d ">" | grep -v -w -f list_ids.txt) > output.fasta

ADD REPLY
1
Entering edit mode
6.1 years ago
GenoMax 141k

faSomeRecords from Kent Utilities is the one you want. Linux version linked here, macOS available.

faSomeRecords in.fa listFile out.fa
options:
   -exclude - output sequences not in the list file.
ADD COMMENT
0
Entering edit mode
6.1 years ago
Joe 21k

As others have said, this has been asked many many times, but this script will also do what you want if you invoke it with --invert.

ADD COMMENT

Login before adding your answer.

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