ensembl-hive  2.8.1
CodelinkParser.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::CodelinkParser;
21 
22 use strict;
23 use File::Basename;
24 use Carp;
25 use base qw( XrefParser::BaseParser );
26 
27 # Parser for Codelink probes
28 
29 #>GE469530
30 #TTGTTTTCAGCTTGCTTCTGTCATTCTTCC
31 #>GE469548
32 #CACAGTTGGGTGAAGCTGGTGATGAAGGTA
33 
34 sub run {
35 
36  my ($self, $ref_arg) = @_;
37  my $source_id = $ref_arg->{source_id};
38  my $species_id = $ref_arg->{species_id};
39  my $files = $ref_arg->{files};
40  my $release_file = $ref_arg->{rel_file};
41  my $verbose = $ref_arg->{verbose};
42 
43  if((!defined $source_id) or (!defined $species_id) or (!defined $files) or (!defined $release_file)){
44  croak "Need to pass source_id, species_id, files and rel_file as pairs";
45  }
46  $verbose |=0;
47 
48  my $file = @{$files}[0];
49 
50  my @xrefs;
51 
52  local $/ = "\n>";
53 
54  my $codelink_io = $self->get_filehandle($file);
55  if ( !defined $codelink_io ) {
56  print STDERR "ERROR: Could not open $file\n";
57  return 1; # 1 = error
58  }
59 
60  while ( $_ = $codelink_io->getline() ) {
61  my $xref;
62 
63  my ($header, $sequence) = $_ =~ /^>?(.+?)\n([^>]*)/s or warn("Can't parse FASTA entry: $_\n");
64 
65  # deconstruct header - only accession for now
66  my $accession = $header;
67 
68  # make sequence into one long string - probably not necessary for short probes
69  $sequence =~ s/\n//g;
70 
71  # build the xref object and store it
72  $xref->{ACCESSION} = $accession;
73  $xref->{LABEL} = $accession;
74  $xref->{SEQUENCE} = $sequence;
75  $xref->{SOURCE_ID} = $source_id;
76  $xref->{SPECIES_ID} = $species_id;
77  $xref->{SEQUENCE_TYPE} = 'dna';
78  $xref->{STATUS} = 'experimental';
79 
80  push @xrefs, $xref;
81 
82  }
83 
84  $codelink_io->close();
85 
86 
87  $self->upload_xref_object_graphs(\@xrefs);
88 
89  print scalar(@xrefs) . " Codelink xrefs succesfully parsed\n" if($verbose);
90 
91  return 0; #successful
92 }
93 
94 1;
XrefParser::BaseParser
Definition: BaseParser.pm:8
run
public run()