Skip to content

Commit

Permalink
change way to decide the open/nuc/bg states
Browse files Browse the repository at this point in the history
  • Loading branch information
taoliu committed Oct 4, 2022
1 parent 77ffc3c commit 27e4cb3
Show file tree
Hide file tree
Showing 4 changed files with 294 additions and 1,175 deletions.
13 changes: 10 additions & 3 deletions MACS3/Commands/hmmratac_cmd.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Time-stamp: <2022-10-04 15:13:57 Tao Liu>
# Time-stamp: <2022-10-04 16:58:30 Tao Liu>

"""Description: Main HMMR command
Expand Down Expand Up @@ -243,8 +243,15 @@ def run( args ):
options.info( f"# HMM converged: {hmm_model.monitor_.converged}")

# label hidden states
i_open_region = np.where(hmm_model.means_ == max(hmm_model.means_[0:3,0]))[0][0]
i_background_region = np.where(hmm_model.transmat_ == min(hmm_model.transmat_[0:3, i_open_region]))[0][0]
means_sum = np.sum( hmm_model.means_, axis=1 )

# first, the state with the highest overall emission is the open state
i_open_region = np.where( means_sum == max(means_sum) )[0][0]

# second, the state with lowest overall emission is the bg state
i_background_region = np.where( means_sum == min(means_sum) )[0][0]

# last one is the nuc state (note it may not be accurate though
i_nucleosomal_region = list(set([0, 1, 2]) - set([i_open_region, i_background_region]))[0]

# write hmm into model file
Expand Down
4 changes: 2 additions & 2 deletions MACS3/Signal/BedGraph.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# cython: language_level=3
# cython: profile=True
# Time-stamp: <2022-09-29 09:07:23 Tao Liu>
# Time-stamp: <2022-10-04 15:46:00 Tao Liu>

"""Module for BedGraph data class.
Expand Down Expand Up @@ -981,7 +981,7 @@ cdef class bedGraphTrackI:
int32_t pre_p, p1, p2, i
float32_t v1, v2
bytes chrom
object ret
list ret

assert isinstance(bdgTrack2,bedGraphTrackI), "not a bedGraphTrackI object"

Expand Down
14 changes: 5 additions & 9 deletions MACS3/Signal/HMMR_Signal_Processing.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# cython: language_level=3
# cython: profile=True
# Time-stamp: <2022-09-29 14:58:12 Tao Liu>
# Time-stamp: <2022-10-04 16:14:23 Tao Liu>

"""Module description:
Expand Down Expand Up @@ -155,23 +155,19 @@ cpdef list extract_signals_from_regions( list signals, object regions, int binsi
assert len( extracted_data[0] ) == len( extracted_data[1] )
assert len( extracted_data[0] ) == len( extracted_data[2] )
assert len( extracted_data[0] ) == len( extracted_data[3] )
#nnn =len( extracted_len[0] )
#debug( f"{n} bins, {nn}, {nnn}" )
counter = 0
prev_c = extracted_len[0][0]
c = 0
for i in range( nn ):
ret_training_bins.append( extracted_positions[0][i] )
ret_training_data.append(
[ max( 0.0001, abs(round(extracted_data[0][i], 4))),
max( 0.0001, abs(round(extracted_data[1][i], 4))),
max( 0.0001, abs(round(extracted_data[2][i], 4))),
max( 0.0001, abs(round(extracted_data[3][i], 4))) ] )
[ max( 0.0001, extracted_data[0][i] ),
max( 0.0001, extracted_data[1][i] ),
max( 0.0001, extracted_data[2][i] ),
max( 0.0001, extracted_data[3][i] ) ] )
c = extracted_len[0][i]
#print(f"{extracted_positions[0][i]} {extracted_len[0][i]}")
if counter != 0 and c != prev_c:
ret_training_lengths.append( counter )
#print(f"### add a bin length {counter}")
counter = 0
prev_c = c
counter += 1
Expand Down
Loading

0 comments on commit 27e4cb3

Please sign in to comment.