-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathContentRegions.C
94 lines (73 loc) · 2.39 KB
/
ContentRegions.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/****************************************************************
ContentRegions.C
Copyright (C)2015 William H. Majoros ([email protected]).
This is OPEN SOURCE SOFTWARE governed by the Gnu General Public
License (GPL) version 3, as described at www.opensource.org.
****************************************************************/
#include <iostream>
#include "ContentRegions.H"
using namespace std;
using namespace BOOM;
ContentRegions::ContentRegions(const GffTranscript &transcript,int seqLength)
{
init(transcript,seqLength);
}
const Vector<ContentRegion> &ContentRegions::asVector()
{
return regions;
}
void ContentRegions::init(const GffTranscript &transcript,int seqLength)
{
const int numExons=transcript.numExons();
if(numExons<1) throw "Empty transcript in ContentRegions::init()";
regions.push_back(ContentRegion(INTERGENIC,0,transcript.getBegin()));
for(int i=0 ; i<numExons ; ++i) {
const GffExon &exon=transcript.getIthExon(i);
ContentType type;
if(numExons==1) type=SINGLE_EXON;
else if(i==0) type=INITIAL_EXON;
else if(i==numExons-1) type=FINAL_EXON;
else type=INTERNAL_EXON;
regions.push_back(ContentRegion(type,exon.getBegin(),exon.getEnd()));
if(i+1<numExons) {
const GffExon &nextExon=transcript.getIthExon(i+1);
regions.push_back(ContentRegion(INTRON,exon.getEnd(),nextExon.getBegin()));
}
}
regions.push_back(ContentRegion(INTERGENIC,transcript.getEnd(),seqLength));
}
bool ContentRegions::findJunction(int pos,const ContentRegion *&preceding,
const ContentRegion *&following) const
{
for(Vector<ContentRegion>::const_iterator cur=regions.begin(),
end=regions.end() ; cur!=end ; ++cur) {
const ContentRegion *region=&*cur;
if(region->getInterval().getEnd()==pos) {
preceding=region;
++cur;
following=&*cur;
return true;
}
}
return false;
}
ContentRegion *ContentRegions::regionOverlapping(int pos) const
{
for(Vector<ContentRegion>::const_iterator cur=regions.begin(),
end=regions.end() ; cur!=end ; ++cur)
if((*cur).getInterval().contains(pos)) return &*cur;
return NULL;
}
void ContentRegions::printOn(ostream &os) const
{
for(Vector<ContentRegion>::const_iterator cur=regions.begin(),
end=regions.end() ; cur!=end ; ++cur) {
os<<*cur;
if(cur+1!=end) os<<",";
}
}
ostream &operator<<(ostream &os,const ContentRegions &r)
{
r.printOn(os);
return os;
}