def primer_process(options, session_dir, fcdict, db, oligos):
    '''Primer Process'''
    #options.processor = int(options.processor)
    oligo_pos = []
    oligo_id_list = []
    #t1 = time.time()
    for oligo in oligos:
        primer_seq = oligo['seq']
        oligo_id_list.append(oligo['id'])

        #mer = primer_seq[-options.k:]
        mer = primer_seq[-options.k_value:]
        mer_id = chilli.DNA2int(mer)

        # p for plus strand, m for minus strand
        p_pos_list, m_pos_list = get_position(options, mer_id, db)

        oligo_pos.append({
            'p_list' : p_pos_list,
            'm_list' : m_pos_list,
        })

    #t2 = time.time()
    #cost = t2 - t1
    #print cost

    product = []
    binding_range = []
    binding_primer = []
    for i in xrange(len(oligos)):
        p_list = oligo_pos[i]['p_list']
        p_oligo_length = oligos[i]['size']
        for k in xrange(len(oligos)):
            m_list = oligo_pos[k]['m_list']
            m_oligo_length = oligos[k]['size']

            for j in p_list.iterkeys():
                hid = str(j) # Because the database has been re-formated
                try:
                    p_pos = p_list[j]
                    m_pos = m_list[j]
                except:
                    continue

                for p in p_pos:
                    left = get_pos_range(p, m_pos)
                    for pos_index in xrange(left, len(m_pos)):
			f3_pos = p+1
			r3_pos = m_pos[pos_index]

                        # The amplicon size <= p.len + m.len
			if f3_pos >= r3_pos:
			    continue

                        product_size = p_oligo_length + m_pos[pos_index] - p + m_oligo_length - 1

                        if product_size < options.size_start:
                            continue
                        if product_size > options.size_stop:
                            break

                        p_start = p - p_oligo_length + 1
                        if p_start < 0:
                            p_start = 0

                        m_stop = r3_pos + m_oligo_length
                        if m_stop > fcdict[hid]['size']:
                            m_stop = fcdict[hid]['size'] 

                        binding_range.append('%s:%s-%s' % (hid, p_start, p + 1))
                        # Reverse: Correction for reverse
                        binding_range.append('%s:%s-%s' % (hid, r3_pos, m_stop))

                        amp = {
                            'hid' : hid,
                            'pid' : oligos[i]['id'],
                            'mid' : oligos[k]['id'],
                            'plen' : p_oligo_length,
                            'mlen' : m_oligo_length,
                            'pseq' : oligos[i]['seq'],
                            'mseq' : Seq.rev_com(oligos[k]['seq']),
                            'size' : product_size,
                            'f3_pos' : f3_pos,
                            'r3_pos' : r3_pos,
                        }

                        product.append(amp)

    return product, binding_range
Example #2
0
def primer_process(options, session_dir, fcdict, db, oligos):
    '''Primer Process'''
    #options.processor = int(options.processor)
    oligo_pos = []
    oligo_id_list = []
    #t1 = time.time()
    for oligo in oligos:
        primer_seq = oligo['seq']
        oligo_id_list.append(oligo['id'])

        #mer = primer_seq[-options.k:]
        mer = primer_seq[-options.k_value:]
        mer_id = chilli.DNA2int(mer)

        # p for plus strand, m for minus strand
        p_pos_list, m_pos_list = get_position(options, mer_id, db)

        oligo_pos.append({
            'p_list': p_pos_list,
            'm_list': m_pos_list,
        })

    #t2 = time.time()
    #cost = t2 - t1
    #print cost

    product = []
    binding_range = []
    binding_primer = []
    for i in xrange(len(oligos)):
        p_list = oligo_pos[i]['p_list']
        p_oligo_length = oligos[i]['size']
        for k in xrange(len(oligos)):
            m_list = oligo_pos[k]['m_list']
            m_oligo_length = oligos[k]['size']

            for j in p_list.iterkeys():
                hid = str(j)  # Because the database has been re-formated
                try:
                    p_pos = p_list[j]
                    m_pos = m_list[j]
                except:
                    continue

                for p in p_pos:
                    left = get_pos_range(p, m_pos)
                    for pos_index in xrange(left, len(m_pos)):
                        f3_pos = p + 1
                        r3_pos = m_pos[pos_index]

                        # The amplicon size <= p.len + m.len
                        if f3_pos >= r3_pos:
                            continue

                        product_size = p_oligo_length + m_pos[
                            pos_index] - p + m_oligo_length - 1

                        if product_size < options.size_start:
                            continue
                        if product_size > options.size_stop:
                            break

                        p_start = p - p_oligo_length + 1
                        if p_start < 0:
                            p_start = 0

                        m_stop = r3_pos + m_oligo_length
                        if m_stop > fcdict[hid]['size']:
                            m_stop = fcdict[hid]['size']

                        binding_range.append('%s:%s-%s' %
                                             (hid, p_start, p + 1))
                        # Reverse: Correction for reverse
                        binding_range.append('%s:%s-%s' %
                                             (hid, r3_pos, m_stop))

                        amp = {
                            'hid': hid,
                            'pid': oligos[i]['id'],
                            'mid': oligos[k]['id'],
                            'plen': p_oligo_length,
                            'mlen': m_oligo_length,
                            'pseq': oligos[i]['seq'],
                            'mseq': Seq.rev_com(oligos[k]['seq']),
                            'size': product_size,
                            'f3_pos': f3_pos,
                            'r3_pos': r3_pos,
                        }

                        product.append(amp)

    return product, binding_range