检查我的元组代码

时间:2014-04-11 23:54:27

标签: python replace fastq

所以我试图创建一个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 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()

1 个答案:

答案 0 :(得分:1)

如果您的输入是这样的,请删除第一个字符(@),将字符串拆分为:,然后将您获得的值压缩为预先设定的值键:

>>> 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

我强烈建议您检查:

  • 切片(here
  • 拆分功能对字符串的作用
  • dict是什么(here
  • 什么拉链(here