Mercurial > repos > iuc > scanpy_filter
changeset 15:aa0059118fb9 draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/scanpy/ commit c21958f44b81d740191999fb6015d5ae69538ee0
author | iuc |
---|---|
date | Wed, 31 Jul 2024 18:10:52 +0000 |
parents | d636ce5cde16 |
children | 72a6bebab2a5 |
files | filter.xml macros.xml test-data/cosg.rank_genes_groups.newton-cg.pbmc68k_highly_reduced_1.h5ad test-data/tl.rank_genes_groups.newton-cg.pbmc68k_highly_reduced_marker_1.tsv test-data/tl.rank_genes_groups.newton-cg.pbmc68k_highly_reduced_marker_filtered_1.tsv |
diffstat | 5 files changed, 130 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/filter.xml Sat May 18 18:29:27 2024 +0000 +++ b/filter.xml Wed Jul 31 18:10:52 2024 +0000 @@ -98,6 +98,41 @@ random_state=$method.random_state, replace=$method.replace, copy=False) + +#else if $method.method == "filter_marker" + +#if $method.layer_selection.use_raw == 'False': + adata.X = adata.layers['$method.layer_selection.layer'] +#end if + +def check_marker(adata, group, gene, thresh_mean, thresh_frac, groupby): + filtered_data = adata[adata.obs[groupby] == group, adata.var_names == gene] + mean_expression = np.mean(filtered_data.X) + frac_cell_mean_expression = len(filtered_data.X[filtered_data.X > mean_expression]) / filtered_data.n_obs + if ( mean_expression > thresh_mean and frac_cell_mean_expression >= thresh_frac ): + return(True) + return(False) + +header='infer' + +#if $method.header == 'not_included': + header=None +#end if + +marker_list={key: list(value.values()) for key, value in pd.read_csv('$method.markerfile', sep='\t', index_col=0, header=header).to_dict(orient='index').items()} + +for key, value in marker_list.items(): + marker_list[key] = [x for x in value if check_marker(adata, key, x, $method.thresh_mean, $method.thresh_frac, '$method.groupby')] + +# Find the maximum length of lists +max_len = max(len(lst) for lst in marker_list.values()) + +# Fill smaller lists with empty values +for key, value in marker_list.items(): + marker_list[key] = value + [''] * (max_len - len(value)) + +df = pd.DataFrame(marker_list).T +df.to_csv('marker.tsv', sep='\t', index=True) #end if @CMD_anndata_write_outputs@ @@ -113,6 +148,7 @@ <option value="pp.highly_variable_genes">Annotate (and filter) highly variable genes, using 'pp.highly_variable_genes'</option> <option value="pp.subsample">Subsample to a fraction of the number of observations, using 'pp.subsample'</option> <option value="pp.downsample_counts">Downsample counts from count matrix, using 'pp.downsample_counts'</option> + <option value="filter_marker">Filter markers from count matrix and marker list</option> </param> <when value="pp.filter_cells"> <conditional name="filter"> @@ -213,11 +249,36 @@ <param argument="random_state" type="integer" value="0" label="Random seed to change subsampling"/> <param argument="replace" type="boolean" truevalue="True" falsevalue="False" checked="false" label="Sample the counts with replacement?"/> </when> + <when value="filter_marker"> + <param argument="markerfile" type="data" format="tabular" label="List of markers" help="This should be a tsv where row = group (e.g. celltypes) and columns = markers."></param> + <param name="header" type="select" label="Header in the list of markers?"> + <option value="included">Header incldued</option> + <option value="not_included">Header not included</option> + </param> + <param argument="thresh_mean" type="float" min="0.0" value="1.0" label="Minimal average count of all cells of a group (e.g., celltype) for a particular marker" help="Increasing the threshold will result in a smaller marker set."/> + <param argument="thresh_frac" type="float" min="0.0" max="1.0" value="0.1" label="Minimal fractions of cells that has a higher count than the average count of all cells of the group for the marker" help="Increasing this threshold might remove marker outliers."/> + <conditional name="layer_selection"> + <param name="use_raw" type="select" label="Use .X of adata to perform the filtering" help=""> + <option value="True">Yes</option> + <option value="False">No</option> + </param> + <when value="False"> + <param argument="layer" type="text" value="" label="Key from adata.layers whose value will be used to filter" help="If layers specified then use adata.layers[layer]."/> + </when> + <when value="True"/> + </conditional> + <param argument="groupby" type="text" value="" label="The key of the observation grouping to consider (e.g., celltype)" help=""> + <expand macro="sanitize_query" /> + </param> + </when> </conditional> <expand macro="inputs_common_advanced"/> </inputs> <outputs> <expand macro="anndata_outputs"/> + <data name="marker_out" format="tabular" from_work_dir="marker.tsv" label="${tool.name} on ${on_string}: Markers"> + <filter>method['method'] == 'filter_marker'</filter> + </data> </outputs> <tests> <test expect_num_outputs="2"> @@ -444,6 +505,32 @@ </output> <output name="anndata_out" file="pp.downsample_counts.random-randint.h5ad" ftype="h5ad" compare="sim_size" delta="10000000" delta_frac="0.5"/> </test> + <test expect_num_outputs="3"> + <!-- test 10 --> + <param name="adata" value="cosg.rank_genes_groups.newton-cg.pbmc68k_highly_reduced_1.h5ad" /> + <conditional name="method"> + <param name="method" value="filter_marker"/> + <param name="markerfile" value="tl.rank_genes_groups.newton-cg.pbmc68k_highly_reduced_marker_1.tsv"/> + <param name="thresh_mean" value="1.0"/> + <param name="thresh_frac" value="0.2"/> + <param name="layer_selection" value="True"/> + <param name="groupby" value="bulk_labels"/> + </conditional> + <section name="advanced_common"> + <param name="show_log" value="true" /> + </section> + <output name="hidden_output"> + <assert_contents> + <has_text_matching expression="adata, key, x, 1.0, 0.2, 'bulk_labels'"/> + </assert_contents> + </output> + <output name="anndata_out" file="cosg.rank_genes_groups.newton-cg.pbmc68k_highly_reduced_1.h5ad" ftype="h5ad"> + <assert_contents> + <has_h5_keys keys="obs, var, uns" /> + </assert_contents> + </output> + <output name="marker_out" file="tl.rank_genes_groups.newton-cg.pbmc68k_highly_reduced_marker_filtered_1.tsv" ftype="tabular" compare="sim_size"/> + </test> </tests> <help><![CDATA[ @@ -502,6 +589,16 @@ Downsample counts so that each cell has no more than `target_counts`. Cells with fewer counts than `target_counts` are unaffected by this. This has been implemented by M. D. Luecken. + +Filter marker genes (`filter_marker`) +====================================================================== + +This option is specific for celltype marker gene detection. You can generate a celltype marker gene file (tsv) with **COSG** provided at Galaxy. + +The marker gene file should have as rows celltypes and columns as marker genes. Each celltype can have varying number of marker genes. + +A marker gene is returned (retained in the list) if the mean expression of the marker gene is bigger than the threshold of mean expression (thresh_mean) and if the fraction of cells with the marker gene expression is equal or higher than the cell fraction threshold (thresh_frac). + More details on the `scanpy documentation <https://scanpy.readthedocs.io/en/stable/api/scanpy.pp.downsample_counts.html>`__
--- a/macros.xml Sat May 18 18:29:27 2024 +0000 +++ b/macros.xml Wed Jul 31 18:10:52 2024 +0000 @@ -1,6 +1,6 @@ <macros> <token name="@TOOL_VERSION@">1.9.6</token> - <token name="@VERSION_SUFFIX@">3</token> + <token name="@VERSION_SUFFIX@">4</token> <token name="@profile@">21.09</token> <xml name="requirements"> <requirements> @@ -425,6 +425,7 @@ <param name="type" type="select" label="Variables to plot (columns of the heatmaps)" > <option value="all">All variables in 'adata.var_names'</option> <option value="custom">Subset of variables in 'adata.var_names'</option> + <option value="customfile">Subset of variables as a tabular file</option> </param> <when value="all"/> <when value="custom"> @@ -432,6 +433,9 @@ <expand macro="sanitize_query" /> </param> </when> + <when value="customfile"> + <param argument="var_names" type="data" format="tabular" label="List of variables to plot" help="This should be a tsv where row = group (e.g. celltypes) and columns = variables."></param> + </when> </conditional> </xml> <xml name="param_num_categories"> @@ -468,11 +472,13 @@ <expand macro="param_num_categories"/> </xml> <token name="@CMD_params_inputs@"><![CDATA[ - #if $method.var_names.type == 'all' - var_names=adata.var_names, - #else + #if $method.var_names.type == 'custom' #set $var_names = ([x.strip() for x in str($method.var_names.var_names).split(',')]) var_names=$var_names, + #else if $method.var_names.type == 'customfile' + var_names={key: [v for v in list(value.values()) if pd.notna(v)] for key, value in pd.read_csv('$var_names', sep='\t', index_col=0).to_dict(orient='index').items()}, + #else + var_names=adata.var_names, #end if #if $method.groupby groupby='$method.groupby', @@ -1122,7 +1128,7 @@ </param> </xml> <xml name="param_n_genes"> - <param argument="n_genes" type="integer" min="0" value="10" label="Number of genes to show" help=""/> + <param argument="n_genes" type="integer" min="0" value="10" label="Number of genes to show" help="It is only used if you are not specifying certain variable names"/> </xml> <xml name="pl_dotplot"> <param argument="color_map" type="select" optional="true" label="Color palette">
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/tl.rank_genes_groups.newton-cg.pbmc68k_highly_reduced_marker_1.tsv Wed Jul 31 18:10:52 2024 +0000 @@ -0,0 +1,11 @@ + 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 +CD14+ Monocyte PILRA PSAP CD68 TMEM176B FTL NPC2 LST1 FCGR3A FCER1G CEBPB FCN1 SERPINA1 OAZ1 CFD FTH1 HCK AIF1 SAT1 CTSS S100A11 MS4A7 TYROBP COTL1 STXBP2 RP11-290F20.3 S100A4 IFITM2 SPI1 DUSP1 SESN2 IFITM3 MPP1 GALE CORO1B RP11-390E23.6 VIMP RSBN1L-AS1 CHD4 CFP GSTP1 PFN1 FCGRT ADTRP ARHGDIB AMICA1 HLA-DRB5 CST3 GRN HLA-DPA1 SSR3 +CD19+ B TNFRSF13B CD79B SMARCB1 PNOC CCDC50 AL928768.3 BANK1 MS4A1 CD79A ISG20 IGLL5 TNFRSF17 KIAA0125 TPD52 PEBP1 FKBP11 CCDC132 SUB1 POU2AF1 MZB1 PTPRCAP UBE2J1 BLK SPIB DERL3 FAM63B MPHOSPH9 IGJ FCRLA XBP1 NCF1 SSR3 CD52 TSHZ2 PDLIM1 VIMP SSR4 S1PR4 SELL HMGA1 NUCB2 JUN CD27 ARHGDIB GYPC CALR ADTRP BTG1 EXOG RARRES3 +CD34+ PRSS57 C19orf77 SPINK2 RP11-620J15.3 SNHG7 CYTL1 EGFL7 NGFRAP1 SOX4 NFE2 EGR1 RP3-467N11.1 H1FX CDK6 SERPINB1 SPINT2 HMGA1 IL1B NUCB2 RPLP0 IGFBP7 RPLP1 ATXN7L3B RPS3 C1orf228 KIAA0125 RPL3 SYPL1 CD63 LDHB SEPT1 JUN FAM101B PRKCQ-AS1 MATK PEBP1 SELL ITM2A SSR3 SPON2 XBP1 UBE2J1 VIMP GYPC STK17A STMN1 VIM MZB1 HOPX CD99 +CD4+/CD25 T Reg IL32 SPOCK2 ACTG1 CD2 CD3D GPR171 ARHGDIB ACOX1 MAL SIT1 GIMAP4 AES CD52 SEPT1 TMSB10 LAT STMN1 LINC00402 CD27 TSHZ2 S1PR4 CD3E PFN1 CD99 AQP3 PTPRCAP CD3G LY9 LCK CD247 S100A4 CCR7 TTC39C CORO1B MPHOSPH9 FYB RPSA FLT3LG B2M GIMAP7 PRKCQ-AS1 SELL BTG1 CCDC132 GYPC DENND2D LDHB IL7R ITM2A RPLP0 +CD4+/CD45RA+/CD25- Naive T EAF2 GNG7 SSR4 CALR DERL3 MANF IGJ XBP1 ATXN7L3B SSR3 UBE2J1 CD79A MZB1 RP3-467N11.1 TNFRSF17 NCF1 CDK6 SUB1 POU2AF1 AL928768.3 FKBP11 VIMP GYPC JUN CD27 PEBP1 SMARCB1 FLT3LG RPLP1 RPLP0 CCDC50 ISG20 IGLL5 HCST GSTP1 GPX1 CD52 VIM PTPRCAP FCGRT CD74 B2M RPL3 CYTL1 SPINK2 PRSS57 C19orf77 RP11-620J15.3 FAM101B CCDC132 +CD4+/CD45RO+ Memory RNF138 NOSIP IFITM1 LCK RARRES3 ALOX5AP FAM63B RAB3IP GZMK CD3G SEPT1 LDHB SELL CD3D EXOG RPSA CD247 AES CD52 TMSB10 NUCB2 DENND2D RPL3 RPLP1 ACTG1 FYB GIMAP7 CORO1B LY9 CD7 PFN1 RPS3 GYPC CD2 ARHGDIB IL32 RPLP0 CD99 CD3E GIMAP4 HCST B2M LAT ISG20 ITM2A FKBP11 SERPINB1 STK17A CCR7 PTPRCAP +CD56+ NK CST7 SPON2 HOPX GNLY NKG7 CTSW KLRC2 CD7 MATK PCIF1 CLIC3 FGFBP2 SYPL1 GZMB C9orf142 PRF1 CD247 HCST GZMA GZMH STMN1 ALOX5AP CD63 CD99 IGFBP7 GZMM CCL5 B2M DENND2D GIMAP7 RARRES3 SIT1 IFITM1 PFN1 EXOG XBP1 IFITM2 GIMAP4 VIMP STK17A LCK GZMK SEPT1 SSR3 CD8A CD3G SPOCK2 RPS3 LDHB IL32 +CD8+ Cytotoxic T FAM101B ADTRP GZMK HCST LAT EGR1 CD8B CCL5 RPL3 LINC00402 FGFBP2 GZMM RPS3 CD3E GYPC DENND2D C9orf142 GZMA SEPT1 JUN FYB CD8A SELL ALOX5AP CD3G STK17A AQP3 C1orf228 CD3D HOPX NKG7 CD2 NGFRAP1 RPLP1 RPSA CCR7 IL7R SPON2 PRF1 RARRES3 PRKCQ-AS1 FKBP11 MANF CTSW GNLY CD27 LDHB MAL LTB RPLP0 +CD8+/CD45RA+ Naive Cytotoxic RP11-291B21.2 CD8A CD8B RSBN1L-AS1 GIMAP5 GZMM GALE CCR7 STK17A RAB3IP GZMH GIMAP7 CD3E C1orf228 LCK CCL5 PEBP1 CD27 GYPC LDHB RNF34 CD99 CD3G PFN1 IL7R CD2 C9orf142 TMSB10 NGFRAP1 S1PR4 ITM2A CD7 RPS3 IL32 FYB IFITM1 CD52 LAT GIMAP4 MAL STMN1 NOSIP RARRES3 SPOCK2 ACTG1 PRF1 CD3D RPLP1 SELL GZMA +Dendritic HLA-DQB1 CST3 HLA-DRB1 HLA-DQA2 HLA-DQA1 LYZ HLA-DPB1 HLA-DPA1 HLA-DMA HLA-DRA VIM CD74 ALDH2 FCER1A GPX1 HLA-DRB5 LGALS2 MNDA FCGRT GRN HLA-DMB FOS CPVL CLEC10A AMICA1 CFP LY86 GSTP1 RP11-473M20.7 IL1B GSN SPINT2 CCDC163P IGFBP7 EXOG DUSP1 CD63 COTL1 FTH1 SPI1 TYROBP SPIB S100A11 OAZ1 CTSS CCDC50 AIF1 SERPINB1 TMSB10 PCIF1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/tl.rank_genes_groups.newton-cg.pbmc68k_highly_reduced_marker_filtered_1.tsv Wed Jul 31 18:10:52 2024 +0000 @@ -0,0 +1,11 @@ + 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 +CD14+ Monocyte PILRA PSAP CD68 TMEM176B FTL NPC2 LST1 FCGR3A FCER1G CEBPB FCN1 SERPINA1 OAZ1 CFD FTH1 HCK AIF1 SAT1 CTSS S100A11 TYROBP COTL1 S100A4 SPI1 DUSP1 +CD19+ B TNFRSF13B CD79B SMARCB1 PNOC CCDC50 AL928768.3 BANK1 MS4A1 CD79A ISG20 IGLL5 TNFRSF17 KIAA0125 TPD52 PEBP1 FKBP11 SUB1 POU2AF1 MZB1 PTPRCAP DERL3 XBP1 CD52 +CD34+ PRSS57 C19orf77 SPINK2 RP11-620J15.3 SNHG7 CYTL1 EGFL7 NGFRAP1 SOX4 NFE2 EGR1 RP3-467N11.1 H1FX CDK6 SERPINB1 SPINT2 HMGA1 IL1B NUCB2 RPLP0 IGFBP7 RPLP1 ATXN7L3B RPS3 KIAA0125 RPL3 SYPL1 LDHB SEPT1 FAM101B +CD4+/CD25 T Reg IL32 SPOCK2 ACTG1 CD2 CD3D ARHGDIB GIMAP4 AES CD52 SEPT1 TMSB10 LAT STMN1 CD27 CD3E PFN1 CD99 PTPRCAP CD3G LCK CD247 +CD4+/CD45RA+/CD25- Naive T +CD4+/CD45RO+ Memory RNF138 NOSIP IFITM1 LCK RARRES3 ALOX5AP RAB3IP GZMK CD3G SEPT1 LDHB SELL CD3D EXOG RPSA CD247 AES CD52 TMSB10 RPL3 +CD56+ NK CST7 SPON2 HOPX GNLY NKG7 CTSW KLRC2 CD7 MATK PCIF1 CLIC3 FGFBP2 SYPL1 GZMB C9orf142 PRF1 CD247 HCST GZMA GZMH STMN1 ALOX5AP CD63 CD99 IGFBP7 GZMM CCL5 B2M DENND2D GIMAP7 RARRES3 SIT1 PFN1 XBP1 +CD8+ Cytotoxic T FAM101B ADTRP GZMK HCST LAT EGR1 CD8B CCL5 RPL3 LINC00402 FGFBP2 GZMM RPS3 CD3E GYPC C9orf142 SEPT1 SELL CD3G CD3D HOPX NGFRAP1 +CD8+/CD45RA+ Naive Cytotoxic RP11-291B21.2 CD8A CD8B RSBN1L-AS1 GIMAP5 GZMM GALE CCR7 STK17A RAB3IP GIMAP7 CD3E LCK PEBP1 CD27 LDHB CD99 CD3G C9orf142 NGFRAP1 IL32 +Dendritic HLA-DQB1 CST3 HLA-DRB1 HLA-DQA2 HLA-DQA1 HLA-DPB1 HLA-DPA1 HLA-DRA CD74