0

I am working on finding and returning elements in the human genome annotation file that overlap with a given genomic region in R, but it must be with a for-loop.

So far, this is the code I have, but I am not sure if it is correct because I am not sure what to return exactly, and it keeps giving me errors. Any help is appreciated:

 genome <- "gencode.v31.annotation.gff3.gz"
 cat("Loading", genome, "at", date())


 genomeTable <- read.table(genome, header = F, sep = "\t", nrows = 1000)

 colnames(genomeTable) <- c("seqid", "source", "type", "start", "end", 
 "score", "strand", "phase", "attributes")

chr = 10
q.start = 10000
q.end = 20000

for(i in genomeTable){

  if (i < q.start) {

   return FALSE
  }

  if (i > q.end){
   return FALSE
  } else {
    return TRUE
  }

} #END FOR LOOP
  • Please provide a reproducible example https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – M-- Oct 04 '19 at 18:14
  • 1
    If I understood you correctly, you should use the `intersect` function and/or other set operations. – slava-kohut Oct 04 '19 at 18:16
  • 1
    why do you insist on a for loop? there are many better/faster/more versatile functions that can easily outperform a for-loop. – Wimpel Oct 04 '19 at 18:17
  • Hi! I have to find overlapping regions with many different functions for a class assignment, and the for-loop is one of them. – oldsoulsongs Oct 04 '19 at 20:25

0 Answers0