cgc_create

import os.path
sig_dir = "D://project//gff//out//"
w_dir = "D://project//gff//cgc_table5//"
# fw= open(w_dir,"w")

cgc_number = 0
yuzhi = 4
for parent,dirnames,filenames in os.walk(sig_dir):
    for filename in filenames:
        gen = filename
        f = open(os.path.join(parent,filename))
        h = f.readlines()
        f.close()
        h_len = len(h)
        prev_reseq = h[0].split("   ")[0]
        list=[]
        #wirte cluster
        fw = open(w_dir+gen,"w")
        for i in range(h_len):
            if h[i]=='\n':
                continue
            line = h[i].split(" ")
            if prev_reseq != line[0]:
                #write the cluster
                cluster=[]
                cazy = 0
                tc = 0
                tf = 0
                list_len = len(list)
                cgc_no = 1
                #wirte the cluster
                for k in range(list_len):
                    cluster.append(list[k])
                    #print cluster[-1]
                    if list[k][-1] <= yuzhi :
                        if list[k][1]=="TC-DB":
                            tc = tc+1
                        elif list[k][1]=="TF":
                            tf = tf+1
                        elif list[k][1]=="CAZyme":
                            cazy = cazy +1
                    else :
                        if (cazy > 0 and tc > 0 and tf >0):
                        # if (cazy>0 and tc >0) or (cazy>0 and tf>0):
                            cnt = 0
                            for j in range(cluster[-1][0]+1-cluster[0][0]):
                                if h[cluster[0][0] + j].split()[-1] == "null":
                                    for p in range(4):
                                        fw.write("null" + " ")
                                else:
                                    for p in range(4):
                                        fw.write(str(cluster[cnt][p]) + "   ")
                                    cnt = cnt + 1
                                fw.write(prev_reseq+"-"+"CGC"+str(cgc_no)+" "+h[cluster[0][0]+j])
                            fw.write("+++\n")
                            cazy = 0
                            tc = 0
                            tf = 0
                            cgc_no = cgc_no +1
                            cgc_number = cgc_number+1
                        cluster=[] #delete the cluster
                #write the left cluster
                if len(cluster)>0:
                    if (cazy > 0 and tc > 0 and tf > 0):
                    # if (cazy > 0 and tc > 0) or (cazy > 0 and tf > 0):
                        cnt = 0
                        for j in range(cluster[-1][0] + 1 - cluster[0][0]):
                            if h[cluster[0][0] + j].split()[-1] == "null":
                                for p in range(4):
                                    fw.write("null" + " ")
                            else:
                                for p in range(4):
                                    fw.write(str(cluster[cnt][p]) + "   ")
                                cnt = cnt + 1
                            fw.write(prev_reseq + "-" + "CGC" + str(cgc_no) + " " + h[cluster[0][0] + j])
                        fw.write("+++\n")
                        cazy = 0
                        tc = 0
                        tf = 0
                        cgc_no = cgc_no + 1
                        cgc_number = cgc_number + 1
                    cluster = []  # delete the cluster
                # process the new refseq
                list = []
            if line[6] != "null":
                sig = line[6].split('|')[0]
                if len(list) == 0:
                    dis_prev = 0
                else:
                    dis_prev = i - list[-1][0]
                    list[-1][3] = dis_prev
                dis_next = 0
                list.append([i, sig, dis_prev, dis_next])
                prev_reseq = line[0]
        # write left cluster
        if len(list)>0:
            cluster = []
            cazy = 0
            tc = 0
            tf = 0
            list_len = len(list)
            cgc_no=1
            # wirte the cluster
            for k in range(list_len):
                cluster.append(list[k])
                if list[k][-1] <= yuzhi :
                    if list[k][1] == "TC-DB":
                        tc = tc + 1
                    elif list[k][1] == "TF":
                        tf = tf + 1
                    elif list[k][1] == "CAZyme":
                        cazy = cazy + 1
                else:
                    if (cazy > 0 and tc > 0 and tf > 0):
                    # if (cazy > 0 and tc > 0) or (cazy > 0 and tf > 0):
                        cnt = 0
                        for j in range(cluster[-1][0] + 1 - cluster[0][0]):
                            if h[cluster[0][0] + j].split()[-1] == "null":
                                for p in range(4):
                                    fw.write("null" + " ")
                            else:
                                for p in range(4):
                                    fw.write(str(cluster[cnt][p]) + "   ")
                                cnt = cnt + 1
                            fw.write(prev_reseq + "-" + "CGC" + str(cgc_no) + " " + h[cluster[0][0] + j])
                        fw.write("+++\n")
                        cazy = 0
                        tc = 0
                        tf = 0
                        cgc_no = cgc_no + 1
                        cgc_number = cgc_number + 1

                    cluster = []  # delete the cluster
            # write the left cluster
            if len(cluster) > 0:
                if (cazy > 0 and tc > 0 and tf > 0):
                # if (cazy > 0 and tc > 0) or (cazy > 0 and tf > 0):
                    cnt = 0
                    for j in range(cluster[-1][0] + 1 - cluster[0][0]):
                        if h[cluster[0][0] + j].split()[-1] == "null":
                            for p in range(4):
                                fw.write("null" + " ")
                        else:
                            for p in range(4):
                                fw.write(str(cluster[cnt][p]) + "   ")
                            cnt = cnt + 1
                        fw.write(prev_reseq + "-" + "CGC" + str(cgc_no) + " " + h[cluster[0][0] + j])
                    cazy = 0
                    tc = 0
                    tf = 0
                    cgc_no = cgc_no + 1
                    cgc_number = cgc_number + 1
                cluster = []  # delete the cluster
            # process the new refseq
            list = []
print cgc_number
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末拾枣,一起剝皮案震驚了整個濱河市盒让,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌姨蝴,老刑警劉巖肺缕,帶你破解...
    沈念sama閱讀 218,546評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異炒辉,居然都是意外死亡泉手,警方通過查閱死者的電腦和手機(jī)偶器,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,224評論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來颊郎,“玉大人霎苗,你說我怎么就攤上這事⊙湔担” “怎么了?”我有些...
    開封第一講書人閱讀 164,911評論 0 354
  • 文/不壞的土叔 我叫張陵昆淡,是天一觀的道長刽严。 經(jīng)常有香客問我,道長眨补,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,737評論 1 294
  • 正文 為了忘掉前任含思,我火速辦了婚禮实蓬,結(jié)果婚禮上茸俭,老公的妹妹穿的比我還像新娘。我一直安慰自己调鬓,他們只是感情好酌伊,可當(dāng)我...
    茶點故事閱讀 67,753評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著虹脯,像睡著了一般奏候。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上蔗草,一...
    開封第一講書人閱讀 51,598評論 1 305
  • 那天咒精,我揣著相機(jī)與錄音,去河邊找鬼模叙。 笑死,一個胖子當(dāng)著我的面吹牛故觅,可吹牛的內(nèi)容都是我干的渠啊。 我是一名探鬼主播,決...
    沈念sama閱讀 40,338評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼评也,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了盗迟?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,249評論 0 276
  • 序言:老撾萬榮一對情侶失蹤艇纺,失蹤者是張志新(化名)和其女友劉穎邮弹,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體腌乡,經(jīng)...
    沈念sama閱讀 45,696評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡与纽,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,888評論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了影所。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片僚碎。...
    茶點故事閱讀 40,013評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖胀溺,靈堂內(nèi)的尸體忽然破棺而出皆看,到底是詐尸還是另有隱情背零,我是刑警寧澤腰吟,帶...
    沈念sama閱讀 35,731評論 5 346
  • 正文 年R本政府宣布毛雇,位于F島的核電站侦镇,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏壳繁。R本人自食惡果不足惜荔棉,卻給世界環(huán)境...
    茶點故事閱讀 41,348評論 3 330
  • 文/蒙蒙 一润樱、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧壹若,春花似錦皂冰、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,929評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽睡腿。三九已至峻贮,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間纤控,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,048評論 1 270
  • 我被黑心中介騙來泰國打工刻撒, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留耿导,地道東北人。 一個月前我還...
    沈念sama閱讀 48,203評論 3 370
  • 正文 我出身青樓醋火,卻偏偏與公主長得像箱吕,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子茬高,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,960評論 2 355

推薦閱讀更多精彩內(nèi)容