-1

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. This is what the program is supposed to carry out:

if I enter the FASTQ seqname line...

@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()
Leandro Papasidero
  • 3,728
  • 1
  • 18
  • 33
user3504701
  • 45
  • 1
  • 6
  • to further clarify, this is what the program should do: "if I enter the FASTQ seqname line “@EAS139:136:FC706VJ:2:2104:15343:197393” (without quotes), 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" – user3504701 Apr 11 '14 at 23:55
  • Put that comment in the question! Just edit it in. Any new relevant information should always go in your question. :) – Mdev Apr 11 '14 at 23:58
  • `"@EAS139:136:FC706VJ:2:2104:15343:197393"[1:].split(':')` – Savir Apr 11 '14 at 23:59
  • 2
    @Human, I just did :-), @user3504701, in these cases, click on the `edit` link below the question. It will allow you to add text and stuff – Savir Apr 12 '14 at 00:00
  • @user3504701, I added the output to the question but I didn't want to change your indentation. Are you sure that's correct? Because you'd get an `Exception` if you try to run that. Is that the case or is just that your indentation got messed up when you posted the question? – Savir Apr 12 '14 at 00:02
  • 1
    You're going to get an Exception no matter how you slice it because `(float(1[1]),float(1[2))]` isn't even close to valid Python syntax. – Two-Bit Alchemist Apr 12 '14 at 00:04
  • @Two-BitAlchemist fair point, I didn't even get to that part... I stopped after the `__class__` :-D – Savir Apr 12 '14 at 00:08

1 Answers1

1

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:

  • Slicing strings (here)
  • What the split function does to an string
  • What a dict is (here)
  • What zip does (here)
Savir
  • 17,568
  • 15
  • 82
  • 136
  • @user3504701 I just updated my question... I think you should check the links I provided **:)** – Savir Apr 12 '14 at 00:33