[英]Checking my Tuple code
So I'm trying to parce a FastQ sequence, but I'm a beginner to Python, and I'm a little confused as to how to complete my code.所以我试图解析一个 FastQ 序列,但我是 Python 的初学者,我对如何完成我的代码有点困惑。 This is what the program is supposed to carry out:
这是程序应该执行的操作:
if I enter the FASTQ seqname line...如果我输入 FASTQ seqname 行...
@EAS139:136:FC706VJ:2:2104:15343:197393
...then the program will output: ...然后程序将输出:
Instrument = EAS139
Run ID = 136
Flow Cell ID = FC706VJ
Flow Cell Lane = 2
Tile Number = 2104
X-coord = 15343
Y-coord = 197393
Here's my (incomplete) code:这是我的(不完整的)代码:
class cleaner:
def __init__(self,str):
self.str = seq.upper()
def line (self):
1 = inStr.replace ('@',' ').replace (':',' ').split (' ')
newTuple =(float(1[1]),float(1[2))] #...etc
def printInstrument (self):
print ("Instrument: {0}".format(float(1[1])))
def printRunID (self):
print ("Run ID: {0}".format(float(1[2])))
def printFlowCellID (self):
print ("Flow Cell ID: {0}".format(float(1[3])))
def printFlowCellLane (self):
print ("Flow Cell Lane: {0}".format(float(1[4])))
def printTileNumber (self):
print ("Tile Number{0}".format(float(1[5])))
def printX (self):
print ("X-coordinate:{0}".format(float(1[6])))
def printY (self):
print ("y-coordinate: {0}".format(float(1[7])))
def main():
seq = input('Enter FastQ sequence:')
main()
If your input is like that, remove the first character (the @
), split the string by :
and then zip the values you'll obtain by doing that to a pre-set of keys:如果您的输入是这样的,请删除第一个字符(
@
),用:
分割字符串,然后将通过这样做获得的值压缩到一组预先设置的键中:
>>> keys=["Instrument", "Run ID", "Flow Cell ID", "Flow Cell Lane", "Title Number", "X-coord", "Y-coord"]
>>> values="@EAS139:136:FC706VJ:2:2104:15343:197393"[1:].split(':')
>>> my_dict=dict(zip(keys, values))
>>> for key, val in my_dict.iteritems():
... print "%s: %s" % (key, val)
...
Run ID: 136
Flow Cell ID: FC706VJ
Title Number: 2104
Y-coord: 197393
X-coord: 15343
Flow Cell Lane: 2
Instrument: EAS139
I strongly recommend that you check:我强烈建议您检查:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.