public GtfItem ToGtfItem() { var result = new GtfItem(this); result.Start = result.Start + 1; return(result); }
public string GetValue(string chrom, long start, long end) { if (!maps.ContainsKey(chrom)) { return(this.emptyStr); } var items = maps[chrom]; long minAbsoluteDistance = int.MaxValue; long minDistance = int.MaxValue; GtfItem distItem = null; bool bStart = true; foreach (var item in items) { var disStart = start - item.Start; var absDisStart = Math.Abs(disStart); if (absDisStart < minAbsoluteDistance) { minAbsoluteDistance = absDisStart; minDistance = disStart; distItem = item; bStart = true; } var disEnd = start - item.End; var absDisEnd = Math.Abs(disEnd); if (absDisEnd < minAbsoluteDistance) { minAbsoluteDistance = absDisEnd; minDistance = disEnd; distItem = item; bStart = false; } if (disStart < 0 && disEnd < 0) { break; } } var position = distItem.GetNameExon() + ":" + (bStart ? "start" : "end"); string gene = string.Empty; string gene_func = string.Empty; if (bStart && distItem.ExonNumber <= 1 && minDistance < 0) { } else { var maxExon = items.Where(m => m.Name.Equals(distItem.Name)).Select(m => m.ExonNumber).Max(); if (!bStart && distItem.ExonNumber == maxExon && minDistance > 0) { } else { gene = distItem.Name; if ((bStart && minDistance < 0) || (!bStart && minDistance > 0)) { gene_func = "intron"; } else { gene_func = "exon"; } } } return(string.Format("{0}\t{1}\t{2}\t{3}", minDistance, position, gene, gene_func)); }
public void MatchGtfTranscriptItem(GtfTranscriptItem gtItem) { int index = gtItem.FindItemIndex(this.Start, this.End - 1); if (-1 == index) { return; } GtfItem gitem = gtItem[index]; MatchExon exon = new MatchExon(); this.exons.Add(exon); exon.TranscriptId = gitem.TranscriptId; exon.TranscriptCount = 1; exon.TranscriptType = gitem.Source; Location ml = new Location(); exon.Add(ml); if (gitem.Start > this.Start) { //if the peak range is out of the exon range, that peak range may be potential exon which //is detected by RNASeq data, so just extend the peak range to expect length rather than //extend by prior exon range ml.Start = this.ExpectStart; exon.IntronSize = gitem.Start - this.Start; exon.RetainedIntron = true; } else if (gitem.Start <= this.ExpectStart) { //the exon has enough base pair ml.Start = this.ExpectStart; } else { //the exon has no enough base pair ml.Start = gitem.Start; long expectLength = ml.Start - this.ExpectStart; int curindex = index - 1; while (expectLength > 0 && curindex >= 0) { Location lp = new Location(); exon.Insert(0, lp); GtfItem prior = gtItem[curindex]; lp.End = prior.End; if (prior.Length >= expectLength) { lp.Start = prior.End - expectLength + 1; break; } else { lp.Start = prior.Start; expectLength = expectLength - prior.Length; curindex--; } } } if (gitem.End < this.End - 1) { ml.End = this.ExpectEnd; exon.IntronSize = this.End - 1 - gitem.End; exon.RetainedIntron = true; } else if (gitem.End >= this.ExpectEnd) { ml.End = this.ExpectEnd; } else { ml.End = gitem.End; long expectLength = this.ExpectEnd - ml.End; int curindex = index + 1; while (expectLength > 0 && curindex < gtItem.Count) { Location lp = new Location(); exon.Add(lp); GtfItem next = gtItem[curindex]; lp.Start = next.Start; if (next.Length >= expectLength) { lp.End = next.Start + expectLength - 1; break; } else { lp.End = next.End; expectLength = expectLength - next.Length; curindex++; } } } }
private static bool IsGene(GtfItem l) { return(l.Feature.Equals("gene")); }
private static bool IsCDS(GtfItem l) { return(l.Feature.Equals("CDS")); }
private static bool IsExon(GtfItem l) { return(l.Feature.Equals("exon")); }