<commit_before>package Bio::EnsEMBL::Funcgen::RunnableDB::PeakCalling::FindControlExperiments;

use strict;
use base 'Bio::EnsEMBL::Hive::Process';
use Data::Dumper;
use Bio::EnsEMBL::Funcgen::PeakCallingPlan::ExecutionPlanUtils qw (
    lock_execution_plan
    resolve_nonterminal_symbols
);

use Bio::EnsEMBL::Funcgen::PeakCallingPlan::Constants qw ( :all );

use constant {

  BRANCH_SIGNALS                  => 2,
  BRANCH_CONTROLS                 => 3,
  BRANCH_SIGNALS_WITHOUT_CONTROLS => 4,

};

sub run {

  my $self = shift;
  my $species             = $self->param_required('species');
  my $execution_plan_list = $self->param_required('execution_plan_list');
  
  $self->say_with_header("Got " . scalar @$execution_plan_list . " execution plans.", 1);
  
  my %found_control_alignments;
  my %plan_depending_on_control;
  my @signal_experiments_without_controls;
  
  EXECUTION_PLAN:
  foreach my $current_execution_plan (@$execution_plan_list) {

    my $meta_data = $current_execution_plan->{meta_data};
    
    if (
         ( $meta_data->{experiment_is_control}  ne TRUE  )
      && ( $meta_data->{experiment_has_control} eq FALSE )
    ) {
      push 
        @signal_experiments_without_controls, 
        $current_execution_plan;

      next EXECUTION_PLAN;
    }

    my $current_execution_plan_expanded = resolve_nonterminal_symbols($current_execution_plan);
    lock_execution_plan($current_execution_plan_expanded);
    
    my $alignment_plans = $current_execution_plan_expanded->{alignment};
    
    ALIGNMENT_PLAN:
    foreach my $alignment_name (keys %$alignment_plans) {
    
      my $alignment_plan = $alignment_plans->{$alignment_name};
      
      my $want_this
        =    
             ( $alignment_plan->{name}     ne NO_CONTROL_FLAG             )
          && ( $alignment_plan->{is_control}                              )
          && ( $alignment_plan->{analysis} eq REMOVE_DUPLICATES_ANALYSIS  )
      ;
      if (! $want_this) {
        next ALIGNMENT_PLAN;
      }
      $found_control_alignments{$alignment_name} = $alignment_plan;
      
      if (! exists $plan_depending_on_control{$alignment_name}) {
        $plan_depending_on_control{$alignment_name} = []
      }
      push $plan_depending_on_control{$alignment_name}, $current_execution_plan;
    }
  }

  $self->dataflow_output_id(
    {
      'execution_plan_list' => \@signal_experiments_without_controls,<commit_msg>Avoid 'Experimental push on scalar now forbidden' error<commit_after>package Bio::EnsEMBL::Funcgen::RunnableDB::PeakCalling::FindControlExperiments;

use strict;
use base 'Bio::EnsEMBL::Hive::Process';
use Data::Dumper;
use Bio::EnsEMBL::Funcgen::PeakCallingPlan::ExecutionPlanUtils qw (
    lock_execution_plan
    resolve_nonterminal_symbols
);

use Bio::EnsEMBL::Funcgen::PeakCallingPlan::Constants qw ( :all );

use constant {

  BRANCH_SIGNALS                  => 2,
  BRANCH_CONTROLS                 => 3,
  BRANCH_SIGNALS_WITHOUT_CONTROLS => 4,

};

sub run {

  my $self = shift;
  my $species             = $self->param_required('species');
  my $execution_plan_list = $self->param_required('execution_plan_list');
  
  $self->say_with_header("Got " . scalar @$execution_plan_list . " execution plans.", 1);
  
  my %found_control_alignments;
  my %plan_depending_on_control;
  my @signal_experiments_without_controls;
  
  EXECUTION_PLAN:
  foreach my $current_execution_plan (@$execution_plan_list) {

    my $meta_data = $current_execution_plan->{meta_data};
    
    if (
         ( $meta_data->{experiment_is_control}  ne TRUE  )
      && ( $meta_data->{experiment_has_control} eq FALSE )
    ) {
      push 
        @signal_experiments_without_controls, 
        $current_execution_plan;

      next EXECUTION_PLAN;
    }

    my $current_execution_plan_expanded = resolve_nonterminal_symbols($current_execution_plan);
    lock_execution_plan($current_execution_plan_expanded);
    
    my $alignment_plans = $current_execution_plan_expanded->{alignment};
    
    ALIGNMENT_PLAN:
    foreach my $alignment_name (keys %$alignment_plans) {
    
      my $alignment_plan = $alignment_plans->{$alignment_name};
      
      my $want_this
        =    
             ( $alignment_plan->{name}     ne NO_CONTROL_FLAG             )
          && ( $alignment_plan->{is_control}                              )
          && ( $alignment_plan->{analysis} eq REMOVE_DUPLICATES_ANALYSIS  )
      ;
      if (! $want_this) {
        next ALIGNMENT_PLAN;
      }
      $found_control_alignments{$alignment_name} = $alignment_plan;
      
      if (! exists $plan_depending_on_control{$alignment_name}) {
        $plan_depending_on_control{$alignment_name} = []
      }
      push @{$plan_depending_on_control{$alignment_name}}, $current_execution_plan;
    }
  }

  $self->dataflow_output_id(
    {
      'execution_plan_list' => \@signal_experiments_without_controls,
{'fraction_non_alphanumeric': 0.10774892659987732, 'fraction_numerical': 0.001635657329789409, 'mean_word_length': 3.2391681109185444, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2146279', 'n_tokens_mistral': 1716, 'n_tokens_neox': 1589, 'n_words': 226}