@@ -53,28 +53,30 @@ clean_duplicates <- function(setup, segs, xy_thresh = 1, z_thresh = 10, compare_
53
53
# Search and identify cells that have the same x,y coordinate
54
54
for (r in 1 : n_rows ){ # r for row
55
55
for (c in 1 : n_cols ) { # c for column
56
- if (! is.na(segs $ segmentations [[s ]]$ soma $ x [r ])) {
57
- ind_x <- which.min(abs(segs $ segmentations [[s + c ]]$ soma $ x - segs $ segmentations [[s ]]$ soma $ x [r ]))
58
- ind_y <- which.min(abs(segs $ segmentations [[s + c ]]$ soma $ y - segs $ segmentations [[s ]]$ soma $ y [r ]))
59
- if ((length(ind_x ) != 0 ) & (length(ind_y ) != 0 )){
60
- if (ind_x == ind_y ){
61
- comp_matrix [r ,c + 1 ] <- ind_x
62
- # exact_overlap_cnt <- exact_overlap_cnt + 1
56
+ if (length(is.na(segs $ segmentations [[s ]]$ soma $ x [r ])) != 0 ){
57
+ if (! is.na(segs $ segmentations [[s ]]$ soma $ x [r ])) {
58
+ ind_x <- which.min(abs(segs $ segmentations [[s + c ]]$ soma $ x - segs $ segmentations [[s ]]$ soma $ x [r ]))
59
+ ind_y <- which.min(abs(segs $ segmentations [[s + c ]]$ soma $ y - segs $ segmentations [[s ]]$ soma $ y [r ]))
60
+ if ((length(ind_x ) != 0 ) & (length(ind_y ) != 0 )){
61
+ if (ind_x == ind_y ){
62
+ comp_matrix [r ,c + 1 ] <- ind_x
63
+ # exact_overlap_cnt <- exact_overlap_cnt + 1
63
64
64
- } else {
65
- # in cells isolated by x, threshold by difference in y
66
- diff_y <- abs(segs $ segmentations [[s + c ]]$ soma $ y [ind_x ] - segs $ segmentations [[s ]]$ soma $ y [r ])
65
+ } else {
66
+ # in cells isolated by x, threshold by difference in y
67
+ diff_y <- abs(segs $ segmentations [[s + c ]]$ soma $ y [ind_x ] - segs $ segmentations [[s ]]$ soma $ y [r ])
67
68
68
- # in cells isolated by y, threshold by difference in x
69
- diff_x <- abs(segs $ segmentations [[s + c ]]$ soma $ x [ind_y ] - segs $ segmentations [[s ]]$ soma $ x [r ])
69
+ # in cells isolated by y, threshold by difference in x
70
+ diff_x <- abs(segs $ segmentations [[s + c ]]$ soma $ x [ind_y ] - segs $ segmentations [[s ]]$ soma $ x [r ])
70
71
71
- if (diff_y < diff_x & diff_y < xy_thresh ) {
72
- comp_matrix [r ,c + 1 ] <- ind_x
73
- # thresh_overlap_cnt <- thresh_overlap_cnt + 1
72
+ if (diff_y < diff_x & diff_y < xy_thresh ) {
73
+ comp_matrix [r ,c + 1 ] <- ind_x
74
+ # thresh_overlap_cnt <- thresh_overlap_cnt + 1
74
75
75
- } else if (diff_x < diff_y & diff_x < xy_thresh ) {
76
- comp_matrix [r ,c + 1 ] <- ind_y
77
- # thresh_overlap_cnt <- thresh_overlap_cnt + 1
76
+ } else if (diff_x < diff_y & diff_x < xy_thresh ) {
77
+ comp_matrix [r ,c + 1 ] <- ind_y
78
+ # thresh_overlap_cnt <- thresh_overlap_cnt + 1
79
+ }
78
80
}
79
81
}
80
82
}
@@ -90,7 +92,7 @@ clean_duplicates <- function(setup, segs, xy_thresh = 1, z_thresh = 10, compare_
90
92
91
93
92
94
# ## start if else statement for last 5 columns here
93
- while (sep_cnt < sep_z && c != n_cols + 1 ) {
95
+ while (sep_cnt < sep_z && c != n_cols + 1 & length( comp_matrix > 0 ) ) {
94
96
prev <- is.na(comp_matrix [r ,c ])
95
97
cur <- is.na(comp_matrix [r ,c + 1 ])
96
98
if (cur ) {
@@ -114,8 +116,12 @@ clean_duplicates <- function(setup, segs, xy_thresh = 1, z_thresh = 10, compare_
114
116
intensities <- vector(length = end_soma )
115
117
116
118
for (c in 1 : end_soma ) {
117
- if (! is.na(comp_matrix [r ,c ])) {
118
- intensities [c ] <- segs $ segmentations [[s + c - 1 ]]$ soma $ intensity [comp_matrix [r ,c ]]
119
+ if (length(comp_matrix ) > 0 ){
120
+ if (! is.na(comp_matrix [r ,c ])) {
121
+ intensities [c ] <- segs $ segmentations [[s + c - 1 ]]$ soma $ intensity [comp_matrix [r ,c ]]
122
+ } else {
123
+ intensities [c ] <- NA
124
+ }
119
125
} else {
120
126
intensities [c ] <- NA
121
127
}
0 commit comments