Exemplo n.º 1
0
def user_defined_exons(tmp_sg, line):
    chr, strand = utils.get_chr(
        line[utils.TARGET]), line[utils.TARGET][0]  # get chr and strand
    upstream_exon = utils.get_pos(
        line[utils.UPSTREAM_EXON])  # get user-defined flanking exons
    downstream_exon = utils.get_pos(line[utils.DOWNSTREAM_EXON])
    first_primer, second_primer = utils.get_primer_coordinates(
        line[utils.PRIMER_COORD])

    # get possible exons for primer amplification
    tmp = sorted(tmp_sg.get_graph().nodes(), key=lambda x: (x[0], x[1]))
    first_ex = utils.find_first_exon(first_primer, tmp)
    last_ex = utils.find_last_exon(second_primer, tmp)
    my_exons = tmp[first_ex:last_ex + 1]
    # if tmp_sg.strand == '+':
    #     my_exons = tmp[tmp.index(upstream_exon):tmp.index(downstream_exon) + 1]
    # else:
    #     my_exons = tmp[tmp.index(downstream_exon):tmp.index(upstream_exon) + 1]

    # Use correct tx's and estimate counts/psi
    all_paths = algs.AllPaths(
        tmp_sg,
        my_exons,
        utils.get_pos(line[utils.TARGET]),  # tuple (start, end)
        chr=chr,
        strand=strand)
    # all_paths.trim_tx_paths()
    fexon = upstream_exon if strand == "+" else downstream_exon
    lexon = downstream_exon if strand == "+" else upstream_exon
    all_paths.trim_tx_paths_using_primers(first_primer, second_primer, fexon,
                                          lexon)
    all_paths.set_all_path_coordinates()
    paths, counts = all_paths.estimate_counts()  # run EM algorithm
    return paths, counts
Exemplo n.º 2
0
def user_defined_exons(tmp_sg, line):
    chr, strand = utils.get_chr(line[utils.TARGET]), line[utils.TARGET][0]  # get chr and strand
    upstream_exon = utils.get_pos(line[utils.UPSTREAM_EXON])  # get user-defined flanking exons
    downstream_exon = utils.get_pos(line[utils.DOWNSTREAM_EXON])
    first_primer, second_primer = utils.get_primer_coordinates(line[utils.PRIMER_COORD])

    # get possible exons for primer amplification
    tmp = sorted(tmp_sg.get_graph().nodes(), key=lambda x: (x[0], x[1]))
    first_ex = utils.find_first_exon(first_primer, tmp)
    last_ex = utils.find_last_exon(second_primer, tmp)
    my_exons = tmp[first_ex:last_ex + 1]
    # if tmp_sg.strand == '+':
    #     my_exons = tmp[tmp.index(upstream_exon):tmp.index(downstream_exon) + 1]
    # else:
    #     my_exons = tmp[tmp.index(downstream_exon):tmp.index(upstream_exon) + 1]

    # Use correct tx's and estimate counts/psi
    all_paths = algs.AllPaths(tmp_sg,
                              my_exons,
                              utils.get_pos(line[utils.TARGET]),  # tuple (start, end)
                              chr=chr,
                              strand=strand)
    # all_paths.trim_tx_paths()
    fexon = upstream_exon if strand == "+" else downstream_exon
    lexon = downstream_exon if strand == "+" else upstream_exon
    all_paths.trim_tx_paths_using_primers(first_primer, second_primer, fexon, lexon)
    all_paths.set_all_path_coordinates()
    paths, counts = all_paths.estimate_counts()  # run EM algorithm
    return paths, counts
Exemplo n.º 3
0
    def trim_tx_paths_using_primers(self, first_primer, second_primer,
                                    first_exon, second_exon):
        """
        Get rid of all transcripts which do not contain both the first
        and second primer. This method may keep transcripts that do not
        contain the exact user defined flanking exons.
        """
        self.component = sorted(self.component, key=lambda x:
                                (x[0], x[1]))  # make sure it is sorted

        # trim tx_paths to only contain paths within component_subgraph
        tmp = set()
        for p in self.tx_paths:
            first_ex = utils.find_first_exon(first_primer, p)
            last_ex = utils.find_last_exon(second_primer, p)
            if first_ex is not None and last_ex is not None:
                tmp_path = p[first_ex:last_ex + 1]
                if tmp_path[0][0] < first_exon[0]:
                    tmp_path[0] = (first_exon[0], tmp_path[0][1]
                                   )  # don't be before user-defined exon
                if tmp_path[-1][1] > second_exon[1]:
                    tmp_path[-1] = (tmp_path[-1][0], second_exon[1]
                                    )  # don't be after user-defined exon
                tmp.add(tuple(tmp_path))  # make sure no redundancies
        # self.tx_paths = sorted(list(tmp), key=lambda x: (x[0], x[1]))
        self.tx_paths = list(tmp)
Exemplo n.º 4
0
    def trim_tx_paths_using_primers(self, first_primer, second_primer, first_exon, second_exon):
        """
        Get rid of all transcripts which do not contain both the first
        and second primer. This method may keep transcripts that do not
        contain the exact user defined flanking exons.
        """
        self.component = sorted(self.component, key=lambda x: (x[0], x[1]))  # make sure it is sorted

        # trim tx_paths to only contain paths within component_subgraph
        tmp = set()
        for p in self.tx_paths:
            first_ex = utils.find_first_exon(first_primer, p)
            last_ex = utils.find_last_exon(second_primer, p)
            if first_ex is not None and last_ex is not None:
                tmp_path = p[first_ex:last_ex+1]
                if tmp_path[0][0] < first_exon[0]:
                    tmp_path[0] = (first_exon[0], tmp_path[0][1])  # don't be before user-defined exon
                if tmp_path[-1][1] > second_exon[1]:
                    tmp_path[-1] = (tmp_path[-1][0], second_exon[1])  # don't be after user-defined exon
                tmp.add(tuple(tmp_path))  # make sure no redundancies
        # self.tx_paths = sorted(list(tmp), key=lambda x: (x[0], x[1]))
        self.tx_paths = list(tmp)