@@ -17,7 +17,8 @@ to a dictionary model.
1717 {' id' : ' NG_012337.1' , ' selector' : {' id' : ' SDHD_v001' }}
1818
1919
20- An alternative start rule for the grammar can be used.
20+ An alternative start rule can be used to parse a partial description.
21+ See :doc: `usage ` for the list of available start rules.
2122
2223.. code :: python
2324
@@ -27,16 +28,64 @@ An alternative start rule for the grammar can be used.
2728 {' location' : {' type' : ' point' , ' position' : 274 }, ' type' : ' deletion' , ' source' : ' reference' }
2829
2930
31+ The ``"source" `` field
32+ ----------------------
33+
34+ The ``"source" `` field indicates where a sequence or location originates:
35+
36+ ``"description" ``
37+ The sequence is written explicitly in the HGVS string.
38+
39+ .. code :: python
40+
41+ >> > to_model(' 274G>T' , ' variant' )[' deleted' ]
42+ [{' sequence' : ' G' , ' source' : ' description' }]
43+
44+ ``"reference" ``
45+ The sequence or location is implied by HGVS convention; it must be
46+ retrieved from the (same) reference sequence.
47+
48+ .. code :: python
49+
50+ >> > to_model(' 274del' , ' variant' )[' source' ]
51+ ' reference'
52+
53+ >> > to_model(' NG_012337.1:g.274_275ins100_200' )[' variants' ][0 ][' inserted' ]
54+ [{' location' : {... }, ' source' : ' reference' }]
55+
56+ ``{"id": "..."} ``
57+ The sequence comes from an explicitly named external reference.
58+
59+ .. code :: python
60+
61+ >> > to_model(' NG_012337.1:g.274_275insNG_012337.3:g.100_200' )[' variants' ][0 ][' inserted' ]
62+ [{' type' : ' description_dna' , ... , ' source' : {' id' : ' NG_012337.3' }, ... }]
63+
64+
3065 The ``parse() `` function
3166------------------------
3267
33- The ``parse() `` function can be used to parse for syntax correctness purposes
34- an HGVS description. Its output is a lark parse tree.
68+ The ``parse() `` function checks whether a description is syntactically valid
69+ and raises an exception if not. Most users will want ``to_model() `` instead,
70+ which both checks validity and returns the dictionary model in one step.
71+ ``parse() `` is useful when you only need to validate and do not need the model,
72+ as it skips the conversion step.
3573
3674.. code :: python
3775
3876 >> > from mutalyzer_hgvs_parser import parse
3977 >> > parse(" LRG_1:100del" )
40- Tree(' description' , [Tree(' reference' , [Token(' ID' , ' LRG_1' )]), Tree(' variants' ,
41- [Tree(' variant' , [Tree(' location' , [Tree(' point' , [Token(' NUMBER' , ' 100' )])]), Tree(' deletion' , [])])])])
78+ Tree(' description' , ... )
79+
80+ The return value is a `lark Tree
81+ <https://lark-parser.readthedocs.io/en/stable/classes.html#tree> `_ object.
82+ Working with it directly requires familiarity with lark.
83+
84+
85+ The ``HgvsParser `` class
86+ ------------------------
87+
88+ For advanced use cases, such as supplying a custom grammar file or controlling
89+ whitespace handling, the ``HgvsParser `` class can be used directly. See the
90+ :doc: `API documentation <api/hgvs_parser >` for details.
4291
0 commit comments