generate_compartments_bed_fun.R 1.0 KB

12345678910111213141516171819
  1. ## Yuanlong LIU, 09-08-2018
  2. generate_compartments_bed <- function(input_mat, p_thresh, out_file_name, chr, window.sizes=3, stat_window_size=NULL, bin_size)
  3. {
  4. input_mat_extended = data.frame(chr=paste0('chr', chr), pos_start=0:(nrow(input_mat)-1), pos_end=1:nrow(input_mat), mat=input_mat)
  5. res_input_mat = TopDom_v2(input_mat_extended, window.size=NULL, NULL, T, p_thresh=p_thresh, window.sizes=window.sizes, stat_window_size=stat_window_size, domain_size_min=NULL)
  6. # return(res_input_mat)
  7. to_id = as.numeric(rownames(input_mat)[res_input_mat$domain$to.id])
  8. from_id = as.numeric(rownames(input_mat)[res_input_mat$domain$from.id])
  9. start_poses = (from_id-1)*bin_size + 1
  10. # end_poses = start_poses + n2one*bin_size
  11. end_poses = start_poses + bin_size
  12. input_mat_compartments_bed = data.frame(paste0('chr', chr), as.character(start_poses), as.character(end_poses) )
  13. if(!is.null(out_file_name)) write.table( input_mat_compartments_bed, file=out_file_name, quote=FALSE, row.names=FALSE, col.names=FALSE, sep=' ' )
  14. return( res_input_mat )
  15. }