[ensembl-dev] issue with my script to fetch genes from a file using API
Nathalie Conte
nac at sanger.ac.uk
Wed Nov 2 15:18:02 GMT 2011
HI, I have a file see format attached
basically the coordinates of the regions I want to retrieve genes from
are column 1( chromosome) 5(start) and 6(end)
I used this script to parse through the file and give my external gene
names , in the output I get only 1 gene name and a message:
Can't call method "get_all_Genes" on an undefined value at
./fetch_gene_API.pl line 34.
I don't understand where this comes from , I wanted to check whether you
could help/advise
thanks
Nathalie
#!/software/bin/perl
use warnings;
use strict;
use Bio::EnsEMBL::Registry;
use Bio::EnsEMBL::Utils::Sequence qw(reverse_comp);
#use lib "/nfs/team82/nac/amy/may2011/lib";
my $registry = "Bio::EnsEMBL::Registry";
$registry->load_registry_from_db(-host => 'ensembldb.ensembl.org', -user
=> 'anonymous');
my $file =
"/nfs/team82/nac/Roland/November_2011/PT_mcrs0.25T_50_2_20M_sdundo.bind_API.txt";
unless (open(REGIONS, $file)){
print "Cannot open file \"$file\"\n\n";
}
my @regions = <REGIONS>;
close REGIONS;
open(OUT,">PT_mcrs0.25T_50_2_20M_sdundo.bind_API_fetchGene.txt");
my $slice_adaptor = $registry->get_adaptor('Mouse', 'Core', 'Slice');
foreach my $region(@regions){
chomp $region;
my @coordinates = split(/\t/, $region);
my $chromosome = $coordinates[0];
my $start = $coordinates[4];
my $end = $coordinates[5];
my $slice = $slice_adaptor->fetch_by_region('chromosome',$chromosome,
$start, $end);
my $genes = $slice->get_all_Genes;
foreach my $gene( @{$genes} ){
print OUT
$coordinates[0],"\t",$coordinates[1],"\t",$coordinates[2],"\t",$coordinates[3],"\t",$coordinates[4],"\t",$coordinates[5],"\t",$gene->external_name,"\t",$coordinates[6],
"\n";
}
}
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: PT_mcrs0.25T_50_2_20M_sdundo.bind_API.txt
URL: <http://mail.ensembl.org/pipermail/dev_ensembl.org/attachments/20111102/e239707f/attachment.txt>
More information about the Dev
mailing list