#!/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-dbs/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; } }