Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 707
  • Last Modified:

calculate and plot the percentage....

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
shragi
Asked:
shragi
  • 7
  • 6
  • 2
1 Solution
 
ozoCommented:
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
 
shragiAuthor Commented:
oops that a mistake I cannot get 22 0.545....
0
 
shragiAuthor Commented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Adam314Commented:
For creating the graph/plot, look at GD::Graph:
    http://search.cpan.org/~bwarfield/GDGraph-1.44/Graph.pm
0
 
shragiAuthor Commented:
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
 
Adam314Commented:
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);

Open in new window

0
 
shragiAuthor Commented:
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
 
ozoCommented:
there are probably extra characters at the end, perhaps newlines, which are neither C nor G
0
 
Adam314Commented:
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 header();
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);

Open in new window

0
 
shragiAuthor Commented:
how to use web server and what to write in it...
0
 
Adam314Commented:
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:
    http://your.ip.address.here/cgi-bin/name-of-script.pl?windowsize=10

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
 
shragiAuthor Commented:
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>
<head>
   <title> form </title>
</head>
<body>
        <form action= "servlet1" method = "get">
        <input type = "text" name="entervalue"><br>
        <input type = "submit" value="submit">
        </form>
</body>
</html> 

Open in new window

0
 
Adam314Commented:
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
 
shragiAuthor Commented:
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;
print $cgi->header('text/html');
 
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>
<HEAD>
<TITLE>CGI Test</TITLE>
</HEAD>
<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
}

Open in new window

0
 
Adam314Commented:
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now