ensembl-hive  2.8.1
SGDParser.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::SGDParser;
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  my $dbi = $ref_arg->{dbi};
41  $dbi = $self->dbi unless defined $dbi;
42 
43  if((!defined $source_id) or (!defined $species_id) or (!defined $files) ){
44  croak "Need to pass source_id, species_id and files as pairs";
45  }
46  $verbose |=0;
47 
48  my $file = @{$files}[0];
49 
50  my $gene_source_id = $self->get_source_id_for_source_name("SGD_GENE", undef, $dbi);
51  #my $transcript_source_id = $self->get_source_id_for_source_name("SGD_TRANSCRIPT");
52  my $translation_source_id = $self->get_source_id_for_source_name("SGD_TRANSLATION", undef, $dbi);
53 
54  my $sgd_io = $self->get_filehandle($file);
55 
56  if ( !defined $sgd_io ) {
57  print STDERR "ERROR: Could not open $file\n";
58  return 1; # 1 is an error
59  }
60 
61  my $xref_count =0;
62  my $syn_count =0;
63 
64  while ( $_ = $sgd_io->getline() ) {
65 
66  chomp;
67 
68  if ($_ =~ /^([^\t]+)\t([^\t]+)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t[^\t]+\t[^\t]*\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]*\t[^\t]+\t[^\t]+\t([^\t]*)$/) {
69  my ($sgd_id, $biotype, $status, $orf_name, $locus_name, $alias_name, $desc) = ($1,$2,$3,$4,$5,$6,$7);
70 
71  # parse the lines corresponding to the gene entries
72  # and filter out lines corresponding to the CDS for example
73 
74  if ($biotype =~ /ORF|.+RNA|transposable_element_gene|pseudogene/) {
75 
76  if ($verbose) {
77  #print STDERR "parsing line for biotype, $biotype\n";
78  #print STDERR "sgd_id, biotype, status, orf_name, locus_name, alias_name, $sgd_id, $biotype, $status, $orf_name, $locus_name, $alias_name\n";
79  #print STDERR "desc: $desc\n";
80  }
81 
82  if (!defined $locus_name || ($locus_name eq "")) {
83 
84  if (!defined $orf_name || ($orf_name eq "")) {
85  print STDERR "can't assign the orf_name as the locus_name!\n";
86  }
87  else {
88  if ($verbose) {
89  #print STDERR "assigning the orf_name as the locus_name(ie the gene_name)\n";
90  }
91  $locus_name = $orf_name;
92  }
93  }
94 
95  my (@syn) = split(/\|/,$alias_name);
96 
97  my $gene_xref_id = $self->add_xref({ acc => $sgd_id,
98  label => $locus_name,
99  desc => $desc,
100  source_id => $gene_source_id,
101  species_id => $species_id,
102  dbi => $dbi,
103  info_type => "DIRECT"} );
104  $self->add_direct_xref($gene_xref_id, $orf_name, "Gene", "DIRECT", $dbi);
105 
106  my $translation_xref_id = $self->add_xref({ acc => $sgd_id,
107  label => $locus_name,
108  desc => $desc,
109  source_id => $translation_source_id,
110  species_id => $species_id,
111  dbi => $dbi,
112  info_type => "DIRECT"} );
113  $self->add_direct_xref($translation_xref_id, $orf_name, "Translation", "DIRECT", $dbi);
114 
115  $xref_count++;
116 
117  foreach my $synonym (@syn){
118  if ($verbose) {
119  # print STDERR "adding synonym, $synonym\n";
120  }
121  $self->add_to_syn($sgd_id, $gene_source_id, $synonym, $species_id, $dbi);
122  $syn_count++;
123  }
124 
125  }
126  else {
127  if ($verbose) {
128  #print STDERR "filtering biotype, $biotype\n";
129  }
130  }
131  }
132  else {
133  if ($verbose) {
134  print STDERR "failed to parse line, $_\n\n";
135  }
136  }
137  }
138 
139  $sgd_io->close();
140 
141  print $xref_count." SGD Xrefs added with $syn_count synonyms\n" if($verbose);
142  return 0; #successful
143 }
144 
145 1;
XrefParser::BaseParser
Definition: BaseParser.pm:8
run
public run()