CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
How to delete certain lines from a file in perl

 



perlchaser
Novice

Aug 31, 2012, 9:04 AM

Post #1 of 2 (939 views)
How to delete certain lines from a file in perl Can't Post

I have a file like the following (I am showing the first several dozens of lines here):
----------------------------

>91ES8_RN Satellite Rattus
gaattctgttcgttccaagcgggaaaagcttgtaggaagttgactttgaagataaacacacagctagtgttttgcaaagtgaattgctgttacttggcnaataagcttagttttaagtggttctagakggtaaaaagcatacttttctatatagacaaaacatgcgtttcccagtctgaatcncacattctttggc
>ALSAT_RN SAT Rattus norvegicus
agctttgcagttttatgagatcccatttgtcgattcttgatcttagagcataagccattggtgttttgttcaggaaattttttccagtgcccatgtgttccagatgcttccctagtttttcttctattagtttgagtgtgtctggtttgatgtggaggtccttgatccacttggacttaagct
>B1_Rn SINE1/7SL Rattus
agccgggcggtggtggcgcacgcctttaatcccagcactcgggaggcagaggcaggcggatctctgagttcgaggccagcctggtctacagagtgagttccaggacagccagggctacacagagaaaccctgtctcgaaaaaacaaaa
>B2_Rat1 SINE2/tRNA Rattus
ggggctggagagatggctcagcggttaagagcaccgactgctcttccagaggtcctgagttcaattcccagcaaccacatggtggctcacaaccatctgtaatgggatctgatgccctcttctggtgtgtctgaagacagctacagtgtactcatatataataaataaataaatctttaaaaaaaaaa
>B2_Rat2 SINE2/tRNA Rattus
ggggctggagagatggctcagtggttaagagcactgactgctcttccagaggtcctgagttcaaatcccagcaaccacatggtggctcacaaccatctgtaatgagatctgatgccctcttctggtgtgtctgaagacagctacagtgtacttatatataataaataaataaatctttaaaaaaaaaa
>B2_Rat3 SINE2/tRNA Rattus
ggggctggagagatggctcagcggttaagagcactgactgctcttccagaggtcctgagttcaattcccagcaaccacatggtggctcacaaccatctgtaatgggatccgatgccctcttctggtgtgtctgaagacagcgacagtgtactcatataaaataaataaataaatctttaaaaaaaaaa
>B2_Rat4 SINE2/tRNA Rattus
ggggctggagagatggctcagcggttaagagcactgactgctcttccagaggtcctgagttcaattcccagcaaccacatggtggctcacaaccatctgtaatgggatccgatgccctcttctggtgtgtctgaagacagctacagtgtactcacatacataaaataaataaatctttaaaaaaaaaa
----------------------------------------
The 'name' right after the '>' sign is sort of my IDs. I have an array which have some IDs in it:
@names = ('B2_Rat4', 'B2_Rat1');

What I am trying to do is: I want check if the 'ID' in my file is among the IDs in the '@names' array. If yes, then I want to delete these IDs as well as all the information associated with the IDs from the file (the information after the 'ID', and the several lines of sequences below it). Which is the efficient way to do it?

Thank you very much!

Jackie


Laurent_R
Veteran / Moderator

Aug 31, 2012, 10:40 AM

Post #2 of 2 (936 views)
Re: [perlchaser] How to delete certain lines from a file in perl [In reply to] Can't Post

If the size of your data is not too large, you could use a grep to find out whether your name is in the array.

If you have really a lot of names, you'll probably want to copy the array in a a hash (the names in the array being the keys of the hash) and then check for each name whether it is found in the hash.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives