/// <summary> /// For input sequence, constructs k-mers by sliding /// a frame of size kmerLength along the input sequence. /// Track positions of occurance for each kmer in sequence. /// Constructs KmersOfSequence for sequence and associated k-mers. /// </summary> /// <param name="start">Start index of sequence range.</param> /// <param name="end">End index of sequence range.</param> /// <param name="kmerLength">Kmer Length.</param> /// <param name="sequences">List of sequences.</param> /// <returns>Kmer Dictionary.</returns> public static Dictionary <string, KmerDataGraphNodePair> BuildPaDeNAKmerDictionary( int start, int end, int kmerLength, IList <ISequence> sequences) { if (kmerLength <= 0) { throw new ArgumentException(Resource.KmerLengthShouldBePositive); } if (sequences == null) { throw new ArgumentNullException("sequences"); } char[] rcBuilder = new char[kmerLength]; Dictionary <string, KmerDataGraphNodePair> kmerDict = new Dictionary <string, KmerDataGraphNodePair>(); for (int index = start; index < end; index++) { // Sequence 'kmer' stores the k-mer in each window. // Construct each k-mer using range from sequence for (int i = 0; i <= sequences[index].Count - kmerLength; ++i) { ISequence kmerSeq = sequences[index].Range(i, kmerLength); if (!kmerSeq.Any <ISequenceItem>(a => a.IsAmbiguous || a.IsGap)) { string kmerString = kmerSeq.ToString(); string kmerStringRC = kmerString.GetReverseComplement(rcBuilder); bool isNormalOrientation = string.Compare(kmerString, kmerStringRC, StringComparison.OrdinalIgnoreCase) <= 0; string kmer = isNormalOrientation ? kmerString : kmerStringRC; //take the alphabetically first one KmerDataGraphNodePair kmerData; if (!kmerDict.TryGetValue(kmer, out kmerData)) { kmerDict.Add(kmer, new KmerDataGraphNodePair(new KmerData(index, i, isNormalOrientation), isNormalOrientation)); } else { kmerData.Kmer.IncrementCount(isNormalOrientation); } } } } return(kmerDict); }
public static ISequence <bool> All <T>(this ISequence <T> source, Func <T, bool> predicate) { return(source.Any(x => !predicate(x)).Select(x => !x)); }
public static ISequence <bool> Any <T>(this ISequence <T> source) { return(source.Any(x => true)); }