File: createAugustusJoblist.pl

package info (click to toggle)
augustus 3.5.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 777,036 kB
  • sloc: cpp: 80,063; perl: 21,491; python: 4,368; ansic: 1,244; makefile: 1,126; sh: 171; javascript: 32
file content (192 lines) | stat: -rwxr-xr-x 7,504 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/usr/bin/perl
#
# createAugustusJoblist.pl
# Create a joblist with overlapping sequence chunks from multiple fasta files.
#
# This script is used by the braker.pl pipeline.
# Please be extremely careful when changing this script because the braker.pl
# pipeline may fail upon custom modification of this script.
# In case of doubt, contact katharina.hoff@uni-greifswald.de 
#
# Mario Stanke & Katharina J. Hoff, last changes on Dec 6 2021
#
#

use strict;
use Getopt::Long;

my $usage = "$0 -- Create a joblist with sequence chunks from multiple fasta files.\n\n";
$usage .= "Usage: $0\n\n";
$usage .= "parameters:\n";
$usage .= "--sequences seqs.lst input sequences, format: each line contains one sequence including the full path and its size, e.g.\n";
$usage .= "                     /cluster/data/panTro2/1/chr1.fa\t1\t229974691\n";
$usage .= "                     /cluster/data/panTro2/1/chr1_random\t1\t9420409\n";
$usage .= "                     /cluster/data/panTro2/2/chr2a\t1\t114460064\n";
$usage .= "                     or\n";
$usage .= "                     /cluster/data/panTro2/1/chr1_random\t/hints/chr1_random\t1\t9420409\n";
$usage .= "                     /cluster/data/panTro2/2/chr2a\t/hints/chr2a\t1\t114460064\n";
$usage .= "--outputdir s        directory, in which later the AUGUSTUS output will be written.\n";
$usage .= "--command s          AUGUSTUS command, e.g. \"augustus --species=human --maxDNAPieceSize=600000\".\n";
$usage .= "--joblist job.lst    filename with list of jobs as given to parasol.\n";
$usage .= "--chunksize n        chunk size. Each sequence is (imaginarily) cut into chunks of this size\n\n";
$usage .= "options:\n";
$usage .= "--overlap n          overlap. Neighboring chunks overlap by this number of bases.\n";
$usage .= "--padding n          padding on both sides (default 0).\n";
$usage .= "--errordir errdir    directory, in which later the AUGUSTUS error messages will be written.\n";
$usage .= "--check              insert parasol input/output checks.\n";
$usage .= "--wrap=s             have each job in a separate file, preceded by command s.\n";
$usage .= "--jobprefix=s        prefix of job name (default: \"job.\")\n";
$usage .= "--partitionHints     partition hints files according to genomic locus of single augustus runs,\n";
$usage .= "                     add a command to the augustus job that will create and delete this hints file\n";
$usage .= "                     in the output directory of the augustus job. This option also will automatically\n";
$usage .= "                     delete empty error files of augustus.\n";

if ( @ARGV < 2 ) {
    print $usage;
    exit;
}

my ($seqfilename, $chunksize,    $overlap, $outputdir, $errordir,
    $command,     $joblist,      $seqnr,   $name,      $predStart,
    $predEnd,     $pE,           $chunkid, $padding,   $check,
    $wrap,        $wholecommand, $partitionHints,      $localHints
);
my $jobnr = 0;
$padding = 0;
$check   = 0;
$wrap    = "";
my $jobprefix = "job.";

GetOptions(
    'sequences=s' => \$seqfilename,
    'chunksize=i' => \$chunksize,
    'overlap:i'   => \$overlap,
    'outputdir=s' => \$outputdir,
    'errordir=s'  => \$errordir,
    'command=s'   => \$command,
    'padding:i'   => \$padding,
    'joblist=s'   => \$joblist,
    'check!'      => \$check,
    'wrap=s'      => \$wrap,
    'jobprefix:s' => \$jobprefix,
    'partitionHints!' => \$partitionHints
);

die("Need to specify chunksize.\n") unless ( defined $chunksize );
die("Need to specify command.\n")   unless ( defined $command );
die("Need to specify joblist.\n")   unless ( defined $joblist );
die("Need to specify chunksize.\n") unless ( defined $chunksize );
die("Need to specify outputdir.\n") unless ( defined $outputdir );

open( SEQ,   "<$seqfilename" ) or die("Could not open $seqfilename");
open( BATCH, ">$joblist" )     or die "Couldn't open $joblist\n";

$outputdir =~ s/\/$//;
$seqnr = 1;
while (<SEQ>) {
    my ( $path, $start, $end, $hints );
    if (/(.+)\s+(.+)\s+(.+)\s+(.+)/) {
        $path  = $1;
        $hints = $2;
        $start = $3;
        $end   = $4;
    }
    elsif (/(.+)\s+(.+)\s+(.+)/) {
        $path  = $1;
        $start = $2;
        $end   = $3;
        undef $hints;
    }
    $start -= $padding;
    $end += $padding;

    my $ovlp;
    if ( !$overlap ) {
        $ovlp = ( ( $chunksize > 3000000 ) ? 500000 : $$chunksize / 6 );
    }
    else {
        $ovlp = $overlap;
    }
    my $chunknr = 0;
    $name = $path;
    $name =~ s/.*\///;
    $predEnd = -1;
    for (
        $predStart = $start;
        $predStart <= $end && $predEnd < $end;
        $predStart = $predEnd + 1 - $ovlp
        )
    {
        $chunknr++;
        $predEnd = $predStart + $chunksize - 1;
        $pE      = $predEnd;
        if ( $pE > $end ) {
            $pE = $end;
        }
        $chunkid = sprintf( "%03d", $chunknr );
        my $gfffilename = "$outputdir/$seqnr.$chunkid.${name}.$predStart..$pE.gff";
        if($gfffilename=~m/\;/){
            $gfffilename=s/\;/\\\;/;
        }
        my $errorfilename;
        if($errorfilename=~m/\;/){
            $errorfilename=~s/\;/\\\;/;
        }
        if ( defined $errordir ) {
            $errorfilename = "$errordir/$seqnr.$chunkid.${name}.$predStart..$pE.err";
        }
        else {
            $errorfilename = "$outputdir/$seqnr.$chunkid.${name}.$predStart..$pE.err";
        }
        $wholecommand = "";
        if( $partitionHints ) {
            $localHints = "$outputdir/$seqnr.$chunkid.${name}.$predStart..$pE.hints";
            if($localHints=~m/\;/){
                $localHints=~s/\;/\\\;/;
            }
            my $locus = ${name};
            $locus =~ s/(.*)\..*/$1/;
            $wholecommand .= "grep \"^$locus\" $hints | awk ' {if (\$4 >= $predStart ) print \$0 } ' | awk ' {if (\$5 <= $pE) print \$0 } ' > $localHints\n";
        } else {
            $localHints = $hints;
        }
        $wholecommand .= $command;
        if ( defined $hints ) {
            if ($check) {
                $wholecommand .= " --hintsfile={check in exists $localHints}";
            }
            else {
                $wholecommand .= " --hintsfile=$localHints";
            }
        }
        if ($check) {
            $wholecommand .= " --predictionStart=$predStart --predictionEnd=$pE"
                          . " {check in line+ $path} "
                          . "--outfile={check out line+ $gfffilename} "
                          . "--errfile=$errorfilename\n";
        }
        else {
            $wholecommand .= " --predictionStart=$predStart --predictionEnd=$pE"
                          . " $path --outfile=$gfffilename "
                          . "--errfile=$errorfilename\n";
        }
        if( $partitionHints ) {
            $wholecommand .= "if [ -e $outputdir/$seqnr.$chunkid.${name}.$start..$end.hints ]\nthen\nrm $outputdir/$seqnr.$chunkid.${name}.$start..$end.hints\nfi\n";
            # for braker.pl (where we use partitionHints) I want to delete empty error files
            $wholecommand .= "if [ ! -s $errorfilename ]; then rm -f $errorfilename;fi\n";
        }
        if ( $wrap eq "" ) {
            print BATCH $wholecommand;
        }
        else {
            $jobnr++;
            my $jobname = "$jobprefix$jobnr";
            open( JOB, ">$jobname" );
            print JOB "$wrap\n" . $wholecommand;
            print BATCH "$jobname\n";
            close JOB;
            system("chmod +x $jobname");
        }
    }
    $seqnr++;
}