I am a beginner programming and was given a task, where certain strings from "INFO" column in a text file should be extracted using awk. Here is the code:
awk -F '\t' '/^[^#]/ {n=split($8,a,/[;]/); for(i=1;i<=n;i++) {if(a[i] ~ /^CLNDN=/) printf("%s\t",a[i]); else if(a[i] ~ /^CLNREVSTAT=/) printf("%s\t",a[i]); else if(a[i] ~ /^CLNSIG=/) printf("%s\t",a[i]);else if(a[i] ~ /^CLNSIGCONF=/) printf("%s\t",a[i]); else if(a[i] ~ /^ORIGIN=/) printf("%s\t",a[i]); } printf("\n");}' test.vcf > trial.vcf
The input file here:
1 879375 950448 C T . . ALLELEID=929884;CLNDISDB=MedGen:CN517202;CLNDN=not_provided;CLNHGVS=NC_000001.10:g.879375C>T;CLNREVSTAT=criteria_provided,_single_submitter;CLNSIG=Pathogenic;CLNVC=single_nucleotide_variant;CLNVCSO=SO:0001483;GENEINFO=SAMD11:148398;MC=SO:0001587|nonsense;ORIGIN=1
1 955619 210112 G C . . AF_EXAC=0.03475;AF_TGP=0.00879;ALLELEID=206690;CLNDISDB=MONDO:MONDO:0014052,MedGen:C3808739,OMIM:615120|MedGen:CN169374|MedGen:CN517202;CLNDN=Myasthenic_syndrome,_congenital,_8|not_specified|not_provided;CLNHGVS=NC_000001.10:g.955619G>C;CLNREVSTAT=criteria_provided,_conflicting_interpretations;CLNSIG=Conflicting_interpretations_of_pathogenicity;CLNSIGCONF=Benign(1),Likely_benign(2),Uncertain_significance(1);CLNVC=single_nucleotide_variant;CLNVCSO=SO:0001483;GENEINFO=AGRN:375790;MC=SO:0001583|missense_variant;ORIGIN=1;RS=201073369
Below, you can see the example output what I want to get.
CLNDN=not_provided CLNREVSTAT=criteria_provided,_single_submitter CLNSIG=Pathogenic ORIGIN=1
CLNDN=Myasthenic_syndrome,_congenital,_8|not_specified|not_provided CLNREVSTAT=criteria_provided,_conflicting_interpretations CLNSIG=Conflicting_interpretations_of_pathogenicity CLNSIGCONF=Benign(1),Likely_benign(2),Uncertain_significance(1) ORIGIN=1
There is a gap between CLNSIG and ORIGIN in the first line because this line does not contain CLNSIGCONF= information. Here, I would like to extract strings starting with CLDN=, CLNREVSTAT=, CLNSIG=, CLNSIGCONF= and ORIGIN=, and print them into column1-5 in output file, respectively. The code is able to extract the interests but I am stuck on printing them into specified columns.
I would be very appreciated if you could help me out (And very open to any suggestion).
Thank you very much in advance.