Exemple #1
0
    def nonmaxima(self):
        nonmaxima_img = np.array(self.image_out_grad.copy())
        imagea = np.array(self.image_out_angle.copy())

        (h, w) = self.image_out_grad.shape

        for i in range(h):
            for j in range(w):
                if (i == 0 or i == h - 1 or j == 0 or j == w - 1):
                    nonmaxima_img[i][j] = 0
                    continue

                tq = (imagea[i][j]) % 4
                if (tq == 0):
                    if (self.image_out_grad[i, j] <= self.image_out_grad[i,
                                                                         j - 1]
                            or self.image_out_grad[i, j] <=
                            self.image_out_grad[i, j + 1]):
                        nonmaxima_img[i][j] = 0
                if (tq == 1):
                    if (self.image_out_grad[i, j] <= self.image_out_grad[i - 1,
                                                                         j + 1]
                            or self.image_out_grad[i, j] <=
                            self.image_out_grad[i + 1, j - 1]):
                        nonmaxima_img[i][j] = 0
                if (tq == 2):
                    if (self.image_out_grad[i, j] <= self.image_out_grad[i - 1,
                                                                         j]
                            or self.image_out_grad[i, j] <=
                            self.image_out_grad[i + 1, j]):
                        nonmaxima_img[i][j] = 0
                if (tq == 3):
                    if (self.image_out_grad[i, j] <= self.image_out_grad[i - 1,
                                                                         j - 1]
                            or self.image_out_grad[i, j] <=
                            self.image_out_grad[i + 1, j + 1]):
                        nonmaxima_img[i][j] = 0
            if self.completed < 40:
                self.completed += 0.1
                self.progress.setValue(self.completed)

        self.nonmaxima_img = nonmaxima_img
        self.progress.setValue(self.completed)
        tab_Var = mplt_plot(self.tab, nonmaxima_img)
        self.t_index = self.tabWidget.addTab(tab_Var, 'Non-Maximum Supressed')
        self.tabWidget.setCurrentIndex(self.t_index)
        QMessageBox.about(self, "Status!", "Non-max image Generated!")
        #        '''Input Window for Max and Min Threshold'''
        input_dialog = QtWidgets.QDialog()
        input_ui = Threshold.Ui_Dialog()
        input_ui.setupUi(input_dialog)
        input_dialog.show()

        if input_dialog.exec():
            thes_l, Thresh_h = input_ui.onOk()
            if thes_l and Thresh_h:
                thresh = thes_l, Thresh_h
                self.h_thres = np.max(thresh)  # Value
                self.l_thres = np.min(thresh)  # Value
                self.thres()
Exemple #2
0
def image_process(img, seq_n, NUM_SEGS, IMG_FRACTION):
    #cv2.imwrite(str(seq_n) + "_in.jpg", img)
    img = cv2.GaussianBlur(img, (13, 13), 0)
    imgThreshed = th.thresholding(img)
    imgMiddle, colOffset = get_middle(imgThreshed, IMG_FRACTION)
    midCentroids, leftCentroids, rightCentroids, frameAtIntersection = row_segment_centers(
        imgMiddle, NUM_SEGS, colOffset)

    # Draw all
    #for i in range(0,len(midCentroids)):
    #    cv2.circle(img, midCentroids[i], 5, (255,0,0))
    #if leftCentroids != None and rightCentroids != None:
    #    for i in range(0,len(leftCentroids)):
    #        cv2.circle(img, leftCentroids[i], 3, (0,255,0))
    #    for i in range(0,len(rightCentroids)):
    #        cv2.circle(img, rightCentroids[i], 7, (0,0,255))
    # cv2.imshow('imageThreshed',imgThreshed)
    # cv2.imshow('image', img)
    # cv2.imwrite(str(seq_n) + "_th.jpg", imgThreshed)
    # cv2.imwrite(str(seq_n) + "_out.jpg", img)
    return midCentroids, leftCentroids, rightCentroids, frameAtIntersection
def legacy():
    """
    This is the code that I had originall wrote to do this.
    This code was really messy, but worked, so I am leaving it here.
    It has been rewritten in the above functions, but could be useful to look
    at.
    """
    ## initialize the scope    
    scope=DGLab_Leica2.DGLab_Leica2()
    
    ## set up the 
    rows=string.ascii_uppercase[1:7]
    columns=range(2,12)
    sites=range(0,225)
    pos_string=open("PositionList_96well_15x15sites.pos").read()
    positions=StagePositions.positionList_parser(pos_string)
    scope.mmc.enableContinuousFocus(True)
    scope.set_illumination(Illuminations.Cy5)
    #start_time=time.asctime().replace(" ","_").replace(":","_")
    start_time="Thu_Aug_13_14_38_51_2015"
    done_list={}
    well_counter={}
    ## if this is a continuation of an old scan, this will add on to the 
    ## existing log file. 
    if os.path.exists("Scan_%s.txt" % start_time):
        completed_fin=open("Scan_%s.txt" % start_time,"r")
        for line in completed_fin:
            site=line.split(";")[0]
            try:
                if "No cells of interest" not in line.split(";")[1]:
                    well=site.split("-")
                    if well not in well_counter:
                        well_counter[well]=0
                    well_counter+=1
            except:
                pass
        completed_fin.close()
        status_out=open("Scan_%s.txt" % start_time,"r")
        status_string=status_out.read()
        status_out.close()
        status_out=open("Scan_%s.txt" % start_time,"w")
        status_out.write(status_string)
    else:
        status_out=open("Scan_%s.txt" % start_time,"w")    

    data_dir="Scan_%s" % start_time
    if os.path.isdir(data_dir) is False:
        os.mkdir(data_dir)
    order=-1
    for row in rows:
            ## flip the order that the columns are gone through
            order=order*-1
            for column in columns[::order]:
                well="%s%s" % (row,column)
                if well not in well_counter:well_counter[well]=0
                if well_counter[well]<15:
                ## reset the well count for this new well. 
                    well_count=well_counter[well]
                    ## iterate through the site in this well. 
                    for site in sites: ## Test case
                        if "%s%s-Site_%s" % (row,column,site) not in done_list.keys():
                            done_list["%s%s-Site_%s" % (row,column,site)]=True
                            print ">Looking at %s%s-Site_%s" % (row,column,site)
                            x,y=positions["%s%s-Site_%s" % (row,column,site)].get_xy()
                            ## take an image to use for a trigger
                            scope.set_illumination(Illuminations.qCy5)
                            scope.mmc.setXYPosition("XYStage",x,y)
                            scope.mmc.snapImage()
                            img=scope.mmc.getImage()
                            ## show image
                            plt.imshow(img)
                            plt.draw()
                            ## analyze this image
                            cois=Threshold.coi_finder(img,
                                                        threshold=1000,
                                                        min_area=100,
                                                        max_area=1000)
                            if cois:
                                do_stack=True
                                progress_line=">%s%s-Site_%s;cois=%s\n" % (row,column,site,cois)
                            else:
                                do_stack=False
                                progress_line=">%s%s-Site_%s;No cells of interest\n" % (row,column,site)
                            status_out.write(progress_line)
                            ## run the stack if there was a COI found
                            if do_stack:
                                print ">Stack at %s%s-Site_%s" % (row,column,site)
                                well_count+=1
                                well_counter[well]+=1
                                channels=[Illuminations.DIC,
                                            Illuminations.GFP,
                                            Illuminations.qCy5,
                                            Illuminations.DAPI]
                                scope.mmc.enableContinuousFocus(False)
                                mda,md=scope.multi_channel_acquisition(channels)
                                FileOut.mda_save(out_dir=data_dir,
                                                prefix="%s%s-Site_%s" % (row,column,site),
                                                mda=mda,
                                                md=md,
                                                channels=channels) 
                                print "Stack taken at %s%s-Site_%s" % (row,column,site)                   
                            ## turn AFC back on
                            scope.mmc.enableContinuousFocus(True)
                            ## move onto the next well if we have acquired enough
                            if well_count > 15:
                                break
                            ## break out of the well if you can't focus
                            if scope.mmc.isContinuousFocusLocked() is False:
                                time.sleep(5)
                                if scope.mmc.isContinuousFocusLocked() is False:
                                    print "Couldnt focus 3"
                                    break
                ## break out of the column if you still cant focus
                if scope.mmc.isContinuousFocusLocked() is False:
                    time.sleep(5)
                    if scope.mmc.isContinuousFocusLocked() is False:
                        print "Couldnt focus 2"
                        break
            ## break out of the row if you STILL cant focus. 
            if scope.mmc.isContinuousFocusLocked() is False:
                time.sleep(5)
                if scope.mmc.isContinuousFocusLocked() is False:
                    print "Couldnt focus 1"
                    break                     
    status_out.close()
def plateScanSite(scope,
                  illumination,
                  mda_channels,
                  x,
                  y,
                  visible=True,
                  name="",
                  stack_height=5,
                  slice_height=.5,
                  minAreaCOI=100,
                  maxAreaCOI=1000,
                  thresholdCOI=1000):
    """
    This is a function to run at each site of a 96well plate scan.
    
    This requires:
        -scope
        -scan illumination
        -MDA illuminations
        -x
        -y
        
    Optional:
        -visibility of scan image during acquisition
        -name this is mostly for progress and debugging purposes
    This returns:
        -site_imaged: 0 or 1 depending if a MDA was taken
        -MDA
        -MDA_md
    """
    scope.set_illumination(illumination)
    scope.mmc.setXYPosition("XYStage",x,y)
    scope.mmc.snapImage()
    img=scope.mmc.getImage()
    ## show image
    if visible is True:
        plt.imshow(img)
        plt.show()
        plt.draw()
   # analyze this image
    cois=Threshold.coi_finder(img,
                                threshold=thresholdCOI,
                                min_area=minAreaCOI,
                                max_area=maxAreaCOI)
    if cois:
        do_stack=True
        site_imaged=1
        print "COIs found in %s, taking a stack" % name
    else:
        do_stack=False
        site_imaged=0
        md=None
        mda=None
        print "No COIs found in %s" % name
    if do_stack:
        scope.mmc.enableContinuousFocus(False)
        mda,md=scope.multi_channel_acquisition(mda_channels,
                                                z_width=stack_height,
                                                z_increments=slice_height)
        scope.mmc.enableContinuousFocus(True)
    if visible is True: plt.close()
    del img
    return site_imaged, mda, md 
Exemple #5
0
def mm_XG_iRNA_M6A(sequence, species, modification, M_threshold):
    M_threshold = Threshold.choiceThreshold(species, modification, M_threshold)
    mm_importance_dict_sorted_list_num_M6A = [
        1834, 1500, 1549, 1367, 1310, 1459, 5, 1854, 1877, 58, 1843, 498, 42,
        71, 1389, 700, 1775, 213, 906, 942, 81, 16, 1429, 888, 1373, 1817,
        1501, 218, 124, 1380, 1436, 60, 12, 1536
    ]
    XG_iRNA_mm_M6A = load('model/mm/mm_xgb_M6A_10fold')
    # --------------------------------------------------------------
    line = sequence  # bug
    if re.search(r'[^AUCG]', line.strip()):
        nota = "Please input the RNA sequence 'AUCG'."
        return nota
    length = len(line.strip())
    if length < 41:
        nota = "Please input the RNA sequence at least 51 bases! "
        return nota
    mm_n_base_41_M6A = 19
    mm_n_base_list_M6A_proba = []
    mm_M6A_list_num = []
    for base in line.strip()[20:-20]:
        mm_n_base_41_M6A += 1
        file_inter_M6A = open('inter_use/mm_inter_use_M6A.txt', 'w')
        if base == 'A':
            new_line = line.strip()[mm_n_base_41_M6A - 20:mm_n_base_41_M6A +
                                    21]
            # ---f nc dnc tnc tenc pnc nd dnd ncp dpcp onehot dbe-----------------
            print(*iMRMFeatureEtraction.nc(new_line, 41),
                  *iMRMFeatureEtraction.dnc(new_line, 41),
                  *iMRMFeatureEtraction.tnc(new_line, 41),
                  *iMRMFeatureEtraction.tenc(new_line, 41),
                  *iMRMFeatureEtraction.pnc(new_line, 41),
                  *iMRMFeatureEtraction.nd(new_line, 41),
                  *iMRMFeatureEtraction.dnd(new_line, 41),
                  *iMRMFeatureEtraction.ncp(new_line, 41),
                  *iMRMFeatureEtraction.dpcp(new_line, 41),
                  *iMRMFeatureEtraction.onehot(new_line, 41),
                  *iMRMFeatureEtraction.dbe(new_line, 41),
                  file=file_inter_M6A)
            file_inter_M6A.close()
            pddtest = pd.read_csv("inter_use/mm_inter_use_M6A.txt",
                                  sep=' ',
                                  header=None)
            X_test = pddtest.values[:, [
                x - 1 for x in mm_importance_dict_sorted_list_num_M6A
            ]]
            prediction = XG_iRNA_mm_M6A.predict_proba(X_test)
            if prediction[0][1] > M_threshold:
                mm_n_base_list_M6A_proba.append(prediction[0][1])
                mm_M6A_list_num.append(mm_n_base_41_M6A + 1)
    if len(mm_M6A_list_num) > 0:
        mm_M6A_list_num.reverse()
        mm_n_base_list_M6A_proba.reverse()
        n = 0
        for i in [i - 1 for i in mm_M6A_list_num]:
            line = list(line)
            line[i] = '<font color=#00FF00>A</font>(' + str(
                mm_n_base_list_M6A_proba[n]) + ')'
            n += 1
    line = str(line).replace(',', '')
    line = line.replace('[', '')
    line = line.replace(']', '')
    line = line.replace(' ', '')
    line = line.replace('\'', '')
    line = line.replace('\\r', '')
    line_pro = line.replace('fontcolor', 'font color')
    line = line_pro
    pro_list = re.findall('\(.*?\)', line_pro)
    for i in pro_list:
        line = line.replace(i, '')
    return line, line_pro, mm_M6A_list_num
Exemple #6
0
def mm_XG_iRNA_M5C(sequence, species, modification, M_threshold):
    M_threshold = Threshold.choiceThreshold(species, modification, M_threshold)
    mm_importance_dict_sorted_list_num_M5C = [
        16, 48, 1458, 1197, 299, 859, 1359, 1879, 383, 65, 381, 82, 1519
    ]
    XG_iRNA_mm_M5C = load('model/mm/mm_xgb_M5C_10fold')
    # --------------------------------------------------------------
    line = sequence  # bug
    if re.search(r'[^AUCG]', line.strip()):
        nota = "Please input the RNA sequence 'AUCG'."
        return nota
    length = len(line.strip())
    if length < 41:
        nota = "Please input the RNA sequence at least 51 bases! "
        return nota
    mm_n_base_41_M5C = 19
    mm_n_base_list_M5C_proba = []
    mm_M5C_list_num = []
    for base in line.strip()[20:-20]:
        mm_n_base_41_M5C += 1
        file_inter_M5C = open('inter_use/mm_inter_use_M5C.txt', 'w')
        if base == 'C':
            new_line = line.strip()[mm_n_base_41_M5C - 20:mm_n_base_41_M5C +
                                    21]
            # ---f nc dnc tnc tenc pnc nd dnd ncp dpcp onehot dbe-----------------
            print(*iMRMFeatureEtraction.nc(new_line, 41),
                  *iMRMFeatureEtraction.dnc(new_line, 41),
                  *iMRMFeatureEtraction.tnc(new_line, 41),
                  *iMRMFeatureEtraction.tenc(new_line, 41),
                  *iMRMFeatureEtraction.pnc(new_line, 41),
                  *iMRMFeatureEtraction.nd(new_line, 41),
                  *iMRMFeatureEtraction.dnd(new_line, 41),
                  *iMRMFeatureEtraction.ncp(new_line, 41),
                  *iMRMFeatureEtraction.dpcp(new_line, 41),
                  *iMRMFeatureEtraction.onehot(new_line, 41),
                  *iMRMFeatureEtraction.dbe(new_line, 41),
                  file=file_inter_M5C)
            file_inter_M5C.close()
            pddtest = pd.read_csv("inter_use/mm_inter_use_M5C.txt",
                                  sep=' ',
                                  header=None)
            X_test = pddtest.values[:, [
                x - 1 for x in mm_importance_dict_sorted_list_num_M5C
            ]]
            prediction = XG_iRNA_mm_M5C.predict_proba(X_test)
            if prediction[0][1] > M_threshold:
                mm_n_base_list_M5C_proba.append(prediction[0][1])
                mm_M5C_list_num.append(mm_n_base_41_M5C + 1)
    if len(mm_M5C_list_num) > 0:
        mm_M5C_list_num.reverse()
        mm_n_base_list_M5C_proba.reverse()
        n = 0
        for i in [i - 1 for i in mm_M5C_list_num]:
            line = list(line)
            line[i] = '<font color=#FFA500>C</font>(' + str(
                mm_n_base_list_M5C_proba[n]) + ')'
            n += 1
    line = str(line).replace(',', '')
    line = line.replace('[', '')
    line = line.replace(']', '')
    line = line.replace(' ', '')
    line = line.replace('\'', '')
    line = line.replace('\\r', '')
    line_pro = line.replace('fontcolor', 'font color')
    line = line_pro
    pro_list = re.findall('\(.*?\)', line_pro)
    for i in pro_list:
        line = line.replace(i, '')
    return line, line_pro, mm_M5C_list_num
Exemple #7
0
def human_XG_iRNA_pse(sequence, species, modification, M_threshold):
    # -------------------------------------------------------------
    hg_importance_dict_sorted_list_num_Pse = [
        16, 22, 1441, 1389, 1692, 300, 661, 406, 1666, 1660, 1432, 1698, 1695,
        338, 738, 10, 1680, 808, 1414, 204, 77, 940, 69, 1408, 74, 980, 31,
        234, 8, 292, 178, 1382, 1458, 1, 1689, 13, 1373, 39, 237, 1369, 1444,
        245, 66, 54, 1434, 1417, 1396
    ]
    XG_iRNA_hg_Pse = load('model/hg/hg_xgb_Pse_10fold')
    # --------------------------------------------------------------
    line = sequence
    hg_n_base_21 = 9
    hg_n_base_list_pse_proba = []
    hg_pse_list_num = []
    M_threshold = Threshold.choiceThreshold(species, modification, M_threshold)
    # -----------------------------PSE ---------------------------------------------------
    for base in line.strip()[10:-10]:
        hg_n_base_21 += 1
        file_inter_pse = open('inter_use/hg_inter_use_pse.txt', 'w')
        if base == 'U':
            new_line = line.strip()[hg_n_base_21 - 10:hg_n_base_21 + 11]
            # ---f nc dnc tnc tenc pnc nd dnd ncp dpcp onehot dbe-----------------
            print(*iMRMFeatureEtraction.nc(new_line, 21),
                  *iMRMFeatureEtraction.dnc(new_line, 21),
                  *iMRMFeatureEtraction.tnc(new_line, 21),
                  *iMRMFeatureEtraction.tenc(new_line, 21),
                  *iMRMFeatureEtraction.pnc(new_line, 21),
                  *iMRMFeatureEtraction.nd(new_line, 21),
                  *iMRMFeatureEtraction.dnd(new_line, 21),
                  *iMRMFeatureEtraction.ncp(new_line, 21),
                  *iMRMFeatureEtraction.dpcp(new_line, 21),
                  *iMRMFeatureEtraction.onehot(new_line, 21),
                  *iMRMFeatureEtraction.dbe(new_line, 21),
                  file=file_inter_pse)
            file_inter_pse.close()
            pddtest = pd.read_csv("inter_use/hg_inter_use_pse.txt",
                                  sep=' ',
                                  header=None)
            X_test = pddtest.values[:, [
                x - 1 for x in hg_importance_dict_sorted_list_num_Pse
            ]]
            prediction = XG_iRNA_hg_Pse.predict_proba(X_test)
            if prediction[0][1] > M_threshold:
                hg_n_base_list_pse_proba.append(prediction[0][1])
                hg_pse_list_num.append(hg_n_base_21 + 1)
    if len(hg_pse_list_num) > 0:
        hg_pse_list_num.reverse()
        hg_n_base_list_pse_proba.reverse()
        n = 0
        for i in [i - 1 for i in hg_pse_list_num]:
            line = list(line)
            line[i] = '<font color=#FF3333>U</font>(' + str(
                hg_n_base_list_pse_proba[n]) + ')'
            n += 1
    line = str(line).replace(',', '')
    line = line.replace('[', '')
    line = line.replace(']', '')
    line = line.replace(' ', '')
    line = line.replace('\'', '')
    line = line.replace('\\r', '')
    line_pro = line.replace('fontcolor', 'font color')
    line = line_pro
    pro_list = re.findall('\(.*?\)', line_pro)
    for i in pro_list:
        line = line.replace(i, '')
    return line, line_pro, hg_pse_list_num
Exemple #8
0
from imutils.video import FileVideoStream
from imutils.video import FPS
from skimage.measure import compare_ssim
import numpy as np
import argparse
import imutils
import time
import cv2
import os
import datetime
from pydarknet import Detector, Image
import Threshold

videoFile="HighlineGate.mp4"
yolodir="yolo"
threshold =  Threshold.Threshold(videoFile).get()

# parse the arguments
ap = argparse.ArgumentParser()

ap.add_argument("-y", "--yolo", default=yolodir,
	help="base path to YOLO directory")
ap.add_argument("-c", "--confidence", type=float, default=0.5,
	help="minimum probability to filter weak detections")
ap.add_argument("-s", "--sample", default=videoFile,
	help="minimum probability to filter weak detections")
ap.add_argument("-st", "--thresh", default=threshold,
	help="minimum probability to filter weak detections")
args = vars(ap.parse_args())

Exemple #9
0
def sc_XG_iRNA_M5C(sequence, species, modification, M_threshold):
    M_threshold = Threshold.choiceThreshold(species, modification, M_threshold)
    importance_dict_sorted_list_num_M5C = [
        299, 1009, 705, 1542, 1522, 1008, 1764, 4, 1862, 1200, 142, 1385, 1358,
        1214, 1842, 27, 693, 1086, 193, 1527, 1904, 1533, 1554, 920, 323, 1879,
        16
    ]
    XG_iRNA_sc_M5C = load('model/sc/sc_xgb_M5C_10fold')
    # --------------------------------------------------------------
    line = sequence  # bug
    if re.search(r'[^AUCG]', line.strip()):
        nota = "Please input the RNA sequence 'AUCG'."
        return nota
    length = len(line.strip())
    if length < 41:
        nota = "Please input the RNA sequence at least 51 bases! "
        return nota
    sc_n_base_41_M5C = 19
    sc_n_base_list_M5C_proba = []
    sc_M5C_list_num = []
    for base in line.strip()[20:-20]:
        sc_n_base_41_M5C += 1
        file_inter_M5C = open('inter_use/sc_inter_use_M5C.txt', 'w')
        if base == 'C':
            new_line = line.strip()[sc_n_base_41_M5C - 20:sc_n_base_41_M5C +
                                    21]
            # ---f nc dnc tnc tenc pnc nd dnd ncp dpcp onehot dbe-----------------
            print(*iMRMFeatureEtraction.nc(new_line, 41),
                  *iMRMFeatureEtraction.dnc(new_line, 41),
                  *iMRMFeatureEtraction.tnc(new_line, 41),
                  *iMRMFeatureEtraction.tenc(new_line, 41),
                  *iMRMFeatureEtraction.pnc(new_line, 41),
                  *iMRMFeatureEtraction.nd(new_line, 41),
                  *iMRMFeatureEtraction.dnd(new_line, 41),
                  *iMRMFeatureEtraction.ncp(new_line, 41),
                  *iMRMFeatureEtraction.dpcp(new_line, 41),
                  *iMRMFeatureEtraction.onehot(new_line, 41),
                  *iMRMFeatureEtraction.dbe(new_line, 41),
                  file=file_inter_M5C)
            file_inter_M5C.close()
            pddtest = pd.read_csv("inter_use/sc_inter_use_M5C.txt",
                                  sep=' ',
                                  header=None)
            X_test = pddtest.values[:, [
                x - 1 for x in importance_dict_sorted_list_num_M5C
            ]]
            prediction = XG_iRNA_sc_M5C.predict_proba(X_test)
            if prediction[0][1] > M_threshold:
                sc_n_base_list_M5C_proba.append(prediction[0][1])
                sc_M5C_list_num.append(sc_n_base_41_M5C + 1)
    if len(sc_M5C_list_num) > 0:
        sc_M5C_list_num.reverse()
        sc_n_base_list_M5C_proba.reverse()
        n = 0
        for i in [i - 1 for i in sc_M5C_list_num]:
            line = list(line)
            line[i] = '<font color=#FFA500>C</font>(' + str(
                sc_n_base_list_M5C_proba[n]) + ')'
            n += 1
    line = str(line).replace(',', '')
    line = line.replace('[', '')
    line = line.replace(']', '')
    line = line.replace(' ', '')
    line = line.replace('\'', '')
    line = line.replace('\\r', '')
    line_pro = line.replace('fontcolor', 'font color')
    line = line_pro
    pro_list = re.findall('\(.*?\)', line_pro)
    for i in pro_list:
        line = line.replace(i, '')
    return line, line_pro, sc_M5C_list_num
Exemple #10
0
def sc_XG_iRNA_M6A(sequence, species, modification, M_threshold):
    M_threshold = Threshold.choiceThreshold(species, modification, M_threshold)
    importance_dict_sorted_list_num_M6A = [
        1912, 1879, 1905, 1310, 327, 11, 1, 1536, 1309, 53, 18, 1311, 762, 280,
        474, 4, 34, 71, 1908, 1555, 1549, 1142, 728, 186, 29, 7, 1554, 43, 46,
        1117, 75, 1943, 100, 1559, 872, 126, 135, 650, 58, 1411, 981, 542,
        1577, 119, 568, 216, 1441, 552
    ]
    XG_iRNA_sc_M6A = load('model/sc/sc_xgb_M6A_10fold')
    # -------------------------------------------------------------
    line = sequence
    if re.search(r'[^AUCG]', line.strip()):
        nota = "Please input the RNA sequence 'AUCG'."
        return nota
    length = len(line.strip())
    if length < 41:
        nota = "Please input the RNA sequence at least 51 bases! "
        return nota
    sc_n_base_41_M6A = 19
    sc_n_base_list_M6A_proba = []
    sc_M6A_list_num = []
    for base in line.strip()[20:-20]:
        sc_n_base_41_M6A += 1
        file_inter_M6A = open('inter_use/sc_inter_use_M6A.txt', 'w')
        if base == 'A':
            new_line = line.strip()[sc_n_base_41_M6A - 20:sc_n_base_41_M6A +
                                    21]
            # ---f nc dnc tnc tenc pnc nd dnd ncp dpcp onehot dbe-----------------
            print(*iMRMFeatureEtraction.nc(new_line, 41),
                  *iMRMFeatureEtraction.dnc(new_line, 41),
                  *iMRMFeatureEtraction.tnc(new_line, 41),
                  *iMRMFeatureEtraction.tenc(new_line, 41),
                  *iMRMFeatureEtraction.pnc(new_line, 41),
                  *iMRMFeatureEtraction.nd(new_line, 41),
                  *iMRMFeatureEtraction.dnd(new_line, 41),
                  *iMRMFeatureEtraction.ncp(new_line, 41),
                  *iMRMFeatureEtraction.dpcp(new_line, 41),
                  *iMRMFeatureEtraction.onehot(new_line, 41),
                  *iMRMFeatureEtraction.dbe(new_line, 41),
                  file=file_inter_M6A)
            file_inter_M6A.close()
            pddtest = pd.read_csv("inter_use/sc_inter_use_M6A.txt",
                                  sep=' ',
                                  header=None)
            X_test = pddtest.values[:, [
                x - 1 for x in importance_dict_sorted_list_num_M6A
            ]]
            prediction = XG_iRNA_sc_M6A.predict_proba(X_test)
            if prediction[0][1] > M_threshold:
                sc_n_base_list_M6A_proba.append(prediction[0][1])
                sc_M6A_list_num.append(sc_n_base_41_M6A + 1)
    if len(sc_M6A_list_num) > 0:
        sc_M6A_list_num.reverse()
        sc_n_base_list_M6A_proba.reverse()
        n = 0
        for i in [i - 1 for i in sc_M6A_list_num]:
            line = list(line)
            line[i] = '<font color=#00FF00>A</font>(' + str(
                sc_n_base_list_M6A_proba[n]) + ')'
            n += 1
    line = str(line).replace(',', '')
    line = line.replace('[', '')
    line = line.replace(']', '')
    line = line.replace(' ', '')
    line = line.replace('\'', '')
    line = line.replace('\\r', '')
    line_pro = line.replace('fontcolor', 'font color')
    line = line_pro
    pro_list = re.findall('\(.*?\)', line_pro)
    for i in pro_list:
        line = line.replace(i, '')
    return line, line_pro, sc_M6A_list_num
Exemple #11
0
def sc_XG_iRNA_M1A(sequence, species, modification, M_threshold):
    # -------------------------------------------------------------
    M_threshold = Threshold.choiceThreshold(species, modification, M_threshold)
    importance_dict_sorted_list_num_M1A = [1824, 1831, 1500]
    XG_iRNA_sc_M1A = load('model/sc/sc_xgb_M1A_10fold')
    # --------------------------------------------------------------
    line = sequence
    # bug
    if re.search(r'[^AUCG]', line.strip()):
        nota = "Please input the RNA sequence 'AUCG'."
        return nota
    length = len(line.strip())
    if length < 41:
        nota = "Please input the RNA sequence at least 51 bases! "
        return nota
    sc_n_base_41_M1A = 19
    sc_n_base_list_M1A_proba = []
    sc_M1A_list_num = []
    for base in line.strip()[20:-20]:
        sc_n_base_41_M1A += 1
        file_inter_M1A = open('inter_use/sc_inter_use_M1A.txt', 'w')
        if base == 'A':
            new_line = line.strip()[sc_n_base_41_M1A - 20:sc_n_base_41_M1A +
                                    21]
            # ---f nc dnc tnc tenc pnc nd dnd ncp dpcp onehot dbe-----------------
            print(*iMRMFeatureEtraction.nc(new_line, 41),
                  *iMRMFeatureEtraction.dnc(new_line, 41),
                  *iMRMFeatureEtraction.tnc(new_line, 41),
                  *iMRMFeatureEtraction.tenc(new_line, 41),
                  *iMRMFeatureEtraction.pnc(new_line, 41),
                  *iMRMFeatureEtraction.nd(new_line, 41),
                  *iMRMFeatureEtraction.dnd(new_line, 41),
                  *iMRMFeatureEtraction.ncp(new_line, 41),
                  *iMRMFeatureEtraction.dpcp(new_line, 41),
                  *iMRMFeatureEtraction.onehot(new_line, 41),
                  *iMRMFeatureEtraction.dbe(new_line, 41),
                  file=file_inter_M1A)
            file_inter_M1A.close()
            pddtest = pd.read_csv("inter_use/sc_inter_use_M1A.txt",
                                  sep=' ',
                                  header=None)
            X_test = pddtest.values[:, [
                x - 1 for x in importance_dict_sorted_list_num_M1A
            ]]
            prediction = XG_iRNA_sc_M1A.predict_proba(X_test)
            if prediction[0][1] > M_threshold:
                sc_n_base_list_M1A_proba.append(prediction[0][1])
                sc_M1A_list_num.append(sc_n_base_41_M1A + 1)
    if len(sc_M1A_list_num) > 0:
        sc_M1A_list_num.reverse()
        sc_n_base_list_M1A_proba.reverse()
        n = 0
        for i in [i - 1 for i in sc_M1A_list_num]:
            line = list(line)
            line[i] = '<font color=#1E90FF>A</font>(' + str(
                sc_n_base_list_M1A_proba[n]) + ')'
            n += 1
    line = str(line).replace(',', '')
    line = line.replace('[', '')
    line = line.replace(']', '')
    line = line.replace(' ', '')
    line = line.replace('\'', '')
    line = line.replace('\\r', '')
    line_pro = line.replace('fontcolor', 'font color')
    line = line_pro
    pro_list = re.findall('\(.*?\)', line_pro)
    for i in pro_list:
        line = line.replace(i, '')
    return line, line_pro, sc_M1A_list_num
Exemple #12
0
def sc_XG_iRNA_pse(sequence, species, modification, M_threshold):
    M_threshold = Threshold.choiceThreshold(species, modification, M_threshold)
    # -------------------------------------------------------------
    sc_importance_dict_sorted_list_num_Pse = [
        1477, 201, 1748, 1759, 1380, 1784, 10, 1121, 693, 1492, 135, 1377,
        1792, 808, 1383, 251, 1800, 1766, 1746, 1, 302, 146, 78, 1488, 34, 242,
        76, 230, 12, 1747, 13, 6, 269, 1753, 714, 38, 182, 77, 324, 97, 165,
        1788, 664, 82, 893, 194
    ]
    XG_iRNA_sc_Pse = load('model/sc/sc_xgb_Pse_10fold')
    # --------------------------------------------------------------
    line = sequence
    line = line.upper()  # bug
    if re.search(r'[^AUCG]', line.strip()):
        nota = "Please input the RNA sequence 'AUCG'."
        return nota
    length = len(line.strip())
    if length < 31:
        nota = "Please input the RNA sequence at least 51 bases! "
        return nota
    sc_n_base_31 = 14
    sc_n_base_list_pse_proba = []
    sc_pse_list_num = []
    # -----------------------------PSE ---------------------------------------------------
    for base in line.strip()[15:-15]:
        sc_n_base_31 += 1
        file_inter_pse = open('inter_use/sc_inter_use_pse.txt', 'w')
        if base == 'U':
            new_line = line.strip()[sc_n_base_31 - 15:sc_n_base_31 + 16]
            # ---f nc dnc tnc tenc pnc nd dnd ncp dpcp onehot dbe-----------------
            print(*iMRMFeatureEtraction.nc(new_line, 31),
                  *iMRMFeatureEtraction.dnc(new_line, 31),
                  *iMRMFeatureEtraction.tnc(new_line, 31),
                  *iMRMFeatureEtraction.tenc(new_line, 31),
                  *iMRMFeatureEtraction.pnc(new_line, 31),
                  *iMRMFeatureEtraction.nd(new_line, 31),
                  *iMRMFeatureEtraction.dnd(new_line, 31),
                  *iMRMFeatureEtraction.ncp(new_line, 31),
                  *iMRMFeatureEtraction.dpcp(new_line, 31),
                  *iMRMFeatureEtraction.onehot(new_line, 31),
                  *iMRMFeatureEtraction.dbe(new_line, 31),
                  file=file_inter_pse)
            file_inter_pse.close()
            pddtest = pd.read_csv("inter_use/sc_inter_use_pse.txt",
                                  sep=' ',
                                  header=None)
            X_test = pddtest.values[:, [
                x - 1 for x in sc_importance_dict_sorted_list_num_Pse
            ]]
            prediction = XG_iRNA_sc_Pse.predict_proba(X_test)
            if prediction[0][1] > M_threshold:
                sc_n_base_list_pse_proba.append(prediction[0][1])
                sc_pse_list_num.append(sc_n_base_31 + 1)
    if len(sc_pse_list_num) > 0:
        sc_pse_list_num.reverse()
        sc_n_base_list_pse_proba.reverse()
        n = 0
        for i in [i - 1 for i in sc_pse_list_num]:
            line = list(line)
            line[i] = '<font color=#FF3333>U</font>(' + str(
                sc_n_base_list_pse_proba[n]) + ')'
            n += 1
    line = str(line).replace(',', '')
    line = line.replace('[', '')
    line = line.replace(']', '')
    line = line.replace(' ', '')
    line = line.replace('\'', '')
    line = line.replace('\\r', '')
    line_pro = line.replace('fontcolor', 'font color')
    line = line_pro
    pro_list = re.findall('\(.*?\)', line_pro)
    for i in pro_list:
        line = line.replace(i, '')
    return line, line_pro, sc_pse_list_num
Exemple #13
0
def human_XG_iRNA_M5C(sequence, species, modification, M_threshold):
    importance_dict_sorted_list_num_M5C = [
        16, 144, 1442, 82, 18, 1225, 210, 1401, 1430, 80, 57, 68, 1562, 74, 950
    ]
    XG_iRNA_hg_M5C = load('model/hg/hg_xgb_M5C_10fold')
    M_threshold = Threshold.choiceThreshold(species, modification, M_threshold)
    # --------------------------------------------------------------
    line = sequence
    line = line.upper()  # bug
    if re.search(r'[^AUCG]', line.strip()):
        nota = "Please input the RNA sequence 'AUCG'."
        return nota
    length = len(line.strip())
    if length < 41:
        nota = "Please input the RNA sequence at least 51 bases! "
        return nota
    hg_n_base_41_M5C = 19
    hg_n_base_list_M5C_proba = []
    hg_M5C_list_num = []
    for base in line.strip()[20:-20]:
        hg_n_base_41_M5C += 1
        file_inter_M5C = open('inter_use/hg_inter_use_M5C.txt', 'w')
        if base == 'C':
            new_line = line.strip()[hg_n_base_41_M5C - 20:hg_n_base_41_M5C +
                                    21]
            # ---f nc dnc tnc tenc pnc nd dnd ncp dpcp onehot dbe-----------------
            print(*iMRMFeatureEtraction.nc(new_line, 41),
                  *iMRMFeatureEtraction.dnc(new_line, 41),
                  *iMRMFeatureEtraction.tnc(new_line, 41),
                  *iMRMFeatureEtraction.tenc(new_line, 41),
                  *iMRMFeatureEtraction.pnc(new_line, 41),
                  *iMRMFeatureEtraction.nd(new_line, 41),
                  *iMRMFeatureEtraction.dnd(new_line, 41),
                  *iMRMFeatureEtraction.ncp(new_line, 41),
                  *iMRMFeatureEtraction.dpcp(new_line, 41),
                  *iMRMFeatureEtraction.onehot(new_line, 41),
                  *iMRMFeatureEtraction.dbe(new_line, 41),
                  file=file_inter_M5C)
            file_inter_M5C.close()
            pddtest = pd.read_csv("inter_use/hg_inter_use_M5C.txt",
                                  sep=' ',
                                  header=None)
            X_test = pddtest.values[:, [
                x - 1 for x in importance_dict_sorted_list_num_M5C
            ]]
            prediction = XG_iRNA_hg_M5C.predict_proba(X_test)
            if prediction[0][1] > M_threshold:
                hg_n_base_list_M5C_proba.append(prediction[0][1])
                hg_M5C_list_num.append(hg_n_base_41_M5C + 1)
    if len(hg_M5C_list_num) > 0:
        hg_M5C_list_num.reverse()
        hg_n_base_list_M5C_proba.reverse()
        n = 0
        for i in [i - 1 for i in hg_M5C_list_num]:
            line = list(line)
            line[i] = '<font color=#FFA500>C</font>(' + str(
                hg_n_base_list_M5C_proba[n]) + ')'
            n += 1
    line = str(line).replace(',', '')
    line = line.replace('[', '')
    line = line.replace(']', '')
    line = line.replace(' ', '')
    line = line.replace('\'', '')
    line = line.replace('\\r', '')
    line_pro = line.replace('fontcolor', 'font color')
    line = line_pro
    pro_list = re.findall('\(.*?\)', line_pro)
    for i in pro_list:
        line = line.replace(i, '')
    return line, line_pro, hg_M5C_list_num
Exemple #14
0
def human_XG_iRNA_M6A(sequence, species, modification, M_threshold):
    importance_dict_sorted_list_num_M6A = [
        1834, 1500, 1831, 1503, 16, 1446, 1489, 1882, 30, 113, 997, 1545, 1857,
        1892, 87, 4, 147, 1866, 209, 369, 1395, 1366, 1520, 1401, 1422, 1397,
        1398, 279, 1454, 40, 243, 1417, 1498, 42, 81, 377, 1441, 51, 12, 1557,
        17, 404, 96, 724
    ]
    XG_iRNA_hg_M6A = load('model/hg/hg_xgb_M6A_10fold')

    M_threshold = Threshold.choiceThreshold(species, modification, M_threshold)
    # -------------------------------------------------------------
    line = sequence
    line = line.upper()  # bug
    if re.search(r'[^AUCG]', line.strip()):
        nota = "Please input the RNA sequence 'AUCG'."
        return nota
    length = len(line.strip())
    if length < 41:
        nota = "Please input the RNA sequence at least 51 bases! "
        return nota
    hg_n_base_41_M6A = 19
    hg_n_base_list_M6A_proba = []
    hg_M6A_list_num = []
    for base in line.strip()[20:-20]:
        hg_n_base_41_M6A += 1
        file_inter_M6A = open('inter_use/hg_inter_use_M6A.txt', 'w')
        if base == 'A':
            new_line = line.strip()[hg_n_base_41_M6A - 20:hg_n_base_41_M6A +
                                    21]
            # ---f nc dnc tnc tenc pnc nd dnd ncp dpcp onehot dbe-----------------
            print(*iMRMFeatureEtraction.nc(new_line, 41),
                  *iMRMFeatureEtraction.dnc(new_line, 41),
                  *iMRMFeatureEtraction.tnc(new_line, 41),
                  *iMRMFeatureEtraction.tenc(new_line, 41),
                  *iMRMFeatureEtraction.pnc(new_line, 41),
                  *iMRMFeatureEtraction.nd(new_line, 41),
                  *iMRMFeatureEtraction.dnd(new_line, 41),
                  *iMRMFeatureEtraction.ncp(new_line, 41),
                  *iMRMFeatureEtraction.dpcp(new_line, 41),
                  *iMRMFeatureEtraction.onehot(new_line, 41),
                  *iMRMFeatureEtraction.dbe(new_line, 41),
                  file=file_inter_M6A)
            file_inter_M6A.close()
            pddtest = pd.read_csv("inter_use/hg_inter_use_M6A.txt",
                                  sep=' ',
                                  header=None)
            X_test = pddtest.values[:, [
                x - 1 for x in importance_dict_sorted_list_num_M6A
            ]]
            prediction = XG_iRNA_hg_M6A.predict_proba(X_test)
            if prediction[0][1] > M_threshold:
                hg_n_base_list_M6A_proba.append(prediction[0][1])
                hg_M6A_list_num.append(hg_n_base_41_M6A + 1)
    if len(hg_M6A_list_num) > 0:
        hg_M6A_list_num.reverse()
        hg_n_base_list_M6A_proba.reverse()
        n = 0
        for i in [i - 1 for i in hg_M6A_list_num]:
            line = list(line)
            line[i] = '<font color=#00FF00>A</font>(' + str(
                hg_n_base_list_M6A_proba[n]) + ')'
            n += 1
    line = str(line).replace(',', '')
    line = line.replace('[', '')
    line = line.replace(']', '')
    line = line.replace(' ', '')
    line = line.replace('\'', '')
    line = line.replace('\\r', '')
    line_pro = line.replace('fontcolor', 'font color')
    line = line_pro
    pro_list = re.findall('\(.*?\)', line_pro)
    for i in pro_list:
        line = line.replace(i, '')
    return line, line_pro, hg_M6A_list_num
Exemple #15
0
def human_XG_iRNA_M1A(sequence, species, modification, M_threshold):
    # -------------------------------------------------------------
    importance_dict_sorted_list_num_M1A = [
        1834, 1831, 16, 1500, 1503, 3, 9, 1, 19, 4, 20, 6, 2, 1378, 1386, 1872,
        30, 1520, 1529, 1484, 243, 1002, 1372, 259, 1873, 200, 1817, 312, 1400,
        584, 572, 1404, 943, 239, 41, 190, 1415, 34, 1455, 64, 1856
    ]
    XG_iRNA_hg_M1A = load('model/hg/hg_xgb_M1A_10fold')
    # --------------------------------------------------------------
    M_threshold = Threshold.choiceThreshold(species, modification, M_threshold)
    line = sequence  # bug
    hg_n_base_41_M1A = 19
    hg_n_base_list_M1A_proba = []
    hg_M1A_list_num = []
    for base in line.strip()[20:-20]:
        hg_n_base_41_M1A += 1
        file_inter_M1A = open('inter_use/hg_inter_use_M1A.txt', 'w')
        if base == 'A':
            new_line = line.strip()[hg_n_base_41_M1A - 20:hg_n_base_41_M1A +
                                    21]
            # ---f nc dnc tnc tenc pnc nd dnd ncp dpcp onehot dbe-----------------
            print(*iMRMFeatureEtraction.nc(new_line, 41),
                  *iMRMFeatureEtraction.dnc(new_line, 41),
                  *iMRMFeatureEtraction.tnc(new_line, 41),
                  *iMRMFeatureEtraction.tenc(new_line, 41),
                  *iMRMFeatureEtraction.pnc(new_line, 41),
                  *iMRMFeatureEtraction.nd(new_line, 41),
                  *iMRMFeatureEtraction.dnd(new_line, 41),
                  *iMRMFeatureEtraction.ncp(new_line, 41),
                  *iMRMFeatureEtraction.dpcp(new_line, 41),
                  *iMRMFeatureEtraction.onehot(new_line, 41),
                  *iMRMFeatureEtraction.dbe(new_line, 41),
                  file=file_inter_M1A)
            file_inter_M1A.close()
            pddtest = pd.read_csv("inter_use/hg_inter_use_M1A.txt",
                                  sep=' ',
                                  header=None)
            X_test = pddtest.values[:, [
                x - 1 for x in importance_dict_sorted_list_num_M1A
            ]]
            prediction = XG_iRNA_hg_M1A.predict_proba(X_test)
            if prediction[0][1] > M_threshold:
                hg_n_base_list_M1A_proba.append(prediction[0][1])
                hg_M1A_list_num.append(hg_n_base_41_M1A + 1)
    if len(hg_M1A_list_num) > 0:
        hg_M1A_list_num.reverse()
        hg_n_base_list_M1A_proba.reverse()
        n = 0
        for i in [i - 1 for i in hg_M1A_list_num]:
            line = list(line)
            line[i] = '<font color=#1E90FF>A</font>(' + str(
                hg_n_base_list_M1A_proba[n]) + ')'
            n += 1
    line = str(line).replace(',', '')
    line = line.replace('[', '')
    line = line.replace(']', '')
    line = line.replace(' ', '')
    line = line.replace('\'', '')
    line = line.replace('\\r', '')
    line_pro = line.replace('fontcolor', 'font color')
    line = line_pro
    pro_list = re.findall('\(.*?\)', line_pro)
    for i in pro_list:
        line = line.replace(i, '')
    return line, line_pro, hg_M1A_list_num
def process_image(mtx, dist, image):

    # Define an image to draw on
    draw_image = np.copy(image)

    # **LANE LINE DETECTION**

    # Undistort the image
    dist = cv2.undistort(image, mtx, dist, None, mtx)

    # Apply thresholding to the image
    combined_binary = Threshold.white_yellow_threshold(dist)

    # Mask lane line area
    masked_img = FindLaneLineUtils.mask_lane_line_area(combined_binary)

    # Warp the image to an overhead view
    warped_img, src, dest = FindLaneLineUtils.warp_image(masked_img)

    # Identify the lane line pixels
    combined = FindLaneLineUtils.get_lane_line_pixels(warped_img)

    # Get polynomials for lane lines
    left_fit, right_fit = FindLaneLineUtils.get_polynomials(combined)

    # **VEHICLE DETECTION**

    # Define xy overlap and use slide_windows function to develop search windows for vehicles
    xy_overlap = (0.8, 0.8)
    windows_1 = slide_window(image,
                             x_start_stop=[None, None],
                             y_start_stop=[440, 620],
                             xy_window=(128, 128),
                             xy_overlap=xy_overlap)
    windows_2 = slide_window(image,
                             x_start_stop=[None, None],
                             y_start_stop=[400, 496],
                             xy_window=(96, 96),
                             xy_overlap=xy_overlap)
    windows_3 = slide_window(image,
                             x_start_stop=[None, None],
                             y_start_stop=[400, 528],
                             xy_window=(64, 64),
                             xy_overlap=xy_overlap)
    windows = windows_1 + windows_2 + windows_3

    # Alter images read since images are jpg, where training data is png
    sized_image = image.astype(np.float32) / 255

    # Use hot_windows function to "turn on" windows are assigned as vehicle by the classifier
    hot_windows = search_windows(sized_image,
                                 windows,
                                 svc,
                                 X_scaler,
                                 color_space=color_space,
                                 spatial_size=spatial_size,
                                 hist_bins=hist_bins,
                                 orient=orient,
                                 pix_per_cell=pix_per_cell,
                                 cell_per_block=cell_per_block,
                                 hog_channel=hog_channel,
                                 spatial_feat=spatial_feat,
                                 hist_feat=hist_feat,
                                 hog_feat=hog_feat)

    # Intialize all_hot_windows with this frame's hot windows
    all_hot_windows = hot_windows

    # Define window image, draw_boxes draws all_hot_windows onto the draw image
    window_img = draw_boxes(draw_image,
                            all_hot_windows,
                            color=(0, 0, 255),
                            thick=6)

    # Add heat to each box in box list
    heat = np.zeros_like(image[:, :, 0]).astype(np.float)
    heat = add_heat(heat, all_hot_windows)

    # Apply a threshold to the heatmap
    threshold = (np.array(all_hot_windows).shape[0]) // 10 + 1
    # threshold = 1

    heat = apply_threshold(heat, threshold)

    # Visualize the heatmap when displaying
    heatmap = np.clip(heat, 0, 255)
    # mpimg.imsave((os.path.join("output_images/heat_images/", filename)), heatmap)

    # Find final boxes from heatmap using label function
    # save the boxes drawn as an array
    labels = label(heat)
    output_boxes = get_vehicle_boxes(np.copy(image), labels)

    # **MONITOR OVER LAST 10 FRAMES**

    # Update results
    results.update(output_boxes, left_fit, right_fit)

    # Get the average over the last 10 frames
    avg_boxes = results.get_boxes()
    avg_left_fit = results.get_poly_left()
    avg_right_fit = results.get_poly_right()

    # **COMBINED DETECTION & DRAW**

    # Draw the lane area on a blank image
    poly_img = FindLaneLineUtils.plot_polynomial_overlay(
        combined, avg_left_fit, avg_right_fit)

    # Un-warp the image back to it's normal view with the lane line area overlain
    lane_line_overlay_img = FindLaneLineUtils.overlay_with_inverse_transform(
        draw_image, poly_img, src, dest)

    # Add the vehicle detection boxes to to the lane line overlay image
    box_image = draw_labeled_bboxes(np.copy(image), avg_boxes)
    result = cv2.addWeighted(box_image, 0.5, lane_line_overlay_img, 0.5, 0)

    return result
import Sobel_edge_enhancement as enhance
import Threshold as detect
import time

#Create a grayscale image
grayImage = gray.GrayScale()

#Apply a Gaussian Blur filter
blurImage = blur.GaussianBlur(grayImage)

#Perform Edge Enhancement
start = time.time()
enhancedImage = enhance.sobel_edge_detection(blurImage)
end = time.time()
print(f"Edge enhancement completed in {round(end-start,2)} seconds.")

#Perform Sobel Edge Detection
start = time.time()
finalImage = detect.Threshold()
end = time.time()
print(f"Final edge detection completed in {round(end-start,2)} seconds.")
'''
===============================================================================
ACADEMIC INTEGRITY STATEMENT
    I have not used source code obtained from any other unauthorized
    source, either modified or unmodified. Neither have I provided
    access to my code to another. The project I am submitting
    is my own original work.
===============================================================================
'''
Exemple #18
0
def mm_XG_iRNA_pse(sequence, species, modification, M_threshold):
    M_threshold = Threshold.choiceThreshold(species, modification, M_threshold)
    # -------------------------------------------------------------
    mm_importance_dict_sorted_list_num_Pse = [
        1441, 1442, 85, 1692, 55, 190, 1678, 101, 25, 221, 122, 128, 60, 692,
        93, 16, 255, 173, 1696, 12, 35, 701, 1715, 67, 183, 150, 808, 147,
        1431, 43, 1463, 5, 1378, 71, 44, 1377, 1385, 1440, 1446, 1373, 278,
        1649, 1697, 1368, 49, 662, 1457, 327, 1384, 767
    ]
    XG_iRNA_mm_Pse = load('model/mm/mm_xgb_Pse_10fold')
    # --------------------------------------------------------------
    line = sequence  # bug
    if re.search(r'[^AUCG]', line.strip()):
        nota = "Please input the RNA sequence 'AUCG'."
        return nota
    length = len(line.strip())
    if length < 21:
        nota = "Please input the RNA sequence at least 51 bases! "
        return nota
    mm_n_base_21 = 9
    mm_n_base_list_pse_proba = []
    mm_pse_list_num = []
    # -----------------------------PSE ---------------------------------------------------
    for base in line.strip()[10:-10]:
        mm_n_base_21 += 1
        file_inter_pse = open('inter_use/mm_inter_use_pse.txt', 'w')
        if base == 'U':
            new_line = line.strip()[mm_n_base_21 - 10:mm_n_base_21 + 11]
            # ---f nc dnc tnc tenc pnc nd dnd ncp dpcp onehot dbe-----------------
            print(*iMRMFeatureEtraction.nc(new_line, 21),
                  *iMRMFeatureEtraction.dnc(new_line, 21),
                  *iMRMFeatureEtraction.tnc(new_line, 21),
                  *iMRMFeatureEtraction.tenc(new_line, 21),
                  *iMRMFeatureEtraction.pnc(new_line, 21),
                  *iMRMFeatureEtraction.nd(new_line, 21),
                  *iMRMFeatureEtraction.dnd(new_line, 21),
                  *iMRMFeatureEtraction.ncp(new_line, 21),
                  *iMRMFeatureEtraction.dpcp(new_line, 21),
                  *iMRMFeatureEtraction.onehot(new_line, 21),
                  *iMRMFeatureEtraction.dbe(new_line, 21),
                  file=file_inter_pse)
            file_inter_pse.close()
            pddtest = pd.read_csv("inter_use/mm_inter_use_pse.txt",
                                  sep=' ',
                                  header=None)
            X_test = pddtest.values[:, [
                x - 1 for x in mm_importance_dict_sorted_list_num_Pse
            ]]
            prediction = XG_iRNA_mm_Pse.predict_proba(X_test)
            if prediction[0][1] > M_threshold:
                mm_n_base_list_pse_proba.append(prediction[0][1])
                mm_pse_list_num.append(mm_n_base_21 + 1)
    if len(mm_pse_list_num) > 0:
        mm_pse_list_num.reverse()
        mm_n_base_list_pse_proba.reverse()
        n = 0
        for i in [i - 1 for i in mm_pse_list_num]:
            line = list(line)
            line[i] = '<font color=#FF3333>U</font>(' + str(
                mm_n_base_list_pse_proba[n]) + ')'
            n += 1
    line = str(line).replace(',', '')
    line = line.replace('[', '')
    line = line.replace(']', '')
    line = line.replace(' ', '')
    line = line.replace('\'', '')
    line = line.replace('\\r', '')
    line_pro = line.replace('fontcolor', 'font color')
    line = line_pro
    pro_list = re.findall('\(.*?\)', line_pro)
    for i in pro_list:
        line = line.replace(i, '')
    return line, line_pro, mm_pse_list_num
Exemple #19
0
def human_XG_iRNA_AI(sequence, species, modification, M_threshold):
    hg_importance_dict_sorted_list_num_AI = [
        1899, 1895, 5, 1, 69, 79, 252, 1892, 19, 1540, 1390, 1441, 1391, 52,
        299, 1931, 1406, 25, 572, 1547, 83, 1983, 303, 1367, 72, 1414, 23, 250,
        61, 110, 1584, 24, 401, 1402, 1449, 1903, 1437, 341, 214, 1894, 1833,
        36, 1574, 739, 1382, 44, 1404, 1526
    ]
    XG_iRNA_hg_AI = load('model/hg/hg_xgb_AI_10fold')

    # --------------------------------------------------------------
    line = sequence
    hg_n_base_51 = 24
    hg_n_base_list_AI_proba = []
    hg_AI_list_num = []
    M_threshold = Threshold.choiceThreshold(species, modification, M_threshold)
    # -----------------------------AI ---------------------------------------------------
    for base in line.strip()[25:-25]:
        hg_n_base_51 += 1
        file_inter_AI = open('inter_use/hg_inter_use_AI.txt', 'w')
        if base == 'A':
            new_line = line.strip()[hg_n_base_51 - 25:hg_n_base_51 + 26]
            # ---f nc dnc tnc tenc pnc nd dnd ncp dpcp onehot dbe-----------------
            print(*iMRMFeatureEtraction.nc(new_line, 51),
                  *iMRMFeatureEtraction.dnc(new_line, 51),
                  *iMRMFeatureEtraction.tnc(new_line, 51),
                  *iMRMFeatureEtraction.tenc(new_line, 51),
                  *iMRMFeatureEtraction.pnc(new_line, 51),
                  *iMRMFeatureEtraction.nd(new_line, 51),
                  *iMRMFeatureEtraction.dnd(new_line, 51),
                  *iMRMFeatureEtraction.ncp(new_line, 51),
                  *iMRMFeatureEtraction.dpcp(new_line, 51),
                  *iMRMFeatureEtraction.onehot(new_line, 51),
                  *iMRMFeatureEtraction.dbe(new_line, 51),
                  file=file_inter_AI)
            file_inter_AI.close()
            pddtest = pd.read_csv("inter_use/hg_inter_use_AI.txt",
                                  sep=' ',
                                  header=None)
            X_test = pddtest.values[:, [
                x - 1 for x in hg_importance_dict_sorted_list_num_AI
            ]]
            prediction = XG_iRNA_hg_AI.predict_proba(X_test)
            if prediction[0][1] > M_threshold:
                hg_n_base_list_AI_proba.append(prediction[0][1])
                hg_AI_list_num.append(hg_n_base_51 + 1)
    if len(hg_AI_list_num) > 0:
        hg_AI_list_num.reverse()
        hg_n_base_list_AI_proba.reverse()
        n = 0
        for i in [i - 1 for i in hg_AI_list_num]:
            line = list(line)
            line[i] = '<font color=#9400D3>A</font>(' + str(
                hg_n_base_list_AI_proba[n]) + ')'
            n += 1
    line = str(line).replace(',', '')
    line = line.replace('[', '')
    line = line.replace(']', '')
    line = line.replace(' ', '')
    line = line.replace('\'', '')
    line = line.replace('\\r', '')
    line_pro = line.replace('fontcolor', 'font color')
    line = line_pro
    pro_list = re.findall('\(.*?\)', line_pro)
    for i in pro_list:
        line = line.replace(i, '')
    return line, line_pro, hg_AI_list_num
Exemple #20
0
import numpy as np
import Threshold as th

test = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
thresholdClass = th.Thresholds(test)

print(thresholdClass.allLabelings())

goodInput = False
while goodInput is False:
    choice = int(input("Enter function choice: "))

    if choice >= 0 and choice < len(test):
        goodInput = True

    else:
        print("Please enter a number between 0 and the length of the array")
thresholdClass.setBestFunction(choice)

bestThreshold = thresholdClass.getBestFunction()

print(bestThreshold(test))

print(bestThreshold(4))