Skip to content

Instantly share code, notes, and snippets.

Douglas Myers-Turnbull dmyersturnbull

  • Stanford University
  • Stanford, CA
Block or report user

Report or block dmyersturnbull

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@dmyersturnbull
dmyersturnbull / toml_data.py
Last active Feb 8, 2017
A data structure for TOML data that's more convenient to use than a plain dict.
View toml_data.py
from typing import Iterator, Tuple, Dict, List
class MissingConfigEntry(Exception): pass
class TomlData:
"""A better TOML data structure than a plain dict.
Usage examples:
data = TomlData({'x': {'y': {'z': 155}}})
print(data['x.y.z']) # prints 155
@dmyersturnbull
dmyersturnbull / LICENSE
Created Nov 21, 2016
Apache License, Version 2.0 for all Gists under dmyersturnbull. The copyright owners may be different for each Gist.
View LICENSE
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
@dmyersturnbull
dmyersturnbull / SpiderRecovery.py
Last active Nov 21, 2016
Makes a best-effort attempt to recover SMILES strings from compound names unambiguously by searching ChemSpider.
View SpiderRecovery.py
# Douglas Myers-Turnbull wrote this for the Kokel Lab, which has released it under the Apache Software License, Version 2.0
# See the license file here: https://gist.github.com/dmyersturnbull/bfa1c3371e7449db553aaa1e7cd3cac1
# The list of copyright owners is unknown
import re
import warnings
import time
from chemspipy import ChemSpider
@dmyersturnbull
dmyersturnbull / connected.py
Last active Nov 21, 2016
Context with convenience functions for MySQL/MariaDB calls with pymysql.
View connected.py
# Douglas Myers-Turnbull wrote this for the Kokel Lab, which has released it under the Apache Software License, Version 2.0
# See the license file here: https://gist.github.com/dmyersturnbull/bfa1c3371e7449db553aaa1e7cd3cac1
# The list of copyright owners is unknown
import pymysql
import contextlib
from typing import Tuple, List, Dict, Iterator
@contextlib.contextmanager
def connected(connection: pymysql.connections.Connection):
@dmyersturnbull
dmyersturnbull / anethum.py
Last active Aug 16, 2016
Convenience functions for pickling with dill.
View anethum.py
import dill
def pkl(data, path: str):
with open(path, 'wb') as f:
dill.dump(data, f)
def unpkl(path: str):
with open(path, 'rb') as f:
return dill.load(f)
@dmyersturnbull
dmyersturnbull / plot_dose_response.py
Last active Nov 21, 2016
Plot a grid of nice-looking dose-response curves.
View plot_dose_response.py
# Douglas Myers-Turnbull wrote this for the Kokel Lab, which has released it under the Apache Software License, Version 2.0
# See the license file here: https://gist.github.com/dmyersturnbull/bfa1c3371e7449db553aaa1e7cd3cac1
# The list of copyright owners is unknown
import numpy as np
from matplotlib import pyplot as plt
import seaborn as sns
import matplotlib
import pandas as pd
from typing import Callable, Tuple, Dict, Optional, Union
@dmyersturnbull
dmyersturnbull / marker_iterator.py
Last active Nov 21, 2016
Iterate over Matplotlib marker shapes.
View marker_iterator.py
# Douglas Myers-Turnbull wrote this for the Kokel Lab, which has released it under the Apache Software License, Version 2.0
# See the license file here: https://gist.github.com/dmyersturnbull/bfa1c3371e7449db553aaa1e7cd3cac1
# The list of copyright owners is unknown
import pandas as pd
import itertools
from typing import Iterator
def marker_iterator(df: pd.DataFrame, class_column: str='class') -> Iterator[str]:
"""Returns an iterator of decent marker shapes. The order is such that similar markers aren't used unless they're needed."""
@dmyersturnbull
dmyersturnbull / clustering_plot.py
Last active Nov 21, 2016
Calculate tSNE or MDS+PCA and plot the results in Seaborn in a way that doesn't look terrible.
View clustering_plot.py
# Douglas Myers-Turnbull wrote this for the Kokel Lab, which has released it under the Apache Software License, Version 2.0
# See the license file here: https://gist.github.com/dmyersturnbull/bfa1c3371e7449db553aaa1e7cd3cac1
# The list of copyright owners is unknown
import pandas as pd
import seaborn as sns
from scipy.spatial.distance import squareform
from sklearn import manifold
from scipy.spatial.distance import pdist
from sklearn.decomposition import PCA
@dmyersturnbull
dmyersturnbull / colored_barplot.py
Last active Nov 21, 2016
Colored barplot in Matplotlib that makes sense and doesn't look terrible.
View colored_barplot.py
# Douglas Myers-Turnbull wrote this for the Kokel Lab, which has released it under the Apache Software License, Version 2.0
# See the license file here: https://gist.github.com/dmyersturnbull/bfa1c3371e7449db553aaa1e7cd3cac1
# The list of copyright owners is unknown
import matplotlib.pyplot as plt
import numpy as np
from typing import Optional, Tuple
def colored_barplot(x: np.ndarray, y: np.ndarray, colors: np.ndarray, y_ticks: Optional[np.ndarray]=None, fig_size: Tuple[float, float]=(10.0, 10.0), label_rotation: float=75):
index = np.arange(0, len(x))
@dmyersturnbull
dmyersturnbull / TryWith.scala
Created Aug 4, 2016
Scala try-with-resources
View TryWith.scala
import java.io.Closeable
import scala.util.control.NonFatal
import scala.util.{Failure, Try}
/**
* Taken from user Morgen on StackOverflow with no substantive modifications:
* https://codereview.stackexchange.com/questions/79267/scala-trywith-that-closes-resources-automatically
* Which is licensed under cc-wiki with attribution required.
*/
object TryWith {
You can’t perform that action at this time.