1.下载liftover : wget http://hgdownload.cse.ucsc.edu/admin/exe/linux.x86_64/liftOver
2.下载坐标注释文件:Index of /goldenPath/hg38/liftOver
3.input文件,bed格式:只定义前三列:chr start end,无表头。start和end不同,若是相同,end可以取start+1
4.坐标转换:chmod +x ./liftover #将liftover变成可执行文件
./liftover inputfile over.chain.gz outputfile unmapfile(对应未对应上的行)
inputfile:输入文件 bed格式
over.chain.gz:坐标注释文件(无需解压)
outputfile:输出文件
unmapfile:输出为对应上的行
#常见报错:Expecting integer field 3 line 225125 of chr19.bed, got 2.9e+07
原因:出现此问题的原因是 第三列的bp位置出现了科学计数法的形式,因此无法识别。
解决办法:在利用R对原bp位置执行加1操作时,先设置不使用科学计数法:options(scipen = 100)
代码记录:
options(scipen = 100)
library(dplyr)
df = read.table('AD.txt',sep='\t',header = T)
df = mutate(df,end=BP+1)#增加一列
options(max.print = 30000000)
df = df %>% select(CHR, BP, end, SNP)#改换列的位置
#因为liftover输入文件要求的chr列为chr1这种类型(不能只是数字)
df = mutate(df,chr='chr')#增加chr一列
df = tidyr::unite(df,'CHR',chr,CHR,sep='',remove=TRUE)#将chr和CHR数字列合并,sep为以''为连接符连接,remove=TRUE表示去除原来的列
write.table(df,file = 'AD.bed',sep = '\t',row.names = F,col.names = F,quote = F)#保存时要无列名
df1=df %>% filter(df[,1] %in% "chr1") #提取df中第一列为chr1的列