Code of imsn()

19 views
Skip to first unread message

Sarah G

unread,
Nov 25, 2023, 3:09:18 PM11/25/23
to poppr
Hello  :)

I was reading one paper recently about haplotype network branch diversity (https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0251878).  I would really love to include this calculation method in my project! But it is very tricky, because for calculating haplotype network branch diversity (HBd) the authors used fasta files instead of microsatellites or SNP data. With poppr I can plot a minimum spanning network with microsatellites and SNP data using imsn(), but to calculate HBd I would need information about how many branches each genotype has and how many individuals share this genotype. Here is an example how the data I need for HBd could look like:

> this_is_a_data_frame_showing_haplotypes_and_branches
haplotype branches 
1 1 
5 2 
2 1 
3 3 
1 4 
4 1 
5 5 
1 6 
6 1
 
The dataset consists of 6 different haplotypes. If you want to see how they are connected to each other you can open the .png-file in the attachment. HBd doesn't take the branch length into account.

 
>And_here_is_another_data_frame_showing_how_many_individuals_have_a_specific_haplotype
 
A B C D E F G H I J K L M N O P Q R S T U total
 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 
 2 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 3 
 3 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 3 
 4 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 3 
 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 3 
 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 3
The sites are named from A to U and 1 to 6 are the haplotypes. If I am not mistaken this could be the allele frequencies of a microsatellite or SNP data set.

Is there a way, how I can optain this information from imsn()?


Best wishes,
Sarah

Zhian Kamvar

unread,
Nov 25, 2023, 3:16:37 PM11/25/23
to poppr
Hello,

the purpose of imsn() is to provide you with code that you can use to reproduce the network you obtained interactively. When you get your plot, you can recreate it in the R terminal by going to the "code" tab and copying the code used to make the plot.

The minimum spanning network will be inside of the `min_span_net` object, which will contain a `$graph` element that is an igraph object. You can use the {igraph} package to extract information like the adjency matrix (https://r.igraph.org/articles/igraph.html#treating-a-graph-as-an-adjacency-matrix) and the specific edge lengths.

Best,
Zhian
Reply all
Reply to author
Forward
0 new messages