Skip to content

Commit 24edc3a

Browse files
ericmjlZeroto521
andauthored
[DOC] MkDocs Chemistry (#899)
* mkdocstrings on chemistry functions * Minor update to biology.py * Proper config for syntax highlighting * Switch to nord theme for syntax highlighting * [INF] simplify a bit linting, use pre-commit as CI linting checker (#892) * [INF] simplify a bit linting There is two similar linting CIs (pre-commit and code-checks) but also have tiny differences. We should use one of them as the standard, not both. * Update CHANGELOG.md * should be `--config` not `-c` `-c` = `--code TEXT`, Format the code passed in as a string. * remove nbstripout keep the same with the old code-checks.yml * lint via pre-commit * Update CHANGELOG.md Co-authored-by: Eric Ma <[email protected]> * FLake8 fix. Co-authored-by: Zero <[email protected]>
1 parent b938b9f commit 24edc3a

File tree

4 files changed

+134
-116
lines changed

4 files changed

+134
-116
lines changed

janitor/biology.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ def join_fasta(
5858
Method chaining usage example:
5959
6060
```python
61-
6261
import pandas as pd
6362
import janitor.biology
6463

janitor/chemistry.py

Lines changed: 123 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -94,36 +94,38 @@ def smiles2mol(
9494
9595
Functional usage example:
9696
97-
.. code-block:: python
97+
```python
98+
import pandas as pd
99+
import janitor.chemistry
98100
99-
import pandas as pd
100-
import janitor.chemistry
101+
df = pd.DataFrame(...)
101102
102-
df = pd.DataFrame(...)
103-
104-
df = janitor.chemistry.smiles2mol(
105-
df=df,
106-
smiles_column_name='smiles',
107-
mols_column_name='mols'
108-
)
103+
df = janitor.chemistry.smiles2mol(
104+
df=df,
105+
smiles_column_name='smiles',
106+
mols_column_name='mols'
107+
)
108+
```
109109
110110
Method chaining usage example:
111111
112-
.. code-block:: python
113-
114-
import pandas as pd
115-
import janitor.chemistry
112+
```python
113+
import pandas as pd
114+
import janitor.chemistry
116115
117-
df = pd.DataFrame(...)
116+
df = pd.DataFrame(...)
118117
119-
df = df.smiles2mol(smiles_column_name='smiles',
120-
mols_column_name='mols')
118+
df = df.smiles2mol(
119+
smiles_column_name='smiles',
120+
mols_column_name='mols'
121+
)
122+
```
121123
122124
A progressbar can be optionally used.
123125
124-
- Pass in "notebook" to show a tqdm notebook progressbar. (ipywidgets must
125-
be enabled with your Jupyter installation.)
126-
- Pass in "terminal" to show a tqdm progressbar. Better suited for use
126+
- Pass in "notebook" to show a `tqdm` notebook progressbar.
127+
(`ipywidgets` must be enabled with your Jupyter installation.)
128+
- Pass in "terminal" to show a `tqdm` progressbar. Better suited for use
127129
with scripts.
128130
- "none" is the default value - progress bar will be not be shown.
129131
@@ -180,67 +182,70 @@ def morgan_fingerprint(
180182
181183
Functional usage example:
182184
183-
.. code-block:: python
185+
```python
186+
import pandas as pd
187+
import janitor.chemistry
184188
185-
import pandas as pd
186-
import janitor.chemistry
189+
df = pd.DataFrame(...)
187190
188-
df = pd.DataFrame(...)
189-
190-
# For "counts" kind
191-
morgans = janitor.chemistry.morgan_fingerprint(
192-
df=df.smiles2mol('smiles', 'mols'),
193-
mols_column_name='mols',
194-
radius=3, # Defaults to 3
195-
nbits=2048, # Defaults to 2048
196-
kind='counts' # Defaults to "counts"
197-
)
191+
# For "counts" kind
192+
morgans = janitor.chemistry.morgan_fingerprint(
193+
df=df.smiles2mol('smiles', 'mols'),
194+
mols_column_name='mols',
195+
radius=3, # Defaults to 3
196+
nbits=2048, # Defaults to 2048
197+
kind='counts' # Defaults to "counts"
198+
)
198199
199-
# For "bits" kind
200-
morgans = janitor.chemistry.morgan_fingerprint(
201-
df=df.smiles2mol('smiles', 'mols'),
202-
mols_column_name='mols',
203-
radius=3, # Defaults to 3
204-
nbits=2048, # Defaults to 2048
205-
kind='bits' # Defaults to "counts"
206-
)
200+
# For "bits" kind
201+
morgans = janitor.chemistry.morgan_fingerprint(
202+
df=df.smiles2mol('smiles', 'mols'),
203+
mols_column_name='mols',
204+
radius=3, # Defaults to 3
205+
nbits=2048, # Defaults to 2048
206+
kind='bits' # Defaults to "counts"
207+
)
208+
```
207209
208210
Method chaining usage example:
209211
210-
.. code-block:: python
212+
```python
213+
import pandas as pd
214+
import janitor.chemistry
211215
212-
import pandas as pd
213-
import janitor.chemistry
216+
df = pd.DataFrame(...)
214217
215-
df = pd.DataFrame(...)
216-
217-
# For "counts" kind
218-
morgans = (
219-
df.smiles2mol('smiles', 'mols')
220-
.morgan_fingerprint(mols_column_name='mols',
221-
radius=3, # Defaults to 3
222-
nbits=2048, # Defaults to 2048
223-
kind='counts' # Defaults to "counts"
224-
)
218+
# For "counts" kind
219+
morgans = (
220+
df.smiles2mol('smiles', 'mols')
221+
.morgan_fingerprint(
222+
mols_column_name='mols',
223+
radius=3, # Defaults to 3
224+
nbits=2048, # Defaults to 2048
225+
kind='counts' # Defaults to "counts"
225226
)
227+
)
226228
227-
# For "bits" kind
228-
morgans = (
229-
df.smiles2mol('smiles', 'mols')
230-
.morgan_fingerprint(mols_column_name='mols',
231-
radius=3, # Defaults to 3
232-
nbits=2048, # Defaults to 2048
233-
kind='bits' # Defaults to "counts"
234-
)
229+
# For "bits" kind
230+
morgans = (
231+
df
232+
.smiles2mol('smiles', 'mols')
233+
.morgan_fingerprint(
234+
mols_column_name='mols',
235+
radius=3, # Defaults to 3
236+
nbits=2048, # Defaults to 2048
237+
kind='bits' # Defaults to "counts"
235238
)
239+
)
240+
```
236241
237242
If you wish to join the morgan fingerprints back into the original
238243
dataframe, this can be accomplished by doing a `join`,
239244
because the indices are preserved:
240245
241-
.. code-block:: python
242-
243-
joined = df.join(morgans)
246+
```python
247+
joined = df.join(morgans)
248+
```
244249
245250
:param df: A pandas DataFrame.
246251
:param mols_column_name: The name of the column that has the RDKIT
@@ -294,52 +299,57 @@ def molecular_descriptors(
294299
295300
The molecular descriptors are from the rdkit.Chem.rdMolDescriptors:
296301
297-
Chi0n, Chi0v, Chi1n, Chi1v, Chi2n, Chi2v, Chi3n, Chi3v,
298-
Chi4n, Chi4v, ExactMolWt, FractionCSP3, HallKierAlpha, Kappa1,
299-
Kappa2, Kappa3, LabuteASA, NumAliphaticCarbocycles,
300-
NumAliphaticHeterocycles, NumAliphaticRings, NumAmideBonds,
301-
NumAromaticCarbocycles, NumAromaticHeterocycles, NumAromaticRings,
302-
NumAtomStereoCenters, NumBridgeheadAtoms, NumHBA, NumHBD,
303-
NumHeteroatoms, NumHeterocycles, NumLipinskiHBA, NumLipinskiHBD,
304-
NumRings, NumSaturatedCarbocycles, NumSaturatedHeterocycles,
305-
NumSaturatedRings, NumSpiroAtoms, NumUnspecifiedAtomStereoCenters,
306-
TPSA.
302+
```
303+
Chi0n, Chi0v, Chi1n, Chi1v, Chi2n, Chi2v, Chi3n, Chi3v,
304+
Chi4n, Chi4v, ExactMolWt, FractionCSP3, HallKierAlpha, Kappa1,
305+
Kappa2, Kappa3, LabuteASA, NumAliphaticCarbocycles,
306+
NumAliphaticHeterocycles, NumAliphaticRings, NumAmideBonds,
307+
NumAromaticCarbocycles, NumAromaticHeterocycles, NumAromaticRings,
308+
NumAtomStereoCenters, NumBridgeheadAtoms, NumHBA, NumHBD,
309+
NumHeteroatoms, NumHeterocycles, NumLipinskiHBA, NumLipinskiHBD,
310+
NumRings, NumSaturatedCarbocycles, NumSaturatedHeterocycles,
311+
NumSaturatedRings, NumSpiroAtoms, NumUnspecifiedAtomStereoCenters,
312+
TPSA.
313+
```
307314
308315
Functional usage example:
309316
310-
.. code-block:: python
311-
312-
import pandas as pd
313-
import janitor.chemistry
317+
```python
318+
import pandas as pd
319+
import janitor.chemistry
314320
315-
df = pd.DataFrame(...)
321+
df = pd.DataFrame(...)
316322
317-
mol_desc = janitor.chemistry.molecular_descriptors(
323+
mol_desc = (
324+
janitor.chemistry.molecular_descriptors(
318325
df=df.smiles2mol('smiles', 'mols'),
319326
mols_column_name='mols'
320327
)
328+
)
329+
```
321330
322331
Method chaining usage example:
323332
324-
.. code-block:: python
333+
```python
325334
326-
import pandas as pd
327-
import janitor.chemistry
335+
import pandas as pd
336+
import janitor.chemistry
328337
329-
df = pd.DataFrame(...)
338+
df = pd.DataFrame(...)
330339
331-
mol_desc = (
332-
df.smiles2mol('smiles', 'mols')
333-
.molecular_descriptors(mols_column_name='mols')
334-
)
340+
mol_desc = (
341+
df.smiles2mol('smiles', 'mols')
342+
.molecular_descriptors(mols_column_name='mols')
343+
)
344+
```
335345
336346
If you wish to join the molecular descriptors back into the original
337347
dataframe, this can be accomplished by doing a `join`,
338348
because the indices are preserved:
339349
340-
.. code-block:: python
341-
342-
joined = df.join(mol_desc)
350+
```python
351+
joined = df.join(mol_desc)
352+
```
343353
344354
:param df: A pandas DataFrame.
345355
:param mols_column_name: The name of the column that has the RDKIT mol
@@ -410,40 +420,39 @@ def maccs_keys_fingerprint(
410420
411421
Functional usage example:
412422
413-
.. code-block:: python
414-
415-
import pandas as pd
416-
import janitor.chemistry
423+
```python
424+
import pandas as pd
425+
import janitor.chemistry
417426
418-
df = pd.DataFrame(...)
427+
df = pd.DataFrame(...)
419428
420-
maccs = janitor.chemistry.maccs_keys_fingerprint(
421-
df=df.smiles2mol('smiles', 'mols'),
422-
mols_column_name='mols'
423-
)
429+
maccs = janitor.chemistry.maccs_keys_fingerprint(
430+
df=df.smiles2mol('smiles', 'mols'),
431+
mols_column_name='mols'
432+
)
433+
```
424434
425435
Method chaining usage example:
426436
427-
.. code-block:: python
437+
```python
438+
import pandas as pd
439+
import janitor.chemistry
428440
429-
import pandas as pd
430-
import janitor.chemistry
441+
df = pd.DataFrame(...)
431442
432-
df = pd.DataFrame(...)
433-
434-
maccs = (
435-
df.smiles2mol('smiles', 'mols')
436-
.maccs_keys_fingerprint(mols_column_name='mols')
437-
)
443+
maccs = (
444+
df.smiles2mol('smiles', 'mols')
445+
.maccs_keys_fingerprint(mols_column_name='mols')
446+
)
447+
```
438448
439449
If you wish to join the maccs keys fingerprints back into the
440450
original dataframe, this can be accomplished by doing a `join`,
441451
because the indices are preserved:
442452
443-
.. code-block:: python
444-
445-
joined = df.join(maccs_keys_fingerprint)
446-
453+
```python
454+
joined = df.join(maccs_keys_fingerprint)
455+
```
447456
448457
:param df: A pandas DataFrame.
449458
:param mols_column_name: The name of the column that has the RDKIT mol

mkdocs.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,11 @@ plugins:
6161

6262
# Taken from here: https://squidfunk.github.io/mkdocs-material/extensions/codehilite/
6363
markdown_extensions:
64-
- codehilite
64+
# - codehilite
6565
- admonition
66+
- pymdownx.highlight:
67+
use_pygments: false
68+
- pymdownx.inlinehilite
6669
# - pymdownx.tabbed
6770
# - pymdownx.arithmatex
6871
# - pymdownx.details
@@ -71,10 +74,16 @@ markdown_extensions:
7174

7275
extra_javascript:
7376
- https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML
77+
- https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.7.2/highlight.min.js
78+
- js/config.js
7479

7580
extra_css:
7681
- css/nb_mods.css
7782
- css/apidocs.css
83+
# This sets the theme for syntax highlighting.
84+
# Theme names are available here: https://highlightjs.org/static/demo/
85+
# Not sure how the theme names map onto CSS filenames though.
86+
- https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.7.2/styles/nord.min.css
7887

7988
repo_name: "ericmjl/pyjanitor"
8089
repo_url: "https://github.com/ericmjl/pyjanitor"

mkdocs/js/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hljs.highlightAll();

0 commit comments

Comments
 (0)