我已經在文本文件中使用pairwiseAlignment函數進行局部對齊了一個評分矩陣。然後我用這個功能,將其輸入到R:如何將矩陣轉換爲數字矩陣?
ex <- as.matrix(read.table("~/scoringMatrix", header=FALSE, sep = "\t", row.names = 1, as.is=TRUE)
格式是這樣的:
> ex
A T C G
A 5 -2 -1 -2
T -2 7 -1 -2
C -1 -1 7 2
G -2 -2 2 8
現在,每當我用pairwiseAlignment
功能我得到以下錯誤:如果我
pairwiseAlignment(x[[1]], x[[2]], substitutionMatrix = ex, gapOpening = -2, gapExtension = -8, scoreOnly = FALSE)
Error in XStringSet.pairwiseAlignment(pattern = pattern, subject = subject, :
'substitutionMatrix' must be a numeric matrix
會使用已經存在的替代矩陣,如BLOSUM50,它可以很好地工作。那麼如何讓這個矩陣適合pairwiseAlignment?
> dput(ex)
structure(logical(0), .Dim = c(5L, 0L), .Dimnames = list(c(" A T C G",
"A 5 -2 -1 -2", "T -2 7 -1 -2", "C -1 -1 7 2", "G -2 -2 2 8"
), NULL))
雖然dput(BLOSUM50)
看起來完全不同:
> dput(BLOSUM50)
structure(c(5L, -2L, -1L, -2L, -1L, -1L, -1L, 0L, -2L, -1L, -2L,
-1L, -1L, -3L, -1L, 1L, 0L, -3L, -2L, 0L, -2L, -1L, -1L, -5L,
-2L, 7L, -1L, -2L, -4L, 1L, 0L, -3L, 0L, -4L, -3L, 3L, -2L, -3L,
-3L, -1L, -1L, -3L, -1L, -3L, -1L, 0L, -1L, -5L, -1L, -1L, 7L,
2L, -2L, 0L, 0L, 0L, 1L, -3L, -4L, 0L, -2L, -4L, -2L, 1L, 0L,
-4L, -2L, -3L, 4L, 0L, -1L, -5L, -2L, -2L, 2L, 8L, -4L, 0L, 2L,
-1L, -1L, -4L, -4L, -1L, -4L, -5L, -1L, 0L, -1L, -5L, -3L, -4L,
5L, 1L, -1L, -5L, -1L, -4L, -2L, -4L, 13L, -3L, -3L, -3L, -3L,
-2L, -2L, -3L, -2L, -2L, -4L, -1L, -1L, -5L, -3L, -1L, -3L, -3L,
-2L, -5L, -1L, 1L, 0L, 0L, -3L, 7L, 2L, -2L, 1L, -3L, -2L, 2L,
0L, -4L, -1L, 0L, -1L, -1L, -1L, -3L, 0L, 4L, -1L, -5L, -1L,
0L, 0L, 2L, -3L, 2L, 6L, -3L, 0L, -4L, -3L, 1L, -2L, -3L, -1L,
-1L, -1L, -3L, -2L, -3L, 1L, 5L, -1L, -5L, 0L, -3L, 0L, -1L,
-3L, -2L, -3L, 8L, -2L, -4L, -4L, -2L, -3L, -4L, -2L, 0L, -2L,
-3L, -3L, -4L, -1L, -2L, -2L, -5L, -2L, 0L, 1L, -1L, -3L, 1L,
0L, -2L, 10L, -4L, -3L, 0L, -1L, -1L, -2L, -1L, -2L, -3L, 2L,
-4L, 0L, 0L, -1L, -5L, -1L, -4L, -3L, -4L, -2L, -3L, -4L, -4L,
-4L, 5L, 2L, -3L, 2L, 0L, -3L, -3L, -1L, -3L, -1L, 4L, -4L, -3L,
-1L, -5L, -2L, -3L, -4L, -4L, -2L, -2L, -3L, -4L, -3L, 2L, 5L,
-3L, 3L, 1L, -4L, -3L, -1L, -2L, -1L, 1L, -4L, -3L, -1L, -5L,
-1L, 3L, 0L, -1L, -3L, 2L, 1L, -2L, 0L, -3L, -3L, 6L, -2L, -4L,
-1L, 0L, -1L, -3L, -2L, -3L, 0L, 1L, -1L, -5L, -1L, -2L, -2L,
-4L, -2L, 0L, -2L, -3L, -1L, 2L, 3L, -2L, 7L, 0L, -3L, -2L, -1L,
-1L, 0L, 1L, -3L, -1L, -1L, -5L, -3L, -3L, -4L, -5L, -2L, -4L,
-3L, -4L, -1L, 0L, 1L, -4L, 0L, 8L, -4L, -3L, -2L, 1L, 4L, -1L,
-4L, -4L, -2L, -5L, -1L, -3L, -2L, -1L, -4L, -1L, -1L, -2L, -2L,
-3L, -4L, -1L, -3L, -4L, 10L, -1L, -1L, -4L, -3L, -3L, -2L, -1L,
-2L, -5L, 1L, -1L, 1L, 0L, -1L, 0L, -1L, 0L, -1L, -3L, -3L, 0L,
-2L, -3L, -1L, 5L, 2L, -4L, -2L, -2L, 0L, 0L, -1L, -5L, 0L, -1L,
0L, -1L, -1L, -1L, -1L, -2L, -2L, -1L, -1L, -1L, -1L, -2L, -1L,
2L, 5L, -3L, -2L, 0L, 0L, -1L, 0L, -5L, -3L, -3L, -4L, -5L, -5L,
-1L, -3L, -3L, -3L, -3L, -2L, -3L, -1L, 1L, -4L, -4L, -3L, 15L,
2L, -3L, -5L, -2L, -3L, -5L, -2L, -1L, -2L, -3L, -3L, -1L, -2L,
-3L, 2L, -1L, -1L, -2L, 0L, 4L, -3L, -2L, -2L, 2L, 8L, -1L, -3L,
-2L, -1L, -5L, 0L, -3L, -3L, -4L, -1L, -3L, -3L, -4L, -4L, 4L,
1L, -3L, 1L, -1L, -3L, -2L, 0L, -3L, -1L, 5L, -4L, -3L, -1L,
-5L, -2L, -1L, 4L, 5L, -3L, 0L, 1L, -1L, 0L, -4L, -4L, 0L, -3L,
-4L, -2L, 0L, 0L, -5L, -3L, -4L, 5L, 2L, -1L, -5L, -1L, 0L, 0L,
1L, -3L, 4L, 5L, -2L, 0L, -3L, -3L, 1L, -1L, -4L, -1L, 0L, -1L,
-2L, -2L, -3L, 2L, 5L, -1L, -5L, -1L, -1L, -1L, -1L, -2L, -1L,
-1L, -2L, -1L, -1L, -1L, -1L, -1L, -2L, -2L, -1L, 0L, -3L, -1L,
-1L, -1L, -1L, -1L, -5L, -5L, -5L, -5L, -5L, -5L, -5L, -5L, -5L,
-5L, -5L, -5L, -5L, -5L, -5L, -5L, -5L, -5L, -5L, -5L, -5L, -5L,
-5L, -5L, 1L), .Dim = c(24L, 24L), .Dimnames = list(c("A", "R",
"N", "D", "C", "Q", "E", "G", "H", "I", "L", "K", "M", "F", "P",
"S", "T", "W", "Y", "V", "B", "Z", "X", "*"), c("A", "R", "N",
"D", "C", "Q", "E", "G", "H", "I", "L", "K", "M", "F", "P", "S",
"T", "W", "Y", "V", "B", "Z", "X", "*")))
'apply(x,2,as.numeric)'工作嗎? –
@TadDallas是不是指'ex2 < - apply(ex,2,as.numeric)'?如果這就是你的意思,這是行不通的。 – estranged
你確定要'header = FALSE',因爲你看起來有一個頭部'A T C G'。如果是這樣,使用'header = FALSE'將使矩陣的第一行成爲這些標籤,因此您的矩陣將是'character' – user20650