0

I got an table "countdata"

    /share/Data01/zhangxi/workspace/Bioinformatics_Data/RNA_seq_program/01_4_DESeq2_analysis/B18-N.sorted.bam /share/Data01/zhangxi/workspace/Bioinformatics_Data/RNA_seq_program/01_4_DESeq2_analysis/B18-CA.sorted.bam
ENSG00000223972             0            0
ENSG00000227232           413          196
ENSG00000243485             0            0
ENSG00000237613             0            0
ENSG00000268020             0            0
ENSG00000240361             0            0

I did it with R.

colnames(countdata) <- gsub("((?:[^/]*/)*)", "", colnames(countdata))
colnames(countdata) <- gsub("\\.[sb]am$", "", colnames(countdata))

#change it into this
                B18-CA.sorted B18-N.sorted
ENSG00000223972             0            0
ENSG00000227232           413          196
ENSG00000243485             0            0
ENSG00000237613             0            0
ENSG00000268020             0            0
ENSG00000240361             0            0

How could I change the table in one line?

colnames(countdata) <- gsub(Regular_Expression, "", colnames(countdata))
zx8754
  • 52,746
  • 12
  • 114
  • 209

1 Answers1

2

Maybe you can try:

sub("\\.bam", "", basename(colnames(countdata)))

basename permits to retrieve what is after the last / in a path.

Cath
  • 23,906
  • 5
  • 52
  • 86
  • the R script came out error. "invalid class "SummarizedExperiment0" object: 'assays' ncol differs from 'colData' nrow" – user6903386 Sep 30 '16 at 08:27
  • 1
    @user6903386 what exactly is "SummarizedExperiment0". We are probably missing some elements because with what you posted, it works... please provide more details – Cath Sep 30 '16 at 08:30
  • My script is like this:countdata <- countdata[ ,6:ncol(countdata)] colnames(countdata) <- gsub("((?:[^/]*/)*)", "", colnames(countdata)) colnames(countdata) <- gsub("\\.[sb]am$", "", colnames(countdata)) countdata <- as.matrix(countdata) head(countdata) (condition <- factor(c(rep("cancel", 1), rep("normal", 1)))) – user6903386 Sep 30 '16 at 08:40
  • @user6903386 try my line of code just after the first step : my line is supposed to replace the `gsub` steps... – Cath Sep 30 '16 at 08:50