Skip to content

Commit f68d656

Browse files
run 2to3 (only changes one import and adds '()' to a lot of print statement
1 parent a7a5400 commit f68d656

File tree

1 file changed

+46
-46
lines changed

1 file changed

+46
-46
lines changed

src/CombineNearbyInteraction.py

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import math
3232
from optparse import OptionParser
3333
import networkx as nx
34-
from Queue import heapq
34+
from queue import heapq
3535

3636
#==========================================================
3737
# this function returns the element below which top K % of
@@ -145,21 +145,21 @@ def main():
145145

146146
# print the parameters
147147
if 1:
148-
print '****** Merge filtering of adjacent loops is enabled *****'
149-
print '***** within function of merged filtering - printing the parameters ***'
150-
print '*** bin_size: ', bin_size
151-
print '*** headerInp: ', headerInp
152-
print '*** connectivity_rule: ', connectivity_rule
153-
print '*** TopPctElem: ', TopPctElem
154-
print '*** NeighborHoodBinThr: ', NeighborHoodBinThr
155-
print '*** QValCol: ', QValCol
156-
print '*** PValCol: ', PValCol
157-
print '*** SortOrder: ', SortOrder
148+
print('****** Merge filtering of adjacent loops is enabled *****')
149+
print('***** within function of merged filtering - printing the parameters ***')
150+
print('*** bin_size: ', bin_size)
151+
print('*** headerInp: ', headerInp)
152+
print('*** connectivity_rule: ', connectivity_rule)
153+
print('*** TopPctElem: ', TopPctElem)
154+
print('*** NeighborHoodBinThr: ', NeighborHoodBinThr)
155+
print('*** QValCol: ', QValCol)
156+
print('*** PValCol: ', PValCol)
157+
print('*** SortOrder: ', SortOrder)
158158

159159
# output directory
160160
OutDir = os.path.dirname(os.path.realpath(OutFile))
161161
if 1:
162-
print 'OutDir: ', str(OutDir)
162+
print('OutDir: ', str(OutDir))
163163

164164
# open the output file
165165
# if input interaction file has header information,
@@ -196,7 +196,7 @@ def main():
196196
for l in fp_in.readlines():
197197
currchrname = (l.rstrip()).split()[0]
198198
TargetChrList.append(currchrname)
199-
print 'list of chromosomes: ', str(TargetChrList)
199+
print('list of chromosomes: ', str(TargetChrList))
200200
# remove temporary files
201201
sys_cmd = "rm " + temp_chr_log_file
202202
os.system(sys_cmd)
@@ -207,7 +207,7 @@ def main():
207207
for chridx in range(len(TargetChrList)):
208208
curr_chr = TargetChrList[chridx]
209209
if 1:
210-
print 'Processing the chromosome: ', str(curr_chr)
210+
print('Processing the chromosome: ', str(curr_chr))
211211

212212
# extract the interactions of current chromosome from the complete set of interactions
213213
tempchrdumpfile = OutDir + '/Temp_chr_Dump.bed'
@@ -222,11 +222,11 @@ def main():
222222

223223
if (num_Int == 0):
224224
if 0:
225-
print 'Number of interactions for this chromosome = 0 --- continue'
225+
print('Number of interactions for this chromosome = 0 --- continue')
226226
continue
227227

228228
if 0:
229-
print 'Extracted interactions for the current chromosome'
229+
print('Extracted interactions for the current chromosome')
230230

231231
# # extract also the max span of interactions (6th column maximum element)
232232
# # so as to estimate the matrix size
@@ -271,7 +271,7 @@ def main():
271271
# add the node to the given graph as well
272272
G.add_node(curr_key)
273273
if 0:
274-
print 'Current interaction: ', str(line), ' ------ curr_key: ', curr_key
274+
print('Current interaction: ', str(line), ' ------ curr_key: ', curr_key)
275275

276276
# now check the nodes of G
277277
# assign edges of G according to the 8 / 4 connectivity rule (according to the input parameter)
@@ -282,35 +282,35 @@ def main():
282282
for j in range(i+1, len(nodelist)):
283283
node2 = nodelist[j]
284284
if 0:
285-
print 'Checking the edge between node 1: ', node1, ' and node 2: ', node2
285+
print('Checking the edge between node 1: ', node1, ' and node 2: ', node2)
286286
# check if there should be an edge between node1 and node2
287287
# according to the desired connectivity rule
288288
if (connectivity_rule == 8):
289289
if (abs(node1[0] - node2[0]) <= 1) and (abs(node1[1] - node2[1]) <= 1):
290290
G.add_edge(node1, node2)
291291
if 0:
292-
print '8 connectivity Edge between node 1: ', node1, ' and node 2: ', node2
292+
print('8 connectivity Edge between node 1: ', node1, ' and node 2: ', node2)
293293
if (connectivity_rule == 4):
294294
if ((abs(node1[0] - node2[0]) + abs(node1[1] - node2[1])) <= 1):
295295
G.add_edge(node1, node2)
296296
if 0:
297-
print '4 connectivity Edge between node 1: ', node1, ' and node 2: ', node2
297+
print('4 connectivity Edge between node 1: ', node1, ' and node 2: ', node2)
298298

299299
# check the edges of G
300300
edgelist = list(G.edges())
301301

302302
if 1:
303-
print 'No of nodes of G: ', G.number_of_nodes()
304-
print 'No of edges of G: ', G.number_of_edges()
305-
print 'Number of connected components of G: ', nx.number_connected_components(G)
303+
print('No of nodes of G: ', G.number_of_nodes())
304+
print('No of edges of G: ', G.number_of_edges())
305+
print('Number of connected components of G: ', nx.number_connected_components(G))
306306

307307
# scan through individual connected components
308308
# for each such connected component (list of interactions)
309309
# we find a representative interaction and print it in the final output file
310310
list_conn_comp = sorted(nx.connected_components(G), key = len, reverse=True)
311311

312312
if 0:
313-
print '\n\n**** Number of connected components: ', len(list_conn_comp), ' ****\n\n'
313+
print('\n\n**** Number of connected components: ', len(list_conn_comp), ' ****\n\n')
314314

315315
#====================
316316
# process individual connected components
@@ -319,31 +319,31 @@ def main():
319319
# a connected component - a particular list of connected nodes
320320
curr_comp_list = list(list_conn_comp[i])
321321
if 0:
322-
print '\n\n\n ===>>>>> Processing the connected component no: ', i, ' list: ', str(curr_comp_list), ' number of elements: ', len(curr_comp_list)
322+
print('\n\n\n ===>>>>> Processing the connected component no: ', i, ' list: ', str(curr_comp_list), ' number of elements: ', len(curr_comp_list))
323323

324324
# from the first interacting bin set, get the lower and higher bin index
325325
min_idx_bin1 = min([x[0] for x in curr_comp_list])
326326
max_idx_bin1 = max([x[0] for x in curr_comp_list])
327327
if 0:
328-
print 'min_idx_bin1: ', min_idx_bin1, ' max_idx_bin1: ', max_idx_bin1
328+
print('min_idx_bin1: ', min_idx_bin1, ' max_idx_bin1: ', max_idx_bin1)
329329

330330
# get the span of coordinates for the first interacting bin (set)
331331
span_low_bin1 = (min_idx_bin1 - 1) * bin_size
332332
span_high_bin1 = max_idx_bin1 * bin_size
333333
if 0:
334-
print 'span_low_bin1: ', span_low_bin1, ' span_high_bin1: ', span_high_bin1
334+
print('span_low_bin1: ', span_low_bin1, ' span_high_bin1: ', span_high_bin1)
335335

336336
# from the second interacting bin set, get the lower and higher bin index
337337
min_idx_bin2 = min([x[1] for x in curr_comp_list])
338338
max_idx_bin2 = max([x[1] for x in curr_comp_list])
339339
if 0:
340-
print 'min_idx_bin2: ', min_idx_bin2, ' max_idx_bin2: ', max_idx_bin2
340+
print('min_idx_bin2: ', min_idx_bin2, ' max_idx_bin2: ', max_idx_bin2)
341341

342342
# get the span of coordinates for the first interacting bin (set)
343343
span_low_bin2 = (min_idx_bin2 - 1) * bin_size
344344
span_high_bin2 = max_idx_bin2 * bin_size
345345
if 0:
346-
print 'span_low_bin2: ', span_low_bin2, ' span_high_bin2: ', span_high_bin2
346+
print('span_low_bin2: ', span_low_bin2, ' span_high_bin2: ', span_high_bin2)
347347

348348
# sum of contact counts for all the interacting bins
349349
# within this set of connected nodes
@@ -365,7 +365,7 @@ def main():
365365
Percent_Significant_BinPair = (possible_bin_pairs * 1.0) / total_possible_bin_pairs
366366

367367
if 0:
368-
print ' ==>>> total_possible_bin_pairs: ', total_possible_bin_pairs, ' possible_bin_pairs: ', possible_bin_pairs, ' % clique: ', Percent_Significant_BinPair
368+
print(' ==>>> total_possible_bin_pairs: ', total_possible_bin_pairs, ' possible_bin_pairs: ', possible_bin_pairs, ' % clique: ', Percent_Significant_BinPair)
369369

370370

371371
#==================================================
@@ -387,7 +387,7 @@ def main():
387387
curr_key_bin1_mid = (((curr_key[0] - 1) * bin_size) + (curr_key[0] * bin_size)) / 2
388388
curr_key_bin2_mid = (((curr_key[1] - 1) * bin_size) + (curr_key[1] * bin_size)) / 2
389389
if 0:
390-
print ' Connected component index: ', j, ' curr_key: ', curr_key, ' bin 1 mid: ', curr_key_bin1_mid, ' bin 2 mid: ', curr_key_bin2_mid, ' CC: ', curr_cc, ' Pval: ', curr_pval, ' Qval: ', curr_qval
390+
print(' Connected component index: ', j, ' curr_key: ', curr_key, ' bin 1 mid: ', curr_key_bin1_mid, ' bin 2 mid: ', curr_key_bin2_mid, ' CC: ', curr_cc, ' Pval: ', curr_pval, ' Qval: ', curr_qval)
391391
if (j == 0):
392392
# first index
393393
rep_bin_key = curr_key
@@ -412,7 +412,7 @@ def main():
412412
qval = CurrChrDict[rep_bin_key]._GetQVal()
413413

414414
if 0:
415-
print '**** Selected bin key: ', rep_bin_key, ' start bin mid: ', (rep_bin1_low + rep_bin1_high)/2, ' end bin mid: ', (rep_bin2_low + rep_bin2_high) / 2, ' cc: ', cc, ' pval: ', pval, ' qval: ', qval
415+
print('**** Selected bin key: ', rep_bin_key, ' start bin mid: ', (rep_bin1_low + rep_bin1_high)/2, ' end bin mid: ', (rep_bin2_low + rep_bin2_high) / 2, ' cc: ', cc, ' pval: ', pval, ' qval: ', qval)
416416

417417
# write the interaction in the specified output file
418418
fp_outInt.write('\n' + str(curr_chr) + '\t' + str(rep_bin1_low) + '\t' + str(rep_bin1_high) + '\t' + str(curr_chr) + '\t' + str(rep_bin2_low) + '\t' + str(rep_bin2_high) + '\t' + str(cc) + '\t' + str(pval) + '\t' + str(qval) + '\t' + str(span_low_bin1) + '\t' + str(span_high_bin1) + '\t' + str(span_low_bin2) + '\t' + str(span_high_bin2) + '\t' + str(sum_cc) + '\t' + str(Percent_Significant_BinPair))
@@ -468,7 +468,7 @@ def main():
468468
custom_qval = custom_percent(curr_conn_comp_QValList, TopPctElem, (SortOrder+1))
469469

470470
if 0:
471-
print ' --> current connected component: max CC: ', max_cc, ' min Q val: ', min_qval, ' top K (TopPctElem): ', TopPctElem, ' custom_cc threshold: ', custom_cc, ' custom_qval threshold: ', custom_qval
471+
print(' --> current connected component: max CC: ', max_cc, ' min Q val: ', min_qval, ' top K (TopPctElem): ', TopPctElem, ' custom_cc threshold: ', custom_cc, ' custom_qval threshold: ', custom_qval)
472472

473473
# this list stores the candidate interactions
474474
# from this particular connected component
@@ -479,7 +479,7 @@ def main():
479479
while (len(Curr_Comp_Tuple_List) > 0):
480480
curr_elem = heapq.heappop(Curr_Comp_Tuple_List)
481481
if 0:
482-
print 'extracted element from heap: ', curr_elem
482+
print('extracted element from heap: ', curr_elem)
483483

484484
#===================================
485485
# earlier condition - 1 - sourya
@@ -509,7 +509,7 @@ def main():
509509
subl = [curr_elem[2], curr_elem[3]]
510510
Final_Rep_Key_List.append(subl)
511511
if 0:
512-
print '\t\t *** inserted element in the final list: ', str(subl), ' generated Final_Rep_Key_List: ', str(Final_Rep_Key_List)
512+
print('\t\t *** inserted element in the final list: ', str(subl), ' generated Final_Rep_Key_List: ', str(Final_Rep_Key_List))
513513
continue
514514

515515
# otherwise, check with the existing interactions
@@ -523,7 +523,7 @@ def main():
523523
if (((abs(Final_Rep_Key_List[i][0] - curr_elem[2])) * bin_size) <= NeighborHoodBinThr) and (((abs(Final_Rep_Key_List[i][1] - curr_elem[3])) * bin_size) <= NeighborHoodBinThr):
524524
flag = True
525525
if 0:
526-
print ' --- current element is within neighborhood of the bins indexed by ', i, ' of Final_Rep_Key_List'
526+
print(' --- current element is within neighborhood of the bins indexed by ', i, ' of Final_Rep_Key_List')
527527
break
528528

529529
if (flag == False):
@@ -532,7 +532,7 @@ def main():
532532
subl = [curr_elem[2], curr_elem[3]]
533533
Final_Rep_Key_List.append(subl)
534534
if 0:
535-
print '\t\t *** inserted element in the final list: ', str(subl), ' generated Final_Rep_Key_List: ', str(Final_Rep_Key_List)
535+
print('\t\t *** inserted element in the final list: ', str(subl), ' generated Final_Rep_Key_List: ', str(Final_Rep_Key_List))
536536

537537
# now print the candidate interactions
538538
# of the current component
@@ -549,7 +549,7 @@ def main():
549549
qval = CurrChrDict[rep_bin_key]._GetQVal()
550550

551551
if 0:
552-
print '**** Selected bin key: ', rep_bin_key, ' start bin mid: ', (rep_bin1_low + rep_bin1_high)/2, ' end bin mid: ', (rep_bin2_low + rep_bin2_high) / 2, ' cc: ', cc, ' pval: ', pval, ' qval: ', qval
552+
print('**** Selected bin key: ', rep_bin_key, ' start bin mid: ', (rep_bin1_low + rep_bin1_high)/2, ' end bin mid: ', (rep_bin2_low + rep_bin2_high) / 2, ' cc: ', cc, ' pval: ', pval, ' qval: ', qval)
553553

554554
# write the interaction in the specified output file
555555
fp_outInt.write('\n' + str(curr_chr) + '\t' + str(rep_bin1_low) + '\t' + str(rep_bin1_high) + '\t' + str(curr_chr) + '\t' + str(rep_bin2_low) + '\t' + str(rep_bin2_high) + '\t' + str(cc) + '\t' + str(pval) + '\t' + str(qval) + '\t' + str(span_low_bin1) + '\t' + str(span_high_bin1) + '\t' + str(span_low_bin2) + '\t' + str(span_high_bin2) + '\t' + str(sum_cc) + '\t' + str(Percent_Significant_BinPair))
@@ -599,23 +599,23 @@ def main():
599599
Final_Rep_Key_List = []
600600

601601
if 0:
602-
print ' **** Processing the connected component ===== number of elements: ', len(Curr_Comp_Tuple_List)
602+
print(' **** Processing the connected component ===== number of elements: ', len(Curr_Comp_Tuple_List))
603603

604604
# now extract elements from the constructed queue
605605
while (len(Curr_Comp_Tuple_List) > 0):
606606
# extract the first element from the min-heap
607607
# element with the lowest value
608608
curr_elem = heapq.heappop(Curr_Comp_Tuple_List)
609609
if 0:
610-
print 'extracted element from heap: ', curr_elem
610+
print('extracted element from heap: ', curr_elem)
611611

612612
# if this is the first element
613613
# then insert they key in the candidate set of interactions
614614
if (len(Final_Rep_Key_List) == 0):
615615
subl = [curr_elem[2], curr_elem[3]]
616616
Final_Rep_Key_List.append(subl)
617617
if 0:
618-
print '*** inserted element in the final list: ', str(subl)
618+
print('*** inserted element in the final list: ', str(subl))
619619
continue
620620

621621
# otherwise, check with the existing interactions
@@ -629,7 +629,7 @@ def main():
629629
if (((abs(Final_Rep_Key_List[i][0] - curr_elem[2])) * bin_size) <= NeighborHoodBinThr) and (((abs(Final_Rep_Key_List[i][1] - curr_elem[3])) * bin_size) <= NeighborHoodBinThr):
630630
flag = True
631631
if 0:
632-
print ' --- current element is within neighborhood of the existing (included) bin ', Final_Rep_Key_List[i]
632+
print(' --- current element is within neighborhood of the existing (included) bin ', Final_Rep_Key_List[i])
633633
break
634634

635635
if (flag == False):
@@ -638,12 +638,12 @@ def main():
638638
subl = [curr_elem[2], curr_elem[3]]
639639
Final_Rep_Key_List.append(subl)
640640
if 0:
641-
print '*** inserted element in the final list: ', str(subl)
641+
print('*** inserted element in the final list: ', str(subl))
642642

643643
# now print the candidate interactions
644644
# of the current component
645645
if 0:
646-
print '\n\n**** Printing selected loops of the connected component ***\n\n'
646+
print('\n\n**** Printing selected loops of the connected component ***\n\n')
647647

648648
for i in range(len(Final_Rep_Key_List)):
649649
rep_bin_key = (Final_Rep_Key_List[i][0], Final_Rep_Key_List[i][1])
@@ -657,7 +657,7 @@ def main():
657657
pval = CurrChrDict[rep_bin_key]._GetPVal()
658658
qval = CurrChrDict[rep_bin_key]._GetQVal()
659659
if 0:
660-
print 'Selected bin key: ', rep_bin_key, ' start bin mid: ', (rep_bin1_low + rep_bin1_high)/2, ' end bin mid: ', (rep_bin2_low + rep_bin2_high) / 2, ' cc: ', cc, ' pval: ', pval, ' qval: ', qval
660+
print('Selected bin key: ', rep_bin_key, ' start bin mid: ', (rep_bin1_low + rep_bin1_high)/2, ' end bin mid: ', (rep_bin2_low + rep_bin2_high) / 2, ' cc: ', cc, ' pval: ', pval, ' qval: ', qval)
661661

662662
# write the interaction in the specified output file
663663
fp_outInt.write('\n' + str(curr_chr) + '\t' + str(rep_bin1_low) + '\t' + str(rep_bin1_high) + '\t' + str(curr_chr) + '\t' + str(rep_bin2_low) + '\t' + str(rep_bin2_high) + '\t' + str(cc) + '\t' + str(pval) + '\t' + str(qval) + '\t' + str(span_low_bin1) + '\t' + str(span_high_bin1) + '\t' + str(span_low_bin2) + '\t' + str(span_high_bin2) + '\t' + str(sum_cc) + '\t' + str(Percent_Significant_BinPair))
@@ -677,7 +677,7 @@ def main():
677677
os.system(sys_cmd)
678678

679679
if 1:
680-
print '==================== End of merge filtering adjacent interactions !!! ======================'
680+
print('==================== End of merge filtering adjacent interactions !!! ======================')
681681

682682
#===============================================
683683
if __name__ == "__main__":

0 commit comments

Comments
 (0)