<commit_before>
=head1 LICENSE

Copyright [1999-2016] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

=head1 CONTACT

  Please email comments or questions to the public Ensembl
  developers list at <http://lists.ensembl.org/mailman/listinfo/dev>.

  Questions may also be sent to the Ensembl help desk at
  <http://www.ensembl.org/Help/Contact>.

=head1 NAME

Bio::EnsEMBL::Funcgen::Hive::Utils

=head1 DESCRIPTION



=cut

package Bio::EnsEMBL::Funcgen::Hive::Utils;

use warnings;
use strict;

use Bio::EnsEMBL::Utils::Exception         qw( throw );
use Bio::EnsEMBL::Utils::Scalar            qw( assert_ref );  

use base qw( Exporter );
use vars qw( @EXPORT_OK );

@EXPORT_OK = qw(
  inject_DataflowRuleAdaptor_methods  
 ); 

sub inject_DataflowRuleAdaptor_methods{
  my $dfr_adaptor = shift;
  my $helper      = shift;
  
  assert_ref($dfr_adaptor, 'Bio::EnsEMBL::Hive::DBSQL::DataflowRuleAdaptor');
  
  if(defined $helper){
    assert_ref($helper, 'Bio::EnsEMBL::Funcgen::Utils::Helper', 'Helper');  
  }
  
  my $dfr_ref = ref($dfr_adaptor);
   
  if(! $dfr_adaptor->can('fetch_all_by_analysis_id')){      #inject method here   
  
    if($helper){
      $helper->debug(1, 'Injecting '.$dfr_ref..'::fetch_all_by_analysis_id');    
    }
    
    no strict 'refs';
  
    *{$dfr_ref.'::fetch_all_by_analysis_id'} = sub { 
      my $self    = shift;
      my $anal_id = shift;
      throw('Must provide and analysis id argument') if ! defined $anal_id;
      return $self->fetch_all("from_analysis_id=${anal_id}");
    }; 
   
    use strict;
  }
    
  if(! $dfr_adaptor->can('get_dataflow_config_by_analysis_id')){  #inject method here using fetch_all_by_analysis_id 
    

    if($helper){
      $helper->debug(1, 'Injecting '.$dfr_ref..'::get_dataflow_config_by_analysis_id');
    }
    
    no strict 'refs';
   
    *{$dfr_ref.'::get_dataflow_config_by_analysis_id'} = sub { 
      my $self    = shift;
      my $anal_id = shift;
      throw('Must provide and analysis id argument') if ! defined $anal_id;
      my %df_config;
        
      foreach my $dfr(@{$self->fetch_all_by_analysis_id($anal_id)}) {
        #$anal_id here always represents the from analysis
        
#         use Data::Dumper;
#         print Dumper($dfr->to_analysis);
        
        next if ($dfr->to_analysis->isa('Bio::EnsEMBL::Hive::Accumulator'));
        
        my $to_analysis = $dfr->to_analysis->logic_name;
          
        #Is it valid to wire to the same analysis using two different branches
        #We need to catch this and throw          
        if(exists $df_config{$to_analysis}){
          throw('It appears that the pipeline configuration for '.$to_analysis.
            " has been wired via two separate branches:\t".$dfr->branch_code.
            ' & '.$df_config{$to_analysis}{branch}.
            "\nDynamic branch dataflow currently only supports 1 assoicated branch");  
        }
          
        $df_config{$to_analysis} ||= {branch => $dfr->branch_code, funnel=>undef };<commit_msg>For the QC this must be able to cope with several dataflows to the same analysis. At least for now.<commit_after>
=head1 LICENSE

Copyright [1999-2016] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

=head1 CONTACT

  Please email comments or questions to the public Ensembl
  developers list at <http://lists.ensembl.org/mailman/listinfo/dev>.

  Questions may also be sent to the Ensembl help desk at
  <http://www.ensembl.org/Help/Contact>.

=head1 NAME

Bio::EnsEMBL::Funcgen::Hive::Utils

=head1 DESCRIPTION



=cut

package Bio::EnsEMBL::Funcgen::Hive::Utils;

use warnings;
use strict;

use Bio::EnsEMBL::Utils::Exception         qw( throw );
use Bio::EnsEMBL::Utils::Scalar            qw( assert_ref );  

use base qw( Exporter );
use vars qw( @EXPORT_OK );

@EXPORT_OK = qw(
  inject_DataflowRuleAdaptor_methods  
 ); 

sub inject_DataflowRuleAdaptor_methods{
  my $dfr_adaptor = shift;
  my $helper      = shift;
  
  assert_ref($dfr_adaptor, 'Bio::EnsEMBL::Hive::DBSQL::DataflowRuleAdaptor');
  
  if(defined $helper){
    assert_ref($helper, 'Bio::EnsEMBL::Funcgen::Utils::Helper', 'Helper');  
  }
  
  my $dfr_ref = ref($dfr_adaptor);
   
  if(! $dfr_adaptor->can('fetch_all_by_analysis_id')){      #inject method here   
  
    if($helper){
      $helper->debug(1, 'Injecting '.$dfr_ref..'::fetch_all_by_analysis_id');    
    }
    
    no strict 'refs';
  
    *{$dfr_ref.'::fetch_all_by_analysis_id'} = sub { 
      my $self    = shift;
      my $anal_id = shift;
      throw('Must provide and analysis id argument') if ! defined $anal_id;
      return $self->fetch_all("from_analysis_id=${anal_id}");
    }; 
   
    use strict;
  }
    
  if(! $dfr_adaptor->can('get_dataflow_config_by_analysis_id')){  #inject method here using fetch_all_by_analysis_id 
    

    if($helper){
      $helper->debug(1, 'Injecting '.$dfr_ref..'::get_dataflow_config_by_analysis_id');
    }
    
    no strict 'refs';
   
    *{$dfr_ref.'::get_dataflow_config_by_analysis_id'} = sub { 
      my $self    = shift;
      my $anal_id = shift;
      throw('Must provide and analysis id argument') if ! defined $anal_id;
      my %df_config;
        
      DFR: foreach my $dfr(@{$self->fetch_all_by_analysis_id($anal_id)}) {
        #$anal_id here always represents the from analysis
        
#         use Data::Dumper;
#         print Dumper($dfr->to_analysis);
        
        next if ($dfr->to_analysis->isa('Bio::EnsEMBL::Hive::Accumulator'));
        
        my $to_analysis = $dfr->to_analysis->logic_name;
          
        #Is it valid to wire to the same analysis using two different branches
        #We need to catch this and throw          
        
        if(exists $df_config{$to_analysis}){
	  # Skip, because we need this for the QC
	  next DFR;
          throw('It appears that the pipeline configuration for '.$to_analysis.
            " has been wired via two separate branches:\t".$dfr->branch_code.
            ' & '.$df_config{$to_analysis}{branch}.
            "\nDynamic branch dataflow currently only supports 1 assoicated branch");  
        }
          
        $df_config{$to_analysis} ||= {branch => $dfr->branch_code, funnel=>undef };
{'fraction_non_alphanumeric': 0.11272627537026879, 'fraction_numerical': 0.005211190345584202, 'mean_word_length': 3.132011331444759, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2753817', 'n_tokens_mistral': 2412, 'n_tokens_neox': 2307, 'n_words': 640}