scgenefit
Python code for genetic marker selection using linear programming
Science Score: 23.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
○codemeta.json file
-
○.zenodo.json file
-
✓DOI references
Found 1 DOI reference(s) in README -
✓Academic publication links
Links to: biorxiv.org -
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (12.7%) to scientific vocabulary
Repository
Python code for genetic marker selection using linear programming
Basic Info
- Host: GitHub
- Owner: solevillar
- License: mit
- Language: Python
- Default Branch: master
- Size: 20.6 MB
Statistics
- Stars: 42
- Watchers: 2
- Forks: 13
- Open Issues: 2
- Releases: 0
Metadata Files
README.md
scGeneFit
Python code for genetic marker selection using linear programming.
The algorithm is described in https://www.biorxiv.org/content/10.1101/599654v1
Dependencies: numpy, matplotlib, scipy, sklearn.
Examples and source code: https://github.com/solevillar/scGeneFit-python
The package main function is scGeneFit.functions.get_markers()
getmarkers(data, labels, nummarkers, method='centers', epsilon=1, samplingrate=1, nneighbors=3, max_constraints=1000, redundancy=0.01, verbose=True)
- data: Nxd numpy array with point coordinates, N: number of points, d: dimension
- labels: list with labels (N labels, one per point)
- nummarkers: target number of markers to select (nummarkers<d)
- method: 'centers', 'pairwise', or 'pairwise_centers'
- 'centers' considers constraints that require that two consecutive classes have their empirical centers separated after projection to the selected markers. According to our numerical experiments is the least general but most efficient and stable set of constraints.
- 'pairwise' considers constraints that require that points from different classes are separated by a minimal distance after projection to the selected markers. Since all pairwise constraints would typically make the problem computationally too expensive, the constraints are sampled (samplingrate) and capped (nneighbors, max_constraints).
- 'pairwise_centers' after projection to the selected markers every point is required to lie closest to its empirical center than every other class center (sampling and capping also apply here).
- epsilon: constraints will be of the form expr>Delta, where Delta is chosen to be epsilon times the norm of the smallest constraint (default 1) This is the most important parameter in this problem, it determines the scale of the constraints, the rest the rest of the parameters only determine the size of the LP to adapt to limited computational resources. We include a function that finds the optimal value of epsilon given a classifier and a training/test set. We provide an example of the optimization in scGeneFitfunctionalgroups.ipynb
- samplingrate: (if method=='pairwise' or 'pairwisecenters') selects constraints from a random sample of proportion sampling_rate (default 1)
- nneighbors: (if method=='pairwise') chooses the constraints from nneighbors nearest neighbors (default 3)
- max_constraints: maximum number of constraints to consider (default 1000)
- redundancy: (if method=='centers') in this case not all pairwise constraints are considered but just between centers of consecutive labels plus a random fraction of constraints given by redundancy. If redundancy==1 all constraints between pairs of centers are considered
- verbose: whether it prints information like size of the LP or elapsed time (default True)
```python from scGeneFit.functions import *
%matplotlib inline import numpy as np np.random.seed(0) ```
```python
```
Auxiliary functions
```python from sklearn.neighbors import NearestCentroid clf=NearestCentroid()
def performance(Xtrain, ytrain, Xtest, ytest, clf): clf.fit(Xtrain, ytrain) return clf.score(Xtest, ytest) ```
CITEseq example
Data included in package, from
[1] Marlon Stoeckius, Christoph Hafemeister, William Stephenson, Brian Houck-Loomis, Pratip K Chattopadhyay, Harold Swerdlow, Rahul Satija, and Peter Smibert. Simultaneous epitope and transcriptome measurement insingle cells. Nature Methods, 14(9):865, 2017.
```python
load data from files
[data, labels, names]= loadexampledata("CITEseq") N,d=data.shape ```
Use of scGeneFit (center based constraints)
```python num_markers=25 method='centers' redundancy=0.25
markers= getmarkers(data, labels, nummarkers, method=method, redundancy=redundancy)
accuracy=performance(data, labels, data, labels, clf) accuracy_markers=performance(data[:,markers], labels, data[:,markers], labels, clf)
print("Accuracy (whole data,", d, " markers): ", accuracy) print("Accuracy (selected", nummarkers, "markers)", accuracymarkers) ```
Solving a linear program with 500 variables and 45 constraints
Time elapsed: 0.3295409679412842 seconds
Accuracy (whole data, 500 markers): 0.8660786816757572
Accuracy (selected 25 markers) 0.7863525588952072
```python
TSNE plot
a=plotmarkerselection(data, markers, names) ```
Computing TSNE embedding
Elapsed time: 117.06255102157593 seconds

Use of scGeneFit (pairwise distance constraints)
```python nummarkers=25 method='pairwise' samplingrate=0.1 #use 10 percent of the data to generate constraints nneighbors=3 #3 constraints per point epsilon=1 #Delta is 10*norm of the smallest constraint maxconstraints=1000 #use at most 1000 constraints (for efficiency)
markers= getmarkers(data, labels, nummarkers, method=method, samplingrate=samplingrate, nneighbors=nneighbors, epsilon=epsilon, maxconstraints=maxconstraints)
accuracy=performance(data, labels, data, labels, clf) accuracy_markers=performance(data[:,markers], labels, data[:,markers], labels, clf)
print("Accuracy (whole data,", d, " markers): ", accuracy) print("Accuracy (selected", nummarkers, "markers)", accuracymarkers) ```
Solving a linear program with 500 variables and 1000 constraints
Time elapsed: 6.737841844558716 seconds
Accuracy (whole data, 500 markers): 0.8660786816757572
Accuracy (selected 25 markers) 0.7710340025530927
```python
TSNE plot
a=plotmarkerselection(data, markers, names) ```
Computing TSNE embedding
Elapsed time: 118.96086025238037 seconds

Use of scGeneFit (pairwise center based constraints)
```python nummarkers=25 method='pairwisecenters' samplingrate=0.1 #use 10 percent of the data to generate constraints nneighbors=0 #neighbors are not used for the center constraints epsilon=10 #Delta is 10*norm of the smallest constraint max_constraints=1000 #use at most 5000 constraints (for efficiency)
markers= getmarkers(data, labels, nummarkers, method=method, samplingrate=samplingrate, nneighbors=nneighbors, epsilon=epsilon, maxconstraints=maxconstraints)
accuracy=performance(data, labels, data, labels, clf) accuracy_markers=performance(data[:,markers], labels, data[:,markers], labels, clf)
print("Accuracy (whole data,", d, " markers): ", accuracy) print("Accuracy (selected", nummarkers, "markers)", accuracymarkers) ```
Solving a linear program with 500 variables and 1000 constraints
Time elapsed: 4.070271015167236 seconds
Accuracy (whole data, 500 markers): 0.8660786816757572
Accuracy (selected 25 markers) 0.7864686085644655
```python
TSNE plot
a=plotmarkerselection(data, markers, names) ```
Computing TSNE embedding
Elapsed time: 118.61988186836243 seconds

One vs all markers
```python markers2=onevsall_selection(data,labels)
accuracy=performance(data, labels, data, labels, clf) accuracy_markers=performance(data[:,markers2], labels, data[:,markers2], labels, clf)
print("Accuracy (whole data,", d, " markers): ", accuracy) print("Accuracy (selected", nummarkers, "markers)", accuracymarkers) ```
Accuracy (whole data, 500 markers): 0.8660786816757572
Accuracy (selected 25 markers) 0.7537426018335848
python
a=plot_marker_selection(data, markers2, names)
Computing TSNE embedding
Elapsed time: 115.60354685783386 seconds

Zeisel example
Zeisel data included in package, from
[2] Amit Zeisel, Ana B Munoz-Manchado, Simone Codeluppi, Peter Lonnerberg, Gioele La Manno, Anna Jureus, Sueli Marques, Hermany Munguba, Liqun He, Christer Betsholtz, et al. Cell types in the mouse cortex and hippocampus revealed by single-cell RNA-seq. Science, 347(6226):1138–1142, 2015.
This example exhibits a hierarchical clustering structure. We use the function getmarkershierarchy that takes the hierarchical structure into consideration to select the constraints.
```python
load data from file
[data, labels, names]=loadexampledata("zeisel") N,d=data.shape ```
Use of scGeneFit (center based constraints)
```python num_markers=25 method='centers' redundancy=0.1
markers= getmarkershierarchy(data, labels, num_markers, method=method, redundancy=redundancy)
accuracy=performance(data, labels[0], data, labels[0], clf) accuracy_markers=performance(data[:,markers], labels[0], data[:,markers], labels[0], clf)
print("Accuracy (whole data,", d, " markers): ", accuracy) print("Accuracy (selected", nummarkers, "markers)", accuracymarkers)
```
Solving a linear program with 4000 variables and 96 constraints
Time elapsed: 67.69524931907654 seconds
Accuracy (whole data, 4000 markers): 0.8745424292845257
Accuracy (selected 25 markers) 0.8861896838602329
```python
TSNE plot
a=plotmarkerselection(data, markers, names[0]) ```
Computing TSNE embedding
Elapsed time: 71.29064297676086 seconds

Use of scGeneFit (pairwise distance constraints)
```python nummarkers=25 method='pairwise' samplingrate=0.05 #use 5 percent of the data to generate constraints nneighbors=3 #3 constraints per point epsilon=10 #Delta is 10*norm of the smallest constraint maxconstraints=500 #use at most 500 constraints (for efficiency) use_centers=False #constraints given by pairwise distances
markers= getmarkershierarchy(data, labels, nummarkers, method=method, samplingrate=samplingrate, nneighbors=n_neighbors, epsilon=epsilon)
accuracy=performance(data, labels[0], data, labels[0], clf) accuracy_markers=performance(data[:,markers], labels[0], data[:,markers], labels[0], clf)
print("Accuracy (whole data,", d, " markers): ", accuracy) print("Accuracy (selected", nummarkers, "markers)", accuracymarkers)
```
Solving a linear program with 4000 variables and 1000 constraints
Time elapsed: 40.95984506607056 seconds
Accuracy (whole data, 4000 markers): 0.8745424292845257
Accuracy (selected 25 markers) 0.8435940099833611
```python
```
Use of scGeneFit (pairwise center based constraints)
```python nummarkers=25 method='pairwisecenters' samplingrate=0.05 #use 5 percent of the data to generate constraints nneighbors=0 #neighbors are not used for the center constraints epsilon=10 #Delta is 10*norm of the smallest constraint maxconstraints=500 #use at most 500 constraints (for efficiency) usecenters=True #constraints given by pairwise distances
markers = getmarkershierarchy(data, labels, nummarkers, method=method, samplingrate=samplingrate, nneighbors=n_neighbors, epsilon=epsilon)
accuracy=performance(data, labels[0], data, labels[0], clf) accuracy_markers=performance(data[:,markers], labels[0], data[:,markers], labels[0], clf)
print("Accuracy (whole data,", d, " markers): ", accuracy) print("Accuracy (selected", nummarkers, "markers)", accuracymarkers) ```
Solving a linear program with 4000 variables and 1000 constraints
Time elapsed: 168.19283509254456 seconds
Accuracy (whole data, 4000 markers): 0.8745424292845257
Accuracy (selected 25 markers) 0.9237936772046589
```python
TSNE plot
a=plotmarkerselection(data, markers, names[0]) ```
Computing TSNE embedding
Elapsed time: 69.88537192344666 seconds

```python
```
Example from second level of the hierarchy
python
for name in set(names[0]):
idx=[s for s in range(len(names[0])) if names[0][s]==name]
aux=plot_marker_selection(data[idx], markers, [names[1][s] for s in idx])
Computing TSNE embedding
Elapsed time: 8.925884008407593 seconds
Computing TSNE embedding
Elapsed time: 1.5634911060333252 seconds
Computing TSNE embedding
Elapsed time: 0.638862133026123 seconds
Computing TSNE embedding
Elapsed time: 7.366800785064697 seconds
Computing TSNE embedding
Elapsed time: 1.0175950527191162 seconds
Computing TSNE embedding
Elapsed time: 2.3961689472198486 seconds
Computing TSNE embedding
Elapsed time: 1.0149860382080078 seconds







```python
```
One vs all markers
```python markers2=onevsall_selection(data,labels[0])
accuracy=performance(data, labels[0], data, labels[0], clf) accuracy_markers=performance(data[:,markers2], labels[0], data[:,markers2], labels[0], clf)
print("Accuracy (whole data,", d, " markers): ", accuracy) print("Accuracy (selected", nummarkers, "markers)", accuracymarkers) ```
Accuracy (whole data, 4000 markers): 0.8745424292845257
Accuracy (selected 25 markers) 0.8569051580698835
python
a=plot_marker_selection(data, markers2, names[0])
Computing TSNE embedding
Elapsed time: 69.53578591346741 seconds

```python
```
Owner
- Name: Soledad Villar
- Login: solevillar
- Kind: user
- Location: solevillar.github.io
- Company: Johns Hopkins University
- Website: https://www.ams.jhu.edu/villar
- Twitter: SoledadVillar5
- Repositories: 1
- Profile: https://github.com/solevillar
GitHub Events
Total
- Watch event: 1
Last Year
- Watch event: 1
Committers
Last synced: almost 3 years ago
Top Committers
| Name | Commits | |
|---|---|---|
| Soledad Villar | s****r | 23 |
| Soledad Villar | s****r@S****l | 2 |
Issues and Pull Requests
Last synced: 11 months ago
All Time
- Total issues: 2
- Total pull requests: 2
- Average time to close issues: about 2 months
- Average time to close pull requests: less than a minute
- Total issue authors: 2
- Total pull request authors: 2
- Average comments per issue: 1.5
- Average comments per pull request: 0.0
- Merged pull requests: 1
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- mjleone (1)
- giovp (1)
Pull Request Authors
- vidalarroyo (2)
- HekpoMaH (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 15 last-month
- Total dependent packages: 0
- Total dependent repositories: 2
- Total versions: 3
- Total maintainers: 1
pypi.org: scgenefit
Genetic marker selection with linear programming
- Homepage: https://github.com/solevillar/scGeneFit-python
- Documentation: https://scgenefit.readthedocs.io/
- License: MIT License
-
Latest release: 1.0.2
published about 6 years ago
Rankings
Maintainers (1)
Dependencies
- matplotlib *
- numpy *
- scipy *
- sklearn *