Produces kmers of the specified size e.g. ATGTGA returns two views which
have ATG TGA

@param <C> Compound to use
@param sequence Sequence to build from
@param kmer Kmer size
@return The list of non-overlapping K-mers
184908
public static <C extends Compound> List<SequenceView<C>> nonOverlappingKmers(Sequence<C> sequence, int kmer) {
		List<SequenceView<C>> l = new ArrayList<SequenceView<C>>();
		WindowedSequence<C> w = new WindowedSequence<C>(sequence, kmer);
		for(SequenceView<C> view: w) {
			l.add(view);
		}
		return l;
	}
277154
@Override
	public AbstractSequence<AminoAcidCompound> getSequence(String sequence, long index) throws CompoundNotFoundException, IOException {
		SequenceFileProxyLoader<AminoAcidCompound> sequenceFileProxyLoader =
				new SequenceFileProxyLoader<AminoAcidCompound>(
						file,
						sequenceParser,
						index,
						sequence.length(),
						compoundSet
						);
		return new ProteinSequence(sequenceFileProxyLoader, compoundSet);
	}
451601
def _kmp_search_first(self, pInput_sequence, pPattern):
                """"""
                input_sequence, pattern = pInput_sequence, [len(bin(e)) for e in pPattern]
                n, m = len(input_sequence), len(pattern)
                d = p = 0
                next = self._kmp_construct_next(pattern)
                while d < n and p < m:
                        p = next[len(bin(input_sequence[d]))][p]
                        d += 1
                if p == m: return d - p
                else: return -1
1216017
public <T> List<T> reorder( List<T> sequence)
    {
    int elementCount = sequence.size();
    if( elementCount > 1)
      {
      List<T> elements = new ArrayList<T>( sequence);
      sequence.clear();

      for( ; elementCount > 0; elementCount--)
        {
        sequence.add( elements.remove( generator_.nextInt( elementCount)));
        }
      }

    return sequence;
    }
1366462
def group_by_key_impl(sequence):
    
    result = {}
    for element in sequence:
        if result.get(element[0]):
            result.get(element[0]).append(element[1])
        else:
            result[element[0]] = [element[1]]
    return six.viewitems(result)
595838
public static <S extends Sequence<C>, C extends Compound> int getGCGChecksum(List<S> sequences) {
		int check = 0;
		for (S as : sequences) {
			check += getGCGChecksum(as);
		}
		return check % 10000;
	}
1147350
public int[] buildSuffixArray(CharSequence sequence) {
        /*
         * Allocate slightly more space, some suffix construction strategies need it and
         * we don't want to waste space for multiple symbol mappings.
         */

        this.input = new int[sequence.length() + SuffixArrays.MAX_EXTRA_TRAILING_SPACE];
        for (int i = sequence.length() - 1; i >= 0; i--) {
            input[i] = sequence.charAt(i);
        }

        final int start = 0;
        final int length = sequence.length();

        final ISymbolMapper mapper = new DensePositiveMapper(input, start, length);
        mapper.map(input, start, length);

        return delegate.buildSuffixArray(input, start, length);
    }
1147905
public Callable<ResponderResult> createSequence(final Responder responder, final ResultHandler resultHandler) {
        return new Sequence<>(this, this.chainResponder(responder, resultHandler));
    }
513184
@Deprecated
  public static <A,B,C,D,E> Parser<Tuple5<A,B,C,D,E>> tuple(
      Parser<? extends A> p1, Parser<? extends B> p2, Parser<? extends C> p3,
      Parser<? extends D> p4, Parser<? extends E> p5) {
    return sequence(p1, p2, p3, p4, p5, Tuple5::new);
  }
546076
public static KmeansDataSet createDataModel(List<KmeansPoint> pointList, int clusterNum,
            int maxIteration, double convergenceThres)
    {
        // クラスタ数よりもデータ数が少ない場合、結果はnullとして返す。
        if (pointList.size() < clusterNum)
        {
            return null;
        }

        // 初回の中心点リストを生成する。
        List<KmeansPoint> centroids = createInitialCentroids(pointList, clusterNum);
        long[] clusteredNum = new long[clusterNum];

        // イテレーションを最大回数実行し、収束を試みる。
        for (int exeIndex = 0; exeIndex < maxIteration; exeIndex++)
        {
            Map<Integer, List<KmeansPoint>> assignments = Maps.newHashMap();
            for (int centroidIndex = 0; centroidIndex < clusterNum; centroidIndex++)
            {
                assignments.put(centroidIndex, Lists.<KmeansPoint> newArrayList());
            }

            for (KmeansPoint targetPoint : pointList)
            {
                KmeansResult result = nearestCentroid(targetPoint, centroids);
                assignments.get(result.getCentroidIndex()).add(targetPoint);
            }

            List<KmeansPoint> newCentroids = Lists.newArrayList();
            for (Map.Entry<Integer, List<KmeansPoint>> entry : assignments.entrySet())
            {
                if (entry.getValue().isEmpty())
                {
                    newCentroids.add(centroids.get(entry.getKey()));
                }
                else
                {
                    newCentroids.add(calculateCentroid(entry.getValue()));
                }

                clusteredNum[entry.getKey()] = entry.getValue().size();
            }

            boolean isConvergenced = isConvergenced(centroids, newCentroids, convergenceThres);
            centroids = newCentroids;

            if (isConvergenced == true)
            {

                break;
            }
        }

        double[][] centroidPoints = new double[clusterNum][];

        for (int centroidIndex = 0; centroidIndex < clusterNum; centroidIndex++)
        {
            centroidPoints[centroidIndex] = centroids.get(centroidIndex).getDataPoint();
        }

        KmeansDataSet createdModel = new KmeansDataSet();
        createdModel.setCentroids(centroidPoints);
        createdModel.setClusteredNum(clusteredNum);
        return createdModel;
    }
342415
public static AminoAcidSequence translate(NucleotideSequence sequence) {
        if (sequence.size() % 3 != 0)
            throw new IllegalArgumentException("Only nucleotide sequences with size multiple " +
                    "of three are supported (in-frame).");
        byte[] aaData = new byte[sequence.size() / 3];
        GeneticCode.translate(aaData, 0, sequence, 0, sequence.size());
        return new AminoAcidSequence(aaData, true);
    }
141826
public static FastaSequence convertProteinSequencetoFasta(ProteinSequence sequence){
		StringBuffer buf = new StringBuffer();
		for (AminoAcidCompound compound : sequence) {

			String c = compound.getShortName();

			if (! SequenceUtil.NON_AA.matcher(c).find()) {
				buf.append(c);
			} else {
				buf.append("X");
			}
		}

		return new FastaSequence(sequence.getAccession().getID(),buf.toString());
	}
29939
@Override
    public Object mapSequence(Object sequence) {
        List<?> seq = (List<?>) sequence;
        List<Object> out = new ArrayList<>();
        for (Object step : seq) {
            out.add(map(step));
        }
        return out;
    }
1025312
@Override
	public SequenceView<C> getSubSequence(Integer start, Integer end) {
		return new SequenceProxyView<C>(this, start, end);
	}
707777
public static List<KmeansPoint> createInitialCentroids(List<KmeansPoint> basePoints,
            int clusterNum)
    {
        Random random = new Random();
        List<KmeansPoint> resultList = Lists.newArrayList();
        // ベースデータリストを更新しないためにコピーを生成して用いる
        List<KmeansPoint> pointList = Lists.newArrayList(basePoints);
        KmeansPoint firstCentroid = pointList.remove(random.nextInt(pointList.size()));
        resultList.add(firstCentroid);

        double[] dxs;
        // KMeans++方式による中心点算出をクラスタの数だけ実施する。
        // 最初の1点はランダムで算出しているため、1オリジンで開始している。
        for (int centroidIndex = 1; centroidIndex < clusterNum; centroidIndex++)
        {
            // 各データポイントに対する距離を用いて重みつき確率分布を算出する。
            dxs = computeDxs(pointList, resultList);

            // 重みつき確率分布を用いて次の中心点を選出する。
            double r = random.nextDouble() * dxs[dxs.length - 1];
            int next = Arrays.binarySearch(dxs, r);
            int index = 0;
            if (next > 0)
            {
                index = next - 1;
            }
            else if (next < 0)
            {
                index = COMPENSATE_INDEX - next;
            }

            while (index > 0 && resultList.contains(pointList.get(index)))
            {
                index = index - 1;
            }

            resultList.add(pointList.get(index));
        }

        return resultList;
    }
324165
def SequenceOf(klass):
    """"""
    if _debug: SequenceOf._debug("SequenceOf %r", klass)

    global _sequence_of_map
    global _sequence_of_classes, _array_of_classes

    # if this has already been built, return the cached one
    if klass in _sequence_of_map:
        if _debug: SequenceOf._debug("    - found in cache")
        return _sequence_of_map[klass]

    # no SequenceOf(SequenceOf(...)) allowed
    if klass in _sequence_of_classes:
        raise TypeError("nested sequences disallowed")
    # no SequenceOf(ArrayOf(...)) allowed
    if klass in _array_of_classes:
        raise TypeError("sequences of arrays disallowed")

    # define a generic class for lists
    @bacpypes_debugging
    class _SequenceOf:

        subtype = None

        def __init__(self, value=None):
            if _debug: _SequenceOf._debug("(%r)__init__ %r (subtype=%r)", self.__class__.__name__, value, self.subtype)

            if value is None:
                self.value = []
            elif isinstance(value, list):
                self.value = value
            else:
                raise TypeError("invalid constructor datatype")

        def append(self, value):
            if issubclass(self.subtype, Atomic):
                pass
            elif issubclass(self.subtype, AnyAtomic) and not isinstance(value, Atomic):
                raise TypeError("instance of an atomic type required")
            elif not isinstance(value, self.subtype):
                raise TypeError("%s value required" % (self.subtype.__name__,))
            self.value.append(value)

        def __len__(self):
            return len(self.value)

        def __getitem__(self, item):
            return self.value[item]

        def __iter__(self):
            return iter(self.value)

        def encode(self, taglist):
            if _debug: _SequenceOf._debug("(%r)encode %r", self.__class__.__name__, taglist)
            for value in self.value:
                if issubclass(self.subtype, (Atomic, AnyAtomic)):
                    # a helper cooperates between the atomic value and the tag
                    helper = self.subtype(value)

                    # build a tag and encode the data into it
                    tag = Tag()
                    helper.encode(tag)

                    # now encode the tag
                    taglist.append(tag)
                elif isinstance(value, self.subtype):
                    # it must have its own encoder
                    value.encode(taglist)
                else:
                    raise TypeError("%s must be a %s" % (value, self.subtype.__name__))

        def decode(self, taglist):
            if _debug: _SequenceOf._debug("(%r)decode %r", self.__class__.__name__, taglist)

            while len(taglist) != 0:
                tag = taglist.Peek()
                if tag.tagClass == Tag.closingTagClass:
                    return

                if issubclass(self.subtype, (Atomic, AnyAtomic)):
                    if _debug: _SequenceOf._debug("    - building helper: %r %r", self.subtype, tag)
                    taglist.Pop()

                    # a helper cooperates between the atomic value and the tag
                    helper = self.subtype(tag)

                    # save the value
                    self.value.append(helper.value)
                else:
                    if _debug: _SequenceOf._debug("    - building value: %r", self.subtype)
                    # build an element
                    value = self.subtype()

                    # let it decode itself
                    value.decode(taglist)

                    # save what was built
                    self.value.append(value)

        def debug_contents(self, indent=1, file=sys.stdout, _ids=None):
            i = 0
            for value in self.value:
                if issubclass(self.subtype, (Atomic, AnyAtomic)):
                    file.write("%s[%d] = %r\n" % ("    " * indent, i, value))
                elif isinstance(value, self.subtype):
                    file.write("%s[%d]" % ("    " * indent, i))
                    value.debug_contents(indent+1, file, _ids)
                else:
                    file.write("%s[%d] %s must be a %s" % ("    " * indent, i, value, self.subtype.__name__))
                i += 1

        def dict_contents(self, use_dict=None, as_class=dict):
            # return sequences as arrays
            mapped_value = []

            for value in self.value:
                if issubclass(self.subtype, Atomic):
                    mapped_value.append(value)              ### ambiguous
                elif issubclass(self.subtype, AnyAtomic):
                    mapped_value.append(value.value)        ### ambiguous
                elif isinstance(value, self.subtype):
                    mapped_value.append(value.dict_contents(as_class=as_class))

            # return what we built
            return mapped_value

    # constrain it to a list of a specific type of item
    setattr(_SequenceOf, 'subtype', klass)
    _SequenceOf.__name__ = 'SequenceOf' + klass.__name__
    if _debug: SequenceOf._debug("    - build this class: %r", _SequenceOf)

    # cache this type
    _sequence_of_map[klass] = _SequenceOf
    _sequence_of_classes[_SequenceOf] = 1

    # return this new type
    return _SequenceOf
1038455
public static JavaRDD<List<List<Writable>>> zeroMeanUnitVarianceSequence(Schema schema,
                    JavaRDD<List<List<Writable>>> sequence) {
        return zeroMeanUnitVarianceSequence(schema, sequence, null);
    }