Web Analytics Made Easy -
StatCounter Perl script - "$orthomclparser" requires explicit package name - CodingForum

Announcement

Collapse
No announcement yet.

Perl script - "$orthomclparser" requires explicit package name

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Perl script - "$orthomclparser" requires explicit package name

    Hello,

    Whenever I try to run this script, I get the following error on command line: "Can't call method "parse" on an undefined value at....". Also, my debugger keeps telling me that "$orthomclparser requires explicit package name". Any help would be appreciated as I am very new to Perl.

    Code:
    #!/usr/bin/perl 
    
    use OBO::Core::RelationshipType;
    use OBO::Core::Relationship;
    use OBO::Core::Term;
    use OBO::CCO::CCO_ID_Term_Map;
    use OBO::Core::Ontology;
    
    use strict;
    use warnings;
    use Carp;
    
     $OrthoMCLParser->parse();
     $OrthoMCLParser-> work();
    
    
    sub new {
        my $class = $_[0];
        my $self  = {};
    
        bless( $self, $class );
        return $self;
    }
    
    sub parse {
    	my $self = shift;
    	# get orthoMCL data file
    	my $omclDataFile = shift;	
    	open(my $FH, '<', $omclDataFile) || die "Cannot open file '$omclDataFile': $!";
    	
    	# parse orthoMCL output
    	my %clusters; # %clusters{protein_name}{taxon_label}
    	while(<$FH>){
    		my ($cluster, $proteins) = split /:\s+/xms;
    		my $cluster_num = $.-1;
    		$cluster = $cluster_num;
    		my @proteins = split /\s/xms, $proteins;
    		foreach ( @proteins) {
    			$_ =~/\A(\w+?)\((\w+?)\)/xms; # $1 is protein name, $2 is taxon label (e.g Hsa)
    			$clusters{$cluster}->{$1} =  $2;			
    		}
    	}		
    	close $FH;
    	return \%clusters;
    }
    
    sub work {
    	my ($self, $clust, $files,  $tax) = @_;
    	my %clusters = %{$clust};
    	my %taxa = %{$tax};
    	# input/output files
    	my ($new_OBO_file, $u_map_file, $t_map_file, $o_map_file, $b_map_file) = @{$files}; 
    	
    	# Initialize  maps (OBO::CCO::CCO_ID_Term_Map objects)
    	my $u_map = OBO::CCO::CCO_ID_Term_Map->new($u_map_file);  # map for Upper Level Ontology terms
    	my $t_map  = OBO::CCO::CCO_ID_Term_Map->new($t_map_file); # map for taxonomy terms
    	my $o_map  = OBO::CCO::CCO_ID_Term_Map->new($o_map_file); # map for orthologous groups terms
    	my $b_map  = OBO::CCO::CCO_ID_Term_Map->new($b_map_file); # map for biomolecule terms
    	# taxon specific maps for biolmolecule terms
    	foreach (keys %taxa) {
    		push @{$taxa{$_}}, OBO::CCO::CCO_ID_Term_Map->new($taxa{$_}->[1]);
    	}
    	# @{$taxa{taxon_label}} contains now taxon name, taxon specific map file, taxon specific map object
    	
    	my $ontology = OBO::Core::Ontology->new();
    	
    	# populate ontology
    	$ontology->add_relationship_type_as_string ('is_a',       'is_a');
    	$ontology->add_relationship_type_as_string ('has_source', 'has_source');
    	#$ontology->add_relationship_type_as_string ('source_of', 'source_of');
    	
    	my $protein = OBO::Core::Term->new();# upper level ontology term
    	$protein->name('protein');
    	$protein->id(assign_term_id($u_map, 'U', 'protein'));
    	if ($u_map->contains_value('protein')) {
    		$protein->id($u_map->get_cco_id_by_term('protein'));
    	}else{
    		$protein->id(assign_term_id($u_map, 'U', 'protein'));
    	}
    	$ontology->add_term($protein);
    	
    	foreach (keys %taxa) {
    		my $taxon = OBO::Core::Term->new();
    		my $taxon_lab = $_;
    		my $tax_name = $taxa{$taxon_lab}->[0];
    		$taxon->name($tax_name);
    		$taxon->id(assign_term_id($t_map, 'T', $tax_name));
    		$ontology->add_term($taxon);
    		push @{$taxa{$taxon_lab}}, $taxon;
    		#@{$taxa{$taxon_lab}} contains now taxon name, taxon specific map file, taxon specific map object, taxon term object
    	}
    	
    	foreach (keys %clusters) {
    		my $cluster = OBO::Core::Term->new();
    		my $clust_num = $_;
    		my $clust_name = "Type $_ protein";
    		$cluster->name($clust_name);
    		$cluster->id(assign_term_id($o_map, 'O', $clust_name));
    		$cluster->def_as_string("A protein belonging to the orthological type $_ produced by orthoMCL", "[CCO:vm]");
    		$ontology->create_rel($cluster, 'is_a', $protein);
    		foreach (keys %{$clusters{$clust_num}}) {   # for each protein in the cluster
    			my $prot_name = $_;
    			my $taxon_lab = $clusters{$clust_num}{$prot_name};
    			my $clust_protein = OBO::Core::Term->new();
    			$clust_protein->name($prot_name);
    			$clust_protein->id(assign_biomol_id($taxa{$taxon_lab}[2], $b_map, $prot_name));
    			my $short_map = $taxa{$taxon_lab}[2];
    			if ($short_map->contains_value($prot_name)) {
    				$clust_protein->id($short_map->get_cco_id_by_term($prot_name));
    			} else {
    				$clust_protein->id(assign_biomol_id($short_map, $b_map, $prot_name));
    			}
    			$ontology->add_term($clust_protein);
    			$ontology->create_rel($clust_protein, 'is_a', $cluster);
    			
    			$ontology->create_rel($clust_protein,         'has_source',   $taxa{$taxon_lab}->[3]);
    			#$ontology->create_rel($taxa{$taxon_lab}->[3], 'source_of',         $clust_protein);
    		}
    	}
    	
    	# Write the new ontology and maps to disk
    	open (my $FH, ">".$new_OBO_file) || die "Cannot write OBO file: ", $!;
    	$ontology->export(\*$FH);
    	close $FH;
    	foreach ((keys %taxa)) {
    		$taxa{$_}[2] -> write_map();
    	}
    	$b_map -> write_map();
    	$o_map -> write_map();
    	$t_map -> write_map();
    	$u_map -> write_map();
    	return $ontology;
    }
    Last edited by roro; Apr 13, 2009, 02:59 PM.

  • #2
    Originally posted by roro View Post
    Hello,

    Whenever I try to run this script, I get the following error on command line: "Can't call method "parse" on an undefined value at....". Also, my debugger keeps telling me that "$orthomclparser requires explicit package name". Any help would be appreciated as I am very new to Perl.

    Code:
    #!/usr/bin/perl 
    
    use OBO::Core::RelationshipType;
    use OBO::Core::Relationship;
    use OBO::Core::Term;
    use OBO::CCO::CCO_ID_Term_Map;
    use OBO::Core::Ontology;
    
    use strict;
    use warnings;
    use Carp;
    
     $OrthoMCLParser->parse();
     $OrthoMCLParser-> work();
    
    
    sub new {
        my $class = $_[0];
        my $self  = {};
    
        bless( $self, $class );
        return $self;
    }
    
    sub parse {
    	my $self = shift;
    	# get orthoMCL data file
    	my $omclDataFile = shift;	
    	open(my $FH, '<', $omclDataFile) || die "Cannot open file '$omclDataFile': $!";
    	
    	# parse orthoMCL output
    	my %clusters; # %clusters{protein_name}{taxon_label}
    	while(<$FH>){
    		my ($cluster, $proteins) = split /:\s+/xms;
    		my $cluster_num = $.-1;
    		$cluster = $cluster_num;
    		my @proteins = split /\s/xms, $proteins;
    		foreach ( @proteins) {
    			$_ =~/\A(\w+?)\((\w+?)\)/xms; # $1 is protein name, $2 is taxon label (e.g Hsa)
    			$clusters{$cluster}->{$1} =  $2;			
    		}
    	}		
    	close $FH;
    	return \%clusters;
    }
    
    sub work {
    	my ($self, $clust, $files,  $tax) = @_;
    	my %clusters = %{$clust};
    	my %taxa = %{$tax};
    	# input/output files
    	my ($new_OBO_file, $u_map_file, $t_map_file, $o_map_file, $b_map_file) = @{$files}; 
    	
    	# Initialize  maps (OBO::CCO::CCO_ID_Term_Map objects)
    	my $u_map = OBO::CCO::CCO_ID_Term_Map->new($u_map_file);  # map for Upper Level Ontology terms
    	my $t_map  = OBO::CCO::CCO_ID_Term_Map->new($t_map_file); # map for taxonomy terms
    	my $o_map  = OBO::CCO::CCO_ID_Term_Map->new($o_map_file); # map for orthologous groups terms
    	my $b_map  = OBO::CCO::CCO_ID_Term_Map->new($b_map_file); # map for biomolecule terms
    	# taxon specific maps for biolmolecule terms
    	foreach (keys %taxa) {
    		push @{$taxa{$_}}, OBO::CCO::CCO_ID_Term_Map->new($taxa{$_}->[1]);
    	}
    	# @{$taxa{taxon_label}} contains now taxon name, taxon specific map file, taxon specific map object
    	
    	my $ontology = OBO::Core::Ontology->new();
    	
    	# populate ontology
    	$ontology->add_relationship_type_as_string ('is_a',       'is_a');
    	$ontology->add_relationship_type_as_string ('has_source', 'has_source');
    	#$ontology->add_relationship_type_as_string ('source_of', 'source_of');
    	
    	my $protein = OBO::Core::Term->new();# upper level ontology term
    	$protein->name('protein');
    	$protein->id(assign_term_id($u_map, 'U', 'protein'));
    	if ($u_map->contains_value('protein')) {
    		$protein->id($u_map->get_cco_id_by_term('protein'));
    	}else{
    		$protein->id(assign_term_id($u_map, 'U', 'protein'));
    	}
    	$ontology->add_term($protein);
    	
    	foreach (keys %taxa) {
    		my $taxon = OBO::Core::Term->new();
    		my $taxon_lab = $_;
    		my $tax_name = $taxa{$taxon_lab}->[0];
    		$taxon->name($tax_name);
    		$taxon->id(assign_term_id($t_map, 'T', $tax_name));
    		$ontology->add_term($taxon);
    		push @{$taxa{$taxon_lab}}, $taxon;
    		#@{$taxa{$taxon_lab}} contains now taxon name, taxon specific map file, taxon specific map object, taxon term object
    	}
    	
    	foreach (keys %clusters) {
    		my $cluster = OBO::Core::Term->new();
    		my $clust_num = $_;
    		my $clust_name = "Type $_ protein";
    		$cluster->name($clust_name);
    		$cluster->id(assign_term_id($o_map, 'O', $clust_name));
    		$cluster->def_as_string("A protein belonging to the orthological type $_ produced by orthoMCL", "[CCO:vm]");
    		$ontology->create_rel($cluster, 'is_a', $protein);
    		foreach (keys %{$clusters{$clust_num}}) {   # for each protein in the cluster
    			my $prot_name = $_;
    			my $taxon_lab = $clusters{$clust_num}{$prot_name};
    			my $clust_protein = OBO::Core::Term->new();
    			$clust_protein->name($prot_name);
    			$clust_protein->id(assign_biomol_id($taxa{$taxon_lab}[2], $b_map, $prot_name));
    			my $short_map = $taxa{$taxon_lab}[2];
    			if ($short_map->contains_value($prot_name)) {
    				$clust_protein->id($short_map->get_cco_id_by_term($prot_name));
    			} else {
    				$clust_protein->id(assign_biomol_id($short_map, $b_map, $prot_name));
    			}
    			$ontology->add_term($clust_protein);
    			$ontology->create_rel($clust_protein, 'is_a', $cluster);
    			
    			$ontology->create_rel($clust_protein,         'has_source',   $taxa{$taxon_lab}->[3]);
    			#$ontology->create_rel($taxa{$taxon_lab}->[3], 'source_of',         $clust_protein);
    		}
    	}
    	
    	# Write the new ontology and maps to disk
    	open (my $FH, ">".$new_OBO_file) || die "Cannot write OBO file: ", $!;
    	$ontology->export(\*$FH);
    	close $FH;
    	foreach ((keys %taxa)) {
    		$taxa{$_}[2] -> write_map();
    	}
    	$b_map -> write_map();
    	$o_map -> write_map();
    	$t_map -> write_map();
    	$u_map -> write_map();
    	return $ontology;
    }
    please put your code between [ code] and [ /code] tags. You can edit your previous post to do that.
    Did you have onto-perl installed?

    Edit: also, do you call this from another script? I don't see where $OrthoMCLParser is created

    best regards
    Last edited by oesxyl; Apr 13, 2009, 02:56 PM.

    Comment


    • #3
      Hi,

      Yes I have onto-perl installed. And I believe the OrthoMCLParser is a perl module that comes with onto-perl.

      Comment


      • #4
        Originally posted by roro View Post
        Hi,

        Yes I have onto-perl installed. And I believe the OrthoMCLParser is a perl module that comes with onto-perl.
        onto-perl come with two parsers, for OBO and OWL ontologies and for both you must first create the parser with new and then pass an argument to work method, the ontology you want to parse.

        Edit: this script look more like a package,

        best regards
        Last edited by oesxyl; Apr 13, 2009, 03:29 PM.

        Comment


        • #5
          Thanks for the quick reply. Could you provide me examples of what you mean? I am sorry, but I am quite new to this (it has already been a steep learning curve). How could I fix it?

          Thanks so much.

          Comment


          • #6
            Originally posted by roro View Post
            Thanks for the quick reply. Could you provide me examples of what you mean? I am sorry, but I am quite new to this (it has already been a steep learning curve). How could I fix it?

            Thanks so much.
            your script looks like this one:

            http://cpansearch.perl.org/src/EASR/...hoMCLParser.pm

            which is a module in onto-perl 1.13. Is my fault that I don't know about it,

            http://search.cpan.org/~easr/ONTO-PERL-1.13/

            you have examples of scripts to the "Other files" section.

            best regards

            Comment

            Working...
            X