-
Notifications
You must be signed in to change notification settings - Fork 2
/
bwa.cgi
executable file
·60 lines (52 loc) · 1.22 KB
/
bwa.cgi
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
#!/usr/bin/perl
use strict;
use CGI qw();
use File::Temp qw();
$CGI::POST_MAX = 50 * 1024 * 1024; #50MB
my $input_fh = CGI::param('fastq');
my $database = CGI::param('database');
my $args = CGI::param('args') || '';
#no args
if ( !$input_fh || !$database ) {
#load balancer request, ok
if ( -f "/data/ok" ) {
print CGI::header(-status=>200);
print CGI::header('text/plain');
print "OK\n";
exit(0);
}
#regular request, user error
else {
print CGI::header(-status=>400);
exit(0);
}
}
my $bytes = 0;
my $head = undef;
my (undef, $tempfile) = File::Temp::tempfile();
open( F, ">$tempfile.fq" );
if ( defined(fileno($input_fh)) ) {
while ( my $line = <$input_fh> ) {
$head ||= $line;
$bytes += length($line);
print F $line;
}
}
else {
$bytes += length($input_fh);
print F $input_fh;
}
close( F );
print STDERR "input_bytes=$bytes\nhead=$head";
system( "bwa mem $args /data/$database $tempfile.fq > $tempfile.out" ) == 0
or die "'bwa mem' exited with non zero code";
open( B, "$tempfile.out" );
print CGI::header('text/plain');
while ( my $line = <B> ) {
print $line;
if ( $line !~ m/^[@#]/ ) {
print STDERR "hit=$line";
}
}
unlink "$tempfile.fq";
unlink "$tempfile.out";