{"id":411,"date":"2020-11-02T21:00:59","date_gmt":"2020-11-02T20:00:59","guid":{"rendered":"https:\/\/itrop.ird.fr\/wordpress\/?page_id=411"},"modified":"2022-04-06T14:50:46","modified_gmt":"2022-04-06T12:50:46","slug":"vcfextract","status":"publish","type":"page","link":"https:\/\/bioinfo.ird.fr\/index.php\/tutorials-fr\/vcfextract\/","title":{"rendered":"Tutorials &#8211; vcfExtract"},"content":{"rendered":"<h2>Commands to manipulate VCF files<\/h2>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: left;\">Name<\/th>\n<th style=\"text-align: left;\">Commands to manipulate VCF files.<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: left;\">Description<\/td>\n<td style=\"text-align: left;\">This page describes a serie of tools and linux commands used to manipulate VCF files.<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">Authors<\/td>\n<td style=\"text-align: left;\">christine Tranchant-Dubreuil (christine.tranchant@ird.fr)<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">Creation Date<\/td>\n<td style=\"text-align: left;\">10\/03\/2017<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">Last Modified Date<\/td>\n<td style=\"text-align: left;\">25\/03\/2018<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>We need, in this tutorial:<\/p>\n<ul>\n<li>1 vcf file<\/li>\n<li>GATK tools<\/li>\n<li>bcftools<\/li>\n<\/ul>\n<h3>Keywords<\/h3>\n<p><code>gatk<\/code>,<code>bcftools<\/code><\/p>\n<hr \/>\n<h3>Summary<\/h3>\n<ul>\n<li><a href=\"#sample-list\">Extracting list of samples from a vcf file<\/a>\n<ul>\n<li><a href=\"#sample-list1\">one line with all samples with <code>grep<\/code><\/a><\/li>\n<li><a href=\"#sample-list1\">one line by sample with <code>grep | cut | xargs<\/code><\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#sample-from-vcf-gatk\">Extracting a subset of samples from a multigenome vcf file<\/a>\n<ul>\n<li><a href=\"#sample-from-vcf-gatk1\">Select two samples out of a vcf with many samples with <code>GATK selectVariants<\/code><\/a><\/li>\n<li><a href=\"#sample-from-vcf-gatk2\">Select genotypes from a file containing a list of samples to include with <code>GATK selectVariants<\/code><\/a><\/li>\n<li><a href=\"#sample-from-vcf-gatk3\">Select genotypes from a file containing a list of samples to exclude with <code>GATK selectVariants<\/code><\/a><\/li>\n<li><a href=\"#sample-from-vcf-bcftools1\">Select genotypes from a file containing a list of samples to include with <code>bcftools<\/code><\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#calculating-pi\">Calculating the nucleotide diversity from a vcf file with <code>vcftools<\/code><\/a><\/li>\n<\/ul>\n<hr \/>\n<p><a name=\"sample-list\"><\/a><\/p>\n<h3>Extracting list of samples from a vcf file<\/h3>\n<p><a name=\"sample-list1\"><\/a><\/p>\n<h5>one line with all samples with <code>grep<\/code><\/h5>\n<pre><code>$grep &quot;#CHROM&quot; output | cut -f 10-<\/code><\/pre>\n<p><a name=\"sample-list2\"><\/a><\/p>\n<h5>one line by sample with <code>grep | cut | xargs<\/code><\/h5>\n<pre><code>$grep &quot;#CHROM&quot; output | cut -f 10- | xargs -n 1\n#Getting the sample number\n$grep &quot;#CHROM&quot; output | cut -f 10- | xargs -n 1 | wc -l<\/code><\/pre>\n<hr \/>\n<p><a name=\"sample-from-vcf-gatk\"><\/a><\/p>\n<h3>Extracting a subset of samples from a multigenome vcf file<\/h3>\n<p><a name=\"sample-from-vcf-gatk1\"><\/a><\/p>\n<h5>Select two samples out of a vcf with many samples with <code>GATK selectVariants<\/code><\/h5>\n<pre><code>java -Xmx12g -jar \/usr\/local\/gatk-3.6\/GenomeAnalysisTK.jar -T SelectVariants -R reference.fa -V inputFileName.vcf -o outputFilename.vcf -sn sample1 -sn sample2<\/code><\/pre>\n<blockquote>\n<p>Rk : if you get the following error message &quot;<em>Fasta dict file ... for reference ... does not exist<\/em>&quot;, please see <a href=\"https:\/\/www.broadinstitute.org\/gatk\/guide\/article?id=1601\">https:\/\/www.broadinstitute.org\/gatk\/guide\/article?id=1601<\/a><\/p>\n<\/blockquote>\n<p><a name=\"sample-from-vcf-gatk2\"><\/a><\/p>\n<h5>Select genotypes from a file containing a list of samples to include with <code>GATK selectVariants<\/code><\/h5>\n<pre><code>java -Xmx12g -jar \/usr\/local\/gatk-3.6\/GenomeAnalysisTK.jar -T SelectVariants -R reference.fa -V inputFileName.vcf -o outputFileName.vcf --sample_file barthii.only.RG.list  --ALLOW_NONOVERLAPPING_COMMAND_LINE_SAMPLES<\/code><\/pre>\n<p><a name=\"sample-from-vcf-gatk3\"><\/a><\/p>\n<h5>Select genotypes from a file containing a list of samples to exclude with <code>GATK selectVariants<\/code><\/h5>\n<pre><code>java -Xmx12g -jar \/usr\/local\/gatk-3.6\/GenomeAnalysisTK.jar -T SelectVariants -R reference.fa -V inputFileName.vcf -o outputFileName.vcf --exclude_sample_file barthii.only.RG.list  --ALLOW_NONOVERLAPPING_COMMAND_LINE_SAMPLES<\/code><\/pre>\n<blockquote>\n<p>Rk : if you get the following error message : &quot;<em>Bad input: Samples entered on command line (through -sf or -sn)) that are not present in the VCF<\/em>&quot;, run with --ALLOW_NONOVERLAPPING_COMMAND_LINE_SAMPLES<\/p>\n<\/blockquote>\n<p><a name=\"sample-from-vcf-bcftools1\"><\/a><\/p>\n<h5>Select genotypes from a file containing a list of samples to include with <code>bcftools<\/code><\/h5>\n<pre><code>bcftools view -S barthii.only.RG.list inputFileName.vcf --force-samples -o outputFilename.vcf<\/code><\/pre>\n<hr \/>\n<p><a name=\"calculating-pi\"><\/a><\/p>\n<h3>Calculating the nucleotide diversity from a vcf file with <code>vcftools<\/code><\/h3>\n<pre><code>vcftools --vcf inputFilename.vcf  --out outputFilename.PI  --window-pi 100000 --remove-filtered-all<\/code><\/pre>\n<pre><code>grep &quot;PI&quot; OgOb-all-MSU7-CHR2.GATKSV.VCFTOOLS.stats-100000.windowed.pi -v | awk &#039;{ sum+=$5; print $5,&quot;; &quot;,sum , &quot;* &quot;, NR ; } END { print &quot;PI average :&quot;, sum \/ NR; }&#039;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Commands to manipulate VCF files Name Commands to manipulate VCF files. Description This page describes a serie of tools and&hellip; <br \/> <a class=\"read-more\" href=\"https:\/\/bioinfo.ird.fr\/index.php\/tutorials-fr\/vcfextract\/\">Lire la suite<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1325,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"footnotes":""},"class_list":["post-411","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Tutorials - vcfExtract - itrop<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/bioinfo.ird.fr\/index.php\/tutorials-fr\/vcfextract\/\" \/>\n<meta property=\"og:locale\" content=\"fr_FR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Tutorials - vcfExtract - itrop\" \/>\n<meta property=\"og:description\" content=\"Commands to manipulate VCF files Name Commands to manipulate VCF files. Description This page describes a serie of tools and&hellip; Lire la suite\" \/>\n<meta property=\"og:url\" content=\"https:\/\/bioinfo.ird.fr\/index.php\/tutorials-fr\/vcfextract\/\" \/>\n<meta property=\"og:site_name\" content=\"itrop\" \/>\n<meta property=\"article:modified_time\" content=\"2022-04-06T12:50:46+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@ItropBioinfo\" \/>\n<meta name=\"twitter:label1\" content=\"Dur\u00e9e de lecture estim\u00e9e\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/bioinfo.ird.fr\/index.php\/tutorials-fr\/vcfextract\/\",\"url\":\"https:\/\/bioinfo.ird.fr\/index.php\/tutorials-fr\/vcfextract\/\",\"name\":\"Tutorials - vcfExtract - itrop\",\"isPartOf\":{\"@id\":\"https:\/\/bioinfo.ird.fr\/#website\"},\"datePublished\":\"2020-11-02T20:00:59+00:00\",\"dateModified\":\"2022-04-06T12:50:46+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/bioinfo.ird.fr\/index.php\/tutorials-fr\/vcfextract\/#breadcrumb\"},\"inLanguage\":\"fr-FR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/bioinfo.ird.fr\/index.php\/tutorials-fr\/vcfextract\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/bioinfo.ird.fr\/index.php\/tutorials-fr\/vcfextract\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/bioinfo.ird.fr\/index.php\/en\/front-page-2\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Tutorials &#8211; FR\",\"item\":\"https:\/\/bioinfo.ird.fr\/index.php\/tutorials-fr\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Tutorials &#8211; vcfExtract\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/bioinfo.ird.fr\/#website\",\"url\":\"https:\/\/bioinfo.ird.fr\/\",\"name\":\"itrop\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/bioinfo.ird.fr\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/bioinfo.ird.fr\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"fr-FR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/bioinfo.ird.fr\/#organization\",\"name\":\"i-Trop\",\"url\":\"https:\/\/bioinfo.ird.fr\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"fr-FR\",\"@id\":\"https:\/\/bioinfo.ird.fr\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/bioinfo.ird.fr\/wp-content\/uploads\/2021\/10\/i-tropTwt5.png\",\"contentUrl\":\"https:\/\/bioinfo.ird.fr\/wp-content\/uploads\/2021\/10\/i-tropTwt5.png\",\"width\":1356,\"height\":1356,\"caption\":\"i-Trop\"},\"image\":{\"@id\":\"https:\/\/bioinfo.ird.fr\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/ItropBioinfo\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Tutorials - vcfExtract - itrop","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/bioinfo.ird.fr\/index.php\/tutorials-fr\/vcfextract\/","og_locale":"fr_FR","og_type":"article","og_title":"Tutorials - vcfExtract - itrop","og_description":"Commands to manipulate VCF files Name Commands to manipulate VCF files. Description This page describes a serie of tools and&hellip; Lire la suite","og_url":"https:\/\/bioinfo.ird.fr\/index.php\/tutorials-fr\/vcfextract\/","og_site_name":"itrop","article_modified_time":"2022-04-06T12:50:46+00:00","twitter_card":"summary_large_image","twitter_site":"@ItropBioinfo","twitter_misc":{"Dur\u00e9e de lecture estim\u00e9e":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/bioinfo.ird.fr\/index.php\/tutorials-fr\/vcfextract\/","url":"https:\/\/bioinfo.ird.fr\/index.php\/tutorials-fr\/vcfextract\/","name":"Tutorials - vcfExtract - itrop","isPartOf":{"@id":"https:\/\/bioinfo.ird.fr\/#website"},"datePublished":"2020-11-02T20:00:59+00:00","dateModified":"2022-04-06T12:50:46+00:00","breadcrumb":{"@id":"https:\/\/bioinfo.ird.fr\/index.php\/tutorials-fr\/vcfextract\/#breadcrumb"},"inLanguage":"fr-FR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/bioinfo.ird.fr\/index.php\/tutorials-fr\/vcfextract\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/bioinfo.ird.fr\/index.php\/tutorials-fr\/vcfextract\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/bioinfo.ird.fr\/index.php\/en\/front-page-2\/"},{"@type":"ListItem","position":2,"name":"Tutorials &#8211; FR","item":"https:\/\/bioinfo.ird.fr\/index.php\/tutorials-fr\/"},{"@type":"ListItem","position":3,"name":"Tutorials &#8211; vcfExtract"}]},{"@type":"WebSite","@id":"https:\/\/bioinfo.ird.fr\/#website","url":"https:\/\/bioinfo.ird.fr\/","name":"itrop","description":"","publisher":{"@id":"https:\/\/bioinfo.ird.fr\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/bioinfo.ird.fr\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"fr-FR"},{"@type":"Organization","@id":"https:\/\/bioinfo.ird.fr\/#organization","name":"i-Trop","url":"https:\/\/bioinfo.ird.fr\/","logo":{"@type":"ImageObject","inLanguage":"fr-FR","@id":"https:\/\/bioinfo.ird.fr\/#\/schema\/logo\/image\/","url":"https:\/\/bioinfo.ird.fr\/wp-content\/uploads\/2021\/10\/i-tropTwt5.png","contentUrl":"https:\/\/bioinfo.ird.fr\/wp-content\/uploads\/2021\/10\/i-tropTwt5.png","width":1356,"height":1356,"caption":"i-Trop"},"image":{"@id":"https:\/\/bioinfo.ird.fr\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/ItropBioinfo"]}]}},"_links":{"self":[{"href":"https:\/\/bioinfo.ird.fr\/index.php\/wp-json\/wp\/v2\/pages\/411","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bioinfo.ird.fr\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/bioinfo.ird.fr\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/bioinfo.ird.fr\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bioinfo.ird.fr\/index.php\/wp-json\/wp\/v2\/comments?post=411"}],"version-history":[{"count":2,"href":"https:\/\/bioinfo.ird.fr\/index.php\/wp-json\/wp\/v2\/pages\/411\/revisions"}],"predecessor-version":[{"id":740,"href":"https:\/\/bioinfo.ird.fr\/index.php\/wp-json\/wp\/v2\/pages\/411\/revisions\/740"}],"up":[{"embeddable":true,"href":"https:\/\/bioinfo.ird.fr\/index.php\/wp-json\/wp\/v2\/pages\/1325"}],"wp:attachment":[{"href":"https:\/\/bioinfo.ird.fr\/index.php\/wp-json\/wp\/v2\/media?parent=411"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}