Skip to content

R2 Decay Across Distance #1118

Discussion options

You must be logged in to vote

Here's something I've used for my projects.

import numpy as np
import pandas as pd
import msprime
import tskit

## Simulate
tree_sequence=msprime.simulate(sample_size=50, Ne=600, 
                                   length=1e7, recombination_rate=1e-6,
                                  mutation_rate=1e-8)


## Get pairwise matrix
ld_calc = tskit.LdCalculator(tree_sequence)
A = ld_calc.r2_matrix()

## Annotate matrix
df=pd.DataFrame(A)
df.index=tree_sequence.tables.sites.position
df.columns=tree_sequence.tables.sites.position

## Turn into long dataframe
long_format_distance_df=df.unstack().reset_index()
long_format_distance_df.columns = ['position_1', 'position_2', 'r_2']
long_format_dista…

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by soulcreator3
Comment options

You must be logged in to vote
1 reply
@soulcreator3
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants