Solved

calculate and plot the percentage....

Posted on 2009-03-30
15
696 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
  • 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
 
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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 500 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
changeXy challenge 13 57
Running Jira on Raspberry PI 2? 3 130
listing all functions in JavaScript 19 105
Java and GPO 11 47
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now