line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bio::VertRes::Config::References; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: A class for translating between a reference name and the location on disk |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
101604
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use Bio::VertRes::Config::Types; |
8
|
|
|
|
|
|
|
use Bio::VertRes::Config::Exceptions; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has 'reference_lookup_file' => ( is => 'ro', isa => 'Bio::VertRes::Config::File', required => 1 ); |
11
|
|
|
|
|
|
|
has '_reference_names_to_files' => ( is => 'ro', isa => 'HashRef', lazy => 1, builder => '_build__reference_names_to_files'); |
12
|
|
|
|
|
|
|
has 'available_references' => ( is => 'ro', isa => 'ArrayRef', lazy => 1, builder => '_build_available_references'); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub _build__reference_names_to_files |
15
|
|
|
|
|
|
|
{ |
16
|
|
|
|
|
|
|
my ($self) = @_; |
17
|
|
|
|
|
|
|
my %reference_names_to_files; |
18
|
|
|
|
|
|
|
open(my $index_file, $self->reference_lookup_file) or Bio::VertRes::Config::Exceptions::FileDoesntExist->throw(error => 'Couldnt open file '.$self->reference_lookup_file); |
19
|
|
|
|
|
|
|
while(<$index_file>) |
20
|
|
|
|
|
|
|
{ |
21
|
|
|
|
|
|
|
chomp; |
22
|
|
|
|
|
|
|
my $line = $_; |
23
|
|
|
|
|
|
|
my @reference_details = split(/\t/, $line); |
24
|
|
|
|
|
|
|
$reference_names_to_files{$reference_details[0]} = $reference_details[1]; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
return \%reference_names_to_files; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _build_available_references |
30
|
|
|
|
|
|
|
{ |
31
|
|
|
|
|
|
|
my ($self) = @_; |
32
|
|
|
|
|
|
|
my @references = sort(keys %{$self->_reference_names_to_files}); |
33
|
|
|
|
|
|
|
return \@references; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub search_for_references |
37
|
|
|
|
|
|
|
{ |
38
|
|
|
|
|
|
|
my ($self, $query) = @_; |
39
|
|
|
|
|
|
|
$query =~ s!\W!.+!g; |
40
|
|
|
|
|
|
|
my @search_results = grep { /$query/i } @{$self->available_references}; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
return \@search_results; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub is_reference_name_valid |
46
|
|
|
|
|
|
|
{ |
47
|
|
|
|
|
|
|
my ($self, $query) = @_; |
48
|
|
|
|
|
|
|
return 1 if(defined($self->_reference_names_to_files->{$query})); |
49
|
|
|
|
|
|
|
return 0; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub invalid_reference_message |
53
|
|
|
|
|
|
|
{ |
54
|
|
|
|
|
|
|
my ($self, $query) = @_; |
55
|
|
|
|
|
|
|
my $output_message ="Invalid reference specified.\n"; |
56
|
|
|
|
|
|
|
my $search_results = $self->search_for_references($query); |
57
|
|
|
|
|
|
|
if(@{$search_results} > 0) |
58
|
|
|
|
|
|
|
{ |
59
|
|
|
|
|
|
|
$output_message .= "Did you mean:\n\n"; |
60
|
|
|
|
|
|
|
$output_message .= join( |
61
|
|
|
|
|
|
|
"\n", |
62
|
|
|
|
|
|
|
@{ $search_results |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
return $output_message; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub get_reference_location_on_disk |
70
|
|
|
|
|
|
|
{ |
71
|
|
|
|
|
|
|
my ($self, $reference_name) = @_; |
72
|
|
|
|
|
|
|
$self->_reference_names_to_files->{$reference_name}; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
76
|
|
|
|
|
|
|
no Moose; |
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
__END__ |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=pod |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 NAME |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Bio::VertRes::Config::References - A class for translating between a reference name and the location on disk |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 VERSION |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
version 1.133090 |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 SYNOPSIS |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
A class for translating between a reference name and the location on disk |
94
|
|
|
|
|
|
|
use Bio::VertRes::Config::References; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Bio::VertRes::Config::References->new( reference_lookup_file => $self->reference_lookup_file ) |
97
|
|
|
|
|
|
|
->get_reference_location_on_disk( $self->reference ); |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 AUTHOR |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Andrew J. Page <ap13@sanger.ac.uk> |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
This software is Copyright (c) 2013 by Wellcome Trust Sanger Institute. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
This is free software, licensed under: |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
The GNU General Public License, Version 3, June 2007 |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=cut |