-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtarintron2interval.c
58 lines (52 loc) · 1.99 KB
/
tarintron2interval.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
#include <bios/format.h>
#include <bios/log.h>
#include <bios/intervalFind.h>
#include <bios/common.h>
int main( int argc, char** argv)
{
Array intervals; // of Interval
Array overlaps; // of Interval*
Interval* leftInterval;
Interval* rightInterval;
Interval* intron;
int i,j;
if( argc != 3 ) {
usage("%s <tars.interval> <genes.interval>", argv[0]);
}
// reading tar interval file
intervals = intervalFind_parseFile( argv[1], 0 );
intervalFind_addIntervalsToSearchSpace( argv[2], 1 );
for( i=0; i<arrayMax( intervals)-1; i++) {
leftInterval = arrp( intervals, i, Interval );
rightInterval = arrp( intervals, i+1, Interval );
if( !strEqual( leftInterval->chromosome, rightInterval->chromosome ) ||
(rightInterval->start - leftInterval->end ) > 100000 )
continue;
AllocVar( intron );
intron->chromosome = hlr_strdup( leftInterval->chromosome );
intron->strand = leftInterval->strand;
intron->start = leftInterval->end+1;
intron->end = rightInterval->start-1;
intron->name = hlr_strdup( leftInterval->name );
intron->subIntervalCount = 1;
intron->subIntervals = arrayCreate(intron->subIntervalCount , SubInterval);
SubInterval* subInterval = arrayp( intron->subIntervals, arrayMax( intron->subIntervals ), SubInterval );
subInterval->start = leftInterval->end+1;
subInterval->end = rightInterval->start-1;
overlaps = intervalFind_getOverlappingIntervals( intron->chromosome, intron->start, intron->end );
if( arrayMax( overlaps ) == 0 ) {
printf("%s\n",intervalFind_writeInterval( intron ) );
} else {
unsigned short int contained=0;
for( j = 0; j< arrayMax( overlaps ); j++) {
Interval* currOverlap = arru( overlaps, j, Interval* );
if( (intron->start <= currOverlap->start) && ( intron->end >= currOverlap->end ) ) contained=1; // checking if fully contained
}
if( !contained ) {
printf("%s\n",intervalFind_writeInterval( intron ) );
}
}
freeMem( intron );
}
return 0;
}