[Bio] / FigKernelPackages / FIGV.pm Repository:
ViewVC logotype

Diff of /FigKernelPackages/FIGV.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.12, Thu Nov 30 17:58:38 2006 UTC revision 1.13, Thu Nov 30 20:18:22 2006 UTC
# Line 26  Line 26 
26  use Tracer;  use Tracer;
27  use Data::Dumper;  use Data::Dumper;
28  use vars qw($AUTOLOAD);  use vars qw($AUTOLOAD);
29    use DB_File;
30    use FileHandle;
31    
32  sub new {  sub new {
33      my($class,$org_dir,$low_level) = @_;      my($class,$org_dir,$low_level) = @_;
# Line 1046  Line 1048 
1048      $self->{_functions} = $functions;      $self->{_functions} = $functions;
1049  }  }
1050    
1051  sub sims {  sub sims
1052    {
1053        my($self,$peg,$max,$maxP,$select) = @_;
1054    
1055        my $fig     = $self->{_fig};
1056        my $newG    = $self->{_genome};
1057        my $newGdir = $self->{_orgdir};
1058        my $max     = $max ? $max : 10000;
1059        my $maxP    = $maxP ? $maxP : 1.0e-5;
1060        $select     = $select ? $select : "all";
1061    
1062        if (not ($peg =~ /^fig\|(\d+\.\d+)/) && ($1 eq $newG))
1063        {
1064            return $fig->sims($peg,$max,$maxP,$select);
1065        }
1066    
1067        $self->load_sims_index();
1068        my $sims_file = "$newGdir/expanded_similarities";
1069    
1070        my $info = $self->{_sims_index}->{$peg};
1071    
1072        if ($info !~ /^(\d+),(\d+)$/)
1073        {
1074            return;
1075        }
1076        my($seek, $len) = ($1, $2);
1077    
1078        my $sims_txt = &FIG::read_block($self->{_sims_fh}, $seek, $len);
1079    
1080        my @sims = map { bless $_, 'Sim' } grep { $_->[10] <= $maxP } map { [split(/\t/)] } @$sims_txt;
1081    
1082        if ($select =~ /^figx?$/)
1083        {
1084            @sims = grep { $_->[1] =~ /^fig/ } @sims;
1085        }
1086    
1087        if (@sims > $max)
1088        {
1089            $#sims = $max-1;
1090        }
1091    
1092        return @sims;
1093    }
1094    
1095    
1096    sub sims_old {
1097      my($self,$peg,$max,$maxP,$select) = @_;      my($self,$peg,$max,$maxP,$select) = @_;
1098    
1099      my $fig     = $self->{_fig};      my $fig     = $self->{_fig};
# Line 1111  Line 1158 
1158      }      }
1159  }  }
1160    
1161    sub load_sims_index
1162    {
1163        my($self) = @_;
1164    
1165        return if defined($self->{_sims_index});
1166    
1167        my $fig     = $self->{_fig};
1168        my $newG    = $self->{_genome};
1169        my $newGdir = $self->{_orgdir};
1170    
1171        my $sims_file = "$newGdir/expanded_similarities";
1172        my $sims_index_file = "$sims_file.index";
1173        my $sims_index = {};
1174    
1175        my $tied = tie %$sims_index, 'DB_File', $sims_index_file, O_RDONLY, 0666, $DB_BTREE;
1176    
1177        #
1178        # Set these even if failed so we don't keep trying to open and failing.
1179        #
1180        $self->{_sims_index} = $sims_index;
1181        $self->{_sims_tie} = $tied;
1182    
1183        if (not $tied)
1184        {
1185            warn "Cannot tie sims index $sims_index_file: $!\n";
1186        }
1187    
1188        #
1189        # open the sims file as well.
1190        #
1191    
1192        $self->{_sims_fh} = new FileHandle("<$sims_file");
1193    
1194        if (!$self->{_sims_fh})
1195        {
1196            warn "Cannot open sims file $sims_file: $!\n";
1197        }
1198    }
1199    
1200  sub load_sims {  sub load_sims {
1201      my($self) = @_;      my($self) = @_;
1202    

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.13

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3