Previous changeset 1:dcfcad35e847 (2022-08-29) Next changeset 3:3a441d347a46 (2024-06-26) |
Commit message:
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea |
modified:
main_macros.xml mcmicro_to_anndata.py scimap_phenotyping.py scimap_phenotyping.xml test-data/mcmicro_output.csv test-data/tutorial_data.h5ad test-data/tutorial_data_pheno.h5ad |
added:
anndata_to_csv.py scimap_plotting.py |
removed:
test-data/imc.h5ad |
b |
diff -r dcfcad35e847 -r ce22e846c5e4 anndata_to_csv.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/anndata_to_csv.py Mon Jun 10 18:44:25 2024 +0000 |
[ |
@@ -0,0 +1,45 @@ +import argparse +import json +import warnings + +import scimap as sm +from anndata import read_h5ad + + +def main(inputs, outfile): + """ + Parameters + --------- + inputs : str + File path to galaxy tool parameter. + anndata : str + File path to anndata. + output : str + File path to output. + """ + warnings.simplefilter('ignore') + + with open(inputs, 'r') as param_handler: + params = json.load(param_handler) + + adata = read_h5ad(params['anndata']) + + if params['layer'] == 'x': + params['layer'] = None + + df = sm.hl.scimap_to_csv( + adata=adata, + layer=params['layer'], + CellID=params['cellid'], + ) + + df.to_csv(outfile, index=False) + + +if __name__ == '__main__': + aparser = argparse.ArgumentParser() + aparser.add_argument("-i", "--inputs", dest="inputs", required=True) + aparser.add_argument("-e", "--outfile", dest="outfile", required=True) + args = aparser.parse_args() + + main(args.inputs, args.outfile) |
b |
diff -r dcfcad35e847 -r ce22e846c5e4 main_macros.xml --- a/main_macros.xml Mon Aug 29 23:55:18 2022 +0000 +++ b/main_macros.xml Mon Jun 10 18:44:25 2024 +0000 |
b |
@@ -1,5 +1,5 @@ <macros> - <token name="@TOOL_VERSION@">0.17.7</token> + <token name="@TOOL_VERSION@">2.1.0</token> <token name="@VERSION_SUFFIX@">0</token> <token name="@PROFILE@">20.01</token> |
b |
diff -r dcfcad35e847 -r ce22e846c5e4 mcmicro_to_anndata.py --- a/mcmicro_to_anndata.py Mon Aug 29 23:55:18 2022 +0000 +++ b/mcmicro_to_anndata.py Mon Jun 10 18:44:25 2024 +0000 |
[ |
@@ -31,7 +31,11 @@ if v == '': options[k] = None - adata = sm.pp.mcmicro_to_scimap(image_path, drop_markers=drop_markers, **options) + adata = sm.pp.mcmicro_to_scimap( + image_path, + drop_markers=drop_markers, + **options + ) adata.write(outfile) |
b |
diff -r dcfcad35e847 -r ce22e846c5e4 scimap_phenotyping.py --- a/scimap_phenotyping.py Mon Aug 29 23:55:18 2022 +0000 +++ b/scimap_phenotyping.py Mon Jun 10 18:44:25 2024 +0000 |
[ |
@@ -9,11 +9,12 @@ def main( adata, output, + log, gating_workflow, gating_workflow_ext, manual_gates=None, manual_gates_ext=None, - rescale_plots=False + random_state=0 ): """ Parameter @@ -22,6 +23,8 @@ File path to the input AnnData. output : str File path to the output AnnData. + log: bool + Boolean whether to log the input data prior to rescaling gating_workflow : str File path to the gating workflow. gating_workflow_ext : str @@ -30,8 +33,8 @@ File path to the munual gating. manual_gates_ext : str Datatype for munual gate, either 'csv' or 'tabular'. - rescale_plots : boolean - Save plots from rescaling. + random_state: int + The seed used by the random number generator for GMM in sm.pp.rescale """ warnings.simplefilter('ignore') @@ -41,13 +44,22 @@ sep = ',' if manual_gates_ext == 'csv' else '\t' manual_gates = pd.read_csv(manual_gates, sep=sep) - adata = sm.pp.rescale(adata, gate=manual_gates, save_fig=rescale_plots) + adata = sm.pp.rescale( + adata, + gate=manual_gates, + log=log, + random_state=random_state + ) # Phenotype cells # Load the gating workflow sep = ',' if gating_workflow_ext == 'csv' else '\t' phenotype = pd.read_csv(gating_workflow, sep=sep) - adata = sm.tl.phenotype_cells(adata, phenotype=phenotype, label="phenotype") + adata = sm.tl.phenotype_cells( + adata, + phenotype=phenotype, + label="phenotype" + ) # Summary of the phenotyping print(adata.obs['phenotype'].value_counts()) @@ -59,15 +71,50 @@ aparser = argparse.ArgumentParser() aparser.add_argument("-a", "--adata", dest="adata", required=True) aparser.add_argument("-o", "--output", dest="output", required=True) - aparser.add_argument("-g", "--gating_workflow", dest="gating_workflow", required=True) - aparser.add_argument("-s", "--gating_workflow_ext", dest="gating_workflow_ext", required=True) - aparser.add_argument("-m", "--manual_gates", dest="manual_gates", required=False) - aparser.add_argument("-S", "--manual_gates_ext", dest="manual_gates_ext", required=False) - aparser.add_argument("-p", "--rescale_plots", dest="rescale_plots", action="store_true", - default=False, required=False) + aparser.add_argument("-l", "--log", dest="log", action="store_true") + aparser.add_argument( + "-g", + "--gating_workflow", + dest="gating_workflow", + required=True + ) + aparser.add_argument( + "-s", + "--gating_workflow_ext", + dest="gating_workflow_ext", + required=True + ) + aparser.add_argument( + "-m", + "--manual_gates", + dest="manual_gates", + required=False + ) + aparser.add_argument( + "-S", + "--manual_gates_ext", + dest="manual_gates_ext", + required=False + ) + aparser.add_argument( + "--random_state", + dest="random_state", + type=int, + required=False + ) args = aparser.parse_args() - main(args.adata, args.output, args.gating_workflow, - args.gating_workflow_ext, args.manual_gates, - args.manual_gates_ext, args.rescale_plots) + if args.log: + print("\n adata.raw.X will be log1p transformed \n") + + main( + adata=args.adata, + output=args.output, + log=args.log, + gating_workflow=args.gating_workflow, + gating_workflow_ext=args.gating_workflow_ext, + manual_gates=args.manual_gates, + manual_gates_ext=args.manual_gates_ext, + random_state=args.random_state + ) |
b |
diff -r dcfcad35e847 -r ce22e846c5e4 scimap_phenotyping.xml --- a/scimap_phenotyping.xml Mon Aug 29 23:55:18 2022 +0000 +++ b/scimap_phenotyping.xml Mon Jun 10 18:44:25 2024 +0000 |
[ |
@@ -7,19 +7,20 @@ <expand macro="scimap_requirements"/> <expand macro="macro_stdio" /> <version_command>echo "@VERSION@"</version_command> - <command> + <command detect_errors="aggressive"> <![CDATA[ python '$__tool_directory__/scimap_phenotyping.py' --adata '$anndata' + #if $log + --log + #end if #if $manual_gates --manual_gates '$manual_gates' --manual_gates_ext '${manual_gates.ext}' #end if --gating_workflow '$gating_workflow' --gating_workflow_ext '${gating_workflow.ext}' - #if $rescale_plots - --rescale_plots - #end if + --random_state '$random_state' --output '$output' ]]> @@ -29,17 +30,14 @@ </configfiles> <inputs> <param name="anndata" type="data" format="h5ad" label="Select the input anndata" /> + <param name="log" type="boolean" checked="true" label="Whether to log the data prior to rescaling" /> <param name="manual_gates" type="data" format="tabular,csv" optional="true" label="Select the dataset containing manual gate information" help="First column as markers and second column as the gate values in log1p scale. If a marker is not included, auto gating based on gaussian mixture modeling will be executed. Optional."/> <param name="gating_workflow" type="data" format="tabular,csv" label="Select the dataset containing gating workflow" /> - <param name="rescale_plots" type="boolean" checked="false" label="Save the GMM gates plots If True"/> + <param name="random_state" type="integer" value="0" optional="true" label="Set seed used by the random number generator for GMM" /> </inputs> <outputs> <data format="h5ad" name="output" /> - <collection name="gmm_plots" type="list" label="${tool.name}: GMM-plots"> - <filter>rescale_plots</filter> - <discover_datasets pattern="__designation_and_ext__" directory="auto_gating" ext="png"/> - </collection> </outputs> <tests> <test> @@ -63,6 +61,10 @@ AnnData. +**Important Note** + +If adata.raw.X exists, it will be used. If adata.raw.X does not exist, adata.X is used + **Output** Anndata with "obs/phenotype" added. @@ -70,6 +72,5 @@ ]]> </help> - <citations> - </citations> + <expand macro="citations" /> </tool> |
b |
diff -r dcfcad35e847 -r ce22e846c5e4 scimap_plotting.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scimap_plotting.py Mon Jun 10 18:44:25 2024 +0000 |
[ |
@@ -0,0 +1,125 @@ +import argparse +import json +import os +import warnings + +import matplotlib.pylab as plt +import numpy as np +import scimap as sm +import seaborn as sns +from anndata import read_h5ad + +sns.set(color_codes=True) + + +def main(inputs, anndata, output): + """ + Parameter + --------- + inputs : str + File path to galaxy tool parameter. + anndata : str + File path to anndata containing phenotyping info. + output : str + File path to output. + """ + warnings.simplefilter('ignore') + + with open(inputs, 'r') as param_handler: + params = json.load(param_handler) + + adata = read_h5ad(anndata) + + tool = params['analyses']['selected_tool'] + options = params['analyses']['options'] + + if tool == 'stacked_barplot': + + # parse list text arguments + for o in options.copy(): + opt_list = options.pop(o) + if opt_list: + options[o] = [x.strip() for x in opt_list.split(',')] + + # add base args into options dict to pass to tool + options['x_axis'] = params['analyses']['x_axis'] + options['y_axis'] = params['analyses']['y_axis'] + options['method'] = params['analyses']['method'] + + options['return_data'] = True + + df = sm.pl.stacked_barplot(adata, **options) + + # Pick cmap to use + num_phenotypes = len(df.columns) - 1 + if num_phenotypes <= 9: + matplotlib_cmap = "Set1" + elif num_phenotypes > 9 and num_phenotypes <= 20: + matplotlib_cmap = plt.cm.tab20 + else: + matplotlib_cmap = plt.cm.gist_ncar + + # Plotting + sns.set_theme(style="white") + ax = df.plot.bar(stacked=True, cmap=matplotlib_cmap) + fig = ax.get_figure() + handles, labels = ax.get_legend_handles_labels() + ax.legend( + reversed(handles), + reversed(labels), + bbox_to_anchor=(1, 1), + loc='upper left' + ) + plt.tight_layout() + + # # save and close + fig.savefig('out.png', dpi=300) + plt.close(fig) + + if tool == 'voronoi': + + plt.style.use('fast') + + tool_func = getattr(sm.pl, tool) + + # x_lim/y_lim need to be parsed from comma-sep str to integer tuples + for lim in ['x_lim', 'y_lim']: + opt_list = options.pop(lim) + if opt_list: + options[lim] = [int(x.strip()) for x in opt_list.split(',')] + + # parse list text arguments + for cat in ['overlay_points_categories', 'overlay_drop_categories']: + opt_list = options.pop(cat) + if opt_list: + options[cat] = [x.strip() for x in opt_list.split(',')] + + # add base args into options dict to pass to tool + options['color_by'] = params['analyses']['color_by'] + options['x_coordinate'] = params['analyses']['x_coordinate'] + options['y_coordinate'] = params['analyses']['y_coordinate'] + + # fill any missing params with None as tool expects + for k, v in options.items(): + if v == '': + options[k] = None + + options['saveDir'] = os.getcwd() + options['fileName'] = 'out.png' + + if options['size_max'] is None: + options['size_max'] = np.inf + + # call the tool and unpack all options + tool_func(adata, **options) + + +if __name__ == '__main__': + aparser = argparse.ArgumentParser() + aparser.add_argument("-i", "--inputs", dest="inputs", required=True) + aparser.add_argument("-a", "--anndata", dest="anndata", required=True) + aparser.add_argument("-e", "--output", dest="output", required=True) + + args = aparser.parse_args() + + main(args.inputs, args.anndata, args.output) |
b |
diff -r dcfcad35e847 -r ce22e846c5e4 test-data/imc.h5ad |
b |
Binary file test-data/imc.h5ad has changed |
b |
diff -r dcfcad35e847 -r ce22e846c5e4 test-data/mcmicro_output.csv --- a/test-data/mcmicro_output.csv Mon Aug 29 23:55:18 2022 +0000 +++ b/test-data/mcmicro_output.csv Mon Jun 10 18:44:25 2024 +0000 |
b |
b'@@ -498,4329 +498,3 @@\n 497,42428.94915,967.1186441,702.5762712,1137.59322,37041.13559,769.5254237,699.7966102,1651.576271,20054.16949,632.5762712,473.220339,1735.813559,27445.84746,1412.050847,3662.644068,5047.627119,9486.847458,1401.084746,451.4237288,2420.813559,18292.86441,419.3389831,891.2711864,474.4915254,21906.47458,428.0338983,134.9830508,5820.372881,18267.83051,1575.728814,1378.322034,2861.389831,14785.0678,610.6271186,304.4237288,4221.474576,11649.98305,947.8135593,470.7288136,1340.881356,8565.525424,922.2372881,190.3050847,4911.305085,7047.830508,1394.59322,241.440678,3259.491525,429.8644068,178.6440678,59,11.70055465,6.412084822,0.836468205,1,0.702380952,-0.357722233\r\n 498,39463.22973,893.7972973,515.6081081,1135.648649,34346.16216,731.8581081,735.1891892,1597.736486,18834.41216,619.2364865,641.1891892,1735.648649,25783.81757,1374.885135,5027.702703,5324.797297,9471.641892,1411.5,429.472973,2478.878378,17068.97973,447.1081081,298.6621622,516.5810811,20917.72973,627.4459459,130.6216216,3780.493243,16956.41892,1579.837838,1096.385135,2824.175676,13704.2027,686.5135135,303.7972973,3696.635135,10937.43243,1098.189189,473.0810811,1332.5,8170.756757,712.6824324,178.3513514,3573.527027,6672.777027,1386.087838,233.0945946,3267.655405,441.222973,179.3040541,148,18.5882607,10.57722018,0.822318915,0.836158192,0.528571429,-1.175521806\r\n 499,26292.65942,766.3115942,489.6014493,1078.492754,22702.01449,623.7391304,742.2028986,1470.775362,12958.5942,548.5724638,1449.753623,1772.855072,17588.95652,1211.514493,7064.181159,3506.978261,6610.746377,1229.623188,387.9927536,5530.333333,11590.8913,1304.217391,1642.463768,961.8623188,14059.71739,406.057971,120.2246377,2963.673913,11347.33333,1955.181159,823.7753623,2827.934783,9194.297101,608.0869565,260.2536232,6088.057971,7353.369565,1161.876812,412.7391304,1410.724638,5301.985507,998.0217391,163.3115942,4404.985507,4391.101449,1185.550725,370.4637681,3114.978261,483.4492754,179.9782609,138,15.73824671,11.41944783,0.688131741,0.932432432,0.616071429,0.747407505\r\n-500,35212.17021,846.1382979,522.6595745,1109.978723,31911.03191,724.4042553,1042.808511,1645.723404,17461.04255,602.3510638,2728.148936,1799.265957,24183.05319,1316.085106,7381.234043,4300.765957,8776.053191,1345.159574,413.0744681,5757.361702,16328.3617,1424.734043,781.5106383,1781.223404,19136.55319,618.0851064,150.9148936,4067.010638,15988.51064,2212.457447,819.6595745,2881.925532,12858.17021,617.3829787,289.8829787,5058.223404,10421.93617,1606.37234,445.106383,1352.851064,7721.404255,838.106383,175.0106383,4391.287234,6381.617021,1306.819149,379.1914894,3215.468085,505.4148936,176.6702128,94,14.16376386,8.800377455,0.783548658,0.930693069,0.696296296,-1.269369465\r\n-501,25232.47761,763.3208955,460.738806,1082.753731,21492.05224,621.1492537,733.8731343,1545.708955,12546.35075,542.3134328,1074.947761,1798.992537,17081.91791,1184.559701,4892.507463,3600.656716,6156.850746,1212.313433,447.7313433,3135.731343,11374.12687,1174.589552,1045.88806,667.5298507,13244.77612,416.2089552,150.7164179,4759.343284,11318.35821,1563.067164,844.6343284,2814.432836,9133.462687,571.2761194,259.9253731,11027.08955,7345.485075,2328.664179,418.4626866,1332.350746,5382.485075,883.9253731,161.5746269,3980.164179,4542.223881,1220.664179,208.4477612,3232.044776,564.9104478,179.1641791,134,14.62803128,11.75489382,0.59518749,0.97810219,0.683673469,-0.760607989\r\n-502,22738.63125,748.85,504.7125,1099.05,20355.8375,601.15,475.03125,1713.65,11096.075,507.03125,458.60625,1893.5875,15998.04375,1169.05625,3869.2,3326.50625,5704.00625,1177.80625,367.64375,2861.9,10069.2875,2744.575,298.65625,464.90625,12165.33125,387.975,113.93125,5175.03125,10313.00625,1332.3375,969.6625,2796.29375,8259.0875,537.1,244.45625,9805.04375,6886.96875,809.2375,386.98125,1310.175,5097.13125,729.9625,152.275,3792.4625,4247.9875,1181.6375,148.94375,3613.25625,692.65625,182.025,160,16.62407963,12.75301343,0.64147849,0.91954023,0.592592593,0.13200122\r\n-503,20210.01282,767.1410256,509.5,11'..b',981.4204545,16357.47727,557.7045455,687.3295455,1381.409091,6497.295455,464.5909091,1087.954545,1708.022727,8616.204545,1064.079545,3466.704545,2985.647727,3181.965909,1032.340909,240.0340909,2393.147727,6480.659091,297.0454545,248.8295455,1392.738636,7762.011364,536.0795455,103.9659091,2944.659091,5869.909091,1975.034091,311.1704545,2774.715909,4753.454545,508.6136364,232.9545455,879.8863636,2242.443182,1146.852273,338.8977273,1270.75,1436.261364,599.4772727,145.2840909,1646.204545,1463.897727,1019.875,270.5,3031.022727,752.75,1087.875,88,12.88562484,9.253094799,0.69594573,0.897959184,0.666666667,0.957043206\r\n-4821,16663.31818,918.8896104,592.4220779,1113.168831,14460.98701,669.512987,551.6103896,1553.292208,6450.363636,570.5974026,743.5714286,1773.409091,8279.136364,1203.538961,2151.24026,2188.558442,3193.402597,1600.701299,283.2857143,2290.266234,7050.883117,374.8181818,199.7012987,1060.61039,8511.383117,471.6948052,110.8376623,2289.331169,6521.811688,1532.798701,298.3051948,2842.896104,5753.175325,595.7662338,249.8376623,1114.045455,2975.525974,988.7857143,384.8571429,1316.785714,1767.123377,604.5714286,155.0064935,3352.824675,1826.668831,1162.292208,518.961039,3162.61039,559.5974026,1091.577922,154,18.15030705,11.68328834,0.76528091,0.900584795,0.57037037,-0.342314995\r\n-4822,24303.67339,847.4919355,682.3991935,1087.040323,20231.05645,641.4959677,761.8145161,1550.205645,9459.254032,542.6048387,1148.193548,1756.467742,12225.40726,1147.822581,3659.919355,3115.084677,4849.274194,1120.846774,267.8024194,2366.669355,10215.43548,345.1048387,475.7096774,1330.322581,12767.6129,598.9516129,115.375,2522.350806,9422.931452,2069.883065,513.6935484,2786.955645,8182.576613,999.9677419,246.9475806,1026.133065,3994.149194,1323.616935,352.0967742,1324.274194,2428.96371,664.2862903,141.9274194,4181.064516,2517.875,1156.274194,511.3629032,3163.528226,619.983871,1092.959677,248,21.73441363,15.5658204,0.697912404,0.864111498,0.551111111,1.432242241\r\n-4823,28656.2561,878.2560976,585.3292683,1109,26340.39024,704.0731707,780.1707317,1667.987805,10873.62195,554.097561,917.597561,1754.121951,13894.54878,1200.146341,3076.402439,2854.682927,5523.829268,1184.47561,287.5365854,2339.085366,12032.81707,380.597561,234.695122,745.7926829,14771.08537,533.0487805,131.6219512,2374.512195,10363.86585,1905.060976,349.4146341,2797.317073,9098.963415,700.6341463,272.7560976,1087.865854,4526.353659,1215.573171,388.9268293,1316.890244,2884.390244,635.4268293,145.5609756,2076.585366,2662.47561,1233.182927,1243.54878,3194.195122,583.3170732,1093.573171,82,12.06003923,9.539788552,0.611784252,0.964705882,0.630769231,0.203022727\r\n-4824,22054.81818,685.8484848,424.8522727,999.3674242,19502,564.1212121,533.6401515,1392.80303,8292.32197,522.5,666.6287879,1670.159091,10429.95076,1008.814394,2310.219697,1606.685606,4121.117424,1026.170455,232.2878788,2289.689394,8755.742424,307.3939394,305.0530303,920.5757576,10190.22727,440.8939394,187.3295455,2048.893939,7579.159091,1631.219697,316.6780303,2784.416667,6559.219697,660.6287879,221.9734848,876.6439394,3082.431818,860.8030303,338.7878788,1294.844697,1929.806818,611.5265152,135.1818182,1765.609848,1834.310606,1031.242424,313.3257576,3038.810606,607.0643939,1101.583333,264,22.54949397,15.90532077,0.708857655,0.882943144,0.661654135,0.69183765\r\n-4825,23992.8526,850.2514451,529.8988439,1038.630058,18614.19075,589.2572254,482.265896,1413.858382,7905.135838,495.265896,572.5,1692.979769,10212.27746,1042.635838,2429.346821,1848.277457,3843.011561,1033.361272,243.0144509,2259.849711,8138.063584,1081.375723,194.1127168,673.8468208,9755.317919,408.5606936,100.1936416,3065.66763,7173.176301,1507.528902,315.8150289,2788.537572,6309.33526,562.4682081,221.1965318,922.517341,3052.216763,873.6907514,335.0635838,1286.430636,1860.872832,573.0144509,133.7456647,1829.913295,1734.875723,1000.557803,285.982659,3087.300578,641.5924855,1100.132948,346,23.1498058,19.37556441,0.547257266,0.945355191,0.791762014,-1.39051567\n\\ No newline at end of file\n' |
b |
diff -r dcfcad35e847 -r ce22e846c5e4 test-data/tutorial_data.h5ad |
b |
Binary file test-data/tutorial_data.h5ad has changed |
b |
diff -r dcfcad35e847 -r ce22e846c5e4 test-data/tutorial_data_pheno.h5ad |
b |
Binary file test-data/tutorial_data_pheno.h5ad has changed |