Remove X in row name with only number
0
0
Entering edit mode
9 months ago
Chris ▴ 340

Hi Biostars,

I follow this tutorial to perform GSVA: https://alexslemonade.github.io/refinebio-examples/02-microarray/pathway-analysis_microarray_03_gsva.html

They can create a matrix name filtered_mapped_matrix with row names are only number. I convert my column EntrezID to row name and got X before EntrezID, so I would like to remove it. However, this code didn't work.

rownames(your_data) <- gsub("^X", "", rownames(your_data))

Would you please have a suggestion? I can't upload a screenshot here to illustrate as I got this error from Biostar: Exceeded the maximum amount of images you can upload. Thank you so much.

GSVA • 1.1k views
ADD COMMENT
0
Entering edit mode

You don't need to upload the screenshot, you can simply copy-paste the content. Also "code didn't work" is not a sufficient description - was any error message displayed? How did you deduce that the code did not work?

Also, did you check online if rownames can be numeric?

ADD REPLY
0
Entering edit mode

There is no error message and nothing changes with the variable your_data. I can't copy and paste a matrix from Rstudio to here that keep the information in the right format. I read that rownames can't start with number but don't know why the tutorial has rownames are only number.

ADD REPLY
1
Entering edit mode

I can't copy and paste a matrix from Rstudio to here that keep the information in the right format.

Yes, you can. Ensure you're only copy-pasting a limited number of rows and columns (10, say):

matrix(round(rnorm(100),2), nrow=10)
       [,1]  [,2]  [,3]  [,4]  [,5]  [,6]  [,7]  [,8]  [,9] [,10]
 [1,]  1.15 -1.47 -1.37 -1.08 -0.19  0.44 -0.16 -1.42  0.39  1.10
 [2,]  1.85 -0.87  0.32  1.78  2.59 -0.75  0.23 -1.36  2.69  0.33
 [3,]  0.79  0.30  1.78 -0.37 -1.38  0.09  0.94 -0.64 -0.57 -1.29
 [4,] -0.53  1.22  2.12 -0.20 -0.66  1.30  0.40  0.52  0.18  0.20
 [5,]  0.11  0.30 -1.52  0.20 -2.80 -0.33  1.14  1.27  1.09  0.20
 [6,] -1.15 -0.63 -0.54 -1.45 -0.52 -0.81  0.32 -0.71  1.55 -0.64
 [7,]  0.35 -0.46  0.28  0.79 -1.05 -0.84 -0.09  0.74  2.86 -1.57
 [8,]  0.06 -0.24  1.24  2.54  0.96  0.64  0.92 -1.40  0.43  0.21
 [9,]  0.29  0.31  1.29 -0.07  0.17  0.69 -0.62  0.69 -0.45  0.85
[10,] -0.29 -1.41  0.31 -0.09 -0.68 -0.13 -0.37  1.14 -2.58 -0.20

don't know why the tutorial has rownames are only number.

Can you point to where this happens in the tutorial, please? Are you speaking about the tibble::column_to_rownames("entrez_id") in section 4.3? If so, they don't seem to care what happens to the Entrez IDs, so why do you care?

ADD REPLY
0
Entering edit mode

Yes, section 4.3. Variable: filtered_mapped_matrix. Seem they format Entrez_ID as character with allowing number as rowname. The matrix has thousand of columns so I can't use mouse to select first few rows and columns. It will automatically select all column.

ADD REPLY
1
Entering edit mode

I can't use mouse to select first few rows and columns.

What are you trying to do with the mouse? All you gotta do is run your_data[1:10,1:10] on the Console.

Seem they format Entrez_ID as character with allowing number as rowname.

I don't see them doing that, but you could. Try:

filtered_mapped_matrix <- filtered_mapped_df %>% mutate(entrez_id = as.character(entrez_id)) %>%
  # We need to store our gene identifiers as row names
  tibble::column_to_rownames("entrez_id") %>%
  # Now we can convert our object into a matrix
  as.matrix()
ADD REPLY
0
Entering edit mode

Thank you for the suggestion! It turns out that if I use View(your_data), it will show X at the beginning of each rowname but your_data[1:4,1:4] is not. But View(filtered_mapped_matrix), it doesn't show X. Maybe they format Entrez_id as character. Do I need to delete some old images in previous posts to able to upload new images?

       GSM917011  GSM917012  GSM917013  GSM917014
7105   3.861330  3.8247815  5.5487436  3.0800561
64102  0.188879  0.2688151  0.2806487  0.1761636
8813  12.257555 18.8303678 20.3525452 14.8965009
57147  2.074070  3.2011826  3.0844439  2.2441181
ADD REPLY
1
Entering edit mode

Do I need to delete some old images in previous posts to able to upload new images?

I don't know, Maybe Istvan Albert can answer. In any case, you should not be uploading screenshots of plain text content. Read my post on this topic: How to Use Biostars Part-3: Formatting Text and Using GitHub Gists (skip the part on the strikethrough, the rest should help you)

ADD REPLY
0
Entering edit mode

Try to get rowname as chracter but still didn't work

rownames(your_data) <- as.character(rownames(your_data))

The rowname in the tutorial is right align, so it is still number. Anyway the row name doesn't have X, it is only how View() work.

       GSM917011  GSM917012  GSM917013  GSM917014
X7105   3.861330  3.8247815  5.5487436  3.0800561
X64102  0.188879  0.2688151  0.2806487  0.1761636
X8813  12.257555 18.8303678 20.3525452 14.8965009
X57147  2.074070  3.2011826  3.0844439  2.2441181
ADD REPLY
0
Entering edit mode
rownames(your_data) <- as.character(rownames(your_data))

That makes no sense. rownames(your_data) is already a character vector. Are you sure you know what you're doing?

ADD REPLY
0
Entering edit mode

Just trying possible solutions. Seem I trying to remove something doesn't exist. But when using View(), it will show in my case but not in the tutorial.

ADD REPLY
1
Entering edit mode

You've isolated the problem to View on Rstudio. Running any R code on the data.frame is not going to help. I ran the following code on Rstudio and it worked without any prefix so you might actually have a different problem:

mat <- matrix(rnorm(100), nrow=10)
rownames(mat) <- 7001:7010
View(mat)

It showed the matrix with no X prefixes. In my experience, the prefixes are added only on import (which can be avoided using check.names=FALSE), so there is some problem at the file or the file-reader level.

ADD REPLY

Login before adding your answer.

Traffic: 1715 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6