line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bio::MLST::SearchForFiles; |
2
|
|
|
|
|
|
|
# ABSTRACT: Take in a species name and get the allele and profile files. |
3
|
|
|
|
|
|
|
$Bio::MLST::SearchForFiles::VERSION = '2.1.1630910'; |
4
|
|
|
|
|
|
|
|
5
|
11
|
|
|
11
|
|
133542
|
use Moose; |
|
11
|
|
|
|
|
430130
|
|
|
11
|
|
|
|
|
104
|
|
6
|
11
|
|
|
11
|
|
72752
|
use Bio::MLST::Types; |
|
11
|
|
|
|
|
139
|
|
|
11
|
|
|
|
|
9860
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has 'species_name' => ( is => 'ro', isa => 'Str', required => 1 ); |
9
|
|
|
|
|
|
|
has 'base_directory' => ( is => 'ro', isa => 'Str', required => 1 ); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has 'profiles_filename' => ( is => 'ro', isa => 'Bio::MLST::File', lazy => 1, builder => '_build_profiles_filename'); |
12
|
|
|
|
|
|
|
has 'allele_filenames' => ( is => 'ro', isa => 'ArrayRef', lazy => 1, builder => '_build_allele_filenames'); |
13
|
|
|
|
|
|
|
has 'search_base_directory' => ( is => 'ro', isa => 'Str', lazy => 1, builder => '_build__search_base_directory'); |
14
|
|
|
|
|
|
|
has 'list_species' => ( is => 'ro', isa => 'ArrayRef', lazy => 1, builder => '_build_list_species'); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub _build_list_species |
17
|
|
|
|
|
|
|
{ |
18
|
11
|
|
|
11
|
|
20
|
my($self) = @_; |
19
|
11
|
|
|
|
|
475
|
opendir(my $dh,$self->base_directory); |
20
|
11
|
|
|
|
|
407
|
my $species_name = $self->species_name; |
21
|
11
|
|
|
|
|
304
|
my $species_name_with_underscores = $self->species_name; |
22
|
11
|
|
|
|
|
119
|
$species_name =~ s!\W!.+!gi; |
23
|
11
|
|
|
|
|
62
|
$species_name_with_underscores =~ s!\W!_!gi; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# If there is an exact match return it |
26
|
11
|
|
|
|
|
308
|
my @search_results = grep { /^$species_name$/i } readdir($dh); |
|
63
|
|
|
|
|
488
|
|
27
|
11
|
100
|
100
|
|
|
110
|
if(@search_results == 1 && $search_results[0] eq $species_name_with_underscores) |
28
|
|
|
|
|
|
|
{ |
29
|
2
|
|
|
|
|
106
|
return \@search_results; |
30
|
|
|
|
|
|
|
} |
31
|
9
|
|
|
|
|
157
|
rewinddir($dh); |
32
|
9
|
|
|
|
|
83
|
@search_results = grep { /$species_name/i } readdir($dh); |
|
54
|
|
|
|
|
301
|
|
33
|
|
|
|
|
|
|
|
34
|
9
|
|
|
|
|
436
|
return \@search_results; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub _build__search_base_directory |
38
|
|
|
|
|
|
|
{ |
39
|
11
|
|
|
11
|
|
33
|
my($self) = @_; |
40
|
|
|
|
|
|
|
|
41
|
11
|
|
|
|
|
20
|
my @search_results = @{$self->list_species}; |
|
11
|
|
|
|
|
399
|
|
42
|
|
|
|
|
|
|
|
43
|
11
|
50
|
|
|
|
55
|
if(@search_results > 1) |
44
|
|
|
|
|
|
|
{ |
45
|
0
|
|
|
|
|
0
|
print "More than 1 MLST database has been found, please use a more specific query\n"; |
46
|
0
|
|
|
|
|
0
|
for my $search_result (@search_results) |
47
|
|
|
|
|
|
|
{ |
48
|
0
|
|
|
|
|
0
|
print $search_result."\n"; |
49
|
|
|
|
|
|
|
} |
50
|
0
|
|
|
|
|
0
|
die(); |
51
|
|
|
|
|
|
|
} |
52
|
11
|
|
|
|
|
362
|
return join('/',($self->base_directory,$search_results[0])); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _build_profiles_filename |
56
|
|
|
|
|
|
|
{ |
57
|
11
|
|
|
11
|
|
24
|
my($self) = @_; |
58
|
11
|
|
|
|
|
414
|
my $profiles_base = join('/',($self->search_base_directory,'profiles')); |
59
|
|
|
|
|
|
|
|
60
|
11
|
|
|
|
|
362
|
opendir(my $dh, $profiles_base); |
61
|
11
|
|
|
|
|
219
|
my @profiles = grep { /txt$/ } readdir($dh); |
|
33
|
|
|
|
|
168
|
|
62
|
11
|
50
|
33
|
|
|
114
|
if(@profiles > 1 || @profiles ==0) |
63
|
|
|
|
|
|
|
{ |
64
|
0
|
|
|
|
|
0
|
die "Couldn't find a single MLST profile\n"; |
65
|
|
|
|
|
|
|
} |
66
|
11
|
|
|
|
|
533
|
return join('/',($profiles_base, $profiles[0])); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub _build_allele_filenames |
70
|
|
|
|
|
|
|
{ |
71
|
11
|
|
|
11
|
|
28
|
my($self) = @_; |
72
|
11
|
|
|
|
|
361
|
my $alleles_base = join('/',($self->search_base_directory,'alleles')); |
73
|
|
|
|
|
|
|
|
74
|
11
|
|
|
|
|
301
|
opendir(my $dh, $alleles_base); |
75
|
11
|
|
|
|
|
162
|
my @alleles = grep { /tfa$/ } readdir($dh); |
|
53
|
|
|
|
|
200
|
|
76
|
11
|
|
|
|
|
22
|
my @alleles_with_full_path; |
77
|
11
|
|
|
|
|
56
|
for my $allele_filename (@alleles) |
78
|
|
|
|
|
|
|
{ |
79
|
31
|
|
|
|
|
88
|
push(@alleles_with_full_path, join('/',($alleles_base,$allele_filename))); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
11
|
|
|
|
|
465
|
return \@alleles_with_full_path; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
11
|
|
|
11
|
|
125
|
no Moose; |
|
11
|
|
|
|
|
25
|
|
|
11
|
|
|
|
|
102
|
|
86
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
87
|
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__END__ |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=pod |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=encoding UTF-8 |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 NAME |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Bio::MLST::SearchForFiles - Take in a species name and get the allele and profile files. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 VERSION |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
version 2.1.1630910 |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 SYNOPSIS |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Take in a species name and get the allele and profile files. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
use Bio::MLST::SearchForFiles; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
my $search_results = Bio::MLST::SearchForFiles->new( |
110
|
|
|
|
|
|
|
species_name => 'coli', |
111
|
|
|
|
|
|
|
base_directory => '/path/to/mlst/data' |
112
|
|
|
|
|
|
|
); |
113
|
|
|
|
|
|
|
$search_results->allele_filenames(); |
114
|
|
|
|
|
|
|
$search_results->profiles_filename(); |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 METHODS |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head2 allele_filenames |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Return the path to the allele files |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head2 profiles_filename |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Return the path to the profile file |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 AUTHOR |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Andrew J. Page <ap13@sanger.ac.uk> |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
This software is Copyright (c) 2012 by Wellcome Trust Sanger Institute. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
This is free software, licensed under: |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
The GNU General Public License, Version 3, June 2007 |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=cut |