taxontabletools2 2.3.4__tar.gz → 2.3.6__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 (26) hide show
  1. {taxontabletools2-2.3.4/taxontabletools2.egg-info → taxontabletools2-2.3.6}/PKG-INFO +1 -1
  2. {taxontabletools2-2.3.4 → taxontabletools2-2.3.6}/setup.py +1 -1
  3. {taxontabletools2-2.3.4 → taxontabletools2-2.3.6}/taxontabletools2/taxontabletools_2.0.py +110 -295
  4. {taxontabletools2-2.3.4 → taxontabletools2-2.3.6/taxontabletools2.egg-info}/PKG-INFO +1 -1
  5. {taxontabletools2-2.3.4 → taxontabletools2-2.3.6}/LICENSE +0 -0
  6. {taxontabletools2-2.3.4 → taxontabletools2-2.3.6}/MANIFEST.in +0 -0
  7. {taxontabletools2-2.3.4 → taxontabletools2-2.3.6}/README.md +0 -0
  8. {taxontabletools2-2.3.4 → taxontabletools2-2.3.6}/setup.cfg +0 -0
  9. {taxontabletools2-2.3.4 → taxontabletools2-2.3.6}/taxontabletools2/Rscripts/EFI.R +0 -0
  10. {taxontabletools2-2.3.4 → taxontabletools2-2.3.6}/taxontabletools2/Rscripts/diathor.R +0 -0
  11. {taxontabletools2-2.3.4 → taxontabletools2-2.3.6}/taxontabletools2/Rscripts/internal/.DS_Store +0 -0
  12. {taxontabletools2-2.3.4 → taxontabletools2-2.3.6}/taxontabletools2/Rscripts/internal/efiminus.R +0 -0
  13. {taxontabletools2-2.3.4 → taxontabletools2-2.3.6}/taxontabletools2/Rscripts/internal/internal.zip +0 -0
  14. {taxontabletools2-2.3.4 → taxontabletools2-2.3.6}/taxontabletools2/WFD_conversion/.DS_Store +0 -0
  15. {taxontabletools2-2.3.4 → taxontabletools2-2.3.6}/taxontabletools2/WFD_conversion/efi_ecoregions.png +0 -0
  16. {taxontabletools2-2.3.4 → taxontabletools2-2.3.6}/taxontabletools2/WFD_conversion/efi_table.xlsx +0 -0
  17. {taxontabletools2-2.3.4 → taxontabletools2-2.3.6}/taxontabletools2/__init__.py +0 -0
  18. {taxontabletools2-2.3.4 → taxontabletools2-2.3.6}/taxontabletools2/__main__.py +0 -0
  19. {taxontabletools2-2.3.4 → taxontabletools2-2.3.6}/taxontabletools2/read_table_example.xlsx +0 -0
  20. {taxontabletools2-2.3.4 → taxontabletools2-2.3.6}/taxontabletools2/taxonomy_table_example.xlsx +0 -0
  21. {taxontabletools2-2.3.4 → taxontabletools2-2.3.6}/taxontabletools2/user_preferences.xlsx +0 -0
  22. {taxontabletools2-2.3.4 → taxontabletools2-2.3.6}/taxontabletools2.egg-info/SOURCES.txt +0 -0
  23. {taxontabletools2-2.3.4 → taxontabletools2-2.3.6}/taxontabletools2.egg-info/dependency_links.txt +0 -0
  24. {taxontabletools2-2.3.4 → taxontabletools2-2.3.6}/taxontabletools2.egg-info/entry_points.txt +0 -0
  25. {taxontabletools2-2.3.4 → taxontabletools2-2.3.6}/taxontabletools2.egg-info/requires.txt +0 -0
  26. {taxontabletools2-2.3.4 → taxontabletools2-2.3.6}/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.4
3
+ Version: 2.3.6
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
@@ -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.4",
8
+ version="2.3.6",
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",
@@ -85,7 +85,7 @@ warnings.filterwarnings("ignore", category=pd.errors.PerformanceWarning)
85
85
  # TTT_colorscale
86
86
 
87
87
  if 'test' == 'pass':
88
- table_display_name = Path('/Users/tillmacher/Desktop/TTT_projects/AA_test/TaXon_tables/River_mulde_fish_eDNA_2019_merged_NCsub_fish.xlsx')
88
+ table_display_name = Path('/Users/tillmacher/Desktop/TTT_projects/AA_test/TaXon_tables/LL_fwh_taxon_table_NCsub_cons_invertebrates_merged_perlodes.xlsx')
89
89
  df_taxon_table = pd.read_excel(table_display_name).fillna('')
90
90
  seq_loc = df_taxon_table.columns.tolist().index('Seq')
91
91
  hash_loc = df_taxon_table.columns.tolist().index('Hash')
@@ -100,20 +100,6 @@ if 'test' == 'pass':
100
100
  df_samples = df_metadata_table['Samples'].values.tolist()
101
101
  selected_metadata = 'Season'
102
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
103
 
118
104
  def default_data_handling(): # just for copying
119
105
  # Handle Metadata
@@ -538,14 +524,22 @@ def create_taxon_table():
538
524
  samples = merged_df.columns.tolist()[seq_loc:]
539
525
  metadata_df = pd.DataFrame([[i] + i.split('_') for i in samples])
540
526
  metadata_df.rename(columns={0: "Samples"}, inplace=True)
541
-
542
- # Save table to a single Excel file
543
- to_excel_path = st.session_state['active_project_path'] / 'TaXon_tables' / str(
544
- st.session_state['taxon_table_creation_name'] + '_taxon_table.xlsx')
545
- with pd.ExcelWriter(to_excel_path, engine="openpyxl") as writer:
546
- merged_df.to_excel(writer, sheet_name="Taxon Table", index=False)
547
- metadata_df.to_excel(writer, sheet_name="Metadata Table", index=False)
548
- st.success(f'Saved Taxon Table as: {to_excel_path}')
527
+ metadata_df.insert(loc=1, column="Date", value="")
528
+ metadata_df.insert(loc=1, column="Longitude", value="")
529
+ metadata_df.insert(loc=1, column="Latitude", value="")
530
+
531
+ # Write table
532
+ if st.session_state['taxon_table_export_format'] == '.h5':
533
+ to_h5_path = st.session_state['active_project_path'] / 'TaXon_tables' / str(st.session_state['taxon_table_creation_name'] + '_taxon_table.h5')
534
+ merged_df.to_hdf(to_h5_path, key='Taxon Table')
535
+ metadata_df.to_hdf(to_h5_path, key='Metadata Table')
536
+ st.success(f'Saved Taxon Table as: {to_h5_path}')
537
+ else:
538
+ to_excel_path = st.session_state['active_project_path'] / 'TaXon_tables' / str(st.session_state['taxon_table_creation_name'] + '_taxon_table.xlsx')
539
+ with pd.ExcelWriter(to_excel_path, engine="openpyxl") as writer:
540
+ merged_df.to_excel(writer, sheet_name="Taxon Table", index=False)
541
+ metadata_df.to_excel(writer, sheet_name="Metadata Table", index=False)
542
+ st.success(f'Saved Taxon Table as: {to_excel_path}')
549
543
 
550
544
  else:
551
545
  expected_columns = ["id", "phylum", "class", "order", "family", "genus", "species", "pct_identity", "status", "records", "records_ratio", "selected_level", "BIN", "flags"]
@@ -587,14 +581,22 @@ def create_taxon_table():
587
581
  samples = merged_df.columns.tolist()[merged_df.columns.tolist().index('Seq') + 1:]
588
582
  metadata_df = pd.DataFrame([[i] + i.split('_') for i in samples])
589
583
  metadata_df.rename(columns={0: "Samples"}, inplace=True)
590
-
591
- # Save table to a single Excel file
592
- to_excel_path = st.session_state['active_project_path'] / 'TaXon_tables' / str(
593
- st.session_state['taxon_table_creation_name'] + '_taxon_table.xlsx')
594
- with pd.ExcelWriter(to_excel_path, engine="openpyxl") as writer:
595
- merged_df.to_excel(writer, sheet_name="Taxon Table", index=False)
596
- metadata_df.to_excel(writer, sheet_name="Metadata Table", index=False)
597
- st.success(f'Saved Taxon Table as: {to_excel_path}')
584
+ metadata_df.insert(loc=1, column="Date", value="")
585
+ metadata_df.insert(loc=1, column="Longitude", value="")
586
+ metadata_df.insert(loc=1, column="Latitude", value="")
587
+
588
+ # Write table
589
+ if st.session_state['taxon_table_export_format'] == '.h5':
590
+ to_h5_path = st.session_state['active_project_path'] / 'TaXon_tables' / str(st.session_state['taxon_table_creation_name'] + '_taxon_table.h5')
591
+ merged_df.to_hdf(to_h5_path, key='Taxon Table')
592
+ metadata_df.to_hdf(to_h5_path, key='Metadata Table')
593
+ st.success(f'Saved Taxon Table as: {to_h5_path}')
594
+ else:
595
+ to_excel_path = st.session_state['active_project_path'] / 'TaXon_tables' / str(st.session_state['taxon_table_creation_name'] + '_taxon_table.xlsx')
596
+ with pd.ExcelWriter(to_excel_path, engine="openpyxl") as writer:
597
+ merged_df.to_excel(writer, sheet_name="Taxon Table", index=False)
598
+ metadata_df.to_excel(writer, sheet_name="Metadata Table", index=False)
599
+ st.success(f'Saved Taxon Table as: {to_excel_path}')
598
600
 
599
601
  ########################################################################################################################
600
602
  # Tutorial
@@ -3259,11 +3261,6 @@ def gbif_taxonomy_validation():
3259
3261
 
3260
3262
  def gbif_occurrence_download():
3261
3263
  df_taxon_table = st.session_state['df_taxon_table'].copy()
3262
-
3263
- username = 'till_macher'
3264
- password = 'ZN_kw7@!gBsABNn'
3265
- email = 'macher@uni-trier.de'
3266
-
3267
3264
  occ.download_get(key='0024088-260226173443078')
3268
3265
 
3269
3266
  active_project_path = st.session_state['active_project_path']
@@ -3586,47 +3583,57 @@ def taxon_distribution_map():
3586
3583
  ########################################################################################################################
3587
3584
  # ESC calculation
3588
3585
 
3589
- def convert_to_perlodes(path_to_outdirs, taxon_table_xlsx, taxon_table_df, samples, metadata_df, traits_df, tool_settings):
3586
+ def convert_to_perlodes():
3590
3587
  # Make copies of input dataframes to prevent altering the originals
3591
- taxon_table_df = taxon_table_df.copy()
3592
- metadata_df = metadata_df.copy()
3593
- river_types_dict = {i:j for i,j in metadata_df[['Sample', 'Perlodes_river_type']].values.tolist()}
3594
- taxa_list_dict = {i:j for i,j in metadata_df[['Sample', 'Perlodes_taxa_list']].values.tolist()}
3595
- usage_dict = {i:j for i,j in metadata_df[['Sample', 'Perlodes_usage']].values.tolist()}
3596
-
3597
- # Ensure all samples have metadata in all three categories
3598
- samples = [
3599
- i for i in samples
3600
- if i in river_types_dict and pd.notna(river_types_dict[i]) and
3601
- i in taxa_list_dict and pd.notna(taxa_list_dict[i]) and
3602
- i in usage_dict and pd.notna(usage_dict[i])
3603
- ]
3588
+ table_display_name = st.session_state['table_display_name'].stem
3589
+ df_taxon_table = st.session_state['df_taxon_table'].copy()
3590
+ df_metadata_table = st.session_state['df_metadata_table'].copy()
3591
+ df_samples = st.session_state['df_samples'].copy()
3592
+ table_display_name = st.session_state['table_display_name']
3593
+ df_taxon_cols = st.session_state['df_taxon_cols']
3594
+ perlodes_measure = st.session_state['perlodes_measure']
3604
3595
 
3605
- if len(samples) == 0:
3606
- st.warning('Please fill out the required metadata for at least one sample!')
3596
+ # Check if all required columns are present in the table:
3597
+ perlodes_cols = {
3598
+ "Perlodes_river_type": "",
3599
+ "Perlodes_taxa_list": "original",
3600
+ "Perlodes_usage": "keine"}
3601
+
3602
+ available_metadata = df_metadata_table.columns.tolist()
3603
+ if not all(col in available_metadata for col in perlodes_cols.keys()):
3604
+ st.warning('Could not find all required PERLODES columns in the Metadata Table.')
3605
+ for col, values in perlodes_cols.items():
3606
+ df_metadata_table[col] = values
3607
+ export_taxon_table(table_display_name, df_taxon_table, df_metadata_table, '', st.session_state['TTT_tableformat'])
3608
+ st.info('You table was updated - please fill out and reload you Taxon Table.')
3609
+ open_file(table_display_name)
3607
3610
  return
3608
3611
 
3609
3612
  # Extract relevant settings from the tool settings
3610
- presence_absence = tool_settings['presence_absence']
3611
- taxon_table_taxonomy = taxon_table_df.columns.tolist()[1:7]
3612
-
3613
3613
  all_reads = []
3614
- for sample in samples:
3615
- total_reads = taxon_table_df[sample].sum()
3614
+ for sample in df_samples:
3615
+ total_reads = df_taxon_table[sample].sum()
3616
3616
  taxon_dict = {}
3617
- for OTU in taxon_table_df[taxon_table_taxonomy + [sample]].values.tolist():
3618
- taxon = [item for item in OTU[0:6] if item != ''][-1]
3617
+ for OTU in df_taxon_table[df_taxon_cols + [sample]].values.tolist():
3618
+ taxon = [i for i in OTU[:-1] if i != ''][-1]
3619
3619
  if taxon not in taxon_dict.keys():
3620
3620
  n_reads = OTU[-1]
3621
- taxon_dict[taxon] = n_reads
3621
+ if perlodes_measure == 'Presence/Absence' or perlodes_measure == 'Rel. Reads':
3622
+ taxon_dict[taxon] = n_reads
3623
+ else:
3624
+ taxon_dict[taxon] = 1 if n_reads != 0 else 0
3622
3625
  else:
3623
3626
  n_reads = OTU[-1]
3624
- taxon_dict[taxon] = taxon_dict[taxon] + n_reads
3625
- if presence_absence == True:
3627
+ if perlodes_measure == 'Presence/Absence' or perlodes_measure == 'Rel. Reads':
3628
+ taxon_dict[taxon] = taxon_dict[taxon] + n_reads
3629
+ else:
3630
+ add = 1 if n_reads != 0 else 0
3631
+ taxon_dict[taxon] = taxon_dict[taxon] + add
3632
+ if perlodes_measure == "Presence/Absence":
3626
3633
  pa_list = [1 if i != 0 else 0 for i in taxon_dict.values()]
3627
3634
  all_reads.append(pa_list)
3628
- elif presence_absence == 'Relative':
3629
- rel_list = [round(i / total_reads * 100, 2) for i in taxon_dict.values()]
3635
+ elif perlodes_measure == 'Rel. Reads':
3636
+ rel_list = [i / total_reads * 100 for i in taxon_dict.values()]
3630
3637
  all_reads.append(rel_list)
3631
3638
  else:
3632
3639
  all_reads.append(list(taxon_dict.values()))
@@ -3636,209 +3643,29 @@ def convert_to_perlodes(path_to_outdirs, taxon_table_xlsx, taxon_table_df, sampl
3636
3643
  species = list(taxon_dict.keys())
3637
3644
  perlodes_df = pd.DataFrame(species, columns=['species'])
3638
3645
  perlodes_df.insert(0, '', index)
3639
- perlodes_df = pd.concat([perlodes_df, pd.DataFrame(all_reads, index=samples).transpose()], axis=1)
3646
+ perlodes_df = pd.concat([perlodes_df, pd.DataFrame(all_reads, index=df_samples).transpose()], axis=1)
3640
3647
 
3641
3648
  # convert the df to match the (complicated) perlodes input format
3642
- columns = ['ID_ART', 'TAXON_NAME'] + samples
3643
- gewässertyp = ['Gewässertyp', ''] + [river_types_dict[i] for i in samples]
3644
- Taxaliste = ['Taxaliste', ''] + [taxa_list_dict[i] for i in samples]
3645
- Nutzung = ['Nutzung', ''] + [usage_dict[i] for i in samples]
3649
+ columns = ['ID_ART', 'TAXON_NAME'] + df_samples
3650
+ # Gewässertyp
3651
+ gewässertyp = ['Gewässertyp', ''] + df_metadata_table['Perlodes_river_type'].values.tolist()
3652
+ # Taxaliste
3653
+ Taxaliste = ['Taxaliste', ''] + df_metadata_table['Perlodes_taxa_list'].values.tolist()
3654
+ # Nutzung
3655
+ Nutzung = ['Nutzung', ''] + df_metadata_table['Perlodes_usage'].values.tolist()
3656
+
3646
3657
  taxa = [[1] + i[1:] for i in perlodes_df.values.tolist()]
3647
3658
  df_list = [gewässertyp] + [Taxaliste] + [Nutzung] + taxa
3648
3659
  perlodes_input_df = pd.DataFrame(df_list, columns=columns)
3649
3660
 
3650
- # write the filtered list to a dataframe
3651
- if presence_absence == True:
3652
- perlodes_directory = Path(str(path_to_outdirs) + "/" + "Perlodes" + "/" + taxon_table_xlsx.stem)
3653
- perlodes_xlsx = Path(str(perlodes_directory) + "_Perlodes_PA.xlsx")
3654
- perlodes_input_df.to_excel(perlodes_xlsx, index=False)
3655
- elif presence_absence == 'Relative':
3656
- perlodes_directory = Path(str(path_to_outdirs) + "/" + "Perlodes" + "/" + taxon_table_xlsx.stem)
3657
- perlodes_xlsx = Path(str(perlodes_directory) + "_Perlodes_RELATIVE_ABUNDANCE.xlsx")
3658
- perlodes_input_df.to_excel(perlodes_xlsx, index=False)
3661
+ if perlodes_measure == 'Presence/Absence':
3662
+ suffix = f'{table_display_name.stem}_PA'
3663
+ elif perlodes_measure == 'Rel. Reads':
3664
+ suffix = f'{table_display_name.stem}_RelReads'
3659
3665
  else:
3660
- perlodes_directory = Path(str(path_to_outdirs) + "/" + "Perlodes" + "/" + taxon_table_xlsx.stem)
3661
- perlodes_xlsx = Path(str(perlodes_directory) + "_Perlodes_ABUNDANCE.xlsx")
3662
- perlodes_input_df.to_excel(perlodes_xlsx, index=False)
3663
-
3664
- st.success(f'Wrote Perlodes input file to: {perlodes_xlsx}')
3665
-
3666
- def convert_to_phylib(path_to_outdirs, taxon_table_xlsx, taxon_table_df, samples, metadata_df, traits_df, tool_settings):
3667
-
3668
- #get the taxonomy from the operational taxon list
3669
- operational_taxon_list_df = pd.read_excel(Path(operational_taxon_list), sheet_name="TTT import").fillna('')
3670
-
3671
- # load the taxon table and create a list
3672
- TaXon_table_xlsx = Path(TaXon_table_xlsx)
3673
- TaXon_table_df = pd.read_excel(TaXon_table_xlsx).fillna('')
3674
- meta_data_df = collect_metadata(TaXon_table_df)
3675
- TaXon_table_df = strip_metadata(TaXon_table_df)
3676
- TaXon_table_taxonomy = TaXon_table_df.columns.tolist()[0:7]
3677
- samples_list = TaXon_table_df.columns.tolist()[10:]
3678
-
3679
- ## load the metadata -> freshwater type
3680
- Meta_data_table_xlsx = Path(str(path_to_outdirs) + "/" + "Meta_data_table" + "/" + TaXon_table_xlsx.stem + "_metadata.xlsx")
3681
- Meta_data_table_df = pd.read_excel(Meta_data_table_xlsx, header=0).fillna("")
3682
- Meta_data_table_samples = Meta_data_table_df['Samples'].tolist()
3683
- metadata_loc = Meta_data_table_df.columns.tolist().index(meta_data_to_test)
3684
- types_dict = {i[0]:i[1] for i in Meta_data_table_df[['Samples', meta_data_to_test]].values.tolist()}
3685
-
3686
- ## drop samples with metadata called nan (= empty)
3687
- drop_samples = [i[0] for i in Meta_data_table_df.values.tolist() if i[metadata_loc] == ""]
3688
-
3689
- ## test if samples have metadata
3690
- if drop_samples != []:
3691
- sg.PopupError("Please fill out all the metadata for all samples.")
3692
-
3693
- ## test if all metadata for Phylib is available
3694
- elif len(set([True if i in Meta_data_table_df.columns.tolist() else False for i in ['Ökoregion', 'Makrophytenverödung', 'Begründung', 'Helophytendominanz', 'Diatomeentyp', 'Phytobenthostyp', 'Makrophytentyp', 'WRRL-Typ', 'Gesamtdeckungsgrad']])) != 1:
3695
- sg.PopupError("Please fill out all the required phylib metadata for all samples.")
3696
-
3697
- elif sorted(Meta_data_table_samples) == sorted(samples_list):
3698
- # store hits and dropped OTUs
3699
- hit_list, dropped_list = [], []
3700
-
3701
- # loop through the taxon table
3702
- for taxonomy in TaXon_table_df[TaXon_table_taxonomy].values.tolist():
3703
- ## test species
3704
- if taxonomy[6] != '' and taxonomy[6] in operational_taxon_list_df['Species'].values.tolist():
3705
- ## merge the OTU's taxonomy with OTL information
3706
- res = taxonomy + operational_taxon_list_df[operational_taxon_list_df['Species'].str.contains(taxonomy[6])][['DV-NR.', 'Taxon']].values.tolist()[0]
3707
-
3708
- ## test genus
3709
- elif taxonomy[5] != '' and taxonomy[5] in operational_taxon_list_df['Genus'].values.tolist():
3710
- ## merge the OTU's taxonomy with OTL information
3711
- res = taxonomy + operational_taxon_list_df[operational_taxon_list_df['Genus'].str.contains(taxonomy[5])][['DV-NR.', 'Taxon']].values.tolist()[0]
3712
-
3713
- ## test family
3714
- elif taxonomy[4] != '' and taxonomy[4] in operational_taxon_list_df['Family'].values.tolist():
3715
- ## merge the OTU's taxonomy with OTL information
3716
- res = taxonomy + operational_taxon_list_df[operational_taxon_list_df['Family'].str.contains(taxonomy[4])][['DV-NR.', 'Taxon']].values.tolist()[0]
3717
-
3718
- ## test order
3719
- elif taxonomy[3] != '' and taxonomy[3] in operational_taxon_list_df['Order'].values.tolist():
3720
- ## merge the OTU's taxonomy with OTL information
3721
- res = taxonomy + operational_taxon_list_df[operational_taxon_list_df['Order'].str.contains(taxonomy[3])][['DV-NR.', 'Taxon']].values.tolist()[0]
3722
-
3723
- ## test class
3724
- elif taxonomy[2] != '' and taxonomy[2] in operational_taxon_list_df['Class'].values.tolist():
3725
- ## merge the OTU's taxonomy with OTL information
3726
- res = taxonomy + operational_taxon_list_df[operational_taxon_list_df['Class'].str.contains(taxonomy[2])][['DV-NR.', 'Taxon']].values.tolist()[0]
3727
-
3728
- ## test phylum
3729
- elif taxonomy[1] != '' and taxonomy[1] in operational_taxon_list_df['Phylum'].values.tolist():
3730
- ## merge the OTU's taxonomy with OTL information
3731
- res = taxonomy + operational_taxon_list_df[operational_taxon_list_df['Phylum'].str.contains(taxonomy[1])][['DV-NR.', 'Taxon']].values.tolist()[0]
3732
- else:
3733
- res = taxonomy + ['', '']
3734
- dropped_list.append(taxonomy)
3735
-
3736
- hit_list.append(res)
3737
-
3738
- ## create a dataframe
3739
- ## create a new df and export it as TaXon table
3740
- df = pd.DataFrame(hit_list, columns=TaXon_table_df.columns[0:7].values.tolist() + ['DV-NR.', 'Taxon (Phylib)'])
3741
- concatenated_df = pd.concat([df, TaXon_table_df[samples_list + ['Similarity', 'Status', 'seq']]], axis=1)
3742
- reordered_df = concatenated_df[['ID', 'Phylum', 'Class', 'Order', 'Family', 'Genus', 'Species', 'Similarity', 'Status', 'DV-NR.', 'Taxon (Phylib)', 'seq'] + samples_list]
3743
- reordered_metadata_df = add_metadata(reordered_df, meta_data_df)
3744
- phylib_TaXon_Table = Path(str(path_to_outdirs) + "/" + "TaXon_tables" + "/" + TaXon_table_xlsx.stem + "_phylib.xlsx")
3745
- reordered_metadata_df.to_excel(phylib_TaXon_Table, index=False)
3746
-
3747
- # create an output list for phylib
3748
- messwerte_list = []
3749
- messtellen_list = []
3750
-
3751
- for sample in samples_list:
3752
- ## collect information about the sampling site
3753
- sample_metadata_df = Meta_data_table_df.loc[Meta_data_table_df['Samples'] == sample]
3754
- messstelle = sample
3755
- ökoregion = sample_metadata_df['Ökoregion'].values.tolist()[0]
3756
- Makrophytenverödung = sample_metadata_df['Makrophytenverödung'].values.tolist()[0]
3757
- Begründung = sample_metadata_df['Begründung'].values.tolist()[0]
3758
- Helophytendominanz = sample_metadata_df['Helophytendominanz'].values.tolist()[0]
3759
- Diatomeentyp = sample_metadata_df['Diatomeentyp'].values.tolist()[0]
3760
- Phytobenthostyp = sample_metadata_df['Phytobenthostyp'].values.tolist()[0]
3761
- Makrophytentyp = sample_metadata_df['Makrophytentyp'].values.tolist()[0]
3762
- WRRL_Typ = sample_metadata_df['WRRL-Typ'].values.tolist()[0]
3763
- Gesamtdeckungsgrad = sample_metadata_df['Gesamtdeckungsgrad'].values.tolist()[0]
3764
- messtellen_list.append([messstelle, ökoregion, Makrophytenverödung, Begründung, Helophytendominanz, Diatomeentyp, Phytobenthostyp, Makrophytentyp, WRRL_Typ, Gesamtdeckungsgrad])
3765
-
3766
- ## calcualte sum of reads for taxa with multiple OTUs
3767
- sample_df = reordered_metadata_df[[sample, 'DV-NR.', 'Taxon (Phylib)']]
3768
- reads_dict = {}
3769
- for taxon in sample_df.values.tolist():
3770
- key = taxon[2]
3771
- values = taxon[:2]
3772
- if key != '':
3773
- if key not in reads_dict.keys():
3774
- reads_dict[key] = values
3775
- else:
3776
- reads_dict[key] = [reads_dict[key][0] + values[0], values[1]]
3777
-
3778
- ## remove duplicates
3779
- samples_taxa = [[key]+values for key,values in reads_dict.items() if values[0] != 0]
3780
-
3781
- ## if PA data is required: Convert to 1/0
3782
- if presence_absence == True:
3783
- samples_taxa = [[i[0], 1, i[2]] for i in samples_taxa]
3784
-
3785
- ## calculate the overall number of reads/specimens. This is required for later relative abundance calculation
3786
- sum_measurement = sum([i[1] for i in samples_taxa])
3787
-
3788
- ## loop through all taxa
3789
- for taxon in samples_taxa:
3790
- ## if the taxon (assigned to the OTU) is present in the sample and present on the OTL, continue
3791
- ## add all relevant information to list (for df)
3792
- probe = sample
3793
- taxon_id = taxon[2]
3794
- taxonname = taxon[0]
3795
- form = "o.A."
3796
- messwert = taxon[1] / sum_measurement * 100
3797
- einheit = "%"
3798
- cf = ""
3799
- messwerte_list.append([messstelle, probe, taxon_id, taxonname, form, messwert, einheit, cf])
3800
-
3801
- phylib_df_1 = pd.DataFrame(messtellen_list, columns=["Messstelle", "Ökoregion", "Makrophytenverödung", "Begründung", "Helophytendominanz", "Diatomeentyp", "Phytobenthostyp", "Makrophytentyp", "WRRL-Typ", "Gesamtdeckungsgrad"])
3802
- phylib_df_2 = pd.DataFrame(messwerte_list, columns=["Messstelle", "Probe", "Taxon", "Taxonname", "Form", "Messwert", "Einheit", "cf"])
3803
-
3804
- if presence_absence == False:
3805
- phylib_directory = Path(str(path_to_outdirs) + "/" + "Phylib" + "/" + TaXon_table_xlsx.stem)
3806
- phylib_xlsx = Path(str(phylib_directory) + "_phylib_ABUNDANCE.xlsx")
3807
- writer = pd.ExcelWriter(phylib_xlsx, engine='xlsxwriter')
3808
- else:
3809
- phylib_directory = Path(str(path_to_outdirs) + "/" + "Phylib" + "/" + TaXon_table_xlsx.stem)
3810
- phylib_xlsx = Path(str(phylib_directory) + "_phylib_PA.xlsx")
3811
- writer = pd.ExcelWriter(phylib_xlsx, engine='xlsxwriter')
3812
- phylib_df_1.to_excel(writer, sheet_name='Messstelle', index=False)
3813
- phylib_df_2.to_excel(writer, sheet_name='Messwerte', index=False)
3814
- writer.save()
3815
-
3816
- ################################################################################################################
3817
- ## create some plots and provide statistics
3818
- unique_original_taxa = list(k for k, _ in itertools.groupby(reordered_metadata_df[['Phylum', 'Class', 'Order', 'Family', 'Genus', 'Species']].values.tolist()))
3819
- len(unique_original_taxa)
3820
-
3821
- unique_OTL_taxa = [i for i in set(reordered_metadata_df['Taxon (Phylib)'].values.tolist()) if i != '']
3822
- len(unique_OTL_taxa)
3823
-
3824
- phylib_conversion_loss = {}
3825
- for taxon in unique_OTL_taxa:
3826
- all_taxa = reordered_metadata_df[reordered_metadata_df['Taxon (Phylib)'].str.contains(taxon)][['Phylum', 'Class', 'Order', 'Family', 'Genus', 'Species']].values.tolist()
3827
- unique_taxa = set([''.join(i) for i in all_taxa])
3828
- phylib_conversion_loss[taxon] = len(unique_taxa)
3829
-
3830
- perlodes_conversion_loss = {k: v for k, v in sorted(phylib_conversion_loss.items(), key=lambda item: item[1])}
3831
-
3832
- fig = go.Figure()
3833
- x_values = [i[:19] for i in list(perlodes_conversion_loss.keys())[-30:][::-1]] ## [:20] to cut names off
3834
- y_values = list(perlodes_conversion_loss.values())[-30:][::-1]
3835
- fig.add_trace(go.Bar(x=x_values, y=y_values, marker_color='blue'))
3836
- fig.update_yaxes(title='# taxa')
3837
- fig.update_layout(title='', showlegend=False, font_size=14, width=width_value, height=height_value, template=template)
3838
- phylib_plot = Path(str(phylib_directory) + "_phylib.pdf")
3839
- fig.write_image(phylib_plot)
3840
- phylib_plot = Path(str(phylib_directory) + "_phylib.html")
3841
- fig.write_html(phylib_plot)
3666
+ suffix = f'{table_display_name.stem}_Haplotyes'
3667
+ export_table("Perlodes", suffix, perlodes_input_df, "xlsx", False)
3668
+ st.success(f'Wrote Perlodes input file.')
3842
3669
 
3843
3670
  def calculate_diathor_index():
3844
3671
  # Tables & Samples
@@ -4395,21 +4222,17 @@ if path_to_projects.exists():
4395
4222
 
4396
4223
  a1, a2 = st.columns(2)
4397
4224
  with a1:
4398
- selected_read_table = st.selectbox(label='Select Read Table', options=import_folder_files.keys(), key='selected_read_table')
4399
- st.selectbox(label='Choose Import Format', options=['APSCALE'], key='read_table_import_format')
4225
+ selected_read_table = st.selectbox(label='Select Read Table:', options=import_folder_files.keys(), key='selected_read_table')
4226
+ st.selectbox(label='Choose Import Format:', options=['APSCALE'], key='read_table_import_format')
4400
4227
  with a2:
4401
- selected_taxonomy_table = st.selectbox(label='Select Taxonomy Table', options=import_folder_files.keys(), key='selected_taxonomy_table')
4402
- st.selectbox(label='Choose Import Format', options=['APSCALE', 'BOLDigger'], key='taxonomy_table_import_format')
4228
+ selected_taxonomy_table = st.selectbox(label='Select Taxonomy Table:', options=import_folder_files.keys(), key='selected_taxonomy_table')
4229
+ st.selectbox(label='Choose Import Format:', options=['APSCALE', 'BOLDigger'], key='taxonomy_table_import_format')
4403
4230
 
4404
4231
  a1, a2 = st.columns(2)
4405
4232
  with a1:
4406
- taxon_table_creation_name = st.text_input(label='Enter Name of Taxon Table', key='taxon_table_creation_name')
4233
+ taxon_table_creation_name = st.text_input(label='Enter Name of Taxon Table:', value=st.session_state['active_project_path'].stem, key='taxon_table_creation_name')
4407
4234
  with a2:
4408
- st.write('')
4409
- if st.session_state['TTT_tableformat'] == '.h5':
4410
- st.info(f'Export Format: {st.session_state["TTT_tableformat"]} (fast, recommended for large tables)')
4411
- else:
4412
- st.info(f'Export Format: {st.session_state["TTT_tableformat"]} (editable, slower)')
4235
+ st.selectbox(label='Select Export Format:', options=['.xlsx', '.h5'], key='taxon_table_export_format', help=format_help_text)
4413
4236
 
4414
4237
  if selected_read_table and selected_taxonomy_table:
4415
4238
  if st.button('Create Taxon Table'):
@@ -5083,7 +4906,15 @@ if 'df_taxon_table' in st.session_state and 'table_display_name' in st.session_s
5083
4906
  )
5084
4907
 
5085
4908
  cols = st.session_state['df_metadata_table'].columns.tolist()
5086
- if "Latitude" in cols and "Longitude" in cols:
4909
+ lat_lon_check = "Latitude" in cols and "Longitude" in cols
4910
+ if lat_lon_check == True:
4911
+ lat_data = list(st.session_state['df_metadata_table']['Latitude'].unique()) != ['']
4912
+ lon_data = list(st.session_state['df_metadata_table']['Longitude'].unique()) != ['']
4913
+ else:
4914
+ lat_data = False
4915
+ lon_data = False
4916
+
4917
+ if lat_lon_check == True and lat_data == True and lon_data == True:
5087
4918
  st.write('### GBIF Occurrence Validation')
5088
4919
  col1, col2 ,col3 = st.columns(3)
5089
4920
  with col1:
@@ -5118,7 +4949,7 @@ if 'df_taxon_table' in st.session_state and 'table_display_name' in st.session_s
5118
4949
  st.divider()
5119
4950
 
5120
4951
  else:
5121
- st.info('Please add the columns "Latitude" and "Longitude" to your Metadata Table!')
4952
+ st.info('Please add the columns "Latitude" and "Longitude" to your Metadata Table and enter the GPS coordinates!')
5122
4953
 
5123
4954
  ########################################################################################################################
5124
4955
  st.markdown("## 📆 Time Series")
@@ -5213,15 +5044,15 @@ if 'df_taxon_table' in st.session_state and 'table_display_name' in st.session_s
5213
5044
  st.divider()
5214
5045
 
5215
5046
  ########################################################################################################################
5216
- st.markdown("## 🇪🇺 Ecological Status Classes")
5047
+ st.markdown("## 🟢 Ecological Status Classes")
5217
5048
  with st.expander(expanded=False, label='See more'):
5218
5049
  st.success(
5219
5050
  "This section allows you to calculate widely used ecological status indices for freshwater ecosystems. "
5220
- "You can compute the **European Fish Index (EFI)** and **Diathor Index**, as well as convert your taxon table into formats compatible with **Perlodes** and **Phylib** online tools. "
5051
+ "You can compute the **European Fish Index (EFI)** and **Diathor Index**, as well as convert your taxon table into formats compatible with the **Perlodes** online tool. "
5221
5052
  "These indices help assess biodiversity, ecological quality, and ecosystem health based on species composition and abundance."
5222
5053
  )
5223
5054
 
5224
- st.write('### European Fish Index')
5055
+ st.write('### European Fish Index Calculation')
5225
5056
  # --- Initialize structure ---
5226
5057
  col1, col2, col3 = st.columns(3)
5227
5058
  with col1:
@@ -5237,13 +5068,12 @@ if 'df_taxon_table' in st.session_state and 'table_display_name' in st.session_s
5237
5068
  st.write('Table 2: Available ecoregions for EFI calculation.')
5238
5069
  st.dataframe(pd.read_excel(efi_table, sheet_name='Sheet2').fillna(''), hide_index=True)
5239
5070
  efi_map = efi_table / 'WFD_conversion', 'efi_ecoregions.png'
5240
-
5241
5071
  # --- Action Button ---
5242
5072
  if st.button(f"🔄 Calculate EFI", width='stretch'):
5243
5073
  calculate_efi_index()
5244
5074
  st.divider()
5245
5075
 
5246
- st.write('### Diathor Index')
5076
+ st.write('### Diathor Index Calculation')
5247
5077
  # --- Initialize structure ---
5248
5078
  col1, col2, col3 = st.columns(3)
5249
5079
  with col1:
@@ -5257,7 +5087,7 @@ if 'df_taxon_table' in st.session_state and 'table_display_name' in st.session_s
5257
5087
  calculate_diathor_index()
5258
5088
  st.divider()
5259
5089
 
5260
- st.write('### Convert To Perlodes Format')
5090
+ st.write('### Perlodes Conversion')
5261
5091
  # --- Initialize structure ---
5262
5092
  col1, col2 = st.columns([3,6])
5263
5093
  with col1:
@@ -5266,25 +5096,10 @@ if 'df_taxon_table' in st.session_state and 'table_display_name' in st.session_s
5266
5096
  st.write('')
5267
5097
  st.write('')
5268
5098
  if st.button("🔗 Perlode Online Calculation", width='stretch'):
5269
- pass
5099
+ webbrowser.open('https://gewaesser-bewertung-berechnung.de/index.php/methoden_berechnung.html')
5270
5100
  # --- Action Button ---
5271
5101
  if st.button(f"🔄 Convert To Perlodes", width='stretch'):
5272
- st.info('Coming soon!')
5273
- st.divider()
5274
-
5275
- st.write('### Convert To Phylib Format')
5276
- # --- Initialize structure ---
5277
- col1, col2 = st.columns([3,6])
5278
- with col1:
5279
- phylib_measure = st.selectbox(label='Select Diversity Measure:', options=['Presence/Absence', 'Rel. Reads', f'{TTT_hash[:-1]} Diversity'], key='phylib_measure')
5280
- with col2:
5281
- st.write('')
5282
- st.write('')
5283
- if st.button("🔗 Phylib Online Calculation", width='stretch'):
5284
- pass
5285
- # --- Action Button ---
5286
- if st.button(f"🔄 Convert To Phylib", width='stretch'):
5287
- st.info('Coming soon!')
5102
+ convert_to_perlodes()
5288
5103
  st.divider()
5289
5104
 
5290
5105
  else:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: taxontabletools2
3
- Version: 2.3.4
3
+ Version: 2.3.6
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