Can not rename row names of the taxonomy table and ASV-table

Hi,

I exported the taxonomy table (sequences as rownames, and columns are the taxonomy (kingdom,phylum,...Species)), and ASV_table where sampleID are the rownames and column headers are ASV sequences. So, I need to rename the rownames of the taxonomy table to ASV1,2,3,.....n, and rename the colnames in the ASV-table to ASV1,2,3. Also, I need to assure that the assigned ASVs in each table are corresponding to the same sequences as a primary key that could be used to merge them together.
What I did as follows:

st.nochim = readRDS("st.nochim.rds") #ASV table
tax = readRDS("tax_Silva138.rds") #taxonomy table

#first manipulating the taxonomy table
t

axa_df <- data.frame(tax) #displayed the sequences as rownames and 7 columns of taxonomy, so did not count the rownames as the first column.

x <- taxa_df[,1, drop=FALSE] #saved the first column which is the rownames in a vector.
x1 <- data.frame(x) #convert it into a dataframe
x1$Kingdom <- gsub("Bacteria", "", as.character(x1$Kingdom)) #remove the word bacteria that attached to the sequence, 
names(x1) <- NULL # remove the column name kingdom
colnames(x1)[1] <- "sequences" #rename the column with sequences
new_taxa <- cbind(x1,taxa_df) #merge the 2 dataframes
new_df <- subset(new_taxa, select = -c(sequences)) #drop the column sequences, so I have the sequences (rownames as the first column now)
new_df1 <- cbind(Sequences = rownames(new_df), new_df) #to add sequences as a column, so I have now 8 columns. NOw I have sequences as 2 columns; the first does not have a header and will be removed in the next step, and the second with a header (sequences)
rownames(new_df1) <- NULL #to remove the rownames which contain sequences. Now I have a datframe of 8 columns, the first includes sequences

#then rename the sequences as ASV1,2,... and export the the dataframe as an excel sheet

new_df1.export <- new_df1
rownames(new_df1.export) <- paste0("ASV", seq(nrow(new_df1)))
write_xlsx(new_df1.export,"/home/tax_table.xlsx")

when I opened the file I found the sequences column empty, any explanation please?

The second table ASV-table
#sequences names were used as sampleIDs, so I extracted the sampleID from sequences names as follows

samples.out <- rownames(st.nochim) 
names <- sapply(strsplit(samples.out, "reverse."), `[`, 2)
names <- sapply(strsplit(names, "_"), function(x) paste(x[1]))
names

#Then

row.names(st.nochim) <- names #add the extracted sampleIDs as rownames 
st_df <- data.frame(st.nochim) #convert it to a dataframe
y <- colnames(st_df) #store the columnames (sequences) in a vector
st.nochim.export <- st.nochim
colnames(st.nochim.export) <- paste0("ASV", seq(ncol(st.nochim))) #replace the columnames (sequences) by  ASV1,2,3,...
y2 <- colnames(st.nochim.export) #extract the new columnnames in a vector

asv_names <- cbind(y,y2)# bind 2 vectors for my records
st.nochim.export_df <- data.frame(st.nochim.export) #convert into a dataframe
ASV_table <- t(st.nochim.export_df) #transpose dataframe to get the required format
write_xlsx(ASV_table_df,"/home/ASV_table.xlsx") #export table

same problem, the ASVs column (rownames) is not available.
Need your help, please!
Thanks

Without these pieces it's hard to attract answers, which is why a reprex (See the FAQ: How to do a minimal reproducible example reprex for beginners ) is so helpful.

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.