-1

だから私は 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()
4

1 に答える 1

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

以下を確認することを強くお勧めします。

  • 文字列のスライス (ここ)
  • 分割関数が文字列に対して行うこと
  • dict とは ( here )
  • zip の機能 ( here )
于 2014-04-12T00:07:05.473 に答える