Ejemplo n.º 1
0
    def _do_trim(self, seq):
        'It trims the edges of the given seqs.'
        annots = get_annotations(seq)
        if not TRIMMING_RECOMMENDATIONS in annots:
            return seq

        trim_rec = annots[TRIMMING_RECOMMENDATIONS]
        # fixing the trimming recommendations
        if TRIMMING_RECOMMENDATIONS in annots:
            del annots[TRIMMING_RECOMMENDATIONS]

        trim_segments = []
        for trim_kind in TRIMMING_KINDS:
            trim_segments.extend(trim_rec.get(trim_kind, []))

        # masking
        if self.mask:
            seq = _mask_sequence(seq, trim_segments)
        else:
            # trimming
            if trim_segments:
                trim_limits = get_longest_complementary_segment(
                                            trim_segments, get_length(seq))
                if trim_limits is None:
                    # there's no sequence left
                    return None
            else:
                trim_limits = []

            if trim_limits:
                seq = slice_seq(seq, trim_limits[0], trim_limits[1] + 1)

        return seq
Ejemplo n.º 2
0
    def _do_trim(self, seq):
        'It trims the edges of the given seqs.'
        annots = get_annotations(seq)
        if not TRIMMING_RECOMMENDATIONS in annots:
            return seq

        trim_rec = annots[TRIMMING_RECOMMENDATIONS]
        # fixing the trimming recommendations
        if TRIMMING_RECOMMENDATIONS in annots:
            del annots[TRIMMING_RECOMMENDATIONS]

        trim_segments = []
        for trim_kind in TRIMMING_KINDS:
            trim_segments.extend(trim_rec.get(trim_kind, []))

        # masking
        if self.mask:
            seq = _mask_sequence(seq, trim_segments)
        else:
            # trimming
            if trim_segments:
                trim_limits = get_longest_complementary_segment(
                    trim_segments, get_length(seq))
                if trim_limits is None:
                    # there's no sequence left
                    return None
            else:
                trim_limits = []

            if trim_limits:
                seq = slice_seq(seq, trim_limits[0], trim_limits[1] + 1)

        return seq
Ejemplo n.º 3
0
    def __call__(self, seqrecords):
        'It trims the edges of the given seqrecords.'
        stats = self._stats
        stats[PROCESSED_PACKETS] += 1
        mask = self.mask
        processed_seqs = []
        for seqrecord in seqrecords:
            stats[PROCESSED_SEQS] += 1

            if not TRIMMING_RECOMMENDATIONS in seqrecord.annotations:
                processed_seqs.append(copy_seqrecord(seqrecord))
                continue

            trim_rec = seqrecord.annotations[TRIMMING_RECOMMENDATIONS]
            #fixing the trimming recommendations
            if TRIMMING_RECOMMENDATIONS in seqrecord.annotations:
                del seqrecord.annotations[TRIMMING_RECOMMENDATIONS]

            trim_segments = []
            for trim_kind in TRIMMING_KINDS:
                trim_segments.extend(trim_rec.get(trim_kind, []))

            #masking
            if mask:
                seqrecord = _mask_sequence(seqrecord, trim_segments)
            else:
                #trimming
                if trim_segments:
                    trim_limits = get_longest_complementary_segment(
                                                 trim_segments, len(seqrecord))
                    if trim_limits is None:
                        # there's no sequence left
                        continue
                else:
                    trim_limits = []

                if trim_limits:
                    seqrecord = seqrecord[trim_limits[0]:trim_limits[1] + 1]

            processed_seqs.append(seqrecord)

            stats[YIELDED_SEQS] += 1
        return processed_seqs
Ejemplo n.º 4
0
    def __call__(self, seqs):
        'It trims the edges of the given seqs.'
        mask = self.mask
        processed_seqs = []
        for seq in seqs:
            annots = get_annotations(seq)
            if not TRIMMING_RECOMMENDATIONS in annots:
                processed_seqs.append(copy_seq(seq))
                continue

            trim_rec = annots[TRIMMING_RECOMMENDATIONS]
            # fixing the trimming recommendations
            if TRIMMING_RECOMMENDATIONS in annots:
                del annots[TRIMMING_RECOMMENDATIONS]

            trim_segments = []
            for trim_kind in TRIMMING_KINDS:
                trim_segments.extend(trim_rec.get(trim_kind, []))

            # masking
            if mask:
                seq = _mask_sequence(seq, trim_segments)
            else:
                # trimming
                if trim_segments:
                    trim_limits = get_longest_complementary_segment(
                                                trim_segments, get_length(seq))
                    if trim_limits is None:
                        # there's no sequence left
                        continue
                else:
                    trim_limits = []

                if trim_limits:
                    seq = slice_seq(seq, trim_limits[0], trim_limits[1] + 1)

            processed_seqs.append(seq)

        return processed_seqs
Ejemplo n.º 5
0
 def test_get_longest_complementary():
     'It test that we can get the longest complementary segment'
     segments = [(0, 200)]
     result = get_longest_complementary_segment(segments, seq_len=200)
     assert result is None
Ejemplo n.º 6
0
 def test_get_longest_complementary():
     'It test that we can get the longest complementary segment'
     segments = [(0, 200)]
     result = get_longest_complementary_segment(segments, seq_len=200)
     assert result is None