Demo GUI #34 by 21ec845a004c1ca2b8fe4bb6170c7bf7?s=40&d=mm 0

Demo_GUI.py
Raw
#! /usr/bio_venv/venv_36/bin/python


'''Example of how to use the place() method to create a GUI layout'''
from tkinter import *
from tkinter import messagebox
from tkinter.filedialog import askdirectory, askopenfilename, askopenfilenames

from tkinter.ttk import Combobox, Style
import os

import subprocess

root  =  Tk()  # create root window
root.title("Basic GUI Layout with Place")
root.geometry("940x700")  # Set the starting size of the window
root.maxsize(940,  700)  # width x height
root.config(bg="skyblue")

# Create left and right frames
left_frame  =  Frame(root,  width=920,  height=675,  bg='grey')
left_frame.place(x=10,  y=10)

Style01 = Style()
Style01.configure("large.TLabel",font = ("Arial",20,"bold"),foreground = "black")
Style01.configure("TEntry",font = ("Arial",20,"bold"))
Style01.configure("TButton",font = ("Arial",20,"bold"),foreground = "royalblue")


# Create frames and labels in left_frame
# Label(left_frame,  text="Original Image", font=("Arial",20,"bold")).place(relx=0.5,  rely=0.05,  anchor=N)

# image  =  PhotoImage(file="/home/pi/Desktop/GUI/Image_created_with_a_mobile_phone.png")
# original_image  =  image.subsample(3,3)

# Label(left_frame,  image=original_image,  bg='grey').place(rely=0.15,  relwidth=1)
# Label(right_frame,  image=image,  bg='grey').place(y=5,  relwidth=1,  relheight=1)

input_bar_h= 50+10
h_off = 50
input_bar = Frame(left_frame,  width=400,  height=50,  )
input_bar.place(relx=0.5, y=50,anchor=CENTER)

output_bar = Frame(left_frame,  width=400,  height=50,  )
output_bar.place(relx=0.5, y=625,anchor=CENTER)

host_bar = Frame(left_frame,  width=400,  height=50,  )
host_bar.place(relx=0.5, y=125,anchor=CENTER)

aln_bar = Frame(left_frame,  width=400,  height=50,  )
aln_bar.place(relx=0.5, y=200,anchor=CENTER)
trim_bar = Frame(left_frame,  width=400,  height=50,  )
trim_bar.place(relx=0.5, y=275,anchor=CENTER)

COVID_bar  =  Frame(left_frame,  width=270,  height=225,  )
COVID_bar.place(x=25,  y=350)

cancer_bar  =  Frame(left_frame,  width=270,  height=225,)
cancer_bar.place(x=325,   y=350)

microbio_bar  =  Frame(left_frame,  width=270,  height=225,)
microbio_bar.place(x=625,   y=350)

def clicked():
    '''if button is clicked, display message'''
    print("Clicked.")
    if (configs["unifrac"].plateform.get()):
        if configs["aln"].plateform.get()==1:
            cmds = [
                    "./fpga_unifrac.py -r ./microbimoe_read_0.fastq -o ./microbimoe_read_0.sam -k 16 -tables /data/tianqi/Microbiome/ref107/FPGA_TABLE/",
                    "pigz -p 16 ./microbimoe_read_0.sam",
                    "mv ./microbimoe_read_0.sam.gz ./results/unifrac_pipe/sam/READ_0.sam.gz",
                    "/usr/bio_venv/venv_36/bin/woltka classify -f sam -i ./results/unifrac_pipe/sam/ -o ./results/unifrac_pipe/ogu.biom --uniq",
                    "/home/tianqi/miniconda3/envs/unifrac/bin/ssu -i ./results/unifrac_pipe/ogu.biom -t ./fasttree.nwk -o ./results/unifrac_pipe/unifrac.txt -m unweighted",
                    # "/usr/bio_venv/venv_36/bin/python3 ./showresult_unifrac.py -i ./results/unifrac_pipe/unifrac.txt"
                    ]
            for cmd in cmds:
                print(cmd.split(" "))
            print("CPU_Microbiome_pipeline...")
            for cmd in cmds:
                subprocess.run(cmd.split(" "))
        elif configs["aln"].plateform.get()==2:
            cmds = [
                    "./fpga_unifrac.py -r ./microbimoe_read_0.fastq -o ./microbimoe_read_0.sam -k 16 -tables /data/tianqi/Microbiome/ref107/FPGA_TABLE/",
                    "pigz -p 16 ./microbimoe_read_0.sam",
                    "mv ./microbimoe_read_0.sam.gz ./results/unifrac_pipe/sam/READ_0.sam.gz",
                    "/usr/bio_venv/venv_36/bin/woltka classify -f sam -i ./results/unifrac_pipe/sam/ -o ./results/unifrac_pipe/ogu.biom --uniq",
                    "/home/tianqi/miniconda3/envs/unifrac/bin/ssu -i ./results/unifrac_pipe/ogu.biom -t ./fasttree.nwk -o ./results/unifrac_pipe/unifrac.txt -m unweighted",
                    "/usr/bio_venv/venv_36/bin/python3 ./showresult_unifrac.py -i ./results/unifrac_pipe/unifrac.txt"
                    ]
            for cmd in cmds:
                print(cmd.split(" "))
            print("Acclerated_Microbiome_pipeline...")
            for cmd in cmds:
                subprocess.run(cmd.split(" "))
    elif (configs["dv"].plateform.get()):
        if configs["aln"].plateform.get()==1:
            print("CPU_DeepVariant_pipline...")
        elif configs["aln"].plateform.get()==2:
                cmds = [
                    "./fpga_dv.py -r ./cancer_variant_read.fastq -o ./results/dv_results/cancer_variant_read.sam -tables /home/tianqi/DeepVariant/quickstart-testdata/SIM/FPGA_table/",
                    "samtools view -@ 16 -b -S ./results/dv_results/cancer_variant_read.sam -o ./results/dv_results/cancer_variant_read.bam",
                    "samtools sort -@ 16 ./results/dv_results/cancer_variant_read.bam -o ./results/dv_results/cancer_variant_read.bam",
                    "samtools index -@ 16 ./results/dv_results/cancer_variant_read.bam",

                    "cp ./results/dv_results/cancer_variant_read.bam /home/tianqi/end2end/DeepVariant/SIM/align/",
                    "cp ./results/dv_results/cancer_variant_read.bam.bai /home/tianqi/end2end/DeepVariant/SIM/align/",
                    "sudo docker exec f111ac394c88 /opt/deepvariant/bin/run_deepvariant "+\
                        "--model_type=WGS --ref=/input/small/ucsc.hg19.chr20.unittest.fasta "+\
                        "--reads=/input/cancer_variant_read.bam "+\
                        "--output_vcf=/output/crisp_demo/output_cancer_variant_read.vcf.gz "+\
                        "--output_gvcf=/output/crisp_demo/output_cancer_variant_read.g.vcf.gz "+\
                        "--num_shards=15 "+\
                        "--logging_dir=/output/crisp_demo/logs_cancer_variant_read "+\
                        "--dry_run=false",
                    "cp -r /home/tianqi/end2end/DeepVariant/SIM/DV_output/crisp_demo/ ./results/dv_results",
                    "/usr/bio_venv/venv_36/bin/python3 ./showresult_dv.py -i ./results/dv_results/crisp_demo/output_cancer_variant_read.vcf.gz"
                    ]
                for cmd in cmds:
                    print(cmd.split(" "))
                print("Acclerated_DeepVariant_pipeline...")
                for cmd in cmds:
                    subprocess.run(cmd.split(" "))
    elif (configs["covid_pileup"].plateform.get()):
        if (not configs["tn93"].plateform.get()):
            if configs["aln"].plateform.get()==1:
                print("CPU_PerSample_COVID_pipline...")
            elif configs["aln"].plateform.get()==2:
                cmds = [
                    "./fpga_covid_aln.py -r ./covid_per_sample_read_0.fastq -o ./results/covid_per_sample_read_0.sam -tables /home/tianqi/Desktop/covid/new_index/",
                        "./fpga_ivar.py -r ./results/covid_per_sample_read_0.sam -o ./results/covid_per_sample_read_0.trimmed.sam",
                        "samtools sort -@ 16 -o ./results/covid_per_sample_read_0.trimmed.sorted.sam ./results/covid_per_sample_read_0.trimmed.sam",
                        "samtools mpileup -A -aa -d 0 -Q 0 --reference ./NC_045512.2.fas ./results/covid_per_sample_read_0.trimmed.sorted.sam|/home/tianqi/miniconda3/bin/ivar consensus -m 10 -t 0.5 -n N -p ./results/covid_per_sample_read_0.consensus.aln",
                        "./diff.sh ./results/covid_per_sample_read_0.consensus.aln.fa /mnt/sdb1/tianqi/COVID/BHGYJ7DSX2/minimap_pipe/SEARCH-41397__E0000088__B21__210730_A00953_0364_BHGYJ7DSX2__S1170_L002_R1_001.fastq.gz.trimmed.sorted.pileup.consensus.fa 100 50",
                        ]
                for cmd in cmds:
                    print(cmd.split(" "))
                print("Acclerated_PerSample_COVID_pipeline...")
                for cmd in cmds:
                    if "mpileup" in cmd:
                        print(cmd.split("|")[0])
                        print(cmd.split("|")[1])
                        p1 = subprocess.Popen(cmd.split("|")[0].split(" "), stdout=subprocess.PIPE)
                        subprocess.run(cmd.split("|")[1].split(" "), stdin=p1.stdout)
                        p1.wait()
                    else:
                        subprocess.run(cmd.split(" "))
                messagebox.showinfo("DON/E!", "Lineage:	B.1.561")
                return 0


    elif(configs["tn93"].plateform.get()):
        if configs["tn93"].plateform.get()==1:
            print("CPU_MultiSample_COVID_pipline...")
        elif configs["tn93"].plateform.get()==2:
            
            cmds = [
                    "./fpga_tn93.py -r ./tn93.aln -o ./results/tn93.dist",
                    "/usr/bio_venv/venv_36/bin/python3 ./showresult_tn93.py -i ./results/tn93.dist",
                    ]
            for cmd in cmds:
                print(cmd.split(" "))
            print("Acclerated_MultiSample_COVID_pipeline...")
            for cmd in cmds:
                subprocess.run(cmd.split(" "))
    print(configs["covid_pileup"].plateform.get())


    messagebox.showinfo("DON/E!", "DONE!")

input_path = StringVar()
input_path.set("./")
output_path = StringVar()
output_path.set("./")

class Config():
    def __init__(self) -> None:
        self.path = StringVar().set("./")
        self.plateform = IntVar()
        self.plateform.set(0)
        self.rbuttons = []
    def add_button(self,frame,fpga,gpu,offset, interval,y=25, interval_y=0, font=None):
        self.rbuttons = []
        self.rbuttons.append(Radiobutton(frame, text="None", variable=self.plateform, value=0,font=font))
        self.rbuttons[-1].place(in_=frame,y=y, x=offset, anchor=W)
        self.rbuttons[-1].select()
        self.rbuttons.append(Radiobutton(frame, text="CPU", variable=self.plateform, value=1, font=font))
        self.rbuttons[-1].place(in_=frame,y=y+interval_y, x=offset+interval, anchor=W)
        if fpga:
            self.rbuttons.append(Radiobutton(frame, text="FPGA", variable=self.plateform, value=2, font=font))
            self.rbuttons[-1].place(in_=frame,y=y+interval_y*2, x=offset+interval*2, anchor=W)
            # Radiobutton(frame, text="FPGA", variable=self.plateform, value=2).place(in_=frame,y=y, x=offset+interval*2, anchor=W)
            # self.rbuttons[-1].
        if gpu:
            self.rbuttons.append(Radiobutton(frame, text="GPU", variable=self.plateform, value=3, font=font))
            self.rbuttons[-1].place(in_=frame,y=y+interval_y*2, x=offset+interval*2, anchor=W)

def load_config(load):
    for c, p in zip(commands_set, load):
        configs[c].plateform.set(p)
    if load[-1]:
        cmb.current(1)
    else:
        cmb.current(0)

    # def change_plateform(self):
        

# self.Label_user = Label(self,textvariable=self.tee, style = "user.TLabel")
# self.Label_user.pack(side = LEFT,padx = 10,pady = 10)
configs = {}
rbuttons_values = {}
commands_set = ["host","aln","trim","covid_pileup","msa","tn93","dv","woltka","unifrac"]
for c in commands_set:
    configs[c] = (Config())
    # rbuttons_values[c] = IntVar()
    # rbuttons_values[c].set(0)

default_configs = [
    (0,1,1,1,1,1,0,0,0),
    (0,2,2,1,1,2,0,0,0),
    (0,1,0,0,0,0,1,0,0),
    (0,2,0,0,0,0,3,0,0),
    (1,1,0,0,0,0,0,1,1),
    (2,2,0,0,0,0,0,1,3),
]
        
Label(input_bar,text="Input:", font=("Arial",15,"bold")).place(in_=input_bar,rely=0.5, x=40, anchor=CENTER)
Label(input_bar,textvariabl=input_path, font=("Arial",13)).place(in_=input_bar,y=25, x=100, anchor=W)
Button(input_bar,  text="Select", command=lambda :input_path.set(os.path.relpath(askopenfilename(), os.getcwd()))).place(in_=input_bar, relx=1, rely=0.5, anchor=E)


Label(output_bar,text="Output:", font=("Arial",15,"bold")).place(in_=output_bar,rely=0.5, x=40, anchor=CENTER)
Label(output_bar,textvariabl=output_path, font=("Arial",13)).place(in_=output_bar,y=25, x=100, anchor=W)
Button(output_bar,  text="Select", command=lambda :output_path.set(os.path.relpath(askdirectory(), os.getcwd())+"/")).place(in_=output_bar, relx=1, rely=0.5, anchor=E)


Label(host_bar,text="Host\nFiltering:", font=("Arial",15,"bold")).place(in_=host_bar,rely=0.5, x=60, anchor=CENTER)
configs["host"].add_button(host_bar, 1,0,120,100,25)

Label(aln_bar,text="Alignment:", font=("Arial",15,"bold")).place(in_=aln_bar,rely=0.5, x=60, anchor=CENTER)
configs["aln"].add_button(aln_bar, 1,0,120,100,25)

Label(trim_bar,text="Primer\nTrimming:", font=("Arial",15,"bold")).place(in_=trim_bar,rely=0.5, x=60, anchor=CENTER)
configs["trim"].add_button(trim_bar, 1,0,120,100,25)


configs["covid_pileup"].add_button(COVID_bar, 0,0,70,65,30)
Label(COVID_bar,text="Pileup &\nConsensus:", font=("Arial",10,"bold")).place(in_=COVID_bar,y=30, x=40, anchor=CENTER)

Label(COVID_bar,text="MSA:", font=("Arial",12,"bold")).place(in_=COVID_bar,y=70, x=40, anchor=CENTER)
configs["msa"].add_button(COVID_bar, 0,0,70,65,70)

Label(COVID_bar,text="TN93:", font=("Arial",12,"bold")).place(in_=COVID_bar,y=115, x=40, anchor=CENTER)
configs["tn93"].add_button(COVID_bar, 1,0,65,65,115,0)


Label(cancer_bar,text="Deep\nVariant:", font=("Arial",12,"bold")).place(in_=cancer_bar,y=80, x=40, anchor=CENTER)
configs["dv"].add_button(cancer_bar, 0,1,70,65,80,0)


Label(microbio_bar,text="Woltka:", font=("Arial",12,"bold")).place(in_=microbio_bar,y=30, x=35, anchor=CENTER)
configs["woltka"].add_button(microbio_bar, 0,0,65,65,30)

Label(microbio_bar,text="Unifrac:", font=("Arial",12,"bold")).place(in_=microbio_bar,y=70, x=35, anchor=CENTER)
configs["unifrac"].add_button(microbio_bar, 0,1,65,65,70,0)

Label(microbio_bar,text="Database:", font=("Arial",12,"bold")).place(in_=microbio_bar,y=115, x=40, anchor=CENTER)
cmb = Combobox(microbio_bar, values=["None","WoL","Ref107"], state="readonly",width=10)
cmb.place(in_=microbio_bar,y=115, x=135, anchor=CENTER)
cmb.current(0)




pipeline_plateform = IntVar()
pipeline_plateform.set(0)
Radiobutton(COVID_bar, text="CPU", variable=pipeline_plateform, value=0,font=("Arial",15,"bold"),command=lambda:load_config(default_configs[0])).place(in_=COVID_bar,y=165, x=60, anchor=CENTER)
Radiobutton(COVID_bar, text="Acclerator", variable=pipeline_plateform, value=1,font=("Arial",15,"bold"),command=lambda:load_config(default_configs[1])).place(in_=COVID_bar,y=165, x=180, anchor=CENTER)
Radiobutton(cancer_bar, text="CPU", variable=pipeline_plateform, value=2,font=("Arial",15,"bold"),command=lambda:load_config(default_configs[2])).place(in_=cancer_bar,y=165, x=60, anchor=CENTER)
Radiobutton(cancer_bar, text="Acclerator", variable=pipeline_plateform, value=3,font=("Arial",15,"bold"),command=lambda:load_config(default_configs[3])).place(in_=cancer_bar,y=165, x=180, anchor=CENTER)
Radiobutton(microbio_bar, text="CPU", variable=pipeline_plateform, value=4,font=("Arial",15,"bold"),command=lambda:load_config(default_configs[4])).place(in_=microbio_bar,y=165, x=60, anchor=CENTER)
Radiobutton(microbio_bar, text="Acclerator", variable=pipeline_plateform, value=5,font=("Arial",15,"bold"),command=lambda:load_config(default_configs[5])).place(in_=microbio_bar,y=165, x=180, anchor=CENTER)

Label(COVID_bar,text="COVID", font=("Arial",18,"bold")).place(in_=COVID_bar,y=200, relx=0.5, anchor=CENTER)
Label(cancer_bar,text="CANCER", font=("Arial",18,"bold")).place(in_=cancer_bar,y=200, relx=0.5, anchor=CENTER)
Label(microbio_bar,text="MICROBIOME", font=("Arial",18,"bold")).place(in_=microbio_bar,y=200, relx=0.5, anchor=CENTER)


Button(left_frame,  text="Run", command=clicked, font=("Arial",20,"bold")).place(in_=left_frame,  relx=0.85,  rely=0.20,  anchor=CENTER)


# Button(host_bar,  text="Select", command=lambda :configs["host"].path.set(os.path.relpath(askdirectory(), os.getcwd())+"/")).place(in_=host_bar, relx=1, rely=0.5, anchor=E)


# print(os.path.relpath(input_path, os.getcwd()))
# Example labels that serve as placeholders for other widgets
# Label(COVID_bar,  text="COVIDs",  relief=RAISED).place(in_=COVID_bar, relx=0.5, anchor=N)
# Label(cancer_bar,  text="cancers",  relief=RAISED).place(in_=cancer_bar, relx=0.5, anchor=N)
# Label(microbio_bar,  text="microbio",  relief=RAISED).place(in_=microbio_bar, relx=0.5, anchor=N)

# For now, when the buttons are clicked, they only call the clicked() method. We will add functionality later.
# Button(COVID_bar,  text="Select", command=clicked).place(in_=COVID_bar,  relx=0.5,  rely=0.20,  anchor=CENTER)
# Button(COVID_bar,  text="Crop",  command=clicked).place(in_=COVID_bar,  relx=0.5,  rely=0.35,  anchor=CENTER)
# Button(COVID_bar,  text="Rotate &\n Flip",  command=clicked).place(in_=COVID_bar,  relx=0.5,  rely=0.50,  anchor=CENTER)
# Button(COVID_bar,  text="Resize",  command=clicked).place(in_=COVID_bar,  relx=0.5,  rely=0.65,  anchor=CENTER)
# Button(cancer_bar,  text="Black & White",  command=clicked).place(in_=cancer_bar,  relx=0.5,  rely=0.20,  anchor=CENTER)
root.mainloop()