| 1 | # | ||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||
| 3 | # BioPerl module for Bio::DB::Flat | ||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||
| 5 | # Please direct questions and support issues to <bioperl-l@bioperl.org> | ||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||
| 7 | # Cared for by Lincoln Stein <lstein@cshl.org> | ||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||
| 9 | # You may distribute this module under the same terms as perl itself | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | # POD documentation - main docs before the code | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =head1 NAME | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | Bio::DB::Flat - Interface for indexed flat files | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | $db = Bio::DB::Flat->new(-directory => '/usr/share/embl', | ||||||||||||||||||||||||||||
| 20 | -dbname => 'mydb', | ||||||||||||||||||||||||||||
| 21 | -format => 'embl', | ||||||||||||||||||||||||||||
| 22 | -index => 'bdb', | ||||||||||||||||||||||||||||
| 23 | -write_flag => 1); | ||||||||||||||||||||||||||||
| 24 | $db->build_index('/usr/share/embl/primate.embl', | ||||||||||||||||||||||||||||
| 25 | '/usr/share/embl/protists.embl'); | ||||||||||||||||||||||||||||
| 26 | $seq = $db->get_Seq_by_id('HSFOS'); | ||||||||||||||||||||||||||||
| 27 | @sequences = $db->get_Seq_by_acc('DIV' => 'primate'); | ||||||||||||||||||||||||||||
| 28 | $raw = $db->fetch_raw('HSFOS'); | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | This object provides the basic mechanism to associate positions in | ||||||||||||||||||||||||||||
| 33 | files with primary and secondary name spaces. Unlike | ||||||||||||||||||||||||||||
| 34 | Bio::Index::Abstract (see L<Bio::Index::Abstract>), this is specialized | ||||||||||||||||||||||||||||
| 35 | to work with the "flat index" and BerkeleyDB indexed flat file formats | ||||||||||||||||||||||||||||
| 36 | worked out at the 2002 BioHackathon. | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | This object is a general front end to the underlying databases. | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | =head1 FEEDBACK | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =head2 Mailing Lists | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | User feedback is an integral part of the evolution of this and other | ||||||||||||||||||||||||||||
| 45 | Bioperl modules. Send your comments and suggestions preferably to one | ||||||||||||||||||||||||||||
| 46 | of the Bioperl mailing lists. Your participation is much appreciated. | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | bioperl-l@bioperl.org - General discussion | ||||||||||||||||||||||||||||
| 49 | http://bioperl.org/wiki/Mailing_lists - About the mailing lists | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | =head2 Support | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | Please direct usage questions or support issues to the mailing list: | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | I<bioperl-l@bioperl.org> | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | rather than to the module maintainer directly. Many experienced and | ||||||||||||||||||||||||||||
| 58 | reponsive experts will be able look at the problem and quickly | ||||||||||||||||||||||||||||
| 59 | address it. Please include a thorough description of the problem | ||||||||||||||||||||||||||||
| 60 | with code and data examples if at all possible. | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | =head2 Reporting Bugs | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | Report bugs to the Bioperl bug tracking system to help us keep track | ||||||||||||||||||||||||||||
| 65 | the bugs and their resolution. Bug reports can be submitted via the | ||||||||||||||||||||||||||||
| 66 | web: | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | https://github.com/bioperl/bioperl-live/issues | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =head1 AUTHOR - Lincoln Stein | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | Email - lstein@cshl.org | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | =head1 APPENDIX | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | The rest of the documentation details each of the object methods. Internal | ||||||||||||||||||||||||||||
| 77 | methods are usually preceded with an "_" (underscore). | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =cut | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | # Let the code begin... | ||||||||||||||||||||||||||||
| 83 | package Bio::DB::Flat; | ||||||||||||||||||||||||||||
| 84 | 2 | $Bio::DB::Flat::VERSION = '1.7.8'; | |||||||||||||||||||||||||||
| 85 | 2 | ▶ | use File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 2 | ▶ | use base qw(Bio::Root::Root Bio::DB::RandomAccessI); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 2 | ▶ | use constant CONFIG_FILE_NAME => 'config.dat'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =head2 new | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | Title : new | ||||||||||||||||||||||||||||
| 94 | Usage : my $db = Bio::DB::Flat->new( | ||||||||||||||||||||||||||||
| 95 | -directory => $root_directory, | ||||||||||||||||||||||||||||
| 96 | -dbname => 'mydb', | ||||||||||||||||||||||||||||
| 97 | -write_flag => 1, | ||||||||||||||||||||||||||||
| 98 | -index => 'bdb', | ||||||||||||||||||||||||||||
| 99 | -verbose => 0, | ||||||||||||||||||||||||||||
| 100 | -out => 'outputfile', | ||||||||||||||||||||||||||||
| 101 | -format => 'genbank'); | ||||||||||||||||||||||||||||
| 102 | Function: create a new Bio::DB::Flat object | ||||||||||||||||||||||||||||
| 103 | Returns : new Bio::DB::Flat object | ||||||||||||||||||||||||||||
| 104 | Args : -directory Root directory containing "config.dat" | ||||||||||||||||||||||||||||
| 105 | -write_flag If true, allows creation/updating. | ||||||||||||||||||||||||||||
| 106 | -verbose Verbose messages | ||||||||||||||||||||||||||||
| 107 | -out File to write to when write_seq invoked | ||||||||||||||||||||||||||||
| 108 | -index 'bdb' or 'binarysearch' | ||||||||||||||||||||||||||||
| 109 | Status : Public | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | The required -directory argument indicates where the flat file indexes | ||||||||||||||||||||||||||||
| 112 | will be stored. The build_index() and write_seq() methods will | ||||||||||||||||||||||||||||
| 113 | automatically create subdirectories of this root directory. Each | ||||||||||||||||||||||||||||
| 114 | subdirectory will contain a human-readable configuration file named | ||||||||||||||||||||||||||||
| 115 | "config.dat" that specifies where the individual indexes are stored. | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | The required -dbname argument gives a name to the database index. The | ||||||||||||||||||||||||||||
| 118 | index files will actually be stored in a like-named subdirectory | ||||||||||||||||||||||||||||
| 119 | underneath the root directory. | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | The -write_flag enables writing new entries into the database as well | ||||||||||||||||||||||||||||
| 122 | as the creation of the indexes. By default the indexes will be opened | ||||||||||||||||||||||||||||
| 123 | read only. | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | -index is one of "bdb" or "binarysearch" and indicates the type of | ||||||||||||||||||||||||||||
| 126 | index to generate. "bdb" corresponds to Berkeley DB. You *must* be | ||||||||||||||||||||||||||||
| 127 | using BerkeleyDB version 2 or higher, and have the Perl BerkeleyDB | ||||||||||||||||||||||||||||
| 128 | extension installed (DB_File will *not* work). "binarysearch" | ||||||||||||||||||||||||||||
| 129 | corresponds to the OBDA "flat" indexed file. | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | The -out argument specifies the output file for writing objects created | ||||||||||||||||||||||||||||
| 132 | with write_seq(). | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | The -format argument specifies the format of the input file or files. If | ||||||||||||||||||||||||||||
| 135 | the file suffix is one that Bioperl can already associate with a format | ||||||||||||||||||||||||||||
| 136 | then this is optional. | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | =cut | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 3 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=14 SCAR=29.5
Pod
documented
| |||||||||||||||||||||||||||||
| 141 | 3 | my $class = shift; | |||||||||||||||||||||||||||
| 142 | 3 | ▶ | $class = ref($class) if ref($class); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | 3 | my $self = $class->SUPER::new(@_); | |||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | # first we initialize ourselves | ||||||||||||||||||||||||||||
| 146 | 3 | my ($flat_directory,$dbname,$format) = | |||||||||||||||||||||||||||
| 147 | $self->_rearrange([qw(DIRECTORY DBNAME FORMAT)],@_); | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 3 | ▶ | defined $flat_directory | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | or $self->throw('Please supply a -directory argument'); | ||||||||||||||||||||||||||||
| 151 | 3 | ▶ | defined $dbname | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 152 | or $self->throw('Please supply a -dbname argument'); | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | # set values from configuration file | ||||||||||||||||||||||||||||
| 155 | 3 | $self->directory($flat_directory); | |||||||||||||||||||||||||||
| 156 | 3 | $self->dbname($dbname); | |||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 3 | ▶ | $self->throw("Base directory $flat_directory doesn't exist") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | unless -e $flat_directory; | ||||||||||||||||||||||||||||
| 160 | 3 | ▶ | $self->throw("$flat_directory isn't a directory") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | unless -d _; | ||||||||||||||||||||||||||||
| 162 | 3 | my $dbpath = File::Spec->catfile($flat_directory,$dbname); | |||||||||||||||||||||||||||
| 163 | 3 | ▶ | unless (-d $dbpath) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | 2 | $self->debug("creating db directory $dbpath\n"); | |||||||||||||||||||||||||||
| 165 | 2 | ▶ | mkdir $dbpath,0777 or $self->throw("Can't create $dbpath: $!"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | 3 | $self->_read_config(); | |||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | # but override with initialization values | ||||||||||||||||||||||||||||
| 170 | 3 | $self->_initialize(@_); | |||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 3 | ▶ | $self->throw('you must specify an indexing scheme') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 173 | unless $self->indexing_scheme; | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | # now we figure out what subclass to instantiate | ||||||||||||||||||||||||||||
| 176 | 2 | ▶ | my $index_type = $self->indexing_scheme eq 'BerkeleyDB/1' ? 'BDB' | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 177 | :$self->indexing_scheme eq 'flat/1' ? 'Binary' | ||||||||||||||||||||||||||||
| 178 | :$self->throw("unknown indexing scheme: " . | ||||||||||||||||||||||||||||
| 179 | $self->indexing_scheme); | ||||||||||||||||||||||||||||
| 180 | 2 | $format = $self->file_format; | |||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | # because Michele and Lincoln did it differently | ||||||||||||||||||||||||||||
| 183 | # Michele's way is via a standalone concrete class | ||||||||||||||||||||||||||||
| 184 | 2 | ▶ | if ($index_type eq 'Binary') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 185 | 2 | my $child_class = 'Bio::DB::Flat::BinarySearch'; | |||||||||||||||||||||||||||
| 186 | 2 | ▶ | eval "use $child_class"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 187 | 2 | ▶ | $self->throw($@) if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 188 | 2 | push @_, ('-format', $format); | |||||||||||||||||||||||||||
| 189 | 2 | return $child_class->new(@_); | |||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | # Lincoln uses Bio::SeqIO style delegation. | ||||||||||||||||||||||||||||
| 193 | 0 | my $child_class= "Bio\:\:DB\:\:Flat\:\:$index_type\:\:\L$format"; | |||||||||||||||||||||||||||
| 194 | 0 | eval "use $child_class"; | |||||||||||||||||||||||||||
| 195 | 0 | ▶ | $self->throw($@) if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | # rebless & reinitialize with the new class | ||||||||||||||||||||||||||||
| 198 | # (this prevents subclasses from forgetting to call our own initialization) | ||||||||||||||||||||||||||||
| 199 | 0 | bless $self,$child_class; | |||||||||||||||||||||||||||
| 200 | 0 | $self->_initialize(@_); | |||||||||||||||||||||||||||
| 201 | 0 | $self->_set_namespaces(@_); | |||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | 0 | $self; | |||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 3 | ▶ | sub _initialize { | ||||||||||||||||||||||||||
|
Subroutine
_initialize: called CC=9 SCAR=22.5
| |||||||||||||||||||||||||||||
| 207 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | 3 | my ($flat_write_flag,$dbname,$flat_indexing,$flat_verbose,$flat_outfile,$flat_format) | |||||||||||||||||||||||||||
| 210 | = $self->_rearrange([qw(WRITE_FLAG DBNAME INDEX VERBOSE OUT FORMAT)],@_); | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 3 | ▶ | $self->write_flag($flat_write_flag) if defined $flat_write_flag; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 3 | ▶ | if (defined $flat_indexing) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 215 | # very permissive | ||||||||||||||||||||||||||||
| 216 | 1 | ▶ | $flat_indexing = 'BerkeleyDB/1' if $flat_indexing =~ /bdb/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 217 | 1 | ▶ | $flat_indexing = 'flat/1' if $flat_indexing =~ /^(flat|binary)/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 218 | 1 | $self->indexing_scheme($flat_indexing); | |||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | 3 | ▶ | $self->verbose($flat_verbose) if defined $flat_verbose; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 222 | 3 | ▶ | $self->dbname($dbname) if defined $dbname; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 223 | 3 | ▶ | $self->out_file($flat_outfile) if defined $flat_outfile; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 224 | 3 | ▶ | $self->file_format($flat_format) if defined $flat_format; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | 0 | ▶ | sub _set_namespaces { | ||||||||||||||||||||||||||
|
Subroutine
_set_namespaces: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 228 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | $self->primary_namespace($self->default_primary_namespace) | ||||||||||||||||||||||||||||
| 231 | 0 | ▶ | unless defined $self->{flat_primary_namespace}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | $self->secondary_namespaces($self->default_secondary_namespaces) | ||||||||||||||||||||||||||||
| 234 | 0 | ▶ | unless defined $self->{flat_secondary_namespaces}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | $self->file_format($self->default_file_format) | ||||||||||||||||||||||||||||
| 237 | 0 | ▶ | unless defined $self->{flat_format}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | =head2 new_from_registry | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | Title : new_from_registry | ||||||||||||||||||||||||||||
| 243 | Usage : $db = Bio::DB::Flat->new_from_registry(%config) | ||||||||||||||||||||||||||||
| 244 | Function: creates a new Bio::DB::Flat object in a Bio::DB::Registry- | ||||||||||||||||||||||||||||
| 245 | compatible fashion | ||||||||||||||||||||||||||||
| 246 | Returns : new Bio::DB::Flat | ||||||||||||||||||||||||||||
| 247 | Args : provided by the registry, see below | ||||||||||||||||||||||||||||
| 248 | Status : Public | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | The following registry-configuration tags are recognized: | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | location Root of the indexed flat file; corresponds to the new() method's | ||||||||||||||||||||||||||||
| 253 | -directory argument. | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | =cut | ||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | 2 | ▶ | sub new_from_registry { | ||||||||||||||||||||||||||
|
Subroutine
new_from_registry: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||
| 258 | 2 | my ($self,%config) = @_; | |||||||||||||||||||||||||||
| 259 | 2 | ▶ | my $location = $config{'location'} or | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 260 | $self->throw('location tag must be specified.'); | ||||||||||||||||||||||||||||
| 261 | 2 | ▶ | my $dbname = $config{'dbname'} or | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 262 | $self->throw('dbname tag must be specified.'); | ||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | 2 | my $db = $self->new(-directory => $location, | |||||||||||||||||||||||||||
| 265 | -dbname => $dbname, | ||||||||||||||||||||||||||||
| 266 | ); | ||||||||||||||||||||||||||||
| 267 | 1 | $db; | |||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | # accessors | ||||||||||||||||||||||||||||
| 271 | 6 | ▶ | sub directory { | ||||||||||||||||||||||||||
|
Subroutine
directory: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 272 | 6 | my $self = shift; | |||||||||||||||||||||||||||
| 273 | 6 | my $d = $self->{flat_directory}; | |||||||||||||||||||||||||||
| 274 | 6 | ▶ | $self->{flat_directory} = shift if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 275 | 6 | $d; | |||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||
| 277 | 1 | ▶ | sub write_flag { | ||||||||||||||||||||||||||
|
Subroutine
write_flag: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 278 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 279 | 1 | my $d = $self->{flat_write_flag}; | |||||||||||||||||||||||||||
| 280 | 1 | ▶ | $self->{flat_write_flag} = shift if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 281 | 1 | $d; | |||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||
| 283 | 5 | ▶ | sub verbose { | ||||||||||||||||||||||||||
|
Subroutine
verbose: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 284 | 5 | my $self = shift; | |||||||||||||||||||||||||||
| 285 | 5 | my $d = $self->{flat_verbose}; | |||||||||||||||||||||||||||
| 286 | 5 | ▶ | $self->{flat_verbose} = shift if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 287 | 5 | $d; | |||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||
| 289 | 0 | ▶ | sub out_file { | ||||||||||||||||||||||||||
|
Subroutine
out_file: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 290 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 291 | 0 | my $d = $self->{flat_outfile}; | |||||||||||||||||||||||||||
| 292 | 0 | ▶ | $self->{flat_outfile} = shift if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 293 | 0 | $d; | |||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||
| 295 | 9 | ▶ | sub dbname { | ||||||||||||||||||||||||||
|
Subroutine
dbname: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 296 | 9 | my $self = shift; | |||||||||||||||||||||||||||
| 297 | 9 | my $d = $self->{flat_dbname}; | |||||||||||||||||||||||||||
| 298 | 9 | ▶ | $self->{flat_dbname} = shift if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 299 | 9 | $d; | |||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||
| 301 | 1 | ▶ | sub primary_namespace { | ||||||||||||||||||||||||||
|
Subroutine
primary_namespace: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 302 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 303 | 1 | my $d = $self->{flat_primary_namespace}; | |||||||||||||||||||||||||||
| 304 | 1 | ▶ | $self->{flat_primary_namespace} = shift if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 305 | 1 | $d; | |||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||
| 308 | # get/set secondary namespace(s) | ||||||||||||||||||||||||||||
| 309 | # pass an array ref. | ||||||||||||||||||||||||||||
| 310 | # get an array ref in scalar context, list in list context. | ||||||||||||||||||||||||||||
| 311 | 1 | ▶ | sub secondary_namespaces { | ||||||||||||||||||||||||||
|
Subroutine
secondary_namespaces: called CC=7 SCAR=29.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 312 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 313 | 1 | my $d = $self->{flat_secondary_namespaces}; | |||||||||||||||||||||||||||
| 314 | 1 | ▶ | $self->{flat_secondary_namespaces} = (ref($_[0]) eq 'ARRAY' ? shift : [@_]) if @_; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 315 | 1 | ▶ | return unless $d; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 316 | 0 | ▶ | $d = [$d] if $d && ref($d) ne 'ARRAY'; # just paranoia | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$d and ref $d ne "ARRAY"
MC/DC0%0/2
$d and ref $d ne "ARRAY"
$d
ref $d ne "ARRAY"
Truth table0%0/3
A and B
A= $dB= ref $d ne "ARRAY"
| |||||||||||||||||||||||||||||
| 317 | 0 | ▶ | return wantarray ? @$d : $d; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | # return the file format | ||||||||||||||||||||||||||||
| 321 | 4 | ▶ | sub file_format { | ||||||||||||||||||||||||||
|
Subroutine
file_format: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 322 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 323 | 4 | my $d = $self->{flat_format}; | |||||||||||||||||||||||||||
| 324 | 4 | ▶ | $self->{flat_format} = shift if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 325 | 4 | $d; | |||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||
| 328 | # return the alphabet | ||||||||||||||||||||||||||||
| 329 | 0 | ▶ | sub alphabet { | ||||||||||||||||||||||||||
|
Subroutine
alphabet: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 330 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 331 | 0 | my $d = $self->{flat_alphabet}; | |||||||||||||||||||||||||||
| 332 | 0 | ▶ | $self->{flat_alphabet} = shift if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 333 | 0 | $d; | |||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||
| 336 | 0 | ▶ | sub parse_one_record { | ||||||||||||||||||||||||||
|
Subroutine
parse_one_record: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 337 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 338 | 0 | my $fh = shift; | |||||||||||||||||||||||||||
| 339 | my $parser = | ||||||||||||||||||||||||||||
| 340 | 0 | ▶ | $self->{cached_parsers}{fileno($fh)} | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"cached_parsers"}{fileno $fh} ||= "Bio::SeqIO"->new("-fh", $fh, "-format", $self->default_file_format)
MC/DC0%0/2
$self->{"cached_parsers"}{fileno $fh} ||= "Bio::SeqIO"->new("-fh", $fh, "-format", $self->default_file_format)
$self->{"cached_parsers"}{fileno $fh}
"Bio::SeqIO"->new("-fh", $fh, "-format", $self->default_file_format)
Truth table0%0/3
A ||= B
A= $self->{"cached_parsers"}{fileno $fh}B= "Bio::SeqIO"->new("-fh", $fh, "-format", $self->default_file_format)
| |||||||||||||||||||||||||||||
| 341 | ||= Bio::SeqIO->new(-fh=>$fh,-format=>$self->default_file_format); | ||||||||||||||||||||||||||||
| 342 | 0 | ▶ | my $seq = $parser->next_seq or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 343 | 0 | ▶ | $self->{flat_alphabet} ||= $seq->alphabet; | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"flat_alphabet"} ||= $seq->alphabet
MC/DC0%0/2
$self->{"flat_alphabet"} ||= $seq->alphabet
$self->{"flat_alphabet"}
$seq->alphabet
Truth table0%0/3
A ||= B
A= $self->{"flat_alphabet"}B= $seq->alphabet
| |||||||||||||||||||||||||||||
| 344 | 0 | my $ids = $self->seq_to_ids($seq); | |||||||||||||||||||||||||||
| 345 | 0 | return $ids; | |||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||
| 349 | # return the indexing scheme | ||||||||||||||||||||||||||||
| 350 | 9 | ▶ | sub indexing_scheme { | ||||||||||||||||||||||||||
|
Subroutine
indexing_scheme: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 351 | 9 | my $self = shift; | |||||||||||||||||||||||||||
| 352 | 9 | my $d = $self->{flat_indexing}; | |||||||||||||||||||||||||||
| 353 | 9 | ▶ | $self->{flat_indexing} = shift if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 354 | 9 | $d; | |||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||
| 357 | 1 | ▶ | sub add_flat_file { | ||||||||||||||||||||||||||
|
Subroutine
add_flat_file: called CC=7 SCAR=23.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 358 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 359 | 1 | my ($file_path,$file_length,$nf) = @_; | |||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||
| 361 | # check that file_path is absolute | ||||||||||||||||||||||||||||
| 362 | 1 | ▶ | unless (File::Spec->file_name_is_absolute($file_path)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 363 | 0 | $file_path = File::Spec->rel2abs($file_path); | |||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | 1 | ▶ | -r $file_path or $self->throw("flat file $file_path cannot be read: $!"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||
| 368 | 1 | my $current_size = -s _; | |||||||||||||||||||||||||||
| 369 | 1 | ▶ | if (defined $file_length) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 370 | 1 | ▶ | $current_size == $file_length | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 371 | or $self->throw("flat file $file_path has changed size. Was $file_length bytes; now $current_size"); | ||||||||||||||||||||||||||||
| 372 | } else { | ||||||||||||||||||||||||||||
| 373 | 0 | $file_length = $current_size; | |||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||
| 376 | 1 | ▶ | unless (defined $nf) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 377 | 0 | ▶ | $self->{flat_file_index} = 0 unless exists $self->{flat_file_index}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 378 | 0 | $nf = $self->{flat_file_index}++; | |||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||
| 380 | 1 | $self->{flat_flat_file_path}{$nf} = $file_path; | |||||||||||||||||||||||||||
| 381 | 1 | $self->{flat_flat_file_no}{$file_path} = $nf; | |||||||||||||||||||||||||||
| 382 | 1 | $nf; | |||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||
| 385 | 0 | ▶ | sub write_config { | ||||||||||||||||||||||||||
|
Subroutine
write_config: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 386 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 387 | 0 | ▶ | $self->write_flag or $self->throw("cannot write configuration file because write_flag is not set"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 388 | 0 | my $path = $self->_config_path; | |||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | 0 | ▶ | open my $F, '>', $path or $self->throw("Could not write file '$path': $!"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||
| 392 | 0 | my $index_type = $self->indexing_scheme; | |||||||||||||||||||||||||||
| 393 | 0 | print $F "index\t$index_type\n"; | |||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||
| 395 | 0 | my $format = $self->file_format; | |||||||||||||||||||||||||||
| 396 | 0 | my $alphabet = $self->alphabet; | |||||||||||||||||||||||||||
| 397 | 0 | ▶ | my $alpha = $alphabet ? "/$alphabet" : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 398 | 0 | print $F "format\tURN:LSID:open-bio.org:${format}${alpha}\n"; | |||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||
| 400 | 0 | ▶ | my @filenos = $self->_filenos or $self->throw("cannot write config file because no flat files defined"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 401 | 0 | for my $nf (@filenos) { | |||||||||||||||||||||||||||
| 402 | 0 | my $path = $self->{flat_flat_file_path}{$nf}; | |||||||||||||||||||||||||||
| 403 | 0 | my $size = -s $path; | |||||||||||||||||||||||||||
| 404 | 0 | print $F join("\t","fileid_$nf",$path,$size),"\n"; | |||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||
| 407 | # write primary namespace | ||||||||||||||||||||||||||||
| 408 | 0 | ▶ | my $primary_ns = $self->primary_namespace | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 409 | or $self->throw('cannot write config file because no primary namespace defined'); | ||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||
| 411 | 0 | print $F join("\t",'primary_namespace',$primary_ns),"\n"; | |||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | # write secondary namespaces | ||||||||||||||||||||||||||||
| 414 | 0 | my @secondary = $self->secondary_namespaces; | |||||||||||||||||||||||||||
| 415 | 0 | print $F join("\t",'secondary_namespaces',@secondary),"\n"; | |||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||
| 417 | 0 | ▶ | close $F or $self->throw("close error on $path: $!"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||
| 420 | 0 | ▶ | sub files { | ||||||||||||||||||||||||||
|
Subroutine
files: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 421 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 422 | 0 | ▶ | return unless $self->{flat_flat_file_no}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 423 | 0 | return keys %{$self->{flat_flat_file_no}}; | |||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||
| 426 | 0 | ▶ | sub write_seq { | ||||||||||||||||||||||||||
|
Subroutine
write_seq: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 427 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 428 | 0 | my $seq = shift; | |||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||
| 430 | 0 | ▶ | $self->write_flag or $self->throw("cannot write sequences because write_flag is not set"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||
| 432 | 0 | ▶ | my $file = $self->out_file or $self->throw('no outfile defined; use the -out argument to new()'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 433 | 0 | ▶ | my $seqio = $self->{flat_cached_parsers}{$file} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"flat_cached_parsers"}{$file} ||= "Bio::SeqIO"->new("-Format", $self->file_format, "-file", ">$file")
MC/DC0%0/2
$self->{"flat_cached_parsers"}{$file} ||= "Bio::SeqIO"->new("-Format", $self->file_format, "-file", ">$file")
$self->{"flat_cached_parsers"}{$file}
"Bio::SeqIO"->new("-Format", $self->file_format, "-file", ">$file")
Truth table0%0/3
A ||= B
A= $self->{"flat_cached_parsers"}{$file}B= "Bio::SeqIO"->new("-Format", $self->file_format, "-file", ">$file")
| |||||||||||||||||||||||||||||
| 434 | ||= Bio::SeqIO->new(-Format => $self->file_format, | ||||||||||||||||||||||||||||
| 435 | -file => ">$file") | ||||||||||||||||||||||||||||
| 436 | or $self->throw("couldn't create Bio::SeqIO object"); | ||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||
| 438 | 0 | ▶ | my $fh = $seqio->_fh or $self->throw("couldn't get filehandle from Bio::SeqIO object"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 439 | 0 | my $offset = tell($fh); | |||||||||||||||||||||||||||
| 440 | 0 | $seqio->write_seq($seq); | |||||||||||||||||||||||||||
| 441 | 0 | my $length = tell($fh)-$offset; | |||||||||||||||||||||||||||
| 442 | 0 | my $ids = $self->seq_to_ids($seq); | |||||||||||||||||||||||||||
| 443 | 0 | $self->_store_index($ids,$file,$offset,$length); | |||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||
| 445 | 0 | $self->{flat_outfile_dirty}++; | |||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||
| 448 | 3 | ▶ | sub close { | ||||||||||||||||||||||||||
|
Subroutine
close: called CC=2 SCAR=10.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 449 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 450 | 3 | ▶ | return unless $self->{flat_outfile_dirty}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 451 | 0 | $self->write_config; | |||||||||||||||||||||||||||
| 452 | 0 | delete $self->{flat_outfile_dirty}; | |||||||||||||||||||||||||||
| 453 | 0 | delete $self->{flat_cached_parsers}{$self->out_file}; | |||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||
| 457 | 0 | ▶ | sub _filenos { | ||||||||||||||||||||||||||
|
Subroutine
_filenos: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 458 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 459 | 0 | ▶ | return unless $self->{flat_flat_file_path}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 460 | 0 | return keys %{$self->{flat_flat_file_path}}; | |||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||
| 463 | # read the configuration file | ||||||||||||||||||||||||||||
| 464 | 3 | ▶ | sub _read_config { | ||||||||||||||||||||||||||
|
Subroutine
_read_config: called CC=11 SCAR=24.7
| |||||||||||||||||||||||||||||
| 465 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 466 | 3 | my $path = $self->_config_path; | |||||||||||||||||||||||||||
| 467 | 3 | ▶ | return unless -e $path; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||
| 469 | 1 | ▶ | open my $F, '<', $path or $self->throw("Could not read file '$path': $!"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 470 | 1 | my %config; | |||||||||||||||||||||||||||
| 471 | 1 | ▶ | while (<$F>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 472 | 4 | chomp; | |||||||||||||||||||||||||||
| 473 | 4 | my ($tag,@values) = split "\t"; | |||||||||||||||||||||||||||
| 474 | 4 | $config{$tag} = \@values; | |||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||
| 476 | 1 | ▶ | CORE::close $F or $self->throw("close error on $path: $!"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||
| 478 | 1 | ▶ | $config{index}[0] =~ m~(flat/1|BerkeleyDB/1)~ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 479 | or $self->throw("invalid configuration file $path: no index line"); | ||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||
| 481 | 1 | $self->indexing_scheme($1); | |||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||
| 483 | 1 | ▶ | if ($config{format}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 484 | # handle LSID format | ||||||||||||||||||||||||||||
| 485 | 1 | ▶ | if ($config{format}[0] =~ /^URN:LSID:open-bio\.org:(\w+)(?:\/(\w+))/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 486 | 0 | $self->file_format($1); | |||||||||||||||||||||||||||
| 487 | 0 | $self->alphabet($2); | |||||||||||||||||||||||||||
| 488 | } else { # compatibility with older versions | ||||||||||||||||||||||||||||
| 489 | 1 | $self->file_format($config{format}[0]); | |||||||||||||||||||||||||||
| 490 | } | ||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||
| 493 | # set up primary namespace | ||||||||||||||||||||||||||||
| 494 | 1 | ▶ | my $primary_namespace = $config{primary_namespace}[0] | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 495 | or $self->throw("invalid configuration file $path: no primary namespace defined"); | ||||||||||||||||||||||||||||
| 496 | 1 | $self->primary_namespace($primary_namespace); | |||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||
| 498 | # set up secondary namespaces (may be empty) | ||||||||||||||||||||||||||||
| 499 | 1 | $self->secondary_namespaces($config{secondary_namespaces}); | |||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||
| 501 | # get file paths and their normalization information | ||||||||||||||||||||||||||||
| 502 | 1 | ▶ | my @normalized_files = grep {$_ ne ''} map {/^fileid_(\S+)/ && $1} keys %config; | ||||||||||||||||||||||||||
|
Condition66%2/3
/^fileid_(\S+)/ && $1
MC/DC0%0/2
/^fileid_(\S+)/ && $1
/^fileid_(\S+)/
$1
Truth table66%2/3
A && B
A= /^fileid_(\S+)/B= $1
| |||||||||||||||||||||||||||||
| 503 | 1 | for my $nf (@normalized_files) { | |||||||||||||||||||||||||||
| 504 | 1 | my ($file_path,$file_length) = @{$config{"fileid_${nf}"}}; | |||||||||||||||||||||||||||
| 505 | 1 | $self->add_flat_file($file_path,$file_length,$nf); | |||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||
| 507 | 1 | 1; | |||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||
| 511 | 3 | ▶ | sub _config_path { | ||||||||||||||||||||||||||
|
Subroutine
_config_path: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 512 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 513 | 3 | $self->_catfile($self->_config_name); | |||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||
| 516 | 3 | ▶ | sub _catfile { | ||||||||||||||||||||||||||
|
Subroutine
_catfile: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 517 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 518 | 3 | my $component = shift; | |||||||||||||||||||||||||||
| 519 | 3 | File::Spec->catfile($self->directory,$self->dbname,$component); | |||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||
| 522 | 3 | ▶ | sub _config_name { CONFIG_FILE_NAME } | ||||||||||||||||||||||||||
|
Subroutine
_config_name: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||
| 524 | 0 | ▶ | sub _path2fileno { | ||||||||||||||||||||||||||
|
Subroutine
_path2fileno: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 525 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 526 | 0 | my $path = shift; | |||||||||||||||||||||||||||
| 527 | return $self->add_flat_file($path) | ||||||||||||||||||||||||||||
| 528 | 0 | ▶ | unless exists $self->{flat_flat_file_no}{$path}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 529 | 0 | $self->{flat_flat_file_no}{$path}; | |||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||
| 532 | 0 | ▶ | sub _fileno2path { | ||||||||||||||||||||||||||
|
Subroutine
_fileno2path: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 533 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 534 | 0 | my $fileno = shift; | |||||||||||||||||||||||||||
| 535 | 0 | $self->{flat_flat_file_path}{$fileno}; | |||||||||||||||||||||||||||
| 536 | } | ||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||
| 538 | 0 | ▶ | sub _files { | ||||||||||||||||||||||||||
|
Subroutine
_files: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 539 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 540 | 0 | my $paths = $self->{flat_flat_file_no}; | |||||||||||||||||||||||||||
| 541 | 0 | return keys %$paths; | |||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||
| 544 | =head2 fetch | ||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||
| 546 | Title : fetch | ||||||||||||||||||||||||||||
| 547 | Usage : $index->fetch( $id ) | ||||||||||||||||||||||||||||
| 548 | Function: Returns a Bio::Seq object from the index | ||||||||||||||||||||||||||||
| 549 | Example : $seq = $index->fetch( 'dJ67B12' ) | ||||||||||||||||||||||||||||
| 550 | Returns : Bio::Seq object | ||||||||||||||||||||||||||||
| 551 | Args : ID | ||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||
| 553 | Deprecated. Use get_Seq_by_id instead. | ||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||
| 555 | =cut | ||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||
| 557 | 0 | ▶ | sub fetch { shift->get_Seq_by_id(@_) } | ||||||||||||||||||||||||||
|
Subroutine
fetch: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||
| 560 | =head2 To Be Implemented in Subclasses | ||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||
| 562 | The following methods MUST be implemented by subclasses. | ||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||
| 564 | =cut | ||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||
| 566 | # create real live Bio::Seq object | ||||||||||||||||||||||||||||
| 567 | 0 | ▶ | sub get_Seq_by_id { | ||||||||||||||||||||||||||
|
Subroutine
get_Seq_by_id: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 568 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 569 | 0 | my $id = shift; | |||||||||||||||||||||||||||
| 570 | 0 | $self->throw_not_implemented; | |||||||||||||||||||||||||||
| 571 | } | ||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||
| 574 | # fetch array of Bio::Seq objects | ||||||||||||||||||||||||||||
| 575 | 0 | ▶ | sub get_Seq_by_acc { | ||||||||||||||||||||||||||
|
Subroutine
get_Seq_by_acc: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 576 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 577 | 0 | ▶ | return $self->get_Seq_by_id(shift) if @_ == 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 578 | 0 | my ($ns,$key) = @_; | |||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||
| 580 | 0 | $self->throw_not_implemented; | |||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||
| 583 | 0 | ▶ | sub fetch_raw { | ||||||||||||||||||||||||||
|
Subroutine
fetch_raw: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 584 | 0 | my ($self,$id,$namespace) = @_; | |||||||||||||||||||||||||||
| 585 | 0 | $self->throw_not_implemented; | |||||||||||||||||||||||||||
| 586 | } | ||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||
| 588 | 0 | ▶ | sub default_file_format { | ||||||||||||||||||||||||||
|
Subroutine
default_file_format: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 589 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 590 | 0 | $self->throw_not_implemented; | |||||||||||||||||||||||||||
| 591 | } | ||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||
| 593 | 0 | ▶ | sub _store_index { | ||||||||||||||||||||||||||
|
Subroutine
_store_index: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 594 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 595 | 0 | my ($ids,$file,$offset,$length) = @_; | |||||||||||||||||||||||||||
| 596 | 0 | $self->throw_not_implemented; | |||||||||||||||||||||||||||
| 597 | } | ||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||
| 599 | =head2 May Be Overridden in Subclasses | ||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||
| 601 | The following methods MAY be overridden by subclasses. | ||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||
| 603 | =cut | ||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||
| 605 | 0 | ▶ | sub default_primary_namespace { | ||||||||||||||||||||||||||
|
Subroutine
default_primary_namespace: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 606 | 0 | return "ACC"; | |||||||||||||||||||||||||||
| 607 | } | ||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||
| 609 | 0 | ▶ | sub default_secondary_namespaces { | ||||||||||||||||||||||||||
|
Subroutine
default_secondary_namespaces: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 610 | 0 | return; | |||||||||||||||||||||||||||
| 611 | } | ||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||
| 613 | 0 | ▶ | sub seq_to_ids { | ||||||||||||||||||||||||||
|
Subroutine
seq_to_ids: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 614 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 615 | 0 | my $seq = shift; | |||||||||||||||||||||||||||
| 616 | 0 | my %ids; | |||||||||||||||||||||||||||
| 617 | 0 | $ids{$self->primary_namespace} = $seq->accession_number; | |||||||||||||||||||||||||||
| 618 | 0 | \%ids; | |||||||||||||||||||||||||||
| 619 | } | ||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||
| 621 | 3 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 622 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 623 | 3 | $self->close; | |||||||||||||||||||||||||||
| 624 | } | ||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||
| 627 | 2 | 1; | |||||||||||||||||||||||||||