import argparse
import os
import sys
def miRNA_identification_for_total(args):
    from miRNA_part import miRNA_identification
    filename = os.path.realpath(__file__)
    sRNAminer = os.path.dirname(filename) + "/scripts/sRNAminer.jar"
    sRNAminer_database = os.path.dirname(filename) + "/scripts/miRNA_part/miRBase20181216"
    miRNA_identification.miRNA_identification_merger_pipeline(args.genome_file,args.index,args.input_file,args.locate_num,args.mismatch,
                                                              args.thread,args.minLen,args.maxLen,args.Batch_mode,args.output_path,sRNAminer,sRNAminer_database)

def read_mapping(args):
    from Alignment_Part import alignment
    filename = os.path.realpath(__file__)
    sRNAminer = os.path.dirname(filename) + "/scripts/sRNAminer.jar"
    alignment.alignment_pipeline(args.index,args.input_file,args.locate_num,args.mismatch,args.thread,args.output_path,args.Batch_mode,sRNAminer)

def bowtie_to_sRNAminer(args):
    from Alignment_Part import Bowtie_to_sRNAminer
    filename = os.path.realpath(__file__)
    sRNAminer = os.path.dirname(filename) + "/scripts/sRNAminer.jar"
    Bowtie_to_sRNAminer.convert_bowtie_to_sRNAminer(args.input_file,args.output_path,args.thread, sRNAminer ,args.Batch_mode)

def phasiRNA_identification_for_total(args):
    from PHAS_Part import PHAS_identification_one_step
    filename = os.path.realpath(__file__)
    sRNAminer = os.path.dirname(filename) + "/scripts/sRNAminer.jar"
    PHAS_identification_one_step.phas_identification_merger_pipeline(args.index,args.thread,args.locate_num,args.mismatch,args.input_file,
                                                            args.genome_file,args.phasiRNA_len,args.output_path,args.lib_num, args.PhasingScore, args.Pvalue, args.Batch_mode,sRNAminer)

def hc_siRNA_identification_for_total(args):
    from HcsiRNA_Part import hcsiRNA_identification
    filename = os.path.realpath(__file__)
    sRNAminer = os.path.dirname(filename) + "/scripts/sRNAminer.jar"
    hcsiRNA_identification.hc_siRNA_identification_merger_pipeline(args.genome_file, args.index, args.input_file, args.mismatch, args.thread, args.minRegionGap,
                                            args.minRepeatRatio, args.PHAS24_file, args.Batch_mode, args.output_path, sRNAminer)

def miRNA_expression_for_total(args):
    from miRNA_part import miRNA_expression
    filename = os.path.realpath(__file__)
    sRNAminer = os.path.dirname(filename) + "/scripts/sRNAminer.jar"
    miRNA_expression.miRNA_expression_merger_pipeline(args.gff_file, args.input_file, args.output_path,args.Batch_mode, sRNAminer)

def PHAS_expression_for_total(args):
    from PHAS_Part import PHAS_Expression
    filename = os.path.realpath(__file__)
    sRNAminer = os.path.dirname(filename) + "/scripts/sRNAminer.jar"
    PHAS_Expression.PHAS_expression_merger_pipeline(args.input_file,args.phas_info, args.phasiRNA_len, args.Batch_mode,args.output_path,sRNAminer)

def adapter_treat_for_total(args):
    from Data_Preprocessing import Adapter_treat
    filename = os.path.realpath(__file__)
    sRNAminer = os.path.dirname(filename) + "/scripts/sRNAminer.jar"
    Adapter_treat.adapter_treat_merger_pipeline(args.input_file,args.output_path, args.Batch_mode,sRNAminer)

def Quality_control_for_total(args):
    from Data_Preprocessing import Quality_control
    Quality_control.quality_control_merger_pipeline(args.input_file,args.thread,args.output_path,args.od,args.nd,args.Batch_mode)

def One_Step_sRNAminer_for_total(args):
    from One_Step_sRNAminer import One_step_sRNAminer
    filename = os.path.realpath(__file__)
    sRNAminer = os.path.dirname(filename) + "/scripts/sRNAminer.jar"
    sRNAminer_database = os.path.dirname(filename) + "/scripts/miRNA_part/miRBase20181216"
    One_step_sRNAminer.One_step_workflow(args.miRNA,args.genome_file,args.input_file,args.locate_num,args.mismatch,args.thread,args.minLen,args.maxLen,args.Batch_mode,args.output_path,sRNAminer,sRNAminer_database,
                                         args.PHAS21, args.lib_num, args.PhasingScore, args.Pvalue, args.PHAS24,args.hc_siRNA,args.minRegionGap,args.minRepeatRatio,args.nd,args.od)

def Seq_Collapse_for_total(args):
    from Data_Preprocessing import Collapse_seq
    filename = os.path.realpath(__file__)
    sRNAminer = os.path.dirname(filename) + "/scripts/sRNAminer.jar"
    Collapse_seq.seq_collapse_merger_pipeline(args.input_file,args.output_path,args.Batch_mode,sRNAminer)

def sRNA_Target_for_total(args):
    from Target_Part import sRNA_Target
    filename = os.path.realpath(__file__)
    sRNAminer = os.path.dirname(filename) + "/scripts/sRNAminer.jar"
    sRNA_Target.TargetSoPipe_merger_pipeline(args.input_file,args.subject_file,args.output_file,args.Fragment,args.thread,args.SearchCom,args.Evalue,
                             args.maxMismatch,args.Score,sRNAminer)

def sRNAloci_identification_for_total(args):
    from sRNA_abundance import sRNAloci_identification
    filename = os.path.realpath(__file__)
    sRNAminer = os.path.dirname(filename) + "/scripts/sRNAminer.jar"
    sRNAloci_identification.sRNAloci_identification_merger_pipeline(args.input_file,args.minReadDepth,args.minRegionGap,
                                                                    args.output_path,args.Batch_mode,sRNAminer)

def PHAS_Trigger_for_total(args):
    from PHAS_Part import Trigger_Analysis
    filename = os.path.realpath(__file__)
    sRNAminer = os.path.dirname(filename) + "/scripts/sRNAminer.jar"
    Trigger_Analysis.PHAStrigger_merger_pipeline(args.thread,args.phas_info,args.phasiRNA_len,args.genome_file,args.input_file,args.FlankLen,args.output_file,sRNAminer)

def sRNAloci_expression_for_total(args):
    from sRNA_abundance import sRNA_abundance_calculate
    sRNA_abundance_calculate.main(args.sRNAlocus_file,args.input_file,args.output_file,args.Batch_mode)

def phasiRNA_extract_for_total(args):
    from PHAS_Part import phasiRNA_extract
    filename = os.path.realpath(__file__)
    sRNAminer = os.path.dirname(filename) + "/scripts/sRNAminer.jar"
    phasiRNA_extract.phasiRNA_extract_merge_pipeline(args.phas_info,args.genome_file,args.phasiRNA_len,args.output_file,sRNAminer)

def sRNA_extract_for_total(args):
    from sRNA_abundance import sRNA_extract_analysis
    sRNA_extract_analysis.sRNA_extract_merge_pipeline(args.sRNAlocus_file,args.mappingFile,args.output_path,args.Batch_mode)

def miRNA_identification_no_align_for_total(args):
    from miRNA_part import miRNA_identification_without_align
    filename = os.path.realpath(__file__)
    sRNAminer = os.path.dirname(filename) + "/scripts/sRNAminer.jar"
    sRNAminer_database = os.path.dirname(filename) + "/scripts/miRNA_part/miRBase20181216"
    miRNA_identification_without_align.miRNA_identification_merger_pipeline(args.genome_file,args.input_file,args.minLen,args.maxLen,args.Batch_mode,args.output_path,args.thread,sRNAminer,sRNAminer_database)

def PHAS_identification_no_align_for_total(args):
    from PHAS_Part import PHAS_identification_without_align
    filename = os.path.realpath(__file__)
    sRNAminer = os.path.dirname(filename) + "/scripts/sRNAminer.jar"
    PHAS_identification_without_align.phas_identification_merger_pipeline(args.input_file, args.genome_file, args.phasiRNA_len, args.output_path, args.lib_num, args.PhasingScore, args.Pvalue,args.thread, args.Batch_mode, sRNAminer)

def PHASListToGraph_for_total(args):
    from PHAS_Part import PHASlocusToGraph
    filename = os.path.realpath(__file__)
    sRNAminer = os.path.dirname(filename) + "/scripts/sRNAminer.jar"
    PHASlocusToGraph.DrawPHAS_pipeline(args.phas,args.mappingFile,args.phaseLen,args.output_format,args.trigger,args.output_dir,sRNAminer)

def get_parser():
    # 创建ArgumentParser对象,里面可以添加描述信息
    parser = argparse.ArgumentParser(prog="sRNAminer",description="A Multifunctional Toolkit for sRNA Analysis")
    # 添加参数处理
    subparsers = parser.add_subparsers(help='sub-command help')

    One_Step_sRNAminer_parser = subparsers.add_parser('One_step_sRNAminer', help='miRNA, phasiRNA and hc-siRNA identification & miRNA, phasiRNA expression')
    One_Step_sRNAminer_parser.add_argument('--genome_file','-g',required=True,help="Set a genome File [Required]") #
    One_Step_sRNAminer_parser.add_argument('--input_file','-i',required=True,help="Set a list of sequencing File [Fastq Format] [Required]") #
    One_Step_sRNAminer_parser.add_argument('--locate_num','-l',default="20",help="The number of locations a read can map [Default: 20]") #
    One_Step_sRNAminer_parser.add_argument('--lib_num','-b',default="1",help="The minimum of lib PHAS exists [Default: 1]") #
    One_Step_sRNAminer_parser.add_argument('--mismatch','-m',default="1",help="The number of mismatch allowed in mapping reads to the genome [Default: 1]") #
    One_Step_sRNAminer_parser.add_argument('--minLen',default="20",choices=["20","21","22","23","24"],help="Minimum length of miRNA [Default: 20]")
    One_Step_sRNAminer_parser.add_argument('--maxLen',default="22",choices=["20","21","22","23","24"],help="Maximum length of miRNA [Default: 22]")
    One_Step_sRNAminer_parser.add_argument('--thread','-p',default="2",help="The number of thread to run [Default: 2]") #
    One_Step_sRNAminer_parser.add_argument('--PhasingScore',default="10",help="Phasing Score [Default: 10]")
    One_Step_sRNAminer_parser.add_argument('--Pvalue',default="0.001",help="P-value [Default :0.001]")
    One_Step_sRNAminer_parser.add_argument('--nd', required=True, help="Set the path of ncRNA[rRNA, tRNA, snoRNA and snRNA] without miRNA database [Contain index] [Fasta Format] [Required]")
    One_Step_sRNAminer_parser.add_argument('--od', required=True, help="Set the path of Organelle database [Contain index] [Required]")
    One_Step_sRNAminer_parser.add_argument('--minRegionGap',default="200",help="[For hc-siRNA] Set minimum region gap [Default: 200]")
    One_Step_sRNAminer_parser.add_argument('--minRepeatRatio',default="0.5",help="[For hc-siRNA] Set minimum siRNA of specific length (eg. 23,24 nt) abundance ratio to define a locus [Default: 0.5]")
    One_Step_sRNAminer_parser.add_argument('--Batch_mode',action='store_true',help="Bulk sample")
    One_Step_sRNAminer_parser.add_argument('--miRNA',action='store_true',help="miRNA analysis")
    One_Step_sRNAminer_parser.add_argument('--PHAS21',action='store_true',help="21nt phasiRNA analysis")
    One_Step_sRNAminer_parser.add_argument('--PHAS24',action='store_true',help="24nt phasiRNA analysis")
    One_Step_sRNAminer_parser.add_argument('--hc_siRNA',action='store_true',help="hc_siRNA analysis")
    One_Step_sRNAminer_parser.add_argument('--output_path','-o',required=True,help="Directory for output [Required]")
    One_Step_sRNAminer_parser.set_defaults(func=One_Step_sRNAminer_for_total)

    Adapter_treat_parser = subparsers.add_parser('Adapter_trimming', help='Trimming Adapter')
    Adapter_treat_parser.add_argument('--input_file', '-i', required=True,
                                        help="Set a list of seq data[Fastq Format] [Required]")
    Adapter_treat_parser.add_argument('--Batch_mode', action='store_true', help="Bulk sample")
    Adapter_treat_parser.add_argument('--output_path', '-o', required=True, help="Directory for output [Required]")
    Adapter_treat_parser.set_defaults(func=adapter_treat_for_total)

    Quality_control_parser = subparsers.add_parser('Data_cleaning', help='Removing rRNA,tRNA,snoRNA,snRNA & Organelle framents')
    Quality_control_parser.add_argument('--input_file', '-i', required=True,
                                        help="Set a list of sequencing File [Collapsed] [Fasta Format] [Required]")
    Quality_control_parser.add_argument('--thread', '-p', default="2", help="The number of thread to run [Default: 2]")
    Quality_control_parser.add_argument('--nd', required=True, help="Set the path of ncRNA[rRNA, tRNA, snoRNA and snRNA] without miRNA database [Contain index] [Fasta Format] [Required]")
    Quality_control_parser.add_argument('--od', required=True, help="Set the path of Organelle database [Contain index] [Required]")
    Quality_control_parser.add_argument('--Batch_mode', action='store_true', help="Bulk sample")
    Quality_control_parser.add_argument('--output_path', '-o', required=True, help="Directory for output [Required]")
    Quality_control_parser.set_defaults(func=Quality_control_for_total)

    Seq_Collapse_parser = subparsers.add_parser('Seq_collapsing', help='Seq collapsing')
    Seq_Collapse_parser.add_argument('--input_file', '-i', required=True,
                                        help="Set a sequence data [Fasta Format] [Required]")
    Seq_Collapse_parser.add_argument('--Batch_mode', action='store_true', help="Bulk sample")
    Seq_Collapse_parser.add_argument('--output_path', '-o', required=True, help="Directory for output [Required]")
    Seq_Collapse_parser.set_defaults(func=Seq_Collapse_for_total)

    reads_mapping_parser = subparsers.add_parser('Reads_mapping',help='Reads are mapped to the genome')
    reads_mapping_parser.add_argument('--genome','-g', required=True, help="Set the genome [Required]")
    reads_mapping_parser.add_argument('--index', required=True, help="Set the genome index of bowtie [Required]")
    reads_mapping_parser.add_argument('--input_file', '-i', required=True, help=" Set a list of sequencing Files[Collapsed & Quality Controlled] [Fasta Format] [Required]")
    reads_mapping_parser.add_argument('--locate_num', '-l', default="20",
                                             help="The number of locations a read can map [Default: 20]")
    reads_mapping_parser.add_argument('--mismatch', '-m', default="1",
                                             help="The number of mismatch allowed in alignment [Default: 1]")
    reads_mapping_parser.add_argument('--thread', '-p', default="2", help="The number of thread to run [Default: 2]")
    reads_mapping_parser.add_argument('--Batch_mode',action='store_true',help="Bulk sample")
    reads_mapping_parser.add_argument('--output_path', '-o', required=True, help="Directory for output [Required]")
    reads_mapping_parser.set_defaults(func=read_mapping)

    bowtie_to_sRNAminer_parser = subparsers.add_parser('bowtie_to_sRNAminer',help='bowtie format converts to sRNAminer format')
    bowtie_to_sRNAminer_parser.add_argument('--input_file', '-i', required=True, help="Set a bowtie result [.bowtie] [Required]")
    bowtie_to_sRNAminer_parser.add_argument('--thread', '-p', default="2", help="The number of thread to run [Default: 2]")
    bowtie_to_sRNAminer_parser.add_argument('--Batch_mode',action='store_true',help="Bulk sample")
    bowtie_to_sRNAminer_parser.add_argument('--output_path', '-o', required=True, help="Directory for output [Required]")
    bowtie_to_sRNAminer_parser.set_defaults(func=bowtie_to_sRNAminer)

    miRNA_identification_parser = subparsers.add_parser('miRNA_identification', help='miRNA identification')
    miRNA_identification_parser.add_argument('--genome_file','-g',required=True,help="Set a genome File [Required]")
    miRNA_identification_parser.add_argument('--index',required=True,help="Set the name of bowtie index [Required]")
    miRNA_identification_parser.add_argument('--input_file','-i',required=True,help="Set a list of sequencing File [Collapsed & Quality Controlled] [Fasta Format]")
    miRNA_identification_parser.add_argument('--locate_num','-l',default="20",help="The number of locations a read can map [Default: 20]")
    miRNA_identification_parser.add_argument('--mismatch','-m',default="1",help="The number of mismatch allowed in alignment [Default: 1]")
    miRNA_identification_parser.add_argument('--thread','-p',default="2",help="The number of thread to run [Default: 2]")
    miRNA_identification_parser.add_argument('--minLen',default="20",choices=["20","21","22","23","24"],help="Minimum length of miRNA [Default: 20]")
    miRNA_identification_parser.add_argument('--maxLen',default="22",choices=["20","21","22","23","24"],help="Maximum length of miRNA [Default: 22]")
    miRNA_identification_parser.add_argument('--Batch_mode',action='store_true',help="Bulk sample")
    miRNA_identification_parser.add_argument('--output_path','-o',required=True,help="Directory for output [Required]")
    miRNA_identification_parser.set_defaults(func=miRNA_identification_for_total)

    miRNA_identification_no_align_parser = subparsers.add_parser('miRNA_identification_no_align', help='miRNA identification without alignment step')
    miRNA_identification_no_align_parser.add_argument('--genome_file','-g',required=True,help="Set a genome File [Required]")
    miRNA_identification_no_align_parser.add_argument('--input_file','-i',required=True,help="Set a list of bowtie results [sRNAminer Format (*.sorted)] [Required]")
    miRNA_identification_no_align_parser.add_argument('--thread','-p',default="2",help="The number of thread to run [Default: 2]")
    miRNA_identification_no_align_parser.add_argument('--minLen',default="20",choices=["20","21","22","23","24"],help="Minimum length of miRNA [Default: 20]")
    miRNA_identification_no_align_parser.add_argument('--maxLen',default="22",choices=["20","21","22","23","24"],help="Maximum length of miRNA [Default: 22]")
    miRNA_identification_no_align_parser.add_argument('--Batch_mode',action='store_true',help="Bulk sample")
    miRNA_identification_no_align_parser.add_argument('--output_path','-o',required=True,help="Directory for output [Required]")
    miRNA_identification_no_align_parser.set_defaults(func=miRNA_identification_no_align_for_total)

    phasiRNA_identification_parser = subparsers.add_parser('phasiRNA_identification', help='phasiRNA identification')
    phasiRNA_identification_parser.add_argument('--genome_file','-g',required=True,help="Set a genome File [Required]")
    phasiRNA_identification_parser.add_argument('--index',required=True,help="Set the name of bowtie index [Required]")
    phasiRNA_identification_parser.add_argument('--input_file','-i',required=True,help="Set a list of sequencing File [Collapsed & Quality Controlled] [Fasta Format]")
    phasiRNA_identification_parser.add_argument('--locate_num','-l',default="20",help="The number of locations a read can map [Default: 20]")
    phasiRNA_identification_parser.add_argument('--lib_num','-b',default="1",help="The minimum of lib PHAS exists [Default: 1]")
    phasiRNA_identification_parser.add_argument('--mismatch','-m',default="1",help="The number of mismatch allowed in alignment [Default: 1]")
    phasiRNA_identification_parser.add_argument('--thread','-p',default="2",help="The number of thread to run [Default: 2]")
    phasiRNA_identification_parser.add_argument('--phasiRNA_len',default="21",choices=["20","21","22","23","24"],help="Length of phasiRNA [Default 21]")
    phasiRNA_identification_parser.add_argument('--PhasingScore',default="10",help="Phasing Score [Default :10]")
    phasiRNA_identification_parser.add_argument('--Pvalue',default="0.001",help="P-value [Default: 0.001]")
    phasiRNA_identification_parser.add_argument('--Batch_mode',action='store_true',help="Bulk sample")
    phasiRNA_identification_parser.add_argument('--output_path','-o',required=True,help="Directory for output [Required]")
    phasiRNA_identification_parser.set_defaults(func=phasiRNA_identification_for_total)

    phasiRNA_identification_no_align_parser = subparsers.add_parser('phasiRNA_identification_no_align', help='phasiRNA identification without alignment step')
    phasiRNA_identification_no_align_parser.add_argument('--genome_file','-g',required=True,help="Set a genome File [Required]")
    phasiRNA_identification_no_align_parser.add_argument('--input_file','-i',required=True,help="Set a list of bowtie results [sRNAminer Format (*.sorted)] [Required]")
    phasiRNA_identification_no_align_parser.add_argument('--lib_num','-b',default="1",help="The minimum of lib PHAS exists [Default: 1]")
    phasiRNA_identification_no_align_parser.add_argument('--thread','-p',default="2",help="The number of thread to run [Default: 2]")
    phasiRNA_identification_no_align_parser.add_argument('--phasiRNA_len',default="21",choices=["20","21","22","23","24"],help="Length of phasiRNA [Default: 21]")
    phasiRNA_identification_no_align_parser.add_argument('--PhasingScore',default="10",help="Phasing Score [Default :10]")
    phasiRNA_identification_no_align_parser.add_argument('--Pvalue',default="0.001",help="P-value [Default: 0.001]")
    phasiRNA_identification_no_align_parser.add_argument('--Batch_mode',action='store_true',help="Bulk sample")
    phasiRNA_identification_no_align_parser.add_argument('--output_path','-o',required=True,help="Directory for output [Required]")
    phasiRNA_identification_no_align_parser.set_defaults(func=PHAS_identification_no_align_for_total)

    hcsiRNA_identification_parser = subparsers.add_parser('hc-siRNA_identification', help='hc-siRNA identification')
    hcsiRNA_identification_parser.add_argument('--genome_file','-g',required=True,help="Set a genome File [Required]")
    hcsiRNA_identification_parser.add_argument('--index',required=True,help="Set the name of bowtie index [Required]")
    hcsiRNA_identification_parser.add_argument('--input_file','-i',required=True,help="Set a list of sequencing File [Collapsed & Quality Controlled] [Required]")
    hcsiRNA_identification_parser.add_argument('--mismatch','-m',default="0",help="The number of mismatch allowed in alignment [Default: 0]")
    hcsiRNA_identification_parser.add_argument('--thread','-p',default="2",help="The number of thread to run [Default: 2]")
    hcsiRNA_identification_parser.add_argument('--minRegionGap',default="200",help="Set minimum region gap [Default: 200]")
    hcsiRNA_identification_parser.add_argument('--minRepeatRatio',default="0.5",help="Set minimum siRNA of specific length (eg. 23,24 nt) abundance ratio to define a locus [Default: 0.5]")
    hcsiRNA_identification_parser.add_argument('--PHAS24_file',required=True,help="Set the PHAS24 Result(Treated by sRNAminer) [Required]")
    hcsiRNA_identification_parser.add_argument('--Batch_mode',action='store_true',help="Bulk sample")
    hcsiRNA_identification_parser.add_argument('--output_path','-o',required=True,help="Directory for output [Required]")
    hcsiRNA_identification_parser.set_defaults(func=hc_siRNA_identification_for_total)

    miRNA_expression_parser = subparsers.add_parser('miRNA_abundance', help='miRNA abundance')
    miRNA_expression_parser.add_argument('--gff_file','-g',required=True,help="Set a miRNA annotation File[gff format] [Required]")
    miRNA_expression_parser.add_argument('--input_file','-i',required=True,help="Set a list of bowtie file(in sorted format) [Required]")
    miRNA_expression_parser.add_argument('--Batch_mode',action='store_true',help="Bulk sample")
    miRNA_expression_parser.add_argument('--output_path','-o',required=True,help="Directory for output [Required]")
    miRNA_expression_parser.set_defaults(func=miRNA_expression_for_total)

    PHAS_expression_parser = subparsers.add_parser('phasiRNA_abundance', help='phasiRNA abundance')
    PHAS_expression_parser.add_argument('--phas_info',required=True,help="Set a phasiRNA annotation File[Table format] [Required]")
    PHAS_expression_parser.add_argument('--input_file','-i',required=True,help="Set a list of bowtie results [sRNAminer Format (*.sorted)] [Required]")
    PHAS_expression_parser.add_argument('--phasiRNA_len',default="21",help="Length of phasiRNA [Default: 21]")
    PHAS_expression_parser.add_argument('--Batch_mode',action='store_true',help="Bulk sample")
    PHAS_expression_parser.add_argument('--output_path','-o',required=True,help="Directory for output [Required]")
    PHAS_expression_parser.set_defaults(func=PHAS_expression_for_total)

    sRNA_Target_parser = subparsers.add_parser('sRNA_target', help='Finding the target of sRNA')
    sRNA_Target_parser.add_argument('--input_file', '-i', required=True,
                                     help=" Set input miRNA.fa  file for search (Suggest Only One miRNA or One miRNA family One time)... [Required]")
    sRNA_Target_parser.add_argument('--subject_file', '-s', required=True,
                                     help="Set input genome.fa file for search... [Required]")
    sRNA_Target_parser.add_argument('--Fragment', action='store_true', help="Set if fragment genome before searching")
    sRNA_Target_parser.add_argument('--thread', '-p', default="2", help="The number of thread to run [Default: 2]")
    sRNA_Target_parser.add_argument('--SearchCom', action='store_true', help="Whether to search rev and com Strand")
    sRNA_Target_parser.add_argument('--Evalue', default="10000", help="e-value [Default: 10000]")
    sRNA_Target_parser.add_argument('--maxMismatch', default="6", help="Set maximum misMatch bases [Default: 6]")
    sRNA_Target_parser.add_argument('--Score', default="5", help="Set maximum cut score(penalty) [Default: 5]")
    sRNA_Target_parser.add_argument('--output_file', '-o', required=True, help="File for output [Required]")
    sRNA_Target_parser.set_defaults(func=sRNA_Target_for_total)

    PHAS_Trigger_parser = subparsers.add_parser('phasiRNA_trigger', help='PHAS Trigger prediction')
    PHAS_Trigger_parser.add_argument('--thread', '-p', default="2", help="The number of thread to run")
    PHAS_Trigger_parser.add_argument('--input_file', '-i', required=True,
                                     help="Set a miRNA sequences file [Required]")
    PHAS_Trigger_parser.add_argument('--genome_file', '-g', required=True,
                                     help="Set a genome file [Required]")
    PHAS_Trigger_parser.add_argument('--phas_info', required=True,help="Set phasiRNA info in sRNAminer phasiRNA identification result [Required]")
    PHAS_Trigger_parser.add_argument('--phasiRNA_len', default="21",help="Length of phasiRNA [Default: 21]")
    PHAS_Trigger_parser.add_argument('--FlankLen', default="200", help="Set flanking length to PHAS region [Default: 200]")
    PHAS_Trigger_parser.add_argument('--output_file', '-o', required=True, help="File for output [Required]")
    PHAS_Trigger_parser.set_defaults(func=PHAS_Trigger_for_total)

    sRNAloci_identification_parser = subparsers.add_parser('sRNAlocus_identification', help='sRNAlocus identification')
    sRNAloci_identification_parser.add_argument('--input_file','-i',required=True,help="Set a list of bowtie results [sRNAminer Format (*.sorted)][Required]")
    sRNAloci_identification_parser.add_argument('--minReadDepth',default="1000",help="Minimum region depth [Default: 1000]")
    sRNAloci_identification_parser.add_argument('--minRegionGap',default="300",help="Minimum region gap [Default: 300]")
    sRNAloci_identification_parser.add_argument('--Batch_mode',action='store_true',help="Bulk sample")
    sRNAloci_identification_parser.add_argument('--output_path','-o',required=True,help="Directory for output [Required]")
    sRNAloci_identification_parser.set_defaults(func=sRNAloci_identification_for_total)

    sRNAloci_expression_parser = subparsers.add_parser('sRNAlocus_abundance', help='sRNAlocus abundance')
    sRNAloci_expression_parser.add_argument('--input_file','-i',required=True,help="Set a list of bowtie results [sRNAminer Format (*.sorted)] [Required]")
    sRNAloci_expression_parser.add_argument('--sRNAlocus_file',required=True, help="ID\tChr\tStart\tEnd [Required]")
    sRNAloci_expression_parser.add_argument('--Batch_mode',action='store_true',help="Bulk sample")
    sRNAloci_expression_parser.add_argument('--output_file','-o',required=True,help="File for output [Required]")
    sRNAloci_expression_parser.set_defaults(func=sRNAloci_expression_for_total)

    phasiRNA_extract_parser = subparsers.add_parser('phasiRNA_extraction', help='Extracting phasiRNA')
    phasiRNA_extract_parser.add_argument('--phas_info',required=True,help="Set phasiRNA info in sRNAminer phasiRNA identification result [Required]")
    phasiRNA_extract_parser.add_argument('--genome_file','-g',required=True, help="Genome File [Required]")
    phasiRNA_extract_parser.add_argument('--phasiRNA_len',default="21", help="Length of phasiRNA [Default: 21]")
    phasiRNA_extract_parser.add_argument('--output_file','-o',required=True,help="File for output [Required]")
    phasiRNA_extract_parser.set_defaults(func=phasiRNA_extract_for_total)

    sRNA_extract_parser = subparsers.add_parser('sRNA_extraction', help='Extracting sRNA')
    sRNA_extract_parser.add_argument('--sRNAlocus_file',required=True,help="ID\tChr\tStart\tEnd [Required]")
    sRNA_extract_parser.add_argument('--mappingFile',required=True, help="Set a list of bowtie results [sRNAminer Format (*.sorted)] [Required]")
    sRNA_extract_parser.add_argument('--Batch_mode', action='store_true', help="Bulk sample")
    sRNA_extract_parser.add_argument('--output_path','-o',required=True,help="Directory for output [Required]")
    sRNA_extract_parser.set_defaults(func=sRNA_extract_for_total)

    PHASListToGraph_parser = subparsers.add_parser('PHASLocusToGraph', help='Graphing PHAS Locus')
    PHASListToGraph_parser.add_argument('--phas', '-p', required=True, help="ID\tChr\tStart\tEnd [Required]")
    PHASListToGraph_parser.add_argument('--phaseLen', '-l', default="21", help="Length of phasiRNA [Default: 21]")
    PHASListToGraph_parser.add_argument('--mappingFile', '-m', required=True,
                                     help="Set a sRNA lib bowtie mapping result [sRNAminer Format (*.sorted)] [Required]")
    PHASListToGraph_parser.add_argument('--trigger', '-t', default="", help="Set sRNA-directed cleave position, formatted as sRNAId\tChromosome\tStartPos\tEndPos\tCleavePosition\tStrand\tPHASID [Optional]")
    PHASListToGraph_parser.add_argument('--output_format', '-f', default="png", help="Set output graph format [jpg|pdf|png|svg] [Default:png]")
    PHASListToGraph_parser.add_argument('--output_dir', '-o', required=True, help="Directory for output [Required]")
    PHASListToGraph_parser.set_defaults(func=PHASListToGraph_for_total)




    return parser

def main():
    parser = get_parser()
    args = parser.parse_args()
    print(args)
    args.func(args)



if __name__ == '__main__':
    main()
