Skip to content

Commit 3cb6cf5

Browse files
authored
Add files via upload
1 parent 054c01e commit 3cb6cf5

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

R/AutoSmCCNet.R

+18-5
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,11 @@ fastAutoSmCCNet <- function(X, Y, AdjustedCovar = NULL, preprocess = FALSE, Kfol
329329
cat("--------------------------------------------------\n")
330330
cat("\n")
331331
AllComb <- utils::combn(length(X), 2)
332+
DataTypePheno <- c(DataType, 'Phenotype')
332333
ScalingFactor <- rep(0, ncol(AllComb))
334+
names(ScalingFactor) <- apply(AllComb,2, function(x){
335+
paste0(DataTypePheno[x[1]],'-',DataTypePheno[x[2]])
336+
})
333337
for (i in 1:ncol(AllComb))
334338
{
335339
# define the pair of matrices
@@ -353,6 +357,10 @@ fastAutoSmCCNet <- function(X, Y, AdjustedCovar = NULL, preprocess = FALSE, Kfol
353357
CombPheno <- utils::combn(length(X) + 1,2)
354358
NonPhenoIndex <- apply(CombPheno, 2, function(x){x[2] != (length(X) + 1)})
355359
ScalingFactorTemp <- rep(1, ncol(CombPheno))
360+
DataTypePheno <- c(DataType, 'Phenotype')
361+
names(ScalingFactorTemp) <- apply(CombPheno,2, function(x){
362+
paste0(DataTypePheno[x[1]],'-',DataTypePheno[x[2]])
363+
})
356364
ScalingFactorTemp[NonPhenoIndex] <- ScalingFactor
357365
ScalingFactor <- ScalingFactorTemp
358366
# if multi-omics PLS is used
@@ -362,7 +370,12 @@ fastAutoSmCCNet <- function(X, Y, AdjustedCovar = NULL, preprocess = FALSE, Kfol
362370
}
363371

364372
cat("\n")
365-
cat('The scaling factor selection is: ', ScalingFactor, '\n')
373+
cat('The scaling factor selection is: ', '\n')
374+
cat("\n")
375+
for (i in 1:length(ScalingFactor))
376+
{
377+
cat(paste0(names(ScalingFactor)[i],": ", ScalingFactor[i]), '\n')
378+
}
366379

367380
} else{
368381
cat('single omics analysis, skip scaling factor.', '\n')
@@ -642,7 +655,7 @@ fastAutoSmCCNet <- function(X, Y, AdjustedCovar = NULL, preprocess = FALSE, Kfol
642655
cat(paste0('\n'))
643656
for (xx in 1:length(BestPen))
644657
{
645-
cat(paste0('The best penalty term for omics ', xx, ' after ', Kfold,'-fold cross-validation is: ', BestPen[xx]), '\n')
658+
cat(paste0('The best penalty term for ', DataType[xx], ' after ', Kfold,'-fold cross-validation is: ', BestPen[xx]), '\n')
646659
}
647660
cat(paste0('with testing ', EvalMethod,' score = ', round(AggregatedCVResult$TestMetric[which.max(AggregatedCVResult$TestMetric)],3)), '\n')
648661
cat('Now running single-omics PLS with best penalty term on the complete dataset.', '\n')
@@ -702,7 +715,7 @@ fastAutoSmCCNet <- function(X, Y, AdjustedCovar = NULL, preprocess = FALSE, Kfol
702715
cat(paste0('\n'))
703716
for (xx in 1:length(BestPen))
704717
{
705-
cat(paste0('The best penalty term for omics ', xx, ' after ', Kfold,'-fold cross-validation is: ', BestPen[xx]), '\n')
718+
cat(paste0('The best penalty term for ', DataType[xx], ' after ', Kfold,'-fold cross-validation is: ', BestPen[xx]), '\n')
706719
}
707720
cat(paste0('with testing canonical correlation = ', round(AggregatedCVResult$RhoTest[which.min(EvalMetric)],3),
708721
', and prediction error = ', round(AggregatedCVResult$DeltaCor[which.min(EvalMetric)],3)), '\n')
@@ -880,7 +893,7 @@ fastAutoSmCCNet <- function(X, Y, AdjustedCovar = NULL, preprocess = FALSE, Kfol
880893
cat('\n')
881894
for (xx in 1:length(X))
882895
{
883-
cat(paste0('The best penalty term for omics ', xx, ' after ', Kfold,'-fold cross-validation is: ', BestPen[xx]), '\n')
896+
cat(paste0('The best penalty term for ', DataType[xx], ' after ', Kfold,'-fold cross-validation is: ', BestPen[xx]), '\n')
884897
}
885898
cat(paste0('and the best penalty term on classifier is: ', BestPen[length(X) + 1], '\n'))
886899
cat(paste0('with testing ', EvalMethod,' score = ', round(AggregatedCVResult$TestMetric[which.max(AggregatedCVResult$TestMetric)],3)), '\n')
@@ -1018,7 +1031,7 @@ fastAutoSmCCNet <- function(X, Y, AdjustedCovar = NULL, preprocess = FALSE, Kfol
10181031
cat("\n")
10191032
cat("3. To prevent overwriting result files across projects, rename the result file after each run.\n")
10201033
cat("\n")
1021-
cat("4. Subnetwork visualization can be done through shinyApp or cytoscape, please refer to network visualization section in multi-omics or single-omics vignette for more detail.\n")
1034+
cat("4. Subnetwork visualization can be done through shinyApp or cytoscape. Please refer to the network visualization section in the multi-omics or single-omics vignette for more detail. For the Shiny app, visit: https://smccnet.shinyapps.io/smccnetnetwork/\n")
10221035
cat("\n")
10231036
cat("************************************\n")
10241037
return(list(AdjacencyMatrix = Abar, Data = X, ClusteringModules = OmicsModule, CVResult = AggregatedCVResult))

R/SmCCNet-source.R

+15-8
Original file line numberDiff line numberDiff line change
@@ -755,33 +755,40 @@ getRobustWeightsMultiBinary <- function(X, Y, Between_Discriminate_Ratio = c(1,1
755755
# subset selected features
756756
X_subset <- X_all[ ,which(BetweenOmicsWeight[,iii] != 0)]
757757
# run omics-phenotype SmCCA based on selected molecular features
758-
Ws_pheno <- getRobustWeightsSingleBinary(X1 = X_subset, Trait = matrix(Y, ncol = 1), Lambda1 = as.numeric(eta),
758+
Ws_pheno <- getRobustWeightsSingleBinary(X1 = X_subset, Trait = matrix(Y, ncol = 1), Lambda1 = as.numeric(eta),
759759
s1 = 1, SubsamplingNum = 1, K = ncomp_pls)
760-
# store omics-phenotype canonical weight
761-
OmicsPhenoWeight[which(BetweenOmicsWeight[,iii] != 0),iii] <- as.numeric(Ws_pheno)
760+
# store omics-phenotype canonical weight
761+
OmicsPhenoWeight[which(BetweenOmicsWeight[,iii] != 0),iii] <- as.numeric(Ws_pheno)
762762

763763

764764

765765

766766
# normalize each data type
767767
for (j in 1:length(X))
768768
{
769-
OmicsPhenoWeight[which(type_index == j),iii] <- OmicsPhenoWeight[which(type_index == j),iii]/pracma::Norm(OmicsPhenoWeight[which(type_index == j),iii])
769+
if (pracma::Norm(OmicsPhenoWeight[which(type_index == j),iii]) != 0)
770+
{
771+
OmicsPhenoWeight[which(type_index == j),iii] <- OmicsPhenoWeight[which(type_index == j),iii]/pracma::Norm(OmicsPhenoWeight[which(type_index == j),iii])
772+
}
770773
}
771774

772775

773776
}
774777

775778
# set part of the between-omics weight to 0
776-
BetweenOmicsWeight[OmicsPhenoWeight == 0] <- 0
779+
BetweenOmicsWeight[as.vector(OmicsPhenoWeight == 0)] <- 0
777780
# remove all zero columns
778781
if (SubsamplingNum > 1)
779782
{
780783
# find zero columns and NAN columns
781784
zero_cols <- which(apply(OmicsPhenoWeight, 2, function(x) all(x == 0) | any(is.nan(x))))
782-
# remove all these columns
783-
BetweenOmicsWeight <- BetweenOmicsWeight[,-zero_cols]
784-
OmicsPhenoWeight <- OmicsPhenoWeight[,-zero_cols]
785+
if(length(zero_cols)!=0)
786+
{
787+
# remove all these columns
788+
BetweenOmicsWeight <- BetweenOmicsWeight[,-zero_cols]
789+
OmicsPhenoWeight <- OmicsPhenoWeight[,-zero_cols]
790+
}
791+
785792
}
786793
# aggregate canonical weight (trade-off: between-omics, omics-phenotype)
787794
CCWeight <- (Between_Discriminate_Ratio[1]/sum(Between_Discriminate_Ratio)) * BetweenOmicsWeight +

0 commit comments

Comments
 (0)