I've got the following table with expression data for some genes:
> exp_table
exp
PITG_00005b 0.16442671
PITG_00005a 0.94545358
PITG_00004 0.86324023
PITG_00003 0.04110668
PITG_00002 1.10988029
MERGED:PITG_23067_PITG_23068_PITG_16110 34.11854242
MERGED:PITG_23017_PITG_23018 0.00000000
What I'm trying to do is to clean this table up, so that gene names are split as with the following code I used for other purposes:
> exp_names <- gsub("[a-e]", "", rownames(exp_table))
> exp_names <- gsub("MERGED:", "", exp_names)
> exp_names <- strtrim(unlist(strsplit(exp_names, "(?<=[0-9]_)", perl=TRUE)), 10)
> exp_names
[1] "PITG_00005" "PITG_00005" "PITG_00004" "PITG_00003" "PITG_00002" "PITG_23067"
[7] "PITG_23068" "PITG_16110" "PITG_23017" "PITG_23018"
i.e., in the data frame I need:
if there is an additional letter at the end of the gene (a or b) it should be removed and all gene 'copies' should be assigned an average expression level (here, both 'copies' of PITG_00005 should be assigned exp = (0.16442671 + 0.94545358)/2),
all the genes that were previously merged should have the same expression level assigned (i.e., 34.11854242 for all of "PITG_23067", "PITG_23068", "PITG_16110").
I would appreciate any suggestions!