-
Notifications
You must be signed in to change notification settings - Fork 0
/
LR_0_StrucVar.pl
167 lines (135 loc) · 5.06 KB
/
LR_0_StrucVar.pl
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
#!/usr/bin/perl -w
#use strict;
use Getopt::Long;
use FindBin qw($Bin $Script);
use File::Basename qw(basename dirname);
use File::Path qw(make_path);
use Data::Dumper;
use Cwd qw(abs_path);
&usage if @ARGV<1;
sub usage {
my $usage = << "USAGE";
This pipeline is designed for calling SVs from long-reads sequencing data.
Author: ywzhang0713\@gmail.com Yuwei ZHANG
Usage: $0 config.txt
USAGE
print "$usage";
exit(1);
};
my $conf=shift;
my %conf;
&load_conf($conf, \%conf);
my $all='all: ';
my $mk;
my $thread = $conf{THREAD};
my $out = abs_path($conf{OUTDIR});
my $sample_f = abs_path($conf{SAMPLE});
#sample file should be in the below format:
#id sequencing_platform input_path
my $step1 = "";
my $step2 = "";
my $step3 = "";
my $step4 = "";
my $step5 = "";
my $mode = $conf{SNIFFLES_MODE};
#### write you things ###
my $sample_size = 0;
my %allsample;
make_path abs_path($conf{OUTDIR});
my $bsub = "";
my $group = $conf{GROUP};
my $q = $conf{QUEUE};
open IN,"$sample_f" || die $!;
while(<IN>){
chomp;
my @t = split /\t/;
my $id = shift @t;
my $pltform = $t[0];
my $input = abs_path($t[1]);
$step1 = "$conf{MINIMAP2} --MD -t $thread -ax $pltform $conf{INDEX} $input 2> $out/$id/00_mapping/$id.minimap2.log | $conf{SAMTOOLS} view -@ $thread -bS | $conf{SAMTOOLS} sort -@ $thread -o $out/$id/00_mapping/$id.minimap2.align.bam && $conf{SAMTOOLS} index -@ $thread $out/$id/00_mapping/$id.minimap2.align.bam";
$step2 = "$conf{SNIFFLES} --input $out/$id/00_mapping/$id.minimap2.align.bam --vcf $out/$id/01_SVcall/$id.vcf.gz --snf $out/$id/01_SVcall/$id.snf 1> $out/$id/01_SVcall/$id.sniffles.log 2> $out/$id/01_SVcall/$id.sniffles.err";
my $sniffles_version = `$conf{SNIFFLES} --version`;
my $mosaic = "--mosaic";
if(grep(/2.2/, $sniffles_version))
{
$mosaic = "--mosaic";
# print "yes";
}else{
$mosaic = "--non-germline";
# print "no";
}
$step3 = "$conf{SNIFFLES} --input $out/$id/00_mapping/$id.minimap2.align.bam --vcf $out/$id/02_SVcall_mosaic/$id.vcf.gz --snf $out/$id/02_SVcall_mosaic/$id.snf $mosaic 1> $out/$id/02_SVcall_mosaic/$id.sniffles.log 2> $out/$id/02_SVcall_mosaic/$id.sniffles.err";
my $cmd = "";
if($mode eq "Both")
{
make_path "$out/$id/00_mapping";
make_path "$out/$id/01_SVcall";
make_path "$out/$id/02_SVcall_mosaic";
$cmd= $step1." && ".$step2." && ".$step3."\n";
}
if($mode eq "Basic")
{
make_path "$out/$id/00_mapping";
make_path "$out/$id/01_SVcall";
$cmd= $step1." && ".$step2."\n";
}
if($mode eq "Mosaic")
{
make_path "$out/$id/00_mapping";
make_path "$out/$id/02_SVcall_mosaic";
$cmd= $step1." && ".$step3."\n";
}
# print $cmd."\n";
$step4 = "$conf{SAMTOOLS} addreplacerg -r \'\@RG\\tID:samplename\\tSM:samplename\' $out/$id/00_mapping/$id.minimap2.align.bam| $conf{SAMTOOLS} view -bS - >$out/$id/00_mapping/$id.minimap2.rehead.bam && $conf{SAMTOOLS} index $out/$id/00_mapping/$id.minimap2.rehead.bam && rm $out/$id/00_mapping/$id.minimap2.align.bam";
make_path "$out/$id/03_GATK";
$step5 = "$conf{GATK} HaplotypeCaller -R $conf{REF} -I $out/$id/00_mapping/$id.minimap2.rehead.bam -O $out/$id/03_GATK/output.gvcf --ploidy $conf{PLOIDY} --minimum-mapping-quality $conf{MIN_MAP_Q} --min-base-quality-score $conf{MIN_BASE_Q} && $conf{GATK} VariantFiltration -R $conf{REF} -V $out/$id/03_GATK/output.gvcf -O $out/$id/03_GATK/output.filtered.gvcf --filter-name \"lowAF\" --filter-expression \'AD / DP < 0.15\' --filter-name \"lowDP\" --filter-expression \'DP < 10\' --filter-name \"lowAD\" --filter-expression \'AD < 5\'";
$cmd = $cmd.$step4."\n".$step5."\n";
open OUT, ">$out/$id/cmd.sh";
print OUT "$cmd";
close OUT;
my $lsf_out = "$out/$id/bsub.log";
my $lsf_err = "$out/$id/bsub.err";
$bsub = "bsub -g $group -q $q -n 1 -R \"select[mem>30000] rusage[mem=30000]\" -M 3000000 -a \'docker(scao/dailybox)\' -o $lsf_out -e $lsf_err bash $out/$id/cmd.sh";
print $bsub."\n";
system `$bsub`;
}
close IN;
# my $jobname = $conf{JOBNAME};
# my $partition = $conf{PARTITION};
# my $nodenum = $conf{NODENUM};
# my $task = $conf{NTASKS_PER_NODE};
# my $cpu = $conf{CPU_PER_TASK};
# my $cmdpath = "$out/cmd.sh"; #change
# my $failout = "$out/cmd.fail.sh"; #change
# my $array = $conf{ARRAY};
# open OUT, ">$out/slurm_cmd.sh";
# print OUT "\#\!\/bin\/bash
# \#SBATCH --job-name=$jobname
# \#SBATCH -p $partition
# \#SBATCH --nodes=$nodenum
# \#SBATCH --exclusive
# \#SBATCH --ntasks-per-node=$task
# \#SBATCH --cpus-per-task=$cpu
# \#SBATCH -o $out/$jobname.\%N.\%j.out
# \#SBATCH -e $out/$jobname.\%N.\%j.err
# \#SBATCH --array=$array
# arrayjob=\`cat $cmdpath | awk -v line=\$SLURM_ARRAY_TASK_ID \'{if (NR == line) print \$0}\'\`
# bash -c \"\$arrayjob \&\& { echo \'Finish successfully\! \'; } || { echo \$arrayjob >> $failout; }\"
# echo End time : \`date\`";
# close OUT;
sub load_conf
{
my $conf_file=shift;
my $conf_hash=shift; #hash ref
open CONF, $conf_file || die "$!";
while(<CONF>)
{
chomp;
next unless $_ =~ /\S+/;
next if $_ =~ /^#/;
warn "$_\n";
my @F = split"\t", $_; #key->value
$conf_hash->{$F[0]} = $F[1];
}
close CONF;
}