ensembl-hive  2.8.1
PhytozomeGmaxParser.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::PhytozomeGmaxParser;
21 
22 use strict;
23 use warnings;
24 use Carp;
25 use POSIX qw(strftime);
26 use File::Basename;
27 
28 use base qw( XrefParser::BaseParser );
29 
30 # --------------------------------------------------------------------------------
31 # Parse command line and run if being run directly
32 
33 sub run {
34 
35  my ($self, $ref_arg) = @_;
36  my $source_id = $ref_arg->{source_id};
37  my $species_id = $ref_arg->{species_id};
38  my $files = $ref_arg->{files};
39  my $verbose = $ref_arg->{verbose};
40 
41  if((!defined $source_id) or (!defined $species_id) or (!defined $files) ){
42  croak "Need to pass source_id, species_id and files as pairs";
43  }
44  $verbose |=0;
45 
46  my $file = @{$files}[0];
47 
48  my $gene_source_id = $self->get_source_id_for_source_name("PHYTOZOME_GMAX_GENE");
49 
50  my $gmax_io = $self->get_filehandle($file);
51 
52  if ( !defined $gmax_io ) {
53  print STDERR "ERROR: Could not open $file\n";
54  return 1; # 1 is an error
55  }
56 
57  my $xref_count =0;
58  my $syn_count =0;
59 
60  while ( $_ = $gmax_io->getline() ) {
61 
62  chomp;
63 
64  if ($_ =~ /^([^\t]+)\t[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t([^\t]*)/) {
65  my ($gmax_id, $desc) = ($1,$2);
66 
67  if ($verbose) {
68  #print STDERR "gmax_id, $gmax_id\n";
69  #print STDERR "desc: $desc\n";
70  }
71 
72  my $locus_name = $gmax_id;
73  my $gene_xref_id = undef;
74 
75  if ((defined $desc) && ($desc ne "")) {
76  $gene_xref_id = $self->add_xref({ acc => $gmax_id,
77  label => $locus_name,
78  desc => $desc,
79  source_id => $gene_source_id,
80  species_id => $species_id,
81  info_type => "DIRECT"} );
82  }
83  else {
84 
85  # no description given
86 
87  $gene_xref_id = $self->add_xref({ acc => $gmax_id,
88  label => $locus_name,
89  source_id => $gene_source_id,
90  species_id => $species_id,
91  info_type => "DIRECT"} );
92  }
93  $self->add_direct_xref($gene_xref_id, $gmax_id, "Gene", "DIRECT");
94 
95  $xref_count++;
96 
97  }
98  else {
99  if ($verbose) {
100  print STDERR "failed to parse line, $_\n\n";
101  }
102  }
103  }
104 
105  $gmax_io->close();
106 
107  print $xref_count." Phytozome_GMAX Xrefs added\n" if($verbose);
108  return 0; #successful
109 }
110 
111 1;
XrefParser::BaseParser
Definition: BaseParser.pm:8
run
public run()