Robust <- function(geneid, agreemat, nmethods) { #MAKE LIST n = dim(agreemat) n = n[1] plist = matrix(0,0,0) plistsize=0; for (i in 1:(n-1)) { for (j in (i+1):n) { if (agreemat[i,j]==nmethods) { plistsize = plistsize+1 plist = matrix(c(plist,i,j),2,plistsize) } } } # print(geneid) #FORM ROBUST CLUSTERS RC = list() plistsize = (dim(plist)) plistsize = plistsize[2] if (plistsize>0) { newRC = list(c(geneid[plist[1,1]], geneid[plist[2,1]])) #list(c(plist[1,1], plist[2,1])) RC = c(RC,newRC) # print("Add newRC") # print(newRC) } if (plistsize>0) { for (y in 1:plistsize) { var1 = geneid[plist[1,y]] #plist[1,y] var2 = geneid[plist[2,y]] #plist[2,y] #Search the groups for either of the pair newvar=-1 xmax = length(RC) for (x in 1:xmax) { zmax = length(RC[[x]]) for (z in 1:zmax) { if (var1==RC[[x]][z]) { newvar=var2 gp=x # print(c(var1, "is found")) break } if (var2==RC[[x]][z]) { newvar=var1 gp=x # print(c(var2, "is found")) break } } } if (newvar>-1) #One of the Pair is Found { #Check the other of the pair is not in the group found=0 xmax=length(RC) for (x in 1:xmax) { zmax=length(RC[[x]]) for (z in 1:zmax) { if (RC[[x]][z]==newvar) { found=1 # print(c("but", newvar, "also found")) break } } } if (found==0) { RC[[gp]] = c(RC[[gp]],newvar) # print("Add to existing RC") # print(newvar) } } else { newRC = list(c(var1,var2)) RC = c(RC,newRC) # print("Add newRC") # print(c(var1,var2)) } # print(RC) } } # print(RC) Robust = RC }