| 
1
 | 
     1 #' RScript capable
 | 
| 
 | 
     2 #' Rscript plasmidprofile.R -b blast_runG.tsv -s srst2_runG.tsv -u 0.75 -l 10000 -t "This is a test" -a
 | 
| 
 | 
     3 
 | 
| 
 | 
     4 
 | 
| 
 | 
     5 suppressPackageStartupMessages(library("optparse"))
 | 
| 
 | 
     6 suppressPackageStartupMessages(library("Plasmidprofiler"))
 | 
| 
 | 
     7 options(bitmapType='cairo')
 | 
| 
 | 
     8 
 | 
| 
 | 
     9 cl_arguments <- function(){
 | 
| 
 | 
    10   # CL arguments ####
 | 
| 
 | 
    11   option_list = list(
 | 
| 
 | 
    12     make_option(c("-b", "--blastfile"), type="character", default=NULL,
 | 
| 
 | 
    13                 help="BLAST TSV file name", metavar="character"),
 | 
| 
 | 
    14     make_option(c("-s", "--srst2file"), type="character", default=NULL,
 | 
| 
 | 
    15                 help="SRST2 TSV file name", metavar="character"),
 | 
| 
 | 
    16     make_option(c("-u", "--sureness"), type="numeric", default=NA,
 | 
| 
 | 
    17                 help="Sureness cut off [default = %default]", metavar="numeric"),
 | 
| 
 | 
    18     make_option(c("-c", "--coverage"), type="numeric", default=NA,
 | 
| 
 | 
    19                 help="Percent coverage cut off", metavar="numeric"),
 | 
| 
 | 
    20     make_option(c("-l", "--length"), type="numeric", default=NA,
 | 
| 
 | 
    21                 help="Plasmid length cut off", metavar="numeric"),
 | 
| 
 | 
    22     make_option(c("-a", "--anonymize"), action="store_true", default=NA,
 | 
| 
 | 
    23                 help="Anonymize plasmid and sample names"),
 | 
| 
 | 
    24     make_option(c("-o", "--outfile"), type="character", default="P2Run_",
 | 
| 
 | 
    25                 help="Output filename prefix [default=  %default]", metavar="character"),
 | 
| 
 | 
    26     make_option(c("-t", "--title"), type="character", default="Plasmid Profiles",
 | 
| 
 | 
    27                 help="Title of image [default = %default]", metavar="character"),
 | 
| 
 | 
    28     make_option(c("-C", "--combineincs"), action="store_true", default=NA,
 | 
| 
 | 
    29                 help="Combine very closely related incompatibility groups. eg. ")
 | 
| 
 | 
    30     # make_option(c("-T", "--Test"), action="store_true", default=NA,
 | 
| 
 | 
    31     #             help="Test filecache")
 | 
| 
 | 
    32 
 | 
| 
 | 
    33   );
 | 
| 
 | 
    34 
 | 
| 
 | 
    35   opt_parser <- OptionParser(option_list=option_list);
 | 
| 
 | 
    36   opt <- parse_args(opt_parser);
 | 
| 
 | 
    37 
 | 
| 
 | 
    38   if (is.null(opt$blastfile) | is.null(opt$srst2file)){
 | 
| 
 | 
    39     print_help(opt_parser)
 | 
| 
 | 
    40     stop("SRST2 and BLAST files must be supplied.", call.=FALSE)
 | 
| 
 | 
    41   }
 | 
| 
 | 
    42   opt
 | 
| 
 | 
    43 }
 | 
| 
 | 
    44 
 | 
| 
 | 
    45 
 | 
| 
 | 
    46 opt <- cl_arguments()
 | 
| 
 | 
    47 
 | 
| 
 | 
    48 filecache <<- new.env(parent = .GlobalEnv)
 | 
| 
 | 
    49 assign("name", opt$outfile, envir = filecache)
 | 
| 
 | 
    50 assign("mods", "Subsampling applied: ", envir = filecache)
 | 
| 
 | 
    51 
 | 
| 
 | 
    52 main(blast.file = opt$blastfile,
 | 
| 
 | 
    53      srst2.file = opt$srst2file,
 | 
| 
 | 
    54      coverage.filter = opt$coverage,
 | 
| 
 | 
    55      sureness.filter = opt$sureness,
 | 
| 
 | 
    56      length.filter = opt$length,
 | 
| 
 | 
    57      anonymize = opt$anonymize,
 | 
| 
 | 
    58      combine.inc = opt$combineincs,
 | 
| 
 | 
    59      main.title = opt$title)
 |