text: user10677: I am currently asking myself how to rename samples in a vcf file. This is necessary, because the naming of several samples included in thr vcf file was unfortunately not be chosen by me.
  I am loading the vcf file via readVcf() from the VariantAnnotation package in R.
  To check the sample names, i can use samples(header(vcf.file)), which will give me the names as characters.
  It looks like this:
  
  and so on..
  (I am actually very sorry that i cannot give a reproducible example here :( )
  I also have a vector with all the new names. For example
  new.names <- c("1","2","3","4")
  
  I tried to exchange the "old names" with the new.names vector:
  samples(header(vcf.file)) <- new.names
  
  which leads to the error
  Error in samples(header(data.vcf)) <- names.sample :
  could not find function "samples<-"
  I also tried to use the rutilstimflutre package, which has a already designed function for this, but unfortunately the package is outdated and not available for the newest R version.
  Is there a way to do this? Perhaps a better way to assign the new names to the old ones?
  Thanks a lot.
  
  user3694: Easiest to use bcftools, if samples.txt has the new sample names:
  bcftools reheader -s samples.txt -o new.bcf old.bcf
  
  
original_text: 10677: <p>I am currently asking myself how to rename samples in a vcf file. This is necessary, because the naming of several samples included in thr vcf file was unfortunately not be chosen by me.</p>
  <p>I am loading the vcf file via <code>readVcf()</code> from the <code>VariantAnnotation</code> package in R.</p>
  <p>To check the sample names, i can use <code>samples(header(vcf.file))</code>, which will give me the names as characters.</p>
  <p>It looks like this:</p>
  <p><a href="https://i.stack.imgur.com/nSsBq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nSsBq.png" alt="enter image description here" /></a></p>
  <p>and so on..</p>
  <p>(I am actually very sorry that i cannot give a reproducible example here :( )</p>
  <p>I also have a vector with all the new names. For example</p>
  <pre><code>new.names &lt;- c(&quot;1&quot;,&quot;2&quot;,&quot;3&quot;,&quot;4&quot;)
  </code></pre>
  <p>I tried to exchange the &quot;old names&quot; with the new.names vector:</p>
  <pre><code>samples(header(vcf.file)) &lt;- new.names
  </code></pre>
  <p>which leads to the error
  Error in samples(header(data.vcf)) &lt;- names.sample :
  could not find function &quot;samples&lt;-&quot;</p>
  <p>I also tried to use the <code>rutilstimflutre</code> package, which has a already designed function for this, but unfortunately the package is outdated and not available for the newest R version.</p>
  <p>Is there a way to do this? Perhaps a better way to assign the new names to the old ones?</p>
  <p>Thanks a lot.</p>
   3694: <p>Easiest to use <code>bcftools</code>, if <code>samples.txt</code> has the new sample names:</p>
  <pre><code>bcftools reheader -s samples.txt -o new.bcf old.bcf
  </code></pre>
  