tutorials:perl:cmd_blast_.1.pl
- cmd_blast+.1.pl
#!/usr/bin/perl -w my $script_name = 'cmd_blast+.1.pl'; # Chih-Horng Kuo # generate commands for running NCBI blast+ # v1 2010/07/13 use strict; use warnings; use Getopt::Long; use File::Basename; my $exe; my $in_dir; my $out_dir; my $sh_dir; my $in_file_ext; my $out_file_ext; my $sh_prefix; my $opt; my $n_job; my $debug; GetOptions( "exe=s" => \$exe, "in_dir=s" => \$in_dir, "out_dir=s" => \$out_dir, "sh_dir=s" => \$sh_dir, "in_file_ext=s" => \$in_file_ext, "out_file_ext=s" => \$out_file_ext, "sh_prefix=s" => \$sh_prefix, "opt=s" => \$opt, "n_job=i" => \$n_job, "debug=i" => \$debug, ); $exe = $exe ? $exe : '/usr/local/blast+/bin/blastn'; $in_file_ext = $in_file_ext ? $in_file_ext : 'fasta'; $out_file_ext = $out_file_ext ? $out_file_ext : 'blast'; $sh_prefix = $sh_prefix ? $sh_prefix : 'job'; $n_job = $n_job ? $n_job : '1'; system "mkdir -p $out_dir" unless -e $out_dir; system "mkdir -p $sh_dir" unless -e $sh_dir; my $count = 0; my %job_id_HoA; # key = job_id, value = array of file_id opendir( DIR, $in_dir ) or die "can't open $in_dir: $!\n"; while ( defined( my $in_file = readdir(DIR) ) ) { if ( $in_file =~ /(\S+)\.$in_file_ext$/ ) { my $job_id = ( $count % $n_job ) + 1; push @{ $job_id_HoA{$job_id} }, $1; $count++; } } closedir(DIR); # generate job .sh foreach my $job_id ( sort keys %job_id_HoA ) { my $sh_file = $sh_dir . $sh_prefix . $job_id . '.sh'; open OUT, ">$sh_file" or die "Can't open output file $sh_file: $!\n"; # shell print OUT '#!/bin/bash', "\n"; foreach my $file_id ( @{ $job_id_HoA{$job_id} } ) { my $in_file = $in_dir . $file_id . '.' . $in_file_ext; my $out_file = $out_dir . $file_id . '.' . $out_file_ext; print OUT "$exe -query $in_file -out $out_file"; if ($opt) { print OUT " $opt"; } print OUT "\n"; } close OUT; system "chmod +x $sh_file"; } if ($debug) { } exit(0);
tutorials/perl/cmd_blast_.1.pl.txt · Last modified: 2012/06/15 00:29 by chkuo