Esempio n. 1
0
def sliding_windows(rsaValues, win_width):
    """ compute the average of sliding windows; return min,max"""
    rsaseq = rsaValues
    win_num = len(rsaseq) - win_width + 1
    if win_num > 0:
        #set the intial number
        max_score = my_average(rsaseq[0:win_width])
        min_score = max_score
        for i in range(win_num):
            onewin = rsaseq[i:i + win_width]
            oneave = my_average(onewin)
            # find the maximum
            if oneave > max_score:
                max_score = oneave
            if oneave < min_score:
                min_score = oneave
    else:  # win_num =0; or win_width larger than rsaValues
        max_score = 0
        min_score = 0
        print("### rsaValues len: %d < win-width %d" %
              (len(rsaValues), len(win_width)))
    return (min_score, max_score)
Esempio n. 2
0
def api_dowith_spinex(output_f, proseq, CUTOFF=0.25):
    """input fasta,folder,cutoff; ouput >id;seq;ss;exposed/burid"""
    AA, SS = "", ""
    ASA = []
    RSA = []
    BdEd = ""
    if os.path.isfile(output_f):
        AA, SS, ASA = get_asa_spinex(output_f)
    else:
        print("Can not find SpineX prediction of %s" % output_f)

    #print(ASA)
    if proseq != AA:
        print("predicted vs. proseq different: %s" % output_f)
        # do with the sequence contain X
        #write the id;proseq;
        tmp_seq = proseq.replace("X", "")
        tmp_RSA, tmp_BdEd = ASA2RSA(tmp_seq, ASA)
        #used the average rsa to replace the position x.
        tmp_ave_RSA = my_average(tmp_RSA)
        #write the buried/exposed
        count_x = 0
        for k in range(len(proseq)):
            if proseq[k] == "X":
                count_x = count_x + 1
                if tmp_ave_RSA > CUTOFF:
                    BdEd += "1"  #fw.write("1")
                else:
                    BdEd += "0"  #fw.write("0")
            else:
                if tmp_RSA[k - count_x] > CUTOFF:
                    BdEd += "1"  #fw.write("1")
                else:
                    BdEd += "0"  #fw.write("0")
        print("Meet %d X" % count_x)
        # write the rsa values
        for k in range(len(proseq)):
            if proseq[k] == "X":
                RSA.append(tmp_ave_RSA)
            else:
                RSA.append(tmp_RSA[k - count_x])
    else:
        RSA, BdEd = ASA2RSA(AA, ASA)

    return ((AA, SS, BdEd, RSA))
Esempio n. 3
0
def my_dowith_spinex(fr_n, folder, fw_n, CUTOFF=0.25):
    """input fasta,folder,fw_n, cutoff; ouput >id;seq;ss;exposed/burid"""
    fr = open(fr_n, 'r')
    lines = [line.strip() for line in fr.readlines()]
    fr.close()
    AA = ""
    SS = ""
    ASA = RSA = []

    #fw_n="d62.rsa.dat"   RSA values
    fw = open(fw_n, 'w')

    for i in range(len(lines)):
        if len(lines[i]) > 0 and lines[i][0] == '>':
            proid = lines[i].split()[0][1:]
            proseq = lines[i + 1]
            output_f = folder + "/" + proid + ".spXout"  #"./spXout/%s.spXout" %proid.upper()
            AA, SS, ASA = get_asa_spinex(output_f)
            #print(ASA)
            if proseq != AA:
                print("predicted vs. proseq different: %s" % proid)
                # do with the sequence contain X
                #write the id;proseq;
                fw.write("%s\n%s\n%s\n" % (lines[i], lines[i + 1], SS))
                tmp_seq = proseq.replace("X", "")
                tmp_RSA, tmp_BdEd = ASA2RSA(tmp_seq, ASA)
                #used the average rsa to replace the position x.
                tmp_ave_RSA = my_average(tmp_RSA)
                #write the buried/exposed
                count_x = 0
                for k in range(len(proseq)):
                    if proseq[k] == "X":
                        count_x = count_x + 1
                        if tmp_ave_RSA > CUTOFF:
                            fw.write("1")
                        else:
                            fw.write("0")
                    else:
                        if tmp_RSA[k - count_x] > CUTOFF:
                            fw.write("1")
                        else:
                            fw.write("0")
                fw.write("\n")
                # write the rsa values
                count_x = 0
                for k in range(len(proseq)):
                    if proseq[k] == "X":
                        fw.write("%.5f," % tmp_ave_RSA)
                        count_x = count_x + 1
                    else:
                        fw.write("%.5f," % tmp_RSA[k - count_x])
                fw.write("\n")
            else:
                RSA, BdEd = ASA2RSA(AA, ASA)
                #write the id; proseq;ss,rsa_binary
                fw.write("%s\n%s\n%s\n%s\n" % (lines[i], AA, SS, BdEd))
                # write the rsa values
                for j in range(len(RSA)):
                    fw.write("%.5f," % RSA[j])
                fw.write("\n")
    fw.close()
Esempio n. 4
0
def my_dowith_spinex(fr_n, folder, CUTOFF=0.25):
    """input fasta,folder,cutoff; ouput >id;seq;ss;exposed/burid"""
    fr = open(fr_n, 'r')
    lines = [line.strip() for line in fr.readlines()]
    fr.close()

    SSS = []
    BdEdS = []
    RSAS = []

    for i in range(len(lines)):
        if len(lines[i]) > 0 and lines[i][0] == '>':
            proid = lines[i].split()[0][1:]
            proseq = lines[i + 1]
            BdEd = ""
            RSA = []
            #output_f=folder+ "/"+proid+".spXout" #"./spXout/%s.spXout" %proid.upper()
            output_f = "%s/%s.spXout" % (folder, proid)
            if os.path.isfile(output_f):
                AA, SS, ASA = get_asa_spinex(output_f)
            else:
                AA, SS = "", ""
                ASA = []
                print("Can not find SpineX prediction of %s" % proid)

            #print(ASA)
            if proseq != AA:
                print("predicted vs. proseq different: %s" % proid)
                # do with the sequence contain X
                #write the id;proseq;
                tmp_seq = proseq.replace("X", "")
                tmp_RSA, tmp_BdEd = ASA2RSA(tmp_seq, ASA)
                #used the average rsa to replace the position x.
                tmp_ave_RSA = my_average(tmp_RSA)
                #write the buried/exposed
                count_x = 0
                for k in range(len(proseq)):
                    if proseq[k] == "X":
                        count_x = count_x + 1
                        if tmp_ave_RSA > CUTOFF:
                            BdEd += "1"  #fw.write("1")
                        else:
                            BdEd += "0"  #fw.write("0")
                    else:
                        if tmp_RSA[k - count_x] > CUTOFF:
                            BdEd += "1"  #fw.write("1")
                        else:
                            BdEd += "0"  #fw.write("0")
                print("Meet %d X" % count_x)
                # write the rsa values
                for k in range(len(proseq)):
                    if proseq[k] == "X":
                        RSA.append(tmp_ave_RSA)
                    else:
                        RSA.append(tmp_RSA[k - count_x])
            else:
                RSA, BdEd = ASA2RSA(AA, ASA)
            SSS.append(SS)
            BdEdS.append(BdEd)
            RSAS.append(RSA)

    return ((AA, SS, BdEdS, RSAS))