Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
GD::Graph

Posted by revtopo (revtopo), 16 October 2007
Hi

I am writing a script which requires plotting a graph..
my code is like this: #my @count = join('\s', $clone_count);
         #my @count_window = join('\s', $count_window);
         #print "@count";

         #my @data = (\@count, \@count_window);

         #my $graph = GD::Graph::bars->new(600, 600);
         #$graph->set(
              # x_label => 'Hit density',
              # y_label => 'Frequency',
              # title => 'Hits per window',
              # y_max_value => 500,
              # y_label_skip => 50,
             
              # ) or warn $graph->error;
       
        # my $graph_image = $graph ->plot(\@data) or die "cannot plot the graph\n";
         #open (GRAPH, ">graph.png") or die "cannot open the GRAPH file";  
         #binmode GRAPH;
         #print GRAPH $graph_image->png
I am not getting any errors instead, when i open the file it says its not a png file as saved instead a text file. and even if opened as a text file it hasn't got anything!! jus a empty file.
                   

Posted by KevinAD (KevinAD), 16 October 2007
hmmm... all the lines are commented out. Is that the way you run the code?

Posted by revtopo (revtopo), 17 October 2007
no

Posted by KevinAD (KevinAD), 17 October 2007
these lines don't make sense to me:

my @count = join('\s', $clone_count);
my @count_window = join('\s', $count_window);

the join() function returns a string from a list, not a list from a string like you have it above. Did you mean to use split() instead of join()?

my @count = split(/\s/, $clone_count);
my @count_window = split(/\s/, $count_window);

Posted by revtopo (revtopo), 18 October 2007
#!/usr/bin/perl -w
use DBI;
use strict;
use Bio::SeqIO;
use Bio:erl;
use GD::Graph::bars;
#The program used to get the hits that corresponds to the wild type Arabidopsis.


my $connect;
my $database = 'Cloned_RNA_2_dev';
my $user ='root';
my $pass = '';
my $host = 'localhost';
my %sequences;
my $total_length;
my $length;
#open(RESULT, ">result.csv") or die "cannot open the RESULT file";
#print "sequence, Count, Countwindow\n";
#print RESULT "Sequences, Clonecount, Windowcount\n";  

# On connecting to the database the query is prepared once and they are executed more than once until it gets al the required information from the database.
my $dsn = qq(DBI:mysql:database=$database; host=$host);
$connect = DBI-> connect($dsn, $user, $pass,{printError =>1}) or die $DBI::errstr;
my $query = (qq(select c.Rna_sequence_sequence, c.clone_name, h.hit_start, h.hit_end, h.query_strand, h.hit_strand, h.frac_identical, h.accession from Cloned_rna c, Hsp h where c.Rna_sequence_sequence=h.Rna_sequence_sequence and h.frac_identical=1 and h.Sequence_db_idSequence_db =1133 and h.hit_start>=? && h.hit_end <=? and h.accession =?  ));
my $sql = $connect->prepare($query);


my $genome = Bio::SeqIO->new(-file=>'/home/shared-projects/sequence-dbs/TAIR7/TAIR7_nuclear_genome.fna', -format=>'fasta');
while (my $seq = $genome->next_seq()){
   $length = $seq->length();
   my $gseq =$seq->seq();
   my $id =$seq->id();
   #print RESULT  "Chromosome: $id\n";
   my $window_size = 500;
   my $step_size = 500;
   for(my $i=1;$i<=($length-$window_size); $i+=$step_size){
     my $window_start = $i;
     my $window_end = $i+$window_size;
     my $sucess=($sql->execute($window_start, $window_end, $id));
     die "query failed!\n $query \n" unless $sucess;
     while (my( $Rna_sequence_sequence, $clone_name,  $query_strand, $hit_strand, $frac_identical, $accession,$hit_start, $hit_end)= $sql->fetchrow_array()){
        # print "$Rna_sequence_sequence, $clone_name,  $query_strand, $hit_strand, $frac_identical, $accession,$hit_start, $hit_end\n";
         $sequences{$Rna_sequence_sequence}{"$clone_name,  $query_strand, $hit_strand, $frac_identical, $accession,$hit_start, $hit_end"}=1;
         
     }
     my @clone_count;
     my @count_window;;
     foreach my $sequence(keys %sequences){
         #print "$sequence\n";
         my $clone_count = keys % {$sequences{$sequence}};
         my $count_window = int($window_start/$window_size)+1;
        # print RESULT  "$sequence, $clone_count, $count_window\n";
         @clone_count = sort $clone_count;
         @count_window = split (/\s/, $count_window);
         #print "@count_window\n";
         
     }
     
                 
     my @data = (\@clone_count, \@count_window);
          my $graph = GD::Graph::bars->new(600, 600);
         $graph->set(
               x_label => 'Hit density',
               y_label => 'Frequency',
                  title => 'Hits per window',
               y_max_value => 500,
               y_label_skip => 50,
             
               ) or warn $graph->error;
       
         my $graph_image = $graph ->plot(\@data) or die "cannot plot the graph\n";
         open (GRAPH, ">graph.png") or die "cannot open the GRAPH file";  
         binmode GRAPH;
         print GRAPH $graph_image->png
                   
         

           
   }
}
           
I have got two datas
1. clone_count and
2.count_window.

I have to plot the graoh for this is there any thing else that i have to do before starting with the GD::grph??

thanks


Posted by KevinAD (KevinAD), 18 October 2007
Sorry, I have no experience with GD::grph (or any of the GD modules).

Posted by KevinAD (KevinAD), 18 October 2007
one thing that does pop out:

foreach my $sequence(keys %sequences){
    #print "$sequence\n";
    my $clone_count = keys % {$sequences{$sequence}};
    my $count_window = int($window_start/$window_size)+1;
   # print RESULT  "$sequence, $clone_count, $count_window\n";
    @clone_count = sort $clone_count;
    @count_window = split (/\s/, $count_window);
    #print "@count_window\n";
   
}

@clone_count is just going to be one number, that number will be how many keys there are in the last hash (% {$sequences{$sequence}}) as you loop through %sequence. That is probably not what you want to do, but I don't know what it is you want to do. Likewise, @count_window may not be what you need to accomplish the task, for similar reasons.





This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho