-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbsuit
executable file
·127 lines (109 loc) · 3.68 KB
/
bsuit
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
#!/usr/bin/env perl
use strict;
use warnings;
use File::Spec;
use FindBin qw($RealBin);
if ( $FindBin::VERSION < 1.51 ) {
warn "[!]Your Perl is too old, thus there can only be ONE `bsuit` file in your PATH. [FindBin Version: $FindBin::VERSION < 1.51]\n\n";
}
FindBin::again();
use lib "$RealBin/lib";
require BSuitLib;
use Galaxy::IO::INI;
use Galaxy::Data;
use Data::Dump qw(ddx);
my %Cmd2Fun = (
'prepare' => \&do_pre,
'aln' => \&do_aln,
'grep' => \&do_grep,
'analyse' => \&do_analyse,
'check' => \&do_check,
'patch' => \&do_patch
);
my @CmdOrder = qw(prepare aln grep analyse);
sub ShowHelp() {
die '[!]Available Commands are: [', join( '],[', @CmdOrder ), "], case insensitive.\n";
}
my $ShowHelp = 0;
if ( @ARGV < 2 ) {
warn "Usage: $0 <command> <config_file>\n";
ShowHelp();
}
my $cmd = lc shift;
my $cfgfile = shift;
my $base4 = shift;
our $fullcfgfile = File::Spec->rel2abs($cfgfile);
our $FileData = 'DataFiles';
die "[!]Config File [$cfgfile] NOT found !\n" unless -f $cfgfile;
if ( defined $base4 ) {
warn "[!]Switch to use simulated WGS data.\n";
$FileData = 'Base4Files';
}
unless ( exists $Cmd2Fun{$cmd} ) {
warn "[x]Unknown Command: [$cmd] !\n";
ShowHelp();
}
our $minHostDepth = 10;
our $minSoftClip = 10;
our $methly3BaseErrRate = 0.08;
our $posAround = 3;
our $minVirLen = 5;
our $minVirMapLen = 5;
our $DEVELOP = 0;
our $DEBUG = 0;
our $FORCE_UNMETH = 0;
our $GrepMergeBetter = 1;
our $ResultMergeRange = 10;
our $EnableWretchedSequel = 1;
our $idbacmd = '--max_gap 100 --min_region 31 --min_contig 31 --mink 17 --maxk 89 --step 20';
our $PathPrefix = "PATH=\"$RealBin/bin:\$PATH\";";
our $Config = Galaxy::IO::INI->new();
$Config->read($cfgfile);
warn "[!]Runing $0 [$cmd].\n";
our $RootPath = $Config->{'Output'}->{'WorkDir'};
$RootPath =~ s/[\/\\]+$//g;
our $ProjectID = $Config->{'Output'}->{'ProjectID'};
warn "[!] Working on: [$ProjectID] @ [$RootPath]\n";
our $Aligner = $Config->{'Parameters'}->{'Aligner'} || 'bwa-meth';
our $MinVirusLength = $Config->{'Parameters'}->{'MinVirusLength'} || 20;
warn "[!] Aligner is [$Aligner]. Min Virus Length is $MinVirusLength.\n";
if ( grep /^sv1$/i, @ARGV ) {
my @SDs = grep /\.SD$/, keys( %{ $Config->{'InsertSizes'} } );
for (@SDs) {
$Config->{'InsertSizes'}->{$_} = 1;
}
warn "[!] All ", scalar(@SDs), " SD(s) are set to 1.\n";
}
unless ( -f "$RealBin/bin/water" ) {
die "[x] Cannot find \"$RealBin/bin/water\" !\n";
}
our $HostRefName = basename( $Config->{'RefFiles'}->{'HostRef'} );
our $VirusRefName = basename( $Config->{'RefFiles'}->{'VirusRef'} );
our $RefFilesSHA = getFilesHash( $HostRefName, $VirusRefName );
our $RefConfig = Galaxy::IO::INI->new();
our ( %RefChrIDs, %VirusChrIDs, %Qual2LgP );
if ( $cmd ne 'prepare' ) {
if ( -f "$RootPath/Ref/Ref.ini" ) {
$RefConfig->read("$RootPath/Ref/Ref.ini");
}
else { die "[x] Prepare INI not found ! [$RootPath/Ref/Ref.ini]\n"; }
my @RefChrID = split( ',', $RefConfig->{$RefFilesSHA}->{'RefChrIDs'} );
my @VirusChrID = split( ',', $RefConfig->{$RefFilesSHA}->{'VirusChrIDs'} );
for (@RefChrID) {
$RefChrIDs{$_} = $RefConfig->{$RefFilesSHA}->{$_};
}
$VirusChrIDs{$_} = $RefConfig->{$RefFilesSHA}->{$_} for @VirusChrID;
for my $q ( 1 .. 50 ) {
my $qchr = chr( 33 + $q );
my $err = 10**( -$q / 10 );
my $p = 1 - $err;
my $lgp = log($p) / log(10);
my $lgtq = log( $err / 3 ) / log(10);
my $lgbp = log( $p / 2 ) / log(10);
my $lgbq = log( $err / 2 ) / log(10);
my ( $v1, $v2, $v3, $v4 ) = ( -10 * $lgp, -10 * $lgtq, -10 * $lgbp, -10 * $lgbq );
$Qual2LgP{$qchr} = [ $q, $v1 - $v2, $v2, $v3, $v4 ];
}
}
$Cmd2Fun{$cmd}(@ARGV);
warn "[!]done !\n";