Question: Copy Sample ID from VCF file to ID column
gravatar for waqasnayab
17 months ago by
waqasnayab180 wrote:


I have a VCF file. If any of the sample has genotype 0/1 and 1/1, than the sample ID of such genotype should be pasted into the ID column like (I am just putting here ID and sample column):

ID sample1 sample2 sample3
rs123456 0/0 0/1 0/1 
rs789101 1/1 0/0 0/1
rs11213145 0/0 1/1 0/0

My desired output would be:

ID sample1 sample2 sample3
rs123456:sample2:sample3 0/0 0/1 0/1 
rs789101:sample1:sample3 1/1 0/0 0/1
rs11213145:sample2 0/0 1/1 0/0

Any awk or sed would be helpful, searches available to copy the contents of the column to the desired column but not for header (as header here is sample1 etc)



sequencing snp next-gen genome • 667 views
ADD COMMENTlink modified 17 months ago by Pierre Lindenbaum117k • written 17 months ago by waqasnayab180
gravatar for Pierre Lindenbaum
17 months ago by
France/Nantes/Institut du Thorax - INSERM UMR1087
Pierre Lindenbaum117k wrote:

assuming your VCF is really a VCF file and using bioalcidae

 java -jar dist/bioalcidaejdk.jar  -e 'println("ID\t"+header.getSampleNamesInOrder().stream().collect(Collectors.joining("\t")));stream().filter(V->V.hasID()).forEach(V->println(V.getID()+":"+V.getGenotypes().stream().filter(G->G.isHet()||G.isHomVar()).map(G->G.getSampleName()).collect(Collectors.joining(":"))+"\t"+header.getSampleNamesInOrder().stream().map(S->V.getGenotype(S).getAlleles().stream().map(A->String.valueOf(V.getAlleleIndex(A))).collect(Collectors.joining("/"))).collect(Collectors.joining("\t"))));' input.vcf
ADD COMMENTlink written 17 months ago by Pierre Lindenbaum117k

YES, Pierre, it worked for me, although just cross-checking a bit, will further confirm this command...,,,!!!!!

ADD REPLYlink written 17 months ago by waqasnayab180
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 2128 users visited in the last hour