所以我试图解析一个FastQ序列,但我是Python的初学者,我对我的代码无效的原因感到有些困惑。这是该计划应该执行的:
如果我输入FASTQ seqname行...
@EAS139:136:FC706VJ:2:2104:15343:197393
...然后程序应该输出:
Instrument = EAS139
Run ID = 136
Flow Cell ID = FC706VJ
Flow Cell Lane = 2
Tile Number = 2104
X-coord = 15343
Y-coord = 197393
到目前为止,这是我未完成的代码:
class fastq:
def __init__(self,str):
self.str = inStr.replace ('@',' ').split (':')
def lists (self,parameters):
self.parameters = ("Instrument","Run ID","Flow Cell ID","Flow Cell Lane","Tile Number","X-coordinates","y-coordinates")
def zip (self,myZip,zippedTuple):
self.Zip = zip(self.parameters,self.transform)
self.zippedTuple = tuple(myZip)
print (tuple(myZip))
def main():
seq = input('Enter FastQ sequence:')
new_fastq = fastq(str)
new_fastq.lists()
new_fastq.zip()
main()
答案 0 :(得分:2)
您的代码无法正常工作的原因在于它或多或少完全错误。为了在尝试运行程序时按照我们的顺序解决您的错误:
main
:
new_fastq = fastq(str)
未传递我们刚输入的seq
,它会传递内置字符串类型; __init__
:
fastq.__init__
str
是一个坏主意,因为它掩盖了我们刚刚尝试传递给它的内置函数; inStr
来自哪里?lists
:
__init__
parameters
甚至是什么?zip
:
fastq.__str__
更Pythonic。然后你可以print(str(new_fastq))
。话虽如此; self.transform
应该是什么?在其他任何地方都没有提到它。你的意思是self.str
(为了掩盖内置的而且实际上不是字符串),再次应该称之为其他内容?myZip
是您从未通过的论据之一,我认为您实际上需要self.Zip
;但x = tuple(y)
创建print(tuple(y))
? print(x)
<!/ LI>
解决这些问题,加上一些PEP-008奖金整理:
class FastQ:
def __init__(self, seq):
self.elements = seq.replace ('@',' ').split (':')
self.parameters = ("Instrument", "Run ID", "Flow Cell ID",
"Flow Cell Lane", "Tile Number",
"X-coordinates", "y-coordinates")
def __str__(self):
"""A rough idea to get you started."""
return "\n".join(map(str, zip(self.parameters, self.elements)))
def main():
seq = input('Enter FastQ sequence: ')
new_fastq = FastQ(seq)
print(str(new_fastq))
main()