Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hotfix to ensure sample-names are always strings #49

Merged
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/qiita-plugin-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
conda config --add channels conda-forge
conda create -q --yes -n qiita python=3.9 libgfortran numpy nginx cython redis
conda activate qiita
pip install sphinx sphinx-bootstrap-theme nose-timer codecov Click
pip install sphinx sphinx-bootstrap-theme nose-timer Click

- name: Qiita install
shell: bash -l {0}
Expand Down Expand Up @@ -137,7 +137,7 @@ jobs:

nosetests --with-doctest --with-coverage -v --cover-package=qp_klp

- uses: codecov/codecov-action@v1
- uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: codecov.yml
Expand Down
10 changes: 8 additions & 2 deletions qp_klp/process_amplicon_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,15 @@ def process_amplicon(mapping_file_path, qclient, run_identifier, out_dir,
for study_id in gpf_job.prep_file_paths:
for prep_file_path in gpf_job.prep_file_paths[study_id]:
metadata = pd.read_csv(prep_file_path,
dtype=str,
delimiter='\t',
index_col='sample_name').to_dict(
'index')
index_col='sample_name')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

index_col does not interact as expected with dtype. This will still incur a type conversion. Converting it to str after the fact is lossy. Please set remove, and set an explicit index with set_index after parse

>>> df = pd.read_csv('clinical_metadata_formatted.tsv', sep='\t', dtype=str, index_col='sample-id')
>>> df.index[:5]
Float64Index([10317.000106498, 10317.000107092, 10317.000106499,
              10317.000107093, 10317.000106684],
             dtype='float64', name='sample-id')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wasade I can see it - it didn't happen in the case that spawned this hot fix but in general if the index column gets interpreted as a numeric directly instead of getting casted to string first with the other columns before then being converted when it becomes the index, you would get potential data loss.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're in agreement. Please do not allow the index column to be cast to numeric.


# force sample_names (index) to be of type string.
metadata.index = metadata.index.map(str)
charles-cowart marked this conversation as resolved.
Show resolved Hide resolved

# convert to standard dictionary.
metadata = metadata.to_dict('index')

# determine data_type based on target_gene column.
target_gene = metadata[list(metadata.keys())[0]]['target_gene']
Expand Down
9 changes: 6 additions & 3 deletions qp_klp/process_metagenomics_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,16 @@ def process_metagenomics(sample_sheet_path, lane_number, qclient,
for study_id in gpf_job.prep_file_paths:
for prep_file_path in gpf_job.prep_file_paths[study_id]:
metadata = pd.read_csv(prep_file_path,
dtype=str,
delimiter='\t',
index_col='sample_name').to_dict(
'index')
index_col='sample_name')
charles-cowart marked this conversation as resolved.
Show resolved Hide resolved

# force sample_names (index) to be of type string.
metadata.index = metadata.index.map(str)
charles-cowart marked this conversation as resolved.
Show resolved Hide resolved

# determine data_type based on sample-sheet
# value will be from the Assay field
data = {'prep_info': dumps(metadata),
data = {'prep_info': dumps(metadata.to_dict('index')),
'study': study_id,
'data_type': assay_type}

Expand Down
2 changes: 1 addition & 1 deletion qp_klp/tests/test_klp.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def setUp(self):
"Date,2/26/20,,,,,,,,,\n",
"Workflow,GenerateFASTQ,,,,,,,,,\n",
"Application,FASTQ Only,,,,,,,,,\n",
"Assay,Metagenomics,,,,,,,,,\n",
"Assay,Metagenomic,,,,,,,,,\n",
"Description,,,,,,,,,,\n",
"Chemistry,Default,,,,,,,,,\n",
",,,,,,,,,,\n",
Expand Down