Welcome, guest | Sign In | My Account | Store | Cart

Due to a mixup in processing, I require to invert the order of the well numbers from a 96-well plate

Python, 23 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/python
#for inverting the plate order when mixups occur!

##e.g. input file looks like
##B1	B3	B5	B7	B9	B11	B13	B15	B17	B19	B21	B23
##D1	D3	D5	D7	D9	D11	D13	D15	D17	D19	D21	D23
##F1	F3	F5	F7	F9	F11	F13	F15	F17	F19	F21	F23
##H1	H3	H5	H7	H9	H11	H13	H15	H17	H19	H21	H23
##J1	J3	J5	J7	J9	J11	J13	J15	J17	J19	J21	J23
##L1	L3	L5	L7	L9	L11	L13	L15	L17	L19	L21	L23
##N1	N3	N5	N7	N9	N11	N13	N15	N17	N19	N21	N23
##P1	P3	P5	P7	P9	P11	P13	P15	P17	P19	P21	P23

input=open('xa','r')
L=input.readlines() #reads lines into list
L.reverse() #reverse rows
for row in L:
##    print row
    splitrow = row.split("\t")
    splitrow.reverse() #reverse column
    newwell=[]
    newwell.extend(splitrow)
    print newwell
        

inputfile name is 'xa' last print statement needs working.. but its good enough for me

3 comments

Matthew Wood 12 years, 2 months ago  # | flag

I don't understand the newwell variable. It seems that you could just cast splitrow into a list after the reverse.

splitrow = row.split("\t")
splitrow.reverse()
print list(splitrow)
brent pedersen 12 years, 2 months ago  # | flag

can also make it shorter, and take the filename from the command line.

import sys
revlines = ["\t".join(l.rstrip().split("\t")[::-1]) for l in open(sys.argv[1])]
print "\n".join(reversed(revlines))
Kevin (author) 12 years, 2 months ago  # | flag

Thanks for the comments! Matthew Wood: It is true I can immediately print the reversed row. I wanted to put all the wells in the correct order into newwell so that I might possibly do something to it.

brent pedersen: Thanks for the tip! will update the link .. it was a quick hack so not sure if I need to do this again. I was surprised that no one posted this recipe before.

Created by Kevin on Fri, 4 Sep 2009 (MIT)
Python recipes (4591)
Kevin's recipes (1)

Required Modules

  • (none specified)

Other Information and Tasks