<commit_before>#!/usr/bin/perl
package Homer::Annotation;

use strict;
use warnings;
use File::Basename;
use CQS::PBS;
use CQS::ConfigUtils;
use CQS::SystemUtils;
use CQS::FileUtils;
use CQS::Task;
use CQS::NGSCommon;
use CQS::StringUtils;

our @ISA = qw(CQS::Task);

sub new {
  my ($class) = @_;
  my $self = $class->SUPER::new();
  $self->{_name}   = __PACKAGE__;
  $self->{_suffix} = "_ha";
  bless $self, $class;
  return $self;
}

sub perform {
  my ( $self, $config, $section ) = @_;

  my ( $task_name, $path_file, $pbs_desc, $target_dir, $log_dir, $pbs_dir, $result_dir, $option, $sh_direct, $cluster, $thread ) = get_parameter( $config, $section );

  my %tagDirectories = %{ get_raw_files( $config, $section ) };

  my $rawFiles = get_raw_files( $config, $section );
  my $genome = get_option( $config, $section, "homer_genome" );

  my $shfile = $self->get_task_filename( $pbs_dir, $task_name );
  open( my $sh, ">$shfile" ) or die "Cannot create $shfile";
  print $sh get_run_command($sh_direct);

  for my $pairName ( sort keys %$rawFiles ) {
    my $files = $rawFiles->{$pairName};
    my $cur_dir  = create_directory_or_die( $result_dir . "/$pairName" );

    my $pbs_file = $self->get_pbs_filename( $pbs_dir, $pairName );
    my $pbs_name = basename($pbs_file);
    my $log      = $self->get_log_filename( $log_dir, $pairName );
    my $log_desc = $cluster->get_log_description($log);
    
    my $pbs = $self->open_pbs( $pbs_file, $pbs_desc, $log_desc, $path_file, $cur_dir );
    for my $file (@$files) {
      my $output    = basename($file);
      my $annoFile = $output . ".annotation.txt";
      my $annoStatsFile = $output . ".annotation.stats";
      print $pbs "if [ ! -s $annoFile ]; then
  findMotifsGenome.pl $file $genome $output/ $option
  annotatePeaks.pl $file $genome -annStats $annoStatsFile > $output/$annoFile
fi

";
    }
    $self->close_pbs( $pbs, $pbs_file );

    print $sh "\$MYCMD ./$pbs_name \n";
  }
  print $sh "exit 0\n";
  close $sh;

  if ( is_linux() ) {
    chmod 0755, $shfile;
  }

  print "!!!shell file $shfile created, you can run this shell file to submit all tasks.\n";
}

sub result {
  my ( $self, $config, $section, $pattern ) = @_;

  my ( $task_name, $path_file, $pbs_desc, $target_dir, $log_dir, $pbs_dir, $result_dir, $option, $sh_direct ) = get_parameter( $config, $section, 0 );

  my $rawFiles = get_raw_files( $config, $section );

  my $result = {};
  for my $pairName ( sort keys %$rawFiles ) {
    my $files        = $rawFiles->{$pairName};
    my @result_files = ();
    for my $file (@$files) {
      my $output    = basename($file);
      my $annoFile = $output . ".annotation.txt";
      my $annoStatsFile = $output . ".annotation.stats";
      push( @result_files, "${result_dir}/${output}/$annoFile" );
      push( @result_files, "${result_dir}/${output}/$annoStatsFile" );
      push( @result_files, "${result_dir}/${output}/homerResults.html" );
    }
    $result->{$pairName} = filter_array( \@result_files, $pattern );
  }
  return $result;
}

1;<commit_msg>result folder change<commit_after>#!/usr/bin/perl
package Homer::Annotation;

use strict;
use warnings;
use File::Basename;
use CQS::PBS;
use CQS::ConfigUtils;
use CQS::SystemUtils;
use CQS::FileUtils;
use CQS::Task;
use CQS::NGSCommon;
use CQS::StringUtils;

our @ISA = qw(CQS::Task);

sub new {
  my ($class) = @_;
  my $self = $class->SUPER::new();
  $self->{_name}   = __PACKAGE__;
  $self->{_suffix} = "_ha";
  bless $self, $class;
  return $self;
}

sub perform {
  my ( $self, $config, $section ) = @_;

  my ( $task_name, $path_file, $pbs_desc, $target_dir, $log_dir, $pbs_dir, $result_dir, $option, $sh_direct, $cluster, $thread ) = get_parameter( $config, $section );

  my %tagDirectories = %{ get_raw_files( $config, $section ) };

  my $rawFiles = get_raw_files( $config, $section );
  my $genome = get_option( $config, $section, "homer_genome" );

  my $shfile = $self->get_task_filename( $pbs_dir, $task_name );
  open( my $sh, ">$shfile" ) or die "Cannot create $shfile";
  print $sh get_run_command($sh_direct);

  for my $pairName ( sort keys %$rawFiles ) {
    my $files   = $rawFiles->{$pairName};
    my $cur_dir = create_directory_or_die( $result_dir . "/$pairName" );

    my $pbs_file = $self->get_pbs_filename( $pbs_dir, $pairName );
    my $pbs_name = basename($pbs_file);
    my $log      = $self->get_log_filename( $log_dir, $pairName );
    my $log_desc = $cluster->get_log_description($log);

    my $pbs = $self->open_pbs( $pbs_file, $pbs_desc, $log_desc, $path_file, $cur_dir );
    for my $file (@$files) {
      my $output        = basename($file);
      my $outputFolder  = scalar(@$files) == 1 ? "." : $output;
      my $annoFile      = $output . ".annotation.txt";
      my $annoStatsFile = $output . ".annotation.stats";
      print $pbs "if [ ! -s $outputFolder/$annoFile ]; then
  findMotifsGenome.pl $file $genome $outputFolder $option
  annotatePeaks.pl $file $genome -annStats $outputFolder/$annoStatsFile > $outputFolder/$annoFile
fi

";
    }
    $self->close_pbs( $pbs, $pbs_file );

    print $sh "\$MYCMD ./$pbs_name \n";
  }
  print $sh "exit 0\n";
  close $sh;

  if ( is_linux() ) {
    chmod 0755, $shfile;
  }

  print "!!!shell file $shfile created, you can run this shell file to submit all tasks.\n";
}

sub result {
  my ( $self, $config, $section, $pattern ) = @_;

  my ( $task_name, $path_file, $pbs_desc, $target_dir, $log_dir, $pbs_dir, $result_dir, $option, $sh_direct ) = get_parameter( $config, $section, 0 );

  my $rawFiles = get_raw_files( $config, $section );

  my $result = {};
  for my $pairName ( sort keys %$rawFiles ) {
    my $files        = $rawFiles->{$pairName};
    my @result_files = ();
    for my $file (@$files) {
      my $output        = basename($file);
      my $outputFolder  = scalar(@$files) == 1 ? "" : $output . "/";
      my $annoFile      = $output . ".annotation.txt";
      my $annoStatsFile = $output . ".annotation.stats";
      push( @result_files, "${result_dir}/${outputFolder}$annoFile" );
      push( @result_files, "${result_dir}/${outputFolder}$annoStatsFile" );
      push( @result_files, "${result_dir}/${outputFolder}homerResults.html" );
    }
    $result->{$pairName} = filter_array( \@result_files, $pattern );
  }
  return $result;
}

1;
{'fraction_non_alphanumeric': 0.1759656652360515, 'fraction_numerical': 0.002543315848036878, 'mean_word_length': 3.6572908956328645, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, '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': '776709', 'n_tokens_mistral': 2407, 'n_tokens_neox': 2325, 'n_words': 555}