[Bioperl-guts-l] [14474] bioperl-network/trunk/Bio/Network: Add get and set methods, add verbosity
Brian Osborne
bosborne at dev.open-bio.org
Mon Feb 4 13:47:04 EST 2008
Revision: 14474
Author: bosborne
Date: 2008-02-04 13:47:04 -0500 (Mon, 04 Feb 2008)
Log Message:
-----------
Add get and set methods, add verbosity
Modified Paths:
--------------
bioperl-network/trunk/Bio/Network/IO/dip_tab.pm
bioperl-network/trunk/Bio/Network/IO/psi25.pm
bioperl-network/trunk/Bio/Network/IO.pm
bioperl-network/trunk/Bio/Network/ProteinNet.pm
Modified: bioperl-network/trunk/Bio/Network/IO/dip_tab.pm
===================================================================
--- bioperl-network/trunk/Bio/Network/IO/dip_tab.pm 2008-02-04 18:46:33 UTC (rev 14473)
+++ bioperl-network/trunk/Bio/Network/IO/dip_tab.pm 2008-02-04 18:47:04 UTC (rev 14474)
@@ -131,8 +131,8 @@
# ($node_id1,$node_id2) = $self->_fix_id("DIP",$node_id1,$node_id2);
## skip if score is below threshold
- if (defined($self->{'_th'}) && defined($score)) {
- next unless $score >= $self->{'_th'};
+ if ($self->threshold && defined($score)) {
+ next unless $score >= $self->threshold;
}
## build node object if it's a new node, use DIP id
Modified: bioperl-network/trunk/Bio/Network/IO/psi25.pm
===================================================================
--- bioperl-network/trunk/Bio/Network/IO/psi25.pm 2008-02-04 18:46:33 UTC (rev 14473)
+++ bioperl-network/trunk/Bio/Network/IO/psi25.pm 2008-02-04 18:47:04 UTC (rev 14474)
@@ -248,10 +248,10 @@
use Bio::Annotation::Collection;
use Bio::Annotation::Comment;
use Bio::Annotation::Reference;
-use Bio::Annotation::SimpleValue;
+# use Bio::Annotation::SimpleValue;
# use Bio::Network::IO::psi::intact;
-use vars qw( @ISA %species $net $fac );
+use vars qw( @ISA %species $net $fac $verbose );
@ISA = qw(Bio::Network::IO Bio::Root::Root );
BEGIN {
@@ -271,7 +271,7 @@
sub next_network {
my $self = shift;
$net = Bio::Network::ProteinNet->new(refvertexed => 1);
-
+ $verbose = $self->verbose;
# the tag in the handler is an XML field, the value is
# the function called when that field is encountered
my $t = XML::Twig->new(TwigHandlers => {
@@ -302,9 +302,9 @@
my $org = $pi->first_child('organism');
eval { $taxid = $org->att('ncbiTaxId'); };
- if ( $@ ){
+ if ($@) {
print "No organism for interactor " .
- $pi->first_child('names')->first_child('fullName')->text . "\n";
+ $pi->first_child('names')->first_child('fullName')->text . "\n" if $verbose;
$common = $full = $taxid = $nullVal;
} elsif ( !exists($species{$taxid}) ) {
# Make new species object if doesn't already exist
@@ -355,10 +355,10 @@
};
if ($@) {
print "No fullName for interactor " .
- $pi->first_child('names')->first_child('shortLabel')->text . "\n";
+ $pi->first_child('names')->first_child('shortLabel')->text . "\n" if $verbose;
$desc = $pi->first_child('names')->first_child('shortLabel')->text;
}
-
+
# Use ids other than accession_no or primary_id for DBLink annotations
my $ac = Bio::Annotation::Collection->new();
for my $db (keys %ids) {
@@ -385,7 +385,7 @@
my $node = Bio::Network::Node->new(-protein => [($prot)]);
$net->add_node($node);
- # Add primary identifier and accession to internal id<->node mapping hash
+ # Add primary identifier and acc to internal id <-> node mapping hash
$net->add_id_to_node($ids{'psixml'},$node);
$net->add_id_to_node($prot->primary_id,$node);
$net->add_id_to_node($prot->accession_number,$node);
@@ -405,14 +405,16 @@
Purpose : Adds a new Interaction to a graph
Usage : Do not call, called internally by next_network()
Returns :
- Notes : All interactions are made of 2 nodes
-
+ Notes : All interactions are made of 2 nodes - if there are more
+ or less than 2 then no Interaction object is created
=cut
sub _addInteraction {
my ($twig, $i) = @_;
my @ints = $i->first_child('participantList')->children;
+ print "Interaction " . $i->first_child('xref')->first_child('primaryRef')->att('id') .
+ " has " . scalar @ints . " interactors\n" if $verbose;
# 2 nodes are required
if ( scalar @ints == 2 ) {
Modified: bioperl-network/trunk/Bio/Network/IO.pm
===================================================================
--- bioperl-network/trunk/Bio/Network/IO.pm 2008-02-04 18:46:33 UTC (rev 14473)
+++ bioperl-network/trunk/Bio/Network/IO.pm 2008-02-04 18:47:04 UTC (rev 14474)
@@ -16,7 +16,7 @@
# Read protein interaction data in some format
my $io = Bio::Network::IO->new(-file => 'bovine.xml',
- -format => 'psi' );
+ -format => 'psi25' );
my $network = $io->next_network;
=head1 DESCRIPTION
@@ -45,7 +45,7 @@
=head1 REQUIREMENTS
-To read or write from PSI XML you will need the XML::Twig module,
+To read from PSI XML you will need the XML::Twig module,
available from CPAN.
=head1 FEEDBACK
@@ -100,6 +100,7 @@
-format => format
-threshold => a confidence score for the interaction, optional
-source => optional database name (e.g. "intact")
+ -verbose => optional, set to 1 to get commentary
=cut
sub new {
@@ -150,11 +151,40 @@
$self->throw("Sorry, you can't write from a generic Bio::NetworkIO object.");
}
+=head2 threshold
+ Name : get or set a threshold
+ Usage : $io->threshold($val)
+ Returns : The threshold
+ Args : A number or none
+
+=cut
+
+sub threshold {
+ my $self = shift;
+ $self->{_th} = @_ if @_;
+ return $self->{_th};
+}
+
+=head2 verbose
+
+ Name : get or set verbosity
+ Usage : $io->verbose(1)
+ Returns : The verbosity setting
+ Args : 1 or none
+
+=cut
+
+sub verbose {
+ my $self = shift;
+ $self->{_verbose} = @_ if @_;
+ return $self->{_verbose};
+}
+
=head2 _load_format_module
Title : _load_format_module
- Usage : *INTERNAL Bio::Network::IO stuff*
+ Usage : INTERNAL Bio::Network::IO stuff
Function: Loads up (like use) a module at run time on demand
Returns :
Args :
@@ -193,8 +223,9 @@
sub _initialize_io {
my ($self, @args) = @_;
$self->SUPER::_initialize_io(@args);
- my ($th) = $self->_rearrange( [qw(THRESHOLD)], @args);
+ my ($th,$verbose) = $self->_rearrange( [qw(THRESHOLD VERBOSE)], @args);
$self->{'_th'} = $th;
+ $self->{'_verbose'} = $verbose;
return $self;
}
Modified: bioperl-network/trunk/Bio/Network/ProteinNet.pm
===================================================================
--- bioperl-network/trunk/Bio/Network/ProteinNet.pm 2008-02-04 18:46:33 UTC (rev 14473)
+++ bioperl-network/trunk/Bio/Network/ProteinNet.pm 2008-02-04 18:47:04 UTC (rev 14474)
@@ -13,7 +13,7 @@
# Read in from file
my $graphio = Bio::Network::IO->new(-file => 'human.xml',
- -format => 'psi');
+ -format => 'psi25');
my $graph = $graphio->next_network();
my @edges = $gr->edges;
More information about the Bioperl-guts-l
mailing list