ensembl-hive  2.7.0
PGSCParser.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::PGSCParser;
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  # need to uncompress the zip file, whihc is not supported by the xrefs framework
49 
50  # print STDERR "uncompressing the zip file\n";
51 
52  $file =~ /(.+)\/.+\.zip$/;
53  my $dir = $1;
54 
55  #print STDERR "dir, $dir\n";
56 
57  system ("unzip -o $file -d $dir");
58  $file =~ s/\.zip$//;
59 
60  # print STDERR "file after decompression, $file\n";
61 
62  my $gene_source_id = $self->get_source_id_for_source_name("PGSC_GENE");
63 
64  my $pgsc_io = $self->get_filehandle($file);
65 
66  if ( !defined $pgsc_io ) {
67  print STDERR "ERROR: Could not open $file\n";
68  return 1; # 1 is an error
69  }
70 
71  my $xref_count =0;
72  my $syn_count =0;
73 
74  while ( $_ = $pgsc_io->getline() ) {
75 
76  chomp;
77 
78  if ($_ =~ /^([^\t]+)\t([^\t]+)$/) {
79  my ($pgsc_id, $desc) = ($1,$2);
80 
81  if ($verbose) {
82  #print STDERR "pgsc_id, $pgsc_id\n";
83  #print STDERR "desc: $desc\n";
84  }
85 
86  my $locus_name = $pgsc_id;
87 
88  my $gene_xref_id = $self->add_xref({ acc => $pgsc_id,
89  label => $locus_name,
90  desc => $desc,
91  source_id => $gene_source_id,
92  species_id => $species_id,
93  info_type => "DIRECT"} );
94  $self->add_direct_xref($gene_xref_id, $pgsc_id, "Gene", "DIRECT");
95 
96  $xref_count++;
97 
98  }
99  else {
100  if ($verbose) {
101  print STDERR "failed to parse line, $_\n\n";
102  }
103  }
104  }
105 
106  $pgsc_io->close();
107 
108  print $xref_count." PGSC Xrefs added\n" if($verbose);
109  return 0; #successful
110 }
111 
112 1;
XrefParser::BaseParser
Definition: BaseParser.pm:8
run
public run()