Mercurial > repos > willmclaren > ensembl_vep
comparison variant_effect_predictor/Bio/EnsEMBL/Variation/Failable.pm @ 0:21066c0abaf5 draft
Uploaded
author | willmclaren |
---|---|
date | Fri, 03 Aug 2012 10:04:48 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:21066c0abaf5 |
---|---|
1 =head1 LICENSE | |
2 | |
3 Copyright (c) 1999-2012 The European Bioinformatics Institute and | |
4 Genome Research Limited. All rights reserved. | |
5 | |
6 This software is distributed under a modified Apache license. | |
7 For license details, please see | |
8 | |
9 http://www.ensembl.org/info/about/code_licence.html | |
10 | |
11 =head1 CONTACT | |
12 | |
13 Please email comments or questions to the public Ensembl | |
14 developers list at <dev@ensembl.org>. | |
15 | |
16 Questions may also be sent to the Ensembl help desk at | |
17 <helpdesk@ensembl.org>. | |
18 | |
19 =cut | |
20 | |
21 # Ensembl module for Bio::EnsEMBL::Variation::BaseStructuralVariation | |
22 # | |
23 # Copyright (c) 2011 Ensembl | |
24 # | |
25 | |
26 =head1 NAME | |
27 | |
28 Bio::EnsEMBL::Variation::Failable | |
29 | |
30 =head1 DESCRIPTION | |
31 | |
32 This object returns failed information. | |
33 | |
34 =cut | |
35 | |
36 | |
37 use strict; | |
38 use warnings; | |
39 | |
40 package Bio::EnsEMBL::Variation::Failable; | |
41 | |
42 | |
43 =head2 failed_description | |
44 | |
45 Arg [1] : $failed_description (optional) | |
46 The new value to set the failed_description attribute to. Should | |
47 be a reference to a list of strings, alternatively a string can | |
48 be passed. If multiple failed descriptions are specified, they should | |
49 be separated with semi-colons. | |
50 Example : $failed_str = $sv->failed_description(); | |
51 Description: Get/Sets the failed description for this structural variant. The failed | |
52 descriptions are lazy-loaded from the database. | |
53 Returntype : Semi-colon separated string | |
54 Exceptions : Thrown on illegal argument. | |
55 Caller : general | |
56 Status : At risk | |
57 | |
58 =cut | |
59 | |
60 sub failed_description { | |
61 my $self = shift; | |
62 my $description = shift; | |
63 | |
64 # Update the description if necessary | |
65 if (defined($description)) { | |
66 | |
67 # If the description is a string, split it by semi-colon and take the reference | |
68 if (check_ref($description,'STRING')) { | |
69 my @pcs = split(/;/,$description); | |
70 $description = \@pcs; | |
71 } | |
72 # Throw an error if the description is not an arrayref | |
73 assert_ref($description.'ARRAY'); | |
74 | |
75 # Update the cached failed_description | |
76 $self->{'failed_description'} = $description; | |
77 } | |
78 # Else, fetch it from the db if it's not cached | |
79 elsif (!defined($self->{'failed_description'})) { | |
80 $self->{'failed_description'} = $self->get_all_failed_descriptions(); | |
81 } | |
82 | |
83 # Return a semi-colon separated string of descriptions | |
84 return join(";",@{$self->{'failed_description'}}); | |
85 } | |
86 | |
87 | |
88 =head2 get_all_failed_descriptions | |
89 | |
90 Example : | |
91 if ($sv->is_failed()) { | |
92 my $descriptions = $sv->get_all_failed_descriptions(); | |
93 print "Structural variant " . $sv->variation_name() . " has been flagged as failed because '"; | |
94 print join("' and '",@{$descriptions}) . "'\n"; | |
95 } | |
96 | |
97 Description: Gets all failed descriptions associated with this Structural variant. | |
98 Returntype : Reference to a list of strings | |
99 Exceptions : Thrown if an adaptor is not attached to this object. | |
100 Caller : general | |
101 Status : At risk | |
102 | |
103 =cut | |
104 | |
105 sub get_all_failed_descriptions { | |
106 my $self = shift; | |
107 | |
108 # If the failed descriptions haven't been cached yet, load them from db | |
109 unless (defined($self->{'failed_description'})) { | |
110 | |
111 # Check that this allele has an adaptor attached | |
112 unless (defined($self->adaptor())) { | |
113 throw('An adaptor must be attached to the ' . ref($self) . ' object'); | |
114 } | |
115 | |
116 $self->{'failed_description'} = $self->adaptor->get_all_failed_descriptions($self); | |
117 } | |
118 | |
119 return $self->{'failed_description'}; | |
120 } | |
121 | |
122 | |
123 =head2 is_failed | |
124 | |
125 Example : print "Structural variant '" . $sv->variation_name() . "' has " . ($sv->is_failed() ? "" : "not ") . "been flagged as failed\n"; | |
126 Description: Gets the failed attribute for this structural variant. The failed attribute | |
127 is lazy-loaded from the database. | |
128 Returntype : int | |
129 Exceptions : none | |
130 Caller : general | |
131 Status : At risk | |
132 | |
133 =cut | |
134 | |
135 sub is_failed { | |
136 my $self = shift; | |
137 | |
138 return (length($self->failed_description()) > 0); | |
139 } | |
140 1; |