Reverses and (if possible) complements the Sequence so as to represent
the reverse strand (if one exists). Also does checking to see if the
location we are on is on the reverse strand or not.
343362
@SuppressWarnings("unchecked")
	protected <C extends Compound> Sequence<C> reverseSequence(Sequence<C> sequence) {
		if(getStrand() != Strand.NEGATIVE) {
			return sequence;
		}

		Sequence<C> reversed = new ReversedSequenceView<C>(sequence);
		// "safe" operation as we have tried to check this
		if(canComplement(sequence)) {
			Sequence<ComplementCompound> casted = (Sequence<ComplementCompound>) reversed;
			ComplementSequenceView<ComplementCompound> complement =
					new ComplementSequenceView<ComplementCompound>(casted);
			return (Sequence<C>)complement;
		}
		return reversed;
	}
826280
def contain? position
      position = Position.normalize(position)
      return false if position.line < start.line || position.line > ending.line
      return false if position.line == start.line && position.character < start.character
      return false if position.line == ending.line && position.character > ending.character
      true
    end
563042
def _isProtein(self):
        
        last = self.blockCount - 1
        return ((self.tEnd == self.tStarts[last] + 3 * self.blockSizes[last]) \
                and self.strand == "+") or \
                ((self.tStart == self.tSize - (self.tStarts[last] + 3 * self.blockSizes[last])\
                and self.strand == "-"))
13260
def is_downstream_of(self, other):
        
        if self.chrom != other.chrom: return None
        if getattr(other, "strand", None) == "-":
            # other feature is on - strand, so this must have higher start
            return self.end <= other.start
        return self.start >= other.end
894300
public static Location location(int start, int end, Strand strand, int length) {
		int min = Math.min(start, end);
		//if this is true then we have a coord on the +ve strand even though Strand could be negative
		boolean isReverse = (min != start);
		if (isReverse) {
			return new SimpleLocation(
					new SimplePoint(start).reverse(length),
					new SimplePoint(end).reverse(length),
					strand);
		}
		return new SimpleLocation(start, end, strand);
	}
627257
def positions(self, reverse=False):
        """"""
        def Posgen(reverse):
            if reverse:
                lastrootsib = self.last_sibling_position(self.root)
                current = self.last_decendant(lastrootsib)
                while current is not None:
                    yield current
                    current = self.prev_position(current)
            else:
                current = self.root
                while current is not None:
                    yield current
                    current = self.next_position(current)
        return Posgen(reverse)
96722
def reverse(self):
        
        clone = self._clone()
        assert self._ordering, "You need to set an ordering for reverse"
        ordering = []
        for order in self._ordering:
            for k,v in order.items():
                if v=="asc":
                    ordering.append({k: "desc"})
                else:
                    ordering.append({k: "asc"})
        clone._ordering=ordering
        return clone
763663
def reverseComplement(self):
        
        quality = None if self.quality is None else self.quality[::-1]
        sequence = self.sequence.translate(self.COMPLEMENT_TABLE)[::-1]
        return self.__class__(self.id, sequence, quality)
281464
private int checkDictionary(int startPos, int endPos, boolean reverse) {

        // Reset the old break cache first.
        reset();

        // note: code segment below assumes that dictionary chars are in the
        // startPos-endPos range
        // value returned should be next character in sequence
        if ((endPos - startPos) <= 1) {
            return (reverse ? startPos : endPos);
        }

        // Starting from the starting point, scan towards the proposed result,
        // looking for the first dictionary character (which may be the one
        // we're on, if we're starting in the middle of a range).
        fText.setIndex(reverse ? endPos : startPos);
        if (reverse) {
            CharacterIteration.previous32(fText);
        }

        int  rangeStart = startPos;
        int  rangeEnd = endPos;

        int    category;
        int    current;
        DictionaryBreakEngine.DequeI breaks = new DictionaryBreakEngine.DequeI();
        int     foundBreakCount = 0;
        int     c = CharacterIteration.current32(fText);
        category = (short)fRData.fTrie.getCodePointValue(c);

        // Is the character we're starting on a dictionary character? If so, we
        // need to back up to include the entire run; otherwise the results of
        // the break algorithm will differ depending on where we start. Since
        // the result is cached and there is typically a non-dictionary break
        // within a small number of words, there should be little performance impact.
        if ((category & 0x4000) != 0) {
            if (reverse) {
                do {
                    CharacterIteration.next32(fText);
                    c = CharacterIteration.current32(fText);
                    category = (short)fRData.fTrie.getCodePointValue(c);
                } while (c != CharacterIteration.DONE32 && ((category & 0x4000)) != 0);

                // Back up to the last dictionary character
                rangeEnd = fText.getIndex();
                if (c == CharacterIteration.DONE32) {
                    // c = fText->last32();
                    //   TODO:  why was this if needed?
                    c = CharacterIteration.previous32(fText);
                }
                else {
                    c = CharacterIteration.previous32(fText);
                }
            }
            else {
                do {
                    c = CharacterIteration.previous32(fText);
                    category = (short)fRData.fTrie.getCodePointValue(c);
                }
                while (c != CharacterIteration.DONE32 && ((category & 0x4000) != 0));
                // Back up to the last dictionary character
                if (c == CharacterIteration.DONE32) {
                    // c = fText->first32();
                    c = CharacterIteration.current32(fText);
                }
                else {
                    CharacterIteration.next32(fText);
                    c = CharacterIteration.current32(fText);
                }
                rangeStart = fText.getIndex();
            }
            category = (short)fRData.fTrie.getCodePointValue(c);
        }


        // Loop through the text, looking for ranges of dictionary characters.
        // For each span, find the appropriate break engine, and ask it to find
        // any breaks within the span.
        // Note: we always do this in the forward direction, so that the break
        // cache is built in the right order.
        if (reverse) {
            fText.setIndex(rangeStart);
            c = CharacterIteration.current32(fText);
            category = (short)fRData.fTrie.getCodePointValue(c);
        }
        LanguageBreakEngine lbe = null;
        while(true) {
            while((current = fText.getIndex()) < rangeEnd && (category & 0x4000) == 0) {
                CharacterIteration.next32(fText);
                c = CharacterIteration.current32(fText);
                category = (short)fRData.fTrie.getCodePointValue(c);
            }
            if (current >= rangeEnd) {
                break;
            }

            // We now have a dictionary character. Get the appropriate language object
            // to deal with it.
            lbe = getLanguageBreakEngine(c);

            // Ask the language object if there are any breaks. It will leave the text
            // pointer on the other side of its range, ready to search for the next one.
            if (lbe != null) {
                int startingIdx = fText.getIndex();
                foundBreakCount += lbe.findBreaks(fText, rangeStart, rangeEnd, false, fBreakType, breaks);
                assert fText.getIndex() > startingIdx;
            }

            // Reload the loop variables for the next go-round
            c = CharacterIteration.current32(fText);
            category = (short)fRData.fTrie.getCodePointValue(c);
        }

        // If we found breaks, build a new break cache. The first and last entries must
        // be the original starting and ending position.
        if (foundBreakCount > 0) {
            if (foundBreakCount != breaks.size()) {
                System.out.println("oops, foundBreakCount != breaks.size().  LBE = " + lbe.getClass());
            }
            assert foundBreakCount == breaks.size();
            if (startPos < breaks.peekLast()) {
                breaks.offer(startPos);
            }
            if (endPos > breaks.peek()) {
                breaks.push(endPos);
            }

            // TODO: get rid of this array, use results from the deque directly
            fCachedBreakPositions = new int[breaks.size()];

            int i = 0;
            while (breaks.size() > 0) {
                fCachedBreakPositions[i++] = breaks.pollLast();
            }

            // If there are breaks, then by definition, we are replacing the original
            // proposed break by one of the breaks we found. Use following() and
            // preceding() to do the work. They should never recurse in this case.
            if (reverse) {
                return preceding(endPos);
            }
            else {
                return following(startPos);
            }
        }

        // If we get here, there were no language-based breaks. Set the text pointer
        // to the original proposed break.
        fText.setIndex(reverse ? startPos : endPos);
        return (reverse ? startPos : endPos);

        }
483937
def is_upstream_of(self, other):
        
        if self.chrom != other.chrom: return None
        if getattr(other, "strand", None) == "+":
            return self.end <= other.start
        # other feature is on - strand, so this must have higher start
        return self.start >= other.end
490367
def reverse_compl_with_name(old_seq):
    """"""
    new_seq = old_seq.reverse_complement()
    new_seq.id = old_seq.id
    new_seq.description = old_seq.description
    return new_seq
290242
def _reverse(self):
        
        o = self.copy()
        # Clear ok reversed flag
        o._reversed = not o._reversed

        if o.bits == 8:
            # No need for reversing
            return o.copy()

        if o.is_top:
            # A TOP is still a TOP after reversing
            si = o.copy()
            return si

        else:
            if not o.is_integer:
                # We really don't want to do that... but well, sometimes it just happens...
                logger.warning('Reversing a real strided-interval %s is bad', self)

            # Reversing an integer is easy
            rounded_bits = ((o.bits + 7) // 8) * 8
            list_bytes = [ ]
            si = None

            for i in xrange(0, rounded_bits, 8):
                b = o._unrev_extract(min(i + 7, o.bits - 1), i)
                list_bytes.append(b)

            for b in list_bytes:
                si = b if si is None else si.concat(b)
            si.uninitialized = self.uninitialized
            si._reversed = o._reversed
            return si
985470
def reverse_complement(self):
        '''
        
        '''
        if self._reverse_complement is None:
            self._reverse_complement = self._get_reverse_complement()
        return self._reverse_complement
1146431
def checkseq(sequence: str=None,  code="ATGC") -> bool:
    
    for base in sequence:
        if base not in code:
            return False
    return True
118065
@SuppressWarnings({ "unchecked" })
	public static <C extends Compound> SequenceView<C> inverse(Sequence<C> sequence) {
		SequenceView<C> reverse = new ReversedSequenceView<C>(sequence);
		if(sequence.getCompoundSet().isComplementable()) {
			return new ComplementSequenceView(reverse);
		}
		return reverse;
	}
261914
public boolean isRefInverse(Reference ref) {
		if (ref.isInverse()) {
			return true;
		}
		if (!ref.isInverse() && (ref.getOpposite() != null) && ref.getOpposite().isInverse()) {
			return false;
		}
		if (ref.getOpposite() == null) {
			return false;
		}
		// inverse not defined on any side, use this algorithm
		String name1 = ref.getTo().getName();
		String name2 = ref.getFrom().getName();

		// use a well defined algorithm, like alphabetic order
		// A -> B inverse=false
		// B -> A inverse= true
		return (name1.compareTo(name2) < 0);
	}
1060603
public ComparatorChain<E> addComparator(final Comparator<E> comparator, final boolean reverse) {
		checkLocked();

		chain.add(comparator);
		if (reverse == true) {
			orderingBits.set(chain.size() - 1);
		}
		return this;
	}