<commit_before>#!/usr/bin/perl
package CQS::SmallRNACount;

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} = "_sc";
  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 ) = get_parameter( $config, $section );

  my $cqstools = get_cqstools( $config, $section, 1 );
  my $coordinate_file = get_param_file( $config->{$section}{coordinate_file}, "coordinate_file", 1 );

  my $r_script = dirname(__FILE__) . "/smallRNAPosition.R";
  if ( !-e $r_script ) {
    die "File not found : " . $r_script;
  }

  my $fastaFile = get_param_file( $config->{$section}{fasta_file}, "fasta_file", 0 );
  if ( defined $fastaFile ) {
    $option = $option . " -f $fastaFile";
  }

  my $ccaFile = parse_param_file( $config, $section, "cca_file", 0 );
  if ( defined $ccaFile ) {
    $option = $option . " --ccaFile $ccaFile";
  }

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

  my %seqcount_files = ();
  if ( has_raw_files( $config, $section, "seqcount" ) ) {
    %seqcount_files = %{ get_raw_files( $config, $section, "seqcount" ) };
  }

  my %fastqFiles = ();
  if ( has_raw_files( $config, $section, "fastq_files" ) ) {
    %fastqFiles = %{ get_raw_files( $config, $section, "fastq_files" ) };
  }

  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) . "\n";

  for my $sample_name ( sort keys %raw_files ) {
    my @bam_files      = @{ $raw_files{$sample_name} };
    my $bam_file       = $bam_files[0];
    my $final_file     = $sample_name . ".count";
    my $final_xml_file = $sample_name . ".count.mapped.xml";

    my $seqcountFile = "";
    if ( defined $seqcount_files{$sample_name} ) {
      my @seqcounts = @{ $seqcount_files{$sample_name} };
      my $seqcount  = $seqcounts[0];
      $seqcountFile = " -c $seqcount";
    }

    my $fastqFile = "";
    if ( defined $fastqFiles{$sample_name} ) {
      my @files = @{ $fastqFiles{$sample_name} };
      my $file  = $files[0];
      $fastqFile = " -q $file";
    }

    my $cur_dir = create_directory_or_die( $result_dir . "/$sample_name" );

    my $pbs_file = $self->get_pbs_filename( $pbs_dir, $sample_name );
    my $pbs_name = basename($pbs_file);
    my $log      = $self->get_log_filename( $log_dir, $sample_name );

    print $sh "\$MYCMD ./$pbs_name \n";

    my $log_desc = $cluster->get_log_description($log);

    my $pbs = $self->open_pbs( $pbs_file, $pbs_desc, $log_desc, $path_file, $cur_dir, $final_xml_file );
    print $pbs "mono $cqstools smallrna_count --newMethod $option -i $bam_file -g $coordinate_file $seqcountFile $fastqFile -o $final_file
";
    if ( $option !~ /noCategory/ ) {
      print $pbs "
for positionFile in *.position; do
  R --vanilla -f $r_script --args \$positionFile
done    
";<commit_msg>don't apply newMethod for gsnap search result<commit_after>#!/usr/bin/perl
package CQS::SmallRNACount;

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} = "_sc";
  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 ) = get_parameter( $config, $section );

  my $cqstools = get_cqstools( $config, $section, 1 );
  my $coordinate_file = get_param_file( $config->{$section}{coordinate_file}, "coordinate_file", 1 );

  my $r_script = dirname(__FILE__) . "/smallRNAPosition.R";
  if ( !-e $r_script ) {
    die "File not found : " . $r_script;
  }

  my $fastaFile = get_param_file( $config->{$section}{fasta_file}, "fasta_file", 0 );
  if ( defined $fastaFile ) {
    $option = $option . " -f $fastaFile";
  }

  my $ccaFile = parse_param_file( $config, $section, "cca_file", 0 );
  if ( defined $ccaFile ) {
    $option = $option . " --ccaFile $ccaFile";
  }

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

  my %seqcount_files = ();
  if ( has_raw_files( $config, $section, "seqcount" ) ) {
    %seqcount_files = %{ get_raw_files( $config, $section, "seqcount" ) };
  }

  my %fastqFiles = ();
  if ( has_raw_files( $config, $section, "fastq_files" ) ) {
    %fastqFiles = %{ get_raw_files( $config, $section, "fastq_files" ) };
  }

  my $newMethod = ( $option =~ /-e 4/ ) ? "" : "--newMethod";

  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) . "\n";

  for my $sample_name ( sort keys %raw_files ) {
    my @bam_files      = @{ $raw_files{$sample_name} };
    my $bam_file       = $bam_files[0];
    my $final_file     = $sample_name . ".count";
    my $final_xml_file = $sample_name . ".count.mapped.xml";

    my $seqcountFile = "";
    if ( defined $seqcount_files{$sample_name} ) {
      my @seqcounts = @{ $seqcount_files{$sample_name} };
      my $seqcount  = $seqcounts[0];
      $seqcountFile = " -c $seqcount";
    }

    my $fastqFile = "";
    if ( defined $fastqFiles{$sample_name} ) {
      my @files = @{ $fastqFiles{$sample_name} };
      my $file  = $files[0];
      $fastqFile = " -q $file";
    }

    my $cur_dir = create_directory_or_die( $result_dir . "/$sample_name" );

    my $pbs_file = $self->get_pbs_filename( $pbs_dir, $sample_name );
    my $pbs_name = basename($pbs_file);
    my $log      = $self->get_log_filename( $log_dir, $sample_name );

    print $sh "\$MYCMD ./$pbs_name \n";

    my $log_desc = $cluster->get_log_description($log);

    my $pbs = $self->open_pbs( $pbs_file, $pbs_desc, $log_desc, $path_file, $cur_dir, $final_xml_file );
    print $pbs "mono $cqstools smallrna_count $newMethod $option -i $bam_file -g $coordinate_file $seqcountFile $fastqFile -o $final_file
";
    if ( $option !~ /noCategory/ ) {
      print $pbs "
for positionFile in *.position; do
  R --vanilla -f $r_script --args \$positionFile
done    
";
{'fraction_non_alphanumeric': 0.17344461305007589, 'fraction_numerical': 0.002276176024279211, 'mean_word_length': 3.5770833333333334, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '4977147', 'n_tokens_mistral': 2632, 'n_tokens_neox': 2536, 'n_words': 564}