Answers.Body: <p>I cannot access the pipeline from nanopore, but looking at the <a href="https://github.com/nanoporetech/pipeline-structural-variation/blob/a5fec9407f24362c759630b5d331e47a76a9f107/lib/pipeline_structural_variation/sniffles_bamref2bed.py" rel="nofollow noreferrer">python script</a> you provided:</p>
  
  <pre><code>with pysam.AlignmentFile(bam_file, "r") as bam:
      for tid in range(0, bam.nreferences):
          ref_name = bam.get_reference_name(tid)
          if len(list(filter(lambda x: x in ref_name, filter_names))) &gt; 0:
              continue
  
          print(ref_name,
                "0",
                str(bam.get_reference_length(ref_name)),
                sep='\t')
  </code></pre>
  
  <p>So the script gets the length of the chromosome and by default, outputs the start as 0.<a href="http://genome.ucsc.edu/blog/the-ucsc-genome-browser-coordinate-counting-systems/" rel="nofollow noreferrer">Zero based coordinate system</a> is sometimes used in UCSC systems, so I am only guessing the authors of the pipeline use this convention somewhere further down.</p>
  
  <p>As for the coverage you mentioned, that is usually output as a score in the 5th column (<a href="https://genome.ucsc.edu/FAQ/FAQformat.html#format1" rel="nofollow noreferrer">bed format</a>). In those situations, usually the coordinates of the alignments in the bam file are converted into bed format. In this pipeline, i think the authors are simply extracting the chromosome information out and putting it into a tabular form.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-22T09:07:15.363Z
Answers.Text: Thanks, that's useful information, I was not aware of the zero based coordinate system. In fact I managed to find the other `.bed` file with the coverage per chromosome, so I guess the `.bed` file that I mentioned is only displaying the chromosomes length.
Answers.UserDisplayName: BCArg
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-22T09:02:28.150Z
Answers.LastActivityDate: 2019-10-22T09:02:28.150Z
Answers.UserDisplayName: StupidWolf
Body: <p>I am using a <a href="https://community.nanoporetech.com/knowledge/bioinformatics/structural-variation-analy-5068/tutorial#_20_glossary_of_terms" rel="nofollow noreferrer">pipeline</a> from nanopore to detect structural variants (SVs) in a human sample with long-reads sequencing. The first steps of the pipeline are:</p>
  
  <ol>
  <li>index the reference genome with <code>minimap2</code></li>
  <li>map the long reads to a reference genome using same tool as above</li>
  <li>Get BED coordinates from the <code>.bam</code> file.</li>
  </ol>
  
  <p>While the first two steps uses <code>minimap</code>, the third one uses a python script written by the developers of the pipeline, which can be found <a href="https://github.com/nanoporetech/pipeline-structural-variation/blob/a5fec9407f24362c759630b5d331e47a76a9f107/lib/pipeline_structural_variation/sniffles_bamref2bed.py" rel="nofollow noreferrer">here</a>.</p>
  
  <p>After the pipeline calls <code>bamref2bed</code> i.e. the python script above, my <code>target.bed</code> looks like the following:</p>
  
  <pre><code>chr1    0   249250621
  chr2    0   243199373
  chr3    0   198022430
  chr4    0   191154276
  chr5    0   180915260
  chr6    0   171115067
  chr7    0   159138663
  chr8    0   146364022
  chr9    0   141213431
  chr10   0   135534747
  chr11   0   135006516
  chr12   0   133851895
  chr13   0   115169878
  chr14   0   107349540
  chr15   0   102531392
  chr16   0   90354753
  chr17   0   81195210
  chr18   0   78077248
  chr19   0   59128983
  chr20   0   63025520
  chr21   0   48129895
  chr22   0   51304566
  chrX    0   155270560
  chrY    0   59373566
  </code></pre>
  
  <p>As far as I am concerned the first three columns of a bed file refer to (I) chr name, (II) start position (III) end position. The main thing I am wondering is how come all chromosomes have a start position of 0. Also, reading about <a href="https://bedtools.readthedocs.io/en/latest/content/tools/genomecov.html" rel="nofollow noreferrer">converting bam to bed files</a> I guess the most important feature would be the coverage across the whole chromosomes, which in this file is missing.</p>
  
  <p>But my main question would be: is it normal to have a start position of 0 for all chromosomes or is there something wrong here?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-10-22T09:12:46.940Z
Comments.Text: BED intervals are usually zero-based, half-open indexed. Issues aside from whether these particular intervals are meaningful results, a starting position of 0 is entirely normal for a BED element. Cite: http://genome.ucsc.edu/blog/the-ucsc-genome-browser-coordinate-counting-systems/
Comments.UserDisplayName: Alex Reynolds
Tags: <phylogenetics><nanopore><bed><long-reads><structural-variation>
Title: BED file from .bam alignment structure
ThreadText: # BED file from .bam alignment structure
  
  (Asked by: username_0 on 2019-10-22)
  
  I am using a [pipeline](https://community.nanoporetech.com/knowledge/bioinformatics/structural-variation-analy-5068/tutorial#_20_glossary_of_terms) from nanopore to detect structural variants (SVs) in a human sample with long-reads sequencing. The first steps of the pipeline are:
  
  1. index the reference genome with `minimap2`
  2. map the long reads to a reference genome using same tool as above
  3. Get BED coordinates from the `.bam` file.
  
  While the first two steps uses `minimap`, the third one uses a python script written by the developers of the pipeline, which can be found [here](https://github.com/nanoporetech/pipeline-structural-variation/blob/a5fec9407f24362c759630b5d331e47a76a9f107/lib/pipeline_structural_variation/sniffles_bamref2bed.py).
  
  After the pipeline calls `bamref2bed` i.e. the python script above, my `target.bed` looks like the following:
  
  ```
  chr1    0   249250621
  chr2    0   243199373
  chr3    0   198022430
  chr4    0   191154276
  chr5    0   180915260
  chr6    0   171115067
  chr7    0   159138663
  chr8    0   146364022
  chr9    0   141213431
  chr10   0   135534747
  chr11   0   135006516
  chr12   0   133851895
  chr13   0   115169878
  chr14   0   107349540
  chr15   0   102531392
  chr16   0   90354753
  chr17   0   81195210
  chr18   0   78077248
  chr19   0   59128983
  chr20   0   63025520
  chr21   0   48129895
  chr22   0   51304566
  chrX    0   155270560
  chrY    0   59373566
  
  ```
  
  As far as I am concerned the first three columns of a bed file refer to (I) chr name, (II) start position (III) end position. The main thing I am wondering is how come all chromosomes have a start position of 0. Also, reading about [converting bam to bed files](https://bedtools.readthedocs.io/en/latest/content/tools/genomecov.html) I guess the most important feature would be the coverage across the whole chromosomes, which in this file is missing.
  
  But my main question would be: is it normal to have a start position of 0 for all chromosomes or is there something wrong here?
  
  **Tags:** phylogenetics, nanopore, bed, long-reads, structural-variation
  
  > **Comments:**
  > **username_1**: BED intervals are usually zero-based, half-open indexed. Issues aside from whether these particular intervals are meaningful results, a starting position of 0 is entirely normal for a BED element. Cite: http://genome.ucsc.edu/blog/the-ucsc-genome-browser-coordinate-counting-systems/  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2019-10-22. Score: 4 | Accepted answer
  
  I cannot access the pipeline from nanopore, but looking at the [python script](https://github.com/nanoporetech/pipeline-structural-variation/blob/a5fec9407f24362c759630b5d331e47a76a9f107/lib/pipeline_structural_variation/sniffles_bamref2bed.py) you provided:
  
  ```
  with pysam.AlignmentFile(bam_file, "r") as bam:
      for tid in range(0, bam.nreferences):
          ref_name = bam.get_reference_name(tid)
          if len(list(filter(lambda x: x in ref_name, filter_names))) > 0:
              continue
  
          print(ref_name,
                "0",
                str(bam.get_reference_length(ref_name)),
                sep='\t')
  
  ```
  
  So the script gets the length of the chromosome and by default, outputs the start as 0.[Zero based coordinate system](http://genome.ucsc.edu/blog/the-ucsc-genome-browser-coordinate-counting-systems/) is sometimes used in UCSC systems, so I am only guessing the authors of the pipeline use this convention somewhere further down.
  
  As for the coverage you mentioned, that is usually output as a score in the 5th column ([bed format](https://genome.ucsc.edu/FAQ/FAQformat.html#format1)). In those situations, usually the coordinates of the alignments in the bam file are converted into bed format. In this pipeline, i think the authors are simply extracting the chromosome information out and putting it into a tabular form.
  
  > **Comments:**
  > **username_0**: Thanks, that's useful information, I was not aware of the zero based coordinate system. In fact I managed to find the other `.bed` file with the coverage per chromosome, so I guess the `.bed` file that I mentioned is only displaying the chromosomes length.  
  
  ---
  
  