def start(): try: # Create target Directory os.mkdir(data_dir) print("Directory", data_dir, "Created.") except FileExistsError: pass file_path = os.path.join(data_dir, 'data.csv') if not (os.path.exists(file_path)): f = open(file_path, 'w') f.close() read_file = open(file_path, 'r+') lines = read_file.readlines() if (lines.__len__() == 0): placeholder = 'Taking over the world' else: placeholder = get_placeholder_from_line(lines[-1]) read_file.close() append_file = open(file_path, 'a+') result = entry(text="What are you working on?", placeholder=placeholder) now = datetime.datetime.now() data_to_append = f"{now},{result}\n" print(f"Appending {data_to_append} to datefile: {file_path}.") append_file.write(data_to_append) append_file.close()
del D[col] ###Making a subset based on regions #User input and application q = zp.question( title="Mutation Filtering", text= "Do you want to select a subset of regions? Click 'No' in order to analyze all regions!" ) if q == True: regs = M["sample_source_location_state"].unique() regions = [str(a + 1) + " " + b for (a, b) in zip(range(len(regs)), regs)] selection = zp.entry( title="Mutation Filtering", text= "Please enter the NUMBER of the regions you want to include! e.g. 1,2,4\n\n" + "\n".join(regions)) sel = [regs[i] for i in [int(j) - 1 for j in selection.split(",")]] M = M[M["sample_source_location_state"].isin(sel)] for col in D.columns: if not (col.split("_")[0] + "_" + col.split("_")[1]) in M.index: del D[col] ###Making a subset based on locations #User input and application q = zp.question( title="Mutation Filtering", text= "Do you want to select a subset of locations? Click 'No' in order to analyze all locations!"
title="CoMA", text= "A tree file is required for the calculation of Faith's phylogenetic diversity!" ) print("\nProcess terminated!") print( "\n________________________________________________________________________________\n" ) sys.exit(1) metric = "faith_pd" label = "Faith's PD" mname = "faith_pd" ftype = zp.entry( title="CoMA", text= "Which fileformat do you prefer?\n\neps, jpeg, pdf, png, ps, raw, rgba, svg, svgz, tiff\n" ) if ftype == None: print("\nProcess terminated!") print( "\n________________________________________________________________________________\n" ) sys.exit(1) elif ftype not in [ "eps", "jpeg", "pdf", "png", "ps", "raw", "rgba", "svg", "svgz", "tiff" ]: zp.error(title="CoMA", text="Invalid Input, process terminated!") print("\nProcess terminated!") print( "\n________________________________________________________________________________\n"
#! /usr/bin/env python #-*- coding: UTF-8 -*- from zenipy import entry from zenipy import message peso = entry(text='Peso - Use ponto como separador do Peso', placeholder='Digite O Peso', title='IMC') altura = entry(text='Altura - Use ponto como separador da Altura', placeholder='Digite A Altura', title='IMC') imc = float(peso) / (float(altura) * float(altura)) if imc < 17: message(title='IMC', text="%s " '\nIMC Excessivamente Baixo' % (imc)) elif (17 < imc < 18.49): message(title='IMC', text="%s " '\nIMC Baixo' % (imc)) elif (18.5 < imc < 24.99): message(title='IMC', text="%s " '\nIMC Normal' % (imc)) elif (25 < imc < 29.99): message(title='IMC', text="%s " '\nIMC Sobrepeso' % (imc)) elif (30 < imc < 34.99): message(title='IMC', text="%s " '\nIMC Obesidade I' % (imc)) elif (35 < imc < 39.99): message(title='IMC', text="%s " '\nIMC Obesidade II (Severa)' % (imc)) elif imc > 40: message(title='IMC', text="%s " '\nIMC Obesidade III (Móbida)' % (imc))
metric = "chao1" label = "Chao1" mname = "chao1" if metric == "Faith_PD": try: tree_file = sys.argv[4] except: zp.error(title="CoMA", text="A tree file is required for the calculation of Faith's phylogenetic diversity!") print("\nProcess terminated!") print("\n________________________________________________________________________________\n") sys.exit(1) metric = "faith_pd" label = "Faith's PD" mname = "faith_pd" var = zp.entry(title="CoMA", text="Based on which metadata variable do you want to group your samples?\n\nYou can select between the following variables:\n\n" + ", ".join(map_df.columns) + "\n") ftype = zp.entry(title="CoMA", text="Which fileformat do you prefer?\n\neps, jpeg, pdf, png, ps, raw, rgba, svg, svgz, tiff\n") if ftype == None: print("\nProcess terminated!") print("\n________________________________________________________________________________\n") sys.exit(1) elif ftype not in ["eps", "jpeg", "pdf", "png", "ps", "raw", "rgba", "svg", "svgz", "tiff"]: zp.error(title="CoMA", text="Invalid Input, process terminated!") print("\nProcess terminated!") print("\n________________________________________________________________________________\n") sys.exit(1) else: figname = "alphadiversity_" + mname + "_" + var + "." + ftype if ftype in ["jpeg", "png", "raw", "rgba", "tiff"]:
import zenipy as zp import sys import os import subprocess infile = sys.argv[1] outfile = sys.argv[2] with open(infile) as inf: inf.readline() samples = inf.readline().split("\t")[1:-1] variables = zp.entry( title="CoMA", text= "Please type in the variable names you want to add, seperated with ',' (e.g. season,body_site,year)" ) with open(outfile, "w") as outf: outf.write("\t" + "\t".join(variables.split(",")) + "\n") for sample in samples: outf.write(sample + len(variables.split(",")) * "\t" + "\n") zp.message( title="CoMA", text= "Please fill in all missing data in the map file; save then as tab-delimited text file. When you are finished, a quick check will be done to prove your input.\n\nClick now OK to start entering your metadata!", height=100) os.system("libreoffice --calc %s" % (outfile))
) if mapping == True: try: map_file = sys.argv[2] except: pz.error(title="CoMA", text="No mapping file provided, process terminated!") print("\nNo mapping file provided, process terminated!") print( "\n________________________________________________________________________________\n" ) sys.exit(1) map_DF = pd.read_csv(map_file, delimiter="\t", index_col=0) var = pz.entry( title="CoMA", text= "Based on which metadata variable do you want to group your samples?\n\nYou can select between the following variables:\n\n" + ", ".join(map_DF.columns) + "\n") if len(map_DF[var].value_counts()) > 3: pz.error( title="CoMA", text= "You can only create Venn plots for the comparison of 2 or 3 groups! You provided %s groups, process terminated!" ) print( "\nYou can only create Venn plots for the comparison of 2 or 3 groups! You provided %s groups, process terminated!" ) print( "\n________________________________________________________________________________\n" ) sys.exit(1)
import os import pandas as pd import zenipy as zp otu_table = sys.argv[1] map_file = sys.argv[2] outfile = sys.argv[3] otu_DF = pd.read_csv(otu_table, delimiter="\t", header=1, index_col=0) samples = list(otu_DF.columns)[0:-1] map_DF = pd.read_csv(map_file, delimiter="\t", index_col=0) var = zp.entry( title="CoMA", text= "Based on which metadata variable do you want to group your samples?\n\nYou can select between the following variables:\n\n" + ", ".join(map_DF.columns) + "\n") DF = pd.concat([otu_DF.T, map_DF], axis=1) DF = DF.reset_index().groupby(var) pairs = DF.index.value_counts().index.tolist() unique = list(set([a for (a, b) in pairs])) unique_dic = {} for item in unique: unique_dic[item] = [b for (a, b) in pairs if item in (a, b)] #Creation of new dataframe new_DF = pd.DataFrame()
#!/usr/bin/python3 import os from zenipy import entry ## Generates a LaTeX png, stores it in the user's clipboard ## read user input (argument) as a latex equation latex_equation = "$$" + entry(text='Input LaTeX:', placeholder='', title='ClipLaTeX', timeout=None) + "$$" ## skeleton for latex .tex file before_eq_string = r"\documentclass{article} \usepackage{amsmath} \usepackage{amssymb} \begin{document} \thispagestyle{empty} \setlength{\parindent}{0pt}" after_eq_string = r"\end{document}" ## set latex_filename parameter latex_filename = "tempfile" ## create the .tex file from the skeleton tex_file_contents = before_eq_string + latex_equation + after_eq_string tex_file = open(latex_filename + ".tex", "w") tex_file.write(tex_file_contents) tex_file.close() ## create the pdf (`pdflatex -jobname='filename to write' file.tex`) # to specify output name: -jobname=STRING flag before the FILE flag at the end os.system('pdflatex ' + latex_filename + '.tex > /dev/null 2>&1') ## crop the pdf to remove excess whitespace os.system('pdfcrop -margin 3 ' + latex_filename + '.pdf ' + latex_filename + '.pdf > /dev/null 2>&1') ## create the png from the pdf (`convert -density 3000 file.pdf -quality 90 file.png`)
# (c) Sebastian Hupfauf 20018 # # Script groups samples/replicates together and sort the newly defined groups # in alphabetical order. # # USAGE: python group.py otu_table_file import zenipy as pz import sys import os import statistics import time method = pz.entry(title="CoMA", text="Please choose the method for grouping:\n\nSum: sum of all reads\nMean: mean of all reads\nMedian: median of all reads\n") if method == None: print("\nGrouping process terminated!") print("\n________________________________________________________________________________\n") sys.exit(3) if method not in ["Sum", "Mean", "Median"]: pz.error(title="CoMA", text="Invalid Input, process terminated!") print("\nGrouping process terminated!") print("\n________________________________________________________________________________\n") sys.exit(3) input_file = "otu_table.txt" output_file = "otu_table_out.txt" with open(input_file) as inf: inf.readline() samples = [str(a.strip()) + "\n" for a in inf.readline().strip().split("\t")[1:-1]] num = [str(b) + "\t" for b in range(1, len(samples) + 1)]
#!/usr/bin/python3 # Author: Chris Moneyron, Purdue University, [email protected] # Professor: Nina Mahmoudian, Purdue University, [email protected] # # Plot position over time for all Crazyflies using xy_pos csv log import pandas as pd import zenipy import sys from matplotlib import pyplot as plt from tkinter.filedialog import Tk, askopenfilename # Ask user for work width and length measurements work_width = zenipy.entry(text="Enter workspace X length (meters):", placeholder="3.5", title="Crazyflie Mission Planning") work_length = zenipy.entry(text="Enter workspace Y length (meters):", placeholder="4", title="Crazyflie Mission Planning") work_width = float(work_width) work_length = float(work_length) # Ask user which scenario to plot (static, mobile preplan, mobile replan) mission_type = zenipy.zlist(title="Crazyflie Mission Planning", text="Select the mission type", columns=["Mission Type"], items=["Static", "MobilePreplan", "MobileReplan"]) mission_type = mission_type[0] if mission_type == "Static": log_location = '/home/naslab/crazyflie_ws/src/NASLab_Crazyflies/crazyflie_scripts/static_cf_actual_pos_logs/' elif mission_type == "MobilePreplan": log_location = '/home/naslab/crazyflie_ws/src/NASLab_Crazyflies/crazyflie_scripts/' \ 'mobile_preplan_cf_actual_pos_logs/'