Snippets

Dénes Türei Count number of interactions in TF Regulons

Created by Dénes Türei
#!/usr/bin/Rscript

# Denes Turei 2018
# turei.denes@gmail.com

#
# count number of interactions in TF Regulons
#

require(viper)
require(purrr)
require(dplyr)

download.file(
    paste0(
        'https://github.com/saezlab/DoRothEA/raw/master/data/TFregulons/',
        'Robjects_VIPERformat/consensus/A_viperRegulon.rdata'
    ),
    destfile = 'tfregulons_A.rdata'
)

download.file(
    paste0(
        'https://github.com/saezlab/DoRothEA/raw/master/data/TFregulons/',
        'Robjects_VIPERformat/consensus/B_viperRegulon.rdata'
    ),
    destfile = 'tfregulons_B.rdata'
)

download.file(
    paste0(
        'https://github.com/saezlab/DoRothEA/raw/master/data/TFregulons/',
        'Robjects_VIPERformat/consensus/C_viperRegulon.rdata'
    ),
    destfile = 'tfregulons_C.rdata'
)

for(lev in c('A', 'B', 'C')){

    load(sprintf('tfregulons_%s.rdata', lev))
    
    df <- as_tibble(
        t(
            do.call(
                'cbind',
                map(
                    map2(
                        names(viper_regulon),
                        viper_regulon,
                        function(tf, d){
                            m <- (
                                sapply(
                                    names(d$tfmode),
                                    function(tg){c(tf, tg)}
                                )
                            )
                            colnames(m) <- NULL
                            return(m)
                        }
                    ),
                    as.data.frame
                )
            )
        )
    )

    colnames(df) <- c('tf', 'tg')
    
    df <- df %>%
        mutate(tf = gsub(' -.*$', '', tf))

    print(sprintf(
        'Level %s: %d interactions\n',
        lev,
        (df %>% group_by(tf, tg) %>% summarise_all(first) %>% dim)[1]
    ))
    
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.