LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-07-2012, 09:18 PM   #1
jv61
LQ Newbie
 
Registered: May 2012
Posts: 24

Rep: Reputation: Disabled
replace multiple patterns from a file


Hi all,

I have a fasta file that looks like this

Code:
>consensus_5353 
 ACTCGGAGGTCCGATCCAAAGTTTTTCTTTTCAGTGCCGAGTAGAGTTAC
>consensus_5354 
 GCCGGTGGTGGCGGAAGCTGGTGGTTGGCCGGCCGGGTCGAGTGGAGGTC
>consensus_5355 
 AGCAGGAGTCCCGCCGCCCTCGACCTCTCTTCTTCCGCCGCCGCCCGGTG
>consensus_5356 
 AATTAGTGGATTATTTGGTGAGGTGGATGTAGAGTGTAGACCGTATAATT
>consensus_5357 
 GCAATACTCAAATTGGAATAGGATGAGCAAGGAAGAGGAAAATGGTGGGG
>consensus_5358 
 TAAGATGTTCTGTTAGGGACTCAGAAGAACATCAGAATCACTACTTACGT
>consensus_5359 
 TGCTGGACTTGCTCTTAGCCTCCGATCGTCCCTATAGACTTTTGGCCTTT
>consensus_5360 
 ACGTGCCGCACGTGGGGTACAAAACCACCGCGGCGTAGGAGACGTCAAAA
>consensus_5361 
 TCGGCGGGGAGCAGCTAGTAACGCGCATTAACACGAGCAAATCCTAGAGA
I have another file with the list of patterns. My pattern list file looks like this

Code:
>consensus_5353
>consensus_5357
>consensus_5359 
>consensus_5361
What I want to do is to look for the patterns in my fasta file and delete those patterns and the next line of sequence corresponding to that pattern. Any thoughts how do I go about it with sed or awk or grep or perl?

I knew how to use sed to delete a single pattern but how to delete multiple patterns from a file instead of writing something like this

sed -e '/pattern/d' -e '/pattern/d' file

Thanks in advance.
 
Old 06-07-2012, 09:52 PM   #2
mreff555
Member
 
Registered: Sep 2011
Location: Philly
Distribution: Gentoo
Posts: 470

Rep: Reputation: Disabled
sed s/pattern//g input > output

Probably not the best way to do it but it works.
 
1 members found this post helpful.
Old 06-08-2012, 02:48 AM   #3
bsat
Member
 
Registered: Feb 2009
Posts: 347

Rep: Reputation: 72
Here is a script that might help.

Please note that I have used sed with "-i" so it will change your actual file. It is preferable you try this script on a backup file to make sure things don't go wrong.


Code:
 
#!/bin/bash
while read line
do 
sed -i "/$line/ N;s/$line.*//" fasta
done < pattern
 
1 members found this post helpful.
Old 06-08-2012, 05:49 AM   #4
jv61
LQ Newbie
 
Registered: May 2012
Posts: 24

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by bsat View Post
Here is a script that might help.

Please note that I have used sed with "-i" so it will change your actual file. It is preferable you try this script on a backup file to make sure things don't go wrong.


Code:
 
#!/bin/bash
while read line
do 
sed -i "/$line/ N;s/$line.*//" fasta
done < pattern
Many thanks for the replies. The above script solved my query.

Last edited by jv61; 06-08-2012 at 05:50 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Awk to Count Multiple patterns in a huge file reach.sree@gmail.com Programming 6 06-08-2012 02:04 PM
[SOLVED] grep many files in multiple directories using patterns from a file francy_casa Linux - Newbie 4 04-12-2012 09:49 AM
[SOLVED] Search multiple patterns & print matching patterns instead of whole line Trd300 Linux - Newbie 29 03-05-2012 08:41 PM
Replace patterns from linux files. ianeeshps Linux - Newbie 4 06-10-2009 05:15 AM
Find and replace text in multiple file Bad_Bob Linux - Software 9 05-08-2008 03:31 AM


All times are GMT -5. The time now is 08:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration