<commit_before>use strict;
use Getopt::Long;
use Pod::Usage;
use File::Basename;
use IPC::System::Simple qw(system);
use autodie qw(:all);

if (@ARGV == 0) {
    pod2usage(-verbose => 1);
}

my $runline = "running " . basename($0) . " " . join (" ", @ARGV) . "\n";

my $short_read_archive = 0;
my $search_fasta = 0;
my $ins_length = 300;
my $iterations = 5;
my $start_iter = 0;
my $help = 0;
my $log_file = 0;

GetOptions ('reads=s' => \$short_read_archive,
            'target=s' => \$search_fasta,
            'insert_length|ins_length=i' => \$ins_length,
            'iterations=i' => \$iterations,
            'start_iteration=i' => \$start_iter,
            'log_file=s' => \$log_file,
            'help|?' => \$help) or pod2usage(-msg => "GetOptions failed.", -exitval => 2);

if ($help) {
    pod2usage(-verbose => 1);
}

unless($short_read_archive and $search_fasta) {
    pod2usage(-msg => "Must specify a short read archive (that has already been prepared with 0-prepare_files.pl) and a target gene in fasta form.");
}

print $runline;

my $executing_path = dirname(__FILE__);

my $log_fh;
if ($log_file) {
	open $log_fh, ">", $log_file or die "couldn't open $log_file\n";
} else {
	$log_fh = *STDOUT;
}

my $cmd;
if ($start_iter > 0) {
	$search_fasta = "$short_read_archive.$start_iter.contigs.fa";
}

open OUT_FH, ">>", "$short_read_archive.all.fasta";

for (my $i=$start_iter; $i<$iterations; $i++) {
	print ("interation $i starting...\n");
	$cmd = "blastn -db $short_read_archive.db -query $search_fasta -outfmt 6 -num_threads 8 -out $short_read_archive.blast.$i";
	print $log_fh ("\t$cmd\n");
	system($cmd);

	$cmd = "perl ~/TRAM/2.5-sequenceretrieval.pl $short_read_archive.1.fasta $short_read_archive.2.fasta $short_read_archive.blast.$i";
	print $log_fh ("\t$cmd\n");
	system($cmd);

	$cmd = "velveth $short_read_archive.velvet 31 -fasta -shortPaired $short_read_archive.blast.$i.sorted.fasta";
	print $log_fh ("\t$cmd\n");
	system($cmd);

	$cmd = "velvetg $short_read_archive.velvet -ins_length $ins_length -exp_cov 30 -min_contig_lgth 200";
	print $log_fh ("\t$cmd\n");
	system($cmd);
	$search_fasta = "$short_read_archive.$i.contigs.fa";
	system ("mv $short_read_archive.velvet/contigs.fa $search_fasta");

	print OUT_FH `cat $search_fasta | gawk '{sub(/>/,">\$1"); print $0}'`;

	$cmd = "bash $executing_path/5.5-sort_contigs.sh $search_fasta";
	system($cmd);
<commit_msg>extra exit values<commit_after>use strict;
use Getopt::Long;
use Pod::Usage;
use File::Basename;
use IPC::System::Simple qw(system);
use autodie qw(:all);

if (@ARGV == 0) {
    pod2usage(-verbose => 1);
}

my $runline = "running " . basename($0) . " " . join (" ", @ARGV) . "\n";

my $short_read_archive = 0;
my $search_fasta = 0;
my $ins_length = 300;
my $iterations = 5;
my $start_iter = 0;
my $help = 0;
my $log_file = 0;

GetOptions ('reads=s' => \$short_read_archive,
            'target=s' => \$search_fasta,
            'insert_length|ins_length=i' => \$ins_length,
            'iterations=i' => \$iterations,
            'start_iteration=i' => \$start_iter,
            'log_file=s' => \$log_file,
            'help|?' => \$help) or pod2usage(-msg => "GetOptions failed.", -exitval => 2);

if ($help) {
    pod2usage(-verbose => 1);
}

unless($short_read_archive and $search_fasta) {
    pod2usage(-msg => "Must specify a short read archive (that has already been prepared with 0-prepare_files.pl) and a target gene in fasta form.");
}

print $runline;

my $executing_path = dirname(__FILE__);

my $log_fh;
if ($log_file) {
	open $log_fh, ">", $log_file or die "couldn't open $log_file\n";
} else {
	$log_fh = *STDOUT;
}

my $cmd;
if ($start_iter > 0) {
	$search_fasta = "$short_read_archive.$start_iter.contigs.fa";
}

open OUT_FH, ">>", "$short_read_archive.all.fasta";

for (my $i=$start_iter; $i<$iterations; $i++) {
	print ("interation $i starting...\n");
	$cmd = "blastn -db $short_read_archive.db -query $search_fasta -outfmt 6 -num_threads 8 -out $short_read_archive.blast.$i";
	print $log_fh ("\t$cmd\n");
	system([0,1,2], $cmd);

	$cmd = "perl ~/TRAM/2.5-sequenceretrieval.pl $short_read_archive.1.fasta $short_read_archive.2.fasta $short_read_archive.blast.$i";
	print $log_fh ("\t$cmd\n");
	system($cmd);

	$cmd = "velveth $short_read_archive.velvet 31 -fasta -shortPaired $short_read_archive.blast.$i.sorted.fasta";
	print $log_fh ("\t$cmd\n");
	system($cmd);

	$cmd = "velvetg $short_read_archive.velvet -ins_length $ins_length -exp_cov 30 -min_contig_lgth 200";
	print $log_fh ("\t$cmd\n");
	system($cmd);
	$search_fasta = "$short_read_archive.$i.contigs.fa";
	system ("mv $short_read_archive.velvet/contigs.fa $search_fasta");

	print OUT_FH `cat $search_fasta | gawk '{sub(/>/,">\$1"); print $0}'`;

	$cmd = "bash $executing_path/5.5-sort_contigs.sh $search_fasta";
	system($cmd);

{'fraction_non_alphanumeric': 0.1855863361799625, 'fraction_numerical': 0.01603832534888565, 'mean_word_length': 4.152360515021459, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, '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': '1939882', 'n_tokens_mistral': 1996, 'n_tokens_neox': 1885, 'n_words': 411}