Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

calculate and plot the percentage....

Posted on 2009-03-30
15
Medium Priority
?
706 Views
Last Modified: 2013-11-24
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
Comment
Question by:shragi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
  • 2
15 Comments
 
LVL 84

Expert Comment

by:ozo
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

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

Author Comment

by:shragi
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
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 
LVL 39

Expert Comment

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

Author Comment

by:shragi
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

by:Adam314
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);

Open in new window

0
 

Author Comment

by:shragi
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 84

Expert Comment

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

Expert Comment

by:Adam314
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 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
 

Author Comment

by:shragi
ID: 24056570
how to use web server and what to write in it...
0
 
LVL 39

Expert Comment

by:Adam314
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:
    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
 

Author Comment

by:shragi
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>
<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
 
LVL 39

Expert Comment

by:Adam314
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

by:shragi
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;
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
 
LVL 39

Accepted Solution

by:
Adam314 earned 2000 total points
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This video teaches viewers about errors in exception handling.
Suggested Courses

671 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question