ensembl-hive  2.8.1
GramenePathwayParser.pm
Go to the documentation of this file.
1 =head1 LICENSE
2 
3 See the NOTICE file distributed with this work for additional information
4 regarding copyright ownership.
5 
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 
18 =cut
19 
20 package XrefParser::GramenePathwayParser;
21 
22 =pod
23 
24 =head1 NAME
25 
27 
28 =head1 DESCRIPTION
29 
30 Parse pathway dumps from Gramene. File format (and example data):
31 
32  gene_name AT1G66030
33  enzyme_name fatty acid (omega-1)-hydroxylase
34  reaction_id RXN-7796
35  reaction_name
36  ec 2.7.7.-
37  pathway_id PWY-5129
38  pathway_name sphingolipid biosynthesis (plants)
39 
40 =head1 AUTHOR
41 
42 Ken Youens-Clark E<lt>kclark@cshl.eduE<gt>.
43 
44 =cut
45 
46 use strict;
47 use Text::RecordParser::Tab;
48 use base 'XrefParser::BaseParser';
49 
50 sub run {
51  my ($self, $args) = @_;
52  my $source_id = $args->{'source_id'};
53  my $species_id = $args->{'species_id'};
54  my $files = $args->{'files'};
55  my $release_file = $args->{'rel_file'};
56  my $verbose = $args->{'verbose'};
57  my $file = ref $files eq 'ARRAY' ? shift @$files : '';
58 
59  if ( !$file ) {
60  printf STDERR "%s called without a 'files' argument\n%s",
61  __PACKAGE__, Dumper($args);
62  return 1; # error
63  }
64 
65  my $p = Text::RecordParser::Tab->new( $file );
66 
67  my $direct_xref_count = 0;
68  while ( my $rec = $p->fetchrow_hashref ) {
69  my $gene = $rec->{'gene_name'} or next;
70 
71  if ( my $ec = $rec->{'ec'} ) {
72  my $ec_xref_id = $self->add_xref({
73  source_id => $source_id,
74  species_id => $species_id,
75  acc => $ec,
76  label => '',
77  desc => '',
78  info_type => 'DIRECT',
79  });
80 
81  $self->add_direct_xref( $ec_xref_id, $gene, 'Gene', 'DIRECT' );
82  $direct_xref_count++;
83  }
84 
85  if ( my $pathway_id = $rec->{'pathway_id'} ) {
86  my $pathway_xref_id = $self->add_xref({
87  source_id => $source_id,
88  species_id => $species_id,
89  acc => $pathway_id,
90  label => $rec->{'pathway_name'},
91  desc => '',
92  info_type => 'DIRECT'
93  });
94 
95  $self->add_direct_xref( $pathway_xref_id, $gene, 'Gene', 'DIRECT' );
96  $direct_xref_count++;
97  }
98  }
99 
100  printf "Parsed pathway Ids from file '%s,' added %s direct_xrefs\n",
101  $file, $direct_xref_count;
102 
103  return 0; # success
104 }
105 
106 1;
run
public run()
XrefParser::GramenePathwayParser
Definition: GramenePathwayParser.pm:16