Skip to content

Commit c7d6262

Browse files
remove bins that have not coverage in one patient
1 parent f95f98a commit c7d6262

1 file changed

Lines changed: 5 additions & 10 deletions

File tree

bin/compartmentalization_analysis_functions.R

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,6 @@ get.subcompartment.calder <- function( T, blocks, chr, genes_gr, bins_gr, n.comp
330330
# SAMMY_SUBCOMPARTMENTS.R
331331
####################################################
332332

333-
## FUNCTIONS
334333
### It takes tracks in input and calculate the euclidean distance matrix
335334
my_read.SAMMY.calder <- function( tracks, track_names, bins_gr, keeping_bins = "all", metric = "euclidean", cores = 4 ){
336335

@@ -346,20 +345,15 @@ my_read.SAMMY.calder <- function( tracks, track_names, bins_gr, keeping_bins =
346345
keeping_bins <- track_matrix_info[[ "keeping_bins" ]]
347346

348347
## Annotate the bins with 0 coverage in all fractions
349-
## They will be removed in all other samples
350348
bws_df <- as.data.frame( bws_dtable )
351349
rownames( bws_df ) <- as.character( keeping_bins )
352350

353351
removing_bins1 <- rownames( bws_df[ ( rowSums( bws_dtable ) == 0 ), ] )
354-
print( "Bins with no coverage annotated" )
355352

356353
## Calculate eucledean distance between pairs of points (i.e., bins)
357-
## Each point is define in the n-dimensional space, where n is 3,4, or 6 based on the number of fractions or Chip-seq experiments
358354
dist_mat <- as.matrix( dist( bws_dtable, method = metric ) )
359355
rownames( dist_mat ) <- colnames( dist_mat ) <- keeping_bins
360356

361-
print( "Distance matrix made" )
362-
363357
return( list( dist_mat = dist_mat, removing_bins1 = removing_bins1 ) )
364358

365359
}
@@ -427,8 +421,7 @@ call_subcompartments_sammy <- function( patients, tracks_db, bins_gr, subs_file,
427421
print( "No bin removed" )
428422
}
429423

430-
# PHASE 1: Scan all patients to identify bins with zero coverage across fractions
431-
print( "Scanning profiles across all patients to identify zero coverage bins" )
424+
# remove bins with zero coverage in all fractions in at least one patient
432425
sammy_removing_lists <- mclapply( patients, mc.cores = cores, function( patient ){
433426
sammy_files <- tracks_db[ which( tracks_db$Patient_name == patient ), "File" ]
434427
names( sammy_files ) <- tracks_db[ which( tracks_db$Patient_name == patient ), "Fraction" ]
@@ -444,7 +437,9 @@ call_subcompartments_sammy <- function( patients, tracks_db, bins_gr, subs_file,
444437
keeping_bins <- track_matrix_info[[ "keeping_bins" ]]
445438
bws_df <- as.data.frame( bws_dtable )
446439
rownames( bws_df ) <- as.character( keeping_bins )
447-
removing_bins1 <- rownames( bws_df[ ( rowSums( bws_dtable ) == 0 ), ] )
440+
441+
# remove bins with zero coverage in all fractions in at least one patient
442+
removing_bins1 <- rownames( bws_df[ ( rowSums( bws_dtable >= 0.1 ) == 0 ), ] )
448443
return( removing_bins1 )
449444
})
450445

@@ -484,7 +479,7 @@ call_subcompartments_sammy <- function( patients, tracks_db, bins_gr, subs_file,
484479

485480
sammy_dist_mat <- sammy_dist_obj[[ "dist_mat" ]]
486481

487-
# Subset the distance matrix to keep only the bins with coverage in all fractions in all patients
482+
# Subset the distance matrix to keep only the globally filtered bins
488483
keeping_bins1_char <- as.character( keeping_bins1 )
489484
valid_bins <- keeping_bins1_char[ keeping_bins1_char %in% rownames( sammy_dist_mat ) ]
490485
sammy_dist_mat <- sammy_dist_mat[ valid_bins, valid_bins ]

0 commit comments

Comments
 (0)