daviddao / biojs-io-newick

Newick Parser in JS - parses newick strings into JSON and JSON into newick
http://biojs.io/d/biojs-io-newick
Apache License 2.0
17 stars 6 forks source link

🎁 Support quoted names #3

Open BevanR opened 6 years ago

BevanR commented 6 years ago

Advanced Newick formats support punctuation in quoted labels;

Unquoted labels may not contain blanks, parentheses, square brackets, single_quotes, colons, semicolons, or commas.

http://evolution.genetics.washington.edu/phylip/newick_doc.html

Geneious (popular microbiology analysis software) exports phylogenetic trees in the Newick data format using labels like "My sequence (reverse)" and includes the parentheses, escaping the entire label in single quotes, as per that spec.

It would be nice if biojs-io-newick supported this feature.

MortenHofft commented 3 years ago

I tried to parse a sequence downloaded from Open Tree of Life. But it didn't parse correctly due to quotes

(Caragana_leucophloea_ott579,((((Caragana_acanthophylla_ott29478,Caragana_pruinosa_ott738854),Caragana_spinosa_ott232431),(Halimodendron_halodendron_ott761641,Halimodendron_sp._Fayvush_25_ott5532104)Halimodendron_ott170077),(Caragana_tibetica_ott30861,(Caragana_franchetiana_ott204017,Caragana_crassispina_ott5785640)),(((Caragana_chinghaiensis_ott78093,((Caragana_pygmaea_ott232427,Caragana_aurantiaca_ott806587),Caragana_grandiflora_ott702017)),Caragana_laeta_ott806583,Caragana_altaica_ott5785639),(Calophaca_tianschanica_ott222244,Calophaca_soongorica_ott806591,((Calophaca_hovenii_ott1033616,Calophaca_pskemica_ott1033618),Calophaca_wolgarica_ott1033620),Calophaca_chinensis_ott3922338,Calophaca_sinica_ott3922339,Calophaca_grandiflora_ott3922340,Calophaca_sericea_ott3922341,Calophaca_reticulata_ott3922342,Calophaca_kotschyii_ott7632649)Calophaca_ott222246),Caragana_gerardiana_ott78110),Caragana_erinacea_ott29485,Caragana_hololeuca_ott29498,Caragana_stenophylla_ott30863,Caragana_purdomii_ott30867,Caragana_zahlbruckneri_ott30869,Caragana_tragacanthoides_ott30871,Caragana_conferta_ott78091,Caragana_changduensis_ott78095,'Caragana camilloi-schneideri ott78097',Caragana_bungei_ott78099,Caragana_brevispina_ott78101,Caragana_brevifolia_ott78103,Caragana_gobica_ott78108,((Caragana_korshinskii_ott83083,(Caragana_microphylla_f._cinerea_ott604795)Caragana_microphylla_ott604797),Caragana_arborescens_ott110854,Caragana_roborovskyi_ott194717,Caragana_soongorica_ott232425,Caragana_decorticans_ott806570),Caragana_frutex_ott187482,Caragana_stipitata_ott232429,Caragana_tangutica_ott232433,Caragana_sukiensis_ott232435,Caragana_versicolor_ott232437,Caragana_ussuriensis_ott232440,Caragana_sinica_ott428766,Caragana_licentiana_ott428772,Caragana_ordosica_ott428774,Caragana_davazamcii_ott472109,Caragana_opulens_ott738856,Caragana_bongardiana_ott738864,Caragana_sibirica_ott799171,Caragana_boisii_ott806567,Caragana_pekinensis_ott806575,Caragana_pleiophylla_ott806579,Caragana_kirghisorum_ott806581,Caragana_ambigua_ott806585,Caragana_polourensis_ott806589,Caragana_turkestanica_ott817200,Caragana_densa_ott954745,Caragana_dasyphylla_ott954747,Caragana_brachypoda_ott954754,Caragana_bicolor_ott954756,Caragana_jubata_ott1012368,Caragana_shensiensis_ott3922307,Caragana_crassipina_ott3922308,Caragana_polyacantha_ott3922309,Caragana_prestoniae_ott3922310,Caragana_kansuensis_ott3922311,Caragana_alaschanica_ott3922312,Caragana_leucospina_ott3922313,Caragana_turfanensis_ott3922314,Caragana_buriatica_ott3922315,Caragana_leveillei_ott3922316,Caragana_kozlowii_ott3922317,Caragana_alaica_ott3922318,Caragana_balchaschensis_ott3922319,Caragana_pumila_ott3922320,'Caragana cuneato-alata ott3922321',Caragana_sophorifolia_ott3922322,Caragana_alexeenkoi_ott3922323,Caragana_ulicina_ott3922324,Caragana_beefensis_ott3922325,Caragana_scythica_ott3922326,Caragana_arcuata_ott3922327,Caragana_alpina_ott3922328,Caragana_spinifera_ott3922329,Caragana_przewalskii_ott3922330,Caragana_fruticosa_ott3922331,Caragana_maimanensis_ott3922332,Caragana_litwinowii_ott3922333,Caragana_campanulata_ott3922334,Caragana_limprichtii_ott3922335,Caragana_cinerea_ott3922337,Caragana_afghanica_ott5147267,Caragana_qingheensis_ott5785641,Caragana_junatovii_ott6095737,Caragana_liouana_ott6095738,Caragana_tekesiensis_ott6095739,Caragana_potaninii_ott7055458,(Caragana_rosea_var._rosea_ott7055459)Caragana_rosea_ott30865,'Caragana sp. US:3541335 ott7055460',Caragana_ulcina_ott7632650)

The issue is quotes with punctuation. As in ('Bryophyta:123', Chlorophyta)Plantae;

single or double quotes makes no difference