hi all , I have written a script to count the number of RNAs that have exact matches to the genome. the code works just fine. but the problem is I would like to improve the code make that work faster. the genome has 5 chromosomes. and they are all >= 3045655 (in length)
#!/usr/bin/perl -w use DBI; use strict; use Bio::SeqIO; use Bio::Perl; use GD::Graph::bars; $|=1; my $window_size = 500; my $step_size = 500; 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"); my $dsn = qq(DBI:mysql:database=$database; host=$host); $connect = DBI-> connect($dsn, $user, $pass,{printError =>1}) or die $ +DBI::errstr; #querying the database my $query = qq/select count(c.Rna_sequence_sequence) from Cloned_rna c, Hsp h where c.Rna_sequence_sequence=h.Rna_sequence_sequence and c.Project_idproject =72 and h.Sequence_db_idSequence_db =1133 and h.accession =? and h.hit_start >= ? and h.hit_end<=? group by h.accession/; my $sql = $connect->prepare($query); my %window_counts ; print RESULT "\"Chromosome\"\t\"start\"\t\"end\"\t\"counts\"\n" ; my $genome = Bio::SeqIO->new(-file=>'/home/shared-projects/sequence-db +s/TAIR7/TAIR7_nuclear_genome.fna', -format=>'fasta'); while (my $seq = $genome->next_seq()){ $length = $seq->length(); my $id =$seq->id(); warn "Processing on Chromosome $id\n"; #walking along the genome for(my $i=1;$i<=($length-$window_size); $i+=$step_size){ my $window_start = $i; my $window_end = $i+$window_size-1; my $sucess=($sql->execute($id, $window_start, $window_end)); die "query failed!\n $query \n" unless $sucess; my $window_id = "$id,$window_start" ; if (my @result = $sql->fetchrow_array() ) { ( $window_counts{$window_id})= @result; # has the counts as the + value of the hash warn "\$window_counts{$window_id}='$window_counts{$window_id}' +\n"; print RESULT "$id\t$window_start\t$window_end\t$window_counts{ +$window_id}\n" ; } # exit if $i > 50000; } }
is there any other way to do this??? thanks in advance.

In reply to how to improve this? by sirna

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.