vendredi 24 septembre 2021

split list of strings based on conditions

I am looking to script the following in R or python.

I have a list with markers that are ordered by priority and separated by commas. Let's say a few scientists have prioritized the markers differently based on their needs but resources are limited to run all the markers in the first marker panel 1 so a few have to be moved to panel 2. Let's say the plates is the limiting factor and each loci requires 2 plates to run.

for example the Markers column is what I want to split into MP1 and MP2 based on number of plates available.

ID Markers_list # Loci # Plates Scientist Marker Panel 1 Marker Panel 2
1 A1,B2,C3,D4,E5,F6, 6 12 1 A1,B2,C3,D4,E5,F6,
2 B2,C3,A1,D4, 4 6 2 B2,C3,A1, D4,
3 C3,D4,A1,B2,E5,F6 6 0 3 C3,D4,A1,B2,E5,F6,
4 C3,D4,A1, 3 4 3 C3,D4, A1,
5 B2,C3,A1,D4,F6, 5 2 2 B2, C3,A1,D4,F6,

The end result is to have columns Marker Panel 1 and Marker Panel 2 populated from the markers_list limited by # plates.

Aucun commentaire:

Enregistrer un commentaire