File size: 2,120 Bytes
dd7b72a
 
 
 
 
 
 
 
d360998
 
 
 
 
 
dd7b72a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Install required packages
# install.packages("reshape2")
# if (!requireNamespace("BiocManager", quietly = TRUE))
#  install.packages("BiocManager")
# BiocManager::install("BSgenome")
# BiocManager::install("BSgenome.Hsapiens.UCSC.hg19")
# BiocManager::install("GenomeInfoDb", force = TRUE)
# BiocManager::install("deconstructSigs", force = TRUE)
import os

# Attempt to set R_HOME manually (replace "/usr/lib/R" with your R home path if different)
os.environ['R_HOME'] = '/usr/lib/R'
# You might also need to add R to the PATH
os.environ['PATH'] += os.pathsep + '/usr/bin'
import rpy2.robjects as ro
from rpy2.robjects import conversion, default_converter

def get_base_substitutions():
  with conversion.localconverter(default_converter):

    ro.r("""   
        library(deconstructSigs)

          mutationData <- read.csv('./mutation_input.csv', colClasses=c("UNIQUE_SAMPLE_ID"="character", "CHROMOSOME"="character", "POSITION"="integer", "REF_ALLELE"="character", "ALT_ALLELE"="character"))
        
          if(nrow(mutationData) == 0) {
            return("Empty mutation data. No processing done.")
          }
        
          mutationData <- mutationData[!grepl("GL|chrMT", mutationData[,"CHROMOSOME"]), ]
          unique(mutationData[,"CHROMOSOME"])

          # Convert to deconstructSigs input format based on data source
          head(mutationData)

          sigs.input <- mut.to.sigs.input(mut.ref = mutationData, 
                                    sample.id = "UNIQUE_SAMPLE_ID", # type: str
                                    chr = "CHROMOSOME", 
                                    pos = "POSITION", 
                                    ref = "REF_ALLELE", 
                                    alt = "ALT_ALLELE")
    
          # Filter samples with low mutations
          sigs.input <- sigs.input[rowSums(sigs.input) >= 1,]

          # Set filename variable for saving output

          filename <- "trinucs_userinput_profile.csv" # Modify this as needed
    
          # Save the output
          write.csv(sigs.input, file = filename)""")

  return "./trinucs_userinput_profile.csv"