On one file (data.txt) I have a list like the following:
Contig25381
Contig25396
Contig25469
On another file (all.txt) I have a list of sequences like:
>R.fna.Contig25353
AAGCAGTGGTATCAACGCAGTAGTTGGTTCCATTACGGCCGGGCTCTGTT
TCAGAATTTTAGATCCACCATCCGAGTTATTGAAACGCCAAGACCATAGA
>R.fna.Contig25381
GGACGAGATTTAACGACATCCATAAGCAACTCTGCTAATCATTCGATCTG
CTTGGAGGTGTTTTTCCCCCATTTCCCTTAACCATGTCTCAGACTGTGGT
>R.fna.Contig25396
GGGATCTTTGGACGAAGGGGGGAAAAAGATGTCAACTTTAAGCATTCCAC
CAATGCTTACTTCCCCTAGAGATGATGCCATTCAACTGTACAAGGCTTTC
AAGGGATTTGGATGTGACACTTCTGCAGTAATCCATATCTTAGCTCGTCG
>R.fna.Contig25356
GGGAAGCAACCTGCCCTTCTCAGGCTTGCTCTAGATGATGTGCTTGAGGT
GCCTTGATTAGTAGAGGTAGAAGAAGCAGAACAAAGGATTCACCTCGTTT
>R.fna.Contig25469
GGCTCTCTACCTATCTGTCTCTCTCTACCTCTCTCTCCTTTCACGCACAC
>R.fna.Contig25358
GGGAAGACGACGTCGTCACAACAAACCTCTCTTGAGGTTGGCAGCTTCCG
I would like to extract the sequences from the second file that would have the number listed in the first file.
I tried to write all the lines in the first file into $line and then write sequences in the second file with elements seperated by ">". Then I tried to use grep and $line to get the matching elements from the second file. This approach only gives me the last match.
How can I get the full matched list? Each match on the list should have the line starting with '>' and then the full sequence until the line starting with the next '>'. Any tips would be appreciated. Thanks.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.