1
$\begingroup$

I am having a problem in getting all the combinations from my dataset. I need your suggestions and guidance in doing so.

I have a file, whose first column contains the regions and other file five column represents if a binding event takes place or not.

Region  TF1 TF2 TF3 TF4 TF5
Reg1    8   0   4   9   11
Reg2    2   0   0   4   0
Reg3    0   8   9   0   3
Reg4    6   82  8   0   4 

Here the most prevalent combination is of TF1,TF3,TF4, TF5 & TF1, TF2, TF3, TF5. .

I have a file of 1700 regions (rows) and 25 binding events(columns).

How can I get near to my desired result with some associated score for each combination.

Thank you.

$\endgroup$
  • $\begingroup$ This question appears to be off-topic because it is about programming. $\endgroup$ – whuber Feb 27 '14 at 21:31
3
$\begingroup$

The data:

dat <- read.table(text="Region  TF1 TF2 TF3 TF4 TF5
Reg1    8   0   4   9   11
Reg2    2   0   0   4   0
Reg3    0   8   9   0   3
Reg4    6   82  8   0   4", header = TRUE)

The following commands can be used to obtain the frequencies of the unique combinations of bindings:

tab <- table(apply(dat[ , -1] != 0, 1, paste, collapse = "."))

as.data.frame(setNames(tab, lapply(names(tab), function(x)
           paste(names(dat)[-1][as.logical(strsplit(x, "\\.")[[1]])], collapse = ", "))))

The output:

                Var1 Freq
1      TF2, TF3, TF5    1
2           TF1, TF4    1
3 TF1, TF3, TF4, TF5    1
4 TF1, TF2, TF3, TF5    1
| cite | improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ Is it possible to associate the combination with any sort of scoring or p-value or z-score? $\endgroup$ – Angelo Nov 26 '12 at 13:37
  • 1
    $\begingroup$ @Angelo Yes, the combinations could be associated with any other information. You should provide an example. $\endgroup$ – Sven Hohenstein Nov 26 '12 at 13:39
  • 1
    $\begingroup$ Sorry, I figured it out. Secondly how can I direct the output to a file? Thank you in advance $\endgroup$ – Angelo Nov 26 '12 at 16:09
  • 1
    $\begingroup$ I did store the result in a variable for example in "result" Now how can I transfer the data stored in this variable to an excel file :( $\endgroup$ – Angelo Nov 26 '12 at 16:11
  • 1
    $\begingroup$ @Angelo write.csv2(result, row.names = FALSE, file = "filename.csv") $\endgroup$ – Sven Hohenstein Nov 26 '12 at 16:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.