# Last-edition: 20060505

#
# Html links
#
$links= {
}

$rules={

#
# Entry
#
entry:	~ { $In:[file:text] $Out pre {$Skip:0} }
	('PROMOTER_ID' {$entryFip=$Fip $Wrt} toln {$App}
	('PROMOTER_ID' {$Not} toln {$App})+ )?
~

#
# Fields
#

fields:		~ {$In:entry $Out} promoter_id gene_id 	tspec keywords localization
	description? sequence_id reporter? transgene? stage  regulator? comment
	(reference pubmed?)+
	end
~

promoter_id:	~ {$Wrt:promoter_id} 'PROMOTER_ID' sp_toln ~
gene_id:	~ {$Wrt:gene_id} 'GENE_ID' sp_toln ~
tspec:		~ {$Wrt:tspec} 'TARGET SPECIES' sp_toln+ ~
keywords:	~ {$Wrt:keywords} 'KEYWORDS' sp_toln+ ~
localization:	~ {$Wrt:localization} 'LOCALIZATION' sp_toln+ ~
description:	~ {$Wrt:description} 'DESCRIPTION' sp_toln+ ~
sequence_id:	~ {$Wrt:sequence_id} 'SEQUENCE_ID' sp_toln ~
reporter:	~ {$Wrt:reporter} 'REPORTER' sp_toln ~
transgene:	~ {$Wrt:transgene} 'TARGET GENE' sp_toln+  ~
stage:		~ {$Wrt:stage} 'STAGE_ORGAN_TISSUE' sp_toln+ ~
regulator:	~ {$Wrt:regulator} 'REGULATOR' sp_toln+ ~
comment:	~ {$Wrt:comment} 'COMMENT' sp_toln+ ~
reference:	~ {$Wrt:reference} 'REFERENCE' sp_toln+ ~
pubmed:		~ {$Wrt:pubmed} 'PUBMED' sp_toln ~
end:		~ {$Wrt} 'END' toln ~


#
# Indexing
#
i_promoter_id:	~ {$In:[fields c:promoter_id] $Out:promoter_id} tag_sp
	id_ext {$Wrt} ln
~
i_gene_id:	~ {$In:[fields c:gene_id] $Out:gene_id} tag_sp
	( id_ext {$Wrt} | sp_or_ln )*
~
i_tspec: ~ {$In:[fields c:tspec] $Out:tspec} tag_sp tag_sp 
	(wordext2 {if:($StrLen:$Ct >= 3){$Wrt} } | /[,\n]+/ )*
~


i_keywords: ~ {$In:[fields c:keywords] $Out:keywords}  tag_sp 
	(wordext2 {if:($StrLen:$Ct >= 3){$Wrt} } | /[,\n]+/ )*
~
i_sequence_id: 	~ {$In:[fields c:sequence_id] $Out:sequence_id} tag_sp
	( id_ext {$Wrt} | sp_or_ln )*
~
i_reporter: ~ {$In:[fields c:reporter] $Out:reporter}  tag_sp 
	(wordext2 {if:($StrLen:$Ct >= 3){$Wrt} } | /[,\n]+/ )*
~
i_transgene: ~ {$In:[fields c:transgene] $Out:transgene}  tag_sp 
	(wordext2 {if:($StrLen:$Ct >= 3){$Wrt} } | /[,\n]+/ )*
~
i_stage: 	~ {$In:[fields c:stage] $Out:stage} tag_sp
	( wordext2 { if:($StrLen:$Ct >= 3) {$Wrt} } | /[,\n]+/ )*
~


#i_regulator: 	~ {$In:[fields c:regulator] $Out:regulator} tag
#	spaces regulator_text {$Wrt:[s:$Ct.trim]} regulator_comment?
#	( spaces? ',' sp_or_ln regulator_text {$Wrt:[s:$Ct.trim]}
#	regulator_comment? )*
#	ln
#~

i_regulator: 	~ {$In:[fields c:regulator] $Out:regulator} tag_sp
	( wordext2 { if:($StrLen:$Ct >= 3) {$Wrt} } | /[,\n]+/ )*
~
i_comment: 	~ {$In:[fields c:comment] $Out:comment} tag_sp
	( wordext { if:($StrLen:$Ct >= 3) {$Wrt} } | nonword )*
~
#i_reference: 	~ {$In:[fields c:reference] $Out:reference} tag_sp
#	( wordext { if:($StrLen:$Ct >= 3) {$Wrt} } | nonword )*
#~

i_reference: 	~ {$In:[fields c:reference] $Out:reference} tag_sp
	( wordext2 { if:($StrLen:$Ct >= 3) {$Wrt} } | /[,\n]+/ )*
~

i_pubmed: 	~ {$In:[fields c:pubmed] $Out:pubmed} tag_sp
	( wordext { if:($StrLen:$Ct >= 3) {$Wrt} } | nonword )*
~
#
# Html
#
h_gene_id:	~ { $In:[fields c:gene_id t:html] pre {if:$ParInt:isTable $Fail} }
	tag ( id_ext
	{$Rep:$Hlink:[entryR p:{"($ParStr:userIdOpt)" 'TGP_GENE' 'GeneID' $Ct $Ct} ]}
	| sp_or_ln )*
~
h_sequence_id:	~ { $In:[fields c:sequence_id t:html] pre {if:$ParInt:isTable $Fail} }
	tag ( id_ext
	{$Rep:$Hlink:[entryR p:{"($ParStr:userIdOpt)" 'TGP_SEQUENCE' 'SequenceID' $Ct $Ct} ]}
	| sp_or_ln )*
~
h_pubmed:		~ { $In:[fields c:pubmed t:html] pre {if:$ParInt:isTable $Fail} 
				}
	tag_sp /[0-9]+/ {$Rep:$Hlink:[PMIDR p:{$Ct $Ct}]} ln
~

#
# Special
#
id_ext:		~ /^[a-zA-Z]+:[a-zA-Z0-9_:;+.-]+/ ~

#
# Other
#
numb:		~ /[0-9]+/ ~
toln:		~ /[^\n]*\n/ ~
noln:		~ /[^\n]*/ ~
ln:		~ /\n/ ~
sp_or_ln:	~ /[ \n]+/ ~
sp_toln:	~ / [^\n]*\n/ ~
tag:		~ /[A-Z0-9_-]+/ ~
tag_sp:		~ /[A-Z0-9_-]+ / ~
spaces:		~ /[ ]+/ ~
word:		~ /[a-zA-Z0-9]+/ ~
nonword:	~ /[^a-zA-Z0-9]*/ ~
wordext:	~ /[a-zA-Z0-9_-]+/ ~
wordext2:	~ /[a-zA-Z0-9_()<> -]+/ ~
fill:		~ /[^ \t\n]+/ ~
nonfill:	~ /[ \t\n]*/ ~
regulator_text:	~ /[a-zA-Z0-9%._\/ +-]+/ ~
regulator_comment:~ '(' /[^)]+/ ')' ~
} # rules