namespace Genomics { using System; using System.Collections.Generic; using System.Linq; using Shared; public class LocusRegulatoryMap : RegulatoryMap { public LocusRegulatoryMap() { } public LocusRegulatoryMap(Dictionary> source) : base (source) { } /// /// Initializes a new instance of the class. /// /// Source links. public LocusRegulatoryMap(IEnumerable source) : base(source.ToLookup(x => x.LocusName, x => x) .ToDictionary(x => x.Key, x => x.ToLookup(y => y.TranscriptName, y => y).ToDictionary(y => y.Key, y => y.First()))) { } /// /// Gets the transcripts in the map /// /// The transcripts. public override HashSet Transcripts { get { return Helpers.CheckInit( ref this.transcripts, () => new HashSet(this.Values.Select(x => x.Keys).SelectMany(x => x))); } } /// /// Gets the Loci in the map /// /// The Loci. public override HashSet Loci { get { return Helpers.CheckInit( ref this.loci, () => new HashSet(this.Keys)); } } /// /// Gets the nearest neighbor map for the nearest N neighbors /// /// The nearest neighbor map. /// Number of nearest neighbors. public LocusRegulatoryMap GetNearestNeighborMap(int n) { return new LocusRegulatoryMap(this.Select( x => x.Value.Values.OrderBy(y => y.AbsLinkLength).Take(n)) .SelectMany(x => x)); } /// /// Reverse this instance. /// /// A regulatory map with Loci as keys public TssRegulatoryMap Invert() { return new TssRegulatoryMap(this.Links .ToLookup(x => x.TranscriptName, x => x) .ToDictionary(x => x.Key, x => x.ToDictionary(y => y.LocusName, y => y))); } } }