#!/bin/env icarus
# IARC TP53 Mutations Database (Rel. 14)
# Germline References data set
# Author: Domenico Marra domenico.marra@istge.it
# Created: March 21st 2005
# Modified by paolo Romano on 2007/02/06
# Modified by paolo Romano on 2008/03/21

$fn={
Ref_id:ext_ref_id
Title:title
Authors:authors
Year:year
Journal:journal
Volume:volume
Start_page:start
End_page:end
PubMed_entry:pubmed
Comment:comment
}

$rules={
  entry:	~ {$In:[file:text] $Out pre $Skip:0}
		  ('Ref_id' {$Not} ln)*
		  ('Ref_id' {$entryFip=$Fip $Wrt} ln {$App}
		  ('Ref_id' {$Not} ln {$App})*)?
		~
# fields

  fields:	~ {$In:entry $Out $Skip:1}
                  (/\/[^\n]+\n/ {$Wrt} |
                  word {$Wrt:$fn.$Ct} 
                  (/[\/A-Z]/ {$Not} ln {$App})+)+ ~

#indexing
  ext_ref_id:	~ {$In:[fields c:ext_ref_id] $Out}
		  tag / /* number {$Wrt} ~

  numbers:	~ {$In:[fields c:{year volume start end}] $Out}
		  tag ' '* number? {$Uniq:$Itc} ~ 

  unique:	~ {$In:[fields c:{title authors journal comment}] $Out}
		  tag ' '* (word {$Uniq:$Itc}| punct)* ~ 

  strX:		~ {$In:[fields c:{pubmed}] $Out}
		  tag ' '* number {$Uniq:$Itc }  ~ 
#		  tag ' '* ('PM:'|'PU:') ' '* number {$Uniq:$Itc }  ~ 

#HTML stuff...

 h_top:      ~ {$In:[fields c:ext_ref_id t:html] pre if:$ParInt:isTable $Fail}
               word {$Rep:
                     |</TR><TR>
                     |<TD colspan=2 bgcolor=\"#ffffff\">
                     |<font color=\"#000066\"><B><center>
                     |($entry.libName)</center></B></TD>
                     |</TR>
                     |<TR><TD bgcolor=\"#ffffff\">
                     |<font color=\"#000066\"><b><i>$Ct</i></b></font></TD>
                     |<TD bgcolor=\"#ffffff\">
                    } 
                     /.*/ {$Rep:"$Ct</TD></TR>"}  ~

 h_pubmed: ~ {$In:[fields c:pubmed t:html] pre if:$ParInt:isTable $Fail }
             'PubMed_entry' {if:$isTable==0
               $Rep:
                 |<TR><TD bgcolor=\"#ffffff\">
                 |<font color=\"#000066\"><b><i>$Ct</i></b></font></TD>
                 |<TD bgcolor=\"#ffffff\">
               }
             ' '*  number {$Rep:$Hlink:[medlineR p:{$Ct $Ct}]} ~
 
 h_fields:      ~ {$In:[fields t:html] pre if:$ParInt:isTable $Fail}
                        word {if:$isTable==0
                        $Rep:
                     |<TR><TD bgcolor=\"#ffffff\">
                     |<font color=\"#000066\"><b><i>$Ct</i></b></font></TD>
                     |<TD bgcolor=\"#ffffff\">
                     } 
                         /.*/ {$Rep:"$Ct</TD></TR>"}  ~

 t_fields:     ~ {$In:[fields] $Out} tag /.*/ {$Wrt:$Itc} ~

# definitions

  htag:         ~ /<[^>]+>/ ~
  tag:          ~ /[0-9a-zA-Z_]+/ ~
  ln:		~ /[^\n]*\n/ ~
  word:		~ /[0-9a-zA-Z_]+/ ~
  number:	~ /[0-9]+/ ~
  not_number:	~ /[^0-9]+/ ~
  punct:	~ /[^a-zA-Z0-9_]+/ ~ 
 
}

# debugging