mmpoa.pl 1019 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env perl
  2. #
  3. # Author: Jue Ruan <ruanjue@gmail.com>
  4. #
  5. use Getopt::Std;
  6. use strict;
  7. our ($opt_h, $opt_t, $opt_s, $opt_m, $opt_x, $opt_p);
  8. getopts("ht:s:m:x:p:");
  9. &usage if($opt_h);
  10. &usage(1) if(@ARGV < 2);
  11. my $ref = shift || &usage(1);
  12. my $rst = $ref;
  13. $rst=~s/\.fa$//;
  14. $rst=~s/\.fasta$//;
  15. my $ncpu = 4;
  16. $ncpu = $opt_t if(defined $opt_t);
  17. my $MM = $opt_m || "minimap2";
  18. my $MX = $opt_x || "pb";
  19. my $ST = $opt_s || "samtools";
  20. my $WP = $opt_p || "wtpoa-cns";
  21. my $cmd = '';
  22. $cmd = "$MM -t $ncpu -x map-$MX -a $ref @ARGV | $ST view -Sb - > $rst.bam";
  23. &run($cmd);
  24. $cmd = "$ST sort $rst.bam $rst.srt";
  25. &run($cmd);
  26. $cmd = "$ST view $rst.srt.bam | $WP -t $ncpu -d $ref -i - -fo $rst.mmpoa.fa";
  27. &run($cmd);
  28. 1;
  29. sub usage {
  30. my $ret = shift || 0;
  31. print qq{Usage: $0 [-t n_cpu:4] [-s samtools] [-m minimap2] [-p wtpoa-cns] [-x pb|ont] <ref.fa> <reads1.fa> [reads2.fa ...]\n};
  32. exit $ret;
  33. }
  34. sub run {
  35. my $cmd = shift;
  36. system("date");
  37. print "# $cmd\n";
  38. if(system($cmd)){
  39. die("$cmd");
  40. }
  41. system("date");
  42. }