Skip to content

Commit

Permalink
update(main, tidy, utils): arg -ox output files extension tsv|csv|txt
Browse files Browse the repository at this point in the history
  • Loading branch information
johaGL committed Mar 19, 2024
1 parent 13cd909 commit 8c18e22
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
25 changes: 15 additions & 10 deletions tracegroomer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ def prep_args() -> argparse.ArgumentParser:
formatter_class=show_defaults)

parser.add_argument('-cf', '--config_file', type=str,
help="Configuration file given as absolute path.")
help="Configuration file given as absolute path")

parser.add_argument('-lm', '--labeled_metabo_file', type=str, default=None,
help="Labeled metabolomics input file, absolute path.")
help="Labeled metabolomics input file, absolute path")

parser.add_argument('-tf', '--type_of_file', type=str, default=None,
help="One of the following: \
Expand All @@ -25,27 +25,27 @@ def prep_args() -> argparse.ArgumentParser:
parser.add_argument('--amountMaterial_path', type=str, default=None,
help="absolute path to the file having the amount \
of material (number of cells, tissue weight, etc) \
by sample, for the normalization.")
by sample, for the normalization")

parser.add_argument("--alternative_div_amount_material",
action=argparse.BooleanOptionalAction, default=True,
help="When dividing values by the amount of \
material, also multiplies by 'mean(amountMaterial)' \
to stay in abundance units.")
to stay in abundance units")

parser.add_argument("--div_isotopologues_by_amount_material",
action=argparse.BooleanOptionalAction,
default=True,
help="Apply normalization by the amount of material, \
at the level of isotopologue absolute values. \
After this, re-computes all derived metrics. \
If False, only total abundances are normalized.")
If False, only total abundances are normalized")

parser.add_argument("--use_internal_standard", default=None, type=str,
help='Internal Standard for performing the division: \
total_abundances/internal_standard, \
example: --use_internal_standard Myristic_acid_d27. \
By default is not performed.')
By default is not performed')

parser.add_argument("--remove_these_metabolites", default=None, type=str,
help="Absolute path to the file with columns: \
Expand All @@ -59,8 +59,8 @@ def prep_args() -> argparse.ArgumentParser:
help="Plot isotopologue values, as given")

parser.add_argument("--isosprop_min_admitted", default=-0.5, type=float,
help="Metabolites whose isotopologues are less \
or equal to this cutoff, are removed.")
help="Metabolites whose isotopologues proportions are\
less or equal to this cutoff, are removed")

parser.add_argument("--fractions_stomp_values",
action=argparse.BooleanOptionalAction, default=True,
Expand All @@ -72,12 +72,17 @@ def prep_args() -> argparse.ArgumentParser:
parser.add_argument("--under_detection_limit_set_nan",
action=argparse.BooleanOptionalAction,
default=True, help="On VIB results. Any abundance \
< LOD (Limit Of Detection), is set as NaN.")
< LOD (Limit Of Detection), is set as NaN")

parser.add_argument("--subtract_blankavg",
action=argparse.BooleanOptionalAction, default=True,
help="On VIB results. From samples' abundances, \
subtracts the average of the blanks.")
subtracts the average of the blanks")

# output files extension
parser.add_argument("-ox", "--output_files_extension", type=str,
default="csv", help="Extension for the output files, \
must be one of the following: csv|tsv|txt")

return parser

Expand Down
15 changes: 8 additions & 7 deletions tracegroomer/tidy.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ def save_isotopologues_preview(self, args, confdict, groom_out_path):
if not os.path.exists(output_plots_dir):
os.makedirs(output_plots_dir)
ut.save_isos_preview(
compartmentalized_dict, self.metadata,
output_plots_dir, args.isotopologues_preview)
compartmentalized_dict, self.metadata, output_plots_dir,
args.isotopologues_preview, args.output_files_extension)
logger.info(f"saved figures to {output_plots_dir}")

def pull_internal_standard(self, confdict, args):
Expand Down Expand Up @@ -304,7 +304,7 @@ def check_confdict_completeness(confdict) -> None:
f" in columns_variable_description")


def save_tables(frames_dict, groom_out_path) -> None:
def save_tables(frames_dict, groom_out_path, output_extension) -> None:
for k in frames_dict.keys():
# reunify the compartments
tmpli = list()
Expand All @@ -320,10 +320,10 @@ def save_tables(frames_dict, groom_out_path) -> None:
final_df.index.name = "ID"
final_df = final_df.reset_index()
final_df = final_df.drop_duplicates()
final_df.to_csv(os.path.join(groom_out_path, f"{k}.csv"),
sep='\t', header=True, index=False)
o_file_path = os.path.join(groom_out_path, f"{k}.{output_extension}")
final_df.to_csv(o_file_path, sep='\t', header=True, index=False)

logger.info(f"File saved to: {os.path.join(groom_out_path, k)}.csv")
logger.info(f"File saved to: {o_file_path}")
# note : do not clear zero rows, as gives problem pd.merge


Expand Down Expand Up @@ -351,7 +351,8 @@ def wrapper_common_steps(combo_data: CompositeData,
combo_data.drop_metabolites()
combo_data.stomp_fraction_values(args, confdict)
combo_data.transfer__abund_nan__to_all_tables(confdict)
save_tables(combo_data.frames_dict, groom_out_path)
save_tables(combo_data.frames_dict, groom_out_path,
args.output_files_extension)


def perform_type_prep(args, confdict, metadata_used_extension: str,
Expand Down
4 changes: 2 additions & 2 deletions tracegroomer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def save_heatmap_sums_isos(thesums, figuretitle, outputfigure) -> None:


def save_isos_preview(dict_isos_prop, metadata, output_plots_dir,
the_boolean_arg) -> None:
the_boolean_arg, output_extension) -> None:
if the_boolean_arg:
for k in metadata['compartment'].unique().tolist():
df = dict_isos_prop[k]
Expand All @@ -387,7 +387,7 @@ def save_isos_preview(dict_isos_prop, metadata, output_plots_dir,
dfmelt = pd.melt(df, id_vars=['metabolite', 'isotopologue_type'])
dfmelt = impute_custom_levels_to_df(dfmelt)
table_minimalbymet(dfmelt, os.path.join(output_plots_dir,
f"minextremesIso_{k}.csv"))
f"minextremesIso_{k}.{output_extension}"))
outputfigure = os.path.join(output_plots_dir, f"allsampleIsos_{k}.pdf")
figtitle = f"{k} compartment, Isotopologues (proportions) \
across all samples"
Expand Down

0 comments on commit 8c18e22

Please sign in to comment.