How to remove multiple fasta sequence from fasta file using gene id
2
0
Entering edit mode
7.1 years ago
Bioinfonext ▴ 460

I am looking a command or script by which I can remove multiple sequences from fasta file using gene ID.

RNA-Seq • 5.0k views
ADD COMMENT
1
Entering edit mode

Please add more information, concerning how your data looks like. I can only guess that the gene id is part of the fasta description or identifier.

In addition, if you show what you tried (and didn't work) people will be more eager to help you. Show some effort from your side too.

ADD REPLY
2
Entering edit mode
7.1 years ago

There is a very nice, fast and convenient program called faSomeRecords that can do what you are asking. In fact, can do two sorts of things by giving a list. Either extract those fasta file that are containing into a list file, or discard them It is working in the Linux environment, though

You just need to run faSomeRecords to get information about the options

 linux@ARFLinux:~$ faSomeRecords 
faSomeRecords - Extract multiple fa records
usage:
   faSomeRecords in.fa listFile out.fa
options:
   -exclude - output sequences not in the list file.
ADD COMMENT
1
Entering edit mode
7.1 years ago
Jake Warner ▴ 830

If you store the gene names in a variable you can loop and pull them out with awk:

id='gen1 gene2' ;
for gene in $id; 
do 
awk '/'$gene'/{flag=1;print $0;next}/^>/{flag=0}flag' file.fasta >> outfile.fasta ;
done

edit: For a list of genes in a file use:

id=$(cat genelist)

instead of the 'manual' id assignement above.

ADD COMMENT
2
Entering edit mode

Thank you for your solution and explanation, but I don't think we do OP a favour in the long run by always providing ready-to-use answers which will learn OP nothing in the end, especially if OP doesn't show some effort on trying to solve this without help.

ADD REPLY

Login before adding your answer.

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