###Recreate your dataframe
df <- data.frame(row.names = c("ENSMUSG00000044719","ENSMUSG00000044591","ENSMUSG00000044712","ENSMUSG00000044734","ENSMUSG00000044726","ENSMUSG00000044724"), "SYMBOL" = c("E230025N22Rik","AC112933.1","Slc38a6","Serpinb1a","BC030476","Gpr152"), "TF" = c(0,0,0,0,0,0), "TF_SOURCE" = c("genomatix_20140512","genomatix_20140512","genomatix_20140512","genomatix_20140513","genomatix_20140513","genomatix_20140513"), "use_as_marker_1" = c(0,0,0,0,0,0), "use_as_marker_2" = c(0,0,0,0,0,0))
TF_list=c("genomatix_20140512")
marker1_list=c("ENSMUSG00000044591","ENSMUSG00000044734","ENSMUSG00000044726")
marker2_list=c("ENSMUSG00000044591","ENSMUSG00000044712","ENSMUSG00000044724")
###Iterate over the number of row (nrow) of your dataframe (from 1 to 6 here)
###In R you can specify a cell with the column name ($column) and the index (i)
###%in% is for exists in
for (i in 1:nrow(df)){
if (df$TF_SOURCE[i] %in% TF_list){
df$TF[i]=1
}
if (row.names(df)[i] %in% marker1_list){
df$use_as_marker_1[i]=1
}
if (row.names(df)[i] %in% marker2_list){
df$use_as_marker_2[i]=1
}
}
EDIT : Without an existing dataframe
genes = c("ENSMUSG00000044719","ENSMUSG00000044591","ENSMUSG00000044712","ENSMUSG00000044734","ENSMUSG00000044726","ENSMUSG00000044724")
df <- data.frame(matrix(ncol = 3, nrow = length(genes)))
row.names(df) <- genes
colnames(df) <- c("TF", "use_as_marker_1", "use_as_marker_2")
TF_list=c("ENSMUSG00000044719","ENSMUSG00000044591","ENSMUSG00000044712")
marker1_list=c("ENSMUSG00000044591","ENSMUSG00000044734","ENSMUSG00000044726")
marker2_list=c("ENSMUSG00000044591","ENSMUSG00000044712","ENSMUSG00000044724")
for (i in 1:nrow(df)){
if (row.names(df)[i] %in% TF_list){
df$TF[i]=1
}else{
df$TF[i]=0
}
if (row.names(df)[i] %in% marker1_list){
df$use_as_marker_1[i]=1
}else{
df$use_as_marker_1[i]=0
}
if (row.names(df)[i] %in% marker2_list){
df$use_as_marker_2[i]=1
}else{
df$use_as_marker_2[i]=0
}
}
It is not completely clear to me how the data you have looks like, and an example often helps.
Thanks a lot, let's say I have a vector of 150 TFs, a vector of 500 marker genes for cluster 1 and a vector of 350 markers genes for cluster. My genome has 14000 validated gene ids. I need a data frame like above in which for TF column my 14000 genes being compared with vector of TFs, 14000 genes being compared with marker genes of cluster 1 and also cluster 2 so that if one of 14000 genes is common with genes in my three vectors I have
1if not not I have0. For example in above data frame ENSMUSG00000044724 is a TF but not marker of clusters, ENSMUSG00000044719 is a marker of cluster 1 and ENSMUSG00000044734 a marker of cluster 2. Unfortunately I am not able to do iteration or anything complex in R without your helpOK, so in fine you have 3 lists (TF, marker1 and marker2). And for each line of your dataframe
if
TF_SOURCEexists in TF list, set upTFcolumn to 1If the
index(gene name?) exists in marker1 list, set upuse_as_marker_1column to 1Same as previous item for marker2
Correct ?
if my TF column exists in TF list
if your TF does not exist in TF list you want to test maker1 and marker2 or to skip them ?
Actually there is not any defined TF in data frame, please ignore TF_SOURCE column
Please, could you provide a complete example of what you want achieve. What do you have in your lists ? Create a small example by hand to describe your problem and your aim.
Seems like you will have to put your 2 lists in 2 vectors then iterate over your dataframe, compare your current TF to your TF vector and compare your current gene to your gene vector and change the TF value if needed.