Skip to content

Commit

Permalink
resolve more PR suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
jlchang committed Nov 15, 2022
1 parent 9bc7f61 commit 2e07bee
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions ingest/anndata_.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,19 @@ def generate_cluster_header(adata, clustering_name):
"""
Based on clustering dimensions, write clustering NAME line to file
"""
dim2 = ['NAME', 'X', 'Y']
dim3 = dim2 + ['Z']
dim = ['NAME', 'X', 'Y']
clustering_dimension = adata.obsm[clustering_name].shape[1]
if clustering_dimension == 2:
headers = dim2
if clustering_dimension == 3:
headers = dim.append('Z')
elif clustering_dimension == 3:
headers = dim3
headers = dim
elif clustering_dimension > 3:
msg = f"Too many dimensions for visualization in obsm \"{clustering_name}\", found {clustering_dimension}, expected 2 or 3."
raise ValueError(msg)
else:
msg = f"Too few dimensions for visualization in obsm \"{clustering_name}\", found {clustering_dimension}, expected 2 or 3."
raise ValueError(msg)
with open(f"{clustering_name}.tsv", "w") as f:
with open(f"{clustering_name}.cluster.anndata_segment.tsv", "w") as f:
f.write('\t'.join(headers) + '\n')

@staticmethod
Expand All @@ -72,7 +71,7 @@ def generate_cluster_type_declaration(adata, clustering_name):
"""
clustering_dimension = adata.obsm[clustering_name].shape[1]
types = ["TYPE", *["numeric"] * clustering_dimension]
with open(f"{clustering_name}.tsv", "a") as f:
with open(f"{clustering_name}.cluster.anndata_segment.tsv", "a") as f:
f.write('\t'.join(types) + '\n')

@staticmethod
Expand All @@ -85,7 +84,11 @@ def generate_cluster_body(adata, clustering_name):
[cluster_cells, pd.DataFrame(adata.obsm[clustering_name])], axis=1
)
pd.DataFrame(cluster_body).to_csv(
f"{clustering_name}.tsv", sep="\t", mode="a", header=None, index=False
f"{clustering_name}.cluster.anndata_segment.tsv",
sep="\t",
mode="a",
header=None,
index=False,
)

@staticmethod
Expand Down

0 comments on commit 2e07bee

Please sign in to comment.