/// <summary> /// Performs Breadth First Search to traverse through graph to generate scaffold paths. /// </summary> /// <param name="overlapGraph">Contig Overlap Graph.</param> /// <param name="contigPairedReadMaps">InterContig Distances.</param> /// <param name="lengthOfKmer">Length of Kmer.</param> /// <param name="searchDepth">Depth to which graph is searched.</param> /// <returns>List of paths/scaffold.</returns> public IList <ScaffoldPath> FindPaths( ContigGraph overlapGraph, ContigMatePairs contigPairedReadMaps, int lengthOfKmer, int searchDepth = 10) { if (overlapGraph == null) { throw new ArgumentNullException("deBruijnGraph"); } if (contigPairedReadMaps == null) { throw new ArgumentNullException("contigPairedReadMaps"); } if (lengthOfKmer <= 0) { throw new ArgumentException(Resource.KmerLength); } if (searchDepth <= 0) { throw new ArgumentException(Resource.Depth); } this.graph = overlapGraph; this.kmerLength = lengthOfKmer; this.depth = searchDepth; List <ScaffoldPath> scaffoldPaths = new List <ScaffoldPath>(); Parallel.ForEach( overlapGraph.Nodes, (Node node) => { Dictionary <ISequence, IList <ValidMatePair> > contigPairedReadMap; if (contigPairedReadMaps.TryGetValue(overlapGraph.GetNodeSequence(node), out contigPairedReadMap)) { List <ScaffoldPath> scaffoldPath = TraverseGraph(node, contigPairedReadMap); lock (scaffoldPaths) { scaffoldPaths.AddRange(scaffoldPath); } } }); return(scaffoldPaths); }
/// <summary> /// Filter Paired Read Based on Orientation. /// </summary> /// <param name="matePairMap">Map between contigs using mate pair information.</param> /// <param name="redundancy">Number of mate pairs required to create a link between two contigs. /// Hierarchical Scaffolding With Bambus /// by: Mihai Pop, Daniel S. Kosack, Steven L. Salzberg /// Genome Research, Vol. 14, No. 1. (January 2004), pp. 149-159.</param> public ContigMatePairs FilterPairedReads(ContigMatePairs matePairMap, int redundancy = 2) { if (null == matePairMap) { throw new ArgumentNullException("matePairMap"); } if (redundancy < 0) { throw new ArgumentException(Bio.Algorithms.Assembly.Padena.Properties.Resource.NegativeRedundancy); } foreach (KeyValuePair <ISequence, Dictionary <ISequence, IList <ValidMatePair> > > matePair in matePairMap) { foreach (KeyValuePair <ISequence, IList <ValidMatePair> > validMatePair in matePair.Value) { if (matePair.Key != validMatePair.Key) { Dictionary <ISequence, IList <ValidMatePair> > validMatePairs; if (matePairMap.TryGetValue(validMatePair.Key, out validMatePairs)) { IList <ValidMatePair> pair; if (validMatePairs.TryGetValue(matePair.Key, out pair)) { OrientationFilter(pair, validMatePair.Value, redundancy); } else { if (validMatePair.Value.Count < redundancy) { validMatePair.Value.Clear(); } } } else { if (validMatePair.Value.Count < redundancy) { validMatePair.Value.Clear(); } } } else { validMatePair.Value.Clear(); } } } ContigMatePairs newMatePairMap = new ContigMatePairs(); Parallel.ForEach( matePairMap, (KeyValuePair <ISequence, Dictionary <ISequence, IList <ValidMatePair> > > matePair) => { Dictionary <ISequence, IList <ValidMatePair> > map = new Dictionary <ISequence, IList <ValidMatePair> >(); foreach (KeyValuePair <ISequence, IList <ValidMatePair> > validMatePair in matePair.Value) { if (validMatePair.Value.Count > 0) { map.Add(validMatePair.Key, validMatePair.Value); } } if (map.Count > 0) { lock (newMatePairMap) { newMatePairMap.Add(matePair.Key, map); } } }); return(newMatePairMap); }