linnarsson-lab / loompy

Python implementation of the Loom file format - http://loompy.org
BSD 2-Clause "Simplified" License
137 stars 36 forks source link

Saving changes in a loom file #158

Closed cdiaz45 closed 2 years ago

cdiaz45 commented 2 years ago

Good afternoon, I wonder if you can help. I have a loom file and I would like to add info to it but I am unsure how to save the changes. When I exec the code below, the file closes automatically but it does not save the ds.ca["Contributor_Annotation"] as I was expecting: with loompy.connect("adult-hem-organs-10X-bone-marrow.loom") as ds: for i in range(len(ds.ca["CellID"])): my_cell=ds.ca["CellID"][i] my_input_id=ds.ca["input_id"][i] my_cell_type=merge_df[merge_df.CellID.isin([my_cell])&merge_df.input_id.isin([my_input_id])]["cell_suspension.selected_cell_type"].unique()[0] ds.ca["Contributor_Annotation"][i]=my_cell_type So when I read adult-hem-organs-10X-bone-marrow.loom again, the ds.ca["Contributor_Annotation"] does not change

However, if I read the file and change it. The data is there but I am not sure how to save the changes. ds=loompy.connect("adult-hem-organs-10X-bone-marrow.loom") for i in range(len(ds.ca["CellID"])): my_cell=ds.ca["CellID"][i] my_input_id=ds.ca["input_id"][i] my_cell_type=merge_df[merge_df.CellID.isin([my_cell])&merge_df.input_id.isin([my_input_id])]["cell_suspension.selected_cell_type"].unique()[0] ds.ca["Contributor_Annotation"][i]=my_cell_type ds.ca["Contributor_Annotation"] In this last example, I can see the array but I am not sure how to save these changes to the loom? array(['bone marrow hematopoietic cell', 'bone marrow hematopoietic cell', 'bone marrow hematopoietic cell', ..., 'bone marrow hematopoietic cell', 'bone marrow hematopoietic cell', 'bone marrow hematopoietic cell'], dtype=object)

Thank you in advance and apologies for the basic question.

cdiaz45 commented 2 years ago

Sorry actually I think I found out how to save it! with loompy.new("bone_marrow.loom") as dsout: dsout.add_columns(ds.layers, col_attrs=ds.ca, row_attrs=ds.ra)