예제 #1
0
def get_activation(sequences, concentrations, params):
    model = nu.Model(material='dna',
                     celsius=params['temperature'],
                     sodium=params['sodium'],
                     magnesium=params['magnesium'])
    # Define strands and sequences
    probeF = nu.Strand(sequences['probeF'], name='probeF')
    probeQ = nu.Strand(sequences['probeQ'], name='probeQ')
    sink = nu.Strand(sequences['sink'], name='sink')
    sinkC = nu.Strand(sequences['sinkC'], name='sinkC')
    non_mut_target = nu.Strand(sequences['non_mut_target'],
                               name='non_mut_target')
    mut_target = nu.Strand(sequences['mut_target'], name='mut_target')
    # Define 3 tubes: one without target (initial), one with mutated target (mut), and one with non-mutated target (non_mut)
    initial_state = nu.Tube(strands={
        probeF: concentrations['probeF'],
        probeQ: concentrations['probeQ'],
        sink: concentrations['sink'],
        sinkC: concentrations['sinkC']
    },
                            complexes=nu.SetSpec(
                                max_size=2,
                                include=[[probeF, probeQ, sink, sinkC]]),
                            name='initial_state')
    mut_state = nu.Tube(strands={
        probeF: concentrations['probeF'],
        probeQ: concentrations['probeQ'],
        sink: concentrations['sink'],
        sinkC: concentrations['sinkC'],
        mut_target: concentrations['mut_target']
    },
                        complexes=nu.SetSpec(
                            max_size=2,
                            include=[[probeF, probeQ, sink, sinkC,
                                      mut_target]]),
                        name='mut_state')
    non_mut_state = nu.Tube(strands={
        probeF: concentrations['probeF'],
        probeQ: concentrations['probeQ'],
        sink: concentrations['sink'],
        sinkC: concentrations['sinkC'],
        non_mut_target: concentrations['non_mut_target']
    },
                            complexes=nu.SetSpec(max_size=2,
                                                 include=[[
                                                     probeF, probeQ, sink,
                                                     sinkC, non_mut_target
                                                 ]]),
                            name='non_mut_state')
    # Compute proportion of probe which is active in each tube
    result = nu.tube_analysis(tubes=[initial_state, mut_state, non_mut_state],
                              compute=['pairs', 'mfe'],
                              model=model)
    initial_activation = parse_nupack_output(result, 'initial_state',
                                             concentrations)
    mut_activation = parse_nupack_output(result, 'mut_state', concentrations)
    non_mut_activation = parse_nupack_output(result, 'non_mut_state',
                                             concentrations)
    return initial_activation, mut_activation, non_mut_activation
예제 #2
0
 def analysis_all(self):
     count = self.len_g1 + self.len_g2
     strands = self.get_strands()
     my_model = Model(material='dna', celsius=self.temp)
     t1 = Tube(strands=strands,
               complexes=SetSpec(max_size=count),
               name='t1')  # complexes defaults to [A, B]
     tube_results = tube_analysis(tubes=[t1], model=my_model)
예제 #3
0
    def get_strand_tube_all(self):
        # 获取试管中只有两条基因片段的所有情况

        strands = {}
        for i in range(1, len(self.oligo) - 1):
            strands[Strand(self.oligo[i][1],
                           name=self.oligo[i][0])] = self.oligo_conc

        strands[Strand(self.oligo[0][1],
                       name=self.oligo[0][0])] = self.primer_conc
        strands[Strand(self.oligo[-1][1],
                       name=self.oligo[-1][0])] = self.primer_conc

        my_model = Model(material='dna', celsius=self.temp)
        t = Tube(strands=strands, complexes=SetSpec(max_size=2),
                 name='t')  # complexes defaults to [A, B]
        tube_results = tube_analysis(tubes=[t], model=my_model)

        all_conc = {}
        for my_complex, conc in tube_results.tubes[
                t].complex_concentrations.items():
            all_conc[my_complex.name] = conc  # 反应后每个试管中DNA的浓度
        all_conc = sorted(all_conc.items(), key=lambda d: d[1],
                          reverse=True)  # 排序

        error = {}
        for key, val in all_conc:
            if key.count('+') == 1 and val > self.first_check:
                tem_split = key[1:-1].split('+')  # # 先去除括号,在根据+分割字符串

                t1 = tem_split[0][1:]
                t2 = tem_split[1][1:]
                # print(t1, t2)
                # print(t1.isdigit(), t2.isdigit())
                if not t1.isdigit() or not t2.isdigit():
                    # 处理含有primer的片段,都是错配的
                    # primer+pirmer, primer+x         ,  x+primer
                    error['{0}, {1}'.format(tem_split[0], tem_split[1])] = val

                elif tem_split[0][0] == tem_split[1][0]:  # 错配
                    # Rx+Rx ; Fx+Fx
                    error['{0}, {1}'.format(tem_split[0], tem_split[1])] = val
                elif tem_split[0][0] == 'F' and int(t1) - int(t2) not in [
                        0, 1
                ]:
                    error['{0}, {1}'.format(tem_split[0], tem_split[1])] = val
                elif tem_split[0][0] == 'R' and int(t1) - int(t2) not in [
                        0, -1
                ]:
                    error['{0}, {1}'.format(tem_split[0], tem_split[1])] = val
            # 判断条件有待改进
            elif val < self.first_check:  #
                break

        print(error)

        return error
예제 #4
0
    def verification_two(self, list1):
        # 验证错配的是否有问题
        set1 = set()
        strands = {}
        for i in range(len(list1)):
            for j in range(len(list1[i])):
                if j == 0:
                    set1.add(list1[i][j])
                    strands[Strand(
                        self.gene_list[list1[i][j] - 1],
                        name="E:{1}:{0}".format(list1[i][j],
                                                i))] = self.c_gene * 2  # 改正浓度
                elif Strand(self.gene_list[list1[i][j] - 1],
                            name=str(list1[i][j])) in strands.keys():
                    strands[Strand(self.gene_list[list1[i][j] - 1],
                                   name=str(list1[i][j]))] = self.c_gene * 2
                else:
                    strands[Strand(self.gene_list[list1[i][j] - 1],
                                   name=str(list1[i][j]))] = self.c_gene

        tube = Tube(strands=strands,
                    complexes=SetSpec(max_size=len(list1)),
                    name="test")
        my_model = Model(material='dna', celsius=self.temp)
        tube_results = tube_analysis(tubes=[tube], model=my_model)
        all_conc = {}
        # print(tube_results)
        # print("____________-")
        for my_complex, conc in tube_results.tubes[
                tube].complex_concentrations.items():
            all_conc[my_complex.name] = conc
            name = my_complex.name[1:-1]
            # if name.count("E") == 2: #
            if name.count("E") == len(list1) and conc > self.second_check:  #
                name_list = name.split("+")
                set_t = set()
                for i in range(len(list1)):
                    set_t.add(name_list[i][2])
                if len(set_t) == len(list1) and set_t == set1:  # 只关注错配的那几条
                    # print(name, conc)
                    return False
                # print(name, conc)

        new_conc = sorted(all_conc.items(), key=lambda d: d[1], reverse=True)
예제 #5
0
    def analysis_two(self):
        my_model = Model(material='dna', celsius=self.temp)  # 温度
        tubes = self.get_strands_tube_tow()  # 得到每个试管中都有两条DNA单链
        tube_results = tube_analysis(tubes=tubes, model=my_model)
        all_conc = {}
        for t in tubes:
            for my_complex, conc in tube_results.tubes[
                    t].complex_concentrations.items():
                all_conc[my_complex.name] = conc  # 反应后每个试管中DNA的浓度

        all_conc = sorted(all_conc.items(), key=lambda d: d[1],
                          reverse=True)  # 排序

        error = {}  # 怀疑是错配的
        # 验证
        for k, v in all_conc:
            if k.count("+") == 1 and v > self.first_check:  # 将浓度换成输入的浓度
                # 根据:分割k, 然后根据名字具有顺序关系,然后确定是不是正确的配对
                tem_split = k.split('+')
                t1 = int(tem_split[0].split(':')[1][1:])  # 单链序号
                t2 = int(tem_split[1].split(':')[1][1:-1])
                if t1 > t2:
                    t1, t2 = t2, t1

                if t2 - t1 - self.len_g1 not in [-1, 0]:  # 错配
                    ste = '{0},{1}'.format(t1, t2)
                    if ste in error and v < error[ste]:
                        continue
                    else:
                        error[ste] = v
            elif v < self.first_check:  #
                break

        # 找出那两个的相邻的放到一起,然后反应,看下最后的结果
        # error_end = []  # 经过校验后还是错配的
        # for enu in error:
        #     str = enu.split(',')
        #     tem_err_list = [self.get_tube(int(str[0])), self.get_tube(int(str[1]))]
        #     if self.verification_two(tem_err_list):
        #         error_end.append(enu)

        tem_info = {}
        for key, val in error.items():
            arr = key.split(',')
            arr = [int(i) for i in arr]

            if arr[0] >= self.len_g1:
                str1 = 'R{0}'.format(arr[0] - self.len_g1)
            else:
                str1 = 'F{0}'.format(arr[0])

            if arr[1] >= self.len_g1:
                str2 = 'R{0}'.format(arr[1] - self.len_g1)
            else:
                str2 = 'F{0}'.format(arr[1])
            tem_info[str1 + ',' + str2] = val
        # print(len(tem_info), tem_info)

        # print("目标{0},list1:{1},list2:{2}".format(self.len1, self.len_g1, self.len_g2))
        # print("出错的{0},{1}".format(len(error), error))
        # print("最终检测还是出错的{0}".format(error_end))
        # print('总数{0}'.format(len(all_conc)))
        return tem_info
예제 #6
0
    def analysis_three(self):
        my_model = Model(material='dna', celsius=self.temp)
        tubes = self.get_strands_tube_three()  # 得到每个试管中都有两条DNA单链
        start = time.time()
        tube_results = tube_analysis(tubes=tubes, model=my_model)
        print("analysis time:{0}".format(time.time() - start))
        all_conc = {}  # 记录结果
        for t in tubes:
            for my_complex, conc in tube_results.tubes[
                    t].complex_concentrations.items():
                all_conc[my_complex.name] = conc  # 反应后每个试管中DNA的浓度
        all_conc = sorted(all_conc.items(), key=lambda d: d[1],
                          reverse=True)  # 排序

        error = {}  # 怀疑是错配的
        k_cou = 0  # 记录浓度大于某个值的

        for k, v in all_conc:
            if k.count("+") == 2 and v > self.first_check:  # 将浓度换成输入的浓度
                k_cou += 1
                # 根据:分割k, 然后根据名字具有顺序关系,然后确定是不是正确的配对
                tem_split = k.split('+')
                t1 = int(tem_split[0].split(':')[1][1:])
                t2 = int(tem_split[1].split(':')[1][1:])
                t3 = int(tem_split[2].split(':')[1][1:-1])
                set_t = {abs(t1 - t2), abs(t1 - t3), abs(t2 - t3)}

                if set_t != {1, self.len_g1, self.len_g1 - 1}:
                    tem_arr = [t1, t2, t3]
                    tem_arr.sort()
                    key = ''
                    for i in tem_arr:
                        if i >= self.len_g1:
                            key = key + 'R{0},'.format(i - self.len_g1)
                        else:
                            key = key + 'F{0},'.format(i)
                    key = key[:-1]
                    if key in error and v < error[key]:
                        continue
                    else:
                        error[key] = v

            elif v < self.first_check:  #
                break

        # second check
        error_end = []  # 经过校验后还是错配的

        # 添加验证
        # print("验证:{0},{1},{2}".format(t1, t2, t3))
        # tem_err_list = self.get_tube(t1)
        # tem_err_list.extend(self.get_tube(t2))
        # tem_err_list.extend(self.get_tube(t3))
        # if self.verification_two(tem_err_list):
        #     error_end.append(k)

        # print("目标:{0},list1:{1},list2:{2}".format(int(self.len1 / 2), self.len_g1, self.len_g2))
        print("出错的:{0},{1}".format(len(error), error))
        # print("最终检测还是出错的{0}".format(error_end))
        # print("浓度大于1e-9数:{0}".format(k_cou))
        # print('总数:{0}'.format(len(all_conc)))
        return error