<jupyter_start><jupyter_text>assemble amplifiers<jupyter_code>new_primary_amplifiers, new_secondary_amplifiers = [], []

for _i in range(6):
    _p_seq_str = amplifier_table['Primary amplifier sequences '][_i]
    _s_seq_str = amplifier_table['Secondary amplifier sequences'][_i]
    
    # 1. extract 1st amplify seq
    _seqs, _cts = np.unique(_p_seq_str.split(' '), return_counts=True)
    _lens = np.array([len(_seq) for _seq in _seqs], dtype=np.int)
    _1st_seq = str(_seqs[np.where((_cts==5) * (_lens>10))[0]][0])
    
    # 2. assemble primary amp seq
    _p_amp_seq = [ str(readout_sites[_i%3].reverse_complement().seq)]
    _p_amp_seq += [_1st_seq]*4
    _p_amp_seq = ' '.join(_p_amp_seq)
    # generate the name
    _p_name = f"{readout_sites[_i%3].id}_4xbit{amplifier_table['Bit'][_i]}_primary"
    # assemble
    _p_amp = SeqRecord(Seq(_p_amp_seq), id=_p_name, description='', name='')
    new_primary_amplifiers.append(_p_amp)
    
    # 3. assemble secondary amp seq
    _s_amp_seq = [str(Seq(_1st_seq).reverse_complement()), 'AA']
    _s_amp_seq += [str(readout_sites[_i%3].seq)]*4
    _s_amp_seq = ' '.join(_s_amp_seq)[:-2]
    # generate the name
    _s_name = f"bit{amplifier_table['Bit'][_i]}rc_4x{readout_sites[_i%3].id}rc_secondary"
    # assemble
    _s_amp = SeqRecord(Seq(_s_amp_seq), id=_s_name, description='', name='')
    new_secondary_amplifiers.append(_s_amp)
        
readout_folder = r'\\10.245.74.212\Chromatin_NAS_2\Libraries\Readouts'
stv_readout_file = os.path.join(readout_folder, 'updated_Stvs.fasta')
ndb_readout_file = os.path.join(readout_folder, 'updated_NDBs.fasta')

kept_primary_amplifiers = library_tools.readouts.Screen_seqs_against_fasta(new_primary_amplifiers, 
                                                                           stv_readout_file)

kept_primary_amplifiers = library_tools.readouts.Screen_seqs_against_fasta(kept_primary_amplifiers, 
                                                                           ndb_readout_file)
kept_secondary_amplifiers = library_tools.readouts.Screen_seqs_against_fasta(new_secondary_amplifiers, 
                                                                           stv_readout_file)

kept_secondary_amplifiers = library_tools.readouts.Screen_seqs_against_fasta(kept_secondary_amplifiers, 
                                                                           ndb_readout_file)
print(new_primary_amplifiers[0].seq[:20].reverse_complement())
print(new_primary_amplifiers[0].seq)
print(new_secondary_amplifiers[0].seq)
kept_secondary_amplifiers[0].id
print(kept_primary_amplifiers[0].seq)
print(kept_secondary_amplifiers[0].seq)
print(readout_sites[0].reverse_complement().seq)
print(readout_sites[0].seq)
# generate csv file to order in IDT
import csv

with open(os.path.join(amplifier_folder, '20210201-_primary_amplifiers-100mer.csv'), 'w') as csvfile:
    csvwriter = csv.writer(csvfile, delimiter=',', lineterminator='\n',
                       quotechar='|', quoting=csv.QUOTE_MINIMAL)
    # write header
    _header = ['Name', 'Sequence', 'Scale', 'Purification']
    csvwriter.writerow(_header)
    # write sequence
    for _amplifier in kept_primary_amplifiers:
        _info = [_amplifier.id, str(_amplifier.seq), '250nm', 'STD']
        csvwriter.writerow(_info)
# generate csv file to order in IDT
import csv

with open(os.path.join(amplifier_folder, '20210201-_secondary_amplifiers_100mer.csv'), 'w') as csvfile:
    csvwriter = csv.writer(csvfile, delimiter=',', lineterminator='\n',
                       quotechar='|', quoting=csv.QUOTE_MINIMAL)
    # write header
    _header = ['Name', 'Sequence', 'Scale', 'Purification']
    csvwriter.writerow(_header)
    # write sequence
    for _amplifier in kept_secondary_amplifiers:
        _info = [_amplifier.id, str(_amplifier.seq), '250nm', 'STD']
        csvwriter.writerow(_info)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1194451579758541, 'fraction_numerical': 0.018237862830721808, 'mean_word_length': 3.470723306544202, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '595138', 'license': 'MIT', 'n_tokens_mistral': 1430, 'n_tokens_neox': 1311, 'n_words': 192, 'path': 'Adaptor_design/20200125-Design_amplifiers_DNA_100mer.ipynb', 'repo_name': 'shiwei23/Chromatin_Analysis_Scripts', 'size': '3893'}