예제 #1
0
def test_compare_suffixes():
    assert compare_suffixes('AAXAA', 'TTTTTTTAAAAA') == (0, 5, 7, 12, 4, 1)
    assert compare_suffixes('AANAA', 'TTTTTTTAACAA',
                            ALLOW_WILDCARD_SEQ1) == (0, 5, 7, 12, 5, 0)
    assert compare_suffixes('AANAA', 'TTTTTTTAACAA',
                            ALLOW_WILDCARD_SEQ1) == (0, 5, 7, 12, 5, 0)
    assert compare_suffixes('AAAAAX', 'TTTTTTTAAAAA') == (0, 6, 6, 12, 4, 2)
예제 #2
0
def test_compare_suffixes():
    assert compare_suffixes('AAXAA', 'TTTTTTTAAAAA') == (0, 5, 7, 12, 4, 1)
    assert compare_suffixes('AANAA', 'TTTTTTTAACAA',
                            wildcard_ref=True) == (0, 5, 7, 12, 5, 0)
    assert compare_suffixes('AANAA', 'TTTTTTTAACAA',
                            wildcard_ref=True) == (0, 5, 7, 12, 5, 0)
    assert compare_suffixes('AAAAAX', 'TTTTTTTAAAAA') == (0, 6, 6, 12, 4, 2)
예제 #3
0
	def match_to(self, read, match_class=Match):
		"""
		Attempt to match this adapter to the given read.

		Return a Match instance if a match was found;
		return None if no match was found given the matching criteria (minimum
		overlap length, maximum error rate).
		"""
		read_seq = read.sequence.upper()  # temporary copy
		pos = -1

		# try to find an exact match first unless wildcards are allowed
		if not self.adapter_wildcards:
			if self.where == PREFIX:
				pos = 0 if read_seq.startswith(self.sequence) else -1
			elif self.where == SUFFIX:
				pos = (len(read_seq) - len(self.sequence)) if read_seq.endswith(self.sequence) else -1
			elif self.where == BACK or self.where == FRONT:
				pos = read_seq.find(self.sequence)
			# TODO BACK_NOT_INTERNAL, FRONT_NOT_INTERNAL
		if pos >= 0:
			match_args = (
				0, len(self.sequence), pos, pos + len(self.sequence),
				len(self.sequence), 0)
		else:
			# try approximate matching
			if not self.indels and self.where in (PREFIX, SUFFIX):
				if self.where == PREFIX:
					alignment = align.compare_prefixes(self.sequence, read_seq,
						wildcard_ref=self.adapter_wildcards, wildcard_query=self.read_wildcards)
				else:
					alignment = align.compare_suffixes(self.sequence, read_seq,
						wildcard_ref=self.adapter_wildcards, wildcard_query=self.read_wildcards)
				astart, astop, rstart, rstop, matches, errors = alignment
				if astop - astart >= self.min_overlap and errors / (astop - astart) <= self.max_error_rate:
					match_args = alignment
				else:
					match_args = None
			else:
				alignment = self.aligner.locate(read_seq)
				if self._debug:
					print(self.aligner.dpmatrix)  # pragma: no cover
				if alignment is None:
					match_args = None
				else:
					astart, astop, rstart, rstop, matches, errors = alignment
					match_args = (astart, astop, rstart, rstop, matches, errors)

		if match_args is None:
			return None
		if self.remove == 'auto':
			# guess: if alignment starts at pos 0, it’s a 5' adapter
			remove_before = match_args[2] == 0  # index 2 is rstart
		else:
			remove_before = self.remove == 'prefix'
		match = match_class(*match_args, remove_before=remove_before, adapter=self, read=read)

		assert match.length > 0 and match.errors / match.length <= self.max_error_rate, match
		assert match.length >= self.min_overlap
		return match
예제 #4
0
    def match_to(self, read):
        """
		Try to match this adapter to the given read and return an AdapterMatch instance.

		Return None if the minimum overlap length is not met or the error rate is too high.
		"""
        read_seq = read.sequence.upper()
        pos = -1
        # try to find an exact match first unless wildcards are allowed
        if not self.adapter_wildcards:
            if self.where == PREFIX:
                pos = 0 if read_seq.startswith(self.sequence) else -1
            elif self.where == SUFFIX:
                pos = (len(read_seq) -
                       len(self.sequence)) if read_seq.endswith(
                           self.sequence) else -1
            else:
                pos = read_seq.find(self.sequence)
        if pos >= 0:
            match = AdapterMatch(0, len(self.sequence),
                                 pos, pos + len(self.sequence),
                                 len(self.sequence), 0, self._front_flag, self,
                                 read)
        else:
            # try approximate matching
            if not self.indels and self.where in (PREFIX, SUFFIX):
                if self.where == PREFIX:
                    alignment = align.compare_prefixes(self.sequence, read_seq,
                                                       self.wildcard_flags)
                else:
                    alignment = align.compare_suffixes(self.sequence, read_seq,
                                                       self.wildcard_flags)
                astart, astop, rstart, rstop, matches, errors = alignment
                if astop - astart >= self.min_overlap and errors / (
                        astop - astart) <= self.max_error_rate:
                    match = AdapterMatch(*(alignment +
                                           (self._front_flag, self, read)))
                else:
                    match = None
            else:
                alignment = self.aligner.locate(read_seq)
                if self.debug:
                    print(self.aligner.dpmatrix)
                if alignment is None:
                    match = None
                else:
                    astart, astop, rstart, rstop, matches, errors = alignment
                    match = AdapterMatch(astart, astop, rstart, rstop, matches,
                                         errors, self._front_flag, self, read)

        if match is None:
            return None
        assert match.length > 0 and match.errors / match.length <= self.max_error_rate, match
        assert match.length >= self.min_overlap
        return match
예제 #5
0
    def match(self, read):
        """
		Try to match this adapter to the given read and return an AdapterMatch instance.

		Return None if the minimum overlap length is not met or the error rate is too high.
		"""
        read_seq = read.sequence.upper()
        pos = -1
        # try to find an exact match first unless wildcards are allowed
        if not self.adapter_wildcards:
            if self.where == PREFIX:
                pos = 0 if read_seq.startswith(self.sequence) else -1
            elif self.where == SUFFIX:
                pos = (len(read_seq) - len(self.sequence)) if read_seq.endswith(self.sequence) else -1
            else:
                pos = read_seq.find(self.sequence)
        if pos >= 0:
            match = AdapterMatch(
                0,
                len(self.sequence),
                pos,
                pos + len(self.sequence),
                len(self.sequence),
                0,
                self._front_flag,
                self,
                read,
            )
        else:
            # try approximate matching
            if not self.indels:
                assert self.where in (PREFIX, SUFFIX)
                if self.where == PREFIX:
                    alignment = align.compare_prefixes(self.sequence, read_seq, self.wildcard_flags)
                else:
                    alignment = align.compare_suffixes(self.sequence, read_seq, self.wildcard_flags)
                astart, astop, rstart, rstop, matches, errors = alignment
                match = AdapterMatch(*(alignment + (self._front_flag, self, read)))
            else:
                alignment = self.aligner.locate(read_seq)
                astart, astop, rstart, rstop, matches, errors = alignment
                length = astop - astart
                if length < self.min_overlap or errors / length > self.max_error_rate:
                    return None
                return AdapterMatch(astart, astop, rstart, rstop, matches, errors, self._front_flag, self, read)

                # TODO Aligner.locate should be modified to allow the following
                # assertion.
                # assert length == 0 or match.errors / length <= self.max_error_rate
        if match.length < self.min_overlap or match.errors / match.length > self.max_error_rate:
            return None
        return match
예제 #6
0
	def match_to(self, read):
		"""
		Attempt to match this adapter to the given read.

		Return an Match instance if a match was found;
		return None if no match was found given the matching criteria (minimum
		overlap length, maximum error rate).
		"""
		read_seq = read.sequence.upper()
		pos = -1
		# try to find an exact match first unless wildcards are allowed
		if not self.adapter_wildcards:
			if self.where == PREFIX:
				pos = 0 if read_seq.startswith(self.sequence) else -1
			elif self.where == SUFFIX:
				pos = (len(read_seq) - len(self.sequence)) if read_seq.endswith(self.sequence) else -1
			else:
				pos = read_seq.find(self.sequence)
		if pos >= 0:
			match = Match(
				0, len(self.sequence), pos, pos + len(self.sequence),
				len(self.sequence), 0, self._front_flag, self, read)
		else:
			# try approximate matching
			if not self.indels and self.where in (PREFIX, SUFFIX):
				if self.where == PREFIX:
					alignment = align.compare_prefixes(self.sequence, read_seq,
						wildcard_ref=self.adapter_wildcards, wildcard_query=self.read_wildcards)
				else:
					alignment = align.compare_suffixes(self.sequence, read_seq,
						wildcard_ref=self.adapter_wildcards, wildcard_query=self.read_wildcards)
				astart, astop, rstart, rstop, matches, errors = alignment
				if astop - astart >= self.min_overlap and errors / (astop - astart) <= self.max_error_rate:
					match = Match(*(alignment + (self._front_flag, self, read)))
				else:
					match = None
			else:
				alignment = self.aligner.locate(read_seq)
				if self.debug:
					print(self.aligner.dpmatrix)  # pragma: no cover
				if alignment is None:
					match = None
				else:
					astart, astop, rstart, rstop, matches, errors = alignment
					match = Match(astart, astop, rstart, rstop, matches, errors, self._front_flag, self, read)

		if match is None:
			return None
		assert match.length > 0 and match.errors / match.length <= self.max_error_rate, match
		assert match.length >= self.min_overlap
		return match
예제 #7
0
def test_compare_suffixes():
	assert compare_suffixes('AAXAA', 'TTTTTTTAAAAA') == (0, 5, 7, 12, 4, 1)
	assert compare_suffixes('AANAA', 'TTTTTTTAACAA', wildcard_ref=True) == (0, 5, 7, 12, 5, 0)
	assert compare_suffixes('AANAA', 'TTTTTTTAACAA', wildcard_ref=True) == (0, 5, 7, 12, 5, 0)
	assert compare_suffixes('AAAAAX', 'TTTTTTTAAAAA') == (0, 6, 6, 12, 4, 2)
예제 #8
0
def test_compare_suffixes():
	assert compare_suffixes('AAXAA', 'TTTTTTTAAAAA') == (0, 5, 7, 12, 4, 1)
	assert compare_suffixes('AANAA', 'TTTTTTTAACAA', ALLOW_WILDCARD_SEQ1) == (0, 5, 7, 12, 5, 0)
	assert compare_suffixes('AANAA', 'TTTTTTTAACAA', ALLOW_WILDCARD_SEQ1) == (0, 5, 7, 12, 5, 0)
	assert compare_suffixes('AAAAAX', 'TTTTTTTAAAAA') == (0, 6, 6, 12, 4, 2)
def test_compare_suffixes():
    assert compare_suffixes("AAXAA", "TTTTTTTAAAAA") == (0, 5, 7, 12, 4, 1)
    assert compare_suffixes("AANAA", "TTTTTTTAACAA", ALLOW_WILDCARD_SEQ1) == (0, 5, 7, 12, 5, 0)
    assert compare_suffixes("AANAA", "TTTTTTTAACAA", ALLOW_WILDCARD_SEQ1) == (0, 5, 7, 12, 5, 0)
    assert compare_suffixes("AAAAAX", "TTTTTTTAAAAA") == (0, 6, 6, 12, 4, 2)
예제 #10
0
파일: adapters.py 프로젝트: carze/cutadapt
	def match_to(self, read):
		"""
		Attempt to match this adapter to the given read.

		Return an Match instance if a match was found;
		return None if no match was found given the matching criteria (minimum
		overlap length, maximum error rate).
		"""
		read_seq = read.sequence.upper()
		pos = -1
		# try to find an exact match first unless wildcards are allowed
		if not self.adapter_wildcards:
			if self.where == PREFIX:
				pos = 0 if read_seq.startswith(self.sequence) else -1
			elif self.where == SUFFIX:
				pos = (len(read_seq) - len(self.sequence)) if read_seq.endswith(self.sequence) else -1
			else:
				pos = read_seq.find(self.sequence)
		if pos >= 0:

			if self.partial_trim > 0:
				match_end = len(self.sequence) - self.partial_trim
				match = Match(
					0, len(self.sequence), pos, match_end,
					len(self.sequence), 0, self._front_flag, self, read)
			else:
				match = Match(
					0, len(self.sequence), pos, pos + len(self.sequence),
					len(self.sequence), 0, self._front_flag, self, read)
		else:
			# try approximate matching
			if not self.indels and self.where in (PREFIX, SUFFIX):
				if self.where == PREFIX:
					alignment = align.compare_prefixes(self.sequence, read_seq,
						wildcard_ref=self.adapter_wildcards, wildcard_query=self.read_wildcards)
				else:
					alignment = align.compare_suffixes(self.sequence, read_seq,
						wildcard_ref=self.adapter_wildcards, wildcard_query=self.read_wildcards)
				astart, astop, rstart, rstop, matches, errors = alignment

				## HACK HERE! Trying to trim off only a partial part of the adapter
				if self.partial_trim > 0:
					rstop = rstop - self.partial_trim
					#alignment = (astart, astop, rstart, rstop, matches, error)

				if astop - astart >= self.min_overlap and errors / (astop - astart) <= self.max_error_rate:
					match = Match(astart, astop, rstart, rstop, matches, errors, self._front_flag, self, read)
					#match = Match(*(alignment + (self._front_flag, self, read)))
				else:
					match = None
			else:
				alignment = self.aligner.locate(read_seq)
				if self.debug:
					print(self.aligner.dpmatrix)  # pragma: no cover
				if alignment is None:
					match = None
				else:
					astart, astop, rstart, rstop, matches, errors = alignment
					
					## HACK HERE! Trying to trim off only a partial part of the adapter
					if self.partial_trim > 0:
						rstop -= self.partial_trim

					match = Match(astart, astop, rstart, rstop, matches, errors, self._front_flag, self, read)

		if match is None:
			return None
		assert match.length > 0 and match.errors / match.length <= self.max_error_rate, match
		assert match.length >= self.min_overlap
		return match