Return true if the given codon overlaps with a bad sequence.
490109
def problem_with_codon(codon_index, codon_list, bad_seqs):
    

    base_1 = 3 * codon_index
    base_3 = 3 * codon_index + 2

    gene_seq = ''.join(codon_list)

    for bad_seq in bad_seqs:
        problem = bad_seq.search(gene_seq)
        if problem and problem.start() < base_3 and problem.end() > base_1:
            return True

    return False
522319
def overlapping(self, other):
        """"""
        return (
            other.start in self.ref_range) or (
            self.start in other.ref_range)
640976
def _is_subsequence_of(self, sub, sup):
        
        return bool(re.search(".*".join(sub), sup))
1067266
static boolean overlapQuantBounds(int amin[], int amax[], int bmin[], int bmax[]) {
        boolean overlap = true;
        overlap = (amin[0] > bmax[0] || amax[0] < bmin[0]) ? false : overlap;
        overlap = (amin[1] > bmax[1] || amax[1] < bmin[1]) ? false : overlap;
        overlap = (amin[2] > bmax[2] || amax[2] < bmin[2]) ? false : overlap;
        return overlap;
    }
791934
def cdna_codon_sequence_after_insertion_frameshift(
        sequence_from_start_codon,
        cds_offset_before_insertion,
        inserted_nucleotides):
    
    # special logic for insertions
    coding_sequence_after_insertion = \
        sequence_from_start_codon[cds_offset_before_insertion + 1:]

    if cds_offset_before_insertion % 3 == 2:
        # insertion happens after last nucleotide in a codon,
        # doesn't disrupt the existing codon from cds_offset-2 to cds_offset
        mutated_codon_index = cds_offset_before_insertion // 3 + 1
        nucleotides_before = ""
    elif cds_offset_before_insertion % 3 == 1:
        # insertion happens after 2nd nucleotide of a codon
        # codon positions:
        #   1) cds_offset - 1
        #   2) cds_offset
        #    <----- Insertsion
        #   3) cds_offset + 1
        mutated_codon_index = cds_offset_before_insertion // 3
        # the first codon in the returned sequence will contain two reference
        # nucleotides before the insertion
        nucleotides_before = sequence_from_start_codon[
            cds_offset_before_insertion - 1:cds_offset_before_insertion + 1]
    elif cds_offset_before_insertion % 3 == 0:
        # insertion happens after 1st nucleotide of a codon
        # codon positions:
        #   1) cds_offset
        #    <----- Insertsion
        #   2) cds_offset + 1
        #   3) cds_offset + 2
        mutated_codon_index = cds_offset_before_insertion // 3
        # the first codon in the returned sequence will contain one reference
        # nucleotide before the insertion
        nucleotides_before = sequence_from_start_codon[cds_offset_before_insertion]
    sequence_from_mutated_codon = (
        nucleotides_before +
        inserted_nucleotides +
        coding_sequence_after_insertion)
    return mutated_codon_index, sequence_from_mutated_codon
288288
def ref_string_matches_ref_sequence(self, ref_sequence):
        ''''''
        # you never know what you're gonna get...
        if self.POS < 0:
            return False

        end_pos = self.ref_end_pos()
        if end_pos >= len(ref_sequence):
            return False

        return self.REF == ref_sequence[self.POS:end_pos + 1]
1180467
def _check_codons(self):
        
        for stop_codon in self.stop_codons:
            if stop_codon in self.codon_table:
                if self.codon_table[stop_codon] != "*":
                    raise ValueError(
                        ("Codon '%s' not found in stop_codons, but codon table "
                         "indicates that it should be") % (stop_codon,))
            else:
                self.codon_table[stop_codon] = "*"

        for start_codon in self.start_codons:
            if start_codon not in self.codon_table:
                raise ValueError(
                    "Start codon '%s' missing from codon table" % (
                        start_codon,))

        for codon, amino_acid in self.codon_table.items():
            if amino_acid == "*" and codon not in self.stop_codons:
                raise ValueError(
                    "Non-stop codon '%s' can't translate to '*'" % (
                        codon,))

        if len(self.codon_table) != 64:
            raise ValueError(
                "Expected 64 codons but found %d in codon table" % (
                    len(self.codon_table,)))
446800
def overlap_size(self,in_genomic_range):
    
    if self.chr != in_genomic_range.chr:
      return 0
    if self.end < in_genomic_range.start:
      return 0
    if in_genomic_range.end < self.start:
      return 0
    if self.start > in_genomic_range.end:
      return 0
    if self.start >= in_genomic_range.start and self.end <= in_genomic_range.end:
      return self.end-self.start+1
    if self.start <= in_genomic_range.start and self.end >= in_genomic_range.end:
      return in_genomic_range.end-in_genomic_range.start+1
    if self.start <= in_genomic_range.start and self.end >= in_genomic_range.start:
      return self.end-in_genomic_range.start+1
    if self.start <= in_genomic_range.end and self.end >= in_genomic_range.end:
      return in_genomic_range.end-self.start+1
    if in_genomic_range.start <= self.start and in_genomic_range.end >= self.start:
      return in_genomic_range.end-self.start+1
    if in_genomic_range.start <= self.end and in_genomic_range.end >= self.end:
      return self.end-in_genomic_range.start+1
    sys.stderr.write("overlap_size: unprogrammed error\n")
    return 0
405654
def overlap(self, query, subject):
        """"""
        if (self.pt_within(query[0], subject) or self.pt_within(query[1], subject) or 
            self.pt_within(subject[0], query) or self.pt_within(subject[1], query)):
            return True

        return False
12299
def map_alignment(self, prot_seq, nucl_seq):
        
        if prot_seq.id != nucl_seq.id:
            logging.warning(
                'ID mismatch: %s != %s. Are the sequences in the same order?',
                prot_seq.id, nucl_seq.id)

        # Ungap nucleotides
        codons = batch(str(nucl_seq.seq.ungap('-')), 3)
        codons = [''.join(i) for i in codons]
        codon_iter = iter(codons)

        ungapped_prot = str(prot_seq.seq).replace('-', '')

        if len(ungapped_prot) != len(codons):
            table = self.translation_table.forward_table
            prot_str = ' '.join(' ' + p + ' ' for p in ungapped_prot)
            codon_str = ' '.join(codons)
            trans_str = ' '.join(' ' + table.get(codon, 'X') + ' '
                                 for codon in codons)
            raise ValueError("""Length of codon sequence ({0}) does not match \
length of protein sequence ({1}) for {2}
Protein:       {3}
Codons:        {4}
Trans. Codons: {5}""".format(len(codons), len(ungapped_prot), nucl_seq.id, prot_str,
                            codon_str, trans_str))

        try:
            nucl_align = ['---' if p == '-' else next(codon_iter)
                          for p in str(prot_seq.seq)]
        except StopIteration:
            assert False  # Should be checked above

        result = SeqRecord(Seq(''.join(nucl_align)), id=nucl_seq.id,
                           description=nucl_seq.description)

        # Validate
        self._validate_translation(prot_seq.seq.upper(), result.seq.upper())

        return result
520271
def check(self, read_tuple_name):
        

        parts = read_tuple_name.split("__")

        if len(parts[0]) != self.prefix_width or len(parts[1]) != self.read_tuple_id_width:
            return False

        segments = parts[2][1:-1].split("),(")
        for segment in segments:
            int_widths = list(map(len, segment.split(",")))
            if self.genome_id_width != int_widths[0]:
                return False
            if self.chr_id_width != int_widths[1]:
                return False
            if self.coor_width != int_widths[3] or self.coor_width != int_widths[4]:
                return False

        return True
600232
private static boolean isSequence(String asg, int dN) {
    int length = asg.length();
    if (length - dN < 3 || asg.charAt(dN + 1) != 'v') {
      return false;
    }
    for (int i = dN + 2; i < length; ++i) {
      if (!Character.isDigit(asg.charAt(i))) {
        return false;
      }
    }
    return true;
  }
880810
def can_overlap(self, contig, strand=None):
        
        return (self.on_contig(contig) and
                (strand is None or self.on_strand(strand)))
997192
def is_sequence(obj):
    """"""
    return isinstance(obj, Sequence) and not (
        isinstance(obj, str) or BinaryClass.is_valid_type(obj))
428132
protected static int findSequence(byte[] sequence, byte[] buffer) {
        int pos = -1;
        for (int i = 0; i < buffer.length - sequence.length + 1; i++) {
            if (buffer[i] == sequence[0] && testRemaining(sequence, buffer, i)) {
                pos = i;
                break;
            }
        }
        return pos;
    }
145612
def overlap(self, other):
        """"""
        if self._start < other.end and self._end > other.start:
            return True
        return False
804724
def translate_codon(codon, aa_pos):
    
    # not handling rare Leucine or Valine starts!
    if aa_pos == 0 and codon in START_CODONS:
        return "M"
    elif codon in STOP_CODONS:
        return "*"
    else:
        return DNA_CODON_TABLE[codon]