Skip to content

Commit 75a804c

Browse files
authored
importing annotation
importing annotation from external file Sirius shows a message and give the user the option to choose whether to upload the annotation file or not. #If Y shows selection window for annotation file. if N ignors annotatin process
1 parent 89a40cd commit 75a804c

File tree

1 file changed

+86
-2
lines changed

1 file changed

+86
-2
lines changed

R/DataProcessing.R

+86-2
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,66 @@ readProjectData <- function(fileLines, progress = FALSE)
195195
matrixVals <- as.numeric(unlist(listMatrixVals))
196196
listMatrixRows <- NULL
197197
listMatrixCols <- NULL
198+
199+
################################################################################
200+
#inserted for importing sirius annotation
201+
202+
203+
# Display the message and give the user the option to choose whether to upload the annotation file or not.
204+
#If Y shows selection windo for annotation file. if N ignors annotatin process
205+
message("Do you want to upload the annotation file? (Y/N)")
206+
user_choice <- readline()
207+
208+
if (toupper(user_choice) == "Y") {
209+
# Snippet 1 - Importing Sirius annotation
210+
##############################################################################
211+
#inserted for importing sirius annotation
212+
213+
# Read the canopus_summary file (if needed)
214+
canopus_summary <- read.delim(file.choose(), header = TRUE, check.names = FALSE) # select interactively
215+
216+
217+
218+
# Display the available columns in canopus_summary
219+
message("Available columns in canopus_summary:")
220+
available_columns <- colnames(canopus_summary)
221+
for (i in 1:length(available_columns)) {
222+
message(paste(i, "-", available_columns[i]))
223+
}
224+
225+
# Prompt the user to select the column to use
226+
message("Enter the number corresponding to the column you want to use:")
227+
selected_column_index <- as.integer(readline())
228+
229+
# Check if the selected column index is valid
230+
if (selected_column_index >= 1 && selected_column_index <= length(available_columns)) {
231+
selected_column <- available_columns[selected_column_index]
232+
233+
# Iterate through all values in the "Annotation" column of metaboliteProfile, excluding first row
234+
for (i in 1:nrow(metaboliteProfile)) {
235+
# Perform the lookup based on metaboliteProfile's "Annotation" column and canopus_summary's selected column
236+
matching_indices <- which(canopus_summary$featureId == metaboliteProfile$'Alignment ID'[i])
237+
238+
# Check data types and unique values of featureId column in canopus_summary
239+
240+
# Check if any matches were found
241+
if (length(matching_indices) > 0) {
242+
# Update the specified column (Annotation) in metaboliteProfile with the corresponding value from canopus_summary
243+
metaboliteProfile[i, "Annotation"] <- canopus_summary[matching_indices[1], selected_column]
244+
} else {
245+
# Handle the case where no match was found (you can add custom logic here)
246+
warning(paste("No match found for row", i, "in metaboliteProfile"))
247+
}
248+
}
249+
} else {
250+
message("Invalid column selection. Skipping annotation step.")
251+
}
252+
253+
}
254+
255+
#####################################################################################################################################
256+
#end of inserted for importing sirius annotation
257+
198258
listMatrixVals <- NULL
199259

200260
## header
@@ -251,8 +311,32 @@ readProjectData <- function(fileLines, progress = FALSE)
251311
dataFrameHeader[2, target + 1] <- annotationColorsMapInitValue
252312
dataFrameHeader[3, target + 1] <- annotationColumnName
253313
}
254-
255-
annotationColumnIndex <- which(metaboliteProfileColumnNames == annotationColumnName)
314+
315+
################################################################################
316+
# ###adding HEX color codes from external annotations like Sirius to the annotationColorsMapInitValue of dataFrameHeader
317+
#### asking for adding the annotation. Y activates select and N ignors the adding annotation
318+
# Snippet 2 - Adding HEX color codes from external annotations
319+
if (toupper(user_choice) == "Y") {
320+
##############################################################################
321+
###adding HEX color codes from external annotations like Sirius to the annotationColorsMapInitValue of dataFrameHeader
322+
# Copy the selected column by user, Remove duplicates and exclude the first row
323+
uniqueAnnotations <- unique(unlist(strsplit(metaboliteProfile$Annotation, ",")))
324+
uniqueAnnotations <- paste0(uniqueAnnotations, "=")
325+
# Add a random string from the hex color list to each element of uniqueAnnotions
326+
# strings_list <- c("#000000", "#FFFFFF", "#FF0000", "#00FF00", "#0000FF", "#FFFF00", "#FF00FF", "#00FFFF", "#800000", "#008000", "#000080", "#808000", "#800080", "#008080", "#808080", "#C0C0C0", "#FFA500", "#FFC0CB", "#FFD700", "#A52A2A")
327+
# uniqueAnnotations <- paste0(uniqueAnnotations, sample(strings_list, length(uniqueAnnotations), replace = TRUE))
328+
allowedCols <- c("blue", "red", "yellow", "green", "brown", "deepskyblue", "orange", "deeppink", "aquamarine", "burlywood", "cadetblue", "coral", "cornflowerblue", "cyan", "firebrick", "goldenrod", "indianred", "khaki", "magenta", "maroon", "beige", "moccasin", "olivedrab", "orangered", "orchid", "paleturquoise3", "rosybrown", "salmon", "seagreen3", "skyblue", "steelblue", "#BF360C", "#33691E", "#311B92", "#880E4F", "#1A237E", "#006064", "#004D40", "#FF6F00", "#E65100")
329+
uniqueAnnotations <- paste0(uniqueAnnotations, sample(allowedCols, length(uniqueAnnotations), replace = TRUE))
330+
# Format uniqueAnnotations into a single line with comma-separated values
331+
uniqueAnnotations1 <- paste(uniqueAnnotations, collapse = ", ")
332+
#uniqueAnnotationsHexs <- paste("AnnotationColors={", paste(uniqueAnnotations1, collapse = ","), "}")# this line introduces a space after the first Item of the object, therefore, replaced with the following to remove the space
333+
uniqueAnnotationsHexs <- gsub("AnnotationColors=\\{\\s+", "AnnotationColors={", paste("AnnotationColors={", paste(uniqueAnnotations1, collapse = ","), "}"))
334+
# Assuming dataFrameHeader is your data frame
335+
dataFrameHeader$Annotation[2] <- uniqueAnnotationsHexs
336+
}
337+
###end of adding HEX color codes from external annotations like Sirius to the annotationColorsMapInitValue of dataFrameHeader
338+
339+
annotationColumnIndex <- which(metaboliteProfileColumnNames == annotationColumnName)
256340
annotationColorsValue <- dataFrameHeader[2, annotationColumnIndex]
257341

258342
dataFrameMS1Header <- dataFrameHeader[, seq_len(numberOfMetaboliteProfileColumns)]

0 commit comments

Comments
 (0)