Challenges of Affymetrix probe IDs for grouping similar genes to calculate their mean

I have an expression matrix with gene probes in rows and GEO samples in columns, on the other hand I have an annotation file of these probes with their symbols. Some symbols are duplicated, that means some symbols may have more than one probe, I want to consider all of them in one group and average them all, moreover some symbols are combined symbols and separated by slashes, but there may be symbols on their own on other lines, e.g. CARD16///CASP1, in one row is CARD16///CASP1, in another row CARD16 and in another CASP1, I want to consider them all in one group and calculate their average. Another issue is that some symbols are combined symbols and separated by a slash like the previous issue I said, but may differ by just one symbol like this: LOC101930400///AKR1C2 and LOC101930400///AKR1C2///AKR1C1, I also want to consider these two as a group and calculate the average, some of them are the same as before but they may have extra symbols e.g. LOC101930343///CATSPER2P1///CATSPER2 and LOC101930343///STRC///CATSPER2 or (DUX4L24///DBET///LOC100291626///DUX4///LOC100288289///DUX4L2///DUX4L3///DUX4L5///DUX4L6///DUX4L7///LOC652301///DUX4L4///DUX4L8///DUX4L1) and (DUX4L24///DBET///LOC100291626///DUX4///LOC100288289///LOC100287823///LOC100133400///DUX4L2///DUX4L3///DUX4L5///DUX4L6///DUX4L7///LOC652301///DUX4L4///DUX4L8///DUX3///DUX4L1), I also want to consider these in a group and calculate the average.

 # Function to create a lookup table mapping each base symbol to its most comprehensive form
create_lookup_table <- function(all_symbols) {
  lookup_table <- list()
  for (symbol in all_symbols) {
    # Split the symbol into parts
    parts <- unlist(strsplit(symbol, "///"))
    # Iterate over each part to update the lookup table
    for (part in parts) {
      # If the part is not already in the lookup table, or if the current symbol is more comprehensive, update the lookup table
      if (!part %in% names(lookup_table) || nchar(symbol) > nchar(lookup_table[[part]])) {
        lookup_table[[part]] <- symbol
      }
    }
  }
  return(lookup_table)
}


# Create a vector of all unique gene symbols from the annotation file
all_symbols <- unique(probe_symbols$Gene.symbol)

# Create the lookup table
lookup_table <- create_lookup_table(all_symbols)

# Map each symbol to the most comprehensive symbol using the lookup table
probe_symbols$Group.Symbol <- sapply(probe_symbols$Gene.symbol, function(symbol) {
  base_symbol <- unlist(strsplit(symbol, "///"))[1]
  return(lookup_table[[base_symbol]])
})

# Merge the expression matrix with the annotation to get group symbols for each probe
merged_data <- merge(probe_symbols, data_no_batch, by.x="ID", by.y="row.names", all.y=TRUE)

# Group by 'Group.Symbol' and calculate the mean expression for each group
library(dplyr)
mean_expression <- merged_data %>%
  group_by(Group.Symbol) %>%
  summarise(across(starts_with("GSM"), ~mean(.x, na.rm = TRUE)))

mean_expression <- data.frame(mean_expression)
rownames(mean_expression) <- mean_expression$Group.Symbol
mean_expression2 <- mean_expression[,-1]
#write.table(mean_expression2, file = "D:/GEO/mean-expression.txt", quote = F, sep = "t")
pe here

I ran the above code, it worked correctly in some ways but it did not work well for example it did not consider ACTG1P4///AMY2B///AMY2A///AMY1C///AMY1B///AMY1A
and ACTG1P4///RNPC3///AMY2B or GH1///CSHL1///CSH2///CSH1 and GH2///GH1///CSHL1///CSH1 as one group then computes the mean. How can I solve this and revise my code?

    # Function to create a lookup table mapping each base symbol to its most comprehensive form
create_lookup_table <- function(all_symbols) {
  lookup_table <- list()
  for (symbol in all_symbols) {
    # Split the symbol into parts
    parts <- unlist(strsplit(symbol, "///"))
    # Iterate over each part to update the lookup table
    for (part in parts) {
      # If the part is not already in the lookup table, or if the current symbol is more comprehensive, update the lookup table
      if (!part %in% names(lookup_table) || nchar(symbol) > nchar(lookup_table[[part]])) {
        lookup_table[[part]] <- symbol
      }
    }
  }
  return(lookup_table)
}


# Create a vector of all unique gene symbols from the annotation file
all_symbols <- unique(probe_symbols$Gene.symbol)

# Create the lookup table
lookup_table <- create_lookup_table(all_symbols)

# Map each symbol to the most comprehensive symbol using the lookup table
probe_symbols$Group.Symbol <- sapply(probe_symbols$Gene.symbol, function(symbol) {
  base_symbol <- unlist(strsplit(symbol, "///"))[1]
  return(lookup_table[[base_symbol]])
})

# Merge the expression matrix with the annotation to get group symbols for each probe
merged_data <- merge(probe_symbols, data_no_batch, by.x="ID", by.y="row.names", all.y=TRUE)

# Group by 'Group.Symbol' and calculate the mean expression for each group
library(dplyr)
mean_expression <- merged_data %>%
  group_by(Group.Symbol) %>%
  summarise(across(starts_with("GSM"), ~mean(.x, na.rm = TRUE)))

mean_expression <- data.frame(mean_expression)
rownames(mean_expression) <- mean_expression$Group.Symbol
mean_expression2 <- mean_expression[,-1]
#write.table(mean_expression2, file = "D:/GEO/mean-expression.txt", quote = F, sep = "t")
pe here

I ran the above code, it worked correctly in some ways but it did not work well for example it did not consider ACTG1P4///AMY2B///AMY2A///AMY1C///AMY1B///AMY1A
and ACTG1P4///RNPC3///AMY2B or GH1///CSHL1///CSH2///CSH1 and GH2///GH1///CSHL1///CSH1 as one group then computes the mean. How can I solve this and revise my code?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật