Skip to content

Instantly share code, notes, and snippets.

@zx8754
Created June 10, 2021 21:19
Show Gist options
  • Save zx8754/09937029a3a9366112fce90e2f41556e to your computer and use it in GitHub Desktop.
Save zx8754/09937029a3a9366112fce90e2f41556e to your computer and use it in GitHub Desktop.
# About -------------------------------------------------------------------
# 10/06/2021
#
# Reference: https://www.biostars.org/p/9474813/
#
# input: BIM filname
# Note: This script will overwrite the existing input bim file
#
# example run:
# Rscript makeSNPnamesUnique.R myBimFile.bim
# Input arguments ---------------------------------------------------------
args <- commandArgs(trailingOnly = TRUE)
fileBim <- args[1]
# Data --------------------------------------------------------------------
bim <- read.table(fileBim, header = FALSE, stringsAsFactors = FALSE)
# make unique names
bim$V2 <-
make.unique(
ifelse(bim$V2 == ".",
paste(bim$V1, bim$V4, bim$V5, bim$V6, sep = "_"),
bim$V2),
sep = "_")
# Output ------------------------------------------------------------------
write.table(bim, file = fileBim,
col.names = FALSE, row.names = FALSE, quote = FALSE,
sep = "\t")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment