magnusdv / forrel

Forensic pedigree analysis and relatedness inference
GNU General Public License v2.0
10 stars 0 forks source link

`Familias2ped` #13

Closed thoree closed 5 years ago

thoree commented 5 years ago

I had some problems:

# Example 1. Converting Familias singletons to ped:
library(Familias, quietly = TRUE)
library(forrel, quietly = TRUE)
data(NorwegianFrequencies)
TH01 = NorwegianFrequencies$TH01
locus1 = FamiliasLocus(TH01)
persons = c('singleFemale')
datamatrix = data.frame(locus1.1 = 8, locus1.2= 9.3)
rownames(datamatrix) = persons
# First try
Familias2ped(NULL, datamatrix, locus1)
#> Error in data.frame(id = id, fid = 0, mid = 0, sex = 1, stringsAsFactors = FALSE): arguments imply differing number of rows: 0, 1
# Second try
ped1 = FamiliasPedigree(id = persons, dadid = NA,  momid = NA,  sex = 'female')
Familias2ped(ped1, datamatrix, locus1)
#> Error in matrix("0", nrow = nFath + nMoth, ncol = ncol(allelematrix)): non-numeric matrix extent

# Example 2. A small extension of the first
# example in the help for Familias2ped. Genotypes are lost when a singleton `NN` is added :

persons = c('mother', 'daughter', 'AF', 'NN')
ped1 = FamiliasPedigree(id = persons,
                        dadid = c(NA, 'AF', NA, NA),
                        momid = c(NA, 'mother', NA, NA),
                        sex = c('female', 'female', 'male', 'male'))
datamatrix = data.frame(THO1.1=c(NA, 8, NA, 8), THO1.2=c(NA,9.3, NA, 8))
rownames(datamatrix) = persons
x = Familias2ped(ped1, datamatrix, locus1)
plotPedList(x, marker = 1)

Created on 2019-01-11 by the reprex package (v0.2.1)

magnusdv commented 5 years ago

Thanks. The first one is a simple bug, not related to your second problem. I'll move the second example to a separate issue, so I can deal with them separately.

magnusdv commented 5 years ago

A tip for future issues involving Familias2ped(): When the allele frequencies are not relevant for the problem, you can set loci = NULL to make the example more minimal:

library(forrel, quietly = TRUE)
library(Familias, quietly = TRUE)

persons = 'singleFemale'
ped1 = FamiliasPedigree(id = persons, dadid = NA,  momid = NA,  sex = 'female')

datamatrix = data.frame(locus1.1 = 8, locus1.2= 9.3)
rownames(datamatrix) = persons

Familias2ped(ped1, datamatrix, loci = NULL)
#> Error in matrix("0", nrow = nFath + nMoth, ncol = ncol(allelematrix)): non-numeric matrix extent