Dear all,
Am trying to separate the data from a file into two different files based on the matching of either "GENEID" or "PROTID". Below is the input file.
input file:
>data_1 GENEID_8 1_exons 87028 - 87375 348 bp, chain -
ATGCCCAAATTAGTCAACATATTGATCACTACGGAGGAAATCTTGAAGAGTTCAAGGGGC
TGTCCATTTTACTTGAAGAGCCTAAAGATCAAAAAGGGTGATAATAAATCTTTAGAAGAT
ATGCTCATAATTGAATCTAACCTTACGATTTCTTCTACTTCTAATTGA
>data_1 PROTID_8 1_exons 87028 - 87375 115 aa, chain -
KLVNILITTEEILKSSRGIVLTVEQTSSIKRKFGWKKKKVKSAKKQKRESKPKKDGPK
AAEAKGKYFHYDADGHWRRNCPFYLKSLKIKKGDNKSLEDMLIIESNLTISSTSN
>data_2 GENEID_12 2_exons 121021 - 121590 486 bp, chain -
ATGTGGCACAACCGCCTAGGCCACATGGGTGACAAGGGGCTGAGGGAGTTGAGCAGGAGA
AGACACTTCTCAGTTAAGGGGACTCCACAGCAGAATGGGATGGCCGAGAGGATGAATAGA
ACACTTTTGGAAAAAGGCTCGATGCATGAGGCTGTAGGCAGAGCTTCCAAAGGCATTCTG
GGTTGA
>data_2 PROTID_12 2_exons 121021 - 121590 161 aa, chain -
LVHTDIYFMREKSEVFTKFKIWRAEVEKEQGRSVKCLRSDNGREYTSREFQDYCEECGIR
RHFSVKGTPQQNGMAERMNRTLLEKGSMHEAVGRASKGILG
program written so far:
#!/usr/bin/perl
open(OUT1,">GENEID.out")or die "can not create new file";
open(OUT2,">PROTID.out")or die "can not create new file";
open(FILE,"input.txt")or die "can not open file";
while ($line=<FILE>){
$hit1= $line=~ /^(>data_\d+\s+GENEID_\d+.*\n.*)/s;
print OUT1 "$hit1\n";
$hit2= $line=~ /^(>data_\d+\s+PROTID_\d+.*\n.*)/s;
print OUT2 "$hit2\n";
}
desired output:
file GENEID.out:
>data_1 GENEID_8 1_exons 87028 - 87375 348 bp, chain -
ATGCCCAAATTAGTCAACATATTGATCACTACGGAGGAAATCTTGAAGAGTTCAAGGGGC
TGTCCATTTTACTTGAAGAGCCTAAAGATCAAAAAGGGTGATAATAAATCTTTAGAAGAT
ATGCTCATAATTGAATCTAACCTTACGATTTCTTCTACTTCTAATTGA
>data_2 GENEID_12 2_exons 121021 - 121590 486 bp, chain -
ATGTGGCACAACCGCCTAGGCCACATGGGTGACAAGGGGCTGAGGGAGTTGAGCAGGAGA
AGACACTTCTCAGTTAAGGGGACTCCACAGCAGAATGGGATGGCCGAGAGGATGAATAGA
ACACTTTTGGAAAAAGGCTCGATGCATGAGGCTGTAGGCAGAGCTTCCAAAGGCATTCTG
GGTTGA
file PROTID.out
>data_1 PROTID_8 1_exons 87028 - 87375 115 aa, chain -
KLVNILITTEEILKSSRGIVLTVEQTSSIKRKFGWKKKKVKSAKKQKRESKPKKDGPK
AAEAKGKYFHYDADGHWRRNCPFYLKSLKIKKGDNKSLEDMLIIESNLTISSTSN
>data_2 PROTID_12 2_exons 121021 - 121590 161 aa, chain -
LVHTDIYFMREKSEVFTKFKIWRAEVEKEQGRSVKCLRSDNGREYTSREFQDYCEECGIR
RHFSVKGTPQQNGMAERMNRTLLEKGSMHEAVGRASKGILG
my results are giving only the headers(the line which starts with >) and not the alphabetic string. can any one please correct me in which line i am going wrong in my code? thank you.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|