aristoteleo / dynast-release

Inclusive and efficient quantification of labeling and splicing RNAs for time-resolved metabolic labeling based scRNA-seq experiments
https://dynast-release.readthedocs.io/en/latest/
MIT License
15 stars 4 forks source link

Bug in 'estimate' when p_e is taken from control #9

Closed rorymaizels closed 2 years ago

rorymaizels commented 2 years ago

Hi!

I've been playing around with this package and it looks very cool, congrats and thank you!

There seems to be a little bug in the code for estimating new/old when the background conversion probability is estimated from a control sample. Specifically, in lines 151-155 of estimate.py, there is the following code:

if control_p_e:
    logger.info('--p-e provided. No background mutation rate estimation will be done.')
    df_barcodes = df_counts[p_key].drop_duplicates().reset_index(drop=True)
    df_barcodes['p_e'] = control_p_e
    df_barcodes.to_csv(p_e_path, header=[p_key, 'p_e'], index=False)

df_barcodes is a pandas Series object, not a DataFrame. Thus, when you do df_barcodes['p_e'] = control_p_e, this actually creates a new row in the Series of value control_p_e and index 'p_e'. Instead, a DataFrame should be created with a new column for p_e.

So replacing this line with df_barcodes = pd.DataFrame({p_key:df_barcodes,'p_e':control_p_e}) should resolve this issue. Currently when I try to run estimate I encounter the following issue:

[2022-04-23 23:57:18,936]    INFO [estimate] `--p-e` provided. No background mutation rate estimation will be done.
[2022-04-23 23:57:18,976]   ERROR [main] An exception occurred
Traceback (most recent call last):
  File "/camp/home/maizelr/.local/lib/python3.8/site-packages/dynast/main.py", line 742, in main
    COMMAND_TO_FUNCTION[args.command](parser, args, temp_dir=args.tmp)
  File "/camp/home/maizelr/.local/lib/python3.8/site-packages/dynast/main.py", line 650, in parse_estimate
    estimate(
  File "/camp/home/maizelr/.local/lib/python3.8/site-packages/ngs_tools/logging.py", line 62, in inner
    return func(*args, **kwargs)
  File "/camp/home/maizelr/.local/lib/python3.8/site-packages/dynast/estimate.py", line 155, in estimate
    df_barcodes.to_csv(p_e_path, header=[p_key, 'p_e'], index=False)
  File "/camp/home/maizelr/.local/lib/python3.8/site-packages/pandas/core/generic.py", line 3466, in to_csv
    return DataFrameRenderer(formatter).to_csv(
  File "/camp/home/maizelr/.local/lib/python3.8/site-packages/pandas/io/formats/format.py", line 1105, in to_csv
    csv_formatter.save()
  File "/camp/home/maizelr/.local/lib/python3.8/site-packages/pandas/io/formats/csvs.py", line 257, in save
    self._save()
  File "/camp/home/maizelr/.local/lib/python3.8/site-packages/pandas/io/formats/csvs.py", line 261, in _save
    self._save_header()
  File "/camp/home/maizelr/.local/lib/python3.8/site-packages/pandas/io/formats/csvs.py", line 266, in _save_header
    self.writer.writerow(self.encoded_labels)
  File "/camp/home/maizelr/.local/lib/python3.8/site-packages/pandas/io/formats/csvs.py", line 228, in encoded_labels
    encoded_labels += list(self.write_cols)
  File "/camp/home/maizelr/.local/lib/python3.8/site-packages/pandas/io/formats/csvs.py", line 209, in write_cols
    raise ValueError(
ValueError: Writing 1 cols but got 2 aliases

Cheers, Rory

Lioscro commented 2 years ago

Hi, @rorymaizels, Thanks for catching this! Just fixed this in the devel branch, which you can install with pip directly.

pip install git+https://github.com/aristoteleo/dynast-release@devel --upgrade

Please disregard the dynast consensus command, as that is still in development and has not been tested thoroughly yet.

rorymaizels commented 2 years ago

Awesome, thanks - looking forward to finding out more about these developments!

Xiaojieqiu commented 2 years ago

Joseph also released a new version with the consensus command. I think you are ready to use them too

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days