Skip to content

Commit

Permalink
Finish renaming of cell type labelling to assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
arteymix committed Feb 21, 2024
1 parent 6a993b7 commit 7c29995
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public Set<QuantitationType> getQuantitationTypes() {
* MEX does not provide cell type labels.
*/
@Override
public Optional<CellTypeAssignment> getCellTypeLabelling() {
public Optional<CellTypeAssignment> getCellTypeAssignment() {
return Optional.empty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public interface SingleCellDataLoader {
/**
* Load single-cell type labelling present in the data.
*/
Optional<CellTypeAssignment> getCellTypeLabelling() throws IOException;
Optional<CellTypeAssignment> getCellTypeAssignment() throws IOException;

/**
* Produces a stream of single-cell expression data vectors for the given {@link QuantitationType}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,23 +313,23 @@ Map<ExpressionExperiment, Collection<AuditEvent>> getSampleRemovalEvents(

void deleteSingleCellDimension( ExpressionExperiment ee, SingleCellDimension singleCellDimension );

List<CellTypeAssignment> getCellTypeLabellings( ExpressionExperiment ee );
List<CellTypeAssignment> getCellTypeAssignments( ExpressionExperiment ee );

/**
* Obtain the preferred labelling of the preferred single-cell vectors.
* Obtain the preferred assignment of the preferred single-cell vectors.
*
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException if there are multiple preferred cell-type
* labellings
*/
@Nullable
CellTypeAssignment getPreferredCellTypeLabelling( ExpressionExperiment ee );
CellTypeAssignment getPreferredCellTypeAssignment( ExpressionExperiment ee );

/**
* Add the given cell type labelling to the single-cell dimension.
* Add the given cell type assignment to the single-cell dimension.
* <p>
* If the new labelling is preferred, any existing one is marked as non-preferred.
*/
void addCellTypeLabelling( ExpressionExperiment ee, SingleCellDimension singleCellDimension, CellTypeAssignment cellTypeAssignment );
void addCellTypeAssignment( ExpressionExperiment ee, SingleCellDimension singleCellDimension, CellTypeAssignment cellTypeAssignment );

List<Characteristic> getCellTypes( ExpressionExperiment ee );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1966,42 +1966,42 @@ public void deleteSingleCellDimension( ExpressionExperiment ee, SingleCellDimens
}

@Override
public List<CellTypeAssignment> getCellTypeLabellings( ExpressionExperiment ee ) {
public List<CellTypeAssignment> getCellTypeAssignments( ExpressionExperiment ee ) {
//noinspection unchecked
return getSessionFactory().getCurrentSession()
.createQuery( "select distinct ctl from SingleCellExpressionDataVector scedv "
.createQuery( "select distinct cta from SingleCellExpressionDataVector scedv "
+ "join scedv.singleCellDimension scd "
+ "join scd.cellTypeLabellings ctl "
+ "join scd.cellTypeAssignments cta "
+ "where scedv.expressionExperiment = :ee" )
.setParameter( "ee", ee )
.list();
}

@Nullable
@Override
public CellTypeAssignment getPreferredCellTypeLabelling( ExpressionExperiment ee ) {
public CellTypeAssignment getPreferredCellTypeAssignment( ExpressionExperiment ee ) {
return ( CellTypeAssignment ) getSessionFactory().getCurrentSession()
.createQuery( "select distinct ctl from SingleCellExpressionDataVector scedv "
.createQuery( "select distinct cta from SingleCellExpressionDataVector scedv "
+ "join scedv.singleCellDimension scd "
+ "join scd.cellTypeLabellings ctl "
+ "where scedv.quantitationType.isPreferred = true and ctl.preferred = true and scedv.expressionExperiment = :ee" )
+ "join scd.cellTypeAssignments cta "
+ "where scedv.quantitationType.isPreferred = true and cta.preferred = true and scedv.expressionExperiment = :ee" )
.setParameter( "ee", ee )
.uniqueResult();
}

@Override
public void addCellTypeLabelling( ExpressionExperiment ee, SingleCellDimension dimension, CellTypeAssignment labelling ) {
if ( labelling.isPreferred() ) {
for ( CellTypeAssignment l : dimension.getCellTypeAssignments() ) {
if ( l.isPreferred() ) {
log.info( "Marking existing cell type labelling as non-preferred, a new preferred labelling will be added." );
l.setPreferred( false );
public void addCellTypeAssignment( ExpressionExperiment ee, SingleCellDimension dimension, CellTypeAssignment assignment ) {
if ( assignment.isPreferred() ) {
for ( CellTypeAssignment a : dimension.getCellTypeAssignments() ) {
if ( a.isPreferred() ) {
log.info( "Marking existing cell type assignment as non-preferred, a new preferred assignment will be added." );
a.setPreferred( false );
break;
}
}
}
getSessionFactory().getCurrentSession().persist( labelling );
dimension.getCellTypeAssignments().add( labelling );
getSessionFactory().getCurrentSession().persist( assignment );
dimension.getCellTypeAssignments().add( assignment );
}

@Override
Expand All @@ -2010,9 +2010,9 @@ public List<Characteristic> getCellTypes( ExpressionExperiment ee ) {
return getSessionFactory().getCurrentSession()
.createQuery( "select distinct ct from SingleCellExpressionDataVector scedv "
+ "join scedv.singleCellDimension scd "
+ "join scd.cellTypeLabellings ctl "
+ "join ctl.cellTypeLabels ct "
+ "where scedv.expressionExperiment = :ee and scedv.quantitationType.isPreferred = true and ctl.preferred = true" )
+ "join scd.cellTypeAssignments cta "
+ "join cta.cellTypes ct "
+ "where scedv.expressionExperiment = :ee and scedv.quantitationType.isPreferred = true and cta.preferred = true" )
.setParameter( "ee", ee )
.list();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void replaceSingleCellDataVectors( ExpressionExperiment ee, QuantitationType qua
/**
* Remove the given cell type labelling.
*
* If the cell type labelling is preferred and applies the the preferred vectors as per {@link #getPreferredCellTypeLabelling(ExpressionExperiment)}, the cell type factor will be removed.
* If the cell type labelling is preferred and applies the the preferred vectors as per {@link #getPreferredCellTypeAssignment(ExpressionExperiment)}, the cell type factor will be removed.
*/
@Secured({ "GROUP_USER", "ACL_SECURABLE_READ" })
void removeCellTypeLabels( ExpressionExperiment ee, SingleCellDimension scd, CellTypeAssignment cellTypeAssignment );
Expand All @@ -71,14 +71,14 @@ void replaceSingleCellDataVectors( ExpressionExperiment ee, QuantitationType qua
* Obtain all the cell type labellings from all single-cell vectors.
*/
@Secured({ "GROUP_USER", "ACL_SECURABLE_READ" })
List<CellTypeAssignment> getCellTypeLabellings( ExpressionExperiment ee );
List<CellTypeAssignment> getCellTypeAssignments( ExpressionExperiment ee );

/**
* Obtain the preferred cell type labelling from the preferred single-cell vectors.
*/
@Nullable
@Secured({ "GROUP_USER", "ACL_SECURABLE_READ" })
CellTypeAssignment getPreferredCellTypeLabelling( ExpressionExperiment ee );
CellTypeAssignment getPreferredCellTypeAssignment( ExpressionExperiment ee );

/**
* Obtain the cell types of a given single-cell dataset.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,12 @@ public CellTypeAssignment relabelCellTypes( ExpressionExperiment ee, SingleCellD
.map( l -> Characteristic.Factory.newInstance( Categories.CELL_TYPE, l, null ) )
.collect( Collectors.toList() ) );
labelling.setNumberOfCellTypes( labels.size() );
expressionExperimentDao.addCellTypeLabelling( ee, dimension, labelling );
expressionExperimentDao.addCellTypeAssignment( ee, dimension, labelling );
validateSingleCellDimension( ee, dimension );
log.info( "Relabelled single-cell vectors for " + ee + " with: " + labelling );

// checking labelling.isPreferred() is not enough, the labelling might apply to non-preferred vectors
if ( labelling.equals( getPreferredCellTypeLabelling( ee ) ) ) {
if ( labelling.equals( getPreferredCellTypeAssignment( ee ) ) ) {
log.info( "New labels are preferred and also apply to preferred single-cell vectors, recreating the cell type factor..." );
recreateCellTypeFactor( ee, labelling );
}
Expand All @@ -302,7 +302,7 @@ public void removeCellTypeLabels( ExpressionExperiment ee, SingleCellDimension d
Assert.isTrue( ee.getBioAssays().containsAll( dimension.getBioAssays() ), "Single-cell dimension does not belong to the dataset." );
Assert.isTrue( dimension.getCellTypeAssignments().contains( cellTypeAssignment ),
"The supplied labelling does not belong to the dimension." );
boolean alsoRemoveFactor = cellTypeAssignment.equals( getPreferredCellTypeLabelling( ee ) );
boolean alsoRemoveFactor = cellTypeAssignment.equals( getPreferredCellTypeAssignment( ee ) );
dimension.getCellTypeAssignments().remove( cellTypeAssignment );
if ( alsoRemoveFactor ) {
log.info( "The preferred cell type labels have been removed, removing the cell type factor..." );
Expand All @@ -312,14 +312,14 @@ public void removeCellTypeLabels( ExpressionExperiment ee, SingleCellDimension d

@Override
@Transactional(readOnly = true)
public List<CellTypeAssignment> getCellTypeLabellings( ExpressionExperiment ee ) {
return expressionExperimentDao.getCellTypeLabellings( ee );
public List<CellTypeAssignment> getCellTypeAssignments( ExpressionExperiment ee ) {
return expressionExperimentDao.getCellTypeAssignments( ee );
}

@Override
@Transactional(readOnly = true)
public CellTypeAssignment getPreferredCellTypeLabelling( ExpressionExperiment ee ) {
return expressionExperimentDao.getPreferredCellTypeLabelling( ee );
public CellTypeAssignment getPreferredCellTypeAssignment( ExpressionExperiment ee ) {
return expressionExperimentDao.getPreferredCellTypeAssignment( ee );
}

@Override
Expand Down Expand Up @@ -368,7 +368,7 @@ private void validateSingleCellDimension( ExpressionExperiment ee, SingleCellDim
@Override
@Transactional
public ExperimentalFactor recreateCellTypeFactor( ExpressionExperiment ee ) {
CellTypeAssignment ctl = getPreferredCellTypeLabelling( ee );
CellTypeAssignment ctl = getPreferredCellTypeAssignment( ee );
Assert.notNull( ctl, "There must be a preferred cell type labelling for " + ee + " to update the cell type factor." );
return recreateCellTypeFactor( ee, ctl );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void test() throws IOException {
for ( String sampleName : loader.getSampleNames() ) {
bas.add( BioAssay.Factory.newInstance( sampleName, null, BioMaterial.Factory.newInstance( sampleName ) ) );
}
assertThat( loader.getCellTypeLabelling() ).isEmpty();
assertThat( loader.getCellTypeAssignment() ).isEmpty();
QuantitationType qt = loader.getQuantitationTypes().iterator().next();
assertThat( qt ).isNotNull();
assertThat( qt.getRepresentation() ).isEqualTo( PrimitiveType.DOUBLE );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void testGetSingleCellDataMatrix() {
assertThat( matrix.getQuantitationType() ).isEqualTo( qt );
assertThat( matrix.getSingleCellDimension() ).isEqualTo( scd );
assertThat( matrix.columns() ).isEqualTo( 100 );
assertThat( matrix.rows() ).isEqualTo( 100 );
assertThat( matrix.rows() ).isEqualTo( 10 );
}

@Test
Expand Down Expand Up @@ -271,9 +271,9 @@ public void testRelabelCellTypes() {
SingleCellDimension scd = vectors.iterator().next().getSingleCellDimension();
scExpressionExperimentService.addSingleCellDataVectors( ee, qt, vectors );
sessionFactory.getCurrentSession().flush();
assertThat( scExpressionExperimentService.getCellTypeLabellings( ee ) )
assertThat( scExpressionExperimentService.getCellTypeAssignments( ee ) )
.hasSize( 1 );
assertThat( scExpressionExperimentService.getPreferredCellTypeLabelling( ee ) ).isNotNull();
assertThat( scExpressionExperimentService.getPreferredCellTypeAssignment( ee ) ).isNotNull();
assertThat( scExpressionExperimentService.getCellTypes( ee ) ).hasSize( 2 )
.extracting( Characteristic::getValue )
.containsExactlyInAnyOrder( "A", "B" );
Expand All @@ -289,16 +289,16 @@ public void testRelabelCellTypes() {
assertThat( ee.getSingleCellExpressionDataVectors() )
.hasSize( 10 )
.allSatisfy( v -> assertThat( v.getSingleCellDimension().getCellTypeAssignments() ).contains( newLabelling ) );
assertThat( scExpressionExperimentService.getCellTypeLabellings( ee ) )
assertThat( scExpressionExperimentService.getCellTypeAssignments( ee ) )
.hasSize( 1 )
.contains( newLabelling );
assertThat( scExpressionExperimentService.getPreferredCellTypeLabelling( ee ) ).isEqualTo( newLabelling );
assertThat( scExpressionExperimentService.getPreferredCellTypeAssignment( ee ) ).isEqualTo( newLabelling );
assertThat( scExpressionExperimentService.getCellTypes( ee ) ).hasSize( 2 )
.extracting( Characteristic::getValue )
.containsExactlyInAnyOrder( "A", "B" );

scExpressionExperimentService.removeCellTypeLabels( ee, scd, newLabelling );
assertThat( scExpressionExperimentService.getPreferredCellTypeLabelling( ee ) ).isNull();
assertThat( scExpressionExperimentService.getPreferredCellTypeAssignment( ee ) ).isNull();

// FIXME: add proper assertions for the created factor, but the ExperimentalFactorService is mocked
verify( experimentalFactorService, times( 2 ) ).create( any( ExperimentalFactor.class ) );
Expand All @@ -324,7 +324,7 @@ public void testGetPreferredCellTypeLabellingWhenNonUnique() {
// now we're going to do something really bad...
qt.setIsPreferred( true );

assertThatThrownBy( () -> scExpressionExperimentService.getPreferredCellTypeLabelling( ee ) )
assertThatThrownBy( () -> scExpressionExperimentService.getPreferredCellTypeAssignment( ee ) )
.isInstanceOf( NonUniqueResultException.class );
}

Expand Down

0 comments on commit 7c29995

Please sign in to comment.