@@ -351,7 +351,9 @@ column of the same name.
351351
352352 CHROM; // "1"
353353 POS; // "11259340"
354+ ID; // "."
354355 REF; // "G"
356+ QUAL; // "."
355357
356358 ALT, FILTER
357359```````````
@@ -378,32 +380,86 @@ declared in the header.
378380 INFO.DP; // "795"
379381 INFO.ABC; // "4,5"
380382
381- INFO.DPR = "0.01"; // Will change the value of the DPR info field
382-
383383
384384 {SAMPLE\_ NAME}.{FORMAT\_ FIELD}
385385``````````````````````````````
386386
387387The JavaScript String prototype has been extended to allow access to the
388388format fields for each sample. The string representation of values in
389389the sample column are accessible as properties on the string matching
390- the sample name named after the ``FORMAT `` field ``ID `` These properties can
391- be assigned in order to make modifications. This will be undefined for fields
392- not declared in the header.
390+ the sample name named after the ``FORMAT `` field ``ID ``.
393391
394392.. code-block :: text
395393
396394 'NA12877'.GT; // "1/2"
397395 'NA12878'.GT; // "1/0"
396+
397+ Note that these properties are only defined for fields that are declared
398+ in the VCF header (any that are not declared in the header will be
399+ undefined). See below for how to add new ``INFO `` or ``FORMAT `` field
400+ declarations.
401+
402+
403+ VCF record modification
404+ ~~~~~~~~~~~~~~~~~~~~~~~
405+
406+ Most components of VCF records can be written or updated in a fairly
407+ natural manner by direct assignment in order to make modifications. For
408+ example:
409+
410+ .. code-block :: text
411+
412+ ID = "rs23987382"; // Will change the ID value
413+ QUAL = "50"; // Will change the QUAL value
414+ FILTER = "FAIL"; // Will set the FILTER value
415+ INFO.DPR = "0.01"; // Will change the value of the DPR info field
398416 'NA12877'.DP = "10"; // Will change the DP field of the NA12877 sample
399417
418+ Other components of the VCF record (such as ``CHROM ``, ``POS ``, ``REF ``,
419+ and ``ALT ``) are considered immutable and can not currently be altered.
420+
421+ Direct assignment to ``ID `` and ``FILTER `` fields accept either a string
422+ containing semicolon separated values, or a list of values. For example:
423+
424+ .. code-block :: text
425+
426+ ID = 'rs23987382;COSM3805';
427+ ID = ['rs23987382', 'COSM3805'];
428+ FILTER = 'BAZ;BANG';
429+ FILTER = ['BAZ', 'BANG'];
430+
431+
432+ Note that although the ``FILTER `` field returns an array when read, any
433+ changes made to this array directly are not reflected back into the VCF
434+ record.
435+
436+ Adding a filter to existing filters is a common operation and can be
437+ accomplished by the above assignment methods, for example by adding a
438+ value to the existing list and then setting the result:
439+
440+ .. code-block :: text
441+
442+ var f = FILTER;
443+ f.push('BOING');
444+ FILTER = f;
445+
446+ However, since this is a little unwieldy, a convenience function called
447+ `add() ` can be used (and may be chained):
448+
449+ .. code-block :: text
450+
451+ FILTER.add('BOING');
452+ FILTER.add(['BOING', 'DOING');
453+ FILTER.add('BOING').add('DOING');
454+
455+
400456 VCF header modification
401457~~~~~~~~~~~~~~~~~~~~~~~
402458
403- Functions are provided that allow the addition of new ``INFO `` or `` FORMAT ``
404- fields to the header and records. It is recommended that the following
405- functions only be used within the run-once portion of `` --javascript ``.
406- They may be called on every record, but this will be slow .
459+ Functions are provided that allow the addition of new ``FILTER ``,
460+ `` INFO `` and `` FORMAT `` fields to the header and records. It is
461+ recommended that the following functions only be used within the
462+ run-once portion of `` --javascript `` .
407463
408464ensureFormatHeader(FORMAT\_ HEADER\_ STRING)
409465``````````````````````````````````````````
@@ -429,6 +485,17 @@ corresponding accessor methods for use in record processing.
429485 ensureInfoHeader('##INFO=<ID=CT,Number=1,Type=Integer,' +
430486 'Description="Coverage threshold that was applied">');
431487
488+ ensureFilterHeader(FILTER\_ HEADER\_ STRING)
489+ ``````````````````````````````````````````
490+
491+ Add a new ``FILTER `` field to the VCF header if it is not already
492+ present. This will add an ``FILTER `` declaration line to the header.
493+
494+ .. code-block :: text
495+
496+ ensureFilterHeader('##INFO=<ID=FAIL_VAL,' +
497+ 'Description="Failed validation">');
498+
432499 Additional information and functions
433500~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
434501
@@ -450,6 +517,19 @@ Writes the provided string to standard output.
450517
451518 print('The samples are: ' + SAMPLES);
452519
520+ checkMinVersion(RTG_MINIMUM_VERSION)
521+ ````````````````````````````````````
522+
523+ Checks the version of RTG that the script is running under, and exits
524+ with an error message if the version of RTG does not meet the minimum
525+ required version. This is useful when distributing scripts that make use
526+ of features that are not present in earlier versions of RTG.
527+
528+ .. code-block :: text
529+
530+ checkMinVersion('3.9.2');
531+
532+
453533 .. seealso ::
454534 For javascript filtering usage and examples see :ref: `vcffilter `
455535
0 commit comments