This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Gene expression file to Expression matrix

Hi All,

I have an RNAseq gene expression file (Count data) as follows, I need to conduct a Differential gene expression analysis between Patients, for that, I need to have this file as a Matrix of Rows as Genes and columns as counts (samples), how best can I get this as matrix file?

Thanks a lot for your help, Stay safe

Dave

like this

rna-seq

You'll need to use something like tidyr::pivot_wider() to get patient_id to columns and retain gene_code as rows. You'll end up picking one of gene_raw/gene_tpm as the values.

Thanks a lot, RamRS, it's such a great help. Going forward, I have tried your solution and used the following code

bulk_clean<- tidyr::pivot_wider(bulk,id_cols=patient_id,gene_code)

but i m not getting the desired output, please let me know where i am going wrong. thanks again.

What is the output you're getting? Also, please give us the output to: dput(head(bulk, 25)).

Thanks you RamRS will keep that in mind.

1 answer

 library(tidyverse)
 your_data %>%
 select(patient_id, gene_code, gene_raw) %>%
 pivot_wider(names_from = patient_id, 
          values_from = gene_raw)

Switch gene_raw to some other expression value if you need.

Thanks a lot, It worked like a charm

Log in to answer this question.