Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Code Generator
#2
Cool project!

I wrote this example for you that 'transfers' mastermix to a series of wells as you wanted. Note that I used a dummy transfer function to generate some output. You'll need to adjust this of course.

The idea is: first you make a list of sources for both your mastermix and cDNA. Then, for each mastermix, you must make a list of target wells to transfer them to. Then you make the transfer.
# dummy transfer function, just to test
def transfer(p_amount, p_source, p_target):
 print("Transfering {:>5}ul from {} to {}".format(p_amount, p_source, p_target))


# list of sources of mastermix and cDNA
mastermix_sources = ['A1', 'A2']
cDNA_sources = ['B1', 'B2', 'B3']


# loop through each source of mastermixes
for i, mm in enumerate(mastermix_sources):
 
 # make a list of all targets for this mastermix
 targets =list("{}{}".format(chr(65+i), j+1) for j in range(len(cDNA_sources)))
 
 # transfer mastermixes to wells
 transfer(
           10, 
           mm,
           targets
         )
Which gives me the output:
Output:
Transfering 10ul from A1 to ['A1', 'A2', 'A3'] Transfering 10ul from A2 to ['B1', 'B2', 'B3']
Now this line is a bit complicated, so let me explain:
targets = list( "{}{}".format(chr(65+i), j+1) for j in range(len(cDNA_sources)) )
It generates a list of targets like this:
  • for j in range(len(cDNA_sources))
    loops j through numbers 0 up to the amount of cDNA sources you have
  • "{}{}".format( chr(65+i), j+1)
    format replaces {} in the string with the arguments given:
    • chr(65+i)
      chr returns an ASCII character, chr(65) is A, chr(66) is B, etc. i is the index of this mastermix which we have because we used enumerate
    • j comes from the for loop. We want the first target to be A1, and j starts at 0, so we add 1
  • list makes it into a list (obviously :p)

If anything else is unclear don't hesitate to ask.

Now try and see if you can adapt this example so you can generate the transfers from the cDNA_sources to the wells as well.
Reply


Messages In This Thread
Python Code Generator - by KatherineHov - Jul-24-2017, 05:58 PM
RE: Python Code Generator - by MTVDNA - Jul-24-2017, 10:00 PM
RE: Python Code Generator - by KatherineHov - Jul-25-2017, 04:13 PM
RE: Python Code Generator - by MTVDNA - Jul-25-2017, 04:52 PM
RE: Python Code Generator - by KatherineHov - Jul-25-2017, 05:40 PM
RE: Python Code Generator - by MTVDNA - Jul-25-2017, 06:03 PM
RE: Python Code Generator - by KatherineHov - Jul-25-2017, 09:16 PM
RE: Python Code Generator - by MTVDNA - Jul-25-2017, 09:54 PM
RE: Python Code Generator - by KatherineHov - Jul-26-2017, 05:15 PM
RE: Python Code Generator - by MTVDNA - Jul-26-2017, 09:56 PM
RE: Python Code Generator - by KatherineHov - Jul-27-2017, 01:22 AM
RE: Python Code Generator - by MTVDNA - Jul-27-2017, 10:04 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Is the following code returning a generator expression? quazirfan 8 1,861 Apr-11-2023, 11:44 PM
Last Post: quazirfan
  Python returns generator instead of None Tawnwen 4 4,898 Mar-09-2018, 07:06 AM
Last Post: DeaD_EyE
  receive from a generator, send to a generator Skaperen 9 5,721 Feb-05-2018, 06:26 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020