cfDNA pro
1
0
Entering edit mode
@bonydekumar-19283
Last seen 9 weeks ago
United States

Hi , I am trying to use cfDNA pro package . I have four directories namely Blood , Urine, Blood_control and Urine_contro where my four cohorts are stored. I generated a data path object using following code

data=list.files(path = ".", pattern = "txt", all.files = FALSE,
           full.names = FALSE, recursive = TRUE)

Data path file looks like following

[1] "blood_control/Control-2.txt"
[2] "blood_control/Control-3.txt"
[3] "blood_control/Control-4.txt"
[4] "blood_control/Control-5.txt"
[5] "blood/APK-01-0027.txt"
[6] "blood/APK-01-0029.txt"

Then Created a group list

grp_list<-list("cohort_1"="blood",
               "cohort_2"="urine",
               "cohort_3"="blood_control",
               "cohort_4"="urine_control")

Then I used following code to generate plot as list.

result<-sapply(grp_list, function(x){
  result <-callSize(path = data) %>% 
    dplyr::filter(group==as.character(x)) %>% 
    plotSingleGroup()
}, simplify = FALSE)

I am getting the following error. It seems that package is looking for an object called "group"

setting default outfmt to df. setting default input_type to picard. Error in dplyr::filter(): ! Problem while computing ..1 = group == as.character(x). Caused by error: ! object 'group' not found Backtrace:

  1. base::sapply(...)
  2. dplyr:::filter.data.frame(., group == as.character(x))
    1. dplyr:::filter_rows(.data, ..., caller_env = caller_env())
    2. dplyr:::filter_eval(dots, mask = mask, error_call = error_call)
    3. mask$eval_all_filter(dots, env_filter) Error in dplyr::filter(., group == as.character(x)) : Caused by error: ! object 'group' not found ‘/tmp/Rtmp0ToHu5/downloaded_packages’
cfDNAPro • 103 views
ADD COMMENT
0
Entering edit mode
hw538 • 0
@hw538-24230
Last seen 4 weeks ago
United Kingdom

Hello,

I am Haichao, the author of cfDNAPro.

There are two issues in your code:

  • the input 'data' should be a path to the parent folder containing all of your sub-folders(i.e. blood, urine, blood_control, urine_control), for example, you sub-folders are stored in /path/to/parent/folder , then you should set data as /path/to/parent/folder
  • use lapply instead of sapply

Here is the solution to your question:


data <- "/path/to/parent/folder"

# make sure the names below match with the sub-folder name.
grp_list<-list("cohort_1"="blood",
               "cohort_2"="urine",
               "cohort_3"="blood_control",
               "cohort_4"="urine_control")

# write this function independently,  so as to make the code tidier. 
f <- function(x) {
  result <- callSize(path = data_path) %>% 
    dplyr::filter(group == as.character(x)) %>%
    plotSingleGroup()
  return(result)
}

# use lapply
result<-lapply(grp_list, f)

in the result, you will find the plots for each cohort. Please don't hesitate to let me know further questions. (if any)

Best wishes, Haichao

ADD COMMENT

Login before adding your answer.

Traffic: 581 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6