Solved

# calculate and plot the percentage....

Posted on 2009-03-30
Medium Priority
712 Views
Consider a sequence below...

ATGCATGCCTTGCCGGCCTATA

The user should enter the window size ranges from  10 - 20000 in HTML

Suppose if the user has entered 10 and pressed the enter button ....

then GC% must be calculated ...

For 10 take first 10 alphabets in sequence...i.e., ATGCATGCCT Here it contains 2 G's and 3 C's
so total GC's is 5 i.e, 5/10 so GC% is 0.5
so values are
10   0.5

next step increase length by 1 ..i.e., now take position from 2 to 11 i.e., window size must be 10 at all time....  now the sequence to be considered is TGCATGCCTT
here GC's are 5/10 so GC% is still 0.5
so values are
11   0.5

similarly next time it is from 3 to 12 ... i.e., sequence is GCATGCCTTG ....
Here GC's are 6 out of total 10 i.e., 6/10 ...so GC% is 0.6
so values are
12   0.6

continue untill the end of sequence keeping the window size fixed......as entered by user....

finally I want to plot a graph with values

10   0.5
11   0.5
12   0.6
......
.....
22   0.545

The above values are for this sequence....

// user enters the window size in some HTML or PHP
// calculate GC% based on window size ... as mentioned above until the end of sequence...
// plot the values... as graph....LINE GRAPH...
0
Question by:shragi
• 7
• 6
• 2

LVL 85

Expert Comment

ID: 24026153
How do you get   22   0.545 ?

#!/usr/bin/perl
my \$windowsize=10;
\$\=\$/;
\$/=\(\$windowsize-1);
\$_=<DATA>;
my \$t=tr/GC//;
\$/=\1;
my @t=split//;
while( <DATA> ){
\$t += tr/GC//;
print \$.+\$windowsize-2,"\t",\$t/\$windowsize;
\$t -= (shift @t)=~tr/GC//;
push @t,\$_;
}
__DATA__
ATGCATGCCTTGCCGGCCTATA
0

Author Comment

ID: 24026731
oops that a mistake I cannot get 22 0.545....
0

Author Comment

ID: 24026790
hi ozo....I want to enter the window size from any HTML...and moreover the sequence is in files like input.txt... so code must read sequence from file input.txt   and u I think perl cannot be used for plotting ...can it be used...
0

LVL 39

Expert Comment

ID: 24030035
For creating the graph/plot, look at GD::Graph:
http://search.cpan.org/~bwarfield/GDGraph-1.44/Graph.pm
0

Author Comment

ID: 24033748
Ok can I get the code such that it takes sequence from an input file and calculates the GC% and return the values in the form
10       0.5
11       0.5
12       0.6
-----
------
22       --

into some output file

10 and 0.5 must be seperated by tab so that I will plot the graph .... using the values from the output file...
0

LVL 39

Expert Comment

ID: 24034226
Here is ozo's code, but modified to read from input.txt.
``````#!/usr/bin/perl
use warnings;
use strict;
use Data::Dumper;

my \$windowsize=10;
\$\=\$/;
\$/=\(\$windowsize-1);
open(my \$in, "<input.txt") or die "Could not open input: \$!\n";
\$_=<\$in>;
my \$t=tr/GC//;
\$/=\1;
my @t=split//;
while( <\$in> ){
\$t += tr/GC//;
print \$.+\$windowsize-2,"\t",\$t/\$windowsize;
\$t -= (shift @t)=~tr/GC//;
push @t,\$_;
}
close(\$in);
``````
0

Author Comment

ID: 24035831
I think there is mistake in the code.....

If I had given the below sequence
GGGAGATAATCTTGAATTTGGTTCAAAATGAA

The values can be
10    0.4
12    0.4
13    0.3
...
...
..
...
32    0.2

but ur code output has values with
33   0.2
34   0.1
35   0.1

and more over can the I get the output to a file...like output.txt..... instead of priting it on console.....

HOW CAN THE USER ENTER THE WINDOW SIZE AS 10....
HERE 10 IS DIRECTLY GIVEN INSIDE THE CODE,,,, IT IS NOT GIVEN BY USER.....
0

LVL 85

Expert Comment

ID: 24036491
there are probably extra characters at the end, perhaps newlines, which are neither C nor G
0

LVL 39

Expert Comment

ID: 24040903
A few more changes... output is to a file "output.txt" instead of the screen.  Note that if you run this through a web server, the web server user will need write access to create the output.txt file.  Change the path if necessary.

The window size comes from the "windowsize" parameter, though a web form.

``````#!/usr/bin/perl
use warnings;
use strict;
use Data::Dumper;
use CGI ':standard';
use CGI::Carp 'fatalsToBrowser';

print "All results saved to 'output.txt'\n";

my \$windowsize=param('windowsize');
\$\=\$/;
\$/=\(\$windowsize-1);
open(my \$in, "<input.txt") or die "Could not open input: \$!\n";
open(my \$out, ">output.txt") or die "Could not open output: \$!\n";
\$_=<\$in>;
my \$t=tr/GC//;
\$/=\1;
my @t=split//;
while( <\$in> ){
\$t += tr/GC//;
print \$out \$.+\$windowsize-2,"\t",\$t/\$windowsize;
\$t -= (shift @t)=~tr/GC//;
push @t,\$_;
}
close(\$in);
close(\$out);
``````
0

Author Comment

ID: 24056570
how to use web server and what to write in it...
0

LVL 39

Expert Comment

ID: 24060755
Do you have a webserver installed?  If not, you can use Apache.  It is free.
Next, you'll need to put the above script in your cgi-bin directory.
Next, you will call it using:

The results will be in the output.txt file.  You will need to specify the full path for the input and output files.  The webserver user will need write access to that directory.  So line 14 and 15 should be like so:
open(my \$in, "</path/to/input.txt") or die "Could not open input: \$!\n";
open(my \$out, ">/path/to/output.txt") or die "Could not open output: \$!\n";
0

Author Comment

ID: 24074907
I knew how to use servlets.... it requires...one XML and one HTML and one servlet....

I had written HTML form as below...

here in HTML I am able to call the remote servlet from form action... but how can I call this perl class...
moreover for servlets it requires one XML file .... to connect to server...what abut here...

plz clarify my doubt how to connect this html form to ur perl code...

so that i give input thru ..this Html form and see the output there..in html form..

``````<html>
<title> form </title>
<body>
<form action= "servlet1" method = "get">
<input type = "text" name="entervalue"><br>
<input type = "submit" value="submit">
</form>
</body>
</html>
``````
0

LVL 39

Expert Comment

ID: 24077766
Do you want to see the output, or have it go to a file?  If you want to see it, remove line 15 and 27 (the open and close of the file), and change line 22 from
print \$out ...
to
print ...
(eg: remove the \$out from the line)

Next, is your html being loaded through a web server, or just statically through a browser?  If it is through a web server, you have it work with the cgi by changing the action to "/cgi-bin/name-of-script.pl".  This will tell the browser to send the form info to that script.

If you are not using a web server, it will not work.  I'm not familiar with servlets.  The script is designed to be run from a webserver.
0

Author Comment

ID: 24080578
I had named the above code as gc.pl
and I installed tomcat server 6.0 and I started the server....

I placed the above code in bin folder of tomcat server....

but it's not working...

I had seen the below code in internet...is this type possible with my code..

``````#!/usr/bin/perl

use CGI;

my \$cgi = new CGI;

if (defined \$cgi->param('ok')) {
my %params = \$cgi->Vars;
print "My name is: \${params{realname}}<br>";
print "My email is: \${params{email}}<br>";
} else {
print <<ENDHTML;
<HTML>
<TITLE>CGI Test</TITLE>
<BODY>
<FORM METHOD=POST ACTION="mycgi.pl">
name: <INPUT TYPE=TEXT NAME="realname"><BR>
email: <INPUT TYPE=TEXT NAME="email"><BR>
<INPUT TYPE=SUBMIT NAME="ok">
</FORM>
</BODY>
</HTML>

ENDHTML
}
``````
0

LVL 39

Accepted Solution

ID: 24081301
Are any scripts working on your tomcat server?  Is the tomcat server working for static pages?

You could try the script you posted.  You will have to name it mycgi.pl.
0

## Featured Post

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.