<p>Think about it this way - your <code>elements_file</code> already has only the sites of interest and hence does not need to be subject to a subset operation. In other words, if you were to have a <code>sites_file</code>, it would have the same content as the <code>elements_file</code>.</p>

<p>Can you see where I am going with this?</p>

CC BY-SA 4.0
2020-02-20T17:50:47.403Z
I think you are stating to edit the function for any site file requisition
Zizogolu
CC BY-SA 4.0
2020-02-20T18:34:47.823Z
You don't need to edit the function. `sites_file` would have the **same** content as the `elements_file`. What does this mean in terms of passing file names to the parameters? Are they different files?
Ram RS
CC BY-SA 4.0
2020-02-20T19:01:17.320Z
sites_file is a BED4 separate input file but as the content already in element_file, I don't provide that. Element_file is a BED12
Zizogolu
CC BY-SA 4.0
2020-02-20T19:20:47.350Z
So, `sites_file` should contain fewer columns and possibly (but not necessarily) a subset of the regions in `elements_file`, correct? If they contain the same regions, is it not straighforward to get the `BED4` content from a `BED12` file? You literally need 4 columns of an existing file for a new file.
Ram RS
CC BY-SA 4.0
2020-02-20T19:32:59.473Z
You right contains 4 columns for chromosome start and a more column that I don't know what could be like this  chr17 7565257 7565267 site1. My problem is I don't site column is which part of BED12 file with 12 columns
Zizogolu
CC BY-SA 4.0
2020-02-20T20:12:29.890Z
Please invest some effort in learning the columns in various BED formats. I literally googled "BED4" and got this: https://bedtools.readthedocs.io/en/latest/content/general-usage.html. This should tell you how to get to BED4 from BED12.
Ram RS
CC BY-SA 4.0
2020-02-20T17:34:03.507Z
2020-02-20T17:34:03.507Z
Ram RS
<p>There is a function does need an input as selected genomic site across genomic regions. But my genomic region bed file already is a subset of interesting site (like promoters). I want this function to work not complaining about genomic site
However when I leave genomic site says </p>

<pre><code>&gt; prepare_elements_regions_tf &lt;- prepare_elements("regions.bed",
+                                                 window_size = 50000)
Successfully read elements
 Error in utils::read.delim(sites_file, stringsAsFactors = FALSE, header = FALSE) : 
  argument "sites_file" is missing, with no default 
</code></pre>

<p>The whole function is here </p>

<p><a href="https://github.com/wenmm/ActiveDriverWGS/blob/master/R/ActiveDriverWGS.R" rel="nofollow noreferrer">https://github.com/wenmm/ActiveDriverWGS/blob/master/R/ActiveDriverWGS.R</a></p>

<p>But part of function that nags is this </p>

<pre><code>prepare_elements = function(elements_file, sites_file, window_size = 50000, mc.cores = 1, recovery_dir = NA) {

    try_error = "try-error"



    element_coords_filename = paste0(recovery_dir, "/ADWGS_elements_coords_recovery_file.rsav")

    element_coords_1 = NULL

    load_result = suppressWarnings(try(load(element_coords_filename), silent = TRUE))

    if (class(load_result) == try_error) {

        element_coords_1 = prepare_element_coords_from_BED(elements_file)

        if (!is.na(recovery_dir)) {

            save(element_coords_1, file = element_coords_filename)

        }

        cat("Successfully read elements\n")

    } else {

        cat("Recovered elements\n")

    }



    element_coords = coords_sanity(element_coords_1)



    element_3n_filename = paste0(recovery_dir, "/ADWGS_element_3n_recovery_file.rsav")

    element_3n = NULL

    load_result = suppressWarnings(try(load(element_3n_filename), silent = TRUE))

    if (class(load_result) == try_error) {

        element_3n = add_trinucs_by_elements(get_3n(element_coords))

        if (!is.na(recovery_dir)) {

            save(element_3n, file = element_3n_filename)

        }

    }



    window_coords_filename = paste0(recovery_dir, "/ADWGS_window_coords_recovery_file.rsav")

    window_coords = NULL

    load_result = suppressWarnings(try(load(window_coords_filename), silent = TRUE))

    if (class(load_result) == try_error) {

        window_coords = coords_sanity(get_window_coords(element_coords, window_size))

        if (!is.na(recovery_dir)) {

            save(window_coords, file = window_coords_filename)

        }

    }



    window_3n_filename = paste0(recovery_dir, "/ADWGS_window_3n_recovery_file.rsav")

    window_3n = NULL

    load_result = suppressWarnings(try(load(window_3n_filename), silent = TRUE))

    if (class(load_result) == try_error) {

        window_3n = add_trinucs_by_elements(get_3n(window_coords))

        if (!is.na(recovery_dir)) {

            save(window_3n, file = window_3n_filename)

        }

    }



    raw_site_coords_filename = paste0(recovery_dir, "/ADWGS_raw_site_coords_recovery_file.rsav")

    site_coords_filename = paste0(recovery_dir, "/ADWGS_site_coords_recovery_file.rsav")

    raw_site_coords = NULL

    site_coords = NULL

    sites_load_result = suppressWarnings(try(load(site_coords_filename), silent = TRUE))

    if (class(sites_load_result) == try_error) {

        load_result = suppressWarnings(try(load(raw_site_coords_filename), silent = TRUE))

        if (class(load_result) == try_error) {

            raw_site_coords = utils::read.delim(sites_file, stringsAsFactors = FALSE, header = FALSE)

            colnames(raw_site_coords) = c("chr", "starts", "ends", "site_info")

            raw_site_coords<span class="math-container">$chr = gsub("chr", "", raw_site_coords$</span>chr, ignore.case = TRUE)

            raw_site_coords<span class="math-container">$chr = paste0("chr", raw_site_coords$</span>chr)

            if (!is.na(recovery_dir)) {

                save(raw_site_coords, file = raw_site_coords_filename)

            }

            cat("Successfully read active sites\n")

        } else {

            cat("Recovered active sites\n")

        }



        if (!is.null(raw_site_coords[[1]])) {

            # first only keep sites that overlap with element coordinates

            site_gr = GenomicRanges::GRanges(raw_site_coords$chr,

                IRanges::IRanges(start=raw_site_coords<span class="math-container">$starts, end=raw_site_coords$</span>ends))

            element_gr = GenomicRanges::GRanges(element_coords$chr, 

                IRanges::IRanges(start=element_coords<span class="math-container">$starts, end=element_coords$</span>ends))



            rm(raw_site_coords)



            overlaps_found = GenomicRanges::findOverlaps(element_gr, site_gr)

            site_here_gr = site_gr[S4Vectors::subjectHits(overlaps_found)]



            rm(site_gr, element_gr, overlaps_found)



            site_coords = do.call(rbind, parallel::mclapply(1:nrow(element_coords), 

                get_sites_per_element, element_coords, site_here_gr, mc.cores=mc.cores))

            rm(site_here_gr)

            site_coords = coords_sanity(site_coords)

        }

        if (!is.na(recovery_dir)) {

            save(site_coords, file = site_coords_filename)

        }

    } else {

        cat("Recovered active sites\n")

    }

    rm(sites_load_result, element_coords)



    site_3n_filename = paste0(recovery_dir, "/ADWGS_site_3n_recovery_file.rsav")

    site_3n = NULL

    load_result = suppressWarnings(try(load(site_3n_filename), silent = TRUE))

    if (class(load_result) == try_error) {

        site_3n = get_3n(site_coords)

        if (!is.na(recovery_dir)) {

            save(site_3n, file = site_3n_filename)

        }

    }



    list(element_coords=element_coords_1, element_3n=element_3n, window_coords=window_coords, window_3n=window_3n, site_coords=site_coords, site_3n=site_3n)



}
</code></pre>

<p>How I get rid of nagging part?</p>

CC BY-SA 4.0
2020-02-20T17:02:38.453Z
What have you tried?
Ram RS
CC BY-SA 4.0
2020-02-20T17:49:42.587Z
I tried to edit the function by elimination any line goes with site fine but function is not working at the end
Zizogolu
<r>
How I change a function not to need an input
# How I change a function not to need an input

(Asked by: username_0 on 2020-02-20)

There is a function does need an input as selected genomic site across genomic regions. But my genomic region bed file already is a subset of interesting site (like promoters). I want this function to work not complaining about genomic site
However when I leave genomic site says 
> prepare_elements_regions_tf <- prepare_elements("regions.bed",
+                                                 window_size = 50000)
Successfully read elements
 Error in utils::read.delim(sites_file, stringsAsFactors = FALSE, header = FALSE) : 
  argument "sites_file" is missing, with no default 

The whole function is here 
https://github.com/wenmm/ActiveDriverWGS/blob/master/R/ActiveDriverWGS.R
But part of function that nags is this 
prepare_elements = function(elements_file, sites_file, window_size = 50000, mc.cores = 1, recovery_dir = NA) {

    try_error = "try-error"



    element_coords_filename = paste0(recovery_dir, "/ADWGS_elements_coords_recovery_file.rsav")

    element_coords_1 = NULL

    load_result = suppressWarnings(try(load(element_coords_filename), silent = TRUE))

    if (class(load_result) == try_error) {

        element_coords_1 = prepare_element_coords_from_BED(elements_file)

        if (!is.na(recovery_dir)) {

            save(element_coords_1, file = element_coords_filename)

        }

        cat("Successfully read elements\n")

    } else {

        cat("Recovered elements\n")

    }



    element_coords = coords_sanity(element_coords_1)



    element_3n_filename = paste0(recovery_dir, "/ADWGS_element_3n_recovery_file.rsav")

    element_3n = NULL

    load_result = suppressWarnings(try(load(element_3n_filename), silent = TRUE))

    if (class(load_result) == try_error) {

        element_3n = add_trinucs_by_elements(get_3n(element_coords))

        if (!is.na(recovery_dir)) {

            save(element_3n, file = element_3n_filename)

        }

    }



    window_coords_filename = paste0(recovery_dir, "/ADWGS_window_coords_recovery_file.rsav")

    window_coords = NULL

    load_result = suppressWarnings(try(load(window_coords_filename), silent = TRUE))

    if (class(load_result) == try_error) {

        window_coords = coords_sanity(get_window_coords(element_coords, window_size))

        if (!is.na(recovery_dir)) {

            save(window_coords, file = window_coords_filename)

        }

    }



    window_3n_filename = paste0(recovery_dir, "/ADWGS_window_3n_recovery_file.rsav")

    window_3n = NULL

    load_result = suppressWarnings(try(load(window_3n_filename), silent = TRUE))

    if (class(load_result) == try_error) {

        window_3n = add_trinucs_by_elements(get_3n(window_coords))

        if (!is.na(recovery_dir)) {

            save(window_3n, file = window_3n_filename)

        }

    }



    raw_site_coords_filename = paste0(recovery_dir, "/ADWGS_raw_site_coords_recovery_file.rsav")

    site_coords_filename = paste0(recovery_dir, "/ADWGS_site_coords_recovery_file.rsav")

    raw_site_coords = NULL

    site_coords = NULL

    sites_load_result = suppressWarnings(try(load(site_coords_filename), silent = TRUE))

    if (class(sites_load_result) == try_error) {

        load_result = suppressWarnings(try(load(raw_site_coords_filename), silent = TRUE))

        if (class(load_result) == try_error) {

            raw_site_coords = utils::read.delim(sites_file, stringsAsFactors = FALSE, header = FALSE)

            colnames(raw_site_coords) = c("chr", "starts", "ends", "site_info")

            raw_site_coords$chr = gsub("chr", "", raw_site_coords$chr, ignore.case = TRUE)

            raw_site_coords$chr = paste0("chr", raw_site_coords$chr)

            if (!is.na(recovery_dir)) {

                save(raw_site_coords, file = raw_site_coords_filename)

            }

            cat("Successfully read active sites\n")

        } else {

            cat("Recovered active sites\n")

        }



        if (!is.null(raw_site_coords[[1]])) {

            # first only keep sites that overlap with element coordinates

            site_gr = GenomicRanges::GRanges(raw_site_coords$chr,

                IRanges::IRanges(start=raw_site_coords$starts, end=raw_site_coords$ends))

            element_gr = GenomicRanges::GRanges(element_coords$chr, 

                IRanges::IRanges(start=element_coords$starts, end=element_coords$ends))



            rm(raw_site_coords)



            overlaps_found = GenomicRanges::findOverlaps(element_gr, site_gr)

            site_here_gr = site_gr[S4Vectors::subjectHits(overlaps_found)]



            rm(site_gr, element_gr, overlaps_found)



            site_coords = do.call(rbind, parallel::mclapply(1:nrow(element_coords), 

                get_sites_per_element, element_coords, site_here_gr, mc.cores=mc.cores))

            rm(site_here_gr)

            site_coords = coords_sanity(site_coords)

        }

        if (!is.na(recovery_dir)) {

            save(site_coords, file = site_coords_filename)

        }

    } else {

        cat("Recovered active sites\n")

    }

    rm(sites_load_result, element_coords)



    site_3n_filename = paste0(recovery_dir, "/ADWGS_site_3n_recovery_file.rsav")

    site_3n = NULL

    load_result = suppressWarnings(try(load(site_3n_filename), silent = TRUE))

    if (class(load_result) == try_error) {

        site_3n = get_3n(site_coords)

        if (!is.na(recovery_dir)) {

            save(site_3n, file = site_3n_filename)

        }

    }



    list(element_coords=element_coords_1, element_3n=element_3n, window_coords=window_coords, window_3n=window_3n, site_coords=site_coords, site_3n=site_3n)



}

How I get rid of nagging part?

**Tags:** r
> **Comments:**
> **username_1**: What have you tried?  
> **username_0**: I tried to edit the function by elimination any line goes with site fine but function is not working at the end  

---

## 1 answers

### Answer by username_1 on 2020-02-20. Score: 1

Think about it this way - your `elements_file` already has only the sites of interest and hence does not need to be subject to a subset operation. In other words, if you were to have a `sites_file`, it would have the same content as the `elements_file`.

Can you see where I am going with this?

> **Comments:**
> **username_0**: I think you are stating to edit the function for any site file requisition  
> **username_1**: You don't need to edit the function. `sites_file` would have the **same** content as the `elements_file`. What does this mean in terms of passing file names to the parameters? Are they different files?  
> **username_0**: sites_file is a BED4 separate input file but as the content already in element_file, I don't provide that. Element_file is a BED12  
> **username_1**: So, `sites_file` should contain fewer columns and possibly (but not necessarily) a subset of the regions in `elements_file`, correct? If they contain the same regions, is it not straighforward to get the `BED4` content from a `BED12` file? You literally need 4 columns of an existing file for a new file.  
> **username_0**: You right contains 4 columns for chromosome start and a more column that I don't know what could be like this  chr17 7565257 7565267 site1. My problem is I don't site column is which part of BED12 file with 12 columns  
> **username_1**: Please invest some effort in learning the columns in various BED formats. I literally googled "BED4" and got this: https://bedtools.readthedocs.io/en/latest/content/general-usage.html. This should tell you how to get to BED4 from BED12.  

---

