python - Checking my Tuple code -
so i'm trying parce fastq sequence, i'm beginner python, , i'm little confused how complete code. program supposed carry out:
if enter fastq seqname line...
@eas139:136:fc706vj:2:2104:15343:197393
...then program 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 (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 input that, remove first character (the @
), split string :
, zip values you'll obtain doing 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)) >>> 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 recommend check:
Comments
Post a Comment