/// <summary> /// Builds k-mers from a list of given input sequences. /// For each sequence in input list, constructs a KmersOfSequence /// corresponding to the sequence and associated k-mers. /// </summary> /// <param name="sequences">List of input sequences.</param> /// <param name="kmerLength">K-mer length.</param> /// <returns>List of KmersOfSequence instances.</returns> public static KmerIndexerDictionary BuildKmerDictionary(IList <ISequence> sequences, int kmerLength) { if (sequences == null) { throw new ArgumentNullException("sequences"); } if (kmerLength <= 0) { throw new ArgumentException(Properties.Resource.KmerLengthShouldBePositive); } Task <KmerPositionDictionary>[] kmerTasks = new Task <KmerPositionDictionary> [sequences.Count]; for (int index = 0; index < sequences.Count; index++) { ISequence localSequence = sequences[index]; kmerTasks[index] = Task <KmerPositionDictionary> .Factory.StartNew( o => BuildKmerDictionary(localSequence, kmerLength), TaskCreationOptions.None); } IList <KmerIndexer> kmerIndex; List <KmerPositionDictionary> kmerPositionDictionaries = new List <KmerPositionDictionary>(kmerTasks.Length); int totalElements = 0; for (int index = 0; index < kmerTasks.Length; index++) { KmerPositionDictionary kmerPositionDictionary = kmerTasks[index].Result; kmerPositionDictionaries.Add(kmerPositionDictionary); totalElements += kmerPositionDictionary.Count; } KmerIndexerDictionary maps = new KmerIndexerDictionary(totalElements); for (int index = 0; index < kmerPositionDictionaries.Count; index++) { foreach (KeyValuePair <ISequence, IList <long> > value in kmerPositionDictionaries[index]) { if (maps.TryGetValue(value.Key, out kmerIndex) || maps.TryGetValue(value.Key.GetReverseComplementedSequence(), out kmerIndex)) { kmerIndex.Add(new KmerIndexer(index, value.Value)); } else { maps.Add(value.Key, new List <KmerIndexer> { new KmerIndexer(index, value.Value) }); } } } return(maps); }
/// <summary> /// Builds k-mers from a list of given input sequences. /// For each sequence in input list, constructs a KmersOfSequence /// corresponding to the sequence and associated k-mers. /// </summary> /// <param name="sequences">List of input sequences.</param> /// <param name="kmerLength">K-mer length.</param> /// <returns>List of KmersOfSequence instances.</returns> public static KmerIndexerDictionary BuildKmerDictionary(IList<ISequence> sequences, int kmerLength) { if (sequences == null) { throw new ArgumentNullException("sequences"); } if (kmerLength <= 0) { throw new ArgumentException(Properties.Resource.KmerLengthShouldBePositive); } var kmerTasks = new Task<KmerPositionDictionary>[sequences.Count]; for (int index = 0; index < sequences.Count; index++) { ISequence localSequence = sequences[index]; kmerTasks[index] = Task<KmerPositionDictionary>.Factory.StartNew( o => BuildKmerDictionary(localSequence, kmerLength), TaskCreationOptions.None); } IList<KmerIndexer> kmerIndex; List<KmerPositionDictionary> kmerPositionDictionaries = new List<KmerPositionDictionary>(kmerTasks.Length); int totalElements = 0; for (int index = 0; index < kmerTasks.Length; index++) { KmerPositionDictionary kmerPositionDictionary = kmerTasks[index].Result; kmerPositionDictionaries.Add(kmerPositionDictionary); totalElements += kmerPositionDictionary.Count; } KmerIndexerDictionary maps = new KmerIndexerDictionary(totalElements); for (int index = 0; index < kmerPositionDictionaries.Count; index++) { foreach (KeyValuePair<ISequence, IList<long>> value in kmerPositionDictionaries[index]) { if (maps.TryGetValue(value.Key, out kmerIndex) || maps.TryGetValue(value.Key.GetReverseComplementedSequence(), out kmerIndex)) { kmerIndex.Add(new KmerIndexer(index, value.Value)); } else { maps.Add(value.Key, new List<KmerIndexer> { new KmerIndexer(index, value.Value) }); } } } return maps; }
/// <summary> /// Builds k-mers from a list of given input sequences. /// For each sequence in input list, constructs a KmersOfSequence /// corresponding to the sequence and associated k-mers. /// </summary> /// <param name="sequences">List of input sequences</param> /// <param name="kmerLength">k-mer length</param> /// <returns>List of KmersOfSequence instances</returns> public static KmerIndexerDictionary BuildKmerDictionary(IList <ISequence> sequences, int kmerLength) { if (sequences == null) { throw new ArgumentNullException("sequences"); } if (kmerLength <= 0) { throw new ArgumentException(Properties.Resource.KmerLengthShouldBePositive); } Task <KmerPositionDictionary>[] kmerTasks = new Task <KmerPositionDictionary> [sequences.Count]; int ndx = 0; for (int index = 0; index < sequences.Count; index++) { ISequence localSequence = sequences[index]; kmerTasks[ndx] = Task <KmerPositionDictionary> .Factory.StartNew( o => BuildKmerDictionary(localSequence, kmerLength), TaskCreationOptions.None); ndx++; } KmerIndexerDictionary maps = new KmerIndexerDictionary(); IList <KmerIndexer> kmerIndex; char[] rcBuilder = new char[kmerLength]; for (int index = 0; index < kmerTasks.Length; index++) { foreach (KeyValuePair <string, IList <int> > value in kmerTasks[index].Result) { if (maps.TryGetValue(value.Key, out kmerIndex) || maps.TryGetValue(value.Key.GetReverseComplement(rcBuilder), out kmerIndex)) { kmerIndex.Add(new KmerIndexer(index, value.Value)); } else { maps.Add(value.Key, new List <KmerIndexer> { new KmerIndexer(index, value.Value) }); } } } return(maps); }