Mercurial > repos > ebi-gxa > decoupler_pseudobulk
comparison decoupler_pseudobulk.py @ 1:046d8ff974ff draft
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 45145f380b27c3092e1fa2249adc36d7d6fdf5fe
author | ebi-gxa |
---|---|
date | Wed, 27 Sep 2023 01:11:32 +0000 |
parents | 59a7f3f83aec |
children | 130e25d3ce92 |
comparison
equal
deleted
inserted
replaced
0:59a7f3f83aec | 1:046d8ff974ff |
---|---|
56 # replace any index starting with digits to start with C instead. | 56 # replace any index starting with digits to start with C instead. |
57 obs_for_deseq.rename(index=prepend_c_to_index, inplace=True) | 57 obs_for_deseq.rename(index=prepend_c_to_index, inplace=True) |
58 # avoid dash that is read as point on R colnames. | 58 # avoid dash that is read as point on R colnames. |
59 obs_for_deseq.index = obs_for_deseq.index.str.replace("-", "_") | 59 obs_for_deseq.index = obs_for_deseq.index.str.replace("-", "_") |
60 obs_for_deseq.index = obs_for_deseq.index.str.replace(" ", "_") | 60 obs_for_deseq.index = obs_for_deseq.index.str.replace(" ", "_") |
61 col_metadata_file = f"{output_dir}col_metadata.csv" | 61 col_metadata_file = f"{output_dir}col_metadata.tsv" |
62 # write obs to a col_metadata file | 62 # write obs to a col_metadata file |
63 if factor_fields: | 63 if factor_fields: |
64 # only output the index plus the columns in factor_fields in that order | 64 # only output the index plus the columns in factor_fields in that order |
65 obs_for_deseq[factor_fields].to_csv(col_metadata_file, sep=",", index=True) | 65 obs_for_deseq[factor_fields].to_csv(col_metadata_file, sep="\t", index=True) |
66 else: | 66 else: |
67 obs_for_deseq.to_csv(col_metadata_file, sep=",", index=True) | 67 obs_for_deseq.to_csv(col_metadata_file, sep="\t", index=True) |
68 # write var to a gene_metadata file | 68 # write var to a gene_metadata file |
69 pdata.var.to_csv(f"{output_dir}gene_metadata.csv", sep=",", index=True) | 69 pdata.var.to_csv(f"{output_dir}gene_metadata.tsv", sep="\t", index=True) |
70 # write the counts matrix of a specified layer to file | 70 # write the counts matrix of a specified layer to file |
71 if layer is None: | 71 if layer is None: |
72 # write the X numpy matrix transposed to file | 72 # write the X numpy matrix transposed to file |
73 df = pd.DataFrame(pdata.X.T, index=pdata.var.index, columns=obs_for_deseq.index) | 73 df = pd.DataFrame(pdata.X.T, index=pdata.var.index, columns=obs_for_deseq.index) |
74 else: | 74 else: |
75 df = pd.DataFrame( | 75 df = pd.DataFrame( |
76 pdata.layers[layer].T, index=pdata.var.index, columns=obs_for_deseq.index | 76 pdata.layers[layer].T, index=pdata.var.index, columns=obs_for_deseq.index |
77 ) | 77 ) |
78 df.to_csv(f"{output_dir}counts_matrix.csv", sep=",", index_label="") | 78 df.to_csv(f"{output_dir}counts_matrix.tsv", sep="\t", index_label="") |
79 | 79 |
80 | 80 |
81 def plot_pseudobulk_samples( | 81 def plot_pseudobulk_samples( |
82 pseudobulk_data, | 82 pseudobulk_data, |
83 groupby, | 83 groupby, |