def create_command(lz_cmdlist, outfolder, logname, chromosome=None):
    cmd_list = ["python lz_meta.py"]
    cmd_list.extend(lz_cmdlist)
    if chromosome is not None:
        c_cmd = ["--chromosome",str(chromosome)]
        cmd_list.extend(c_cmd)
    #locate log folder
    lf = pc_toolbox.log_folder(outfolder)
    log_file = os.path.join(lf,logname)
    #add log command
    t_cmd = ["2>&1|tee",log_file]
    cmd_list.extend(t_cmd)
    
    cmd = ' '.join(cmd_list)
    print ('My log file is {0} and my command is {1}'.format(log_file,cmd))
    return cmd
def create_command(script_loc , pheno_tag=None):
    global chromosome,range_start_bp,range_end_bp,plink_test
    global p_bound, pheno_loc, c_interval, chrband, build
    global output_folder, maxloops, out_flag, condition_list, interrupt
    cmd_list = ["python pc_workhorse.py","--chromosome",chromosome,
                "--from-bp", str(range_start_bp),"--to-bp", str(range_end_bp),
                "--pbound",str(p_bound), "--test", plink_test,
                "--script", script_loc, "--outfolder",output_folder,
                "--loop",str(maxloops), "--build",build]
##    if interrupt:
##        cmd_list.extend(['--interrupt'])
    of = ""
    if out_flag is not None:
        of = '_'+out_flag
        f_cmd = ["--flag",out_flag]
        cmd_list.extend(f_cmd)
        
    logname = ""
    
    log_start = 'Chr'+chromosome+'_'
##    if refgene is not None:
##        r_cmd = ["--refgene",refgene]
##        cmd_list.extend(r_cmd)
    if chrband is None:
        log_start = 'Chr'+chromosome+'_'
        if refgene is None:
            r_start = convert_bp_to_mb(range_start_bp)
            r_end = convert_bp_to_mb(range_end_bp)
            logname =log_start + r_start + '-'+r_end+of
        else:
            logname = log_start + refgene+of
    else:
        logname = chrband + of
        b_cmd = ["--chrband",chrband]
        cmd_list.extend(b_cmd)
    
    lf = pc_toolbox.log_folder(output_folder)
    #log_file = os.path.join(lf,log)
    if pheno_tag is not None:
        logname = logname + '_'+pheno_tag
        p_cmd = ["--pheno-tag",pheno_tag]
        cmd_list.extend(p_cmd)
    ci_cmd = []
    if c_interval is None and plink_test in ('logistic',
                                             'linear','assoc',
                                             'fisher'):
        c_interval = C_INTERVAL
    if c_interval is not None:
        ci_cmd = ["--ci",str(c_interval)]
        cmd_list.extend(ci_cmd)
    
    t_cmd = []
    
    if condition_list is None:
        log = logname + '.log'
        log_file = os.path.join(lf,log)
        t_cmd = ["2>&1|tee",log_file]
    elif interrupt:
        cmd_list.extend(['--interrupt'])
        c_cmd = ["--condition-list",condition_list]
        cmd_list.extend(c_cmd)
        if '~' in condition_list:
            log = logname + '~.log'
        else:
            log = logname + '.log'
        log_file = os.path.join(lf,log)
        t_cmd = ["2>&1|tee -a",log_file]
    else:
        c_cmd = ["--condition-list",condition_list]
        cmd_list.extend(c_cmd)
        log = logname + '~.log'
        log_file = os.path.join(lf,log)
        t_cmd = ["2>&1|tee",log_file]

    #t_cmd = ["2>&1|tee",log_file]
    cmd_list.extend(t_cmd)
    
    cmd = ' '.join(cmd_list)
    print ('My log file is {0} and my command is {1}'.format(log_file,cmd))
    return cmd