using OnlinePCA
using ArgParse:
    ArgParseSettings, parse_args, @add_arg_table!

# options
function parse_commandline()
    s = ArgParseSettings()

    @add_arg_table! s begin
        "--input", "-i"
            help = "input file (serialized)"
            arg_type = AbstractString
            required = true
        "--featurelist"
            help = "Feature list for filtering"
            arg_type = AbstractString
            default = ""
        "--samplelist"
            help = "Sample list for filtering"
            arg_type = AbstractString
            default = ""
        "--thr1"
            help = "Threshold for filtering"
            arg_type = Union{Number,AbstractString}
            default = 0.0
        "--thr2"
            help = "Threshold for filtering"
            arg_type = Union{Number,AbstractString}
            default = 0.0
        "--direct1"
            help = "Direction of filtering (+ or -)"
            arg_type = AbstractString
            default = "+"
        "--direct2"
            help = "Direction of filtering (+ or -)"
            arg_type = AbstractString
            default = "+"
        "--outdir", "-o"
            help = "output directory"
            arg_type = AbstractString
            default = "."
            required = false
    end

    return parse_args(s)
end

# main
function main()
    parsed_args = parse_commandline()
    println("Parsed args:")
    for (arg,val) in parsed_args
        println("  $arg  =>  $val")
    end

    thr1 = parsed_args["thr1"]
    thr2 = parsed_args["thr2"]
    if typeof(thr1) == String
        thr1 = parse(Float32, thr1)
    end
    if typeof(thr2) == String
        thr2 = parse(Float32, thr2)
    end

    OnlinePCA.filtering(input=parsed_args["input"], featurelist=parsed_args["featurelist"], samplelist=parsed_args["samplelist"], thr1=thr1, thr2=thr2, direct1=parsed_args["direct1"], direct2=parsed_args["direct2"], outdir=parsed_args["outdir"])
end

main()