/// <summary> /// Finds contig pairs having valid mate pairs connection between them. /// </summary> /// <param name="reads">Input list of reads.</param> /// <param name="alignment">Reads contig alignment.</param> /// <returns>Contig Mate pair map.</returns> public ContigMatePairs MapContigToMatePairs(IList <ISequence> reads, ReadContigMap alignment) { if (alignment == null) { throw new ArgumentNullException("alignment"); } if (reads == null) { throw new ArgumentNullException("reads"); } Dictionary <ISequence, IList <ReadMap> > contigs1; Dictionary <ISequence, IList <ReadMap> > contigs2; ContigMatePairs contigMatePairs = new ContigMatePairs(); foreach (ISequence read in reads) { Match match = _readExpression.Match(read.DisplayID); if (match.Success) { String mateDisplayID = GenerateExpression(match); if (alignment.TryGetValue(read.DisplayID, out contigs1) && alignment.TryGetValue(mateDisplayID, out contigs2)) { MatePair pair; if (match.Groups[2].Value == "X1" || match.Groups[2].Value == "F" || match.Groups[2].Value == "1" || match.Groups[2].Value == "x1" || match.Groups[2].Value == "f" || match.Groups[2].Value == "a" || match.Groups[2].Value == "A") { pair = new MatePair(read.DisplayID, mateDisplayID, match.Groups[3].Value); ContigMatePairMapper(contigs1, contigs2, pair, contigMatePairs); } else { pair = new MatePair(mateDisplayID, read.DisplayID, match.Groups[3].Value); ContigMatePairMapper(contigs2, contigs1, pair, contigMatePairs); } alignment.Remove(read.DisplayID); alignment.Remove(mateDisplayID); } } } return(contigMatePairs); }
/// <summary> /// Creates Paired Read Contig Map. /// </summary> /// <param name="forwardContigs">Contigs aligning to forward read.</param> /// <param name="reverseContigs">Contigs aligning to reverse read.</param> /// <param name="pair">Mate Pair.</param> /// <param name="contigMatePairs">Contig mate pair.</param> private static void ContigMatePairMapper( Dictionary <ISequence, IList <ReadMap> > forwardContigs, Dictionary <ISequence, IList <ReadMap> > reverseContigs, MatePair pair, ContigMatePairs contigMatePairs) { foreach (KeyValuePair <ISequence, IList <ReadMap> > forwardContigMaps in forwardContigs) { Dictionary <ISequence, IList <ValidMatePair> > forwardContig; if (!contigMatePairs.TryGetValue(forwardContigMaps.Key, out forwardContig)) { forwardContig = new Dictionary <ISequence, IList <ValidMatePair> >(); contigMatePairs.Add(forwardContigMaps.Key, forwardContig); } foreach (KeyValuePair <ISequence, IList <ReadMap> > reverseContigMaps in reverseContigs) { IList <ValidMatePair> matePairs; if (!forwardContig.TryGetValue(reverseContigMaps.Key, out matePairs)) { matePairs = new List <ValidMatePair>(); forwardContig.Add(reverseContigMaps.Key, matePairs); } foreach (ReadMap forwardMap in forwardContigMaps.Value) { foreach (ReadMap reverseMap in reverseContigMaps.Value) { ValidMatePair validPairedRead = new ValidMatePair(); validPairedRead.PairedRead = pair; validPairedRead.ForwardReadStartPosition.Add(forwardMap.StartPositionOfContig); validPairedRead.ReverseReadStartPosition.Add( reverseMap.StartPositionOfContig + reverseMap.Length - 1); validPairedRead.ReverseReadReverseComplementStartPosition.Add( reverseContigMaps.Key.Count - reverseMap.StartPositionOfContig - 1); matePairs.Add(validPairedRead); } } } } }
/// <summary> /// Map reads to mate pairs. /// </summary> /// <param name="reads">List of Reads</param> /// <returns>List of mate pairs.</returns> public IList <MatePair> Map(IList <ISequence> reads) { if (null == reads) { throw new ArgumentNullException("reads"); } Dictionary <String, MatePair> pairs = new Dictionary <string, MatePair>(); MatePair mate; string exp = string.Empty; foreach (ISequence read in reads) { if (read == null) { throw new ArgumentException(Properties.Resource.ReadCannotBeNull); } if (pairs.TryGetValue(read.DisplayID, out mate)) { if (string.IsNullOrEmpty(mate.ForwardReadID)) { mate.ForwardReadID = read.DisplayID; } else { mate.ReverseReadID = read.DisplayID; } } else { Match match = _readExpression.Match(read.DisplayID); if (match.Success) { mate = new MatePair(match.Groups[3].Value); if (match.Groups[2].Value == "X1" || match.Groups[2].Value == "F" || match.Groups[2].Value == "1" || match.Groups[2].Value == "x1" || match.Groups[2].Value == "f" || match.Groups[2].Value == "a" || match.Groups[2].Value == "A") { mate.ForwardReadID = read.DisplayID; } else { mate.ReverseReadID = read.DisplayID; } exp = GenerateExpression(match); if (!pairs.ContainsKey(exp)) { pairs.Add(exp, mate); } else { throw new FormatException( string.Format(CultureInfo.CurrentCulture, Resource.DuplicatingReadIds, read.DisplayID)); } } } } return(pairs.Values.Where(pair => !string.IsNullOrEmpty(pair.ForwardReadID) && !string.IsNullOrEmpty(pair.ReverseReadID)).ToList()); }