-
Notifications
You must be signed in to change notification settings - Fork 2
/
gene_extra_info.pl
executable file
·292 lines (239 loc) · 11.4 KB
/
gene_extra_info.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#!/usr/bin/env perl
use strict;
use Getopt::Long;
use Data::Dumper;
use DB_CONFIG;
my $species = 'Homo sapiens';
my $phylo = "";
my $outdir = "/tmp/$species";
my $verbose = '0';
my $help = '0';
####################################################################
## Parsing command line options ####################################
####################################################################
# USAGE: ./core.pl --species "Homo sapiens" --outdir ../../appl_db/ird_v1/hsa ...
## Parsing command line
GetOptions ('species=s' => \$species, 'outdir=s' => \$outdir, 'phylo=s' => \$phylo,
'ensembl-libs=s' => \$ENSEMBL_LIBS, 'ensembl-registry=s' => \$ENSEMBL_REGISTRY,
'ensembl-host=s' => \$ENSEMBL_HOST, 'ensembl-port=s' => \$ENSEMBL_PORT,
'ensembl-user=s' => \$ENSEMBL_USER, 'ensembl-pass=s' => \$ENSEMBL_PASS,
'verbose' => \$verbose, 'help' => \$help);
## Checking help parameter
print_usage() if $help;
## Printing parameters
print_parameters() if $verbose;
## Checking outdir parameter exist, otherwise create it
if(-d $outdir){
print "Writing files to directory '$outdir'...\n" if $verbose;
}else{
print "Directory '$outdir' does not exist, creating directory...\n" if $verbose;
mkdir $outdir or die "Couldn't create dir: [$outdir] ($!)";
}
####################################################################
## Ensembl APIs ####################################################
####################################################################
## loading ensembl libraries
use lib "$ENSEMBL_LIBS/ensembl/modules";
use lib "$ENSEMBL_LIBS/ensembl-variation/modules";
use lib "$ENSEMBL_LIBS/ensembl-compara/modules";
use lib "$ENSEMBL_LIBS/ensembl-funcgen/modules";
use lib "$ENSEMBL_LIBS/bioperl-live";
## creating ensembl adaptors
use Bio::EnsEMBL::DBSQL::DBAdaptor;
use Bio::EnsEMBL::Variation::DBSQL::DBAdaptor;
use Bio::EnsEMBL::Compara::DBSQL::DBAdaptor;
use Bio::EnsEMBL::Funcgen::DBSQL::DBAdaptor;
## loading the registry with the adaptors
#Bio::EnsEMBL::Registry->load_all("$ENSEMBL_REGISTRY");
#Bio::EnsEMBL::Registry->load_registry_from_db(
# -host => 'mysql-eg-publicsql.ebi.ac.uk',
# -port => 4157,
# -user => 'anonymous'
#);
#Bio::EnsEMBL::Registry->load_registry_from_db(
# -host => 'ensembldb.ensembl.org',
# -user => 'anonymous',
# -verbose => '0'
#);
if($phylo eq "" || $phylo eq "vertebrate") {
print ("In vertebrates section");
Bio::EnsEMBL::Registry->load_registry_from_db(
-host => 'ensembl-db',
-port => 3306,
-user => 'anonymous',
-db_version => 85,
-verbose => '1'
);
}else {
print ("In no-vertebrates section");
Bio::EnsEMBL::Registry->load_registry_from_db(
-host => 'mysql-eg-publicsql.ebi.ac.uk',
-port => 4157,
-user => 'anonymous'
);
}
####################################################################
## variables definition
my (%dbnames, %dbnames_cont, %xrefs);
## everything is allright:
&createCoreTables();
my ($ngene, $ntrans, $nxref, $north, $ndbname) = (0, 0, 0, 0, 0);
my $trans_ext_name;
my @ordered_dbnames = ();
my @trans_ext_name = ();
sub create_orthologous {
}
sub createCoreTables {
my ($gene, $exon, $dblink, $translation, %uniq, $gene_adaptor, $transcript_adaptor, $translation_adaptor, $probefeature_adaptor, $pba);
my (@dbentries,@arr_dbnames);
my $orth_gene;
my %exon_trans = ();
## reset dbnames and xrefs
%dbnames = ();
%dbnames_cont = ();
%xrefs = ();
$gene_adaptor = Bio::EnsEMBL::Registry->get_adaptor($species, "core", "Gene");
$transcript_adaptor = Bio::EnsEMBL::Registry->get_adaptor($species, "core", "Transcript");
$translation_adaptor = Bio::EnsEMBL::Registry->get_adaptor($species, "core", "translation");
$probefeature_adaptor = Bio::EnsEMBL::Registry->get_adaptor($species, "funcgen", "ProbeFeature");
$pba = Bio::EnsEMBL::Registry->get_adaptor($species, "funcgen", "ProbeSet");
open (GENE_DESC, ">$outdir/description.txt") || die "Cannot open gene_description.txt file";
open (XREFS, ">$outdir/xrefs.txt") || die "Cannot open xref.txt file";
## for all the genes in the specie
foreach my $gene_id(@{$gene_adaptor->list_stable_ids()}) { #fetch_all_by_biotype('miRNA')
$ngene++;
$gene = $gene_adaptor->fetch_by_stable_id($gene_id);
print $ngene."\t".$gene->stable_id."\t".$gene->description."\n" if $verbose;
##### Gene Info and sequence ######################
print GENE_DESC $gene->stable_id."\t".$gene->description."\n";
########################################################################
##### XREF TRANSCRIPTS #################################################
########################################################################
foreach my $trans(@{$gene->get_all_Transcripts}) {
$ntrans++;
print "\t".$ntrans."\t".$trans->stable_id."\t".$trans->description."\n" if $verbose;
# Si el trancript es un microrna lo introduzco en xref tambien:
if($trans->biotype eq 'miRNA') {
print XREFS $trans->stable_id()."\t".$gene->external_name()."\t".&get_dbname_short("miRNA gene")."\t"."miRNA gene"."\t".$gene->description()."\n";
}
# Referencia al ensembl gene id
print XREFS $trans->stable_id()."\t".$gene->stable_id()."\t".&get_dbname_short("Ensembl gene")."\t"."Ensembl gene"."\t".$gene->description()."\n";
# Additional synonyms
my ($display_xref_entry);
$display_xref_entry = $gene->display_xref();
if ($display_xref_entry) {
foreach my $synonym_str(@{ $display_xref_entry->get_all_synonyms }) {
print XREFS $trans->stable_id()."\t".$synonym_str."\t".&get_dbname_short("Ensembl gene")."\t"."Ensembl gene"."\t".$gene->description()."\n";
}
}
# print XREF $ntrans."\t".$gene->external_name."\t".&get_dbname($gene->get_all_DBEntries->[0]->{'db_display_name'})."\t".$gene->get_all_DBEntries->[0]->{'description'}."\n";
# print XREFS $trans->stable_id()."\t".$gene->external_name()."\t".&get_dbname_short($gene->get_all_DBEntries->[0]->{'db_display_name'})."\t".$gene->get_all_DBEntries->[0]->{'db_display_name'}."\t".$gene->get_all_DBEntries->[0]->{'description'}."\n";
foreach my $dbentry(@{$gene->get_all_DBEntries}){
print XREFS $trans->stable_id()."\t".$dbentry->{'display_id'}."\t".&get_dbname_short($dbentry->{'db_display_name'})."\t".$dbentry->{'db_display_name'}."\t".$dbentry->{'description'}."\n";
}
# Referencia al ensembl transcript id
print XREFS $trans->stable_id()."\t".$trans->stable_id()."\t".&get_dbname_short("Ensembl transcript")."\t"."Ensembl transcript"."\t".$trans->description()."\n";
##### Translation ######################################################
# Referencia al ensembl prot id
$translation = $trans->translation();
if(defined($translation)) {
print XREFS $trans->stable_id()."\t".$translation->stable_id."\t".&get_dbname_short("Ensembl protein")."\t"."Ensembl protein"."\t".$trans->description()."\n";
# foreach my $dblink(@{ $translation->get_all_xrefs }) {
# print XREFS $trans->stable_id()."\t".$dblink->display_id()."\t".&get_dbname_short($dblink->db_display_name())."\t".$dblink->db_display_name()."\t".$dblink->description()."\n";
# }
%uniq = ();
foreach my $df(@{$translation->get_all_ProteinFeatures()}){
if( $df->interpro_ac() ne "" && not defined($uniq{$df->interpro_ac()})) {
print XREFS $trans->stable_id()."\t".$df->interpro_ac()."\t".&get_dbname_short("InterPro")."\t"."InterPro"."\t".$df->idesc()."\n";
$uniq{$df->interpro_ac()} = 1;
}
}
}
# foreach my $dblink(@{ $trans->get_all_DBLinks }) {
foreach my $dblink(@{ $trans->get_all_xrefs }) {
print XREFS $trans->stable_id()."\t".$dblink->display_id()."\t".&get_dbname_short($dblink->db_display_name())."\t".$dblink->db_display_name()."\t".$dblink->description()."\n";
if($dblink->display_id() =~ /(\w+)\.\d$/){
print XREFS $trans->stable_id()."\t".$1."\t".&get_dbname_short($dblink->db_display_name())."\t".$dblink->db_display_name()."\t".$dblink->description()."\n";
}
if($dblink->display_id() =~ /(\w+)\-\d$/){
print XREFS $trans->stable_id()."\t".$1."\t".&get_dbname_short($dblink->db_display_name())."\t".$dblink->db_display_name()."\t".$dblink->description()."\n";
}
if(defined ($trembl_species{$species}) && $dblink->display_id() =~ /(\w+)_$trembl_species{$species}/){
print XREFS $trans->stable_id()."\t".$1."\t".&get_dbname_short($dblink->db_display_name())."\t".$dblink->db_display_name()."\t".$dblink->description()."\n";
}
}
## MICROARRYAYS
if(defined $pba) {
my @probesets = @{$pba->fetch_all_by_external_name($trans->stable_id)};
foreach my $probeset (@probesets){
# my $arrays_string = join(', ', (map $_->name, @{$probeset->get_all_Arrays}));
my @arrays_string = map $_->name, @{$probeset->get_all_Arrays};
my $dbe_info;
#Now get linkage_annotation
# foreach my $dbe(@{$probeset->get_all_Transcript_DBEntries($trans)}){
#This will return all ProbeSet DBEntries for this transcript
#There should really be one max per transcript per probeset/probe
# $dbe_info = $dbe->linkage_annotation;
# }
# print "\t".$probeset->name." on arrays ".$arrays_string." with Probe hits $dbe_info\n";
foreach my $array_string(@arrays_string) {
print XREFS $trans->stable_id()."\t".$probeset->name."\t".&get_dbname_short($array_string)."\t".$array_string."\t\n";
}
}
}
}
########################################################################
# last;
}
close(GENE_DESC);
close(XREFS);
}
sub get_dbname_short {
my $display_name = shift;
my $dbname = $display_name;
if ($display_name =~ /Affymx Microarray/) {
$dbname =~ s/Affymx Microarray/affy/;
}elsif ($display_name =~ /MIM/) {
$dbname =~ s/MIM/omim/;
}elsif ($display_name =~ /Codelink/) {
$dbname = "codelink";
}elsif ($display_name =~ /Swiss-Prot/) {
$dbname =~ s/Swiss-Prot/swissprot/;
}elsif ($display_name =~ /MEROPS/) {
$dbname =~ s/MEROPS - the Peptidase Database/merops/;
}
$dbname =~ s/ /_/g;
$dbname =~ s/-/_/g;
$dbname =~ s/\(//g;
$dbname =~ s/\)//g;
$dbnames{$display_name} = lc($dbname);
return lc($dbname);
}
sub print_parameters {
print "Parameters: ";
print "species: $species, outdir: $outdir, ";
print "ensembl-libs: $ENSEMBL_LIBS, ensembl-registry: $ENSEMBL_REGISTRY, ";
print "ensembl-host: $ENSEMBL_HOST, ensembl-port: $ENSEMBL_PORT, ";
print "ensembl-user: $ENSEMBL_USER, ensembl-pass: $ENSEMBL_PASS, ";
print "verbose: $verbose, help: $help";
print "\n";
}
sub print_usage {
print "Usage: $0 [--species] [--outdir] [--ensembl-libs] [--ensembl-host] [--ensembl-port] ";
print "[--ensembl-user] [--ensembl-pass] [--verbose] [--help]\n";
print "\tDescription:\n";
print "\t species: scientific name, i.e.: Homo sapiens\n";
print "\t outdir: default directory /tmp/species\n";
print "\t ensembl-libs: Ensembl libraries path\n";
print "\t ensembl-host: Ensembl database host\n";
print "\t ensembl-port: Ensembl database port\n";
print "\t ensembl-user: Ensembl database user\n";
print "\t ensembl-pass: Ensembl database pass\n";
print "\t verbose: print logs\n";
print "\t help: print this help\n";
print "\n";
exit(0);
}
########################################################################
########################################################################
########################################################################