SpectralInference

Spectral [phenotype/phylogenetic] Inference package

https://github.com/aramanlab/spectralinference.jl

Science Score: 31.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (9.6%) to scientific vocabulary
Last synced: 10 months ago · JSON representation ·

Repository

Spectral [phenotype/phylogenetic] Inference package

Basic Info
  • Host: GitHub
  • Owner: aramanlab
  • License: bsd-3-clause
  • Language: Julia
  • Default Branch: main
  • Homepage:
  • Size: 303 KB
Statistics
  • Stars: 1
  • Watchers: 0
  • Forks: 1
  • Open Issues: 0
  • Releases: 3
Created almost 3 years ago · Last pushed about 2 years ago
Metadata Files
Readme License Citation

README.md

Spectral Inference

Stable Dev Build Status Coverage

Install

type:

julia-repl ] dev git@github.com:aramanlab/SpectralInference.jl.git into the julia command line

Examples

calculate Spectral distances ```julia using SpectralInference

M = rand(100, 100) usv = svd(M) # from linear algebra spectralpartitions = getintervals(usv.S, alpha=1.0, q=0.5) Dij = spectraldistances(usv.U, usv.S, spectralpartitions) make a tree from the distances using basic hierarchical clusting julia

shortcut of hclust(spimtx; linkage=:average, branchorder=:optimal) from Clustering package

spitree = UPGMA_tree(Dij) ```

or with neighbor joining julia using NeighborJoining # https://github.com/BenjaminDoran/NeighborJoining.jl njclusts = regNJ(Dij) # or fastNJ(Dij) ids = string.(1:100); nwstring = NeighborJoining.newickstring(njclusts, ids)

example script for running SpectralInference on a gene expression matrix in a .csv file to generate spectral tree.

```julia

Example SpectralInference code for gene expression matrix in .csv format (genes = rows, cells = columns)

Ben Doran / Noah Gamble

2023/08/07

Load packages

using SpectralInference using NeighborJoining using CSV, DataFrames using LinearAlgebra using Clustering using Muon using JLD2

Load matrix as data frame from .csv

df = CSV.read("/path/to/geneexpressionmatrix.csv", DataFrame)

Copy to matrix

m = Matrix(df[:,2:end]) #

filter out low abundance genes

filtthresh = 10 genecounts = mapslices(r -> sum(r.>0), m, dims=2) |> vec idxkeep = genecounts .> filtthresh m = m[idxkeep,:]

Organize into annotated data object

m' is transpose of m (make samples rows)

adata = AnnData(X = m') adata.obsnames .= names(df)[2:end] adata.varnames .= string.(df.Column1[idx_keep]) @info size(adata.X)

Perform SVD

@info "Peforming SVD..." @time usv = svd(adata.X)

Perform SpectralInference

@info "Calculating SpectralInference matrix..." @time dij = spectraldistances(usv.U, usv.S, getintervals(usv.S))

Cluster to tree

@info "Clustering SpectralInference matrix..."

@time spitree = UPGMA_tree(dij)

@time nwtreestring = SpectralInference.newickstring(spitree, adata.obs_names.vals)

@time spitree = regNJ(dij) @time nwtreestring = NeighborJoining.newickstring(spitree, adata.obs_names.vals)

Add SpectralInference matrix to adata object

@info "Adding SpectralInference matrix to ADATA..." adata.obsp["spectraldistances"] = dij adata.obs[:,"order"] = spitree.order adata.uns["cellmerges"] = spitree.merges adata.uns["heights"] = spitree.heights adata.uns["treelinkage"] = string(spitree.linkage) adata.uns["newicktreestring"] = nwtreestring

Write annotated data to and Newick tree to disk

@info "Writing results to disk..." @time begin writeh5ad("spitest.h5ad", adata) open("testtree.nw.txt", "w") do io println(io, nwtreestring) end jldsave("test_tree.jld2"; spitree) end

```

example script for creating bootstrap spectral tree and calculating support values

```julia using SpectralInference using NeighborJoining using Muon

spitst = readh5ad("spitest.h5ad") mtx = spitst.X[:, :] NBOOT = 100 boottrees = map(1:NBOOT) do i ncols = size(mtx, 2) tmpmtx = mtx[:, rand(1:ncols, ncols)] usv = svd(tmpmtx) dij = spectraldistances(usv.U, usv.S, getintervals(usv.S)) nwtreestring = NeighborJoining.newickstring(regNJ(dij)) end open("testtree_bootstraps.nw.txt", "w") do io for t in boottrees println(io, t) end end

calculate support values

using GoTreejll reftreefile = joinpath(pwd(), "testtree.nw.txt") boottreefile = joinpath(pwd(), "testtreebootstraps.nw.txt") supporttreefile = joinpath(pwd(), "testtreebootstraps.nw.txt") run($(gotree()) -i $reftreefile -b $boottreefile -o $supporttreefile) ```

script for calculating MI between metavariables and tree depths

```julia using SpectralInference using NewickTree using Muon, DataFrames

spitst = readh5ad("spitest.h5ad") spitree = readnw(readline(joinpath(pwd(), "testtreebootstraps.nw.txt"))) spitree50pct = aspolytomy(n->NewickTree.support(n)<.5, spitree) leafnames = getleafnames(spitree50pct) mi, treedepths = pairedMIacrosstreedepth(eachcolumn(spitst.obs), leafnames, spitree_50pct; ncuts=100)

NBOOTS = 50 results = map(1:NBOOTS) do i pairedMIacrosstreedepth(eachcolumn(spitst.obs), leafnames, spitree_50pct; bootstrap=true, ncuts=100) end

rowmask = spitst.obs.count .> 15 results = map(1:NBOOTS) do i pairedMIacrosstreedepth(eachcolumn(spitst.obs), leafnames, spitree50pct; mask=rowmask, bootstrap=true, ncuts=100) end allmiresults = first.(results) alltreedepths_results = last.(results)

```

Citing

See CITATION.bib for the relevant reference(s).

Owner

  • Name: Raman Lab of UChicago
  • Login: aramanlab
  • Kind: organization

Citation (CITATION.bib)

@misc{SpectralInference.jl,
	author  = {Benjamin Doran and collaborators},
	title   = {SpectralInference.jl},
	url     = {https://github.com/aramanlab/SpectralInference.jl},
	version = {v0.3.0},
	year    = {2022},
	month   = {12}
}

GitHub Events

Total
Last Year

Issues and Pull Requests

Last synced: 10 months ago

All Time
  • Total issues: 2
  • Total pull requests: 0
  • Average time to close issues: about 2 months
  • Average time to close pull requests: N/A
  • Total issue authors: 2
  • Total pull request authors: 0
  • Average comments per issue: 3.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • 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
  • BenjaminDoran (1)
  • JuliaTagBot (1)
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • julia 1 total
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 1
juliahub.com: SpectralInference

Spectral [phenotype/phylogenetic] Inference package

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 1 Total
Rankings
Dependent repos count: 9.9%
Average: 24.9%
Dependent packages count: 39.9%
Last synced: 10 months ago

Dependencies

.github/workflows/CI.yml actions
  • actions/checkout v2 composite
  • codecov/codecov-action v2 composite
  • julia-actions/cache v1 composite
  • julia-actions/julia-buildpkg v1 composite
  • julia-actions/julia-docdeploy v1 composite
  • julia-actions/julia-processcoverage v1 composite
  • julia-actions/julia-runtest v1 composite
  • julia-actions/setup-julia v1 composite
.github/workflows/CompatHelper.yml actions
.github/workflows/TagBot.yml actions
  • JuliaRegistries/TagBot v1 composite