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

8 collapse samples #169

Merged
merged 8 commits into from
Oct 24, 2015
Merged
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ before_install:
- ./miniconda.sh -b
- export PATH=/home/travis/miniconda3/bin:$TRAVIS_BUILD_DIR/scripts:$PATH
- export AG_TESTING='True'
- export AG_CPU_COUNT=1
install:
- conda create --yes -n env_name python=$PYTHON_VERSION pip nose numpy=1.9.2 scipy matplotlib pandas>=0.15 flake8 statsmodels lxml h5py>=2.3.1 notebook
- source activate env_name
Expand All @@ -25,7 +26,7 @@ script:
- runipy ipynb/primary-processing/2-filter_sequences_for_blooms.ipynb
- runipy ipynb/primary-processing/3-pick_otus.ipynb
- runipy ipynb/primary-processing/4-prepare_metaanalyses.ipynb
# runipy ipynb/primary-processing/5-alpha_diversity.ipynb
# runipy ipynb/primary-processing/6-beta-diversity.ipynb
# runipy ipynb/primary-processing/7-taxonomy-summaries.ipynb
# runipy ipynb/primary-processing/7.5-collapse_samples.ipynb
- runipy ipynb/primary-processing/5-alpha_diversity.ipynb
- runipy ipynb/primary-processing/6-beta-diversity.ipynb
- runipy ipynb/primary-processing/7-taxonomy-summaries.ipynb
- runipy ipynb/primary-processing/8-collapse_samples.ipynb
66 changes: 44 additions & 22 deletions americangut/notebook_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,30 +150,30 @@
'ag-L6-taxa-fecal-biom': '7/taxa/otu_table_fecal_L6.biom',

# collapsed samples
'ag-100nt-1k-biom': '7.5/ag-100nt-1k.biom',
'ag-100nt-1k-fecal-biom': '7.5/ag-100nt-1k-fecal.biom',
'ag-100nt-1k-skin-biom': '7.5/ag-100nt-1k-oral.biom',
'ag-100nt-1k-oral-biom': '7.5/ag-100nt-1k-skin.biom',

'ag-100nt-1k-fecal-sex-biom': '7.5/ag-100nt-1k-fecal-sex.biom',
'ag-100nt-1k-fecal-diet-biom': '7.5/ag-100nt-1k-fecal-diet.biom',
'ag-100nt-1k-fecal-age-biom': '7.5/ag-100nt-1k-fecal-age.biom',
'ag-100nt-1k-fecal-bmi-biom': '7.5/ag-100nt-1k-fecal-bmi.biom',

'ag-100nt-1k-oral-sex-biom': '7.5/ag-100nt-1k-oral-sex.biom',
'ag-100nt-1k-oral-diet-biom': '7.5/ag-100nt-1k-oral-diet.biom',
'ag-100nt-1k-oral-age-biom': '7.5/ag-100nt-1k-oral-age.biom',
'ag-100nt-1k-oral-flossing-biom': '7.5/ag-100nt-1k-oral-flossing.biom',

'ag-100nt-1k-skin-sex-biom': '7.5/ag-100nt-1k-skin-sex.biom',
'ag-100nt-1k-skin-cosmetics-biom': '7.5/ag-100nt-1k-skin-cosmetics.biom',
'ag-100nt-1k-skin-age-biom': '7.5/ag-100nt-1k-skin-age.biom',
'ag-100nt-1k-skin-hand-biom': '7.5/ag-100nt-1k-skin-hand.biom',
'ag-100nt-1k-biom': '8/ag-100nt-1k.biom',
'ag-100nt-1k-fecal-biom': '8/ag-100nt-1k-fecal.biom',
'ag-100nt-1k-skin-biom': '8/ag-100nt-1k-oral.biom',
'ag-100nt-1k-oral-biom': '8/ag-100nt-1k-skin.biom',

'ag-100nt-1k-fecal-sex-biom': '8/ag-100nt-1k-fecal-sex.biom',
'ag-100nt-1k-fecal-diet-biom': '8/ag-100nt-1k-fecal-diet.biom',
'ag-100nt-1k-fecal-age-biom': '8/ag-100nt-1k-fecal-age.biom',
'ag-100nt-1k-fecal-bmi-biom': '8/ag-100nt-1k-fecal-bmi.biom',

'ag-100nt-1k-oral-sex-biom': '8/ag-100nt-1k-oral-sex.biom',
'ag-100nt-1k-oral-diet-biom': '8/ag-100nt-1k-oral-diet.biom',
'ag-100nt-1k-oral-age-biom': '8/ag-100nt-1k-oral-age.biom',
'ag-100nt-1k-oral-flossing-biom': '8/ag-100nt-1k-oral-flossing.biom',

'ag-100nt-1k-skin-sex-biom': '8/ag-100nt-1k-skin-sex.biom',
'ag-100nt-1k-skin-cosmetics-biom': '8/ag-100nt-1k-skin-cosmetics.biom',
'ag-100nt-1k-skin-age-biom': '8/ag-100nt-1k-skin-age.biom',
'ag-100nt-1k-skin-hand-biom': '8/ag-100nt-1k-skin-hand.biom',

# per-sample results
'successful-ids': '8/successful_ids.txt',
'unsuccessful-ids': '8/unsuccessful_ids.txt',
'per-sample-results': '8/per-sample-results',
'successful-ids': '9/successful_ids.txt',
'unsuccessful-ids': '9/unsuccessful_ids.txt',
'per-sample-results': '9/per-sample-results',
}


Expand Down Expand Up @@ -247,6 +247,28 @@ def get_reference_set():
return qdr.get_reference_sequences(), qdr.get_reference_taxonomy()


def get_cpu_count():
"""Get the CPU count to use

Returns
-------
int
The number of CPUs available for use.

Notes
-----
This method provides a layer of indirection in the event that a) a user
does not want to allow all cores to be used or b) for testing purposes
as Travis CI appears to be unreliable under multiprocessing and QIIME.
"""
if os.environ.get('AG_CPU_COUNT') is not None:
return int(os.environ.get('AG_CPU_COUNT'))
else:
# import is scoped as far its use is contained here.
import multiprocessing
return multiprocessing.cpu_count()


def get_hmp():
"""Get the HMP 100nt table and mapping"""
return _get_data('HMP', 'HMPv35_100nt')
Expand Down
210 changes: 210 additions & 0 deletions ipynb/primary-processing/8-collapse_samples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
Some of the per-results figures require various slices and perspectives of the data. This notebook performs these necessary additional summarizations.

```python
>>> import os
...
>>> import americangut.notebook_environment as agenv
>>> import americangut.util as agu
...
>>> import qiime_default_reference as qdr
...
>>> chp_path = agenv.activate('8')
```

Let's make sure we have the paths we need.

```python
>>> ag_100nt_biom = agu.get_existing_path(agenv.paths['ag-100nt-biom'])
>>> ag_cleaned_md = agu.get_existing_path(agenv.paths['ag-cleaned-md'])
```

And let's setup all the paths that we're going to create.

```python
>>> ag_100nt_1k_biom = agu.get_new_path(agenv.paths['ag-100nt-1k-biom'])
>>> ag_100nt_1k_fecal_biom = agu.get_new_path(agenv.paths['ag-100nt-1k-fecal-biom'])
>>> ag_100nt_1k_skin_biom = agu.get_new_path(agenv.paths['ag-100nt-1k-skin-biom'])
>>> ag_100nt_1k_oral_biom = agu.get_new_path(agenv.paths['ag-100nt-1k-oral-biom'])
...
>>> ag_100nt_1k_fecal_sex_biom = agu.get_new_path(agenv.paths['ag-100nt-1k-fecal-sex-biom'])
>>> ag_100nt_1k_fecal_diet_biom = agu.get_new_path(agenv.paths['ag-100nt-1k-fecal-diet-biom'])
>>> ag_100nt_1k_fecal_age_biom = agu.get_new_path(agenv.paths['ag-100nt-1k-fecal-age-biom'])
>>> ag_100nt_1k_fecal_bmi_biom = agu.get_new_path(agenv.paths['ag-100nt-1k-fecal-bmi-biom'])
...
>>> ag_100nt_1k_oral_sex_biom = agu.get_new_path(agenv.paths['ag-100nt-1k-oral-sex-biom'])
>>> ag_100nt_1k_oral_diet_biom = agu.get_new_path(agenv.paths['ag-100nt-1k-oral-diet-biom'])
>>> ag_100nt_1k_oral_age_biom = agu.get_new_path(agenv.paths['ag-100nt-1k-oral-age-biom'])
>>> ag_100nt_1k_oral_flossing_biom = agu.get_new_path(agenv.paths['ag-100nt-1k-oral-flossing-biom'])
...
>>> ag_100nt_1k_skin_sex_biom = agu.get_new_path(agenv.paths['ag-100nt-1k-skin-sex-biom'])
>>> ag_100nt_1k_skin_cosmetics_biom = agu.get_new_path(agenv.paths['ag-100nt-1k-skin-cosmetics-biom'])
>>> ag_100nt_1k_skin_age_biom = agu.get_new_path(agenv.paths['ag-100nt-1k-skin-age-biom'])
>>> ag_100nt_1k_skin_hand_biom = agu.get_new_path(agenv.paths['ag-100nt-1k-skin-hand-biom'])
...
>>> ignored = 'foo'
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a placeholder for future use? It's only set here

Copy link
Member Author

Choose a reason for hiding this comment

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

Can add a comment if you'd like, but there was a file path that was necessary for the call but not used after the fact

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, yeah a comment would be good.

```

First, we're going to operate on rarefied data again.

```python
>>> depth = agenv.get_rarefaction_depth()
```

```python
>>> !single_rarefaction.py -i $ag_100nt_biom \
... -o $ag_100nt_1k_biom \
... -d $depth
```

Next, we're going to partition the data into per-body site tables.

```python
>>> !filter_samples_from_otu_table.py -i $ag_100nt_1k_biom \
... -o $ag_100nt_1k_fecal_biom \
... -m $ag_cleaned_md \
... -s "SIMPLE_BODY_SITE:FECAL"
```

```python
>>> !filter_samples_from_otu_table.py -i $ag_100nt_1k_biom \
... -o $ag_100nt_1k_skin_biom \
... -m $ag_cleaned_md \
... -s "SIMPLE_BODY_SITE:SKIN"
```

```python
>>> !filter_samples_from_otu_table.py -i $ag_100nt_1k_biom \
... -o $ag_100nt_1k_oral_biom \
... -m $ag_cleaned_md \
... -s "SIMPLE_BODY_SITE:ORAL"
```

Finally, within each body site, we're going to collapse over categories of interest.

```python
>>> !collapse_samples.py -m $ag_cleaned_md \
... --output_biom_fp $ag_100nt_1k_fecal_sex_biom \
... --normalize \
... -b $ag_100nt_1k_fecal_biom \
... --collapse_fields "SEX" \
... --output_mapping_fp $ignored
```

```python
>>> !collapse_samples.py -m $ag_cleaned_md \
... --output_biom_fp $ag_100nt_1k_fecal_diet_biom \
... --normalize \
... -b $ag_100nt_1k_fecal_biom \
... --collapse_fields "DIET_TYPE" \
... --output_mapping_fp $ignored
```

```python
>>> !collapse_samples.py -m $ag_cleaned_md \
... --output_biom_fp $ag_100nt_1k_fecal_age_biom \
... --normalize \
... -b $ag_100nt_1k_fecal_biom \
... --collapse_fields "AGE_CAT" \
... --output_mapping_fp $ignored
```

```python
>>> !collapse_samples.py -m $ag_cleaned_md \
... --output_biom_fp $ag_100nt_1k_fecal_bmi_biom \
... --normalize \
... -b $ag_100nt_1k_fecal_biom \
... --collapse_fields "BMI_CAT" \
... --output_mapping_fp $ignored
```

```python
>>> !collapse_samples.py -m $ag_cleaned_md \
... --output_biom_fp $ag_100nt_1k_oral_sex_biom \
... --normalize \
... -b $ag_100nt_1k_oral_biom \
... --collapse_fields "SEX" \
... --output_mapping_fp $ignored
```

```python
>>> !collapse_samples.py -m $ag_cleaned_md \
... --output_biom_fp $ag_100nt_1k_oral_diet_biom \
... --normalize \
... -b $ag_100nt_1k_oral_biom \
... --collapse_fields "DIET_TYPE" \
... --output_mapping_fp $ignored
```

```python
>>> !collapse_samples.py -m $ag_cleaned_md \
... --output_biom_fp $ag_100nt_1k_oral_age_biom \
... --normalize \
... -b $ag_100nt_1k_oral_biom \
... --collapse_fields "AGE_CAT" \
... --output_mapping_fp $ignored
```

```python
>>> !collapse_samples.py -m $ag_cleaned_md \
... --output_biom_fp $ag_100nt_1k_oral_flossing_biom \
... --normalize \
... -b $ag_100nt_1k_oral_biom \
... --collapse_fields "FLOSSING_FREQUENCY" \
... --output_mapping_fp $ignored
```

```python
>>> !collapse_samples.py -m $ag_cleaned_md \
... --output_biom_fp $ag_100nt_1k_skin_sex_biom \
... --normalize \
... -b $ag_100nt_1k_skin_biom \
... --collapse_fields "SEX" \
... --output_mapping_fp $ignored
```

```python
>>> !collapse_samples.py -m $ag_cleaned_md \
... --output_biom_fp $ag_100nt_1k_skin_cosmetics_biom \
... --normalize \
... -b $ag_100nt_1k_skin_biom \
... --collapse_fields "COSMETICS_FREQUENCY" \
... --output_mapping_fp $ignored
```

```python
>>> !collapse_samples.py -m $ag_cleaned_md \
... --output_biom_fp $ag_100nt_1k_skin_age_biom \
... --normalize \
... -b $ag_100nt_1k_skin_biom \
... --collapse_fields "AGE_CAT" \
... --output_mapping_fp $ignored
```

```python
>>> !collapse_samples.py -m $ag_cleaned_md \
... --output_biom_fp $ag_100nt_1k_skin_hand_biom \
... --normalize \
... -b $ag_100nt_1k_skin_biom \
... --collapse_fields "DOMINANT_HAND" \
... --output_mapping_fp $ignored
```

As usual, let's make sure we have files.

```python
>>> assert os.stat(ag_100nt_1k_fecal_biom).st_size > 0
>>> assert os.stat(ag_100nt_1k_skin_biom).st_size > 0
>>> assert os.stat(ag_100nt_1k_oral_biom).st_size > 0
>>> assert os.stat(ag_100nt_1k_fecal_sex_biom).st_size > 0
>>> assert os.stat(ag_100nt_1k_fecal_diet_biom).st_size > 0
>>> assert os.stat(ag_100nt_1k_fecal_age_biom).st_size > 0
>>> assert os.stat(ag_100nt_1k_fecal_bmi_biom).st_size > 0
>>> assert os.stat(ag_100nt_1k_oral_sex_biom).st_size > 0
>>> assert os.stat(ag_100nt_1k_oral_diet_biom).st_size > 0
>>> assert os.stat(ag_100nt_1k_oral_age_biom).st_size > 0
>>> assert os.stat(ag_100nt_1k_oral_flossing_biom).st_size > 0
>>> assert os.stat(ag_100nt_1k_skin_sex_biom).st_size > 0
>>> assert os.stat(ag_100nt_1k_skin_hand_biom).st_size > 0
>>> assert os.stat(ag_100nt_1k_skin_age_biom).st_size > 0
>>> assert os.stat(ag_100nt_1k_skin_cosmetics_biom).st_size > 0
```