Skip to content

Conversation

@jamespeapen
Copy link
Member

@jamespeapen jamespeapen commented Oct 16, 2025

S7 objects for analysis

Creates a CompartmentCall S7 object with a vector of inferred singular values from compartmap or PC1 from Hi-C, the genomic resolution and a GRanges of the bins:

<compartmap::CompartmentCall> class
@ parent     : <S7_object>
@ constructor: function(pc, res, gr, name, unitarized) {...}
@ validator  : <NULL>
@ properties :
 $ name      : <character>
 $ gr        : S4<GRanges>
 $ dt        : S3<data.table>
 $ res       : <integer> or <double>
 $ unitarized: <logical>
  • @name: an identifier for the object
  • @res: the resolution at which compartments were called
  • @gr: a GRanges object with the bins
  • @dt: a data.table with index n, singuar values pc, and the name.
    This is used to store the values and to plot the object
  • @unitarized: Whether the values have been unitarized

CompartmentCall implements

  • [ return a new CompartmapCall object with subset data and granges
  • plot: line plot of the singular values
  • flip: return a new CompartmentCall with sign-flipped singular values
  • unitarize: return a new CompartmentCall with unitarized singular values
  • DF: get the @dt slot
  • granges: get the @gr slot
  • resolution: get the resolution
  • is_unitarized: get unitarized state
  • get_name: get object name
  • print: print the object and property metadata

CompartmapCall inherits from CompartmentCall but takes the GRanges output of scCompartments() to construct itself:

<compartmap::CompartmapCall> class
@ parent     : <compartmap::CompartmentCall>
@ constructor: function(gr, res, name, unitarized) {...}
@ validator  : <NULL>
@ properties :
 $ name      : <character>
 $ gr        : S4<GRanges>
 $ dt        : S3<data.table>
 $ res       : <integer> or <double>
 $ unitarized: <logical>

MultiCompartmentCall also inherits from CompartmentCall but takes a list of CompartmentCall and/or CompartmapCall objects. It checks that all input GRanges, and resolutions are the same and that they are all either unitarized or non-unitarized, unless users want to unitarize inputs with unitarize=TRUE.

<compartmap::MultiCompartmentCall> class
@ parent     : <compartmap::CompartmentCall>
@ constructor: function(ccalls, name, unitarized, unitarize) {...}
@ validator  : function(self) {...}
@ properties :
 $ name      : <character>
 $ gr        : S4<GRanges>
 $ dt        : S3<data.table>
 $ res       : <integer> or <double>
 $ unitarized: <logical>
 $ colnames  : <character>
 $ mat       : S3<matrix/array>

MultiCompartmentCall implements

  • [: returns a new MultiCompartmentCall object with both row and column subset
  • print: calls CompartmentCall's print method and adds @mat dimensions
  • corr: gets correlations of every pair of input singular value vectors
  • agr: gets agreement of every pair of input singular value vectors
  • plot: plots singular values by color based on the inputs CompartmentCall
    name property

To compare the example k562 calls at 100kb with the HiC PC1:

example_100kb <- CompartmapCall(
  example_100kb.gr, # the GRanges from scCompartments
  res = 1e5,
  name = "example_100kb_binary"
) |> unitarize()

hic_100kb <- CompartmentCall(
  pc = na.omit(scan(hic_reference$kb100)), # text file containing PC1
  res = 1e5,
  gr = granges(example_100kb.gr), # uses the GRanges from the scCompartments
  name = "hic_100kb",
  unitarized = TRUE
)

example_hic_100kb <- MultiCompartmentCall(
  c(example_100kb, hic_100kb),
  name = "example_hc_100kb"
)

corr(example_hic_100kb)

#                      example_100kb_binary hic_100kb
# example_100kb_binary            1.0000000 0.6347439
# hic_100kb                       0.6347439 1.0000000
agr(example_hic_100kb)
#                      example_100kb_binary hic_100kb
# example_100kb_binary            1.0000000 0.7485844
# hic_100kb                       0.7485844 1.0000000
plot(example_hic_100kb)
image

I chose S7 because its simpler than the S4 system, but it does mean that the subsetting and print methods need to be written from scratch.

@jamespeapen jamespeapen added this to the v2 milestone Oct 22, 2025
@jamespeapen jamespeapen self-assigned this Oct 22, 2025
@jamespeapen jamespeapen force-pushed the s7 branch 3 times, most recently from 4e1a002 to 53c1062 Compare November 4, 2025 20:45
@jamespeapen jamespeapen force-pushed the s7 branch 3 times, most recently from d93fae7 to 91247c5 Compare November 19, 2025 15:45
@jamespeapen jamespeapen changed the base branch from master to dev November 24, 2025 19:05
@jamespeapen jamespeapen marked this pull request as ready for review November 24, 2025 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant