I have retrieved all variants in a single chromosome using the slice adapter and variation feature adaptor, then I got a file that contains variant ids and other basic information, looks like:
rs867361848 A/G 10010 10010 SNV dbSNP
rs370048753 A/T 10014 10014 SNV dbSNP
rs113469508 A/C/G 10015 10015 SNV dbSNP
Then I want to get the phenotype data connective to these variants, so firstly I try to use these ids only to retrieve their phenotypes, here is my code.
#!/usr/bin/env perl
use Bio::EnsEMBL::Registry;
my $registry = 'Bio::EnsEMBL::Registry';
$registry->load_registry_from_db(
-host => 'ensembldb.ensembl.org',
-user => 'anonymous'
);
my $var_adaptor = $registry->get_adaptor('human', 'variation','variation');
my $pf_adaptor = $registry->get_adaptor('homo_sapiens', 'variation', 'phenotypefeature');
my $filename1 = '/home/records/try.txt';
my $filename2 = '/home/records/result.txt';
open( FILE1, "$filename1" ) or die("Could not open file $filename1");
open( FILE2, ">$filename2") or die("could not open file $filename2");
while (my $aline = <FILE1>){
chomp($aline);
my $var = $var_adaptor->fetch_by_name($aline);
foreach my $pf (@{$pf_adaptor->fetch_all_by_Variation($var)}) {
print FILE2 $pf->variation_names, "\t", $pf->phenotype->description, "\t", $pf->source_name,"\t";
print FILE2 $pf->p_value,"\t" if (defined($pf->p_value));
print FILE2 $pf->risk_allele, "\t" if (defined($pf->risk_allele));
print FILE2 $pf->associated_gene,"\t" if (defined($pf->associated_gene));
print FILE2 $pf->clinical_significance, "\n" if (defined($pf->clinical_significance));
}
}
close FILE1;
close FILE2;
The "try.txt" file contains a list of variant ids, like:
rs745593600
rs201278642
rs370160198
And after this line,
my $var = $var_adaptor->fetch_by_name($aline);
if I write "print FILE2 $var->source_name,"\t",$var->variation_name,"\n"; I can get the result:
dbSNP rs745593600
dbSNP rs201278642
dbSNP rs370160198
That means I can access the variation data ($var), so the problem starts from this line:
foreach my $pf (@{$pf_adaptor->fetch_all_by_Variation($var)}) {....}
The results of $pf->variation_names, $pf->phenotype->description,etc. were nothing, so how could I solve this problem?
Thank you so much Ben, I will know better next time