I have a pretty confusing file, with multiple delimiters and not the same order/number of fields between rows.
Columns V1 to V5 are fine but I want to extract from V9 the information from "Variant_seq", "Reference_seq" and the rsxxxx number from "Dbxref".
Another complication is that the "Variant_seq" and "Reference_seq" fields can either single characters ("A","T","C" or "G") or multiple ones comma separated (example "TTTT,TTC,GGGGGC"). These fields can be located either at the end or anywhere in the middle of V9.
V1 V2 V3 V4 V5 V9
9 dbSNP SNV 10007 10007 ID=1;Variant_seq=C;Dbxref=dbSNP_154:rs1449034754;evidence_values=Frequency,TOPMed;Reference_seq=T
9 dbSNP SNV 10009 10009 ID=2;Variant_seq=C,G;Dbxref=dbSNP_154:rs1587255763;evidence_values=Frequency;Reference_seq=A
9 dbSNP SNV 14824990 14824990 ID=30545117;Reference_seq=C;clinical_significance=benign;Variant_seq=GGGC,CCCCG;ancestral_allele=C;Dbxref=dbSNP_154:rs140144319;evidence_values=Frequency,1000Genomes,ESP,Phenotype_or_Disease,ExAC,TOPMed,gnomAD;global_minor_allele_frequency=1|0.004193|211
I originally thought of a awk -F '{print }' with multiple delimiters but quickly realized this wasn't a viable solution as fields aren't consistend across rows. dplyr::separate also isn't really adapted here.
I tried to extract each single field separately into a new column but the command doesn't handle the case where the fields are located at the end of the row:
gsub("Reference_seq[=]([^.]+)[;].*", "\\1", df$V9)
I can't find a solution to grep only the field in the capture group 1 and stop if there's no ";" following. Thanks for your help.