Atlas
Atlas is a user-defined collection of tables that combines the spreadsheets with the relational databases. Each table organizes data around a specific clinical factor or other criteria. With Atlas, users can seamlessly structure and analyze complex datasets.
Parameters:
-
atlas_id
(str
) –Atlas ID
Usage
from polly.auth import Polly from polly.atlas import Atlas, Table, Column
Polly.auth("
atlas = Atlas(atlas_id="atlas_1")
create_atlas
classmethod
create_table
Create a new table with the specified name and columns.
Parameters:
-
table_name
(str
) –The name of the new table to create.
-
columns
(List[Column]
) –A list of Column objects representing the columns of the new table.
-
rows
(list
, default:None
) –A list of key-value pairs representing the table data.
Returns:
-
Table
–The newly created Table object.
Examples:
delete_atlas
classmethod
delete_table
exists
get_name
get_table
Retrieve a specific table object by name.
Parameters:
-
table_name
(str
) –The name of the table to retrieve.
Returns:
-
Table
–The Table object representing the specified table.
Notes
It loads the table object and not the table data. Use to_df() function to do so.
Examples:
list_atlases
classmethod
list_tables
Retrieve the list of tables associated with an Atlas.
Returns:
-
Table
–A list of Table objects representing the tables associated with an Atlas.
Examples:
query
rename_table
Rename the name of an existing table in the Atlas.
Parameters:
-
old_table_name
(str
) –The current name of the table to rename.
-
new_table_name
(str
) –The new name to assign to the table.
Returns:
-
Table
–The renamed Table object.
Examples:
Examples
Create/Delete Atlas
Polly.auth("<access_key>")
Atlas.create_atlas(atlas_id='my_atlas', atlas_name="My Atlas")
# Atlas(atlas_id=my_atlas)
List Atlas Tables
atlas.list_tables()
#[
# Table(
# table_name='gene_table',
# columns=[
# Column(column_name='gene', data_type='text', primary_key=True),
# Column(column_name='basemean', data_type='numeric'),
# Column(column_name='log2foldchange', data_type='decimal'),
# Column(column_name='lfcse', data_type='integer'),
# Column(column_name='stat', data_type='numeric'),
# Column(column_name='pvalue', data_type='double precision'),
# Column(column_name='padj', data_type='numeric'),
# Column(column_name='negative_log10_padj', data_type='numeric'),
# Column(column_name='data_type', data_type='text'),
# Column(column_name='dataset_id', data_type='text')
# ]
# ),
# Table(
# table_name='patient',
# columns=[
# Column(column_name='curated_patient_id', data_type='text',primary_key=True),
# Column(column_name='alcohol_history', data_type='boolean'),
# Column(column_name='alcohol_intensity', data_type='text'),
# Column(column_name='tobacco_smoking', data_type='integer')
# ]
# )
#]
Rename a Table in Atlas
table=atlas.rename_table(old_table_name='patient', new_table_name='patients_info')
print(atlas.get_table(atlas_id='atlas_1', table_name='patients_info'))
#Table(
# table_name='patients_info',
# columns=[
# Column(column_name='curated_patient_id', data_type='text',primary_key=True),
# Column(column_name='alcohol_history', data_type='boolean'),
# Column(column_name='alcohol_intensity', data_type='text'),
# Column(column_name='tobacco_smoking', data_type='integer')
# ]
#)
Query any table from the atlas
atlas.query("SELECT * FROM patient LIMIT 10;")
# alcohol_history alcohol_intensity tobacco_smoking
# curated_patient_id
# patient_1718265078961285000 False None 4
# patient_1718265078961325000 True Moderate 2
# patient_1718265078961336000 False Moderate 2
# patient_1718265078961344000 False Low 9
# patient_1718265078961350000 False Low 4
# patient_1718265078961358000 False Low 7
# patient_1718265078961364000 False None 0
# patient_1718265078961371000 True Low 1
# patient_1718265078961377000 True None 7
# patient_1718265078961385000 True Moderate 4
Add a new table to an atlas/ deleting existing one
columns = [
Column(column_name="curated_patient_id", data_type="text"),
Column(column_name="alcohol_history", data_type="boolean"),
Column(column_name="alcohol_intensity", data_type="text"),
Column(column_name="tobacco_smoking", data_type="integer"),
]
new_table = atlas.create_table(table_name="patient_exposure", columns=columns)
print(new_table)
# Table(
# table_name='patient_exposure',
# columns = [
# Column(column_name="curated_patient_id", data_type="text"),
# Column(column_name="alcohol_history", data_type="boolean"),
# Column(column_name="alcohol_intensity", data_type="text"),
# Column(column_name="tobacco_smoking", data_type="integer"),
# ]
# )