ensembl-hive  2.7.0
db.pm
Go to the documentation of this file.
1 =head1 LICENSE
2 
3 See the NOTICE file distributed with this work for additional information
4 regarding copyright ownership.
5 
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 
18 =cut
19 
20 package XrefMapper::db;
21 
22 use vars '@ISA';
25 use Cwd;
26 
27 sub new{
28  my($class, @args) = @_;
29 
30  my $self ={};
31  bless $self,$class;
32 
33  $self->dbc(new Bio::EnsEMBL::DBSQL::DBConnection(@args));
34 
35  return $self;
36 }
37 
38 sub species{
39  my ($self, $arg) = @_;
40 
41  (defined $arg) &&
42  ($self->{_species} = $arg );
43  return $self->{_species};
44 
45 }
46 
47 sub dbc{
48  my $self = shift;
49 
50  if(@_){
51  my $arg = shift;
52  if(defined($arg)){
53  if(!$arg->isa('Bio::EnsEMBL::DBSQL::DBConnection')){
54  throw("$arg is no a DBConnection\n");
55  }
56  }
57  $self->{_dbc} = $arg;
58  }
59  return $self->{_dbc};
60 }
61 
62 sub dba {
63  my $self = shift;
64  my $dbc = $self->dbc;
65  return Bio::EnsEMBL::DBSQL::DBAdaptor->new(-dbconn => $dbc, -species => $self->species);
66 }
67 
68 =head2 dir
69 
70  Arg [1] : (optional) string $arg
71  The new value of the dir used
72  Example : $dir = $db->dir()
73  Description: Getter/Setter for the directory used in the creation of fasta file
74  Returntype : string
75  Exceptions : none
76  Caller : new
77 
78 =cut
79 
80 sub dir {
81  my ($self, $arg) = @_;
82 
83  (defined $arg) &&
84  ($self->{_dir} = process_dir($arg) );
85  return $self->{_dir};
86 
87 }
88 
89 =head2 protein_file
90 
91  Arg [1] : (optional) string $arg
92  the fasta file name for the ensembl proteins
93  Example : $file_name = $self->ensembl_protein_file();
94  Description: Getter / Setter for the protien ensembl fasta file
95  Returntype : string
96  Exceptions : none
97 
98 =cut
99 
100 sub protein_file{
101  my ($self, $arg) = @_;
102 
103  (defined $arg) &&
104  ($self->{_ens_prot_file} = $arg );
105  return $self->{_ens_prot_file};
106 }
107 
108 =head2 dna_file
109 
110  Arg [1] : (optional) string $arg
111  the fasta file name for the ensembl dna
112  Example : $file_name = $self->ensembl_dna_file();
113  Description: Getter / Setter for the protien ensembl fasta file
114  Returntype : string
115  Exceptions : none
116 
117 =cut
118 
119 sub dna_file{
120  my ($self, $arg) = @_;
121 
122  (defined $arg) &&
123  ($self->{_ens_dna_file} = $arg );
124  return $self->{_ens_dna_file};
125 }
126 
127 sub process_dir {
128  my ($dir) = @_;
129 
130  if($dir =~ "^\/" ) { # if it start with / then its not from pwd
131  if(! -d $dir){
132  die "directory does not exist $dir\n";
133  }
134  }
135  elsif($dir eq "."){
136  $dir = cwd();
137  }
138  elsif($dir =~ "^\.\/"){
139  my $tmp = $dir;
140  $dir = cwd() . "/" . substr( $tmp, 2 );
141  if(! -d $dir){
142  die "directory does not exist $dir\n";
143  }
144  }
145  else{
146  die "directory does not exist $dir\n";
147  }
148  return $dir;
149 }
150 
151 
152 1;
Bio::EnsEMBL::DBSQL::DBAdaptor
Definition: DBAdaptor.pm:40
Bio::EnsEMBL::DBSQL::DBAdaptor::dbc
public Bio::EnsEMBL::DBSQL::DBConnection dbc()
Bio::EnsEMBL::DBSQL::DBConnection
Definition: DBConnection.pm:42
Bio::EnsEMBL::DBSQL::DBAdaptor::new
public Bio::EnsEMBL::DBSQL::DBAdaptor new()