library(simpIntLists)
library(data.table)

setwd("C:/Users/thood/Documents/R/TCGA")

data("HumanBioGRIDInteractionOfficial")


#set up the call to find the interactions
interactions <- findInteractionList("human", "Official")

#list of genes
genes <- read.csv("genenamesPadj001_recurrent_fusions_vs_normal_gene_names_for_interactions.csv", header=FALSE)

#get the list of interactors
test <- lapply(interactions , "[[" , "name" )

#make a data frame
df <- as.data.frame(unlist(test))

#write that data frame 
#write.csv(df, "all_fusions_vs_non_interactors_001.csv")

#find the indices
indices <- which(df$`unlist(test)`%in% genes$V1)

inter <-data.frame()

#create a for loop to pull out what i want
# for (i in 1:length(indices)) {
#   # print(indices[i])
#   x[i] <- interactions[[indices[i]]]$name
#   y[i] <- list(interactions[[indices[i]]]$interactors)
#   
# 
# }
# 
# #bind them together
# inter<- cbind(x, y)
# 
# write.csv(inter, "my_interactions.csv")


my_inter <- data.frame()

for (i in 1:length(indices)) {

    # print(indices[i])
    x <- interactions[[indices[i]]]$name
    y <- interactions[[indices[i]]]$interactors

    inter <- cbind("name"=x,"interactors"=y)
    
    my_inter <- rbind(my_inter, inter)
  

}

write.csv(my_inter, "recurrent_vs_normal_interactions_9820.csv")



# test2 <- lapply(interactions, `[`, c('name', 'interactors'))
