
try:
    from generator.process import Process
except ImportError:
    from flowcraft.generator.process import Process


class PatlasMashDist(Process):

    def __init__(self, **kwargs):

        super().__init__(**kwargs)

        self.input_type = "fasta"
        self.output_type = "json"

        self.params = {
            "pValue": {
                "default": 0.05,
                "description": "P-value cutoff for the distance estimation "
                               "between two sequences to be included in the "
                               "output."
            },
            "mash_distance": {
                "default": 0.1,
                "description": "Sets the maximum distance between two "
                               "sequences to be included in the output."
            },
            "shared_hashes": {
                "default": 0.8,
                "description": "Sets a minimum percentage of hashes shared "
                               "between two sequences in order to include its "
                               "result in the output."
            },
            "refFile": {
                "default": "'/ngstools/data/patlas_mash_sketch.msh'",
                "description": "Specifies the reference file to be provided "
                               "to mash. It can either be a fasta or a .msh "
                               "reference sketch generated by mash."
            }
        }

        self.secondary_inputs = [
            {
                "params": "refFile",
                "channel": "IN_reference_file = Channel.value(params.refFile)"
            }
        ]

        self.directives = {
            "runMashDist": {
                "container": "flowcraft/mash-patlas",
                "version": "1.1.0-1",
                "cpus": 1,
                "memory": "{ 4.GB * task.attempt }"
            },
            "mashDistOutputJson": {
                "container": "flowcraft/mash-patlas",
                "version": "1.1.0-1",
                "cpus": 1,
                "memory": "'4GB'"
            }
        }

        self.status_channels = [
            "runMashDist",
            "mashDistOutputJson"
        ]


class PatlasMashScreen(Process):

    def __init__(self, **kwargs):

        super().__init__(**kwargs)

        self.input_type = "fastq"
        self.output_type = "json"

        self.params = {
            "noWinner": {
                "default": "false",
                "description": "A variable that enables the use of -w option"
                               " for mash screen."
            },
            "pValue": {
                "default": 0.05,
                "description": "P-value cutoff for the distance estimation "
                               "between two sequences to be included in the "
                               "output."
            },
            "identity": {
                "default": 0.9,
                "description": "The percentage of identity between the reads "
                               "input and the reference sequence"
            },
            "refFile": {
                "default": "'/ngstools/data/patlas_mash_sketch.msh'",
                "description": "Specifies the reference file to be provided "
                               "to mash. It can either be a fasta or a .msh "
                               "reference sketch generated by mash."
            }
        }

        self.secondary_inputs = [
            {
                "params": "refFile",
                "channel": "IN_reference_file = Channel.value(params.refFile)"
            },

        ]

        self.directives = {
            "mashScreen": {
                "container": "flowcraft/mash-patlas",
                "version": "1.1.0-1",
                "cpus": 1,
                "memory": "{ 4.GB * task.attempt }"
            },
            "mashOutputJson": {
                "container": "flowcraft/mash-patlas",
                "version": "1.1.0-1",
                "cpus": 1,
                "memory": "'4GB'"
            }
        }

        self.status_channels = [
            "mashScreen",
            "mashOutputJson"
        ]

        self.compiler["patlas_consensus"] = ["mashScreenOutputChannel"]
