forked from BGI-Qingdao/TGS-GapCloser
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtgsgapcloser2
executable file
·675 lines (643 loc) · 24.1 KB
/
tgsgapcloser2
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
#!/bin/bash
#####################################################################
#
# brief: main pipeline script of tgsgapcloser2.
# usage: use -h/--help for details.
# author: [email protected] && [email protected]
#
############################################################3########
#####################################################################
#
# version
#
############################################################3########
VERSION="2.0.0_dev0.1"
RELEASE_TIME="2023-12-20"
HOOM_DIR=`dirname $0`
echo "INFO : Run tgsgapcloser2. from $HOOM_DIR ;"
echo " Version : $VERSION ;"
echo " Release time : $RELEASE_TIME ."
echo ""
#####################################################################
#
# function
#
############################################################3########
function print_info_line()
{
echo " - $1"
}
function print_info()
{
echo "";
echo "INFO : $1"
}
function print_fatal()
{
echo "";
echo "FATAL : $1 ! exit ...";
echo " try -h/--help for usage."
exit 1 ;
}
function print_help()
{
echo "Usage:"
echo " tgsgapcloser2 --scaff SCAFF_FILE --reads TGS_READS_FILE --output OUT_PREFIX [options...]"
echo " required :"
echo " --scaff <scaffold_file> input scaffold file."
echo " --reads <tgs_reads_file> input TGS read file."
echo " --output <output_prefix> output prefix."
echo " part required : "
echo " --ne do not correct errors. off by default."
echo " or"
echo " --racon <racon> installed racon path."
echo " or"
echo " --ngs <ngs_reads> ngs reads used for pilon"
echo " --pilon <pilon> installed pilon path."
echo " --samtools <samtools> installed samtools path."
echo " --java <java> installed java path."
echo " optional:"
echo " --minmap_arg <minmap2 args> for example, --minmap_arg ' -x ava-ont'"
echo " arg must be wrapped by ' '"
echo " --tgstype <ont/pb/hifi> TGS type. ont by default."
echo " --min_idy <float> min_idy for filtering TGS reads ."
echo " 0.3 for ont by default."
echo " 0.2 for pb/hifi by default."
echo " --min_match <int> min match length for filtering TGS reads ."
echo " 300bp for ont by default."
echo " 200bp for pb/hifi by default."
echo " --thread <int> threads uesd. 16 by default."
echo " --chunk <int> split candidates into chunks to separately do error correction."
echo " --pilon_mem <int> memory used for pilon. 300G for default."
echo " --p_round <int> iteration # of error corretion by pilon. 3 by default."
echo " --r_round <int> iteration # of error corretion by racon. 1 by default."
echo " --g_check gapsize diff check. off by default."
echo " --min_nread <int> minimum number of reads that can bridge this gap. 1 by default."
echo " --max_nread <int> maximum number of reads that can bridge this gap. -1 by default."
echo " --max_candidate <int> maximum number of candidate alignments used for error correction and gap filling. 200 by default"
}
function check_arg_null() {
if [[ -z $2 ]] ; then
print_fatal "Arg $1 is not assigned !!!";
fi
}
function check_file()
{
if [[ ! -e $1 ]] ; then
print_fatal "File $1 does not exist !!!"
fi
}
function check_file_exe()
{
check_file $1
if [[ ! -x $1 ]] ; then
print_fatal "File $1 is not executable !!!"
fi
}
function check_arg_exist()
{
check_arg_null $1 $2
check_file $2
}
function check_arg_exe()
{
check_arg_null $1 $2
check_file_exe $2
}
#####################################################################
#
# check args
#
############################################################3########
INPUT_SCAFF=""
TGS_READS=""
OUT_PREFIX=""
RACON=""
PILON=""
NGS_READS=""
JAVA=""
SAMTOOL=""
NE="no"
TGS_TYPE="ont"
THREAD=16
MIN_IDY="0.3"
MIN_IDY_USER="no"
MIN_MATCH="300"
MIN_MATCH_USER="no"
PILON_MEM="300G"
MINIMAP2_PARAM=" -N 1000 -r 10 --no-long-join "
USE_NEW_MINMAP2_ARG="no"
CHUNK_NUM=3
USE_RACON="yes"
PILON_ROUND=3
RACON_ROUND=1
G_CHECK=0
MIN_NREAD=1
MAX_NREAD=-1
MAX_CANDIDATE=200
print_info "Parsing args starting ..."
if [[ $# -lt 1 ]] ; then
print_help
exit 0 ;
fi
ARGS=`getopt -o h --long scaff:,reads:,output:,racon:,pilon:,ngs:,samtools:,java:,tgstype:,chunk:,thread:,minmap_arg:,min_idy:,min_match:,pilon_mem:,p_round:,r_round:,ne,min_nread:,max_nread:,max_candidate:,g_check -- "$@"`
eval set -- "$ARGS"
while true; do
case "$1" in
-h|--help)
shift;
print_help;
exit 0;
;;
--minmap_arg)
shift
MINIMAP2_PARAM="$1"
USE_NEW_MINMAP2_ARG='yes'
shift;
echo " --minmap_arg $MINIMAP2_PARAM"
;;
--scaff)
shift;
INPUT_SCAFF=$1
shift;
echo " --scaff $INPUT_SCAFF"
;;
--reads)
shift;
TGS_READS=$1
shift;
echo " --reads $TGS_READS"
;;
--output)
shift;
OUT_PREFIX=$1
shift;
echo " --output $OUT_PREFIX"
;;
--racon)
shift;
RACON=$1
shift;
echo " --racon $RACON"
;;
--pilon)
shift;
PILON=$1
shift;
echo " --pilon $PILON"
;;
--samtools)
shift;
SAMTOOL=$1
shift;
echo " --samtools $SAMTOOL"
;;
--java)
shift;
JAVA=$1
shift;
echo " --java $JAVA"
;;
--ngs)
shift;
NGS_READS=$1
shift;
echo " --ngs $NGS_READS"
;;
--g_check)
shift;
G_CHECK=1
echo " --g_check"
;;
--tgstype)
shift;
TGS_TYPE=$1
shift;
echo " --tgstype $TGS_TYPE"
;;
--min_idy)
shift;
MIN_IDY=$1
MIN_IDY_USER="yes"
shift;
echo " --min_idy $MIN_IDY"
;;
--min_match)
shift;
MIN_MATCH=$1
MIN_MATCH_USER="yes"
shift;
echo " --min_match $MIN_MATCH"
;;
--thread)
shift;
THREAD=$1
shift;
echo " --thread $THREAD"
;;
--pilon_mem)
shift;
PILON_MEM=$1
shift;
echo " --pilon_mem $PILON_MEM"
;;
--p_round)
shift;
PILON_ROUND=$1
shift;
echo " --p_round $PILON_ROUND"
;;
--r_round)
shift;
RACON_ROUND=$1
shift;
echo " --r_round $RACON_ROUND"
;;
--chunk)
shift;
CHUNK_NUM=$1
shift;
echo " --chunk $CHUNK_NUM"
;;
--max_nread)
shift;
MAX_NREAD=$1
shift;
echo " --max_nread $MAX_NREAD"
;;
--min_nread)
shift;
MIN_NREAD=$1
shift;
echo " --min_nread $MIN_NREAD"
;;
--max_candidate)
shift;
MAX_CANDIDATE=$1
shift;
echo " --max_candidate $MAX_CANDIDATE"
;;
--ne)
shift;
NE="yes"
echo " --ne "
;;
--)
shift;
break;
;;
esac
done
pilon_mem_numer=${PILON_MEM%?}
samtools_mem_number=$((pilon_mem_numer / THREAD))
SAMTOOLS_MEM=${samtools_mem_number}"G"
print_info "Parsing args end ."
#####################################################################
#
# check env
#
############################################################3########
# check binary
Candidate=$HOOM_DIR"/tgsgapcloserbin/tgsgapcandidate"
GapCloser=$HOOM_DIR"/tgsgapcloserbin/tgsgapcloser"
SeqGen=$HOOM_DIR"/tgsgapcloserbin/tgsseqgen"
SeqSplit=$HOOM_DIR"/tgsgapcloserbin/tgsseqsplit"
#MiniMap2=$HOOM_DIR"/minimap2/minimap2"
MiniMap2=minimap2
print_info "Checking basic args & env ..."
check_file_exe $Candidate
check_file_exe $GapCloser
check_file_exe $SeqGen
check_file_exe $SeqSplit
#check_file_exe $MiniMap2
# check input args.
check_arg_exist "input_scaff" $INPUT_SCAFF
check_arg_exist "reads" $TGS_READS
check_arg_null "output" $OUT_PREFIX
if [[ $MIN_NREAD -lt 1 ]] ; then
echo "Error : min_nread < 1. exit ..."
exit 1
fi
if [[ $NE == "no" ]] ; then
if [[ $NGS_READS != "" ]] ; then
check_arg_exist "ngs" $NGS_READS
check_arg_exist "pilon" $PILON
check_arg_exe "samtools" $SAMTOOL
check_arg_exe "java" $JAVA
print_info_line "Doing error correction by pilon with ngs reads. "
USE_RACON="no"
else
check_arg_exe "racon" $RACON
print_info_line "Doing error correction by racon with tgs reads."
USE_RACON="yes"
fi
else
print_info_line "No error correction by --ne option"
fi
# pacbio special default values.
if [[ $TGS_TYPE == "pb" ]] ; then
if [[ $USE_NEW_MINMAP2_ARG != "yes" ]] ; then
MINIMAP2_PARAM=" -N 1000 -r 10 --no-long-join -Hk19 "
fi
if [[ $MIN_IDY_USER == "no" ]] ; then
MIN_IDY="0.2"
fi
if [[ $MIN_MATCH_USER == "no" ]] ; then
MIN_MATCH="200"
fi
fi
# pacbio-hifi special default values.
if [[ $TGS_TYPE == "hifi" ]] ; then
if [[ $USE_NEW_MINMAP2_ARG != "yes" ]] ; then
MINIMAP2_PARAM=" -N 1000 -r 10 --no-long-join -k19 -w19 -U50,500 -g10k -A1 -B4 -O6,26 -E2,1 -s200 "
fi
if [[ $MIN_IDY_USER == "no" ]] ; then
MIN_IDY="0.2"
fi
if [[ $MIN_MATCH_USER == "no" ]] ; then
MIN_MATCH="200"
fi
fi
print_info_line "TGS reads type is $TGS_TYPE . MINIMAP2_PARAM is $MINIMAP2_PARAM MIN_IDY is $MIN_IDY . MIN_MATCH is $MIN_MATCH ."
print_info "Checking basic args & env end."
#####################################################################
#
# step 1, split input scaffold
#
############################################################3########
TMP_INPUT_SCAFTIG=$OUT_PREFIX".contig"
print_info "Step 1, run TGSSeqSplit to split scaffolds into scaftigs(contigs). "
if [[ ! -e 'done_step1_tag' ]] ; then
$SeqSplit --input_scaff $INPUT_SCAFF \
--prefix $OUT_PREFIX 2>$OUT_PREFIX.seq_split.log || exit 1
check_file $TMP_INPUT_SCAFTIG
date >>'done_step1_tag'
else
echo 'skip step1 since done_step1_tag exists'
fi
print_info "Step 1, done ."
#####################################################################
#
# step 2, choose candidate filling sequences.
#
############################################################3########
if [[ $NE == "yes" ]] ; then
print_info "Step 2 , skip TGSCandidate by --ne option."
else
print_info "Step 2 , run TGSCandidate ... "
if [[ ! -e 'done_step2.1_tag' ]] ; then
# run minimap2
#print_info_line "2.1 , run minmap2 to map contigs against tgs reads."
print_info_line "2.1 , run minmap2 to map tgs reads against contigs"
check_file $TMP_INPUT_SCAFTIG
$MiniMap2 $MINIMAP2_PARAM -t $THREAD \
$TMP_INPUT_SCAFTIG $TGS_READS \
1>$OUT_PREFIX.sub.r2c.paf 2>$OUT_PREFIX.minimap2.01.log || exit 1
#to fit previous code, now I will fake $OUT_PREFIX.sub.paf from reads against contigs to contigs against tgs reads
awk '{printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s",$6,$7,$8,$9,$5,$1,$2,$3,$4); for(i=10;i<=NF;i++) printf("\t%s",$i); printf("\n");}' $OUT_PREFIX.sub.r2c.paf >$OUT_PREFIX.sub.paf || exit 1
date >>'done_step2.1_tag'
else
echo 'skip step2.1 since done_step2.1_tag exists'
fi
if [[ ! -e 'done_step2.2_tag' ]] ; then
# run candidate
print_info_line "2.2, run TGSGapCandidate to choose candidate seqs."
TMP_INPUT_SCAFF_INFO=$OUT_PREFIX".orignial_scaff_infos"
check_file $TMP_INPUT_SCAFF_INFO
# pre-filter unwanted alignments.
awk '{if(($3<100000)||($2-$3<100000)) print $0}' $OUT_PREFIX.sub.paf >$OUT_PREFIX.sub.filter.paf
$Candidate --ont_reads_a $TGS_READS \
--contig2ont_paf $OUT_PREFIX.sub.filter.paf \
--min_nread $MIN_NREAD \
--max_nread $MAX_NREAD \
--candidate_max $MAX_CANDIDATE --candidate_shake_filter --candidate_merge \
<$TMP_INPUT_SCAFF_INFO >$OUT_PREFIX.ont.fasta 2>$OUT_PREFIX.cand.log || exit 1
# remove used paf here
rm $OUT_PREFIX.sub.paf
date >>'done_step2.2_tag'
else
echo 'skip step2.2 since done_step2.2_tag exists'
fi
if [[ ! -e 'done_step2.3_tag' ]] ; then
# split candidate into chunks
print_info_line "2.3 , break candidates into $CHUNK_NUM chunk(s)."
if [[ $CHUNK_NUM != "1" ]] ; then
for ((i=0; i<CHUNK_NUM; i++))
do
awk 'BEGIN{id=0}{if($1 ~ />/ ){id=id+1;} if(id % cov == the_i) {print $0;} }' cov=$CHUNK_NUM the_i=$i \
<$OUT_PREFIX.ont.fasta >$OUT_PREFIX.ont.0.$i.fasta || exit 1 ;
done
else
ln -s $OUT_PREFIX.ont.fasta $OUT_PREFIX.ont.0.0.fasta
fi
date >>'done_step2.3_tag'
else
echo 'skip step2.3 since done_step2.3_tag exists'
fi
print_info "Step 2, done ."
fi
#####################################################################
#
# step 3, error-correction .
#
############################################################3########
if [[ $NE == "yes" ]] ; then
print_info "Step 3, skip error correction by --ne option."
else
if [[ $USE_RACON == "yes" ]] ; then
print_info "Step 3.A error correction by racon ... "
if [[ ! -e 'done_step_3.A.1_tag' ]] ; then
print_info_line "3.A.1, racon each chunk ... "
prev_round=0;
last_round=0;
for ((round=0; round<RACON_ROUND ; round++))
do
if [[ $round != $last_round ]] ; then
prev_round=$last_round
last_round=$round
fi
print_info_line " - iteration $round start ... "
for ((i=0; i<CHUNK_NUM; i++))
do
curr_tag="$round"".""$i"
print_info_line " - iteration $round chunk $i - minimap2 indexing ... "
if [[ $round -gt 0 ]] ; then
prev_tag="$prev_round"".""$i"
ln -s $OUT_PREFIX.ont.$prev_tag.racon.fasta $OUT_PREFIX.ont.$curr_tag.fasta
fi
curr_tag="$round"".""$i"
print_info_line " - iteration $round chunk $i - minimap2 ... "
$MiniMap2 -t $THREAD $MINIMAP2_PARAM $OUT_PREFIX.ont.$curr_tag.fasta $TGS_READS \
1>$OUT_PREFIX.$curr_tag.paf 2>$OUT_PREFIX.minimap2.03.$curr_tag.log || exit 1
print_info_line " - iteration $round chunk $i - racon ... "
$RACON -t $THREAD $TGS_READS $OUT_PREFIX.$curr_tag.paf $OUT_PREFIX.ont.$curr_tag.fasta \
1>$OUT_PREFIX.ont.$curr_tag.racon.fasta 2>$OUT_PREFIX.$curr_tag.racon.log || exit 1
# remove used paf here
rm $OUT_PREFIX.$curr_tag.paf
done
print_info_line " - iteration $round end. "
done
date >>'done_step_3.A.1_tag'
else
echo 'skip step3.A.1 since done_step3.A.1_tag exists'
fi
if [[ ! -e 'done_step_3.A.2_tag' ]] ; then
print_info_line "3.A.2 , merge chunks ... "
if [[ $CHUNK_NUM != "1" ]] ; then
for ((i=0; i<CHUNK_NUM; i++))
do
curr_tag="$last_round"".""$i"
cat $OUT_PREFIX.ont.$curr_tag.racon.fasta >> $OUT_PREFIX.ont.racon.fasta
cat $OUT_PREFIX.$curr_tag.racon.log >> $OUT_PREFIX.racon.log
rm -rf $OUT_PREFIX.ont.$curr_tag.racon.fasta
rm -rf $OUT_PREFIX.$curr_tag.racon.log
done
else
curr_tag="$last_round"".0"
mv $OUT_PREFIX.ont.$curr_tag.racon.fasta $OUT_PREFIX.ont.racon.fasta
mv $OUT_PREFIX.$curr_tag.racon.log $OUT_PREFIX.racon.log
fi
date >>'done_step_3.A.2_tag'
else
echo 'skip step3.A.2 since done_step3.A.2_tag exists'
fi
else
print_info "Step 3.B , error correction by pilon ... "
if [[ ! -e 'done_step_3.B.1_tag' ]] ; then
print_info_line "3.B.1 , pilon each chunk ... "
prev_round=0;
last_round=0;
for ((round=0; round<PILON_ROUND ; round++))
do
print_info_line " - iteration $round start ... "
if [[ $round != $last_round ]] ; then
prev_round=$last_round
last_round=$round
fi
for ((i=0; i<CHUNK_NUM; i++))
do
curr_tag="$round"".""$i"
print_info_line " - iteration $round chunk $i - minimap2 indexing ... "
if [[ $round -gt 0 ]] ; then
prev_tag="$prev_round"".""$i"
ln -s $OUT_PREFIX.ont.$prev_tag.pilon.fasta $OUT_PREFIX.ont.$curr_tag.fasta
fi
$MiniMap2 -t $THREAD -d $OUT_PREFIX.mmi $OUT_PREFIX.ont.$curr_tag.fasta \
1>$OUT_PREFIX.minimap2.02.$curr_tag.log 2>&1 || exit 1
print_info_line " - iteration $round chunk $i - minimap2 mapping ngs into tgs ... "
$MiniMap2 -t $THREAD -k14 -w5 -n2 -m20 -s 40 --sr --frag yes \
--split-prefix=$OUT_PREFIX.$curr_tag \
-a $OUT_PREFIX.mmi $NGS_READS \
1>$OUT_PREFIX.sam 2>$OUT_PREFIX.minimap2.03.$curr_tag.log || exit 1
print_info_line " - iteration $round chunk $i - process required bam ... "
awk 'BEGIN{t["none"]=1;}{if( $1 == "@SQ" ){if( $2 in t ){;}else{t[$2]=1;print $0;}}else{print $0;}}'\
< $OUT_PREFIX.sam >$OUT_PREFIX.fiter.sam || exit 1
# remove used sam
rm $OUT_PREFIX.sam
$SAMTOOL view -bo $OUT_PREFIX.bam $OUT_PREFIX.fiter.sam -@ $THREAD \
>$OUT_PREFIX.samtool_01.$curr_tag.log 2>&1 || exit 1
# remove used sam
rm $OUT_PREFIX.fiter.sam
$SAMTOOL sort -m $SAMTOOLS_MEM $OUT_PREFIX.bam -o $OUT_PREFIX.sort.bam -@ $THREAD \
>$OUT_PREFIX.samtool_02.$curr_tag.log 2>&1 || exit 1
# remove used bam
rm $OUT_PREFIX.bam
$SAMTOOL index $OUT_PREFIX.sort.bam -@ $THREAD \
>$OUT_PREFIX.samtool_03.$curr_tag.log 2>&1 || exit 1
print_info_line " - iteration $round chunk $i - run pilon ... "
$JAVA -Xmx$PILON_MEM -jar $PILON --fix all \
--genome $OUT_PREFIX.ont.$curr_tag.fasta --bam $OUT_PREFIX.sort.bam \
--output $OUT_PREFIX.ont.$curr_tag.pilon --outdir ./ \
--diploid --threads $THREAD >$OUT_PREFIX.$curr_tag.pilon.log 2>$OUT_PREFIX.pilon.$curr_tag.err || exit 1
# remove used bam
rm $OUT_PREFIX.sort.bam
done
print_info_line " - iteration $round end. "
done
date >>'done_step_3.B.1_tag'
else
echo 'skip step3.B.1 since done_step3.B.1_tag exists'
fi
if [[ ! -e 'done_step_3.B.2_tag' ]] ; then
print_info_line "3.B.2 , merge chunk results ... "
if [[ $CHUNK_NUM != "1" ]] ; then
for ((i=0; i<CHUNK_NUM; i++))
do
curr_tag="$last_round"".""$i"
cat $OUT_PREFIX.ont.$curr_tag.pilon.fasta >> $OUT_PREFIX.ont.pilon.fasta
cat $OUT_PREFIX.$curr_tag.pilon.log >> $OUT_PREFIX.pilon.log
rm -rf $OUT_PREFIX.ont.$curr_tag.pilon.fasta
rm -rf $OUT_PREFIX.$curr_tag.pilon.log
done
else
curr_tag="$last_round"".0"
mv $OUT_PREFIX.ont.$curr_tag.pilon.fasta $OUT_PREFIX.ont.pilon.fasta
mv $OUT_PREFIX.$curr_tag.pilon.log $OUT_PREFIX.pilon.log
fi
date >>'done_step_3.B.2_tag'
else
echo 'skip step3.B.2 since done_step3.B.2_tag exists'
fi
fi
print_info "Step 3, done ."
fi
#####################################################################
#
# Step 4: gap-filling
#
#####################################################################
print_info "Step 4, gap filling ... "
FINAL_READS=""
if [[ $NE == "yes" ]] ; then
print_info_line "Use $TGS_READS as final TGS READS input."
FINAL_READS=$TGS_READS
else
if [[ $USE_RACON == "yes" ]] ; then
print_info_line "Use $OUT_PREFIX.ont.racon.fasta as final TGS READS input"
FINAL_READS=$OUT_PREFIX.ont.racon.fasta
else
print_info_line "Use $OUT_PREFIX.ont.pilon.fasta as final TGS READS input"
FINAL_READS=$OUT_PREFIX.ont.pilon.fasta
fi
fi
check_file $FINAL_READS
check_file $TMP_INPUT_SCAFTIG
if [[ ! -e 'done_step_4.1_tag' ]] ; then
#print_info_line "4,1 , mapping contigs against reads ... "
print_info_line "4,1 , mapping reads against contigs ... "
$MiniMap2 $MINIMAP2_PARAM -t $THREAD $TMP_INPUT_SCAFTIG $FINAL_READS \
1>$OUT_PREFIX.fill.r2c.paf 2>$OUT_PREFIX.minimap2.04.log || exit 1
awk '{printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s",$6,$7,$8,$9,$5,$1,$2,$3,$4); for(i=10;i<=NF;i++) printf("\t%s",$i); printf("\n");}' $OUT_PREFIX.fill.r2c.paf >$OUT_PREFIX.fill.paf || exit 1
date >>'done_step_4.1_tag'
else
echo 'skip step4.1 since done_step4.1_tag exists'
fi
if [[ ! -e 'done_step_4.2_tag' ]] ; then
print_info_line "4,2 , filling gaps ... "
# pre filter unwanted alignments.
awk '{if(($3<100000)||($2-$3<100000)) print $0}' $OUT_PREFIX.fill.paf >$OUT_PREFIX.fill.filter.paf
if [[ $G_CHECK == 0 ]] ; then
$GapCloser --ont_reads_a $FINAL_READS --contig2ont_paf $OUT_PREFIX.fill.filter.paf \
--min_match=$MIN_MATCH --min_idy=$MIN_IDY \
--prefix $OUT_PREFIX 1>$OUT_PREFIX.fill.log 2>&1|| exit 1
# remove used paf
rm $OUT_PREFIX.fill.paf
else
$GapCloser --ont_reads_a $FINAL_READS --contig2ont_paf $OUT_PREFIX.fill.filter.paf \
--min_match=$MIN_MATCH --min_idy=$MIN_IDY \
--prefix $OUT_PREFIX --use_gapsize_check 1>$OUT_PREFIX.fill.log 2>&1|| exit 1
rm $OUT_PREFIX.fill.paf
fi
print_info_line "4,2, gen final seqs ... "
date >>'done_step_4.2_tag'
else
echo 'skip step4.2 since done_step4.2_tag exists'
fi
$SeqGen --prefix $OUT_PREFIX 1>$OUT_PREFIX.i2s.log 2>&1 || exit 1
print_info "Step 4, done ."
#####################################################################
#
# ALL DONE
#
#####################################################################
print_info "ALL DONE !!! "