Answers.Body: <p>Using this data frame:</p>
  
  <pre><code>gaps
    Chrom Start      End    Name
  1     I     0 15072434 contigs
  2    II     0 15279421 contigs
  3   III     0 13783801 contigs
  4    IV     0 17493829 contigs
  5     V     0 20924180 contigs
  6     X     0 17718942 contigs
  7 MtDNA     0    13794 contigs
  </code></pre>
  
  <p>and this command:</p>
  
  <pre><code>chromPlot(bands = gaps)
  </code></pre>
  
  <p>I could obtain this plot:</p>
  
  <p><a href="https://i.sstatic.net/M4NiR.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/M4NiR.png" alt="Karyotype of *C. elegans*"></a></p>
  
  <p>and then, if you want to add some segments for a subset of bases, you can do:</p>
  
  <pre><code>gaps2 &lt;- gaps[1:2, ]
  gaps2$End[2] &lt;- 7000000
  
  chromPlot(bands = gaps, segment = gaps2)
  </code></pre>
  
  <p>and obtain the following plot:</p>
  
  <p><a href="https://i.sstatic.net/MNvzI.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/MNvzI.png" alt="*C. elegans* karyotype with segments"></a></p>
  
  <p>A more satisfactory answer could put segments of different colour on the chromosome, so bands but this is the best I've got so far.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-28T13:33:42.693Z
Answers.LastActivityDate: 2018-06-28T13:33:42.693Z
Answers.UserDisplayName: Biomagician
Body: <p>I am using <a href="https://bioconductor.org/packages/release/bioc/html/chromPlot.html" rel="nofollow noreferrer">chromPlot</a> to visualise the genome of <em>C. elegans</em>.</p>
  
  <p><code>library(chromPlot)</code></p>
  
  <p>I have created the following data frame with the lengths of <em>C. elegans</em> chromosomes.</p>
  
  <pre><code>Chrom Start      End    Name
  1     1     0 15072434 contigs
  2     2     0 15279421 contigs
  3     3     0 13783801 contigs
  4     4     0 17493829 contigs
  5     6     0 20924180 contigs
  6     7     0 17718942 contigs
  7     5     0    13794 contigs
  </code></pre>
  
  <p>When I use <code>chromPlot(dataframe)</code>, I get a plot with 4 chromosomes and the following output/error:</p>
  
  <pre><code>   1 segment clusters.
     1 segment clusters.
     1 segment clusters.
     1 segment clusters.
     1 segment clusters.
     1 segment clusters.
     1 segment clusters.
  Chrom 1 : 15072434 bp
  Chrom 2 : 15279421 bp
  Chrom 3 : 13783801 bp
  Chrom 4 : 17493829 bp
  Error in seq.default(minval, maxval, length = howmany) : 
    'from' must be of length 1
  </code></pre>
  
  <p>Does anybody know why I get this error?</p>
  
  <p>I don't get this error when I use the data frame provided by the package with human segments. The structure of the data frame is:</p>
  
  <pre><code>'data.frame':   457 obs. of  4 variables:
   $ Chrom: chr  "1" "1" "1" "1" ...
   $ Start: int  124535434 121535434 3845268 13219912 17125658 29878082 120697156 120936695 121485434 142731022 ...
   $ End  : int  142535434 124535434 3995268 13319912 17175658 30028082 120747156 121086695 121535434 142781022 ...
   $ Name : chr  "heterochromatin" "centromere" "contig" "contig" ...
  </code></pre>
  
  <p>Compared to my data frame:</p>
  
  <pre><code>'data.frame':   7 obs. of  4 variables:
   $ Chrom: chr  "1" "2" "3" "4" ...
   $ Start: int  0 0 0 0 0 0 0
   $ End  : int  15072434 15279421 13783801 17493829 20924180 17718942 13794
   $ Name : chr  "contigs" "contigs" "contigs" "contigs" ...
  </code></pre>
  
  <p>I am on MacOS X.</p>
  
  <h3>Update</h3>
  
  <p>The 20th line of the package-provided hg_gap data frame is:</p>
  
  <pre><code>   Chrom Start   End     Name
  20     1     0 10000 telomere
  </code></pre>
  
  <p>Note that the Start is 0.</p>
  
  <p>I've also tried changing the start from 0 to 1. The error stays the same.</p>
  
  <h3>Update 2</h3>
  
  <p>Sorting the data frame by chromosome name does not improve the situation.</p>
  
  <p>The traceback of the error is:</p>
  
  <pre><code>6: stop("'from' must be of length 1")
  5: seq.default(minval, maxval, length = howmany)
  4: seq(minval, maxval, length = howmany)
  3: pretty_ticks(minlab, maxlab, 2, ...)
  2: draw.scale(y = 0.8 * chr.length[[chrom]] + 0.2 * xylims[3], minval = margin, 
         maxval = maxGeneCount, minlab = annot1_plot_range[1], maxlab = annot1_plot_range[2], 
         lwd = 4, col = colAnnot1, cex = cex, title = scale.title)
  1: chromPlot::chromPlot(gaps)
  </code></pre>
  
  <p>I have emailed the maintainer of the package Karen Orostica with a link to this post.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-27T14:16:37.853Z
Comments.Text: I think the error occurs because the `start` should be 1 or more and not zero. I think the BED format should be 1 based (now it is 0 based).
Comments.UserDisplayName: benn
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-27T14:22:32.190Z
Comments.Text: I've updated my question. I don't think this is the problem based on my experimenting with a 1 start.
Comments.UserDisplayName: Biomagician
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-27T14:27:09.600Z
Comments.Text: Maybe `Chrom` needs to be sorted, in your example after `Chrom` 1-4, comes 6 not 5. I am just guessing here.
Comments.UserDisplayName: benn
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-27T14:27:53.297Z
Comments.Text: It seems more like it tries to do something like `seq(NULL, to = 50) `. If the data is valid, it is a bug on the package. Create an issue as required by the maintainer of the package adding the `traceback` to see the origin of the error.
Comments.UserDisplayName: llrs
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-27T14:33:36.110Z
Comments.Text: Sorting does not make a difference. I have sent an email to the maintainer Karen Orostica.
Comments.UserDisplayName: Biomagician
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-27T14:52:36.417Z
Comments.Text: Are you sure *C. elegans* has 7 chromosomes? According to [ensembl](http://www.ensembl.org/Caenorhabditis_elegans/Location/Genome) it has only 5 and X.
Comments.UserDisplayName: benn
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-27T14:54:53.890Z
Comments.Text: + mitochondrial "chromosome", for my own business I consider the mitochondrial genome like a chromosome but I concede it's technically wrong.
Comments.UserDisplayName: Biomagician
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-27T14:56:29.827Z
Comments.Text: also chromPlot didn't like my character names, but one problem at a time.
Comments.UserDisplayName: Biomagician
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-27T14:59:11.590Z
Comments.Text: I was wondering if that may cause the error. Does it work if you only use the first 4 lines of your df? I mean do you still get the error?
Comments.UserDisplayName: benn
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-27T15:08:14.813Z
Comments.Text: The code works with the first two lines of the data frame but fails if I run it one the first three lines.
Comments.UserDisplayName: Biomagician
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-27T15:09:56.940Z
Comments.Text: This gave me an idea. If I change the chromosome 3 length to 16000000, it works, suggesting it's not allowed to be shorter than the previous chromosome? But ordering by end base did not help.
Comments.UserDisplayName: Biomagician
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-27T15:14:38.440Z
Comments.Text: oooouh, but ordering by end base and removing the mitochondrial genome worked! still not an ideal situation. I wonder if I'm using it wrong or if there is a bug.
Comments.UserDisplayName: Biomagician
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-28T07:25:50.663Z
Comments.Text: @charlesdarwin Maybe that could be written as an answer, just so future reader know how to solve/avoid this problem
Comments.UserDisplayName: llrs
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-28T13:21:32.793Z
Comments.Text: @Llopis unfortunately, I could not reproduce it but I've got an alternative that I'll put as an answer.
Comments.UserDisplayName: Biomagician
Tags: <r><bioconductor><visualization><chromplot>
Title: Error in seq.default in chromPlot
ThreadText: # Error in seq.default in chromPlot
  
  (Asked by: username_0 on 2018-06-27)
  
  I am using [chromPlot](https://bioconductor.org/packages/release/bioc/html/chromPlot.html) to visualise the genome of *C. elegans*.
  
  `library(chromPlot)`
  
  I have created the following data frame with the lengths of *C. elegans* chromosomes.
  
  ```
  Chrom Start      End    Name
  1     1     0 15072434 contigs
  2     2     0 15279421 contigs
  3     3     0 13783801 contigs
  4     4     0 17493829 contigs
  5     6     0 20924180 contigs
  6     7     0 17718942 contigs
  7     5     0    13794 contigs
  
  ```
  
  When I use `chromPlot(dataframe)`, I get a plot with 4 chromosomes and the following output/error:
  
  ```
     1 segment clusters.
     1 segment clusters.
     1 segment clusters.
     1 segment clusters.
     1 segment clusters.
     1 segment clusters.
     1 segment clusters.
  Chrom 1 : 15072434 bp
  Chrom 2 : 15279421 bp
  Chrom 3 : 13783801 bp
  Chrom 4 : 17493829 bp
  Error in seq.default(minval, maxval, length = howmany) : 
    'from' must be of length 1
  
  ```
  
  Does anybody know why I get this error?
  
  I don't get this error when I use the data frame provided by the package with human segments. The structure of the data frame is:
  
  ```
  'data.frame':   457 obs. of  4 variables:
   $ Chrom: chr  "1" "1" "1" "1" ...
   $ Start: int  124535434 121535434 3845268 13219912 17125658 29878082 120697156 120936695 121485434 142731022 ...
   $ End  : int  142535434 124535434 3995268 13319912 17175658 30028082 120747156 121086695 121535434 142781022 ...
   $ Name : chr  "heterochromatin" "centromere" "contig" "contig" ...
  
  ```
  
  Compared to my data frame:
  
  ```
  'data.frame':   7 obs. of  4 variables:
   $ Chrom: chr  "1" "2" "3" "4" ...
   $ Start: int  0 0 0 0 0 0 0
   $ End  : int  15072434 15279421 13783801 17493829 20924180 17718942 13794
   $ Name : chr  "contigs" "contigs" "contigs" "contigs" ...
  
  ```
  
  I am on MacOS X.
  
  ### Update
  
  The 20th line of the package-provided hg\_gap data frame is:
  
  ```
     Chrom Start   End     Name
  20     1     0 10000 telomere
  
  ```
  
  Note that the Start is 0.
  
  I've also tried changing the start from 0 to 1. The error stays the same.
  
  ### Update 2
  
  Sorting the data frame by chromosome name does not improve the situation.
  
  The traceback of the error is:
  
  ```
  6: stop("'from' must be of length 1")
  5: seq.default(minval, maxval, length = howmany)
  4: seq(minval, maxval, length = howmany)
  3: pretty_ticks(minlab, maxlab, 2, ...)
  2: draw.scale(y = 0.8 * chr.length[[chrom]] + 0.2 * xylims[3], minval = margin, 
         maxval = maxGeneCount, minlab = annot1_plot_range[1], maxlab = annot1_plot_range[2], 
         lwd = 4, col = colAnnot1, cex = cex, title = scale.title)
  1: chromPlot::chromPlot(gaps)
  
  ```
  
  I have emailed the maintainer of the package Karen Orostica with a link to this post.
  
  **Tags:** r, bioconductor, visualization, chromplot
  
  > **Comments:**
  > **username_1**: I think the error occurs because the `start` should be 1 or more and not zero. I think the BED format should be 1 based (now it is 0 based).  
  > **username_0**: I've updated my question. I don't think this is the problem based on my experimenting with a 1 start.  
  > **username_1**: Maybe `Chrom` needs to be sorted, in your example after `Chrom` 1-4, comes 6 not 5. I am just guessing here.  
  > **username_2**: It seems more like it tries to do something like `seq(NULL, to = 50) `. If the data is valid, it is a bug on the package. Create an issue as required by the maintainer of the package adding the `traceback` to see the origin of the error.  
  > **username_0**: Sorting does not make a difference. I have sent an email to the maintainer Karen Orostica.  
  > **username_1**: Are you sure *C. elegans* has 7 chromosomes? According to [ensembl](http://www.ensembl.org/Caenorhabditis_elegans/Location/Genome) it has only 5 and X.  
  > **username_0**: + mitochondrial "chromosome", for my own business I consider the mitochondrial genome like a chromosome but I concede it's technically wrong.  
  > **username_0**: also chromPlot didn't like my character names, but one problem at a time.  
  > **username_1**: I was wondering if that may cause the error. Does it work if you only use the first 4 lines of your df? I mean do you still get the error?  
  > **username_0**: The code works with the first two lines of the data frame but fails if I run it one the first three lines.  
  > **username_0**: This gave me an idea. If I change the chromosome 3 length to 16000000, it works, suggesting it's not allowed to be shorter than the previous chromosome? But ordering by end base did not help.  
  > **username_0**: oooouh, but ordering by end base and removing the mitochondrial genome worked! still not an ideal situation. I wonder if I'm using it wrong or if there is a bug.  
  > **username_2**: @charlesdarwin Maybe that could be written as an answer, just so future reader know how to solve/avoid this problem  
  > **username_0**: @Llopis unfortunately, I could not reproduce it but I've got an alternative that I'll put as an answer.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2018-06-28. Score: 2 | Accepted answer
  
  Using this data frame:
  
  ```
  gaps
    Chrom Start      End    Name
  1     I     0 15072434 contigs
  2    II     0 15279421 contigs
  3   III     0 13783801 contigs
  4    IV     0 17493829 contigs
  5     V     0 20924180 contigs
  6     X     0 17718942 contigs
  7 MtDNA     0    13794 contigs
  
  ```
  
  and this command:
  
  ```
  chromPlot(bands = gaps)
  
  ```
  
  I could obtain this plot:
  
  [![Karyotype of *C. elegans*](https://i.sstatic.net/M4NiR.png)](https://i.sstatic.net/M4NiR.png)
  
  and then, if you want to add some segments for a subset of bases, you can do:
  
  ```
  gaps2 <- gaps[1:2, ]
  gaps2$End[2] <- 7000000
  
  chromPlot(bands = gaps, segment = gaps2)
  
  ```
  
  and obtain the following plot:
  
  [![*C. elegans* karyotype with segments](https://i.sstatic.net/MNvzI.png)](https://i.sstatic.net/MNvzI.png)
  
  A more satisfactory answer could put segments of different colour on the chromosome, so bands but this is the best I've got so far.
  
  
  ---
  
  