taxontabletools2 2.3.2__tar.gz → 2.3.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. {taxontabletools2-2.3.2/taxontabletools2.egg-info → taxontabletools2-2.3.3}/PKG-INFO +4 -2
  2. {taxontabletools2-2.3.2 → taxontabletools2-2.3.3}/setup.py +4 -2
  3. {taxontabletools2-2.3.2 → taxontabletools2-2.3.3}/taxontabletools2/taxontabletools_2.0.py +190 -28
  4. taxontabletools2-2.3.3/taxontabletools2/user_preferences.xlsx +0 -0
  5. {taxontabletools2-2.3.2 → taxontabletools2-2.3.3/taxontabletools2.egg-info}/PKG-INFO +4 -2
  6. {taxontabletools2-2.3.2 → taxontabletools2-2.3.3}/taxontabletools2.egg-info/requires.txt +3 -1
  7. taxontabletools2-2.3.2/taxontabletools2/user_preferences.xlsx +0 -0
  8. {taxontabletools2-2.3.2 → taxontabletools2-2.3.3}/LICENSE +0 -0
  9. {taxontabletools2-2.3.2 → taxontabletools2-2.3.3}/MANIFEST.in +0 -0
  10. {taxontabletools2-2.3.2 → taxontabletools2-2.3.3}/README.md +0 -0
  11. {taxontabletools2-2.3.2 → taxontabletools2-2.3.3}/setup.cfg +0 -0
  12. {taxontabletools2-2.3.2 → taxontabletools2-2.3.3}/taxontabletools2/Rscripts/EFI.R +0 -0
  13. {taxontabletools2-2.3.2 → taxontabletools2-2.3.3}/taxontabletools2/Rscripts/diathor.R +0 -0
  14. {taxontabletools2-2.3.2 → taxontabletools2-2.3.3}/taxontabletools2/Rscripts/internal/.DS_Store +0 -0
  15. {taxontabletools2-2.3.2 → taxontabletools2-2.3.3}/taxontabletools2/Rscripts/internal/efiminus.R +0 -0
  16. {taxontabletools2-2.3.2 → taxontabletools2-2.3.3}/taxontabletools2/Rscripts/internal/internal.zip +0 -0
  17. {taxontabletools2-2.3.2 → taxontabletools2-2.3.3}/taxontabletools2/WFD_conversion/.DS_Store +0 -0
  18. {taxontabletools2-2.3.2 → taxontabletools2-2.3.3}/taxontabletools2/WFD_conversion/efi_ecoregions.png +0 -0
  19. {taxontabletools2-2.3.2 → taxontabletools2-2.3.3}/taxontabletools2/WFD_conversion/efi_table.xlsx +0 -0
  20. {taxontabletools2-2.3.2 → taxontabletools2-2.3.3}/taxontabletools2/__init__.py +0 -0
  21. {taxontabletools2-2.3.2 → taxontabletools2-2.3.3}/taxontabletools2/__main__.py +0 -0
  22. {taxontabletools2-2.3.2 → taxontabletools2-2.3.3}/taxontabletools2/read_table_example.xlsx +0 -0
  23. {taxontabletools2-2.3.2 → taxontabletools2-2.3.3}/taxontabletools2/taxonomy_table_example.xlsx +0 -0
  24. {taxontabletools2-2.3.2 → taxontabletools2-2.3.3}/taxontabletools2.egg-info/SOURCES.txt +0 -0
  25. {taxontabletools2-2.3.2 → taxontabletools2-2.3.3}/taxontabletools2.egg-info/dependency_links.txt +0 -0
  26. {taxontabletools2-2.3.2 → taxontabletools2-2.3.3}/taxontabletools2.egg-info/entry_points.txt +0 -0
  27. {taxontabletools2-2.3.2 → taxontabletools2-2.3.3}/taxontabletools2.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: taxontabletools2
3
- Version: 2.3.2
3
+ Version: 2.3.3
4
4
  Summary: Taxontabletools2 - A comprehensive, platform-independent graphical user interface software to explore and visualise DNA metabarcoding data
5
5
  Home-page: https://pypi.org/project/taxontabletools2
6
6
  Author: Till-Hendrik Macher
@@ -12,9 +12,11 @@ Classifier: Operating System :: OS Independent
12
12
  Requires-Python: >=3.10
13
13
  Description-Content-Type: text/markdown
14
14
  License-File: LICENSE
15
- Requires-Dist: streamlit
15
+ Requires-Dist: streamlit>=1.54.0
16
16
  Requires-Dist: stqdm
17
17
  Requires-Dist: pygbif
18
+ Requires-Dist: tables
19
+ Requires-Dist: streamlit-sortables
18
20
  Requires-Dist: geopandas
19
21
  Requires-Dist: scikit-learn
20
22
  Requires-Dist: xlsxwriter
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
5
5
 
6
6
  setuptools.setup(
7
7
  name="taxontabletools2",
8
- version="2.3.2",
8
+ version="2.3.3",
9
9
  author="Till-Hendrik Macher",
10
10
  author_email="macher@uni-trier.de",
11
11
  description="Taxontabletools2 - A comprehensive, platform-independent graphical user interface software to explore and visualise DNA metabarcoding data",
@@ -15,9 +15,11 @@ setuptools.setup(
15
15
  packages=setuptools.find_packages(),
16
16
  license = 'MIT',
17
17
  install_requires=[
18
- "streamlit",
18
+ "streamlit>=1.54.0",
19
19
  "stqdm",
20
20
  "pygbif",
21
+ "tables",
22
+ "streamlit-sortables",
21
23
  "geopandas",
22
24
  "scikit-learn",
23
25
  "xlsxwriter",
@@ -48,6 +48,14 @@ from shapely.geometry.polygon import orient
48
48
  from itertools import product
49
49
  import shapely.wkt as wkt
50
50
  from pygbif import maps
51
+ import warnings
52
+ import tables
53
+ from streamlit_sortables import sort_items
54
+
55
+ ########################################################################################################################
56
+ ## supress table warning (for now)
57
+ warnings.filterwarnings("ignore", category=tables.NaturalNameWarning)
58
+ warnings.filterwarnings("ignore", category=pd.errors.PerformanceWarning)
51
59
 
52
60
  ########################################################################################################################
53
61
  ## session state cheat sheet
@@ -92,6 +100,21 @@ if 'test' == 'pass':
92
100
  df_samples = df_metadata_table['Samples'].values.tolist()
93
101
  selected_metadata = 'Season'
94
102
 
103
+ excel_file = Path('/Users/tillmacher/Desktop/_dev/h5_test/Cave_main_taxon_table.xlsx')
104
+ large_df = pd.read_excel(excel_file)
105
+ h5_file = Path('/Users/tillmacher/Desktop/_dev/h5_test/Cave_main_taxon_table.h5')
106
+ large_df.to_hdf(h5_file, key='Taxon Table')
107
+
108
+ t0 = time.perf_counter()
109
+ df = pd.read_hdf(h5_file, key='Taxon Table')
110
+ t1 = time.perf_counter()
111
+ print(t1 - t0)
112
+
113
+ t0 = time.perf_counter()
114
+ df = pd.read_excel(excel_file, sheet_name='Taxon Table')
115
+ t1 = time.perf_counter()
116
+ print(t1 - t0)
117
+
95
118
  def default_data_handling(): # just for copying
96
119
  # Handle Metadata
97
120
  if fig_level != 'Samples':
@@ -228,7 +251,7 @@ def open_file(path: Path):
228
251
  else:
229
252
  subprocess.run(["xdg-open", path])
230
253
 
231
- def export_taxon_table(table_display_name, df_taxon_table, df_metadata_table, suffix):
254
+ def export_taxon_table(table_display_name, df_taxon_table, df_metadata_table, suffix, format='.xlsx'):
232
255
 
233
256
  ## collect remaining samples and filter metadata_df
234
257
  seq_loc = df_taxon_table.columns.tolist().index('Seq')
@@ -242,21 +265,26 @@ def export_taxon_table(table_display_name, df_taxon_table, df_metadata_table, su
242
265
  df_taxon_table = df_taxon_table[mask]
243
266
 
244
267
  if empty_otus_count != 0:
245
- st.warning(f'Warning: Removed {empty_otus_count} IDs where all samples were empty (zero reads).')
268
+ st.warning(f'Warning: Removed {empty_otus_count} {st.session_state["TTT_hash"]} where all samples were empty (zero reads).')
246
269
 
247
270
  ## create a new file name
248
271
  if suffix == '':
249
- output_xlsx = table_display_name
272
+ output_xlsx = table_display_name.parent / Path(f'{Path(table_display_name).stem}.xlsx')
250
273
  else:
251
- output_xlsx = Path(str(Path(table_display_name)).replace('.xlsx', f'_{suffix}.xlsx'))
274
+ output_xlsx = table_display_name.parent / Path(f'{Path(table_display_name).stem}_{suffix}.xlsx')
252
275
 
253
276
  ## sort taxon table
254
277
  df_taxon_table = df_taxon_table.sort_values(by=['Phylum', 'Class', 'Order', 'Family', 'Genus', 'Species', 'Similarity'])
255
278
 
256
279
  ## export the dataframe
257
- with pd.ExcelWriter(output_xlsx) as writer:
258
- df_taxon_table.to_excel(writer, sheet_name='Taxon Table', index=False)
259
- df_metadata_table.to_excel(writer, sheet_name='Metadata Table', index=False)
280
+ if st.session_state['TTT_tableformat'] == '.h5':
281
+ output_h5 = str(output_xlsx.with_suffix('.h5'))
282
+ df_taxon_table.to_hdf(output_h5, key='Taxon Table')
283
+ df_metadata_table.to_hdf(output_h5, key='Metadata Table')
284
+ else:
285
+ with pd.ExcelWriter(output_xlsx) as writer:
286
+ df_taxon_table.to_excel(writer, sheet_name='Taxon Table', index=False)
287
+ df_metadata_table.to_excel(writer, sheet_name='Metadata Table', index=False)
260
288
 
261
289
  def export_plot(folder_name, suffix, fig, lib):
262
290
 
@@ -920,7 +948,8 @@ def replicate_merging():
920
948
  table_display_name,
921
949
  df_taxon_table,
922
950
  df_metadata_table,
923
- "merged"
951
+ "merged",
952
+ st.session_state['TTT_tableformat']
924
953
  )
925
954
 
926
955
  st.success(
@@ -972,7 +1001,7 @@ def NC_subtraction():
972
1001
  table_display_name,
973
1002
  df_taxon_table,
974
1003
  df_metadata_table,
975
- suffix
1004
+ suffix, st.session_state['TTT_tableformat']
976
1005
  )
977
1006
 
978
1007
  st.success(f'Negative controls were subtracted and a new table was saved to "{str(table_display_name.name).replace(".xlsx", "_NCsub.xlsx")}"')
@@ -1008,7 +1037,7 @@ def read_based_filter():
1008
1037
  table_display_name,
1009
1038
  df_taxon_table,
1010
1039
  st.session_state['df_metadata_table'],
1011
- suffix
1040
+ suffix, st.session_state['TTT_tableformat']
1012
1041
  )
1013
1042
 
1014
1043
  st.success(f'Table was filtered according to read thresholds and a new table was saved to "{str(table_display_name.name).replace(".xlsx", "_readfilter.xlsx")}"')
@@ -1047,7 +1076,7 @@ def read_based_normalisation():
1047
1076
  table_display_name,
1048
1077
  df,
1049
1078
  df_metadata_table,
1050
- suffix
1079
+ suffix, st.session_state['TTT_tableformat']
1051
1080
  )
1052
1081
 
1053
1082
  st.success(f"Table was normalized (subsample size = {sub_sample_size}) and saved to '{str(table_display_name.name).replace('.xlsx', '_norm.xlsx')}'")
@@ -1078,7 +1107,7 @@ def taxonomic_filter():
1078
1107
  table_display_name,
1079
1108
  df_filtered,
1080
1109
  st.session_state['df_metadata_table'],
1081
- taxon_filter_suffix
1110
+ taxon_filter_suffix, st.session_state['TTT_tableformat']
1082
1111
  )
1083
1112
 
1084
1113
  st.success(f'Table was filtered according to the selected taxa and a new table was saved to "{str(table_display_name.name).replace(".xlsx", f"_{taxon_filter_suffix}.xlsx")}"')
@@ -1118,11 +1147,35 @@ def sample_filter():
1118
1147
  table_display_name,
1119
1148
  df_filtered,
1120
1149
  df_metadata_table,
1121
- sample_filter_suffix
1150
+ sample_filter_suffix, st.session_state['TTT_tableformat']
1122
1151
  )
1123
1152
 
1124
1153
  st.success(f'Table was filtered according to the selected samples and a new table was saved to "{str(table_display_name.name).replace(".xlsx", f"_{sample_filter_suffix}.xlsx")}"')
1125
1154
 
1155
+ def empty_sample_remove():
1156
+ table_display_name = st.session_state['table_display_name']
1157
+ df_taxon_table = st.session_state['df_taxon_table'].copy()
1158
+ df_metadata_table = st.session_state['df_metadata_table'].copy()
1159
+ df_samples = st.session_state['df_samples']
1160
+ lc_threshold = st.session_state['lc_threshold']
1161
+
1162
+ remove_samples = []
1163
+ for sample in df_samples:
1164
+ reads_total = df_taxon_table[sample].sum()
1165
+ if reads_total <= lc_threshold:
1166
+ remove_samples.append(sample)
1167
+
1168
+ if remove_samples == []:
1169
+ st.info('No Samples to Remove!')
1170
+ return
1171
+ else:
1172
+ out_df1 = df_taxon_table.copy()
1173
+ out_df1 = out_df1.drop(columns=remove_samples)
1174
+ out_df2 = df_metadata_table.copy()
1175
+ out_df2 = out_df2[~out_df2['Samples'].isin(remove_samples)]
1176
+ export_taxon_table(table_display_name, out_df1, out_df2, f'min_{lc_threshold}', st.session_state['TTT_tableformat'])
1177
+ st.success(f'Removed {len(remove_samples)} sample(s)!')
1178
+
1126
1179
  def trait_filter():
1127
1180
  table_display_name = st.session_state['table_display_name']
1128
1181
  df_taxon_table = st.session_state['df_taxon_table'].copy()
@@ -1158,7 +1211,7 @@ def trait_filter():
1158
1211
  table_display_name,
1159
1212
  df_filtered,
1160
1213
  st.session_state['df_metadata_table'],
1161
- trait_filter_suffix
1214
+ trait_filter_suffix, st.session_state['TTT_tableformat']
1162
1215
  )
1163
1216
 
1164
1217
  st.success(f'Table was filtered according to the selected traits and a new table was saved to "{str(table_display_name.name).replace(".xlsx", f"_{trait_filter_suffix}.xlsx")}"')
@@ -1327,7 +1380,7 @@ def merge_taxon_tables():
1327
1380
  export_metadata_table_df['ESV merge'] = ['Original'] * len(df1_metadata_table) + ['Added'] * len(df2_metadata_table)
1328
1381
 
1329
1382
  ## export df
1330
- export_taxon_table(table_display_name, merged_taxon_table_df, export_metadata_table_df, table_merge_suffix)
1383
+ export_taxon_table(table_display_name, merged_taxon_table_df, export_metadata_table_df, table_merge_suffix, st.session_state['TTT_tableformat'])
1331
1384
 
1332
1385
  st.success(f'Tables were successfully merged!')
1333
1386
 
@@ -1423,7 +1476,7 @@ def add_traits_from_file():
1423
1476
  table_display_name,
1424
1477
  df_merged,
1425
1478
  st.session_state['df_metadata_table'],
1426
- ''
1479
+ '', st.session_state['TTT_tableformat']
1427
1480
  )
1428
1481
  st.session_state['df_taxon_table'] = df_merged.copy()
1429
1482
  st.success(f'Traits were added and the original table was updated!')
@@ -1443,7 +1496,7 @@ def sort_samples():
1443
1496
  table_display_name,
1444
1497
  df_sorted,
1445
1498
  st.session_state['df_metadata_table'],
1446
- ''
1499
+ '', st.session_state['TTT_tableformat']
1447
1500
  )
1448
1501
  st.session_state['df_taxon_table'] = df_sorted.copy()
1449
1502
  st.success(f'Samples were sorted and the original table was updated!')
@@ -1464,7 +1517,7 @@ def sample_rename():
1464
1517
  table_display_name,
1465
1518
  df_taxon_table,
1466
1519
  df_metadata_table,
1467
- ''
1520
+ '', st.session_state['TTT_tableformat']
1468
1521
  )
1469
1522
  st.session_state['df_taxon_table'] = df_taxon_table.copy()
1470
1523
  st.session_state['df_metadata_table'] = df_metadata_table.copy()
@@ -2320,6 +2373,14 @@ def pycircos_plot():
2320
2373
  # Export
2321
2374
  export_plot("Alpha_diversity", f"{name}_circos_{fig_taxon0}_{fig_taxon1}_{fig_taxon2}", fig, "matplot")
2322
2375
 
2376
+ # Export to multiple sheets
2377
+ active_project_path = st.session_state['active_project_path']
2378
+ export_file = active_project_path / "Alpha_diversity" / f"{name}_circos_{fig_taxon0}_{fig_taxon1}_{fig_taxon2}.xlsx"
2379
+ with pd.ExcelWriter(export_file, engine="xlsxwriter") as writer:
2380
+ for key, values in res.items():
2381
+ df = pd.DataFrame(values)
2382
+ df.to_excel(writer, sheet_name=key, index=False)
2383
+
2323
2384
  ########################################################################################################################
2324
2385
  # Beta Diversity
2325
2386
 
@@ -2874,7 +2935,6 @@ def haplotype_distribution():
2874
2935
  res_df = pd.DataFrame(output_lst, columns=['Taxon'] + df_samples)
2875
2936
  export_table("Haplotypes", f'{name}_{haplotype_level}_{haplotype_mode}', res_df, "xlsx")
2876
2937
 
2877
-
2878
2938
  ########################################################################################################################
2879
2939
  # Time Series
2880
2940
  def time_series_richness():
@@ -3124,7 +3184,7 @@ def gbif_accession():
3124
3184
  df_taxon_table.insert(loc=similarity_loc, column='GBIF', value=OTU_gbif_link)
3125
3185
 
3126
3186
  ## export table
3127
- export_taxon_table(table_display_name, df_taxon_table, df_metadata_table, '')
3187
+ export_taxon_table(table_display_name, df_taxon_table, df_metadata_table, '', st.session_state['TTT_tableformat'])
3128
3188
  st.session_state['df_taxon_table'] = df_taxon_table.copy()
3129
3189
  st.success('GBIF Data was implemented!')
3130
3190
 
@@ -3881,7 +3941,7 @@ def calculate_efi_index():
3881
3941
  df_metadata_table[col] = values
3882
3942
  else:
3883
3943
  df_metadata_table[col] = ''
3884
- export_taxon_table(table_display_name, df_taxon_table, df_metadata_table, '')
3944
+ export_taxon_table(table_display_name, df_taxon_table, df_metadata_table, '', st.session_state['TTT_tableformat'])
3885
3945
  st.info('You table was updated - please fill out and reload you Taxon Table.')
3886
3946
  open_file(table_display_name)
3887
3947
  return
@@ -4053,6 +4113,7 @@ TTT_input_path_to_projects = ""
4053
4113
  if user_preferences_xlsx.exists():
4054
4114
  user_data_df = pd.read_excel(user_preferences_xlsx).fillna('')
4055
4115
  TTT_input_path_to_projects = user_data_df[user_data_df['Variable'] == 'TTT_input_path_to_projects']['Value'].values.tolist()[0]
4116
+ TTT_tableformat = user_data_df[user_data_df['Variable'] == 'TTT_tableformat']['Value'].values.tolist()[0]
4056
4117
  TTT_height = user_data_df[user_data_df['Variable'] == 'TTT_height']['Value'].values.tolist()[0]
4057
4118
  TTT_width = user_data_df[user_data_df['Variable'] == 'TTT_width']['Value'].values.tolist()[0]
4058
4119
  TTT_showlegend = user_data_df[user_data_df['Variable'] == 'TTT_showlegend']['Value'].values.tolist()[0]
@@ -4132,8 +4193,10 @@ with st.sidebar:
4132
4193
  # Select Table
4133
4194
  st.write(""" ## Taxon Tables """)
4134
4195
 
4135
- taxon_tables_path = active_project_path / 'TaXon_tables' / '*.xlsx'
4136
- available_taxontables_list = glob.glob(str(taxon_tables_path))
4196
+ # Collect available Files
4197
+ taxon_tables_path = active_project_path / 'TaXon_tables'
4198
+ # collect all .xlsx and .h5 files, skip temp files starting with ~ or ending with .tmp
4199
+ available_taxontables_list = [str(f) for f in taxon_tables_path.glob("*") if f.suffix in (".xlsx", ".h5") and not f.name.startswith("~") and not f.name.endswith(".tmp")]
4137
4200
 
4138
4201
  if available_taxontables_list == []:
4139
4202
  st.info('Please first create a Taxon Table!')
@@ -4141,7 +4204,9 @@ with st.sidebar:
4141
4204
  else:
4142
4205
 
4143
4206
  if st.button('🔄 Refresh Available Tables', width='stretch'):
4144
- available_taxontables_list = glob.glob(str(taxon_tables_path))
4207
+ available_taxontables_list = [str(f) for f in taxon_tables_path.glob("*") if
4208
+ f.suffix in (".xlsx", ".h5") and not f.name.startswith(
4209
+ "~") and not f.name.endswith(".tmp")]
4145
4210
  available_taxontables_dict = {Path(i).name:Path(i) for i in available_taxontables_list}
4146
4211
  st.selectbox(label='Select a TaXon table:', options=sorted(available_taxontables_dict.keys()), key='selected_table_xlsx', index=0)
4147
4212
 
@@ -4153,8 +4218,14 @@ with st.sidebar:
4153
4218
  if st.button('📥 Load Table', type='primary', width='stretch'):
4154
4219
  # Update table name for display
4155
4220
  st.session_state['table_display_name'] = Path(active_taxontable_file)
4221
+
4156
4222
  # Taxon Table -> df_taxon_table
4157
- df_taxon_table = pd.read_excel(active_taxontable_file, sheet_name='Taxon Table').fillna('')
4223
+ if st.session_state['table_display_name'].suffix == '.xlsx':
4224
+ df_taxon_table = pd.read_excel(active_taxontable_file, sheet_name='Taxon Table').fillna('')
4225
+ else:
4226
+ df_taxon_table = pd.read_hdf(active_taxontable_file, key='Taxon Table').fillna('')
4227
+
4228
+ # Taxon Table cols
4158
4229
  hash_loc = df_taxon_table.columns.tolist().index('Hash')
4159
4230
  species_loc = df_taxon_table.columns.tolist().index('Species')
4160
4231
  taxa_cols = df_taxon_table.columns.tolist()[hash_loc+1:species_loc+1]
@@ -4164,8 +4235,13 @@ with st.sidebar:
4164
4235
  if 'Taxon' not in df_taxon_table.columns.tolist():
4165
4236
  df_taxon_table.insert(similarity_loc, "Taxon", taxon_string)
4166
4237
  st.session_state['df_taxon_table'] = df_taxon_table
4238
+
4167
4239
  # Metadata Table -> df_metadata_table
4168
- st.session_state['df_metadata_table'] = pd.read_excel(active_taxontable_file, sheet_name='Metadata Table').fillna('')
4240
+ if st.session_state['table_display_name'].suffix == '.xlsx':
4241
+ st.session_state['df_metadata_table'] = pd.read_excel(active_taxontable_file, sheet_name='Metadata Table').fillna('')
4242
+ else:
4243
+ st.session_state['df_metadata_table'] = pd.read_hdf(active_taxontable_file, key='Metadata Table').fillna('')
4244
+
4169
4245
  # Samples -> df_samples
4170
4246
  seq_loc = st.session_state['df_taxon_table'].columns.tolist().index('Seq')
4171
4247
  taxontable_samples = st.session_state['df_taxon_table'].columns.tolist()[seq_loc+1:]
@@ -4184,6 +4260,10 @@ with st.sidebar:
4184
4260
  del st.session_state["df_taxon_table"]
4185
4261
  del st.session_state["table_display_name"]
4186
4262
 
4263
+ # Delete editor tables
4264
+ st.session_state.pop('df_taxon_table_editor', None)
4265
+ st.session_state.pop('df_metadata_table_editor', None)
4266
+
4187
4267
  if 'df_taxon_table' in st.session_state and 'table_display_name' in st.session_state:
4188
4268
  st.success(f'Active table: {st.session_state["table_display_name"].stem}')
4189
4269
  if st.button('📄 Open Active Table', width='stretch'):
@@ -4194,6 +4274,15 @@ with st.sidebar:
4194
4274
  ################################################################################################################
4195
4275
  st.write(""" # Settings """)
4196
4276
 
4277
+ ################################################################################################################
4278
+ st.write(""" ### Table Format """)
4279
+ format_help_text = (
4280
+ "Excel files (.xlsx) are easy to inspect and edit manually, but can be slow to import, "
4281
+ "especially for large taxon tables. The HDF5 format (.h5) loads much faster and is "
4282
+ "recommended for large datasets, but it is not intended for manual editing."
4283
+ )
4284
+ TTT_tableformat = st.selectbox(label="Select Taxon Table Export Format:", options=[".xlsx", ".h5"], index=[".xlsx", ".h5"].index(TTT_tableformat), key="TTT_tableformat", help=format_help_text)
4285
+
4197
4286
  ################################################################################################################
4198
4287
  st.write(""" ### Presentation """)
4199
4288
  # PLOT HEIGHT
@@ -4246,6 +4335,7 @@ with st.sidebar:
4246
4335
 
4247
4336
  settings_keys = [
4248
4337
  'TTT_input_path_to_projects',
4338
+ 'TTT_tableformat',
4249
4339
  'TTT_height',
4250
4340
  'TTT_width',
4251
4341
  'TTT_showlegend',
@@ -4305,11 +4395,22 @@ if path_to_projects.exists():
4305
4395
  selected_taxonomy_table = st.selectbox(label='Select Taxonomy Table', options=import_folder_files.keys(), key='selected_taxonomy_table')
4306
4396
  st.selectbox(label='Choose Import Format', options=['APSCALE', 'BOLDigger'], key='taxonomy_table_import_format')
4307
4397
 
4308
- st.text_input(label='Enter Name of Taxon Table', key='taxon_table_creation_name')
4398
+ a1, a2 = st.columns(2)
4399
+ with a1:
4400
+ taxon_table_creation_name = st.text_input(label='Enter Name of Taxon Table', key='taxon_table_creation_name')
4401
+ with a2:
4402
+ st.write('')
4403
+ if st.session_state['TTT_tableformat'] == '.h5':
4404
+ st.info(f'Export Format: {st.session_state["TTT_tableformat"]} (fast, recommended for large tables)')
4405
+ else:
4406
+ st.info(f'Export Format: {st.session_state["TTT_tableformat"]} (editable, slower)')
4309
4407
 
4310
4408
  if selected_read_table and selected_taxonomy_table:
4311
4409
  if st.button('Create Taxon Table'):
4312
- create_taxon_table()
4410
+ if taxon_table_creation_name != '':
4411
+ create_taxon_table()
4412
+ else:
4413
+ st.warning('Please enter a name first!')
4313
4414
 
4314
4415
  ########################################################################################################################
4315
4416
 
@@ -4319,6 +4420,57 @@ if 'df_taxon_table' in st.session_state and 'table_display_name' in st.session_s
4319
4420
  available_metadata = st.session_state['df_metadata_table'].columns.tolist()[1:]
4320
4421
  st.session_state['taxa_cols2'] = st.session_state['taxa_cols'] + ['Hash']
4321
4422
 
4423
+ ########################################################################################################################
4424
+ # Table Editor
4425
+ st.markdown("## 📄 Taxon Table Editor")
4426
+
4427
+ with st.expander('See more', expanded=False):
4428
+
4429
+ if 'df_taxon_table_editor' not in st.session_state: st.session_state['df_taxon_table_editor'] = st.session_state['df_taxon_table'].copy()
4430
+ if 'df_metadata_table_editor' not in st.session_state: st.session_state['df_metadata_table_editor'] = st.session_state['df_metadata_table'].copy()
4431
+
4432
+ st.success("This section allows you to manually adjust and update your Taxon Table and Metadata Table.")
4433
+
4434
+ col1, col2, col3 = st.columns(3)
4435
+ with col1:
4436
+ editor_table = st.selectbox("Select Table For Editing:", ["Taxon Table", "Metadata Table"], key="editor_table")
4437
+ with col2:
4438
+ editor_add_columns = st.text_input("Add New Trait or Metadata Column:", value="New Metadata")
4439
+ with col3:
4440
+ st.write("")
4441
+ st.write("")
4442
+ if st.button(f'Add Column: "{editor_add_columns}"', use_container_width=True):
4443
+ if editor_table == "Taxon Table":
4444
+ if editor_add_columns not in st.session_state['df_taxon_table_editor'].columns:
4445
+ cols = st.session_state['df_taxon_table_editor'].columns
4446
+ seq_loc = cols.get_loc("Seq")
4447
+ st.session_state['df_taxon_table_editor'].insert(loc=seq_loc, column=editor_add_columns, value="")
4448
+ else:
4449
+ if editor_add_columns not in st.session_state['df_metadata_table_editor'].columns:
4450
+ st.session_state['df_metadata_table_editor'].insert(loc=1, column=editor_add_columns, value="")
4451
+
4452
+ # ---------------------------
4453
+ # Show editor WITHOUT updating session_state yet
4454
+ # ---------------------------
4455
+ if editor_table == "Taxon Table":
4456
+ edited_df = st.data_editor(st.session_state['df_taxon_table_editor'], height=800, key="taxon_editor")
4457
+ else:
4458
+ edited_df = st.data_editor(st.session_state['df_metadata_table_editor'], height=800, key="meta_editor")
4459
+
4460
+ # ---------------------------
4461
+ # Apply edits only when user clicks 'Submit'
4462
+ # ---------------------------
4463
+ if st.button("💾 Apply Changes To File", width='stretch'):
4464
+ edited_df = edited_df.fillna('')
4465
+ if editor_table == "Taxon Table":
4466
+ st.session_state['df_taxon_table'] = edited_df.copy()
4467
+ export_taxon_table(st.session_state['table_display_name'], edited_df, st.session_state['df_metadata_table'], '', st.session_state['TTT_tableformat'])
4468
+ st.success("Taxon Table updated!")
4469
+ else:
4470
+ st.session_state['df_metadata_table'] = edited_df.copy()
4471
+ export_taxon_table(st.session_state['table_display_name'], st.session_state['df_taxon_table'], edited_df, '', st.session_state['TTT_tableformat'])
4472
+ st.success("Metadata Table updated!")
4473
+
4322
4474
  ########################################################################################################################
4323
4475
  st.markdown("## 🖥️ Basic Stats")
4324
4476
  with st.expander(expanded=True, label='See more'):
@@ -4507,6 +4659,16 @@ if 'df_taxon_table' in st.session_state and 'table_display_name' in st.session_s
4507
4659
  sample_filter()
4508
4660
  st.divider()
4509
4661
 
4662
+ st.write('### Remove Low Coverage Samples')
4663
+ col1, col2 = st.columns([2,6])
4664
+ with col1:
4665
+ lc_threshold = st.number_input(label='Minimum Sequencing Depth per Sample:', value=0, min_value=0, key='lc_threshold')
4666
+ with col2:
4667
+ st.write('')
4668
+ st.info(f'Samples with <= {lc_threshold} reads will be discarded from the Taxon Table.')
4669
+ if st.button('🔄 Remove Low-coverage Samples', width='stretch'):
4670
+ empty_sample_remove()
4671
+ st.divider()
4510
4672
 
4511
4673
  st.write('### Trait Filter')
4512
4674
  col1, col2 = st.columns([2,6])
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: taxontabletools2
3
- Version: 2.3.2
3
+ Version: 2.3.3
4
4
  Summary: Taxontabletools2 - A comprehensive, platform-independent graphical user interface software to explore and visualise DNA metabarcoding data
5
5
  Home-page: https://pypi.org/project/taxontabletools2
6
6
  Author: Till-Hendrik Macher
@@ -12,9 +12,11 @@ Classifier: Operating System :: OS Independent
12
12
  Requires-Python: >=3.10
13
13
  Description-Content-Type: text/markdown
14
14
  License-File: LICENSE
15
- Requires-Dist: streamlit
15
+ Requires-Dist: streamlit>=1.54.0
16
16
  Requires-Dist: stqdm
17
17
  Requires-Dist: pygbif
18
+ Requires-Dist: tables
19
+ Requires-Dist: streamlit-sortables
18
20
  Requires-Dist: geopandas
19
21
  Requires-Dist: scikit-learn
20
22
  Requires-Dist: xlsxwriter
@@ -1,6 +1,8 @@
1
- streamlit
1
+ streamlit>=1.54.0
2
2
  stqdm
3
3
  pygbif
4
+ tables
5
+ streamlit-sortables
4
6
  geopandas
5
7
  scikit-learn
6
8
  xlsxwriter