<p>After some guidance from my advisor, this command allowed me to get the output file I needed.</p>
<pre><code>bcftools view -o newvcfFileName.g.vcf -s 123.2 locationOfTheFile chrom1 chrom2 ... chrom23(mito DNA) --force-samples
</code></pre>
<p>I listed every chromosome's title until I typed --force-samples. I found it simpler to copy and paste the names in.</p>

CC BY-SA 4.0
2023-09-22T17:18:58.923Z
2023-09-22T17:18:58.923Z
Lauren Sabo
<p>My objective is to take a g.vcf.gz file and from 25-30 unmapped contigs with titles like &quot;NW_020192317.1&quot;, I want to make a subset of ~10k variants from each of the unmapped contigs and make one final g.vcf file that includes the header from the original g.vcf.gz file.</p>
<p>From the post <a href="https://bioinformatics.stackexchange.com/questions/3565/subset-smaller-bam-to-contain-several-thousand-rows-from-multiple-chromosomes">here</a>, I have tried running:</p>
<pre><code>samtools view -bo output.g.vcf -s 123.4 inputfile.g.vcf.gz NW_020192317.1
</code></pre>
<p>and I keep receiving the output:</p>
<pre><code>Aborted (core dumped)
</code></pre>
<p>I'm not too picky about the number of variants per contig, as long as it is in the thousands, that's why I tried using &quot;.4&quot;</p>
<p>Alternatively, I tried using the code:</p>
<pre><code>samtools view input.g.vcf.gz &quot;NW_020192317.1:1-2&quot; &gt; output.g.vcf
</code></pre>
<p>and I recieved the same response of &quot;Aborted (core dumped)&quot; with nothing else. I am confused what is wrong here and why it is throwing an error.</p>

CC BY-SA 4.0
2023-09-14T20:21:54.747Z
You at least need to be using bcftools, not samtools, if you are working with vcf files. samtools is designed for bam/sam, not vcf, and that’s why it’s throwing that error
user438383
CC BY-SA 4.0
2023-09-15T08:29:19.337Z
Do you have a list of contigs of interest? Are those contig names the first field of the VCF? Does this need to be a _random_ selection or can you keep the first 10k variants from each contig?
terdon
CC BY-SA 4.0
2023-09-15T13:40:19.570Z
Also, gvcf files contain both variants non-variant lines. Do you only want variants?
terdon
<vcf><samtools><gatk><subset>
I am trying to create a subset of 10k variants from 25-30 unmapped contigs of a g.vcf file including the header
# I am trying to create a subset of 10k variants from 25-30 unmapped contigs of a g.vcf file including the header

(Asked by: username_0 on 2023-09-14)

My objective is to take a g.vcf.gz file and from 25-30 unmapped contigs with titles like "NW_020192317.1", I want to make a subset of ~10k variants from each of the unmapped contigs and make one final g.vcf file that includes the header from the original g.vcf.gz file.
From the post here, I have tried running:
samtools view -bo output.g.vcf -s 123.4 inputfile.g.vcf.gz NW_020192317.1

and I keep receiving the output:
Aborted (core dumped)

I'm not too picky about the number of variants per contig, as long as it is in the thousands, that's why I tried using ".4"
Alternatively, I tried using the code:
samtools view input.g.vcf.gz "NW_020192317.1:1-2" > output.g.vcf

and I recieved the same response of "Aborted (core dumped)" with nothing else. I am confused what is wrong here and why it is throwing an error.

**Tags:** vcf, samtools, gatk, subset
> **Comments:**
> **username_1**: You at least need to be using bcftools, not samtools, if you are working with vcf files. samtools is designed for bam/sam, not vcf, and that’s why it’s throwing that error  
> **username_2**: Do you have a list of contigs of interest? Are those contig names the first field of the VCF? Does this need to be a _random_ selection or can you keep the first 10k variants from each contig?  
> **username_2**: Also, gvcf files contain both variants non-variant lines. Do you only want variants?  

---

## 1 answers

### Answer by username_0 on 2023-09-22. Score: 3

After some guidance from my advisor, this command allowed me to get the output file I needed.
bcftools view -o newvcfFileName.g.vcf -s 123.2 locationOfTheFile chrom1 chrom2 ... chrom23(mito DNA) --force-samples

I listed every chromosome's title until I typed --force-samples. I found it simpler to copy and paste the names in.


---

