-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathAlignmentGridView.m
525 lines (445 loc) · 26.9 KB
/
AlignmentGridView.m
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
//
// AlignmentGridView.m
// iGenomics
//
// Created by Stuckinaboot Inc. on 7/10/14.
//
//
#import "AlignmentGridView.h"
@implementation AlignmentGridView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (void)firstSetUp {
[super firstSetUp];
longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(readLongPressed:)];
longPressRecognizer.minimumPressDuration = kReadLongPressRecognizerMinDuration;
[self addGestureRecognizer:longPressRecognizer];
if ([readAlignmentsArr count] > 1) //No need to sort if count is 0 or 1
[GlobalVars sortArrayUsingQuicksort:readAlignmentsArr withStartPos:0 andEndPos:[readAlignmentsArr count]-1];
// [self setUpPositionMatchedCharsArr];
[self setMaxCovValWithNumOfCols:dgenomeLen-1];
[self setUpAlignmentGridPositionsArr];
}
- (void)setUpAlignmentGridPositionsArr {
NSString *noCharStr = [NSString stringWithFormat:@"%c",kAlignmentGridViewCharColumnNoChar];
NSMutableString *noCharLongStr = [[NSMutableString alloc] init];
for (int i = 0; i < maxCoverageVal; i++)
[noCharLongStr appendString:noCharStr];
alignmentGridPositionsArr = (AlignmentGridPosition*__strong*)calloc(dgenomeLen,sizeof(AlignmentGridPosition*));
for (int i = 0; i < dgenomeLen; i++) {
if (coverageArray[i] > 0) {
AlignmentGridPosition *gridPos = [[AlignmentGridPosition alloc] init];
gridPos.str = strdup([noCharLongStr UTF8String]);
gridPos.readInfoStr = calloc(noCharLongStr.length + 1, sizeof(int));
gridPos.readInfoStr[noCharLongStr.length] = '\0';
gridPos.readIndexStr = calloc(noCharLongStr.length + 1, sizeof(int));
gridPos.readIndexStr[noCharLongStr.length] = '\0';
for (int j = 0; j < maxCoverageVal; j++) {
gridPos.readIndexStr[j] = -1;
}
alignmentGridPositionsArr[i] = gridPos;
}
}
int counter = 0;
for (int i = 0; i < [readAlignmentsArr count]; i++) {
ED_Info *read = [readAlignmentsArr objectAtIndex:i];
int lenA = (int)strlen(read.gappedA);
int lenB = (int)strlen(read.gappedB);
int placeToInsertChar = -1;
int insCount = 0;
for (int x = 0; x < lenA; x++) {
if (read.position + x >= 0) {
AlignmentGridPosition *gridPos = alignmentGridPositionsArr[read.position+x-insCount];
if (!gridPos) {
gridPos = [[AlignmentGridPosition alloc] init];
alignmentGridPositionsArr[read.position+x-insCount] = gridPos;
}
gridPos.startIndexInreadAlignmentsArr = read.position;
gridPos.positionRelativeToReadStart = x-insCount;
gridPos.readLen = lenA;
if (read.gappedB[x] == kDelMarker && lenB > 1)
insCount++;
int readInfoNum = [self readInfoNumForX:x len:lenA andInsCount:insCount];
if (readInfoNum == kReadInfoReadStart) {
counter = 0;
placeToInsertChar = 0;
while (placeToInsertChar < maxCoverageVal && gridPos.str[placeToInsertChar] != kAlignmentGridViewCharColumnNoChar)
placeToInsertChar++;
}
gridPos.readIndexStr[placeToInsertChar] = i;
if (placeToInsertChar+1 > gridPos.highestChar)
gridPos.highestChar = placeToInsertChar+1;//+1 because is basically counting the row in normal numbers for math purposes
if (read.insertion) {
if (placeToInsertChar >= maxCoverageVal)
break;
// int temp = x+insCount;
// int prevX = x+insCount;
// while (temp < lenA && read.gappedB[temp] == kDelMarker) {
// insCount++;
// temp++;
// }
if (read.gappedB[x] != kDelMarker) {
// if (prevX != temp) {
readInfoNum = [self readInfoNumForX:x len:lenA andInsCount:insCount];
if (readInfoNum == kReadInfoReadEnd)
alignmentGridPositionsArr[read.position+x-insCount].readInfoStr[placeToInsertChar] = kReadInfoReadPosBeforeEnd;
// }
// if (x + insCount >= lenA)
// break;
gridPos.str[placeToInsertChar] = read.gappedA[x];
gridPos.readInfoStr[placeToInsertChar] = readInfoNum;
counter++;
}
}
else {
if (placeToInsertChar < maxCoverageVal) {//gridPos.str.length) {
gridPos.str[placeToInsertChar] = read.gappedA[x];
gridPos.readInfoStr[placeToInsertChar] = readInfoNum;
}
}
}
}
}
noCharStr = nil;
noCharLongStr = nil;
}
- (int)readInfoNumForX:(int)x len:(int)len andInsCount:(int)insCount {
if (x -insCount == 0)
return kReadInfoReadStart;
else if (x == len-1)
return kReadInfoReadEnd;
else if (x-insCount == 1)
return kReadInfoReadPosAfterStart;
else if (x == len-2)
return kReadInfoReadPosBeforeEnd;
else
return kReadInfoReadMiddle;
}
- (void)setUpGridViewForPixelOffset:(double)offSet {
currOffset = offSet;
drawingView.image = NULL;
CGSize drawingSize = self.frame.size;
//Prevents pixelation of text on retina display
if (UIGraphicsBeginImageContextWithOptions != NULL)
UIGraphicsBeginImageContextWithOptions(drawingSize, NO, 0.0);//0.0 sets the scale factor to the scale of the device's main screen
else
UIGraphicsBeginImageContext(drawingSize);
[drawingView.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
[self drawSegmentDividers];
if (kTxtFontSize >= kMinTxtFontSize && boxWidth >= kThresholdBoxWidth)
[self drawDefaultBoxColors];
int firstPtToDraw = round([self firstPtToDrawForOffset:offSet]/numOfBoxesPerPixel)*numOfBoxesPerPixel;//Rounds to nearest multiple of numOfBoxesPerPixel
double firstPtOffset = [self firstPtToDrawOffset:offSet];//Will be 0 or negative
if (kTxtFontSize >= kMinTxtFontSize && boxWidth >= kThresholdBoxWidth) {//If it is 0, there is no need for them
self.kGridLineWidthCol = kGridLineWidthColDefault;
[self drawGridLinesForOffset:firstPtOffset];
}
else
self.kGridLineWidthCol = kGridLineWidthColDefaultMin;
float x = firstPtOffset+self.kGridLineWidthCol;//If this passes the self.frame.size.width, stop drawing (break)
float y = kPosLblHeight;
float maxAlignmentStrLen = 0;
char mutationPresentArr[(int)ceilf((totalCols-firstPtToDraw)/(float)numOfBoxesPerPixel)];
for (int i = 0; i <= kAlignmentGridViewNumOfGridSections; i++) {
int indexInMutPresentArr = 0;
for (int j = firstPtToDraw; j<totalCols && x <= self.frame.size.width; j += numOfBoxesPerPixel, x += self.kGridLineWidthCol+boxWidth) {
float graphCurrY = 0;
if (i > GraphRow) {//Not Graph Row
//Depending on the value of i, draw foundGenome, refGenome, etc.
if (i == RefRow) {//ref
[self drawText:[NSString stringWithFormat:@"%c",self.refSeq[j]] atPoint:CGPointMake(x, y) withRGB:(double[3]){dnaColors.white.r, dnaColors.white.g, dnaColors.white.b}];
}
else if (i == FoundRow) {//found genome
char matchType = foundGenome[kFoundGenomeArrSize-1][j];
if ((matchType == kMatchTypeHeterozygousMutationImportant || matchType == kMatchTypeHeterozygousMutationNormal || matchType == kMatchTypeHomozygousMutationImportant || matchType == kMatchTypeHomozygousMutationNormal) && boxWidth >= kThresholdBoxWidth) {//Mutation present - highlights the view. If the graph is taking up the whole view, the mutation is checked and dealt with properly when the graph is created
RGB *rgb;
for (int t = 0; t<kACGTLen; t++) {
if (kACGTStr[t] == foundGenome[0][j]) {
//v = t;
rgb = [self colorForIndexInACGTWithInDelsStr:t orChar:' ' usingIndex:YES];
break;
}
else if (kDelMarker == foundGenome[0][j]) {
//v = kACGTLen;
rgb = dnaColors.delLbl;
break;
}
else if (kInsMarker == foundGenome[0][j]) {
//v = kACGTLen+1;
rgb = dnaColors.insLbl;
break;
}
}
double rgbVal[3] = {rgb.r, rgb.g, rgb.b};
[self drawText:[NSString stringWithFormat:@"%c",foundGenome[0][j]] atPoint:CGPointMake(x, y) withRGB:rgbVal];
// float opacity = (boxWidth < kThresholdBoxWidth) ? kMutHighlightOpacityZoomedFarOut : kMutHighlightOpacity;
// CGContextSetRGBFillColor(UIGraphicsGetCurrentContext(), dnaColors.mutHighlight.r, dnaColors.mutHighlight.g, dnaColors.mutHighlight.b, opacity);
// int highlightWidth = (boxWidth < kMutHighlightMinWidth) ? kMutHighlightMinWidth : boxWidth;
//
// CGContextFillRect(UIGraphicsGetCurrentContext(), CGRectMake(x+self.kGridLineWidthCol, kPosLblHeight, highlightWidth, self.frame.size.height-kPosLblHeight));
// [delegate mutationFoundAtPos:j];
}
else {//No mutation
[self drawText:[NSString stringWithFormat:@"%c",foundGenome[0][j]] atPoint:CGPointMake(x, y) withRGB:(double[3]){dnaColors.black.r,dnaColors.black.g,dnaColors.black.b}];
}
}
else {//A through insertion
AlignmentGridPosition *gridPos = alignmentGridPositionsArr[j];
if (gridPos.highestChar > maxAlignmentStrLen)
maxAlignmentStrLen = gridPos.highestChar;
[self drawCharColumnWithAlignmentGridPos:gridPos withGridPosIndexInGridPosArr:j atX:x andY:y-currYOffset andYToNotCross:y];
// [self drawCharColumnWithTxt:[positionMatchedCharsArr objectAtIndex:j] atX:x andY:y];
}
}
else if (i == GraphRow) {
if (posOccArray[kACGTLen+1][j] > 0 && numOfBoxesPerPixel == kPixelWidth) {
NSString *strToDraw = [NSString stringWithFormat:@"%c",kInsMarker];
CGSize size = [strToDraw sizeWithFont:[UIFont systemFontOfSize:kTxtFontSize]];
[self drawText:strToDraw atPoint:CGPointMake(x, kPosLblHeight-size.height-kPosLblTickMarkHeight/2+kGridLineWidthRow) withRGB:(double[3]){dnaColors.insertionIcon.r ,dnaColors.insertionIcon.g, dnaColors.insertionIcon.b}];
}
CGRect rect;
if (kTxtFontSize >= kMinTxtFontSize && boxWidth >= kThresholdBoxWidth) {
//Set up the graph
rect = CGRectMake(x, y, boxWidth, graphBoxHeight);
}
else {
rect = CGRectMake(x, y, boxWidth, kPosLblHeight+graphBoxHeight);
}
int currCoverage = coverageArray[j];//-posOccArray[kACGTLen+1][j];//Don't count insertions
float newHeight = (currCoverage*rect.size.height)/maxCoverageVal;
/* That kinda formula thing comes from this:
Coverage X Height
________ = _________
Max Val Max Height
X = (Coverage*Max Height)/ Max Val
*/
graphCurrY = y+(rect.size.height-newHeight);
CGRect newRect = CGRectMake(x, graphCurrY, rect.size.width, newHeight);
RGB *color;
char mutationPresent = [self mutationPresentWithinInterval:j andEndIndex:j+numOfBoxesPerPixel-1];//Highlights the bar of the graph
if (mutationPresent != kMatchTypeNoAlignment && mutationPresent != kMatchTypeHomozygousNoMutation && mutationPresent != kMatchTypeHeterozygousNoMutation)
color = [self colorForMatchType:mutationPresent];
else
color = dnaColors.graph;
mutationPresentArr[indexInMutPresentArr] = mutationPresent;
indexInMutPresentArr++;
[self drawRectangle:newRect withRGB:(double[3]){color.r,color.g,color.b}];
//Put a position label above the graph
if ([[[delegate getCumulativeSeparateGenomeLenArray] objectAtIndex:0] intValue]/kSegmentsOnScreenMax >= kPosLblInterval)
[self drawTickMarksForPoint:j andX:x];
}
if (i == ARow) {
char mutPresent = mutationPresentArr[indexInMutPresentArr];
if (mutPresent != kMatchTypeNoAlignment && boxWidth >= kThresholdBoxWidth) {
RGB *color = [self colorForMatchType:mutPresent];
float opacity = (boxWidth < kThresholdBoxWidth) ? kMutHighlightOpacityZoomedFarOut : kMutHighlightOpacity;
CGContextSetRGBFillColor(UIGraphicsGetCurrentContext(), color.r, color.g, color.b, opacity);
int highlightWidth = (boxWidth < kMutHighlightMinWidth) ? kMutHighlightMinWidth : boxWidth;
CGContextFillRect(UIGraphicsGetCurrentContext(), CGRectMake(x+self.kGridLineWidthCol, kPosLblHeight, highlightWidth, FoundRow*(boxHeight+kGridLineWidthRow)+graphBoxHeight));
// CGContextFillRect(UIGraphicsGetCurrentContext(), CGRectMake(x+self.kGridLineWidthCol, kPosLblHeight, highlightWidth, self.frame.size.height-kPosLblHeight));
}
if (mutPresent != kMatchTypeNoAlignment && boxWidth < kThresholdBoxWidth && numOfBoxesPerPixel > kPixelWidth) {
RGB *color = [self colorForMatchType:mutPresent];
float opacity = (boxWidth < kThresholdBoxWidth) ? kMutHighlightOpacityZoomedFarOut : kMutHighlightOpacity;
CGContextSetRGBFillColor(UIGraphicsGetCurrentContext(), color.r, color.g, color.b, opacity);
int highlightWidth = (boxWidth < kMutHighlightMinWidth) ? kMutHighlightMinWidth : boxWidth;
float calculatedHeight = alignmentGridPositionsArr[j].highestChar*(boxHeight+kGridLineWidthRow)-scrollingView.contentOffset.y-kGridLineWidthRow;
CGContextFillRect(UIGraphicsGetCurrentContext(), CGRectMake(x+self.kGridLineWidthCol, y, highlightWidth, (calculatedHeight > 0) ? calculatedHeight : 0));
}
indexInMutPresentArr++;
}
}
x = firstPtOffset;
if (i > 0)
y += kGridLineWidthRow+boxHeight;
else
y += kGridLineWidthRow+graphBoxHeight;
}
if (maxAlignmentStrLen > 0)
[self fixScrollViewContentSizeWithMaxAlignmentStrLen:maxAlignmentStrLen];
else if (maxAlignmentStrLen == 0 && scrollingView.contentSize.height > scrollingView.frame.size.height)
[self fixScrollViewContentSizeWithMaxAlignmentStrLen:maxAlignmentStrLen];
newDrawingViewImg = UIGraphicsGetImageFromCurrentImageContext();
[self setNeedsDisplay];
UIGraphicsEndImageContext();
[delegate gridFinishedUpdatingWithOffset:currOffset andGridScrollViewContentSizeChanged:scrollViewContentSizeChangedOnLastUpdate];
scrollViewContentSizeChangedOnLastUpdate = NO;
}
- (void)fixScrollViewContentSizeWithMaxAlignmentStrLen:(int)maxAlignmentStrLen {
float maxY = kPosLblHeight+graphBoxHeight+(maxAlignmentStrLen+FoundRow)*(kGridLineWidthRow+boxHeight)+kAlignmentGridExtraSpaceAtBottomOfScrollView;
if (maxY != scrollingView.contentSize.height)
scrollingView.contentSize = CGSizeMake(scrollingView.contentSize.width, maxY);
else if (maxY < self.bounds.size.height && scrollingView.contentSize.height >= self.bounds.size.height)
scrollingView.contentSize = CGSizeMake(scrollingView.contentSize.width, self.bounds.size.height);
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
currYOffset = scrollView.contentOffset.y;
[super scrollViewDidScroll:scrollView];
}
//Create Grid Lines
- (void)drawGridLinesForOffset:(double)offset {
double rgb[3] = {1,1,1};
float x = offset;
float y = kPosLblHeight+graphBoxHeight;
for (int i = 0; i<ARow; i++) {
[self drawRectangle:CGRectMake(x, y, self.frame.size.width+(abs(offset)), kGridLineWidthRow) withRGB:rgb];
y += kGridLineWidthRow+boxHeight;
}
y = kPosLblHeight-(kPosLblTickMarkHeight/2);//See tickMarkConnectingLine code and this makes sense
for (int i = 0; i<totalCols; i++) {
[self drawRectangle:CGRectMake(x, y, self.kGridLineWidthCol, graphBoxHeight+kGridLineWidthRow+kPosLblTickMarkHeight/2+(boxHeight+kGridLineWidthRow)*(kAlignmentGridViewNumOfGridSections-1)) withRGB:rgb];
x += self.kGridLineWidthCol+boxWidth;
if (x > self.frame.size.width)
break;
}
}
- (void)drawCharColumnWithAlignmentGridPos:(AlignmentGridPosition*)gridPos withGridPosIndexInGridPosArr:(int)j atX:(float)x andY:(float)y andYToNotCross:(int)yToNotCross {
if (!gridPos.str)
return;
CGContextSaveGState(UIGraphicsGetCurrentContext());
CGContextClipToRect(UIGraphicsGetCurrentContext(), CGRectMake(0, yToNotCross, self.bounds.size.width, self.bounds.size.height-yToNotCross));
CGPoint point;
NSString *gridPosStr = [NSString stringWithFormat:@"%s",gridPos.str];
for (int i = 0; i < maxCoverageVal; i++) {
BOOL isHiddenReadStart = NO;
if (numOfBoxesPerPixel > kPixelWidth)
if (j-numOfBoxesPerPixel >= 0 && alignmentGridPositionsArr[j-numOfBoxesPerPixel] && gridPos.readIndexStr[i] != alignmentGridPositionsArr[j-numOfBoxesPerPixel].readIndexStr[i] && alignmentGridPositionsArr[j-numOfBoxesPerPixel].readInfoStr[i] != kReadInfoReadStart)
isHiddenReadStart = YES;
BOOL isHiddenReadEnd = NO;
if (!isHiddenReadStart) {
if (numOfBoxesPerPixel > kPixelWidth)
if (j+numOfBoxesPerPixel<dgenomeLen && alignmentGridPositionsArr[j+numOfBoxesPerPixel] && gridPos.readIndexStr[i] != alignmentGridPositionsArr[j+numOfBoxesPerPixel].readIndexStr[i])
isHiddenReadEnd = YES;
}
point = CGPointMake(x, y);
if (gridPos && gridPos.str[i] != kAlignmentGridViewCharColumnNoChar && y + kGridLineWidthRow+boxHeight > yToNotCross) {
int readInfoNum = gridPos.readInfoStr[i];
CGColorRef ref = [dnaColors.alignedRead rgbColorRef];
if (gridPos.str[i] != originalStr[j])
ref = [dnaColors.mutHighlight rgbColorRef];//If I set it to the individual color of each specific mutation, it hurts the eyes to look at
//For adding outline
if (isHiddenReadStart || isHiddenReadEnd)
ref = [dnaColors.black rgbColorRef];
//
if (gridPos.str[i] != originalStr[j] && numOfBoxesPerPixel == kPixelWidth)
ref = [dnaColors.mutHighlight rgbColorRef];
if (numOfBoxesPerPixel > kPixelWidth)
[self drawReadBodyAtPoint:point withColorRef:ref];
else {
if (readInfoNum == kReadInfoReadStart) {
[self drawReadStartAtPoint:point withColorRef:ref];
}
else if (readInfoNum == kReadInfoReadEnd) {
[self drawReadEndAtPoint:point withColorRef:ref];
}
else if (readInfoNum == kReadInfoReadMiddle) {
[self drawReadBodyAtPoint:point withColorRef:ref];
}
else if (readInfoNum == kReadInfoReadPosAfterStart) {
[self drawReadBodyAtPoint:point nextToAnEnd:kReadInfoReadPosAfterStart withColorRef:ref];
}
else if (readInfoNum == kReadInfoReadPosBeforeEnd) {
[self drawReadBodyAtPoint:point nextToAnEnd:kReadInfoReadPosBeforeEnd withColorRef:ref];
}
}
// }
if (kTxtFontSize >= kMinTxtFontSize && boxWidth >= kThresholdBoxWidth) {
// char gridPosChar = [gridPos.str characterAtIndex:i];
char gridPosChar = gridPos.str[i];
RGB *rgb = [self colorForIndexInACGTWithInDelsStr:-1 orChar:gridPosChar usingIndex:NO];
[self drawText:[gridPosStr substringWithRange:NSMakeRange(i, 1)] atPoint:point withRGB:(double[3]){rgb.r, rgb.g,rgb.b}];//May want to change the color for each read or something
}
}
y += kGridLineWidthRow+boxHeight;
if (y > self.bounds.size.height)
break;
}
CGContextRestoreGState(UIGraphicsGetCurrentContext());
}
- (void)drawReadStartAtPoint:(CGPoint)point withColorRef:(CGColorRef)colorRef {
CGRect rect = CGRectMake(point.x, point.y, boxWidth+boxWidth/2, boxHeight);
UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:15.0];
CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(), colorRef);
[bezierPath fill];
//For adding outline
CGContextSaveGState(UIGraphicsGetCurrentContext());
CGContextClipToRect(UIGraphicsGetCurrentContext(), CGRectMake(rect.origin.x-kAlignmentGridPositionStartEndStrokeBorderWidth, rect.origin.y, boxWidth/2+kAlignmentGridPositionStartEndStrokeBorderWidth, rect.size.height));
bezierPath = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:15.0];
CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), [[UIColor blackColor] CGColor]);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), kAlignmentGridPositionStartEndStrokeBorderWidth);
[bezierPath stroke];
CGContextRestoreGState(UIGraphicsGetCurrentContext());
}
- (void)drawReadEndAtPoint:(CGPoint)point withColorRef:(CGColorRef)colorRef {
CGRect rect = CGRectMake(point.x, point.y, boxWidth, boxHeight);
CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(), colorRef);
CGContextFillRect(UIGraphicsGetCurrentContext(), CGRectMake(rect.origin.x, rect.origin.y, rect.size.width/2, rect.size.height));
CGContextSaveGState(UIGraphicsGetCurrentContext());
CGContextClipToRect(UIGraphicsGetCurrentContext(), CGRectMake(rect.origin.x+boxWidth/2, rect.origin.y, rect.size.width, rect.size.height));
UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:15.0];
[bezierPath fill];
//For adding outline
CGContextRestoreGState(UIGraphicsGetCurrentContext());
CGContextSaveGState(UIGraphicsGetCurrentContext());
CGContextClipToRect(UIGraphicsGetCurrentContext(), CGRectMake(rect.origin.x+boxWidth/2, rect.origin.y, rect.size.width, rect.size.height));
bezierPath = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:15.0];
CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), [[UIColor blackColor] CGColor]);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), kAlignmentGridPositionStartEndStrokeBorderWidth);
[bezierPath stroke];
CGContextRestoreGState(UIGraphicsGetCurrentContext());
}
- (void)drawReadBodyAtPoint:(CGPoint)point withColorRef:(CGColorRef)colorRef {
CGRect rect = CGRectMake(point.x, point.y, boxWidth+self.kGridLineWidthCol, boxHeight);
CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(), colorRef);
CGContextFillRect(UIGraphicsGetCurrentContext(), rect);
}
- (void)drawReadBodyAtPoint:(CGPoint)point nextToAnEnd:(int)end withColorRef:(CGColorRef)colorRef {
CGRect rect = CGRectMake(point.x, point.y, boxWidth+self.kGridLineWidthCol, boxHeight);
if (end == kReadInfoReadPosBeforeEnd)
rect = CGRectMake(point.x, point.y, boxWidth+boxWidth/1.5, boxHeight);
CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(), colorRef);
CGContextFillRect(UIGraphicsGetCurrentContext(), rect);
}
//Read long pressed
- (IBAction)readLongPressed:(id)sender {
if (numOfBoxesPerPixel > kPixelWidth)
return;
CGPoint touchLocInGrid = [sender locationInView:self];
if (touchLocInGrid.y < kPosLblHeight+kGridLineWidthRow+graphBoxHeight+FoundRow*(boxHeight+kGridLineWidthRow))//User selected above all the reads (aka the fnd row or higher) so just return bc we have no info to show them pertaining to a read here
return;
CGPoint touchLocInScrollView = [sender locationInView:scrollingView];
CGPoint pt = CGPointMake(touchLocInGrid.x, touchLocInScrollView.y);
//Get the xCoord in the scrollView
double xCoord = self.currOffset+pt.x;
//Find the box that was clicked
CGPoint box = CGPointMake([self firstPtToDrawForOffset:xCoord],(int)((pt.y-(kPosLblHeight+graphBoxHeight))/(kGridLineWidthRow+self.boxHeight))-FoundRow);//Get the tapped box,... subtracts found row because is assuming box.y = 0 would mean the first row for displaying reads
int index = alignmentGridPositionsArr[(int)box.x].readIndexStr[(int)box.y];
if (index < 0 || alignmentGridPositionsArr[(int)box.x].str[(int)box.y] == kAlignmentGridViewCharColumnNoChar)
return;
ED_Info *read = [readAlignmentsArr objectAtIndex:index];
printf("\n\n%s\n\n%s",read.gappedA, read.gappedB);
[self displayReadPopoverForRead:read atPosInGenome:box.x atPointOnScreen:[sender locationInView:self.superview]];
}
- (void)displayReadPopoverForRead:(ED_Info *)read atPosInGenome:(int)pos atPointOnScreen:(CGPoint)point {
ReadPopoverController *controller = [[ReadPopoverController alloc] init];
[controller setUpWithRead:read];
controller.preferredContentSize = controller.view.bounds.size;
[delegate displayPopoverWithViewController:controller atPoint:point withTitle:kReadPopoverTitleInIPhonePopoverHandler];
}
- (void)freeUsedMemory {
for (int i = 0; i < dgenomeLen; i++) {
AlignmentGridPosition *pos = alignmentGridPositionsArr[i];
free(pos.str);
free(pos.readInfoStr);
free(pos.readIndexStr);
alignmentGridPositionsArr[i] = nil;
}
free(alignmentGridPositionsArr);
}
@end