<opt 
  name="genbanksubmit"
  date="20080511"

  tbl2asn="${ARGOS_ROOT}/common/servers/blast/Bin/tbl2asn" 
  tbl2asnopts="-t template.sbt -V vb -p ./  " 
  >
  
  <title>GenBank Submission table writer</title>
  
  <about><![CDATA[
    These are configurations for converting Chado genome features to
    Genbank submission table files.  Most of these specify how to
    process and convert various features extracted from chado db.
    These are tied to methods in Bulkfiles::GenbankSubmitWriter/FeatureWriter
    See chadofeatconv.xml for similar methods.

    Refer to these specifications:
    http://www.ncbi.nlm.nih.gov/Genbank/eukaryotic_genome_submission.html
    http://www.ncbi.nlm.nih.gov/Genbank/eukaryotic_genome_submission_annotation.html
    http://www.ncbi.nlm.nih.gov/Genbank/tbl2asn2.html
    http://www.ncbi.nlm.nih.gov/Sequin/table.html
    http://www.ncbi.nlm.nih.gov/projects/collab/FT/index.html
  ]]></about>
  
  <!-- 
    chadofeatconv.xml is where that complex, messy
    set of rewrite patterns and logic lives that gbsub also
    needs; should separate out good from old there into two files.
    need some of these: mapattr_pattern**; maptype_pattern; mapname_pattern; 
      ** feat_model
  -->
  <include>chadofeatconv</include>
  
  <informat>feature_table</informat>  
  
  <outformats>genbanktbl</outformats>
  <outformats>dummy</outformats>

  <mapattr_key id="Dbxref">db_xref</mapattr_key>
  <mapattr_key id="Note">note</mapattr_key>
  <mapattr_key id="cyto_range">cyt_map</mapattr_key>
  <mapattr_key id="map">cyt_map</mapattr_key>
  <mapattr_key id="species">organism</mapattr_key>
  <mapattr_key id="eC_number">EC_number</mapattr_key> <!-- fix a GFFism -->
  <!-- mapattr_key id="synonym" >gene_syn</mapattr_key -->
        
  <!-- ID, Name, others are special cases depending on feature type;
      see GenbankSubmitWriter::handleAttribOut()
      try this mapattr_feature
  -->
  <mapattr_key id="ID">db_xref</mapattr_key>
  <mapattr_key id="Name">name</mapattr_key>

  <mapattr_key_gene
    ID="locus_tag"
    Name="gene"
    synonym="gene_syn"
    locus_tag="old_locus_tag"
    gene="old_gene"
    />
  <mapattr_key_mRNA match="RNA" 
    ID="transcript_id"
    Parent="locus_tag"
    ParentName="gene"
    locus_tag="old_locus_tag"
    gene="old_gene"
    Name="product"
    transcript_id="old_transcript_id"
    product="old_product"
    />
 <mapattr_key_CDS 
    ID="protein_id"
    Parent="skip"
    ParentName="skip"
    GrandParent="locus_tag"
    GrandParentName="gene"
    locus_tag="old_locus_tag"
    gene="old_gene"
    Name="product"
    protein_id="old_protein_id"
    product="old_product"
    />
  <mapattr_key_transposon
    ID="transposon"
    transposon="old_transposon"
    />



  <!-- see maptype_gff; all the type recodes here .. ncRNA ??
      but see below feat_model -->
  <maptype_gb>
    <protein>CDS</protein>
    <transposable_element_pred>transposable_element:predicted</transposable_element_pred>
    <dummy_maptype>dummy_maptype</dummy_maptype>
  </maptype_gb>
 
  <!-- these feat_models override those of chadofeatconv ; suited to genbank needs -->
  
    <about id="feat_model"><![CDATA[
    feat_model: construct feature hierarchies for gene/mRNA/exon,UTR,.. models
  
    feat_model keys:
    id = ? type of feature, cant do with multiples
    simple = 1; not structure for this, write just span 
      (gene may be span or structured); replaces "simplefeat" list
    types   = list of types (replaces id?)
    submodels = list of features in kid array that become new structured features
    parent  = feature holding all kid objects (e.g. exons) (for submodel)
        ? is this valid, use featob->parent instead
    typelabel = what to write in place of id type (protein -> CDS)
    hasspan = this feature has start,stop (e.g. gene, mRNA, protein)
        discard/cut parts that fall outside
    part(s) = array of kid types (e.g. exons, UTRs) making structure
    makepartsfrom = list? of parts to make parts from if not given
      (e.g. exons => cds)
  ]]></about>
  

  <feat_model id="gene" simple="1" >
    <submodels>trnatype</submodels> 
    <submodels>ncrnatype</submodels> 
    <!-- submodels>mRNA</submodels --> 
      <!-- data may or may not have gene parent for other rnas ; pseudogene ? -->
  </feat_model>
  
  <feat_model id="mRNA">
    <parts>exon</parts> 
    <submodels>protein</submodels> 
    <!-- submodels>five_prime_UTR</submodels --> 
    <!-- submodels>three_prime_UTR</submodels --> 
    <!-- submodels>intron</submodels --> 
  </feat_model>
  
  <!-- chado is ambiguous: uses both protein, polypeptide types -->
  <feat_model id="protein" 
    typelabel="CDS" 
    parent="mRNA" 
    hasspan="1" 
    NOT_makemethod="getCDSexons" 
    makepartsfrom="exon" 
    >
    <parts>CDS</parts>  
  </feat_model>

  <!-- drop create UTR, intron from mRNA>exon,protein model -->
  <feat_model id="five_prime_UTR" 
    NOT_makemethod="makeUtr5" 
    NOT_makepartsfrom="exon|protein" 
    >
    <parts>five_prime_UTR</parts>  
  </feat_model>
  <feat_model id="three_prime_UTR" 
    NOT_makemethod="makeUtr3" 
    NOT_makepartsfrom="exon|protein" 
    >
    <parts>three_prime_UTR</parts>  
  </feat_model>
  <feat_model id="intron" 
    NOT_makemethod="makeIntrons" 
    NOT_makepartsfrom="exon" 
    >
    <parts>intron</parts>  
  </feat_model>
  
  <!-- tRNA , rRNA are separate in Genbank ; equal to mRNA
  (snoRNA, scRNA, snRNA, miRNA, ncRNA, rRNA)
  -->
  <feat_model id="trnatype" types="tRNA rRNA">
    <parts>exon</parts> 
  </feat_model>

  <feat_model id="ncrnatype" typelabel="ncRNA" 
    types="snRNA snoRNA miRNA ncRNA">
    <parts>exon</parts> 
    <attr id="ncRNA_class">type</attr>
  </feat_model>

  <feat_model id="pseudogene" typelabel="gene">
    <attr id="pseudo">1</attr>
    <!-- submodels>pseudogenic_transcript</submodels --> 
    <!-- submodels>pseudogenic_tRNA</submodels --> 
    <!-- submodels>pseudogenic_rRNA</submodels -->
    <!-- parts>exon</parts --> 
  </feat_model>

  <feat_model id="pseudogenic_transcript" typelabel="mRNA">
    <parts>exon</parts> 
    <attr id="pseudo">1</attr>
  </feat_model>

  <feat_model id="pseudogenic_tRNA" typelabel="tRNA">
    <parts>exon</parts> 
    <attr id="pseudo">1</attr>
  </feat_model>

  <feat_model id="pseudogenic_rRNA" typelabel="rRNA">
    <parts>exon</parts> 
    <attr id="pseudo">1</attr>
  </feat_model>



  <about id="submit_template_info"><![CDATA[
ref: ncbi/doc/tbl2asn.txt
    
SUBMISSION TEMPLATE FORMAT

The submission template is an ASN.1 Submit-block that can be generated by
Sequin.  A simple example is shown below.

   ]]></about>
  
  <doc id="submit_template" path="genbanksubmit/template.sbt">
  <!-- FIXME: configure this or expect customers to edit to taste ? -->
<![CDATA[

Submit-block ::= {
  contact {
    contact {
      name
        name {
          last "Darwin" ,
          first "Charles" ,
          initials "C.R." ,
          suffix "" } ,
      affil
        std {
          affil "Oxbridge University" ,
          div "Evolutionary Biology Department" ,
          city "Camford" ,
          country "United Kingdom" ,
          street "1859 Tennis Court Lane" ,
          email "darwin@beagle.edu.uk" ,
          phone "01 44 171-007-1212" ,
          postal-code "OX1 2BH" } } } ,
  cit {
    authors {
      names
        std {
          {
            name
              name {
                last "Darwin" ,
                first "Charles" ,
                initials "C.R." } } } ,
      affil
        std {
          affil "Oxbridge University" ,
          div "Evolutionary Biology Department" ,
          city "Camford" ,
          country "United Kingdom" ,
          street "1859 Tennis Court Lane" ,
          postal-code "OX1 2BH" } } ,
    date
      std {
        year 2003 ,
        month 2 ,
        day 28 } } ,
  subtype new  }
  ]]> 
  </doc>

 <about id="working notes">
 <![CDATA[
 working notes:
    * add NCBI tbl2asn executable options as per blastfiles.xml
  tbl2asn="${ARGOS_ROOT}/common/servers/blast/Bin/tbl2asn" 
  tbl2asnopts=" " 
   e.g.  tbl2asn -t template.sbt -p path_to_files -a s -V v

# this works .. with errors
$nb/tbl2asn -t template.sbt -V vb -p ./  

GMODTools/data/genomes/Drosophila_melanogaster/drosmelgb_20080512/genbanktbl

# outputs
2415212 May 13 19:50 drosmelgb-all-drosmelgb4.gbf
3910617 May 13 19:50 drosmelgb-all-drosmelgb4.sqn
 653387 May 13 19:50 drosmelgb-all-drosmelgb4.val == ERRORS list

# inputs
 265366 May 13 19:48 drosmelgb-all-drosmelgb4.tbl
1379004 May 13 19:31 drosmelgb-all-drosmelgb4.fsa == ../fasta/drosmelgb-all-chromosome-drosmelgb4.fasta
 296419 May 13 19:30 drosmelgb-all-drosmelgb4.pep == ../fasta/drosmelgb-all-translation-drosmelgb4.fasta
   1085 May 13 19:22 template.sbt

# prot translations mostly bad: no start_codon= field *** only problem w/ genbank2chado ?
# ** need to always explicity write this field from CDS_span location? shouldn't this be
  shouldn't need this; CDS locs should have start/stop

 	perl -pi -e's/protein_id\tNP/old_protein_id\tNP/;' drosmelgb-all-drosmelgb4.tbl
 	perl -pi -e's/transcript_id\tNM_/old_transcript_id\tNM_/;' drosmelgb-all-drosmelgb4.tbl

# all prots.pep missed : fix >IDs ??
[NULL_Caption] Unable to find protein sequence CG17923.p01
SeqID must match protein_id in the .tbl file


# ERRORS .val................

ERROR: valid [SEQ_DESCR.NoOrgFound] No organism name anywhere on this entire record. BIOSEQ: lcl|NC_004353: ra
w, dna len= 1351857
 >> change chromosome type to source type

 	perl -pi -e's/1351857\tchromosome/1351857\tsource/;s/Drosophila_melanogaster/Drosophila melanogaster/;' drosmelgb-all-drosmelgb4.tbl

WARNING: valid [SEQ_FEAT.IllegalDbXref] db_xref type GI is only created by the flatfile generator, 
  >> drop all db_xref == GI: 

 	perl -pi -e's/db_xref\tGI:/db_xref\told_GI:/;' drosmelgb-all-drosmelgb4.tbl
  
ERROR: valid [SEQ_FEAT.SeqLocOrder] Location: Intervals out of order in SeqLoc [(lcl|NC_004353:c53751-53434, c
53999-53817, c57083-56500, c61911-57142, c64403-63540)] FEATURE: CDS: plexin B CG17245-PA [(lcl|NC_004353:c537
51-53434, c53999-53817, c57083-56500, c61911-57142, c64403-63540)] [lcl|NC_004353: raw, dna len= 1351857] -> [
lcl|plexB.p01]
  >> this is probably revcomp error; put last first ...

WARNING: valid [SEQ_FEAT.UnnecessaryGeneXref] Unnecessary gene cross-reference CG32005 FEATURE: CDS: CG32005-P
A [lcl|NC_004353:111840-113903] [lcl|NC_004353: raw, dna len= 1351857] -> [lcl|CG32005.p01]
 >>  
 111840  113903  CDS
        protein_id      CG32005.p01
        gene    CG32005     <<< is this the problem?
        product CG32005-PA
 
 
]]> </about>


</opt>
