Skip to content
Snippets Groups Projects
Commit 39fbffe0 authored by Patrick Meidl's avatar Patrick Meidl
Browse files

added cleanup_tmpfiles(), create_tmpdir() can set directory, only create files...

added cleanup_tmpfiles(), create_tmpdir() can set directory, only create files that don't exist already
parent 7bd95fdc
No related branches found
No related tags found
No related merge requests found
......@@ -106,9 +106,11 @@ sub new {
=head2 create_tempdir
Arg[1] : String $tmpdir - temporary directory name
Example : $aligner->create_tempdir;
Description : Creates a temporary directory in /tmp with a semi-random name
(username.timestamp.randomnumber).
(username.timestamp.randomnumber). Alternatively, you can pass
it the name of a directory to use.
Return type : String - name of the tempdir created
Exceptions : Thrown if tempdir can't be created
Caller : general
......@@ -117,15 +119,23 @@ sub new {
sub create_tempdir {
my $self = shift;
my $tempdir = shift;
# create tmpdir to store input and output
my $user = `whoami`;
chomp $user;
my $tempdir = "/tmp/$user.".time.".".int(rand(1000));
$self->support->log("Creating tmpdir $tempdir...\n");
system("mkdir $tempdir") == 0 or
$self->support->log_error("Can't create tmp dir $tempdir: $!\n");
$self->support->log("Done.\n");
if ($tempdir) {
unless (-d $tempdir) {
$self->support->log_error("Can't find tempdir $tempdir: $!");
}
} else {
# create tmpdir to store input and output
my $user = `whoami`;
chomp $user;
$tempdir = "/tmp/$user.".time.".".int(rand(1000));
$self->support->log("Creating tmpdir $tempdir...\n");
system("mkdir $tempdir") == 0 or
$self->support->log_error("Can't create tmp dir $tempdir: $!\n");
$self->support->log("Done.\n");
}
$self->tempdir($tempdir);
return $tempdir;
......@@ -168,19 +178,23 @@ sub write_sequence {
my $tmpdir = $self->tempdir;
my $fh = $self->support->filehandle('>', "$tmpdir/$basename1.fa");
print $fh join(':', ">$basename1 dna:chromfrag chromosome",
$assembly,
$slice->start,
$slice->end,
$slice->strand
), "\n";
print $fh $slice->get_repeatmasked_seq(undef, 1)->seq, "\n";
close($fh);
unless (-e "$tmpdir/$basename1.fa") {
my $fh = $self->support->filehandle('>', "$tmpdir/$basename1.fa");
print $fh join(':', ">$basename1 dna:chromfrag chromosome",
$assembly,
$slice->start,
$slice->end,
$slice->strand
), "\n";
print $fh $slice->get_repeatmasked_seq(undef, 1)->seq, "\n";
close($fh);
}
# convert fasta to nib (needed for lavToAxt)
system($self->bindir."/faToNib $tmpdir/$basename1.fa $tmpdir/$basename1.nib") == 0
or $self->support->log_error("Can't run faToNib: $!\n");
unless (-e "$tmpdir/$basename1.nib") {
system($self->bindir."/faToNib $tmpdir/$basename1.fa $tmpdir/$basename1.nib") == 0
or $self->support->log_error("Can't run faToNib: $!\n");
}
if ($basename2) {
system("cat $tmpdir/$basename1.fa >> $tmpdir/$basename2.fa") == 0 or
......@@ -192,7 +206,7 @@ sub write_sequence {
Arg[1] : String $A_basename - basename of alternative fasta file
Arg[2] : String $R_basename - basename of reference fasta file
Example : $aligner->run_blastz('A_seq.1', 'R_seq.1');
Example : $aligner->run_blastz('alt_seq.1', 'ref_seq.1');
Description : Runs blastz between an alternative and multiple reference
sequences.
Return type : none
......@@ -210,8 +224,10 @@ sub run_blastz {
my $blastz_cmd = qq($bindir/blastz $tmpdir/$A_basename.fa $tmpdir/$R_basename.fa Q=blastz_matrix.txt T=0 L=10000 H=2200 Y=3400 > $tmpdir/blastz.$id.lav);
system($blastz_cmd) == 0 or
unless (-e "$tmpdir/blastz.$id.lav") {
system($blastz_cmd) == 0 or
$self->support->log_error("Can't run blastz: $!\n");
}
}
=head2 lav_to_axt
......@@ -232,7 +248,9 @@ sub lav_to_axt {
my $tmpdir = $self->tempdir;
my $id = $self->id;
system($self->bindir."/lavToAxt $tmpdir/blastz.$id.lav $tmpdir $tmpdir $tmpdir/blastz.$id.axt") == 0 or $self->support->log_error("Can't run lavToAxt: $!\n");
unless (-e "$tmpdir/blastz.$id.axt") {
system($self->bindir."/lavToAxt $tmpdir/blastz.$id.lav $tmpdir $tmpdir $tmpdir/blastz.$id.axt") == 0 or $self->support->log_error("Can't run lavToAxt: $!\n");
}
}
=head2 find_best_alignment
......@@ -252,7 +270,9 @@ sub find_best_alignment {
my $tmpdir = $self->tempdir;
my $id = $self->id;
system($self->bindir."/axtBest $tmpdir/blastz.$id.axt all $tmpdir/blastz.$id.best.axt") == 0 or $self->support->log_error("Can't run axtBest: $!\n");
unless (-e "$tmpdir/blastz.$id.best.axt") {
system($self->bindir."/axtBest $tmpdir/blastz.$id.axt all $tmpdir/blastz.$id.best.axt") == 0 or $self->support->log_error("Can't run axtBest: $!\n");
}
}
=head2 parse_blastz_output
......@@ -298,7 +318,7 @@ sub parse_blastz_output {
my %coords;
@coords{'R_id', 'A_start', 'A_end', 'R_start', 'R_end', 'strand'} =
(split(/ /, $header))[4, 2, 3, 5, 6, 7];
$coords{'R_id'} =~ s/R_seq\.(.*)/$1/;
$coords{'R_id'} =~ s/ref_seq\.(.*)/$1/;
($coords{'strand'} eq '+') ? ($coords{'strand'} = 1) :
($coords{'strand'} = -1);
for (my $j = 0; $j < scalar(@A_arr); $j++) {
......@@ -329,6 +349,35 @@ sub parse_blastz_output {
}
}
=head2 cleanup_tmpfiles
Arg[1-N] : (optional) list @files - additional tmp files to delete
Example : $self->cleanup_tmpfiles('e_seq.fa', 'v_seq.fa');
Description : deletes temporary files
Return type : none
Exceptions : Warning if file cannot be deleted
Caller : general
Status : stable
=cut
sub cleanup_tmpfiles {
my $self = shift;
my @files = @_;
my $tmpdir = $self->tempdir;
my $id = $self->id;
push @files,
"blastz.$id.lav",
"blastz.$id.axt",
"blastz.$id.best.axt";
foreach my $file (@files) {
unlink("$tmpdir/$file") or $self->support->log_warning("Couldn't delete file $file: $!");
}
}
=head2 found_match
Arg[1] : Boolean $match_flag - flag indicating if last bp was a match
......@@ -531,8 +580,8 @@ sub write_assembly {
my $alt_chr_map = $self->support->get_ensembl_chr_mapping($R_dba, $self->support->param('assembly'));
my $sth = $R_dbh->prepare(qq(
INSERT INTO assembly (asm_seq_region_id, cmp_seq_region_id, asm_start,
asm_end, cmp_start, cmp_end, ori)
INSERT IGNORE INTO assembly (asm_seq_region_id, cmp_seq_region_id,
asm_start,asm_end, cmp_start, cmp_end, ori)
VALUES (?, ?, ?, ?, ?, ?, ?)
));
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment