cant make the correct matrix
0
0
Entering edit mode
3 days ago
Naila • 0

Hi what I wanted to do is have the different Wong conditions (14) along the top and then inset the log fold values underneath. I also have joined the GS(gene symbols) from both data sets. Its not working and I don't know why, please can anyone help?

library(readr)
library(dplyr)
library(readxl)

# 1. Load the Reshaped CSV (renamed)
file_path <- "C:/Users/ns01288/Documents/tarney_wong_joined_logfc_renamed.csv"

tryCatch({
  tarney_df <- read_csv(file_path)
}, error = function(e) {
  stop(paste("Error reading renamed CSV file:", e))
})

# 2. Load the Wong Excel Data
excel_path <- "C:/Users/ns01288/OneDrive - University of Surrey/data using disertation/Total_Proteome_wong_et_al_Tarney_et_al.xlsx"
tryCatch({
  wong_df <- read_excel(excel_path, sheet = "Wong_et_al_Total_Proteome")
}, error = function(e) {
  stop(paste("Error reading Wong Excel file:", e))
})

# 3. Join Based on Gene (GS)
combined_df <- tarney_df %>%
  left_join(wong_df, by = "GS", suffix = c(".tarney", ".wong"))

# 4. Replace Tarney "n/a" with Wong Data
for (col in colnames(wong_df)[-1]) { # Iterate over Wong condition columns
  combined_df$TP_Tarney_et_al_logFC_LGSOCvsTube <- ifelse(
    combined_df$TP_Tarney_et_al_logFC_LGSOCvsTube == "n/a",
    combined_df[[paste0(col, ".wong")]],
    combined_df$TP_Tarney_et_al_logFC_LGSOCvsTube
  )
}

# 5. Select the desired columns, keeping Tarney data separate, and adding Wong data as extra columns.
final_df <- combined_df %>%
  select(GS, TP_Tarney_et_al_logFC_LGSOCvsTube, colnames(wong_df)[-1])

# 6. Write to CSV
new_file_path <- "C:/Users/ns01288/Documents/tarney_wong_joined_logfc_combined_renamed.csv"

tryCatch({
  write_csv(final_df, new_file_path)
  print(paste("Combined renamed data saved to:", new_file_path))
}, error = function(e) {
  stop(paste("Error writing CSV file:", e))
})
logfc csv • 189 views
ADD COMMENT
0
Entering edit mode

This what the csv file look like

GS,TP_Tarney_et_al_logFC_LGSOCvsTube,P.Value,Condition,LogFC
TEKT4,-2.41971357329783,6.62226226973183e-23,TP_Tarney_et_al_logFC_LGSOCvsTube,n/a
CROCC,-2.66099126705531,5.49767753170685e-23,TP_Tarney_et_al_logFC_LGSOCvsTube,n/a
LRRC23,-2.2327989494761,5.1904022851442096e-23,TP_Tarney_et_al_logFC_LGSOCvsTube,n/a
MLF1,-3.22793465818543,1.74355676260876e-22,TP_Tarney_et_al_logFC_LGSOCvsTube,n/a
SAXO2,-2.58097353155963,2.4798723472614e-22,TP_Tarney_et_al_logFC_LGSOCvsTube,n/a
CCDC151,-2.03191540707386,4.591232655773119e-22,TP_Tarney_et_al_logFC_LGSOCvsTube,n/a
SPATA18,-3.29617575891952,4.27286292136911e-22,Wong_et_al_TP_LGS125,2.859113845
SPATA18,-3.29617575891952,4.27286292136911e-22,Wong_et_al_TP_LGS111,1.532280638
SPATA18,-3.29617575891952,4.27286292136911e-22,Wong_et_al_TP_LGS127,-0.309651611
SPATA18,-3.29617575891952,4.27286292136911e-22,Wong_et_al_TP_LGS128,0.98624338
SPATA18,-3.29617575891952,4.27286292136911e-22,Wong_et_al_TP_LGS131,-1.181272098
SPATA18,-3.29617575891952,4.27286292136911e-22,Wong_et_al_TP_LGS107,3.028579858
SPATA18,-3.29617575891952,4.27286292136911e-22,Wong_et_al_TP_LGS108,0.708143704
SPATA18,-3.29617575891952,4.27286292136911e-22,Wong_et_al_TP_LGS101,-0.071148176
SPATA18,-3.29617575891952,4.27286292136911e-22,Wong_et_al_TP_LGS102,3.985737209
SPATA18,-3.29617575891952,4.27286292136911e-22,Wong_et_al_TP_LGS124,0.854255966
SPATA18,-3.29617575891952,4.27286292136911e-22,Wong_et_al_TP_LGS112,-0.611766988
SPATA18,-3.29617575891952,4.27286292136911e-22,Wong_et_al_TP_LGS126,-0.071788177
SPATA18,-3.29617575891952,4.27286292136911e-22,Wong_et_al_TP_LGS129,-1.036444137
SPATA18,-3.29617575891952,4.27286292136911e-22,Wong_et_al_TP_LGS130,-1.537097187
PPIL6,-2.76725897798818,3.27818933774816e-21,TP_Tarney_et_al_logFC_LGSOCvsTube,n/a
DNAH5,-2.52604086722928,3.10253619210591e-21,TP_Tarney_et_al_logFC_LGSOCvsTube,n/a
NME9,-2.54366451539634,5.72277545273211e-21,TP_Tarney_et_al_logFC_LGSOCvsTube,n/a
DNAH10,-2.18361481080545,7.124127398613081e-21,TP_Tarney_et_al_logFC_LGSOCvsTube,n/a
DNAJB13,-2.83710896885775,1.8594797214691098e-20,TP_Tarney_et_al_logFC_LGSOCvsTube,n/a
CEP290,-1.63479465750911,3.24150063938857e-20,TP_Tarney_et_al_logFC_LGSOCvsTube,n/a
DNAL4,-2.79400938444549,3.05058907305361e-20,TP_Tarney_et_al_logFC_LGSOCvsTube,n/a
TTC25,-2.80076368835513,5.6734199770388e-20,TP_Tarney_et_al_logFC_LGSOCvsTube,n/a
DNAJB6,-3.38523506903658,6.21406234130094e-20,TP_Tarney_et_al_logFC_LGSOCvsTube,n/a
ANXA13,-3.22816722379914,9.11272863189027e-20,TP_Tarney_et_al_logFC_LGSOCvsTube,n/a
MNS1,-2.57032863700874,1.3014055533548798e-19,TP_Tarney_et_al_logFC_LGSOCvsTube,n/a
EFHC1,-2.64734609947182,2.14949888489187e-19,TP_Tarney_et_al_logFC_LGSOCvsTube,n/a
CCDC114,-2.45000111714511,2.64933705989881e-19,TP_Tarney_et_al_logFC_LGSOCvsTube,n/a
CFAP77,-2.56787026946101,2.60212136947899e-19,TP_Tarney_et_al_logFC_LGSOCvsTube,n/a
TSGA10,-2.33275051555735,2.85209789258633e-19,TP_Tarney_et_al_logFC_LGSOCvsTube,n/a
DNAH9,-2.38882878955434,3.1745930062973895e-19,TP_Tarney_et_al_logFC_LGSOCvsTube,n/a
TEKT3,-2.64568802738241,4.51662675613301e-19,TP_Tarney_et_al_logFC_LGSOCvsTube,n/a
MYCBPAP,-2.31479016185772,4.5143912776122495e-19,TP_Tarney_et_al_logFC_LGSOCvsTube,n/a
ADD REPLY

Login before adding your answer.

Traffic: 1694 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6