Mercurial > repos > mahtabm > ensembl
comparison variant_effect_predictor/Bio/EnsEMBL/Utils/IO/FeatureSerializer.pm @ 0:1f6dce3d34e0
Uploaded
author | mahtabm |
---|---|
date | Thu, 11 Apr 2013 02:01:53 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:1f6dce3d34e0 |
---|---|
1 =pod | |
2 | |
3 =head1 LICENSE | |
4 | |
5 Copyright (c) 1999-2012 The European Bioinformatics Institute and | |
6 Genome Research Limited. All rights reserved. | |
7 | |
8 This software is distributed under a modified Apache license. | |
9 For license details, please see | |
10 | |
11 http://www.ensembl.org/info/about/code_licence.html | |
12 | |
13 =head1 NAME | |
14 | |
15 FeatureSerializer - An abstract serializer for turning EnsEMBL Features into other formats | |
16 | |
17 =head1 AUTHOR | |
18 | |
19 Kieron Taylor, 2012 - ktaylor@ebi.ac.uk | |
20 | |
21 =head1 SYNOPSIS | |
22 | |
23 my $serializer = new Bio::EnsEMBL::Utils::IO::FeatureSerializer( $filehandle ); | |
24 $serializer->print_feature_list( \@list_of_features ); | |
25 | |
26 =head1 DESCRIPTION | |
27 | |
28 Generic class for serializing features Subclass this class to create a | |
29 format-specific serializer. Be sure to implement print_feature at the | |
30 bare minimum | |
31 | |
32 =cut | |
33 | |
34 package Bio::EnsEMBL::Utils::IO::FeatureSerializer; | |
35 | |
36 use strict; | |
37 use warnings; | |
38 | |
39 use base qw(Bio::EnsEMBL::Utils::IO::Serializer); | |
40 | |
41 # Majority of methods inherited from Serializer | |
42 | |
43 sub print_feature { | |
44 throw( "print_feature method not implemented."); | |
45 } | |
46 | |
47 =head2 print_feature_list | |
48 | |
49 Arg [1] : Listref of Features | |
50 Description: Run print_feature on every feature in the list | |
51 | |
52 =cut | |
53 | |
54 sub print_feature_list { | |
55 my $self = shift; | |
56 my $feature_list = shift; | |
57 if (ref($feature_list) eq 'ARRAY') { | |
58 if (scalar(@$feature_list) > 0) {$self->{'achieved_something'} = 1;} | |
59 foreach my $feature (@{$feature_list}) { | |
60 $self->print_feature($feature); | |
61 } | |
62 } | |
63 else { | |
64 throw( "print_feature_list requires a listref as argument" ); | |
65 } | |
66 } | |
67 | |
68 =head2 print_feature_Iterator | |
69 | |
70 Arg [1] : Bio::EnsEMBL::Utils::Iterator | |
71 Description: Automatically spools through an iterator for convenience | |
72 Returntype : None | |
73 =cut | |
74 | |
75 sub print_feature_Iterator { | |
76 my $self = shift; | |
77 my $iterator = shift; | |
78 if ($iterator->can('has_next')) { | |
79 $iterator->each( | |
80 sub { | |
81 $self->print_feature($_); | |
82 $self->{'achieved_something'} = 1; | |
83 } | |
84 ); | |
85 } | |
86 else { | |
87 throw("Supplied iterator does not look like Bio::EnsEMBL::Utils::Iterator"); | |
88 } | |
89 } | |
90 | |
91 1; |