Question: nrow,ncol name used amino acid string
0
gravatar for gizemtatar
5.3 years ago by
gizemtatar0
Turkey
gizemtatar0 wrote:

I have two amino acid sequence.

seq1="GCATGCT"

seq2="GATTACA"

They used string form for R code

> s1string
[1] "G" "C" "A" "T" "G" "C" "T"
> s2string
[1] "G" "A" "T" "T" "A" "C" "A"

I create matrix for this string

   [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
[1,]    0    0    0    0    0    0    0    0
[2,]    0    0    0    0    0    0    0    0
[3,]    0    0    0    0    0    0    0    0
[4,]    0    0    0    0    0    0    0    0
[5,]    0    0    0    0    0    0    0    0
[6,]    0    0    0    0    0    0    0    0
[7,]    0    0    0    0    0    0    0    0
[8,]    0    0    0    0    0    0    0    0

 I want to define matrix ncol with s1string, nrow= s2string. Can you help me for this topic?

 

 

sequence • 1.3k views
ADD COMMENTlink modified 5.3 years ago by Michael Dondrup47k • written 5.3 years ago by gizemtatar0

I want to [1,] col and [,1] row don't define. I will define finish [2,] and [2,] row and col. 

ADD REPLYlink written 5.3 years ago by gizemtatar0

maybe if you explain what you're trying to accomplish we can help a bit more?

ADD REPLYlink modified 5.3 years ago • written 5.3 years ago by ciclistadan30
       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
[1,]    0   -1   -2   -3   -4   -5   -6   -7
[2,]   -1    1    0   -1   -2   -3   -4   -5
[3,]   -2    0    0    1    0   -1   -2   -3
[4,]   -3   -1   -1    0    2    1    0   -1
[5,]   -4   -2   -2   -1    1    1    0    1
[6,]   -5   -3   -3   -1    0    0    0    0
[7,]   -6   -4   -2   -2   -1   -1    1    0
[8,]   -7   -5   -3   -1   -2   -2    0    0

I want to colname define start [,2] [,3] [,4] [,5] [,6] [,7] [,8]= "GCATGCT"

for example,

[,2]="G" [,3]="C" [,4]="A" [,5]="T" [,6]="G" [,7]="C" [,8]="T" . Because my matrix must create nrow+1 ncol+1 and I don't want define in this [1,1].

ADD REPLYlink modified 11 months ago by RamRS30k • written 5.3 years ago by gizemtatar0
1
gravatar for ciclistadan
5.3 years ago by
ciclistadan30
United States
ciclistadan30 wrote:

Not sure if I understand...or why you might be doing this sort of operation, but you can define the matrix dimensions (ncol and nrow) using the length of each list. If you're looking to name each row/column with the corresponding base, you can use dimnames.

seq1 = "GCATGCT"
seq2 = "GATTACA"

s1string <- strsplit(seq1, "")[[1]]
s2string <- strsplit(seq2, "")[[1]]

matrix(data = 0, nrow = length(s1string), ncol = length(s2string), dimnames = list(s1string,s2string))
ADD COMMENTlink modified 11 months ago by RamRS30k • written 5.3 years ago by ciclistadan30
1
gravatar for Michael Dondrup
5.3 years ago by
Bergen, Norway
Michael Dondrup47k wrote:

You want to assign 7 dimnames to a 8x8 matrix. This is not possible as shown by the error message. You either must assign dimnames of the same length as the matrix dimensions or none at all, this is true for most or all data types. However, for a data.frame you can replace individual dimnames afterwards as shown below. Or you instead simply choose sensible dimnames of length 8, so assign a name to [1,1], say "0", and then

seq1 = "0GCATGCT"
seq2 = "0GATTACA"
s1string <- strsplit(seq1, "")[[1]]
s2string <- strsplit(seq2, "")[[1]]

Otherwise something is wrong with your problem definition.

x = data.frame(matrix(0,ncol=8, nrow=8))
x
  X1 X2 X3 X4 X5 X6 X7 X8
1  0  0  0  0  0  0  0  0
2  0  0  0  0  0  0  0  0
3  0  0  0  0  0  0  0  0
4  0  0  0  0  0  0  0  0
5  0  0  0  0  0  0  0  0
6  0  0  0  0  0  0  0  0
7  0  0  0  0  0  0  0  0
8  0  0  0  0  0  0  0  0 

colnames(x)[2:3] <- c('A','B')
rownames(x)[2:3] <- c('A','B')

x
  X1 A B X4 X5 X6 X7 X8
1  0 0 0  0  0  0  0  0
A  0 0 0  0  0  0  0  0
B  0 0 0  0  0  0  0  0
4  0 0 0  0  0  0  0  0
5  0 0 0  0  0  0  0  0
6  0 0 0  0  0  0  0  0
7  0 0 0  0  0  0  0  0
8  0 0 0  0  0  0  0  0
ADD COMMENTlink modified 11 months ago by RamRS30k • written 5.3 years ago by Michael Dondrup47k
0
gravatar for Antonio R. Franco
5.3 years ago by
Spain. Universidad de Córdoba
Antonio R. Franco4.5k wrote:

if you matrix is named matrix, you can define colnames(matrix) and rownames(matrix)

colnames(matrix) <- strplit(seq1, "")[[1]]
ADD COMMENTlink written 5.3 years ago by Antonio R. Franco4.5k

I try it but programme give error:

Error in dimnames(x) <- dn : 
  length of 'dimnames' [2] not equal to array extent
ADD REPLYlink modified 10 months ago by RamRS30k • written 5.3 years ago by gizemtatar0
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1158 users visited in the last hour