小编Joh*_*ohn的帖子

IndentationError:意外的unindent为什么?

IndentationError:意外的unindent为什么???

#!/usr/bin/python
import sys
class Seq:
    def __init__(self, id, adnseq, colen):
        self.id     = id
        self.dna    = adnseq
        self.cdnlen = colen
        self.prot   = ""
    def __str__(self):
        return ">%s\n%s\n" % (self.id, self.prot)
    def translate(self, transtable):
        self.prot = ""
        for i in range(0,len(self.dna),self.cdnlen):
            codon = self.dna[i:i+self.cdnlen]
            aa    = transtable[codon]
            self.prot += aa
    def parseCommandOptions(cmdargs):
        tfname = cmdargs[1]
        sfname = cmdargs[2]
        return (tfname, sfname)
    def readTTable(fname):
        try:
            ttable = {}
            cdnlen = -1
            tfile = open(fname, "r")
            for line in tfile:
                linearr = line.split() …
Run Code Online (Sandbox Code Playgroud)

python indentation

23
推荐指数
2
解决办法
7万
查看次数

用Python循环遍历

所以我有一个包含这个的文件:

SequenceName 4.6e-38 810..924
SequenceName_FGS_810..924 VAWNCRQNVFWAPLFQGPYTPARYYYAPEEPKHYQEMKQCFSQTYHGMSFCDGCQIGMCH
SequenceName 1.6e-38 887..992
SequenceName_GYQ_887..992 PLFQGPYTPARYYYAPEEPKHYQEMKQCFSQTYHGMSFCDGCQIGMCH
Run Code Online (Sandbox Code Playgroud)

我希望我的程序只读取包含这些蛋白质序列的行.到目前为止,我得到了这个,它跳过第一行并阅读第二行:

handle = open(filename, "r")
handle.readline()
linearr = handle.readline().split()
handle.close()

fnamealpha = fname + ".txt"
handle = open(fnamealpha, "w")
handle.write(">%s\n%s\n" % (linearr[0], linearr[1]))
handle.close()
Run Code Online (Sandbox Code Playgroud)

但它只处理第一个序列,我需要它来处理包含序列的每一行,所以我需要一个循环,我该怎么办呢?保存到txt文件的部分也非常重要,所以我需要找到一种方法,可以将这两个目标结合起来.我的输出与上面的代码是:

>SequenceName_810..924
VAWNCRQNVFWAPLFQGPYTPARYYYAPEEPKHYQEMKQCFSQTYHGMSFCDGCQIGMCH
Run Code Online (Sandbox Code Playgroud)

python loops

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

python ×2

indentation ×1

loops ×1