[英]Running into factor issue with R function
我有一個名為gwas.data
SNP A1 A2 EFF FRQ
2353 rs10001803 A G -0.06620391 0.06860
2307 rs10002573 T C -0.03969763 0.78100
504 rs10003143 A C 0.03829721 0.53170
1802 rs1001022 T C 0.08159842 0.96174
461 rs10011564 T C 0.04930432 0.27840
2331 rs10013187 A C -0.03600030 0.54490
我有第二個框架,名為correct.orientation
:
SNP CLST A1 A2 FRQ IMP POS CHR BVAL
54445 rs10001803 Brahui G A 1.00 1 157121506 4 898
49713 rs10002573 Brahui C T 0.26 0 31120097 4 983
52885 rs10003143 Brahui A C 0.42 0 114272159 4 918
193805 rs1001022 Brahui T C 0.98 0 24733488 22 970
48257 rs10011564 Brahui T C 0.10 1 18734768 4 863
52313 rs10013187 Brahui C A 0.34 1 103040573 4 908
我正在嘗試使兩個文件之間的A1和A2列匹配。 如果列gwas.data
從翻轉correct.orientation
那么我想他們翻轉到正確的方向。 如果翻轉它們,我也想更改EFF
列的符號,並為FRQ
列取(1-FRQ)。 這是我目前正在嘗試使用的代碼:
gwas.data <- MatchAlleles ( gwas.data , assoc.loci.freqs)
MatchAlleles <- function ( gwas.data , assoc.loci.freqs ) {
if ( nrow ( gwas.data ) != nrow ( correct.orientation ) ) {
stop ( "GWAS dataset and Orientation Matching dataset contain differing numbers of SNPs" )
}
flip <- gwas.data$A1 == correct.orientation$A2 & gwas.data$A2 == correct.orientation$A1
dont.flip <- gwas.data$A1 == correct.orientation$A1 & gwas.data$A2 == correct.orientation$A2
for ( i in 1 : nrow ( gwas.data ) ) {
if ( flip [ i ] ) {
gwas.data$A1 [ i ] <- correct.orientation$A1 [ i ]
gwas.data$A2 [ i ] <- correct.orientation$A2 [ i ]
gwas.data$EFF [ i ] <- - gwas.data$EFF [ i ]
gwas.data$FRQ [ i ] <- 1 - gwas.data$FRQ [ i ]
} else if ( dont.flip [ i ] ) {
#do nothing
} else {
stop ( "Strand Issue")
}
}
return ( gwas.data )
}
assoc.loci.freqs
術語無關緊要,並包含在原始代碼中,但在函數中位於較高位置,因此assoc.loci.freqs
。 當我嘗試使用此代碼時,出現錯誤: Error in Ops.factor(gwas.data$A1, correct.orientation$A2) : level sets of factors are different
的錯誤: Error in Ops.factor(gwas.data$A1, correct.orientation$A2) : level sets of factors are different
可能是什么引起的?
可能是gwas.data$A1
中存在某個核苷酸,但是不correct.orientation$A2
gwas.data$A1
correct.orientation$A2
嗎? 使用上面給出的示例,來自A1
的因子水平為A
和T
,而來自A2
的因子水平為A
, T
和C
@dayne評論中的建議應避免此問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.