ensembl-hive  2.8.1
emit_canonical_encodings.pl
Go to the documentation of this file.
1 #!/usr/bin/env perl
2 # See the NOTICE file distributed with this work for additional information
3 # regarding copyright ownership.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 
18 use strict;
19 use warnings;
20 
21 use Getopt::Long;
22 
26 
27 my ($host, $port, $dbname, $user,$pass);
28 my ($dnahost, $dnaport, $dnadbname, $dnauser, $dnapass);
29 my ($ccds_host, $ccds_dbname, $ccds_user, $ccds_port, $ccds_pass);
30 
31 my $transcript;
32 my $gene;
33 
34 GetOptions( 'dbhost:s' => \$host,
35  'dbport:n' => \$port,
36  'dbname:s' => \$dbname,
37  'dbuser:s' => \$user,
38  'dbpass:s' => \$pass,
39  'dnahost:s' => \$dnahost,
40  'dnadbname:s' => \$dnadbname,
41  'dnauser:s' => \$dnauser,
42  'dnapass:s' => \$dnapass,
43  'dnaport:s' => \$dnaport,
44  'ccdshost:s' => \$ccds_host,
45  'ccdsdbname:s' => \$ccds_dbname,
46  'ccdsuser:s' => \$ccds_user,
47  'ccdsport:s' => \$ccds_port,
48  'ccdspass:s' => \$ccds_pass,
49  'transcript:s' => \$transcript,
50  'gene:s' => \$gene,
51  );
52 
53 
54 my $dba =
55  new Bio::EnsEMBL::DBSQL::DBAdaptor( -host => $host,
56  -user => $user,
57  -port => $port,
58  -dbname => $dbname,
59  -pass => $pass,
60  -species => 'default',
61  );
62 
63 if($dnadbname) {
64  if(!$dnauser || !$dnahost) {
65  throw ("You must provide user, host and dbname details to connect to DNA DB!");
66  }
67  my $dna_db = new Bio::EnsEMBL::DBSQL::DBAdaptor( -host => $dnahost,
68  -user => $dnauser,
69  -port => $dnaport,
70  -dbname => $dnadbname,
71  -pass => $dnapass,
72  -species => 'dna_'.$dba->species()
73  );
74  $dba->dnadb($dna_db);
75 }
76 
77 my $ccds_dba;
78 
79 if ($ccds_dbname) {
80  if (!$ccds_user || !$ccds_host) {
81  throw ("You must provide user, host and dbname details to connect to CCDS DB!");
82  }
83  $ccds_dba =
84  new Bio::EnsEMBL::DBSQL::DBAdaptor( -host => $ccds_host,
85  -user => $ccds_user,
86  -port => $ccds_port,
87  -pass => $ccds_pass,
88  -dbname => $ccds_dbname,
89  -species => 'ccds_'.$dba->species() );
90 }
91 
92 my $transcript_selector = Bio::EnsEMBL::Utils::TranscriptSelector->new($ccds_dba, 1);
93 
94 my $gene_object;
95 
96 if($gene) {
97  printf 'Using "%s" as our Gene stable ID'."\n", $gene;
98  $gene_object = $dba->get_GeneAdaptor()->fetch_by_stable_id($gene);
99 }
100 elsif($transcript) {
101  printf 'Using "%s" as a Transcript to find a Gene'."\n", $transcript;
102  my $t = $dba->get_TranscriptAdaptor()->fetch_by_stable_id($transcript);
103  $gene_object = $t->get_Gene();
104  printf 'Using "%s" as our Gene'."\n", $gene_object->stable_id();
105 }
106 
107 $transcript_selector->select_canonical_transcript_for_Gene($gene_object);
108 print "Original: ".$gene_object->canonical_transcript->stable_id."\n";
109 
110 sub usage {
111 print "
112 Example usage: perl emit_canonical_encodings.pl -dbhost host -dbuser user
113  -dbpass *** -dbname dbname -dbport 3306 -transcript ENST00019112
114 
115 Example usage: perl emit_canonical_encodings.pl -dbhost host -dbuser user
116  -dbpass *** -dbname dbname -dbport 3306 -gene ENSG00019111
117 
118 Script options:
119 
120  -dbname Database name
121 
122  -dbhost Database host
123 
124  -dbport Database port
125 
126  -dbuser Database user
127 
128  -dbpass Database password
129 
130 Optional DB connection arguments:
131 
132  -dnadbname DNA Database name
133 
134  -dnadbhost DNA Database host
135 
136  -dnadbuser DNA Database user
137 
138  -dnadbport DNA Database port
139 
140  -dnadbpass DNA Database pass
141 
142  -ccdsdbname CCDS database name
143 
144  -ccdshost CCDS database host
145 
146  -ccdsuser CCDS database user
147 
148  -ccdspass CCDS database pass
149 
150  -ccdsport CCDS database port
151 
152 Search params:
153 
154  -transcript The transcript stable ID to use to find the gene in question
155 
156  -gene The gene stable ID to emit encoded transcripts for
157 
158 A warning about not using CCDS is perfectly acceptible when not running on
159 Human, Mouse and Zebrafish.
160 ";
161 
162 }
usage
public usage()
Bio::EnsEMBL::DBSQL::DBAdaptor
Definition: DBAdaptor.pm:40
Bio::EnsEMBL::Utils::TranscriptSelector::select_canonical_transcript_for_Gene
public Bio::EnsEMBL::Transcript select_canonical_transcript_for_Gene()
Bio::EnsEMBL::Utils::TranscriptSelector::new
public Bio::EnsEMBL::Utils::TranscriptSelector new()
Bio::EnsEMBL::Transcript::stable_id
public String stable_id()
Bio::EnsEMBL::Utils::TranscriptSelector
Definition: TranscriptSelector.pm:30
Bio::EnsEMBL::Utils::Exception
Definition: Exception.pm:68