Answers.Body: <p>The command you're looking for is:</p>
  
  <pre><code>samtools view -c http://ftp.1000genomes.ebi.ac.uk/vol1/ftp/phase3/data/HG01375/alignment/HG01375.mapped.ILLUMINA.bwa.CLM.low_coverage.20120522.bam 2:1000000-2000000
  </code></pre>
  
  <p>For a series of intervals, you'd be better off scripting something with pysam:</p>
  
  <pre class="lang-py prettyprint-override"><code>import pysam
  bam = pysam.AlignmentFile("some file.bam")
  regions = open("your regions.bed")
  for region in regions:
      chrom, start, end = region.split("\t")
       bam.count(chrom, int(start), int(end))  # Do something with the result
  </code></pre>
  
  <p>You might see if there are bigWig files available, they'd be faster to process.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-23T21:18:59.590Z
Answers.Text: ,thanks. I could rum the sam tools command for a single file. Thanks for the pysam, I will try it. But do you know how can I run a samtools command through a loop? just to remind that I do not have bam files downloaded.
Answers.UserDisplayName: Anna1364
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-23T21:20:14.813Z
Answers.Text: You can do `for` loops in bash. It can be pretty painful to script anything complicated in bash, though.
Answers.UserDisplayName: Devon Ryan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-23T21:46:14.437Z
Answers.Text: yes, I know the for loop solution. my problem is that the bam files for each individual are in separate folders. I am trying this: for file in http://ftp.1000genomes.ebi.ac.uk/vol1/ftp/phase3/data/*/alignment/*.bam;
  do /data/programs/samtools-1.3.1/samtools view -c "${file}" 2:1000000-2000000
  done       but get an error message.
Answers.UserDisplayName: Anna1364
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-23T22:17:54.123Z
Answers.Text: You can't wild-card URLs, you'll need to provide them as a list.
Answers.UserDisplayName: Devon Ryan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-24T08:18:49.783Z
Answers.Text: @Anna1364 please add all this information to your question. We can't answer you if you don't tell us all the details. Give us a list of the files you want to read and explain what you need to do with those files.
Answers.UserDisplayName: terdon
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-23T20:36:53.930Z
Answers.LastActivityDate: 2018-04-23T20:36:53.930Z
Answers.UserDisplayName: Devon Ryan
Body: <p>I want to compute the depth of coverage only for specific intervals in phase 3, 1000 genomes project.I have not worked with 1000 genomes project before, so a bit unfamiliar with it. I do not want to download all of the bam files for the entire genomic region, just those intervals which I am interested in them.
  I guess I can use this (I found from biostars forum)</p>
  
  <pre><code>samtools -bu view 'http://ftp.1000genomes.ebi.ac.uk/vol1/ftp/phase3/data/HG01375/alignment/HG01375.mapped.ILLUMINA.bwa.CLM.low_coverage.20120522.bam' "2:1000000-2000000" | (...)
  </code></pre>
  
  <p>However, I am just a bit confused. First of all, when I try the code above directly from the command line, I get an error message "No such file or directory"! Am I doing something wrong? or should I provide a specific path?
  Second, I want to run  it for the mapped files for all individuals: <code>*.bam”.</code> through a loop. </p>
  
  <p>Can anyone help me to solve my problem?</p>
  
Tags: <sam><samtools>
Title: running a samtools command for multiple bam files from 1000 genomes project
ThreadText: # running a samtools command for multiple bam files from 1000 genomes project
  
  (Asked by: username_0 on 2018-04-23)
  
  I want to compute the depth of coverage only for specific intervals in phase 3, 1000 genomes project.I have not worked with 1000 genomes project before, so a bit unfamiliar with it. I do not want to download all of the bam files for the entire genomic region, just those intervals which I am interested in them.
  I guess I can use this (I found from biostars forum)
  
  ```
  samtools -bu view 'http://ftp.1000genomes.ebi.ac.uk/vol1/ftp/phase3/data/HG01375/alignment/HG01375.mapped.ILLUMINA.bwa.CLM.low_coverage.20120522.bam' "2:1000000-2000000" | (...)
  
  ```
  
  However, I am just a bit confused. First of all, when I try the code above directly from the command line, I get an error message "No such file or directory"! Am I doing something wrong? or should I provide a specific path?
  Second, I want to run it for the mapped files for all individuals: `*.bam”.` through a loop.
  
  Can anyone help me to solve my problem?
  
  **Tags:** sam, samtools
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-04-23. Score: 1
  
  The command you're looking for is:
  
  ```
  samtools view -c http://ftp.1000genomes.ebi.ac.uk/vol1/ftp/phase3/data/HG01375/alignment/HG01375.mapped.ILLUMINA.bwa.CLM.low_coverage.20120522.bam 2:1000000-2000000
  
  ```
  
  For a series of intervals, you'd be better off scripting something with pysam:
  
  ```py
  import pysam
  bam = pysam.AlignmentFile("some file.bam")
  regions = open("your regions.bed")
  for region in regions:
      chrom, start, end = region.split("\t")
       bam.count(chrom, int(start), int(end))  # Do something with the result
  
  ```
  
  You might see if there are bigWig files available, they'd be faster to process.
  
  > **Comments:**
  > **username_0**: ,thanks. I could rum the sam tools command for a single file. Thanks for the pysam, I will try it. But do you know how can I run a samtools command through a loop? just to remind that I do not have bam files downloaded.  
  > **username_1**: You can do `for` loops in bash. It can be pretty painful to script anything complicated in bash, though.  
  > **username_0**: yes, I know the for loop solution. my problem is that the bam files for each individual are in separate folders. I am trying this: for file in http://ftp.1000genomes.ebi.ac.uk/vol1/ftp/phase3/data/*/alignment/*.bam; do /data/programs/samtools-1.3.1/samtools view -c "${file}" 2:1000000-2000000 done       but get an error message.  
  > **username_1**: You can't wild-card URLs, you'll need to provide them as a list.  
  > **username_2**: @username_0 please add all this information to your question. We can't answer you if you don't tell us all the details. Give us a list of the files you want to read and explain what you need to do with those files.  
  
  ---
  
  