python脚本 - 没有错误,但没有结果和输出是一个空文件

时间:2016-07-19 07:15:22

标签: python-3.x

我正在尝试使用以下代码根据89,90,91和92索引中的信息过滤txt文件。 问题是输出文件是一个空文件只有标题。代码没有给出任何错误 - 所以我不知道如何调试它。 谢谢你的帮助!!

    for line in fileHandle: 
        if firstLineFlag == 0:  #to skip first line
            firstLineFlag = 1
            firstLineText = line    #save the first line elsewhere
            continue
        parts = line.strip().split('\t')

                        try:
                            column13=float(parts[13-1])
                        except ValueError:
                            column13=0
                        if column13 < 0.01:

                            if parts[92] == "./.:.:.:.:.":
                                Nor_info_2 = parts[92].replace("./.:.:.:.:.", "00:1,1:1:1:1,1,1")

                            if parts[91] == "./.:.:.:.:.":
                                Nor_info = parts[91].replace("./.:.:.:.:.", "00:1,1:1:1:1,1,1")

                            if parts[90] == "./.:.:.:.:.":
                                Tu_info_2 = parts[90].replace("./.:.:.:.:.", "00:1,1:1:1:1,1,1")

                            if parts[89] == "./.:.:.:.:.":
                                Tu_info = parts[89].replace("./.:.:.:.:.", "00:1,1:1:1:1,1,1")

                                normalSplit_2 = parts[92].split(':')
                                normalSplit = parts[91].split(':')
                                tumorSplit_2 = parts[90].split(':')
                                tumorSplit = parts[89].split(':')

                                print(Nor_info_2)
                                try:
                                    TD_Tumor_2 = float(tumorSplit_2[3-1])
                                except ValueError:
                                    TD_Tumor = 0    

                                    try:
                                        TD_Tumor = float(tumorSplit[3-1])
                                    except ValueError:
                                        TD_Tumor = 0

                                try:
                                    TD_Normal_2 = float(normalSplit_2[3-1])
                                except ValueError:
                                    TD_Tumor = 0    

                                    try:
                                        TD_Normal = float(normalSplit[3-1])
                                    except ValueError:
                                        TD_Tumor = 0

                                    if TD_Tumor_2 >= TD_Tumor and TD_Tumor_2 >= 7:
                                        tumorAD=tumorSplit_2[2-1].split(',')
                                        normalAD=normalSplit_2[2-1].split(',')
                                        normalratio=float(normalAD[2-1])/TD_Normal_2
                                    else:
                                        tumorAD=tumorSplit[2-1].split(',')
                                        normalAD=normalSplit[2-1].split(',')
                                        normalratio=float(normalAD[2-1])/TD_Normal

                                        tumorratio=float(tumorAD[2-1])/TD_Tumor_2

                                        parts.append(tumorratio)
                                        parts.append(normalratio)
                                        data.append(parts)

dataz1 = sorted(data,key = itemgetter(91),reverse = True)

#with open('filtered/'+currentFile+'_filtered.txt', 'w') as fileHandle:         ## to write your data in proper format
with open(currentFile+'_filtered.txt', 'w') as fileHandle:          ## to write your data in proper format
    fileHandle.write(firstLineText) 
    for item in data:
        convert_first_to_generator = (str(w) for w in item)
        string =  '\t'.join(convert_first_to_generator)
        string += '\n'
        #print string
        fileHandle.write(string)

command = 'mv '+currentFile+'_filtered.txt  filtered/'      ### to move edited files into a different folder
system(command)

0 个答案:

没有答案