Home > Archive > PERL Beginners > June 2007 > Problem with PERL Function
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Problem with PERL Function
|
|
| Michaelzhao 2007-06-26, 9:59 pm |
| Hey,
I am making a program to tally up the nucleic acid bases of E. Coli.
This data will be used in bioinformatics research to generate a
Markov
Matrix.
However, I am just beginning PERL and ran into a slight problem.
Basically, I need the frequencies of the 4 bases, Adenosine (A),
Thymine (T), Cytosine (C), and Guanine (G). I made a PERL script to
tally up the total counts of the bases. In my case, there are 6254
Adenosine, 4957 Thymine, 4245 Cytosine, and 3534 Guanine.
In order to find the frequencies, all I would do is divide each base
count by the total.
However, here is my problem. Instead of doing it globally. I need to
be able to specify an arbitrary start and stop position to start
tallying the occurences of the bases and also to find the frequencies
of the bases in that particularly defined area.
Herein lies my problem. I have not a clue how to go about doing this
task. I've been looking online for a solution but haven't really
found
one. If anyone can suggest an idea or function(s) I could use to go
about doing this task. I would be much obliged. Thanks!
~Michael
| |
| Tom Phoenix 2007-06-26, 9:59 pm |
| On 6/26/07, michaelzhao <mzhao1@gmail.com> wrote:
> I need to
> be able to specify an arbitrary start and stop position to start
> tallying the occurences of the bases and also to find the frequencies
> of the bases in that particularly defined area.
If your data is in the form of a string, it's simple to use the
substr() function to operate on just part of that string. Is that what
you need?
my $data = 'GATTACA' x 5;
my $start = 5;
my $end = 25;
my $length = $end - $start;
my $g_count = substr($data, $start, $length) =~ tr/G//;;
print "There were $g_count Gs in that range.\n"
Good luck with it!
--Tom Phoenix
Stonehenge Perl Training
|
|
|
|
|