<commit_before>import os
import rpy2.robjects as robjects
import rpy2.robjects.vectors as vectors
import pandas as pd
from bcbio.utils import safe_makedir

this_dir, this_filename = os.path.split(__file__)
RFILE = os.path.join(this_dir, "R", "diffexp.R")


def run(in_file, conds, out_prefix):
    deseq_table_out = out_prefix + ".deseq.txt"
    dispersion_plot_out = out_prefix + ".dispersions.pdf"
    mva_plot_out = out_prefix + ".MvA.pdf"

    safe_makedir(os.path.dirname(out_prefix))

    r = robjects.r
    r.assign('in_file', in_file)
    r.assign('deseq_table_out', deseq_table_out)
    r.assign('mva_plot_out', mva_plot_out)
    r.assign('conds',
             vectors.StrVector.factor(vectors.StrVector(conds)))
    r('''
    require('DESeq')
    counts = read.table(in_file, header=TRUE, row.names=1)
    print(head(counts))
    cds = newCountDataSet(counts, conds)
    print(head(cds))
    cds = estimateSizeFactors(cds)
    ''')
<commit_msg>Documentation cleanup.<commit_after>"""
wrapper to run DESeq analyses. at the moment it will only run with a simple
two-condition comparison. more complicated experimental setups could be
added by creating a dataframe of the conditions and passing it in
"""
import os
import rpy2.robjects as robjects
import rpy2.robjects.vectors as vectors
import pandas as pd
from bcbio.utils import safe_makedir

this_dir, this_filename = os.path.split(__file__)
RFILE = os.path.join(this_dir, "R", "diffexp.R")


def load_count_file(in_file, r):
    """
    returns an r session with a read count file loaded as 'counts'
    """
    r.assign('in_file', in_file)
    r('''
    counts = read.table(in_file, header=TRUE, row.names=1)
    ''')
    return r


def make_count_set(conds, r):
    """
    returns an r session with a new count data set loaded as cds
    """
    r.assign('conds', vectors.StrVector.factor(vectors.StrVector(conds)))
    r('''
    require('DESeq')
    cds = newCountDataSet(counts, conds)
    ''')
    return r


def run(in_file, conds, out_prefix):
    deseq_table_out = out_prefix + ".deseq.txt"
    dispersion_plot_out = out_prefix + ".dispersions.pdf"
    mva_plot_out = out_prefix + ".MvA.pdf"

    safe_makedir(os.path.dirname(out_prefix))

    r = robjects.r
    r.assign('deseq_table_out', deseq_table_out)
    r.assign('mva_plot_out', mva_plot_out)

    r = load_count_file(in_file, r)
    r = make_count_set(conds, r)
    r('''
    cds = estimateSizeFactors(cds)
    ''')

{'fraction_non_alphanumeric': 0.12019623875715454, 'fraction_numerical': 0.0024529844644317253, 'mean_word_length': 3.8169291338582676, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '195970', 'n_tokens_mistral': 903, 'n_tokens_neox': 892, 'n_words': 202}