Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #|*******************************************************************************
- #| Functions that handle mixed starting strain to one ending strain
- #|*******************************************************************************
- def make_extra_plates():
- '''
- | user input -> file
- |
- | Returns a file containing multiplexed plate or plates need to run
- | that includes all the primers missing in the first file but present
- | in the second file.
- |
- | Preconditions:
- | files
- | .txt files
- |
- | example snippet of one input file
- | 1 D15mit252F D6mit224V D15mit59N none
- | 2 D1mit440F D1mit236V D16mit107N none
- |
- | no blank lines in the file
- |
- | python 3 needs to be used
- |
- | Example use of this function:
- | A comstomer comes to start a speed congenics project however the
- | starting strain of the project is mixed. For example the starting
- | strain is 129 and C3H combined. The customer wants to cross this
- | mouse onto the B6 background. Therefore the best approach would be
- | to run a full 129XB6 screen (1st input asked for) and then run the
- | primers that are present in the B6XC3H screen and not in the 129XB6
- | screen. The second screen asked for will be the B6XC3H screen.
- '''
- # get input of locations of files
- full_screen_running = input('''Please enter the location of the full
- screen be you running: ''')
- other_strain = input('''Plese enter the location of the other plate mat
- you are wishing to inducde: ''')
- # output_list will now equall a list of all primers not in file1 but in file2
- extra_primers_needed = primers_missing_from_plate_mat(full_screen_running,other_strain)
- # seperates all primers into nested fluorescence lists
- fluoro_list = make_seperate_lists(extra_primers_needed)
- # remove all the empty lists.
- empties_removed = remove_empties(fluoro_list)
- # multiplex all the primers
- multiplexed = multiplex_primers(empties_removed)
- # get input of where is the output_file is
- to_file = input('''Please enter the location of the .txt file you would
- like the multiplexed extra plates writen to: ''')
- # write all the primers to a file
- write_extra_primer_layout(multiplexed, to_file)
- print('Complete! The extra primers you need are located at', to_file)
- def primers_missing_from_plate_mat(first_screen_mat, extra_primer_mat):
- '''
- | (file, file) -> list
- |
- | Return a list of primers which are not in the first file but are
- | present in the second file.
- |
- | first_screen_mat example
- | 1 D15mit252 F D6mit224 V D15mit59 N none
- | 2 D1mit440 F D1mit236 V D16mit107 N none
- |
- | extra_primer_mat example
- | 1 D15mit252 F D6mit224 V D15mit59 N none
- | 2 D19mit91 V D1mit236 V D16mit107 N none
- |
- | list output example
- | ['D19mit91 V']
- '''
- with open(first_screen_mat, 'r') as sf:
- with open(extra_primer_mat, 'r') as of:
- line = sf.readline()
- sf_list = []
- while line != '':
- line = line.strip().split()
- for s in line:
- if s != 'none' and not s.isdigit():
- sf_list.append(s)
- line = sf.readline()
- line = of.readline()
- output_list = []
- while line != '':
- line = line.strip().split()
- for s in line:
- if s not in sf_list and s != 'none' and not s.isdigit():
- output_list.append(s)
- line = of.readline()
- print('\nThe full screen you will be running includes', len(sf_list), 'primers\n')
- print('The extra plate or plates includes', len(output_list), 'primers\n')
- print('Therefore the total number of primers used for this project is',
- (len(sf_list) + len(output_list)), '\n')
- return output_list
- def make_seperate_lists(mixed_list):
- '''
- | (list) -> list
- |
- | Returns a nested 2D list of strings. Each nested list is seperated into
- | primer fluorescence. Therefore there are 4 nested lists. One for FAM,
- | one for Vic, one for Ned, and one for Pet in that order. Each list will
- | be created. However, somelists might be empty such as the Pet list
- | in the example below.
- |
- | example input list:
- | ['D19mit91F', 'D13mit275V', 'D9mit90V', 'D14mit95F', 'D9mit182F',
- | 'D11mit231N']
- |
- | example output_list:
- | [['D19mit91F', 'D14mit95F', 'D9mit182F'], ['D13mit275V', 'D9mit90V'],
- | ['D11mit231N'], []]
- '''
- l = mixed_list
- F_list = []
- V_list = []
- N_list = []
- P_list = []
- for s in l:
- if s[-1] == 'F':
- F_list.append(s)
- elif s[-1] == 'V':
- V_list.append(s)
- elif s[-1] == 'N':
- N_list.append(s)
- elif s[-1] == 'P':
- P_list.append(s)
- new_list = [F_list, V_list, N_list, P_list]
- return new_list
- def remove_empties(fluro_seperated_list):
- '''
- | (2D list) -> 2D list
- |
- | Returns a nested 2D list that contains no empty lists.
- |
- | Example 2D_list_input:
- | [['D19mit91F', 'D14mit95F', 'D9mit182F'], ['D13mit275V', 'D9mit90V'],
- | ['D11mit231N'], []]
- |
- | Example 2D_list_output:
- | [['D19mit91F', 'D14mit95F', 'D9mit182F'], ['D13mit275V', 'D9mit90V'],
- | ['D11mit231N']]
- '''
- list2 = [x for x in fluro_seperated_list if x]
- return list2
- def multiplex_primers(fluro_seperated_list_no_empties):
- '''
- | (2D list) -> 2D list
- |
- | Returns a list where each primer is multiplexed with one other primer of
- | a different fluorescence.
- |
- | Example input_list:
- | [['D19mit91F', 'D14mit95F', 'D9mit182F'], ['D13mit275V', 'D9mit90V'],
- | ['D11mit231N']]
- |
- | Example output_list:
- | [['D19mit91F', 'D13mit275V'], ['D14mit95F', 'D9mit90V'],
- | ['D9mit182F', 'D11mit231N']]
- '''
- answer = []
- new_list = fluro_seperated_list_no_empties
- while len(new_list[0]) > 0 and len(new_list[1]) > 0:
- answer.append([new_list[0][0], new_list[1][0]])
- del new_list[0][0], new_list[1][0]
- new_list = remove_empties(new_list) #remove empty lists every iteration
- if len(new_list) == 0: #if length is 0, our work is done
- break
- if len(new_list) == 1: #if length is 1, we need to append remaining numbers as lists with length 1
- for i in new_list[0]:
- answer.append([i])
- break
- return answer
- def write_extra_primer_layout(list_of_multiplexed_primers, to_file):
- '''
- | (2D list) -> file
- |
- | Returns a file that contains primers in the lists in plate format. A
- | number in the file counts up to 12 and restarts for the next plate.
- |
- | Example input_list
- | [['D19mit91F', 'D13mit275V'], ['D14mit95F', 'D9mit90V'],
- | ['D9mit182F', 'D11mit231N'], ['D19mit91F', 'D13mit275V'],
- | ['D14mit95F', 'D9mit90V'], ['D9mit182F', 'D11mit231N'],
- | ['D19mit91F', 'D13mit275V'], ['D14mit95F', 'D9mit90V'],
- | ['D9mit182F', 'D11mit231N'],['D19mit91F', 'D13mit275V'],
- | ['D14mit95F', 'D9mit90V'], ['D9mit182F', 'D11mit231N'],
- | ['D19mit91F', 'D13mit275V'], ['D14mit95F', 'D9mit90V'],
- | ['D9mit182F', 'D11mit231N'], ['D19mit91F', 'D13mit275V'],
- | ['D14mit95F', 'D9mit90V'], ['D9mit182F', 'D11mit231N'],
- | ['D19mit91F', 'D13mit275V'], ['D14mit95F', 'D9mit90V'],
- | ['D9mit182F', 'D11mit231N']]
- |
- | Example out_put file:
- | 1 D19mit91F D13mit275V
- | 2 D14mit95F D9mit90V
- | 3 D9mit182F D11mit231N
- | 4 D19mit91F D13mit275V
- | 5 D14mit95F D9mit90V
- | 6 D9mit182F D11mit231N
- | 7 D19mit91F D13mit275V
- | 8 D14mit95F D9mit90V
- | 9 D9mit182F D11mit231N
- | 10 D19mit91F D13mit275V
- | 11 D14mit95F D9mit90V
- | 12 D9mit182F D11mit231N
- |
- | 1 D19mit91F D13mit275V
- | 2 D14mit95F D9mit90V
- | 3 D9mit182F D11mit231N
- | 4 D19mit91F D13mit275V
- | 5 D14mit95F D9mit90V
- | 6 D9mit182F D11mit231N
- | 7 D19mit91F D13mit275V
- | 8 D14mit95F D9mit90V
- | 9 D9mit182F D11mit231N
- '''
- in_list = list_of_multiplexed_primers
- with open(to_file, 'w') as tf:
- num = 1
- for i in in_list:
- if num == 12:
- tf.write(str(num)+ ' ' +(' '.join(i)) + ' ' +'\n\n')
- num = 1
- else:
- tf.write(str(num)+ ' ' +(' '.join(i)) + ' ' +'\n')
- num = num + 1
Advertisement
Add Comment
Please, Sign In to add comment