0

I have a set of vcf files, each one has a string started with 'SRR'.e.g., in file1 I have the following line:

#CHROM  POS ID  REF ALT QUAL    FILTER  INFO    FORMAT  SRR2481146_1

In file2, I have:

 #CHROM POS ID  REF ALT QUAL    FILTER  INFO    FORMAT  SRR2481151_1

In file 3, I have:

 #CHROM POS ID  REF ALT QUAL    FILTER  INFO    FORMAT  SRR2481163_1

And I want to replace these strings with specific cell line names, e.g., replace 'SRR2481146_1' in file1 with 'HCT116_DMSO', replace 'SRR2481151_1' in file2 with 'SW_DMSO', replace 'SRR2481163_1' in file3 with 'COLO205'and so on.

i.e., for file1, the desired output should be :

 #CHROM POS ID  REF ALT QUAL    FILTER  INFO    FORMAT  HCT116_DMSO

And for file2:

 #CHROM POS ID  REF ALT QUAL    FILTER  INFO    FORMAT  SW_DMSO

I knew that I could do that individually using code like the following:

sed -i 's/SRR2481146_1/HCT116_DMSO/g' file1
sed -i 's/SRR2481151_1/SW_DMSO/g' file2

But since I have ~100 files, doing that would be too time-consuming.

Is there any good way?

Thanks!

closed as unclear what you're asking by RalfFriedl, jimmij, jsbillings, Archemar, Scott Feb 21 at 5:19

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Please, don't post images of text. – Kusalananda Feb 19 at 18:45
  • You have a VCF file. The strings, I assume, does not only occur in the VCF header, but could also occur in the annotated variations. You should post a text example of the places where the strings may occur, so that people that does not know about the VCF format may have a chance to help you. Also, you may want to ask real bioinformaticians at bioinformatics.stackexchange.com as they know of VCF parsers and bioinfo tools that could possibly be used. – Kusalananda Feb 19 at 18:49
  • Sorry @Kusalananda, I just replaced the image – Juan Xie Feb 19 at 19:28
1

As @Kusalananda wrote this is better asked on https://bioinformatics.stackexchange.com/ . Maybe someone can move this question to there?

Create a text file where in each line you write the old name and the desired new name delimited by a whitespace.

$ cat names.txt
SRR2481146_1 HCT116_DMSO
SRR2481151_1 SW_DMSO

Use bcftools reheader to change the sample names like this:

$ bcftools reheader -s names.txt file.vcf > file_renamed.vcf

You can use gnu parallel to run this command on all vcf files in a folder:

$ parallel 'bcftools reheader -s names.txt {} > {.}_renamed.vcf' ::: *.vcf
  • Thanks very much, @finswimmer! This is exactly what I am looking for. I will try your method. – Juan Xie Feb 19 at 19:27
  • @JuanXie If you're happy with the answer, upvote it. If it is solving your issue, accepting it would be the best way of saying "Thank You!" Accepting an answer also indicates to future readers that the answer actually solved the problem. – Kusalananda Feb 19 at 22:42
  • Hi finswimmer ! I tried bcftools on individual files and it worked well, yet for the parallel style I typed exactly the same code you showed but it didn't work. Is there anything that I need to change to make it work ? Thanks! – Juan Xie Feb 20 at 14:54
  • I used a for loop with bcftools and it worked, just curious about the parallel – Juan Xie Feb 20 at 14:56
  • What do you mean by "didn't work"? You can use the --dryrun parameter for parallel to see how the commands will look like. – finswimmer Feb 20 at 15:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.