Skip to content

Commit dad4dc7

Browse files
committed
back to version that do not remove the religation products
1 parent 534339b commit dad4dc7

File tree

2 files changed

+8
-47
lines changed

2 files changed

+8
-47
lines changed

scripts/mapped_2hic_fragments.py

+7-46
Original file line numberDiff line numberDiff line change
@@ -247,40 +247,11 @@ def get_overlapping_restriction_fragment(resFrag, chrom, read):
247247
return None
248248

249249

250-
def are_contiguous_fragments(frag1, frag2, chr1, chr2):
251-
'''
252-
Compare fragment positions to check if they are contiguous
253-
'''
254-
ret = False
255-
if chr1 == chr2:
256-
if int(frag1.start) < int(frag2.start):
257-
d = int(frag2.start) - int(frag1.end)
258-
else:
259-
d = int(frag1.start) - int(frag2.end)
260-
261-
if d == 0:
262-
ret = True
263-
264-
return ret
265-
266-
def is_religation(read1, read2, frag1, frag2):
267-
"""
268-
Reads are expected to map adjacent fragments
269-
Check the orientation of reads -><-
270-
271-
"""
272-
ret=False
273-
if are_contiguous_fragments(frag1, frag2, read1.tid, read2.tid):
274-
if get_read_strand(r1) == "+" and get_read_strand(r2) == "-":
275-
ret=True
276-
return ret
277-
278-
279250
def is_self_circle(read1, read2):
280251
"""
281252
Both reads are expected to be on the same restriction fragments
282-
Check the orientation of reads <-->
283253
254+
Check the orientation of reads <-->
284255
read1 : [AlignedRead]
285256
read2 : [AlignedRead]
286257
"""
@@ -313,6 +284,7 @@ def is_dangling_end(read1, read2):
313284
def get_valid_orientation(read1, read2):
314285
"""
315286
Both reads are expected to be on the different restriction fragments
287+
316288
Check the orientation of reads ->-> / <-<- / -><- / <-->
317289
318290
read1 : [AlignedRead]
@@ -346,7 +318,6 @@ def get_PE_fragment_size(read1, read2, resFrag1, resFrag2, interactionType):
346318
interactionType : Type of interaction from get_interaction_type() [str]
347319
348320
"""
349-
350321
fragmentsize = None
351322

352323
# Get oriented reads
@@ -359,11 +330,11 @@ def get_PE_fragment_size(read1, read2, resFrag1, resFrag2, interactionType):
359330
rfrag1 = resFrag1
360331
rfrag2 = resFrag2
361332

362-
## In this case use the read 3' end !
333+
## In this case used the read 3' end !
363334
r1pos = get_read_start(r1)
364335
r2pos = get_read_start(r2)
365336

366-
if interactionType == "DE" or interactionType == "RE":
337+
if interactionType == "DE":
367338
fragmentsize = r2pos - r1pos
368339
elif interactionType == "SC":
369340
fragmentsize = (r1pos - rfrag1.start) + (rfrag2.end - r2pos)
@@ -392,7 +363,6 @@ def get_interaction_type(read1, read1_chrom, resfrag1, read2,
392363
- Interaction
393364
- Self circle
394365
- Dangling end
395-
- Religation
396366
- Unknown
397367
398368
##
@@ -405,7 +375,6 @@ def get_interaction_type(read1, read1_chrom, resfrag1, read2,
405375
verbose = verbose mode [logical]
406376
407377
"""
408-
409378
# If returned InteractionType=None -> Same restriction fragment
410379
# and same strand = Dump
411380
interactionType = None
@@ -419,8 +388,6 @@ def get_interaction_type(read1, read1_chrom, resfrag1, read2,
419388
# Dangling_end -> <-
420389
elif is_dangling_end(read1, read2):
421390
interactionType = "DE"
422-
elif is_religation(read1, read2, resfrag1, resfrag2):
423-
interactionType = "RE"
424391
else:
425392
interactionType = "VI"
426393
elif r1.is_unmapped or r2.is_unmapped:
@@ -501,7 +468,6 @@ def get_read_tag(read, tag):
501468
# Initialize variables
502469
reads_counter = 0
503470
de_counter = 0
504-
re_counter = 0
505471
sc_counter = 0
506472
valid_counter = 0
507473
valid_counter_FF = 0
@@ -531,7 +497,6 @@ def get_read_tag(read, tag):
531497

532498
if allOutput:
533499
handle_de = open(outputDir + '/' + baseReadsFile + '.DEPairs', 'w')
534-
handle_re = open(outputDir + '/' + baseReadsFile + '.REPairs', 'w')
535500
handle_sc = open(outputDir + '/' + baseReadsFile + '.SCPairs', 'w')
536501
handle_dump = open(outputDir + '/' + baseReadsFile + '.DumpPairs', 'w')
537502
handle_single = open(outputDir + '/' + baseReadsFile + '.SinglePairs', 'w')
@@ -580,7 +545,9 @@ def get_read_tag(read, tag):
580545
r2_resfrag = None
581546
r2_chrom = None
582547

548+
583549
if r1_resfrag is not None or r2_resfrag is not None:
550+
584551
interactionType = get_interaction_type(r1, r1_chrom, r1_resfrag, r2, r2_chrom, r2_resfrag, verbose)
585552
dist = get_PE_fragment_size(r1, r2, r1_resfrag, r2_resfrag, interactionType)
586553
cdist = get_cis_dist(r1, r2)
@@ -641,10 +608,6 @@ def get_read_tag(read, tag):
641608
de_counter += 1
642609
cur_handler = handle_de if allOutput else None
643610

644-
elif interactionType == "RE":
645-
re_counter += 1
646-
cur_handler = handle_re if allOutput else None
647-
648611
elif interactionType == "SC":
649612
sc_counter += 1
650613
cur_handler = handle_sc if allOutput else None
@@ -729,13 +692,13 @@ def get_read_tag(read, tag):
729692
or2_fragname + "\t" +
730693
str(or1.mapping_quality) + "\t" +
731694
str(or2.mapping_quality) + "\n")
732-
733695
## Keep initial order
734696
if samOut:
735697
r1.tags = r1.tags + [('CT', str(interactionType))]
736698
r2.tags = r2.tags + [('CT', str(interactionType))]
737699
handle_sam.write(r1)
738700
handle_sam.write(r2)
701+
739702

740703
if (reads_counter % 100000 == 0 and verbose):
741704
print "##", reads_counter
@@ -744,7 +707,6 @@ def get_read_tag(read, tag):
744707
handle_valid.close()
745708
if allOutput:
746709
handle_de.close()
747-
handle_re.close()
748710
handle_sc.close()
749711
handle_dump.close()
750712
handle_single.close()
@@ -762,7 +724,6 @@ def get_read_tag(read, tag):
762724
handle_stat.write(
763725
"Valid_interaction_pairs_FR\t" + str(valid_counter_FR) + "\n")
764726
handle_stat.write("Dangling_end_pairs\t" + str(de_counter) + "\n")
765-
handle_stat.write("Religation_pairs\t" + str(re_counter) + "\n")
766727
handle_stat.write("Self_Cycle_pairs\t" + str(sc_counter) + "\n")
767728
handle_stat.write("Single-end_pairs\t" + str(single_counter) + "\n")
768729
handle_stat.write("Dumped_pairs\t" + str(dump_counter) + "\n")

scripts/plot_hic_fragment.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ if (la > 0){
2525
getHiCMat <- function(x){
2626
require(RColorBrewer)
2727

28-
invalid.lab <- intersect(names(x), c("Self_Cycle_pairs", "Dangling_end_pairs", "Religation_pairs", "Single-end_pairs", "Dumped_pairs"))
28+
invalid.lab <- intersect(names(x), c("Self_Cycle_pairs", "Dangling_end_pairs", "Single-end_pairs", "Dumped_pairs"))
2929
valid.lab <- intersect(names(x), c("Valid_interaction_pairs_FF", "Valid_interaction_pairs_RR", "Valid_interaction_pairs_RF", "Valid_interaction_pairs_FR"))
3030
x <- x[c("Valid_interaction_pairs", valid.lab, invalid.lab)]
3131

0 commit comments

Comments
 (0)