Reverse complement the DNA.

        :returns: A reverse-complemented instance of the current sequence.
        :rtype: coral.DNA
505726
def reverse_complement(self):
        '''

        '''
        copy = self.copy()
        # Note: if sequence is double-stranded, swapping strand is basically
        # (but not entirely) the same thing - gaps affect accuracy.
        copy.top = self.top.reverse_complement()
        copy.bottom = self.bottom.reverse_complement()

        # Remove all features - the reverse complement isn't flip!
        copy.features = []

        return copy
750108
def gene_features(self):
        
        nm, strand = self.gene_name, self.strand
        feats = [(self.chrom, self.start, self.end, nm, strand, 'gene')]
        for feat in ('introns', 'exons', 'utr5', 'utr3', 'cdss'):
            fname = feat[:-1] if feat[-1] == 's' else feat
            res = getattr(self, feat)
            if res is None or all(r is None for r in res): continue
            if not isinstance(res, list): res = [res]
            feats.extend((self.chrom, s, e, nm, strand, fname) for s, e in res)

        tss = self.tss(down=1)
        if tss is not None:
            feats.append((self.chrom, tss[0], tss[1], nm, strand, 'tss'))
            prom = self.promoter()
            feats.append((self.chrom, prom[0], prom[1], nm, strand, 'promoter'))

        return sorted(feats, key=itemgetter(1))
399584
def locate_primers(sequences, forward_primer, reverse_primer,
                   reverse_complement, max_hamming_distance):
    
    forward_loc = None
    reverse_loc = None
    seq_length = None

    # Reverse complement the reverse primer, if appropriate
    if reverse_complement:
        reverse_primer = reverse_primer.reverse_complement()

    forward_aligner = PrimerAligner(forward_primer)
    reverse_aligner = PrimerAligner(reverse_primer)

    for i, sequence in enumerate(sequences):
        if seq_length is None:
            seq_length = len(sequence)
        elif len(sequence) != seq_length:
            raise ValueError(("Sequence Length Heterogeneity: {0} != {1}. "
                              "Is this an alignment?").format(
                                  len(sequence), seq_length))
        index_map = ungap_index_map(sequence.seq)
        if forward_loc is None:
            ham_dist, start, end = forward_aligner.align(sequence.seq.ungap())
            if ham_dist <= max_hamming_distance:
                forward_loc = index_map[start], index_map[end]
                logging.info("Forward in sequence %d: indexes %d to %d", i + 1,
                             *forward_loc)
        if reverse_loc is None:
            ham_dist, start, end = reverse_aligner.align(sequence.seq.ungap())
            if ham_dist <= max_hamming_distance:
                reverse_loc = index_map[start], index_map[end]
                logging.info("Reverse in sequence %d: indexes %d to %d", i + 1,
                             *reverse_loc)
        if forward_loc and reverse_loc:
            # Both found
            # Check order
            if forward_loc[0] > reverse_loc[0]:
                raise PrimerOrderError(forward_loc[0], reverse_loc[0])
            return forward_loc, reverse_loc
        else:
            logging.debug(
                "Sequence %d: %d/2 primers found", i + 1,
                sum(j is not None for j in (forward_loc, reverse_loc)))

    # Did not find either the forward or reverse primer:
    if not forward_loc:
        raise PrimerNotFound(forward_primer)
    else:
        raise PrimerNotFound(reverse_primer)
222479
def generate_complementary_strand(strand1):
        """"""
        rise_adjust = (
            strand1.rise_per_nucleotide * strand1.axis.unit_tangent) * 2
        strand2 = NucleicAcidStrand.from_start_and_end(
            strand1.helix_end - rise_adjust, strand1.helix_start - rise_adjust,
            generate_antisense_sequence(strand1.base_sequence),
            phos_3_prime=strand1.phos_3_prime)
        ad_ang = dihedral(strand1[0]["C1'"]._vector, strand1.axis.start,
                          strand2.axis.start + rise_adjust,
                          strand2[-1]["C1'"]._vector)
        strand2.rotate(
            225.0 + ad_ang, strand2.axis.unit_tangent,
            point=strand2.helix_start)  # 225 is the base adjust
        return strand2
1371184
def _guess_sequence_type_from_string(self, seq):
        ''''''
        # Define expected residues for each sequence type
        aa_chars = ['P','V','L','I','M','F','Y','W','H','K','R','Q','N','E','D','S','X','*']
        aas = set(itertools.chain(aa_chars, [lower(a) for a in aa_chars]))
        na_chars = ['A', 'T', 'G', 'C', 'N', 'U']
        nas = set(itertools.chain(na_chars, [lower(a) for a in na_chars]))

        num_nucleotide = 0
        num_protein = 0
        count = 0
        for residue in seq:
            if residue in nas:
                num_nucleotide += 1
            elif residue in aas:
                num_protein += 1
            else:
                raise Exception('Encountered unexpected character when attempting to guess sequence type: %s' % (residue))
            count += 1
            if count >300: break
        if float(num_protein) / (num_protein+num_nucleotide) > 0.1:
            return self.PROTEIN_SEQUENCE_TYPE
        else:
            return self.NUCLEOTIDE_SEQUENCE_TYPE
993018
def reverse_complement_sequences(records):
    
    logging.info('Applying _reverse_complement_sequences generator: '
                 'transforming sequences into reverse complements.')
    for record in records:
        rev_record = SeqRecord(record.seq.reverse_complement(),
                               id=record.id, name=record.name,
                               description=record.description)
        # Copy the annotations over
        _reverse_annotations(record, rev_record)

        yield rev_record
705163
def _retranslate(seq):
        '''
        
        '''
        if len(seq['vdj_nt']) % 3 != 0:
            trunc = len(seq['vdj_nt']) % 3
            seq['vdj_nt'] = seq['vdj_nt'][:-trunc]
        seq['vdj_aa'] = Seq(seq['vdj_nt'], generic_dna).translate()
556405
def toProtocolElement(self):
        
        ret = protocol.ReferenceSet()
        ret.assembly_id = pb.string(self.getAssemblyId())
        ret.description = pb.string(self.getDescription())
        ret.id = self.getId()
        ret.is_derived = self.getIsDerived()
        ret.md5checksum = self.getMd5Checksum()
        if self.getSpecies():
            term = protocol.fromJson(
                json.dumps(self.getSpecies()), protocol.OntologyTerm)
            ret.species.term_id = term.term_id
            ret.species.term = term.term
        ret.source_accessions.extend(self.getSourceAccessions())
        ret.source_uri = pb.string(self.getSourceUri())
        ret.name = self.getLocalId()
        self.serializeAttributes(ret)
        return ret
229669
def InputDNAQuantitySplines(seq_length, n_bases=10, name="DNASmoothPosition", **kwargs):
    
    return Input((seq_length, n_bases), name=name, **kwargs)
711797
def inverse(self):
        
        result = G2Element()
        librelic.g2_neg_abi(byref(result), byref(self))
        return result
368673
def sequence(self, per_exon=False):
        
        db = self.db
        if not per_exon:
            start = self.txStart + 1
            return _sequence(db, self.chrom, start, self.txEnd)
        else:
            # TODO: use same strategy as cds_sequence to reduce # of requests.
            seqs = []
            for start, end in self.exons:
                seqs.append(_sequence(db, self.chrom, start + 1, end))
            return seqs
230638
def gt_bases(self):
        
        result = []
        for a in self.gt_alleles:
            if a is None:
                result.append(None)
            elif a == 0:
                result.append(self.site.REF)
            else:
                result.append(self.site.ALT[a - 1].value)
        return tuple(result)
563233
def codon2aa(codon, trans_table):
    
    return Seq(''.join(codon), IUPAC.ambiguous_dna).translate(table = trans_table)[0]
1338837
def copy(self):
    
    return Sequence(self.name, self.sequenceData, self.start, self.end,
                    self.strand, self.remaining, self.meta_data,
                    self.mutableString)
985470
def reverse_complement(self):
        '''
        
        '''
        if self._reverse_complement is None:
            self._reverse_complement = self._get_reverse_complement()
        return self._reverse_complement
1230907
private static DNASequence getDNASequence(String str) {
		try {
			DNASequence s = new DNASequence(str);
			return s;
		} catch (CompoundNotFoundException e) {

			logger.error("Unexpected error when creating DNASequence ",e);
		}
		return null;
	}
1088885
def subseq(cls, fasta, start=None, stop=None, strand=None):
        
        start = start - 1 if start is not None else 0
        stop = stop if stop is not None else len(fasta)

        if start < 0:
            msg = "start ({0}) must > 0 of `{1}`. Reset to 1".\
                        format(start + 1, fasta.id)
            logging.error(msg)
            start = 0

        if stop > len(fasta):
            msg = "stop ({0}) must be <= length of `{1}` ({2}). Reset to {2}.".\
                        format(stop, fasta.id, len(fasta))
            logging.error(msg)
            stop = len(fasta)

        seq = fasta.seq[start:stop]

        if strand in (-1, '-1', '-'):
            seq = seq.reverse_complement()

        return seq