-
Notifications
You must be signed in to change notification settings - Fork 0
/
ensembl-query.pl
44 lines (34 loc) · 1.22 KB
/
ensembl-query.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
#!/usr/bin/env perl
use Bio::EnsEMBL::Registry;
my $registry = 'Bio::EnsEMBL::Registry';
$registry->load_registry_from_db(
-host => 'ensembldb.ensembl.org', # alternatively 'useastdb.ensembl.org'
-user => 'anonymous'
);
my $slice_adaptor = $registry->get_adaptor( 'Human', 'Core', 'Slice' );
my $slice = $slice_adaptor->fetch_by_region( 'chromosome', 'X', 1e6, 10e6 );
my $genes = $slice->get_all_Genes();
while ( my $gene = shift @{$genes} ) {
my $gstring = feature2string($gene);
print "$gstring\n";
my $transcripts = $gene->get_all_Transcripts();
while ( my $transcript = shift @{$transcripts} ) {
my $tstring = feature2string($transcript);
print "\t$tstring\n";
foreach my $exon ( @{ $transcript->get_all_Exons() } ) {
my $estring = feature2string($exon);
print "\t\t$estring\n";
}
}
}
sub feature2string
{
my $feature = shift;
my $stable_id = $feature->stable_id();
my $seq_region = $feature->slice->seq_region_name();
my $start = $feature->start();
my $end = $feature->end();
my $strand = $feature->strand();
return sprintf( "%s: %s:%d-%d (%+d)",
$stable_id, $seq_region, $start, $end, $strand );
}