text: user11900: I mapped raw reads obtained from an E. coli genome (.fastq file) to my reference genome. Next, I exported the .vcf (variant calling file), which looks something like the header example shown below (total >50 lines):
  #CHROM  POS ID  REF ALT QUAL    FILTER  INFO    FORMAT  Variants:_LGC19-XL01_S63_L001_R_001_(trimmed)
  CFC381_K12_Bw25113  360287  .   GGGAAT  AATTCC  1952.76 .   NS=1;VF=0.380;SB=0.533;SB50=0.60;SB65=1.0;TYPE=Substitution;AVQUAL=30   DP:AO   231:89
  
  How can I back-fill or quickly assign the missing GTs to the .vcf ?
  For my downstream process (plink --pca, via bfctools merge), I need that there are GT entries in every .vcf, so I can merge them and the respective GT is shown in the merged .vcf. I only found solutions that need the .bam file, but that is laborious and I don't think I need the .bam in the case of haploid data.
  
  This method needs .bam: https://www.biostars.org/p/319304/
  This method needs .fastq: https://training.galaxyproject.org/training-material/topics/variant-analysis/tutorials/non-dip/tutorial.html#examining-the-results
  
  However, the.fastq is actually from a mixed culture, so I wonder do I really need to follow the .bam-strategy? Suggestion for a tool? But in that case, why did it not export the GTs in the fist place (I exported from "geneious" sequence analysis program)
  
  user298: The representation for a variant present in a haploid genome should be 1. A heterozygote in a diploid genome would be 0/1 (or 0|1 or 1|0  if phased). So, to add a 1 as the genotype, you would need to first insert a GT to the beginning of each INFO line and then the 1 at the beginning of the last field. But, this should happen only on lines that are not headers (do not start with #). This should do it:
  $ awk -F'\t' -v OFS="\t" '{ if(/^#/){print}else{$9="GT:"$9;$10="1:"$10;print}}' file.vcf 
  #CHROM  POS ID  REF ALT QUAL    FILTER  INFO    FORMAT  Variants:_LGC19-XL01_S63_L001_R_001_(trimmed)
  CFC381_K12_Bw25113  360287  .   GGGAAT  AATTCC  1952.76 .   NS=1;VF=0.380;SB=0.533;SB50=0.60;SB65=1.0;TYPE=Substitution;AVQUAL=30   GT:DP:AO    1:231:89
  
  So just redirect the output to a fixed file:
  $ awk -F'\t' -v OFS="\t" '{ if(/^#/){print}else{$9="GT:"$9;$10="1:"$10;print}}' file.vcf > fixed.vcf
  
  Now, in this specific case, you could also do something like this:
  $ sed -i.bak '/^[^#]/{s/\<DP:AO\t/GT:DP:AO\t1:/}' file.vcf 
  
  But that assumes that all lines will have the exact same INFO field of DP:AO which is not a safe assumption since each variant can have different INFO fields.
  
original_text: 11900: <p>I mapped raw reads obtained from an E. coli genome (.fastq file) to my reference genome. Next, I exported the .vcf (variant calling file), which looks something like the header example shown below (total &gt;50 lines):</p>
  <pre><code>#CHROM  POS ID  REF ALT QUAL    FILTER  INFO    FORMAT  Variants:_LGC19-XL01_S63_L001_R_001_(trimmed)
  CFC381_K12_Bw25113  360287  .   GGGAAT  AATTCC  1952.76 .   NS=1;VF=0.380;SB=0.533;SB50=0.60;SB65=1.0;TYPE=Substitution;AVQUAL=30   DP:AO   231:89
  </code></pre>
  <p><strong>How can I back-fill or quickly assign the missing GTs to the <code>.vcf</code> ?</strong></p>
  <p>For my downstream process (<code>plink --pca</code>, via <code>bfctools merge</code>), I need that there are GT entries in every <code>.vcf</code>, so I can merge them and the respective GT is shown in the merged <code>.vcf</code>. I only found solutions that need the <code>.bam</code> file, but that is laborious and I don't think I need the <code>.bam</code> in the case of haploid data.</p>
  <ul>
  <li>This method needs <code>.bam</code>: <a href="https://www.biostars.org/p/319304/" rel="nofollow noreferrer">https://www.biostars.org/p/319304/</a></li>
  <li>This method needs <code>.fastq</code>: <a href="https://training.galaxyproject.org/training-material/topics/variant-analysis/tutorials/non-dip/tutorial.html#examining-the-results" rel="nofollow noreferrer">https://training.galaxyproject.org/training-material/topics/variant-analysis/tutorials/non-dip/tutorial.html#examining-the-results</a></li>
  </ul>
  <p>However, the<code>.fastq</code> is actually from a mixed culture, so I wonder do I really need to follow the <code>.bam</code>-strategy? Suggestion for a tool? But in that case, why did it not export the GTs in the fist place (I exported from &quot;geneious&quot; sequence analysis program)</p>
   298: <p>The representation for a variant present in a haploid genome should be <code>1</code>. A heterozygote in a diploid genome would be <code>0/1</code> (or <code>0|1</code> or <code>1|0</code>  if phased). So, to add a <code>1</code> as the genotype, you would need to first insert a <code>GT</code> to the beginning of each INFO line and then the <code>1</code> at the beginning of the last field. But, this should happen only on lines that are not headers (do not start with <code>#</code>). This should do it:</p>
  <pre><code>$ awk -F'\t' -v OFS=&quot;\t&quot; '{ if(/^#/){print}else{$9=&quot;GT:&quot;$9;$10=&quot;1:&quot;$10;print}}' file.vcf 
  #CHROM  POS ID  REF ALT QUAL    FILTER  INFO    FORMAT  Variants:_LGC19-XL01_S63_L001_R_001_(trimmed)
  CFC381_K12_Bw25113  360287  .   GGGAAT  AATTCC  1952.76 .   NS=1;VF=0.380;SB=0.533;SB50=0.60;SB65=1.0;TYPE=Substitution;AVQUAL=30   GT:DP:AO    1:231:89
  </code></pre>
  <p>So just redirect the output to a fixed file:</p>
  <pre><code>$ awk -F'\t' -v OFS=&quot;\t&quot; '{ if(/^#/){print}else{$9=&quot;GT:&quot;$9;$10=&quot;1:&quot;$10;print}}' file.vcf &gt; fixed.vcf
  </code></pre>
  <p>Now, in this specific case, you could also do something like this:</p>
  <pre><code>$ sed -i.bak '/^[^#]/{s/\&lt;DP:AO\t/GT:DP:AO\t1:/}' file.vcf 
  </code></pre>
  <p>But that assumes that all lines will have the exact same INFO field of <code>DP:AO</code> which is not a safe assumption since each variant can have different INFO fields.</p>
  