Exemplo n.º 1
0
    def test_get_longest_section():
        'It gets the longest section from a list of sections'

        segments = [(0, 3), (10, 34)]
        assert (10, 34) == get_longest_segment(segments)

        segments = [(0, 3), (10, 13)]
        segment = get_longest_segment(segments)
        assert segment == (0, 3) or segment == (10, 13)
Exemplo n.º 2
0
    def test_get_longest_section():
        'It gets the longest section from a list of sections'

        segments = [(0, 3), (10, 34)]
        assert (10, 34) == get_longest_segment(segments)

        segments = [(0, 3), (10, 13)]
        segment = get_longest_segment(segments)
        assert segment == (0, 3) or segment == (10, 13)
Exemplo n.º 3
0
    def _do_trim(self, seq):
        str_seq = get_str_seq(seq)
        unmasked_segments = get_uppercase_segments(str_seq)
        segment = get_longest_segment(unmasked_segments)
        if segment is not None:
            segments = []
            if segment[0] != 0:
                segments.append((0, segment[0] - 1))
            len_seq = len(str_seq)
            if segment[1] != len_seq - 1:
                segments.append((segment[1] + 1, len_seq - 1))

            _add_trim_segments(segments, seq, kind=OTHER)

        else:
            segments = [(0, len(seq))]
            _add_trim_segments(segments, seq, kind=OTHER)
        return seq
Exemplo n.º 4
0
    def _do_trim(self, seq):
        str_seq = get_str_seq(seq)
        unmasked_segments = get_uppercase_segments(str_seq)
        segment = get_longest_segment(unmasked_segments)
        if segment is not None:
            segments = []
            if segment[0] != 0:
                segments.append((0, segment[0] - 1))
            len_seq = len(str_seq)
            if segment[1] != len_seq - 1:
                segments.append((segment[1] + 1, len_seq - 1))

            _add_trim_segments(segments, seq, kind=OTHER)

        else:
            segments = [(0, len(seq))]
            _add_trim_segments(segments, seq, kind=OTHER)
        return seq
Exemplo n.º 5
0
    def __call__(self, seqs):
        'It trims the masked segments of the seqrecords.'
        trimmed_seqs = []
        for seq in seqs:
            str_seq = get_str_seq(seq)
            unmasked_segments = get_uppercase_segments(str_seq)
            segment = get_longest_segment(unmasked_segments)
            if segment is not None:
                segments = []
                if segment[0] != 0:
                    segments.append((0, segment[0] - 1))
                len_seq = len(str_seq)
                if segment[1] != len_seq - 1:
                    segments.append((segment[1] + 1, len_seq - 1))

                _add_trim_segments(segments, seq, kind=OTHER)
                trimmed_seqs.append(seq)
        return trimmed_seqs
Exemplo n.º 6
0
    def __call__(self, seqrecords):
        'It trims the masked segments of the seqrecords.'
        stats = self._stats
        stats[PROCESSED_PACKETS] += 1
        trimmed_seqs = []
        for seqrecord in seqrecords:
            stats[PROCESSED_SEQS] += 1
            seq = str(seqrecord.seq)
            unmasked_segments = get_uppercase_segments(seq)
            segment = get_longest_segment(unmasked_segments)
            if segment is not None:
                stats[YIELDED_SEQS] += 1
                segments = []
                if segment[0] != 0:
                    segments.append((0, segment[0] - 1))
                len_seq = len(seqrecord)
                if segment[1] != len_seq - 1:
                    segments.append((segment[1] + 1, len_seq - 1))

                _add_trim_segments(segments, seqrecord, kind=OTHER)
                trimmed_seqs.append(seqrecord)
            #trimmed_seqs.append(seqrecord[segment[0]:segment[1] + 1])
        return trimmed_seqs