This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Perl/Python script: phased vcf to phased tped

Hi All,

Who can share a perl/python script to transfer phased vcf to phased tped?

Thanks.


Update: plink will re-order the alleles therefore 'phase' status will be broken if plink was used in the data processing. Thanks for the explanation to it: the order in which the alleles appear in heterozygous genotype calls is usually determined by which allele is major/minor in the immediate dataset; this ordering will not vary between samples

vcf ped phased

Not answering your question but you have perhaps seen this.

Yes. I think there should be some wheels outside.

Wheels? That word does not make sense in this context. Could you explain using different words, maybe?

This is the correct 'answer'. If you care about representing genotype phase in text, use VCF.

Quote from PLINK docs:

The PED file is a white-space (space or tab) delimited file: the first six columns are mandatory:
     Family ID
     Individual ID
     Paternal ID
     Maternal ID
     Sex (1=male; 2=female; other=unknown)
     Phenotype

PED files do not hold genotype, phased or not, information. Are you sure you're asking the right question?

There are two prevalent PED formats - the one used/generated by plink has genotype information after the first six columns. The subset of this file with the first six columns alone is used in other tools, such as GATK's PhaseByTransmission, etc, and is the more prevalent one for clinical genetics usage. PLINK calls this format the .fam file.

Oops! Got confused with the .fam files. Thanks for the info!

2 answers

plink 1.9's core only handles .bed files. So --vcf causes a temporary .bed file to be generated, which does not contain any phase information. When a ped/tped is then exported from the .bed, the order in which the alleles appear in heterozygous genotype calls is usually determined by which allele is major/minor in the immediate dataset; this ordering will not vary between samples, and has nothing to do with the original phase status.

Great. Thanks Chris. Now. I see. That means plink changes the orders to keep the code for each individual is like same with in minor/major allele. Are you share about the vcftools --tped is same as what you said? Thanks.

It's basically irrelevant what vcftools --tped does, because phase is undefined in the tped format. You're effectively inventing your own file format and can't count on any software support from anyone else; much better to just write software that understands VCF, if you have to deal with text.

Meanwhile, please edit your top level answer to make it absolutely clear that it was incorrect.

Hi Chris, I think I will keep my post. I think my post is correct. Hope you can give further suggestion. I test it use 1000 genome data and use diff chr22.vcf.vcf.tped chr22.vcf.pl.tped to check the whole chr22. and it is totally same.

Could it be that just your example works by coincidence, but that the implementation (which chrchang523 obviously knows better than anyone else) does not guarantee phase information is preserved?

it should be not coincidence, the whole chr22 is totally allele order (phase status) in the tped compared with vcf. Let's wait for chrchang523's further comments. We will be the destination soon.

Part 2 is the one that matters, and I have already explained why that can't possibly work and your test must be flawed. plink is open source, and it is straightforward to verify that (i) .bed does not store phase info and (ii) the implementation of --recode only uses (temporary) .bed as input.

If you do not edit your answer within 24 hours, I will delete it.

Okay. I respect your suggestion and removed plink part. Just keep the 'vcftools --tped' part.

okay, maybe we can delete the whole post.

If you aren't going to delete the post, you need to explicitly mention that the plink test failed, after debugging your test if need be. It's the vcftools result that is meaningless, and can be deleted with no loss to anyone, since .tped is a plink file format; that's why the vcftools flag is called --plink-tped.

Moved this comment to an answer to make it clearer that there is incorrect advice in other answers.

Done. Just Share with you guys. I conducted a test on 1000 Genome chr22.

  1. transfer phased vcf to tped, the tped will keep the phase status, rigtht? Yes. it keeps the phased status

    vcftools --vcf test.vcf --plink-tped --out out

  2. use plink to creat tped, failed, yes. plink will re-order the alleles

    plink --vcf test.vcf --tped --out out

Did it work?

Thought plink could take VCF as input --vcf, --bcf?

Yes. I test it, it works. plink can take --vcf and --bcf as input. But I just want to get phased status and do some further analysis with R which I hope to take 'phased ped' as input. As chris said any files created by plink will remove phase status.

This doesn't work; Shicheng's test was faulty.

I am deeply worried that you come here to post an answer to your own question just 1 day after you had posted [the initial question], and you do this, repeatedly. Further, even in your answer, you indicate that neither you are sure that it actually works correctly.

Please show some greater responsibility and professionalism, Shicheng Guo

This comment made me curious so I went on a bit of an exploration. Turns out you're right. The following posts are self-answered, and many of them within a short period of the question being asked. A few of them even have answers as the next post based on biostars post ID (the ones with #answer_id added in the list below), and you know how hard that is to achieve in a site with users making multiple comments every minute.

Any comments on why this is the case, Shicheng Guo ?

Interesting. I cannot answer my own question?

Of course you can, and you should, if you find the answer to your own question. But the frequency with which it is done gives an impression that the answer is ready at the same time or minutes after the question is. Which is strange, given that one usually invests considerable effort before creating a post, and as far as immediate solutions go, it often happens that an answer becomes visible while creating the post (in the process of elucidating the problem), thereby making the post unnecessary.

I post it and hope to get some answer. and at same time, I will investigate it and then I find some result, and then I share with others, anything wrong?

I know this website is belong to you guys, but at least the freedom of the speaking should be guarantee, right?

This website belongs to everyone :-) so yes you are free to speak and write what you want.
Please keep in mind that if you ask a question here people will try to help you. If you come up with your own solution fairly quickly then we are not spending our time appropriately. If you have a question you cannot solve your self you are of course welcome to post it here. But if you have a problem which you know you will solve by tomorrow or in a couple of hours, it's maybe better to work on this on your own. You are clearly a contributor with a lot of experience.

Related to this, if you like to share your solutions to problems you encounter I would like to encourage you to start blogging, e.g. on wordpress. People who are searching for a solution to a problem will find your website and get back on track. That would be very valuable.

This is be the last post I put on you website.

You're taking this the wrong way. Your contributions are welcome, I'm only hoping you're not gaming the system.

I am sorry for the disrupt. I will delete them later.

Please do not go back and delete your posts, that is bad etiquette.

I have cleaned up this thread. It is good that everyone can share their opinion here, but I hope we can start fresh from now.

This is incorrect, and you should mark it as such.

Hi Chris, Can you show us some details when you coding the plinks to convert vcf to tped? Thanks. At least, from my small test dataset, I found the phase status is kept. However, it will be great if you can tell us some details about the plink when you coding. Thanks.

Let's take tped as example, since in the ped, it will be easy to shown.

Log in to answer this question.