public virtual GtfTranscriptItem Next(bool exonOnly = true) { CheckFileOpened(); GtfTranscriptItem result = new GtfTranscriptItem(); if (this.last != null) { result.Add(last); } Func<GtfItem> getItem; if (exonOnly) { getItem = () => file.NextExon(); } else { getItem = () => file.Next(); } while ((last = getItem()) != null) { if (result.IsSameTranscript(last)) { if (last.Strand == '-') { result.Insert(0, last); } else { result.Add(last); } } else { break; } } if (result.Count > 0) { return result; } else { return null; } }
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++; } } } }