None available.
sub new
{ my $caller = shift;
my $class = ref($caller) || $caller;
my $self = $class->SUPER::new(@_);
$self->{'feature_types'} = {
'REDfly TFBS' => {
name => 'REDfly TFBS',
class => 'Transcription Factor',
description => 'REDfly transciption factor binding site',
},
'REDfly CRM' => {
name => 'REDfly CRM',
class => 'Regulatory Motif',
description => 'REDfly cis regulatory motif',
},
};
$self->{feature_sets} = {
'REDfly TFBSs' => {
feature_type =>\$ self->{'feature_types'}{'REDfly TFBS'},
analysis =>
{
-logic_name => 'REDfly TFBS',
-description => 'REDfly transcription factor binding sites (http://redfly.ccr.buffalo.edu/)',
-display_label => 'REDfly TFBS',
-displayable => 1,
},
xrefs => 1,
},
'REDfly CRMs' => {
feature_type =>\$ self->{'feature_types'}{'REDfly CRM'},
analysis =>
{
-logic_name => 'REDfly CRM',
-description => 'REDfly cis regulatory motif (http://redfly.ccr.buffalo.edu/)',
-display_label => 'REDfly CRM',
-displayable => 1,
},
xrefs => 1,
},
};
$self->{config} = {
'REDfly CRMs' => {
file => $ENV{'EFG_DATA'}.'/input/REDFLY/crm_dump.gff',
gff_attrs => {
'ID' => 1,
},
},
'REDfly TFBSs' => {
file => $ENV{'EFG_DATA'}.'/input/REDFLY/tbfs_dump.gff',
gff_attrs => {
'ID' => 1,
'Factor' => 1,
'Target' => 1,
},
desc_suffix => ' binding site',
}
};
if(! defined $self->import_sets){
@{$self->{'import_sets'}} = keys %{$self->{'feature_sets'}};
}
else{
foreach my $import_fset(@{$self->import_sets}){
if(! exists $self->{'feature_sets'}{$import_fset}){
throw("$import_fset is not a valid import feature set. Maybe you need to add this to the config in:\t".ref($self));
}
}
}
$self->validate_and_store_feature_types;
$self->set_feature_sets;
return $self;
}
} |
sub parse_and_load
{ my $self = shift;
my ($fset_name, $old_assembly, $new_assembly, $file) = rearrange(['FEATURE_SET', 'OLD_ASSEMBLY', 'NEW_ASSEMBLY', 'FILE'], @_);
warn "params not yet fully implemented, loading defaults import sets";
my $analysis_adaptor = $self->db->get_AnalysisAdaptor();
my %slice_cache;
my $extf_adaptor = $self->db->get_ExternalFeatureAdaptor;
my $dbentry_adaptor = $self->db->get_DBEntryAdaptor;
my $ftype_adaptor = $self->db->get_FeatureTypeAdaptor;
my $dummy_analysis = new Bio::EnsEMBL::Analysis(-logic_name => 'REDflyProjection'); my $species = $self->db->species;
if(! $species){
throw('Must define a species to define the external_db');
}
($species = lc($species)) =~ s/ /_/;
foreach my $import_set(@{$self->import_sets}){
$self->log_header("Parsing $import_set data");
my %factor_cache; my %target_cache;
my $config = $self->{'config'}{$import_set};
my $fset = $self->{'feature_sets'}{$import_set};
my %gff_attrs = %{$config->{'gff_attrs'}};
my $file = $config->{'file'};
my $skipped = 0;
my $factor_cnt = 0;
my $factor_xref_cnt = 0;
my $feature_cnt = 0;
my $feature_target_cnt = 0;
open (FILE, "<$file") || die "Can't open $file";
<FILE>;
LINE: while (my $line = <FILE>) {
next if ($line =~ /^\s*\#/o || $line =~ /^\s*$/o);
chomp $line;
my %attr_cache;
my ($chromosome, undef, $feature, $start, $end, undef, undef, undef, $attrs) = split /\t/o, $line;
my @attrs = split/\;\s+/o, $attrs;
$start ++;
$end ++;
foreach my $gff_attr(keys %gff_attrs){
if(($attr_cache{$gff_attr}) = grep {/^${gff_attr}\=/} @attrs){
$attr_cache{$gff_attr} =~ s/(^${gff_attr}\=\")(.*)(\")/$2/;
}
else{
warn "Skipping import, unable to find mandatory $gff_attr attribute in:\t$line";
next LINE;
}
}
if(! exists $slice_cache{$chromosome}){
if($old_assembly){
$slice_cache{$chromosome} = $self->slice_adaptor->fetch_by_region('chromosome',
$chromosome,
undef,
undef,
undef,
$old_assembly);
}else{
$slice_cache{$chromosome} = $self->slice_adaptor->fetch_by_region('chromosome', $chromosome);
}
}
if(! defined $slice_cache{$chromosome}){
warn "Can't get slice $chromosome for motif $attr_cache{'ID'};\n";
$skipped++;
next;
}
my $feature_type;
if(exists $attr_cache{'Factor'}){
if(! exists $factor_cache{$attr_cache{'Factor'}}){
$factor_cache{$attr_cache{'Factor'}} = $ftype_adaptor->fetch_by_name($attr_cache{'Factor'});
if(! defined $factor_cache{$attr_cache{'Factor'}}){
my $desc = (exists $config->{'desc_suffix'}) ? $attr_cache{'Factor'}.$config->{'desc_suffix'} : undef;
($factor_cache{$attr_cache{'Factor'}}) = @{$ftype_adaptor->store(Bio::EnsEMBL::Funcgen::FeatureType->new
(
-name => $attr_cache{'Factor'},
-class => $fset->feature_type->class,
-description => $desc,
))};
$feature_type = $factor_cache{$attr_cache{'Factor'}};
$factor_cnt ++;
my $stable_id = $self->get_core_stable_id_by_display_name($self->db->dnadb, $attr_cache{'Factor'});
if(! defined $stable_id){
warn "Could not generate CODING xref for feature_type:\t". $attr_cache{'Factor'};
}else{
my $dbentry = Bio::EnsEMBL::DBEntry->new(
-dbname => $species.'_core_Gene',
-status => 'KNOWNXREF', - -db_display_name => 'EnsemblGene',
-type => 'MISC', -primary_id => $stable_id,
-display_id => $attr_cache{'Factor'},
-info_type => 'MISC',
-into_text => 'GENE',
-linkage_annotation => 'REDfly Coding'
);
$dbentry_adaptor->store($dbentry, $factor_cache{$attr_cache{'Factor'}}->dbID, 'FeatureType', 1);
$factor_xref_cnt ++;
}
}
}
}
else{
$feature_type = $fset->feature_type;
}
$feature = Bio::EnsEMBL::Funcgen::ExternalFeature->new
(
-display_label => $attr_cache{'ID'},
-start => $start,
-end => $end,
-strand => 0,
-feature_type => $feature_type,
-feature_set => $fset,
-slice => $slice_cache{$chromosome},
);
if ($new_assembly) {
$feature = $self->project_feature($feature, $new_assembly);
if(! defined $feature){
$skipped ++;
next;
}
}
($feature) = @{$extf_adaptor->store($feature)};
$feature_cnt++;
my $target = (exists $attr_cache{'Target'}) ? $attr_cache{'Target'} : (split/_/, $attr_cache{'ID'})[0];
my $stable_id;
if($target ne 'Unspecified'){
$stable_id = $self->get_core_stable_id_by_display_name($self->db->dnadb, $target);
}
if(! defined $stable_id){
warn "Could not generate TARGET xref for feature:\t". $attr_cache{'ID'} if $target ne 'Unspecified';
}
else{
my $dbentry = Bio::EnsEMBL::DBEntry->new(
-dbname => $species.'_core_Gene',
-status => 'KNOWNXREF',
- -db_display_name => 'EnsemblGene',
-type => 'MISC', -primary_id => $stable_id,
-display_id => $target,
-info_type => 'MISC',
-info_text => 'GENE',
-linkage_annotation => $fset->feature_type->name.' Target',
);
$dbentry_adaptor->store($dbentry, $feature->dbID, 'ExternalFeature', 1);
$feature_target_cnt ++;
}
}
close FILE;
$self->log("Loaded ".$fset->name);
$self->log("$factor_cnt feature types");
$self->log("$factor_xref_cnt feature type coding xrefs");
$self->log("$feature_cnt features");
$self->log("$feature_target_cnt feature target xrefs");
$self->log("Skipped $skipped features");
}
return;
}
1; } |