/// <summary> /// Loads a map. /// </summary> /// <returns>The map.</returns> /// <param name="mapFileName">Map file name.</param> /// <param name="configData">Config data.</param> /// <param name="maxRange">Max range.</param> public static TssRegulatoryMap LoadMap( string mapFileName, List <int> promoterRange, int maxRange, double confidenceThreshold) { var mapProperties = new MapLinkFilter { PromoterUpstreamRange = promoterRange[0], PromoterDownstreamRange = promoterRange.Count == 1 ? promoterRange[0] : promoterRange[1], MaximumLinkLength = maxRange, ConfidenceThreshold = confidenceThreshold, }; return(TssRegulatoryMap.LoadMap(mapFileName, mapProperties)); }
public void FilterMap(MapLinkFilter.LinkType linkType) { var mapLinkFilter = new MapLinkFilter { LinkTypeFilter = linkType, }; var map = TssRegulatoryMap.LoadMap(this.MapFileName, mapLinkFilter); var outputMapFile = this.MapFileName.Replace(".bed", "." + linkType.ToString() + ".bed"); var tssSet = this.GeneMap ? this.ExpressionFiles.First().Value.Genes : this.ExpressionFiles.First().Value.Transcripts; WriteMap(map, tssSet, this.HistoneName, outputMapFile); }
/// <summary> /// Convert the map to genes. /// </summary> public void Convert() { MapLinkFilter filter = new MapLinkFilter { MaximumLinkLength = this.MaxRange, ConfidenceThreshold = this.PvalueThreshold, LinkTypeFilter = MapLinkFilter.LinkType.Any, }; TssRegulatoryMap map = TssRegulatoryMap.LoadMap(this.MapFileName, filter); var expression = new GtfExpressionFile( GtfExpressionFile.ExpressionTypeFromString(this.RnaSource), this.AnnotationFileName); var geneMap = map.ConvertToGenes(IUnknown.QueryInterface <IExpressionData>(expression)); foreach (var link in geneMap.Links) { var geneLocation = expression.Transcripts[link.TranscriptName]; string[] lineData = new string[] { geneLocation.Chromosome, geneLocation.Start.ToString(), geneLocation.End.ToString(), link.GeneName, "NA", geneLocation.Strand, link.LocusName, link.Correlation.ToString(), link.ConfidenceScore.ToString(), link.LinkLength.ToString(), this.HistoneName, link.TranscriptName, }; Console.WriteLine(string.Join("\t", lineData)); } }
/// <summary> /// Execute this instance. /// </summary> public void Execute() { var filter = new MapLinkFilter { }; if (this.Threshold >= 0) { filter.ConfidenceThreshold = this.Threshold; } var corrMap = TssRegulatoryMap.LoadMap(this.MapFileName, filter); if (corrMap.Count == 0) { return; } if (this.UseGenes) { corrMap = corrMap.ConvertToGenes(); } var scores = corrMap.Links.OrderBy(x => x.ConfidenceScore).ToArray(); const int thresholdCount = 10; double binSize = (double)scores.Length / thresholdCount; var binEdges = new double[] { 0.0 } .Concat(Enumerable.Range(1, 9).Select(x => scores[(int)Math.Floor(x * binSize)].ConfidenceScore)) .Concat(new double[] { 1 }) .Reverse() .ToArray(); var binColors = new string[] { "192,192,192" } .Concat(binEdges .Select((x, i) => string.Format( "{0},0,{1}", (int)((double)i / (thresholdCount - 1) * 255), 255 - (int)((double)i / (thresholdCount - 1) * 255)))) .ToList(); var links = corrMap.Links.Select(x => { var upstreamLocation = x.LocusLocation.Start < x.TssLocation.DirectionalStart ? x.LocusLocation : x.TssLocation; var downstreamLocation = x.LocusLocation.End > x.TssLocation.DirectionalStart ? x.LocusLocation : x.TssLocation; int upstreamLength = x.LocusLocation.Start < x.TssLocation.DirectionalStart ? x.LocusSize : 1; int downstreamLength = x.LocusLocation.End > x.TssLocation.DirectionalStart ? x.LocusSize : 1; int regionStart = upstreamLocation.Start - (upstreamLength == 1 ? 1 : 0); int regionEnd = downstreamLocation.End + (downstreamLength == 1 ? 1 : 0); var blockCount = "2"; var blockSizes = upstreamLength + "," + downstreamLength; var blockStarts = x.LinkLength > 0 ? "0," + (regionEnd - regionStart - 1) : "0," + (regionEnd - regionStart - x.LocusSize); if (x.LocusLocation.OverlapsDirectionalStart(x.TssLocation)) { blockCount = "1"; blockStarts = "0"; blockSizes = x.LocusSize.ToString(); } return(new string[] { x.LocusLocation.Chromosome, regionStart.ToString(), regionEnd.ToString(), x.LocusLocation.Name + "_" + x.TssLocation.Name, x.ConfidenceScore.ToString(), upstreamLocation == x.LocusLocation ? "+" : "-", regionStart.ToString(), regionEnd.ToString(), binColors[Bin(x.ConfidenceScore, binEdges)], blockCount, blockSizes, blockStarts }); }) .ToList(); Tables.ToNamedTsvFile( this.OutputFile, links, new string[] { "track name=regulatory_map description=\"Regulatory Map\" itemRgb=\"On\"" }); }