LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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, 08: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, 08:52 PM   #2
mreff555
Member
 
Registered: Sep 2011
Location: Philly
Distribution: Gentoo
Posts: 473

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, 01: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, 04: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 04:50 AM.
 
  


Reply



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 01:04 PM
[SOLVED] grep many files in multiple directories using patterns from a file francy_casa Linux - Newbie 4 04-12-2012 08:49 AM
[SOLVED] Search multiple patterns & print matching patterns instead of whole line Trd300 Linux - Newbie 29 03-05-2012 07:41 PM
Replace patterns from linux files. ianeeshps Linux - Newbie 4 06-10-2009 04:15 AM
Find and replace text in multiple file Bad_Bob Linux - Software 9 05-08-2008 02:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:13 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
Open Source Consulting | Domain Registration