<commit_before>#!/usr/bin/perl
##################################################################################
#
# USAGE: perl tBlastx.pl [FASTA filename]
# Script output fasta records split into files  of 100 or less sequences in a directory called split. It also creates blastx bash scripts and qsub commands.
#  Created by <NAME> 12/30/13
#
##################################################################################
use strict;
use warnings;
use IO::File;
use File::Basename; # enable maipulating of the full path
use lib '/homes/bioinfo/bioinfo_software/perl_modules/File-Slurp-9999.19/lib';
use File::Slurp;
# use List::Util qw(max);
# use List::Util qw(sum);
use Getopt::Long;
use Pod::Usage;

###############################################################################
##############         Print informative message             ##################
###############################################################################
print "###########################################################\n";
print "#  tBlastx.pl Version 1.0                                 #\n";
print "#                                                         #\n";
print "#  Created by <NAME> 08/19/14                   #\n";
print "#  github.com/i5K-KINBRE-script-share                     #\n";
print "#  perl tBlastx.pl -help # for usage/options              #\n";
print "#  perl tBlastx.pl -man # for more details                #\n";
print "###########################################################\n";
###############################################################################
##############                get arguments                  ##################
###############################################################################

my $email;
my $max_target_seqs = 100;
my $evalue = 10;
my $h_rt = '6:00:00';
my $input_fasta;
my $man = 0;
my $help = 0;
GetOptions (
        'help|?' => \$help,
        'man' => \$man,
        'f|input_fasta_list:s' => \$input_fasta_list,
        't|max_target_seqs:i' => \$max_target_seqs,
        'e|evalue:s' => \$evalue,
        'h_rt:s' => \$h_rt,
        'm|email:s' => \$email,
)
or pod2usage(2);
pod2usage(1) if $help;
pod2usage(-exitstatus => 0, -verbose => 2) if $man;
sub quote { qq!"$_[0]"! } ## interpolate slurped text
my $dirname = dirname(__FILE__); # github directories (all github directories must be in the same directory)
##################################################################################
##############               get fullpath fasta                 ##################
##################################################################################
open (LIST, "<", $input_fasta) or die "can't open $input_fasta: $!";'
while (<LIST>)
{
    chomp;
    my (${filename}, ${directories}, ${suffix}) = fileparse($_,'\..*');
    my $script_file = "${directories}${filename}_tblastx.sh";
    my $tab_out = "${directories}${filename}_tblastx.txt";
    open (SCRIPT, ">", $script_file) or die "Can't open $script_file: $!";
    my $text_out = read_file("${dirname}/tBlastx_template.txt"); ## read shell template with slurp

    print SCRIPT eval quote($text_out);
    print SCRIPT "\n";
    close (SCRIPT);

    my $qsub =`qsub -l mem=1G,h_rt=${h_rt} -pe single 16 -m abe -M ${email} ${script_file}`;
    #print "qsub -l mem=1G,h_rt=${h_rt} -pe single 16 -m abe -M ${email} ${script_file}\n";
    print "$qsub\n";
}
print "Done\n";
##################################################################################
##############                  Documentation                   ##################
##################################################################################
## style adapted from http://www.perlmonks.org/?node_id=489861
__END__

=head1 NAME

tBlastx.pl - Script outputs fasta records split into files of 100 or less sequences in a directory called split. It also creates blastx bash scripts and qsub commands to annotate a de novo transcriptome with hits to the nr protein database.
 
File names should not include spaces.

=head1 USAGE

perl tBlastx.pl [options]

Documentation options:
    -help    brief help message
    -man	    full documentation
Required parameters:
    -f	    fasta to annotate with blastx
    -e	    email address 
Optional parameters:
    -t	     maximum sequences to report alignments for
    -e	     e-value
    --h_rt	 hours runtime in hh:mm:ss
 
=head1 OPTIONS

=over 8

=item B<-help>

Print a brief help message and exits.

=item B<-man>
<commit_msg>Update documentation<commit_after>#!/usr/bin/perl
##################################################################################
#
# USAGE: perl tBlastx.pl [FASTA filename]
# Script output fasta records split into files  of 100 or less sequences in a directory called split. It also creates blastx bash scripts and qsub commands.
#  Created by <NAME> 12/30/13
#
##################################################################################
use strict;
use warnings;
use IO::File;
use File::Basename; # enable maipulating of the full path
use lib '/homes/bioinfo/bioinfo_software/perl_modules/File-Slurp-9999.19/lib';
use File::Slurp;
# use List::Util qw(max);
# use List::Util qw(sum);
use Getopt::Long;
use Pod::Usage;

###############################################################################
##############         Print informative message             ##################
###############################################################################
print "###########################################################\n";
print "#  tBlastx.pl Version 1.0                                 #\n";
print "#                                                         #\n";
print "#  Created by <NAME> 08/19/14                   #\n";
print "#  github.com/i5K-KINBRE-script-share                     #\n";
print "#  perl tBlastx.pl -help # for usage/options              #\n";
print "#  perl tBlastx.pl -man # for more details                #\n";
print "###########################################################\n";
###############################################################################
##############                get arguments                  ##################
###############################################################################

my $email;
my $max_target_seqs = 100;
my $evalue = 10;
my $h_rt = '6:00:00';
my $input_fasta;
my $man = 0;
my $help = 0;
GetOptions (
        'help|?' => \$help,
        'man' => \$man,
        'f|input_fasta_list:s' => \$input_fasta_list,
        't|max_target_seqs:i' => \$max_target_seqs,
        'e|evalue:s' => \$evalue,
        'h_rt:s' => \$h_rt,
        'm|email:s' => \$email,
)
or pod2usage(2);
pod2usage(1) if $help;
pod2usage(-exitstatus => 0, -verbose => 2) if $man;
sub quote { qq!"$_[0]"! } ## interpolate slurped text
my $dirname = dirname(__FILE__); # github directories (all github directories must be in the same directory)
##################################################################################
##############               get fullpath fasta                 ##################
##################################################################################
open (LIST, "<", $input_fasta) or die "can't open $input_fasta: $!";'
while (<LIST>)
{
    chomp;
    my (${filename}, ${directories}, ${suffix}) = fileparse($_,'\..*');
    my $script_file = "${directories}${filename}_tblastx.sh";
    my $tab_out = "${directories}${filename}_tblastx.txt";
    open (SCRIPT, ">", $script_file) or die "Can't open $script_file: $!";
    my $text_out = read_file("${dirname}/tBlastx_template.txt"); ## read shell template with slurp

    print SCRIPT eval quote($text_out);
    print SCRIPT "\n";
    close (SCRIPT);

    my $qsub =`qsub -l mem=1G,h_rt=${h_rt} -pe single 16 -m abe -M ${email} ${script_file}`;
    #print "qsub -l mem=1G,h_rt=${h_rt} -pe single 16 -m abe -M ${email} ${script_file}\n";
    print "$qsub\n";
}
print "Done\n";
##################################################################################
##############                  Documentation                   ##################
##################################################################################
## style adapted from http://www.perlmonks.org/?node_id=489861
__END__

=head1 NAME

tBlastx.pl - Script outputs fasta records split into files of 100 or less sequences in a directory called split. It also creates blastx bash scripts and qsub commands to annotate a de novo transcriptome with hits to the nr protein database.
 
File names should not include spaces.

=head1 USAGE

perl tBlastx.pl [options]

Documentation options:
    -help    brief help message
    -man	    full documentation
Required parameters:
    -f	    list of fastas to annotate with blastx
    -e	    email address 
Optional parameters:
    -t	     maximum sequences to report alignments for
    -e	     e-value
    --h_rt	 hours runtime in hh:mm:ss
 
=head1 OPTIONS

=over 8

=item B<-help>

Print a brief help message and exits.

=item B<-man>

{'fraction_non_alphanumeric': 0.33637172076478433, 'fraction_numerical': 0.014006224988883948, 'mean_word_length': 3.6233299075025696, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3609046', 'n_tokens_mistral': 2700, 'n_tokens_neox': 2453, 'n_words': 721}