Skip to content

Commit

Permalink
restructured using black
Browse files Browse the repository at this point in the history
  • Loading branch information
mpecchi committed Mar 18, 2024
1 parent 2c1d388 commit b258a93
Show file tree
Hide file tree
Showing 2 changed files with 1,452 additions and 764 deletions.
86 changes: 57 additions & 29 deletions example/example_gcms_data_analysis.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# Import necessary libraries
import pathlib as plib # Used for handling file and directory paths
from gcms_data_analysis import Project # Import the Project class from the gcms_data_analysis package
from gcms_data_analysis import (
Project,
) # Import the Project class from the gcms_data_analysis package

# Define the folder path where your data is located. Change this path to where you've stored your data files.
folder_path = plib.Path(plib.Path(__file__).parent, 'data')
folder_path = plib.Path(plib.Path(__file__).parent, "data")

# Set global configurations for the Project class.
# These configurations affect all instances of the class.
Project.set_folder_path(folder_path) # Set the base folder path for the project's data files
Project.set_folder_path(
folder_path
) # Set the base folder path for the project's data files
Project.set_plot_grid(False) # Disable grid lines in plots for a cleaner look
Project.set_plot_font('Sans') # Set the font style for plots to 'Sans'
Project.set_plot_font("Sans") # Set the font style for plots to 'Sans'

# Initialize a Project instance to manage and analyze GCMS data
gcms = Project()
Expand All @@ -25,7 +29,7 @@

# Load calibration data for standard and derivatized samples, and determine if they are derivatized
calibrations, is_calibr_deriv = gcms.load_calibrations()
c1, c2 = calibrations['calibration'], calibrations['deriv_calibration']
c1, c2 = calibrations["calibration"], calibrations["deriv_calibration"]

# Generate a comprehensive list of all compounds found across samples
list_of_all_compounds = gcms.create_list_of_all_compounds()
Expand All @@ -47,7 +51,7 @@
files, is_files_deriv = gcms.apply_calibration_to_files()

# Extract specific files for detailed analysis or further operations
f11, f22, f33 = files['A_1'], files['Ader_1'], files['B_1']
f11, f22, f33 = files["A_1"], files["Ader_1"], files["B_1"]

# Add statistical information to the files_info DataFrame, such as mean, median, and standard deviation for each file
files_info = gcms.add_stats_to_files_info()
Expand All @@ -57,39 +61,63 @@

# Create samples and their standard deviations from the files, storing the results in dictionaries
samples, samples_std = gcms.create_samples_from_files()
s1, s2, s3 = samples['A'], samples['Ader'], samples['B']
sd1, sd2, sd3 = samples_std['A'], samples_std['Ader'], samples_std['B']
s1, s2, s3 = samples["A"], samples["Ader"], samples["B"]
sd1, sd2, sd3 = samples_std["A"], samples_std["Ader"], samples_std["B"]

# Add statistical information to the samples_info DataFrame, enhancing the initial analysis with statistical data
samples_info = gcms.add_stats_to_samples_info()

# Generate reports for specific parameters (e.g., concentration, mass fraction) for files and samples
rep_files_conc = gcms.create_files_param_report(param='conc_vial_mg_L')
rep_files_fr = gcms.create_files_param_report(param='fraction_of_sample_fr')
rep_samples_conc, rep_samples_conc_std = gcms.create_samples_param_report(param='conc_vial_mg_L')
rep_samples_fr, rep_samples_fr_std = gcms.create_samples_param_report(param='fraction_of_sample_fr')
rep_files_conc = gcms.create_files_param_report(param="conc_vial_mg_L")
rep_files_fr = gcms.create_files_param_report(param="fraction_of_sample_fr")
rep_samples_conc, rep_samples_conc_std = gcms.create_samples_param_report(
param="conc_vial_mg_L"
)
rep_samples_fr, rep_samples_fr_std = gcms.create_samples_param_report(
param="fraction_of_sample_fr"
)

# Generate aggregated reports based on functional groups for files and samples, for specific parameters
agg_files_conc = gcms.create_files_param_aggrrep(param='conc_vial_mg_L')
agg_files_fr = gcms.create_files_param_aggrrep(param='fraction_of_sample_fr')
agg_samples_conc, agg_samples_conc_std = gcms.create_samples_param_aggrrep(param='conc_vial_mg_L')
agg_samples_fr, agg_samples_fr_std = gcms.create_samples_param_aggrrep(param='fraction_of_sample_fr')
agg_files_conc = gcms.create_files_param_aggrrep(param="conc_vial_mg_L")
agg_files_fr = gcms.create_files_param_aggrrep(param="fraction_of_sample_fr")
agg_samples_conc, agg_samples_conc_std = gcms.create_samples_param_aggrrep(
param="conc_vial_mg_L"
)
agg_samples_fr, agg_samples_fr_std = gcms.create_samples_param_aggrrep(
param="fraction_of_sample_fr"
)

# Plotting results based on the generated reports, allowing for visual comparison of average values and standard deviations
# Plot results for individual files or samples based

gcms.plot_ave_std(param='fraction_of_sample_fr', min_y_thresh=0, files_or_samples='files',
legend_location='outside',
only_samples_to_plot=['A_1', 'A_2', 'Ader_1', 'Ader_2'], #y_lim=[0, 5000]
)
gcms.plot_ave_std(
param="fraction_of_sample_fr",
min_y_thresh=0,
files_or_samples="files",
legend_location="outside",
only_samples_to_plot=["A_1", "A_2", "Ader_1", "Ader_2"], # y_lim=[0, 5000]
)
# plot results bases on aggreport
gcms.plot_ave_std(param='fraction_of_sample_fr', aggr=True, files_or_samples='files',
min_y_thresh=0.01,
y_lim=[0, .5], color_palette='Set2')

gcms.plot_ave_std(param='fraction_of_sample_fr', min_y_thresh=0,
legend_location='outside', only_samples_to_plot=['A', 'Ader'], #y_lim=[0, 5000]
)
gcms.plot_ave_std(
param="fraction_of_sample_fr",
aggr=True,
files_or_samples="files",
min_y_thresh=0.01,
y_lim=[0, 0.5],
color_palette="Set2",
)

gcms.plot_ave_std(
param="fraction_of_sample_fr",
min_y_thresh=0,
legend_location="outside",
only_samples_to_plot=["A", "Ader"], # y_lim=[0, 5000]
)
# plot results bases on aggreport
gcms.plot_ave_std(param='fraction_of_sample_fr', aggr=True, min_y_thresh=0.01,
y_lim=[0, .5], color_palette='Set2')
gcms.plot_ave_std(
param="fraction_of_sample_fr",
aggr=True,
min_y_thresh=0.01,
y_lim=[0, 0.5],
color_palette="Set2",
)
Loading

0 comments on commit b258a93

Please sign in to comment.