Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

perl-minimum & maximum value 1

Status
Not open for further replies.

bioman1

Programmer
Jul 19, 2012
2
US
input file
Xm_ABL1 Geneious extracted region 1 168 . + . Name=Extracted region from gi|371443098|gb|JH556762.1|;Extracted interval="3512970000000 -> 3514640000000"
Xm_ABL1 Geneious extracted region 169 334 . + . Name=Extracted region from gi|371443098|gb|JH556762.1|;Extracted interval="3717850000000 -> 3719500000000"

my part of perl code

if ($array[1] =~ /extracted region/){
die "No CDS record for $key!\n" unless $metadata->{$key};
(my $label = $array[7]) =~ s/.*region from (.*)\|;.*/$1/;
$label =~ s/\|/_/g;
$group->{$label} ||= { #seed summary if not exists
pos1 => 1e10,
pos2 => 0,
metadata => $metadata->{$key},
sequences => [],
};
(my $pos1, my $arr, my $pos2) = ($array[7]=~/.*interval=\"(\d+) (<?->?) (\d+)\"$/gm);
# capture hi/lo values for group
$group->{$label}->{pos1} = $pos1 if $pos1 < $group->{$label}->{pos1};
$group->{$label}->{pos2} = $pos2 if $pos2 > $group->{$label}->{pos2};
# push this sequence onto the group's array
push(@{ $group->{$label}->{sequences} }, [ $pos1, $pos2, $arrow->{$arr} ]);
}


In the code $pos1=3512970000000,3717850000000 & $pos2=3514640000000,3719500000000. My code prints new line finding minimum and maximum value (if $pos1 is less than 10,000), but if the value is greater than 10,0000 it gives error in printing minimum value of pos1. Any one help me in debug in finding minimum value of $pos1 and maximum value of $pos2

 
Hi,

In the code $pos1=3512970000000,3717850000000 & $pos2=3514640000000,3719500000000. My code prints new line finding minimum and maximum value (if $pos1 is less than 10,000), but if the value is greater than 10,0000 it gives error in printing minimum value of pos1. Any one help me in debug in finding minimum value of $pos1 and maximum value of $pos2

Your issue isn't entirely clear:
- Where are the values of 10000 and 100000 coming from. Even then, there is nothing in your code to cause issues around these specific values.
- Specifically, what is the "error in printing minimum value".

However, I believe the following could potentially be the issue you are describing; As you know, inevitably the condition "$pos1 < $group->{$label}->{pos1}" won't ever fall true if $group->{$label}->{pos1} initially has an undef value. As a method around this, if $group->{$label}->{pos1} is "false", you assign it the value of "1e10" or "10000000000". However, based on your example input data, all potential pos1 values are higher than "10000000000", therefore pos1 will remain at "10000000000". A better way around this would be to also assign pos1 if $group->{$label}->{pos1} if undefined and remove the initial assignment altogether:

Code:
L.6     [s]pos1 => 1e10,[/s]
L.13    [s]$group->{$label}->{pos1} = $pos1 if $pos1 < $group->{$label}->{pos1};[/s]

L.13    $group->{$label}->{pos1} = $pos1 if ((!defined $group->{$label}->{pos1}) || ($pos1 < $group->{$label}->{pos1}));

Although unaffected, you would probably use the same method for pos2.

Regards,

Chris
 
* A better way around this would be to also assign pos1 if $group->{$label}->{pos1} is undefined / remove the initial assignment altogether:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top