Exemplo n.º 1
0
 def get_empty_score_arrays(self, n_states, dp_options):
     shape = self.get_score_arrays_shape() + (n_states,)
     mantissas = numpy.zeros(shape, float)
     if dp_options.use_logs:
         mantissas[:] = numpy.log(0.0)
     if dp_options.use_scaling:
         exponents = numpy.ones(shape, int) * -10000
     else:
         exponents = None
     return (
         ascontiguousarray(mantissas, dtype="float64"),
         ascontiguousarray(exponents, dtype="int64"),
     )
Exemplo n.º 2
0
 def _as_combined_array(self):
     # POG in a format suitable for Pyrex code, two arrays
     # preds here means predecessor
     pred = []
     offsets = []
     for pre in self:
         offsets.append(len(pred))
         pred.extend(pre)
     offsets.append(len(pred))
     # provides the paths leading to a point (predecessors), and offsets
     # records index positions fdor each point (graph node)
     return (
         ascontiguousarray(pred, dtype="int64"),
         ascontiguousarray(offsets, dtype="int64"),
     )
Exemplo n.º 3
0
    def __init__(self, alignable1, alignable2, backward=False):
        alignables = [alignable1, alignable2]
        assert alignable1.alphabet == alignable2.alphabet
        self.alphabet = alignable1.alphabet

        for alignable in alignables:
            assert isinstance(alignable, _Alignable), type(alignable)
            if not isinstance(alignable, AlignableSeq):
                some_pogs = True
                break
        else:
            some_pogs = False

        if some_pogs and align_module is not None:
            aligner = align_module.calc_rows
        elif (not some_pogs) and seq_align_module is not None:
            aligner = seq_align_module.calc_rows
        else:
            aligner = py_calc_rows

        self.both_seqs = not some_pogs
        self.aligner = aligner

        if backward:
            alignables = [a.backward() for a in alignables]

        self.children = [alignable1, alignable2] = alignables
        self.max_preds = [alignable.max_preds for alignable in alignables]
        self.pointer_encoding = PointerEncoding(*self.max_preds)

        self.size = [len(alignable1), len(alignable2)]
        self.uniq_size = [len(alignable1.plh), len(alignable2.plh)]
        self.plan = ascontiguousarray(
            alignable1.get_row_assignment_plan(), dtype="int64"
        )
        self.x_index = ascontiguousarray(alignable1.index, dtype="int64")
        self.y_index = ascontiguousarray(alignable2.index, dtype="int64")
Exemplo n.º 4
0
    def calc_rows(
        self,
        i_low,
        i_high,
        j_low,
        j_high,
        state_directions,
        T,
        scores,
        rows,
        track,
        track_encoding,
        viterbi,
        **kw,
    ):
        (match_scores, (xscores, yscores)) = scores
        match_scores = ascontiguousarray(match_scores, dtype="float64")
        xscores = ascontiguousarray(xscores, dtype="float64")
        yscores = ascontiguousarray(yscores, dtype="float64")

        track_enc = ascontiguousarray(
            track_encoding and track_encoding.positions, dtype="int64"
        )

        (
            i_sources,
            i_sources_offsets,
            j_sources,
            j_sources_offsets,
        ) = _as_combined_arrays(self.children)

        state_directions = ascontiguousarray(state_directions, dtype="int64")
        T = ascontiguousarray(T, dtype="float64")
        track = ascontiguousarray(track, dtype="uint8")

        (mantissas, exponents) = rows

        mantissa = 0.0
        if kw["use_scaling"]:
            mantissa = numpy.log(0.0)

        return self.aligner(
            self.plan,
            self.x_index,
            self.y_index,
            i_low,
            i_high,
            j_low,
            j_high,
            i_sources,
            i_sources_offsets,
            j_sources,
            j_sources_offsets,
            state_directions,
            T,
            xscores,
            yscores,
            match_scores,
            mantissas,
            mantissa,
            exponents,
            track,
            track_enc,
            viterbi,
            **kw,
        )