Пример #1
0
def uploadecSeg():
    if request.method == "POST":
        if request.files:
            folder = request.files.getlist("input-folder-3[]")
            timestamped = datetime.now().strftime('%Y-%m-%d_%H%M%S')
            email = request.form.get("email")
            sendaddress = app.config["EMAIL_USERNAME"]
            sendpassword = app.config["EMAIL_PASSWORD"]
            directorypath = os.path.join(app.config["IMAGE_UPLOADS"],
                                         "ecSegOutput", timestamped)
            origpath = os.path.join(app.config["IMAGE_UPLOADS"], "ecSegOutput",
                                    timestamped, "orig")
            os.makedirs(origpath)
            os.mkdir(
                os.path.join(app.config["IMAGE_UPLOADS"], "ecSegOutput",
                             timestamped, "dapi"))
            os.mkdir(
                os.path.join(app.config["IMAGE_UPLOADS"], "ecSegOutput",
                             timestamped, "labels"))
            for file in folder:
                if file.filename == "":
                    try:
                        shutil.rmtree(directorypath)
                        flash(f'No folder was selected.', 'warning')
                    except OSError as e:
                        print("Error: %s : %s" % (directorypath, e.strerror))
                    return redirect('/input')
                if im.allowed_image(file.filename, False):
                    path = os.path.join(app.config["IMAGE_UPLOADS"],
                                        "ecSegOutput", timestamped,
                                        '/'.join(file.filename.split('/')[1:]))
                    file.save(path)
                    print(file.filename + " saved")
                else:
                    print(file.filename + " not allowed")
        im.tiffToPNG(timestamped)
        if im.correctOutputFolderStructure(
                directorypath):  # check if folder is correct here
            flash(
                f'Folder {timestamped} has been created and visualized. Save this name for future reference.',
                'success')
        else:
            try:
                shutil.rmtree(directorypath)
                flash(
                    f'Invalid folder. Folder name {timestamped} could not be created and visualized. Check for proper output folder format.',
                    'danger')
            except OSError as e:
                print("Error: %s : %s" % (directorypath, e.strerror))
            return redirect('/input')
        path = os.path.join(app.config["IMAGE_UPLOADS"], "ecSegOutput",
                            timestamped, "orig") + '/'
        session['folder'] = timestamped
        session['imagelist'] = im.imglist(path)
        session['imagename'] = session['imagelist'][0]
        return redirect('/visualize')
    else:
        return render_template(request.url)
Пример #2
0
def directVisualize():
    if request.method == "POST":
        folder = request.form['folder']
        print(folder)
        path = os.path.join(app.config["IMAGE_UPLOADS"], "ecSegOutput", folder,
                            "orig") + '/'
        if os.path.exists(path):
            flash(f'Folder {folder} was visualized.', 'success')
            session['folder'] = folder
            session['imagelist'] = im.imglist(path)
            session['imagename'] = session['imagelist'][0]
            return redirect('/visualize')
        else:
            flash(f'Invalid folder. Folder name {folder} not recognized.',
                  'danger')
    return redirect('/input')
Пример #3
0
def dmddirectVisualize():
    if request.method == "POST":
        folder = request.form['dmdfolder']
        print(folder)
        path = os.path.join(app.config["IMAGE_UPLOADS"],
                            "deepMetaDetectOutput", folder, "orig") + '/'
        if os.path.exists(path):
            flash(f'Folder {folder} was visualized.', 'success')
            session['dmdtimestamped'] = folder
            session['dmdimagelist'] = im.imglist(path)
            session['dmdimagename'] = session['dmdimagelist'][0]
            session['clusters'] = {
            }  #find clusters by reading through text file
            return redirect('/deepmetadetect')
        else:
            flash(f'Invalid folder. Folder name {folder} not recognized.',
                  'danger')
    return redirect('/dmdinput')
Пример #4
0
def uploadWholeSlide():
    if request.method == "POST":
        if request.files:
            folder = request.files.getlist("input-folder-4[]")
            timestamped = datetime.now().strftime('%Y-%m-%d_%H%M%S')
            directorypath = os.path.join(app.config["IMAGE_UPLOADS"],
                                         "deepMetaDetectOutput", timestamped)
            origpath = os.path.join(app.config["IMAGE_UPLOADS"],
                                    "deepMetaDetectOutput", timestamped,
                                    "orig")
            os.makedirs(origpath)
            os.mkdir(
                os.path.join(app.config["IMAGE_UPLOADS"],
                             "deepMetaDetectOutput", timestamped, "labels"))
            for file in folder:
                if file.filename == "":
                    try:
                        shutil.rmtree(directorypath)
                        flash(f'No folder was selected.', 'warning')
                    except OSError as e:
                        print("Error: %s : %s" % (directorypath, e.strerror))
                    return redirect('/dmdinput')
                if im.allowed_image(file.filename, False):
                    path = os.path.join(app.config["IMAGE_UPLOADS"],
                                        "deepMetaDetectOutput", timestamped,
                                        "orig",
                                        '/'.join(file.filename.split('/')[1:]))
                    file.save(path)
                    print(file.filename + " saved")
                else:
                    print(file.filename + " not allowed")
        # if im.correctInputFolderStructure(directorypath):  # check if folder is correct here
        #     flash(f'Folder {timestamped} has been created and visualized. Save this name for future reference.', 'success')
        # else:
        #     try:
        #         shutil.rmtree(directorypath)
        #         flash(f'Invalid folder. Folder name {timestamped} could not be created and visualized. Check for proper output folder format.', 'danger')
        #     except OSError as e:
        #         print("Error: %s : %s" % (directorypath, e.strerror))
        #     return redirect('/dmdinput')
        if request.form.get('checkbox') == "option1":
            im.dmdTiffToPNG(timestamped)
            session['dmdtimestamped'] = timestamped
            session['dmdimagelist'] = im.imglist(origpath)
            session['dmdimagename'] = session['dmdimagelist'][0]
            session['clusters'] = {}
            return redirect('/deepmetadetect')
        # RUN DEEPMETADETECT HERE
        # tools.runDeepMetaDetect(folderpath, 1)
        email = request.form.get("email")
        sendaddress = app.config["EMAIL_USERNAME"]
        sendpassword = app.config["EMAIL_PASSWORD"]
        print(email)
        if email:
            with smtplib.SMTP('smtp.gmail.com', 587) as smtp:
                smtp.ehlo()
                smtp.starttls()
                smtp.ehlo()
                smtp.login(sendaddress, sendpassword)
                subject = 'Your Visualization is Ready'
                body = f'Dear User: \n\ndeepMetaDetect was run successfully on your given input images and parameters. You have been redirected and are now able to visualize the output. \n\nDo not reply to this email. If you have a problem with the ecDNA Analytics webtool, create an issue on github (linked below). \nhttps://github.com/MihirBafna/ecDNA-Analytics/issues/new \n\n- ecDNA Analytics Support'
                msg = f'Subject: {subject}\n\n{body}'
                smtp.sendmail(sendaddress, email, msg)
        return redirect('/deepmetadetect')
    else:
        return redirect('/dmdinput')
Пример #5
0
def uploadInput():
    if request.method == "POST":
        if request.files:
            timestamped = datetime.now().strftime('%Y-%m-%d_%H%M%S')
            folder = request.files.getlist("input-folder-2[]")
            email = request.form.get("email")
            sendaddress = app.config["EMAIL_USERNAME"]
            sendpassword = app.config["EMAIL_PASSWORD"]
            if email:
                with smtplib.SMTP('smtp.gmail.com', 587) as smtp:
                    smtp.ehlo()
                    smtp.starttls()
                    smtp.ehlo()
                    smtp.login(sendaddress, sendpassword)
                    subject = 'ecSeg is Running'
                    body = f'Dear User: \n\necSeg is currently running on your input images and parameters. This may take some time to complete. Another email will be sent when finished and visualizations are ready. \n\nDo not reply to this email. If you have a problem with the ecDNA Analytics webtool, create an issue on github (linked below). \nhttps://github.com/MihirBafna/ecDNA-Analytics/issues/new \n\n- ecDNA Analytics Support'
                    msg = f'Subject: {subject}\n\n{body}'
                    smtp.sendmail(sendaddress, email, msg)
            print(email)
            folderpath = os.path.join(
                app.config["IMAGE_UPLOADS"], "ecSegOutput", timestamped)
            os.makedirs(folderpath)
            print(folderpath)
            for file in folder:
                print(file.filename)
                if file.filename == "":
                    try:
                        shutil.rmtree(folderpath)
                        flash(
                            f'No folder was selected.', 'warning')
                    except OSError as e:
                        print("Error: %s : %s" % (folderpath, e.strerror))
                    return redirect('/input')
                if im.allowed_image(file.filename, True):
                    path = os.path.join(
                        app.config["IMAGE_UPLOADS"], "ecSegOutput", timestamped, '/'.join(file.filename.split('/')[1:]))
                    file.save(path)
                    print("Image saved " + path)
                else:
                    print("not allowed")
        # check if folder is correct here
        if im.correctInputFolderStructure(folderpath):
            flash(f'ecSeg has been run succesfully. Folder {timestamped} has been created and visualized. Save this name for future reference.', 'success')
        else:
            try:
                shutil.rmtree(folderpath)
                flash(f'Invalid folder. Folder name {timestamped} could not be created and visualized. Check for proper input folder format.', 'danger')
            except OSError as e:
                print("Error: %s : %s" % (folderpath, e.strerror))
            return redirect('/input')
        # RUN ECSEG HERE
        tools.runecSeg(folderpath,1)
        im.reorganizeOutput(timestamped)
        path = os.path.join(app.config["IMAGE_UPLOADS"],
                            "ecSegOutput", timestamped, "orig")+'/'
        session['folder'] = timestamped
        im.tiffToPNG(timestamped)
        session['imagelist'] = im.imglist(path)
        session['imagename'] = session['imagelist'][0]
        if email:
            with smtplib.SMTP('smtp.gmail.com', 587) as smtp:
                smtp.ehlo()
                smtp.starttls()
                smtp.ehlo()
                smtp.login(sendaddress, sendpassword)
                subject = 'Your Visualization is Ready'
                body = f'Dear User: \n\necSeg was run successfully on your given input images and parameters. You have been redirected to the \'visualize\' page. Save the folder name {timestamped} for future reference and visualization. \n\nDo not reply to this email. If you have a problem with the ecDNA Analytics webtool, create an issue on github (linked below). \nhttps://github.com/MihirBafna/ecDNA-Analytics/issues/new \n\n- ecDNA Analytics Support'
                msg = f'Subject: {subject}\n\n{body}'
                smtp.sendmail(sendaddress, email, msg)
        return redirect('/visualize')
    else:
        return render_template('input.html')