
orion
Novice
Jun 24, 2011, 10:22 AM
Post #12 of 15
(915 views)
|
|
Re: [orion] My First real script (help needed)
[In reply to]
|
Can't Post
|
|
i have come to a new problem now though something is clearly wrong with my sum loops the terminal output is: Use of uninitialized value in addition (+) at atract.pl line 98, <$fh> line 136. Use of uninitialized value in addition (+) at atract.pl line 106, <$fh> line 136. and like a million of those
#!/usr/bin/perl -w use Math::Trig; use strict; use warnings; ########set both start and end to 0 to scan full file########## my $start; $start = 0; # starts scanning at my $end; $end = 0; # ends scanning at my $bendmin; $bendmin = 45; # minimum bend my $Mtract; $Mtract = 99; # maximum number of a-tracts in a scan my $ecut; my @genome; my $genome; my $length; my $Wi;my $X;my $Y; #for math my @X;my @Y; my @X1; my @Y1; my @X2; my @Y2; my $pop; my $k;my $ysum;my $xsum; #opens input open(my $fh, "<", "input.gbk") or die "cannot open < test.gbk: $!"; #Depricated output #open(MYOUTFILE, ">test.out") or die "could not open test.out"; #print MYOUTFILE "Start:End:A-tract:Xi:Yi:Angle\n"; #imports file removes spaces and digits while (my $line = <$fh>) { if ($line =~ /[\d|\s]{8}\d\s\D{10}\s\D{10}\s\D{10}\s\D{10}/) { push (@genome, $line); } } $genome = "@genome"; $genome =~ s/\s|\d//g; #cuts the genome at the start and end points. $end -= 1; $start -= 1; my $size; $size = length($genome); $ecut = $size - $end; if ($ecut + $start < $size) { if ($end > 0) { $genome = reverse; $genome =~ s/\w{$ecut}//; $genome = reverse;} if ($start > 0) { $genome =~ s/\w{$start}//; } else { $start = 0 ;} } # searches $genome, does math, prints output. while ($genome =~ /(?i)a+t?|(?i)t+/g) { $length = $+[0] - $-[0]; if ( $length == 4 or $length == 5 or $length == 6 or $length == 7 ) { $Wi = ((($-[0] + $start) + ($+[0] + $start)) / 3.18309886); #10.5 period $Y = sin $Wi; $X = cos $Wi; if ( $length == 4 or $length == 7 ) { $X *= 0.261799388; $Y *= 0.261799388; } if ( $length == 5 or $length == 6 ) { $X *= 0.34906585; $Y *= 0.34906585; } $X = rad2deg($X); $Y = rad2deg($Y); push (@X, $X); push (@Y, $Y); } } #stores backups @X2 = @X; @Y2 = @Y; #sub add adds the a-tracts together untill they have reached the max number of a-tracts in a curve #it prints when the curve is larger then the bend min sub add { $pop = shift (@X); push(@X1, $pop); $pop = shift (@Y); push(@Y1, $pop); $k = 0; my $n; $n = 0; while ( $n + 1 < $Mtract ) { $pop = shift (@X); push(@X1, $pop); $xsum = 0; foreach (@X1) { $xsum += $_;} $xsum *= $xsum; $pop = shift (@Y); push(@Y1, $pop); $ysum = 0; foreach (@Y1) { $ysum += $_;} $ysum *= $ysum; $k = sqrt ($xsum + $ysum); $n += 1; if ( $k <= $bendmin ) { print "degrees: $k\n"; } } #this bit is so that if i run &add multiple times (which my end result will) it will advance shift(@X1); shift(@Y1); while ($n > 0) { $pop = pop(@X1); unshift (@X, $pop); $pop = pop(@Y1); unshift (@Y, $pop); $n -= 1; } } &add;
(This post was edited by orion on Jun 24, 2011, 10:31 AM)
|