How to Count the Number of Generations?

Wondering how to count the number of generations in a population? Knowing the pedigree depth is important in population studies. It can get more complex with overlapping generations, but the logic and process are simple. There are two ways to approach this: top-bottom and bottom-top, differing only in the direction of counting. Top-bottom approach Discard animals with both parents missing. Set parents that no longer appear in the pedigree (i.e., not in the first column) to missing. Count one generation. Repeat until no animals remain in the pedigree. Here’s the R code, assuming ped is a pedigree data frame with animal, sire, and dam columns, and missing parents are denoted as 0: ...

October 22, 2025 · Mohammad Ali Nilforooshan

Quick Tip: Calculating Genotype Frequencies

In this short blog post, I’m gonna show you a super simple way to calculate genotype frequencies. Let’s say we’re looking at a single spot in the DNA (a biallelic situation) with two possible versions, “A” and “a”. That means we can have three possible genotype combos: “AA”, “Aa”, and “aa”. What we want to do is count how many times each of these genotypes shows up at each SNP. ...

April 24, 2025 · Mohammad Ali Nilforooshan

An R function for MAF calculation

Here, I introduce an R function for calculating minor allele frequencies (MAF). calcmaf <- function(M, col1ID = TRUE) { if(col1ID) { maf = colMeans(M[,-1])/2 } else { maf = colMeans(M)/2 } maf[maf > 0.5] <- 1 - maf[maf > 0.5] return(unname(maf)) } The calcMAF function takes arguments M and col1ID. M is the genotype data frame with genotypes coded as 0:2. col1ID takes TRUE or FALSE. If TRUE (default) the 1st column of M is animal ID. Let’s create an example genotype data frame for 10 genotypes and 20 SNPs, where the first column is animal ID. ...

February 28, 2025 · Mohammad Ali Nilforooshan

RMarkdown cheat sheet

A basic YAML header to start with. Choose the desired output format. --- title: "RMarkdown Example" author: "Mohammad Ali Nilforooshan" date: "6 August 2017" output: html_document # output: pdf_document # output: word_document --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` horizontal rule *** or --- Formatting Manual line break: End the line with two or more spaces. italic *italic* and italic _italic_ bold **bold** and bold __bold__ superscript2 superscript^2^ subscript2 subscript~2~ ...

October 25, 2024 · Mohammad Ali Nilforooshan