The CofactorTable object#
Cofactors have to be provided as a table.
There are two obligatory columns: ‘fcs_colname’ and ‘antigens’.
‘fcs_colname’ contains a list of the markers used (e.g. CD3). ‘cofactors’ contain the respective cofactor values.
Here, we read in an example cofactor table as a normal dataframe via the pandas library:
[1]:
import pandas as pd
cofactors_file = pd.read_csv("../Tutorials/spectral_dataset/cofactors.txt", sep = "\t")
cofactors_file.head()
[1]:
| fcs_colname | cofactors | |
|---|---|---|
| 0 | CD38 | 3000 |
| 1 | NKG2C_(CD159c) | 5000 |
| 2 | CD3 | 8000 |
| 3 | CD16 | 3000 |
| 4 | CD161 | 4000 |
[2]:
import FACSPy as fp
Create CofactorTable from a pandas dataframe#
In order to create a FACSPy-readable CofactorTable object, we use the fp.dt.CofactorTable class where ‘fp’ is the alias for FACSPy and ‘dt’ stands for dataset.
In this scenario, we use the table that we read via the pandas library from above. We pass the table via the cofactors parameter.
A CofactorTable object is created with 28 channels.
[3]:
cofactors = fp.dt.CofactorTable(cofactors = cofactors_file)
cofactors
[3]:
CofactorTable(28 channels, loaded as provided dataframe)
Create a CofactorTable from a .csv file#
We can also read the table directly from the hard drive. In order to do that, we pass the path to the fp.dt.CofactorTable class. Any file format that can be accessed by pd.read_csv() can be used.
[4]:
cofactors = fp.dt.CofactorTable("../Tutorials/spectral_dataset/cofactors.txt")
Access the cofactor table#
The underlying table is stored in the .dataframe attribute and can be accessed and modified.
Use the method .to_df() to return the underlying table or directly access the table via .dataframe as shown here.
[5]:
df = cofactors.dataframe
df.head()
[5]:
| fcs_colname | cofactors | |
|---|---|---|
| 0 | CD38 | 3000 |
| 1 | NKG2C_(CD159c) | 5000 |
| 2 | CD3 | 8000 |
| 3 | CD16 | 3000 |
| 4 | CD161 | 4000 |
[6]:
df = cofactors.to_df()
df.head()
[6]:
| fcs_colname | cofactors | |
|---|---|---|
| 0 | CD38 | 3000 |
| 1 | NKG2C_(CD159c) | 5000 |
| 2 | CD3 | 8000 |
| 3 | CD16 | 3000 |
| 4 | CD161 | 4000 |
Set cofactors#
In order to manually set cofactors, use the .set_cofactor() method.
[7]:
cofactors.set_cofactor("CD38", 5000)
cofactors.dataframe.head()
[7]:
| fcs_colname | cofactors | |
|---|---|---|
| 0 | CD38 | 5000 |
| 1 | NKG2C_(CD159c) | 5000 |
| 2 | CD3 | 8000 |
| 3 | CD16 | 3000 |
| 4 | CD161 | 4000 |
Access specific cofactors#
[8]:
cofactors.get_cofactor("CD38")
[8]:
5000
Write the table to the hard drive#
In order to write the cofactor table to the hard drive, use the .write() method, specifying a file-path with the file name.
[9]:
### cofactor tables can be written to the hard drive
cofactors.write("../Tutorials/spectral_dataset/vignette_cofactors.csv")