w#!/bin/env icarus
# IARC TP53 Germline Database
# Author: Domenico Marra (domenico.marra@istge.it)
# Created: May 7th, 2005
# Modified by Paolo Romano on 2008/04/08

$fn={
Unique_id:unique_id
Exon:exon
Intron:intron
Nucleotide:nucl
Codon_number:cod_no
Type:type
Description:desc
C_description:c_des
WT_codon:wt_cod
Mutant_codon:mut_cod
WT_AA:wt_aa
Mutant_AA:mut_aa
Effect:eff
Sample_id:smp_id
Topography:topog
Morphology:morpho
Individual_id:ind_id
Sex:sex
Age:age
Country:cnty
Germline_mutation:germ_mut
Ref_id:ref_id
Gene_variation_id:gev_id
Family_id:family
Family_code:fa_code
Family_case:fam_case
Class:class
Generations_analyzed:gen_ana
Individual_code:ind_cod
Generation:generation
Germline_carrier:germ_carr
Mode_of_inheritance:inheritance
Dead:dead
Unaffected:unaffected
Age_at_diagnosis:age_diag
P53Mut_id:p53mid
}

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

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

#indexing

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

  numbers:	~ {$In:[fields c:{generation age_diag gen_ana gev_id nucl family cod_no ind_id age ref_id p53mid}] $Out}
		  tag ' '* number? {$Uniq:$Itc} ~ 

  exon:       ~ {$In:[fields c:exon] $Out}
                  tag ' '*  number{$Wrt}~

  intron:       ~ {$In:[fields c:intron] $Out}
                  tag ' '* number {$Wrt}~

  unique:	~ {$In:[fields c:{ind_cod class unaffected dead inheritance fa_code fam_case mut_cod}] $Out}
		  tag ' '*  (not_word | all {$Uniq:$Itc})*~ 

  germ_carr:	~ {$In:[fields c:germ_carr] $Out}
		  tag ' '*  (/\n/ | ln {$Uniq:$Itc}) ~ 

  type: 	~ {$In:[fields c:type] $Out} 
		  tag ' '* (/\n/ | ln {$Uniq:$Itc}) ~ 

  wt_cod: 	~ {$In:[fields c:wt_cod] $Out} 
		  tag ' '* (/\n/ | ln {$Uniq:$Itc}) ~ 

  wt_aa: 	~ {$In:[fields c:wt_aa] $Out} 
		  tag ' '* (/\n/ | ln {$Uniq:$Itc}) ~ 

  mut_aa: 	~ {$In:[fields c:mut_aa] $Out} 
		  tag ' '* (/\n/ | ln {$Uniq:$Itc}) ~ 

  eff:  	~ {$In:[fields c:eff] $Out} 
		  tag ' '* (/\n/ | ln {$Uniq:$Itc}) ~ 

  topog: 	~ {$In:[fields c:topog] $Out} 
		  tag ' '* (/\n/ | ln {$Uniq:$Itc}) ~ 

  morpho: 	~ {$In:[fields c:morpho] $Out} 
		  tag ' '* (/\n/ | ln {$Uniq:$Itc}) ~ 

  sex:  	~ {$In:[fields c:sex] $Out} 
		  tag ' '* (/\n/ | ln {$Uniq:$Itc}) ~ 

  cnty: 	~ {$In:[fields c:cnty] $Out} 
		  tag ' '* (/\n/ | ln {$Uniq:$Itc}) ~ 

  germ_mut: 	~ {$In:[fields c:germ_mut] $Out} 
		  tag ' '* (/\n/ | ln {$Uniq:$Itc}) ~ 

  c_des:	~ {$In:[fields c:c_des] $Out}
		  tag / /* /[^\n]*/ {$Uniq:$Itc} ~

  desc:       ~ {$In:[fields c:desc] $Out}
                  tag ' '* ( ln {$Wrt})*~ 

#HTML stuff...

 h_top:      ~ {$In:[fields c:unique_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_ref: ~ {$In:[fields c:ref_id t:html] pre if:$ParInt:isTable $Fail }
             'Ref_id' {if:$isTable==0
               $Rep:
                 |<TR><TD bgcolor=\"#ffffff\">
                 |<font color=\"#000066\"><b><i>$Ct</i></b></font></TD>
                 |<TD bgcolor=\"#ffffff\">
               }
             punct? number {$Rep:$Hlink:[tp53_germ_refR 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

  tag:          ~ /[0-9a-zA-Z_]+/ ~
  ln:		~ /[^\n]*\n/ ~
  word:		~ /[0-9a-zA-Z_]+/ ~
  word2:	~ /[a-zA-Z+-]+/ ~
  word3:	~ /[0-9a-zA-Z\\.+-]+/ ~
  number:	~ /[0-9]+/ ~
  not_word:	~ /[^a-zA-Z0-9_ -]+/ ~ 
  all:  	~ /[0-9a-zA-Z_\\"&>?\\.\\'\\\/\+ -]+/ ~ 
  punct:	~ /[^a-zA-Z0-9_]+/ ~

}