This is my code for project 5. It is not completed yet. Can you please tell me if i'm going right or wrong? Is there anything thats need to be modified?
#!/usr/bin/perl
# kmeranalysis.pl
use strict; use warnings;
die "usage: kmeranalysis.pl <file name> <k>\n" unless @ARGV == 2;
my $sequences=$ARGV[0];
my $k=$ARGV[1];
my %count1 = ()
my %count2 = ()
my $total1 = 0;
my $total2 = 0;
open(IN, "<$ARGV[0]") or die "error reading $ARGV[0] for reading";
while (<IN>)
{
chomp;
$key1 = $1 if /^(>\S+i1\S+)/;
$sequences1{$key1} = $_;
for (my $i = 0; $i < length($sequences1{$key1}); $i ++)
{
my $kmer = substr($sequences1{$key1}, $i, $k);
if (exists $count1{$kmer}) {$count1{$kmer}++}
else {$count1{$kmer} = 1}
$total1++;
}
foreach my $kmer (sort keys %count1) {
my $frequency = $count1{$kmer}/$total1;
printf "%s\t%d\t%.4f\n", $kmer, $count1{$kmer}, $frequency;
}}
close IN;
I've modified the code a bit. It is ruuning but there is some problem. It also reads the header line with the sequence and gives result. how i can get the fasta file in only a line . can you please give me a sample code just for the beginning.this project seems to me quite hard.If you can please give a sample code of how to count kmers in intron1 i will understand the procedure. I am at a loss and i need help. please.
Use of uninitialized value $kmer in hash element at project5_kmer.pl line 69.
Use of uninitialized value $kmer in hash element at project5_kmer.pl line 69.
Use of uninitialized value in division (/) at project5_kmer.pl line 69.
Use of uninitialized value in division (/) at project5_kmer.pl line 69.
Illegal division by zero at project5_kmer.pl line 69.
Any hints or suggestions would be greatly appreciated. My code is: