% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/mergebd.R
\name{mergebd}
\alias{mergebd}
\title{Merge Format 5 binary dosage files}
\usage{
mergebd(bdose_files, bdose_file)
}
\arguments{
\item{bdose_files}{Character vector of paths to the input .bdose files.
Must contain at least two entries. The companion .bdi file for each is
expected at \code{paste0(bdose_files[i], ".bdi")}.}

\item{bdose_file}{Path for the output .bdose file. The companion .bdi
metadata file is written to \code{paste0(bdose_file, ".bdi")}.}
}
\value{
NULL (invisibly)
}
\description{
Merges two or more Format 5 binary dosage files into a single Format 5
output file. The merge type is determined automatically:
}
\details{
\itemize{
\item If subject IDs do not overlap across files, a \strong{subject merge}
is performed: the output contains all subjects from every file and
the SNPs common to all files.
\item If SNP IDs do not overlap across files, a \strong{SNP merge} is
performed: the output contains all SNPs from every file and the
subjects common to all files.
}

If both subject IDs and SNP IDs overlap across files the merge cannot be
performed and an error is returned.

SNPs are identified by chromosome, position, reference allele, and alternate
allele.
}
\examples{
bdfile <- system.file("extdata", "vcf1a.bdose", package = "BinaryDosage")
bdinfo_src <- getbdinfo(bdfile)

# Create two format 5 files with non-overlapping subjects
bdose_a   <- tempfile(fileext = ".bdose")
bdose_b   <- tempfile(fileext = ".bdose")
bdose_tmp <- tempfile(fileext = ".bdose")
updatebd(bdfiles = bdfile, bdose_file = bdose_tmp)
subsetbd(bdfiles    = bdose_tmp,
         bdose_file = bdose_a,
         subjectids = bdinfo_src$samples$sid[1:30])
subsetbd(bdfiles    = bdose_tmp,
         bdose_file = bdose_b,
         subjectids = bdinfo_src$samples$sid[31:60])

bdose_out <- tempfile(fileext = ".bdose")
mergebd(bdose_files = c(bdose_a, bdose_b),
        bdose_file  = bdose_out)
}
