def read_params(args):
    parser = argparse.ArgumentParser(description="tax star plot at genus level | v1.0 at 2015/10/09 by liangzb")
    parser.add_argument(
        "-t",
        "--tax_assignment",
        dest="tax_ass",
        metavar="FILE",
        type=str,
        required=True,
        help="set the tax assignment file",
    )
    parser.add_argument(
        "-i",
        "--uniform_profile",
        dest="profile",
        metavar="FILE",
        type=str,
        required=True,
        help="set the uniform profile table",
    )
    parser.add_argument(
        "-o", "--out_dir", dest="out_dir", metavar="DIR", type=str, required=True, help="set the output dir"
    )
    parser.add_argument(
        "-s", "--sort", dest="sort", metavar="FILE", type=str, default=None, help="set the file to sort"
    )

    args = parser.parse_args()
    params = vars(args)
    if params["sort"] is not None:
        params["sort"] = list(parse_group_file(params["sort"]).iterkeys())
    return params
def read_params(args):
    parser = argparse.ArgumentParser(description='tax bar plot | v1.0 at 2015/11/06 by liangzb')
    parser.add_argument('-t', '--wf_tax_dir', dest='wf_tax_dir', metavar='DIR', type=str, required=True,
                        help="set the wf_taxa_summary dir produced by summarize_taxa.py")
    parser.add_argument('-g', '--group', dest='group', metavar='FILE', type=str, default=None,
                        help="set the group_file")
    parser.add_argument('-o', '--out_dir', dest='out_dir', metavar='DIR', type=str, required=True,
                        help="set the output dir")
    parser.add_argument('-l', '--level', dest='level_list', metavar='INTs', nargs='+', type=int,
                        default=[2, 3, 4, 5, 6],
                        help="set the tax level, 1..7 stands for kingdom..species, [default is 2 3 4 5 6]")
    parser.add_argument('--with_group', dest='with_group', action='store_true',
                        help="plot group bar plot, if group is not set, this param will not be used")
    parser.add_argument('--without_group', dest="with_group", action='store_false',
                        help="plot sample bar plot, if this params is set, group file will only for order")
    parser.add_argument('--contains_other', dest="contains_other", action='store_true',
                        help="totel abundance contains other abundance ; totel aundance is 1")
    parser.add_argument('--top', dest="top",metavar="INT",type=int,default=20,
                        help='set the top num, [default is 20]')
    parser.add_argument('--filter_value', dest="filter_value",metavar="float",type=float,default=0.01,
                        help='del abundance <0.01')
    parser.set_defaults(with_group=False)
    args = parser.parse_args()
    params = vars(args)
    params['group'] = parse_group_file(params['group'])
    return params
def read_params(args):
    parser = argparse.ArgumentParser(description='a wrapper for rdp classify | v1.0 at 2015/09/18 by liangzb')
    parser.add_argument('--pick_rep_set', dest='pick_rep_set', metavar='FILE', type=str, default='pick_rep_set.py',
                        help="set the pick_rep_set.py of qiime, [default find in env]")
    parser.add_argument('-i', '--otu_mapping_file', dest='otu_mapping', metavar='FILE', type=str, required=True,
                        help="set the otu mapping file")
    parser.add_argument('-f', '--fasta_file', dest='reference_seqs', metavar='FILE', type=str, required=True,
                        help="set the fasta file")
    parser.add_argument('-m', '--picking_method', dest='picking_method', metavar='STR', choices=['first',
                                                                                                 'random',
                                                                                                 'longest',
                                                                                                 'most_abundant'],
                        type=str, default='most_abundant',
                        help="set the picking method, choice from: first, random, longest, most_abundant, \
                              [default is most_abundant]")
    parser.add_argument('-g', '--group', dest='group', metavar='FILE', type=str, default=None,
                        help="set the group file, if is setted, \
                             rep set will pick each group with a prefix of group_name")
    parser.add_argument('-o', '--outdir', dest='outdir', metavar='DIR', type=str, required=True,
                        help="set the output dir")
    args = parser.parse_args()
    params = vars(args)
    if params['group']:
        params['group'] = parse_group_file(params['group'])
    else:
        params['group'] = None
    return params
Exemple #4
0
def read_params(args):
    parser = argparse.ArgumentParser(description='plot tax tree| v1.0 at 2015/01/06 by liangzb')
    parser.add_argument('--profile', dest='profile', metavar='FILE', type=str, required=True,
                        help="set the profile file")
    parser.add_argument('--tax_ass', dest='tax_ass', metavar='FILE', type=str, required=True,
                        help="set the tax_assignment.txt")
    parser.add_argument('-g', '--group_file', dest='group', metavar='FILE', type=str, default=None,
                        help="set the group file if need")
    parser.add_argument('--top', dest='top', metavar='INT', type=int, default=20,
                        help="set the top num, [default is 20]")
    parser.add_argument('-o', '--outdir', dest='outdir', metavar='DIR', type=str, required=True,
                        help="set the outdir")
    parser.add_argument('--plot_in_samples', dest='plot_in_samples', action='store_true',
                        help="plot every sample's tree")
    parser.add_argument('--with_leaf_pie', dest='with_leaf_pie', action='store_true',
                        help="plot with leaf pie chart, [default is false]")
    parser.set_defaults(with_leaf_pie=False)
    parser.add_argument('--with_branch_circle', dest='with_branch_circle', action='store_true',
                        help="plot with branch circle, [default is false]")
    parser.set_defaults(with_branch_circle=False)

    args = parser.parse_args()
    params = vars(args)
    params['group'] = parse_group_file(params['group'])
    return params
Exemple #5
0
def read_params(args):
    parser = argparse.ArgumentParser(
        description='''otu venn analysis | v1.0 at 2015/10/13 by liangzb ''')
    parser.add_argument('-i',
                        '--otu_profile',
                        dest='otu_table',
                        metavar='FILE',
                        type=str,
                        required=True,
                        help="set the otu table file")
    parser.add_argument('-g',
                        '--group_file',
                        dest='group',
                        metavar='FILE',
                        type=str,
                        required=True,
                        help="set the group file")
    parser.add_argument('-o',
                        '--out_dir',
                        dest='out_dir',
                        metavar='DIR',
                        type=str,
                        required=True,
                        help="set the output dir")
    args = parser.parse_args()
    params = vars(args)
    params['group_dir'] = params['group']
    params['group'] = parse_group_file(params['group'])
    return params
Exemple #6
0
def read_params(args):
    parser = argparse.ArgumentParser(description='''beta cluster wrapper | v1.0 at 2015/10/16 by liangzb ''')
    parser.add_argument('--jackknifed_beta_diversity', dest='jack_soft', metavar='STR', type=str,
                        default="jackknifed_beta_diversity.py",
                        help="set the jackknifed_beta_diversity.py, default find in env")
    parser.add_argument('--make_bootstrapped_tree', dest='bootstrap_soft', metavar='STR', type=str,
                        default="make_bootstrapped_tree.py",
                        help="set the make_bootstrapped_tree.py, default find in env")
    parser.add_argument('-i', '--otu_biom', dest='otu_biom', metavar='FILE', type=str, required=True,
                        help="set the otu biom file")
    parser.add_argument('-t', '--tree_file', dest='tree_file', metavar='FILE', type=str, required=True,
                        help="set the tree file")
    parser.add_argument('-g', '--group_file', dest='group_file', metavar='FILE', type=str, default=None,
                        help="set the group file")
    parser.add_argument('-s', '--seqs_per_sample', dest='seqs', metavar="INT", type=int, default=None,
                        help="set the seqs_per_sample, can be overrited if set stat_file")
    parser.add_argument('--stat_file', dest='stat_file', metavar='FILE', type=str, default=None,
                        help="set the stat file produced by 01_stat.py")
    parser.add_argument('--add_params', dest='add_params', metavar='STR', type=str, default=None,
                        help="add params commands")
    parser.add_argument('-o', '--out_dir', dest='out_dir', metavar='DIR', type=str, required=True,
                        help="set the output dir")
    args = parser.parse_args()
    params = vars(args)
    if params['stat_file'] is not None:
        maximum, minimum = parse_stat_file(params['stat_file'], group_file=params['group_file'])
        params['seqs'] = minimum
    if params['group_file'] is not None:
        params['group'] = parse_group_file(params['group_file'])
    if params['seqs'] is None and params['stat_file'] is None:
        parser.print_help()
        sys.exit()
    return params
def read_params(args):
    parser = argparse.ArgumentParser(description='''downsize script | v1.0 at 2015/09/28 by liangzb ''')
    parser.add_argument('-m', '--minimum', dest='minimum', metavar='INT', type=int, default=None,
                        help="set the minimum to downsize, [default is None]")
    parser.add_argument('-s', '--in_statfile', dest='statfile', metavar='INT', type=str, default=None,
                        help="find the minimum from statfile which produced by 01_stat, can be overrited by MINIMUM")
    parser.add_argument('-i', '--otu_mapfile', dest='otu_map', metavar='STR', type=str, required=True,
                        help="set the otu_mapfile")
    parser.add_argument('-o', '--outfile', dest='outfile', metavar='OUTFILE', type=str, required=True,
                        help="set the output file")
    parser.add_argument('--out_statfile', dest='outstatfile', metavar='FILE', type=str, default=None,
                        help="set the stat file")
    parser.add_argument('--keep_small_size', dest='keep', action='store_true',
                        help="keep the small size [default]")
    parser.add_argument('--no_keep_small_size', dest='keep', action='store_false',
                        help="do not keep the small size")
    parser.set_defaults(keep=True)
    parser.add_argument('--random', dest='random', action='store_true',
                        help="downsize random [default]")
    parser.add_argument('--no_random', dest='random', action='store_false',
                        help="do not downsize random")
    parser.set_defaults(random=True)
    parser.add_argument('-g', '--group', dest='group', metavar='FILE', type=str, default=None,
                        help="if set the group file, in_stat_file will be overwrited")

    args = parser.parse_args()
    params = vars(args)
    if params['minimum'] is None and params['statfile'] is None:
        parser.print_help()
        sys.exit()
    if params['minimum'] is None and params['statfile'] is not None:
        maximum, params['minimum'] = parse_stat_file(params['statfile'], group_file=params['group'])
    params['group'] = parse_group_file(params['group'])
    return params
Exemple #8
0
def read_params(args):
    parser = argparse.ArgumentParser(
        description='a wrapper for LEfSe | v1.0 at 2015/10/19 by liangzb')
    parser.add_argument(
        '-i',
        '--summarize_all',
        dest='infile',
        metavar='FILE',
        type=str,
        required=True,
        help="set hte otu_table_all.txt produced by 02_summarize_trans.py")
    parser.add_argument('-l',
                        '--LEfSe_path',
                        dest='LEfSe_path',
                        metavar='DIR',
                        type=str,
                        default=None,
                        help="set the LEfSe path, default find in env")
    parser.add_argument('-g',
                        '--group_file',
                        dest='group',
                        metavar='FILE',
                        type=str,
                        required=True,
                        help="set the group file")
    parser.add_argument('-o',
                        '--out_dir',
                        dest='out_dir',
                        metavar='DIR',
                        type=str,
                        required=True,
                        help="set the output dir")
    parser.add_argument('--LDA',
                        dest='LDA',
                        metavar='FLOAT',
                        type=float,
                        default=2,
                        help="set the LDA cutoff, [default is 2]")
    parser.add_argument('--class_row',
                        dest='c',
                        metavar='INT',
                        type=int,
                        default=1,
                        help="set the class row, [default is 1]")
    parser.add_argument('--subject_row',
                        dest='u',
                        metavar='INT',
                        type=int,
                        default=2,
                        help="set the subject row, [default is 2]")
    args = parser.parse_args()
    params = vars(args)
    params['group'] = parse_group_file(params['group'])
    if params['LEfSe_path'] is None:
        params['LEfSe_path'] = ''
    else:
        params['LEfSe_path'] += '/'
    return params
def read_params(args):
    parser = argparse.ArgumentParser(description='''otu venn analysis | v1.0 at 2015/10/13 by liangzb ''')
    parser.add_argument('-i', '--otu_profile', dest='otu_table', metavar='FILE', type=str, required=True,
                        help="set the otu table file")
    parser.add_argument('-g', '--group_file', dest='group', metavar='FILE', type=str, required=True,
                        help="set the group file")
    parser.add_argument('-o', '--out_dir', dest='out_dir', metavar='DIR', type=str, required=True,
                        help="set the output dir")
    args = parser.parse_args()
    params = vars(args)
    params['group_dir'] = params['group']
    params['group'] = parse_group_file(params['group'])
    return params
def read_params(args):
    parser = argparse.ArgumentParser(description='''diff boxplot | v1.0 at 2015/10/26 by liangzb ''')
    parser.add_argument('-i', '--infile', dest='infile', metavar='file', type=str, required=True,
                        help="set the marker profile file in")
    parser.add_argument('-o', '--outdir', dest='outdir', metavar='DIR', type=str, required=True,
                        help="set the work dir")
    parser.add_argument('-g', '--group', dest='group', metavar='FILE', type=str, required=True,
                        help="set the group file")
    parser.add_argument('-t', '--top', dest='top', metavar='INT', type=str, default='20',
                        help="set the top num, [default is 20], show all by set it 'all'")
    args = parser.parse_args()
    params = vars(args)
    if params['top'] != 'all':
        params['top'] = int(params['top'])
    else:
        params['top'] = None
    params['group'] = parse_group_file(params['group'])
    params['for_plot'] = params['outdir'] + '/diff_boxplot.for_plot_top_%s.txt' % params['top']
    return params
def read_params(args):
    parser = argparse.ArgumentParser(
        description=
        'tax star plot at genus level | v1.0 at 2015/10/09 by liangzb')
    parser.add_argument('-t',
                        '--tax_assignment',
                        dest='tax_ass',
                        metavar='FILE',
                        type=str,
                        required=True,
                        help="set the tax assignment file")
    parser.add_argument('-i',
                        '--uniform_profile',
                        dest='profile',
                        metavar='FILE',
                        type=str,
                        required=True,
                        help="set the uniform profile table")
    parser.add_argument('-o',
                        '--out_dir',
                        dest='out_dir',
                        metavar='DIR',
                        type=str,
                        required=True,
                        help="set the output dir")
    parser.add_argument('-s',
                        '--sort',
                        dest='sort',
                        metavar='FILE',
                        type=str,
                        default=None,
                        help="set the file to sort")

    args = parser.parse_args()
    params = vars(args)
    if params['sort'] is not None:
        params['sort'] = list(parse_group_file(params['sort']).iterkeys())
    return params
Exemple #12
0
 def __init__(self, profile, taxfile, outfile, group_file=None, expand=1):
     self.table = TableParser(profile)
     self.otu_tax = TaxParser(taxfile)
     self.group = parse_group_file(group_file)
     if self.group is not None:
         self.groups = list(set(self.group.itervalues()))
     else:
         self.groups = None
     self.outfile = outfile
     self.expand = expand
     self.tax_level = ['kingdom', 'phylum', 'class', 'order', 'family', 'genus', 'species']
     self.tax_dict = {
         'k': 'kingdom',
         'p': 'phylum',
         'c': 'class',
         'o': 'order',
         'f': 'family',
         'g': 'genus',
         's': 'species',
     }
     self.samples = {}
     self.node_list = {}
     self.root_nodes = {}
Exemple #13
0
def read_params(args):
    parser = argparse.ArgumentParser(description='a wrapper for LEfSe | v1.0 at 2015/10/19 by liangzb')
    parser.add_argument('-i', '--summarize_all', dest='infile', metavar='FILE', type=str, required=True,
                        help="set hte otu_table_all.txt produced by 02_summarize_trans.py")
    parser.add_argument('-l', '--LEfSe_path', dest='LEfSe_path', metavar='DIR', type=str, default=None,
                        help="set the LEfSe path, default find in env")
    parser.add_argument('-g', '--group_file', dest='group', metavar='FILE', type=str, required=True,
                        help="set the group file")
    parser.add_argument('-o', '--out_dir', dest='out_dir', metavar='DIR', type=str, required=True,
                        help="set the output dir")
    parser.add_argument('--LDA', dest='LDA', metavar='FLOAT', type=float, default=2,
                        help="set the LDA cutoff, [default is 2]")
    parser.add_argument('--class_row', dest='c', metavar='INT', type=int, default=1,
                        help="set the class row, [default is 1]")
    parser.add_argument('--subject_row', dest='u', metavar='INT', type=int, default=2,
                        help="set the subject row, [default is 2]")
    args = parser.parse_args()
    params = vars(args)
    params['group'] = parse_group_file(params['group'])
    if params['LEfSe_path'] is None:
        params['LEfSe_path'] = ''
    else:
        params['LEfSe_path'] += '/'
    return params
    return params


def work(sample_list, group_dict, outfile):
    with open(outfile, 'w') as out:
        group_names = sorted(list(group_dict.iterkeys()))
        out.write('#SampleID\t%s\n' % '\t'.join(group_names))
        for sample in sample_list:
            out_str = sample
            for group_name in group_names:
                group = group_dict[group_name]
                if sample not in group:
                    group[sample] = ''
                out_str += '\t%s' % group[sample]
            out.write(out_str.strip() + '\n')


if __name__ == '__main__':
    params = read_params(sys.argv)
    mkdir(os.path.dirname(params['outfile']))
    sample_list = []
    group_dict = {}
    for group_file in params['group_list']:
        group_name = os.path.basename(group_file)
        group_name = os.path.splitext(group_name)[0]
        group = parse_group_file(group_file)
        group_dict[group_name] = group
        sample_list += list(group.iterkeys())
    sample_list = list(set(sample_list))
    work(sample_list, group_dict, params['outfile'])
    return params


def work(sample_list, group_dict, outfile):
    with open(outfile, 'w') as out:
        group_names = sorted(list(group_dict.iterkeys()))
        out.write('#SampleID\t%s\n' % '\t'.join(group_names))
        for sample in sample_list:
            out_str = sample
            for group_name in group_names:
                group = group_dict[group_name]
                if sample not in group:
                    group[sample] = ''
                out_str += '\t%s' % group[sample]
            out.write(out_str.strip() + '\n')


if __name__ == '__main__':
    params = read_params(sys.argv)
    mkdir(os.path.dirname(params['outfile']))
    sample_list = []
    group_dict = {}
    for group_file in params['group_list']:
        group_name = os.path.basename(group_file)
        group_name = os.path.splitext(group_name)[0]
        group = parse_group_file(group_file)
        group_dict[group_name] = group
        sample_list += list(group.iterkeys())
    sample_list = list(set(sample_list))
    work(sample_list, group_dict, params['outfile'])
        tail = tail.rstrip().split()[3:]
    for ind, sample in enumerate(samples):
        group_name = group[sample]
        if group_name not in alphas:
            alphas[group_name] = []
        if tail[ind] == "n/a":
            continue
        alphas[group_name].append(tail[ind])
    return alphas


def write(outfile, alphas, group):
    group_sort = list(group.itervalues())
    group_names = sorted(set(group_sort), key=group_sort.index)
    with open(outfile, 'w') as out:
        for group_name in group_names:
            alpha_list = alphas[group_name]
            alpha_list = '\t'.join(alpha_list)
            out.write('%s\t%s\n' % (group_name, alpha_list))


if __name__ == '__main__':
    params = read_params(sys.argv)
    mkdir(params['out_dir'])
    group = parse_group_file(params['group'])
    for alpha_name in params['alpha_metrics'].split(','):
        file = '%s/%s.txt' % (params['alpha_dir'], alpha_name)
        outfile = '%s/%s.txt' % (params['out_dir'], alpha_name)
        alphas = work_single(file, group)
        write(outfile, alphas, group)
Exemple #17
0
        if group_name not in alphas:
            alphas[group_name] = []
        if tail[ind] == "n/a":
            continue
        alphas[group_name].append(tail[ind])
    return alphas


def write(outfile, alphas, group):
    group_sort = list(group.itervalues())
    group_names = sorted(set(group_sort), key=group_sort.index)
    with open(outfile, 'w') as out:
        for group_name in group_names:
            alpha_list = alphas[group_name]
            alpha_list = '\t'.join(alpha_list)
            out.write('%s\t%s\n' % (group_name, alpha_list))


if __name__ == '__main__':
    params = read_params(sys.argv)
    mkdir(params['out_dir'])
    group = parse_group_file(params['group'])
    for alpha_name in params['alpha_metrics'].split(','):
        file = '%s/%s.txt' % (params['alpha_dir'], alpha_name)
        outfile = '%s/%s.txt' % (params['out_dir'], alpha_name)
	data = pd.DataFrame.from_csv(file,sep="\t")
        data[group.keys()].to_csv("%s_tmp"%(file),sep="\t")
	file = "%s_tmp"%(file)
        alphas = work_single(file, group)
        write(outfile, alphas, group)