/*   asn2gnbi.h
* ===========================================================================
*
*                            PUBLIC DOMAIN NOTICE
*            National Center for Biotechnology Information (NCBI)
*
*  This software/database is a "United States Government Work" under the
*  terms of the United States Copyright Act.  It was written as part of
*  the author's official duties as a United States Government employee and
*  thus cannot be copyrighted.  This software/database is freely available
*  to the public for use. The National Library of Medicine and the U.S.
*  Government do not place any restriction on its use or reproduction.
*  We would, however, appreciate having the NCBI and the author cited in
*  any work or product based on this material
*
*  Although all reasonable efforts have been taken to ensure the accuracy
*  and reliability of the software and data, the NLM and the U.S.
*  Government do not and cannot warrant the performance or results that
*  may be obtained by using this software or data. The NLM and the U.S.
*  Government disclaim all warranties, express or implied, including
*  warranties of performance, merchantability or fitness for any particular
*  purpose.
*
* ===========================================================================
*
* File Name:  asn2gnbi.h
*
* Author:  Karl Sirotkin, Tom Madden, Tatiana Tatusov, Jonathan Kans
*
* Version Creation Date:   12/30/03
*
* $Revision: 1.173 $
*
* File Description:  New GenBank flatfile generator, internal header
*
* Modifications:  
* --------------------------------------------------------------------------
* ==========================================================================
*/

#ifndef _ASN2NGNBI_
#define _ASN2NGNBI_

#include <asn2gnbp.h>
#include <explore.h>

#undef NLM_EXTERN
#ifdef NLM_IMPORT
#define NLM_EXTERN NLM_IMPORT
#else
#define NLM_EXTERN extern
#endif

#ifdef __cplusplus
extern "C" {
#endif



#define ASN2FF_EMBL_MAX 78
#define ASN2FF_GB_MAX   79
#define SEQID_MAX_LEN   41

#define TILDE_IGNORE     0
#define TILDE_TO_SPACES  1
#define TILDE_EXPAND     2
#define TILDE_OLD_EXPAND 3
#define TILDE_SEMICOLON  4


/* flags set by mode to customize behavior */

typedef struct asn2gbflags {
  Boolean             suppressLocalID;
  Boolean             validateFeats;
  Boolean             ignorePatPubs;
  Boolean             dropShortAA;
  Boolean             avoidLocusColl;
  Boolean             iupacaaOnly;
  Boolean             dropBadCitGens;
  Boolean             noAffilOnUnpub;
  Boolean             dropIllegalQuals;
  Boolean             checkQualSyntax;
  Boolean             needRequiredQuals;
  Boolean             needOrganismQual;
  Boolean             needAtLeastOneRef;
  Boolean             citArtIsoJta;
  Boolean             dropBadDbxref;
  Boolean             useEmblMolType;
  Boolean             hideBankItComment;
  Boolean             checkCDSproductID;
  Boolean             suppressSegLoc;
  Boolean             srcQualsToNote;
  Boolean             hideEmptySource;
  Boolean             goQualsToNote;
  Boolean             separateGeneSyns;
  Boolean             refSeqQualsToNote;
  Boolean             selenocysteineToNote;
  Boolean             pyrrolysineToNote;
  Boolean             extraProductsToNote;
  Boolean             codonRecognizedToNote;
  Boolean             hideSpecificGeneMaps;
  Boolean             forGbRelease;
} Asn2gbFlags, PNTR Asn2gbFlagsPtr;

/* internal Asn2gbSect structure has fields on top of Asn2gbSect fields */

typedef struct int_Asn2gbSect {
  Asn2gbSect  asp;
  Int4        feat_counts [FEATDEF_MAX];
  CharPtr     gi;
  CharPtr     acc;
  CharPtr     feat_key [FEATDEF_MAX];
  Boolean     feat_js_prefix_added;
} IntAsn2gbSect, PNTR IntAsn2gbSectPtr;

/* string structure */

#define STRING_BUF_LEN  1024

typedef struct stringitem {
  struct stringitem  *curr;
  struct stringitem  *next;
  Pointer            iajp;
  Char               buf [STRING_BUF_LEN];
  Int4               pos;
} StringItem, PNTR StringItemPtr;

/* internal asn2gbjob structure has fields on top of Asn2gbJob fields */

typedef struct int_asn2gb_job {
  Asn2gbJob       ajp;
  FmtType         format;
  ModType         mode;
  Asn2gbFlags     flags;
  Boolean         showFarTransl;
  Boolean         transIfNoProd;
  Boolean         alwaysTranslCds;
  Boolean         showTranscript;
  Boolean         showPeptide;
  Boolean         hideTranslation;
  Boolean         hideEvidence;
  Boolean         masterStyle;
  Boolean         newSourceOrg;
  Boolean         produceInsdSeq;
  Boolean         oldXmlPolicy;
  Boolean         refseqConventions;
  ValNodePtr      lockedBspList;
  ValNodePtr      manygaps;
  ValNodePtr      gapvnp;
  ValNodePtr      remotevnp;
  Asn2gbLockFunc  remotelock;
  Asn2gbFreeFunc  remotefree;
  Pointer         remotedata;
  Boolean         relModeError;
  Boolean         skipProts;
  Boolean         skipMrnas;
  IndxPtr         index;
  GBSeqPtr        gbseq;
  BlockMask       bkmask;
  AsnIoPtr        aip;
  AsnTypePtr      atp;
  StringItemPtr   pool;
  Boolean         www;
  Boolean         specialGapFormat;
  Boolean         relaxedMapping;
  Boolean         gpipdDeflines;
  Boolean         hideProteinID;
  Boolean         hideGoTerms;
  Boolean         multiIntervalGenes;
  Boolean         segmentedBioseqs;
  Boolean         smallGenomeSet;
  Boolean         reindex;
  Int4            seqGapCurrLen;
  Boolean         hideGI;
  ValNodePtr      gihead;
  ValNodePtr      gitail;
  TextFsaPtr      bad_html_fsa;
  Boolean         seqspans;
  Int2            sat;
  Int4            sat_key;
} IntAsn2gbJob, PNTR IntAsn2gbJobPtr;

/* array for assigning biosource and feature data fields to qualifiers */
/* should be allocated to MAX (ASN2GNBK_TOTAL_SOURCE, ASN2GNBK_TOTAL_FEATUR) */

typedef union qualval {
  CharPtr              str;
  Boolean              ble;
  Int4                 num;
  ValNodePtr           vnp;
  GBQualPtr            gbq;
  OrgModPtr            omp;
  SubSourcePtr         ssp;
  CodeBreakPtr         cbp;
  SeqLocPtr            slp;
  SeqIdPtr             sip;
  tRNAPtr              trp;
  UserObjectPtr        uop;
  UserFieldPtr         ufp;
  RNAGenPtr            rgp;
  GeneNomenclaturePtr  gnp;
  PCRReactionSetPtr    prp;
  DbtagPtr             dbt;
} QualVal, PNTR QualValPtr;

/* structure passed to individual paragraph format functions */

typedef struct asn2gbformat {
  IntAsn2gbJobPtr  ajp;
  Asn2gbSectPtr    asp;
  QualValPtr       qvp;
  FmtType          format;
  Asn2gbWriteFunc  ffwrite;
  Pointer          userdata;
  FILE             *fp;
  AsnIoPtr         aip;
  AsnTypePtr       atp;
} Asn2gbFormat, PNTR Asn2gbFormatPtr;

/* structure for bypassing unannotated WGS components in Web Entrez */

typedef struct wgsaccn {
  Char     accn [6];
  Int2     count;
  Boolean  hasfeats;
} WgsAccn, PNTR WgsAccnPtr;

/* structure for storing working parameters while building asn2gb_job structure */

typedef struct asn2gbwork {
  IntAsn2gbJobPtr  ajp;
  Uint2            entityID;

  FmtType          format;
  ModType          mode;
  StlType          style;

  ValNodePtr       pubhead;    /* for collecting publications */
  ValNodePtr       srchead;    /* for collecting biosources */

  /* linked lists of paragraphs, sections, blocks */

  ValNodePtr       sectionList;
  ValNodePtr       blockList;    /* reset for each new section */

  /* most recent node of linked lists, for quickly adding next node */

  ValNodePtr       lastsection;
  ValNodePtr       lastblock;    /* reset for each new section */

  Int4             currsection;

  /* set if doing immediate write at time of creation for web speed */

  Asn2gbFormatPtr  afp;

  /* section fields needed for populating blocks */

  Asn2gbSectPtr    asp;

  BioseqPtr        target;
  BioseqPtr        parent;
  BioseqPtr        bsp;
  BioseqPtr        refs;
  SeqLocPtr        slp;
  Uint2            seg;
  Int4             numsegs;
  Int4             partcount;
  Int4             from;
  Int4             to;

  Int2             sectionCount;
  Int2             sectionMax;
  BIG_ID           currGi;
  BIG_ID           prevGi;
  BIG_ID           nextGi;
  ValNodePtr       gilistpos;
  Char             currAccVer [SEQID_MAX_LEN];
  Char             currAccVerLabel [SEQID_MAX_LEN];

  Boolean          showAllFeats;

  Boolean          contig;
  Boolean          showconfeats;
  Boolean          showconsource;
  Boolean          smartconfeats;

  Boolean          onlyNearFeats;
  Boolean          farFeatsSuppress;
  Boolean          nearFeatsSuppress;

  Boolean          citSubsFirst;
  Boolean          hideGeneFeats;
  Boolean          newLocusLine;
  Boolean          showBaseCount;
  Boolean          forcePrimaryBlock;

  Boolean          showFeatStats;
  Boolean          showRefStats;
  Boolean          hideFeatures;
  Boolean          hideImpFeats;
  Boolean          hideVariations;
  Boolean          hideRepeatRegions;
  Boolean          hideSitesBondsRegions;
  Boolean          hideCddFeats;
  Boolean          hideCdsProdFeats;

  Boolean          hideGeneRIFs;
  Boolean          onlyGeneRIFs;
  Boolean          onlyReviewPubs;
  Boolean          newestPubs;
  Boolean          oldestPubs;
  Boolean          hidePubs;

  Boolean          showFtableRefs;
  Boolean          hideGaps;
  Boolean          hideSources;
  Boolean          hideSequence;

  Boolean          isGPS;
  Boolean          copyGpsCdsUp;
  Boolean          copyGpsGeneDown;

  Boolean          isNCBIGenomes;
  Boolean          isRefSeq;

  Boolean          showContigAndSeq;

  Char             basename [SEQID_MAX_LEN];

  SeqFeatPtr       currfargap;

  SeqFeatPtr       lastsfp;
  SeqAnnotPtr      lastsap;
  Int4             lastleft;
  Int4             lastright;

  SeqFeatPtr       bestprot;

  Boolean          firstfeat;
  Boolean          featseen;
  Boolean          featjustseen;
  Int4             localFeatCount;
  ValNodePtr       wgsaccnlist;

  Boolean          has_mat_peptide;
  Boolean          has_sig_peptide;
  Int2             sig_pept_trim_len;

  Boolean          farFeatTimeLimit;
  time_t           farFeatStartTime;

  Boolean          sourcePubFuse;

  SeqSubmitPtr     ssp;
  Boolean          hup;

  Boolean          failed;
} Asn2gbWork, PNTR Asn2gbWorkPtr;


/* Seq-hist replacedBy is preformatted into string field, */
/* then comment descriptors, Map location:, and Region:, */
/* then comment features, finally HTGS */

typedef struct comment_block {
  ASN2GB_BASE_BLOCK
  Boolean           first;
  Boolean           no_blank_before;
} CommentBlock, PNTR CommentBlockPtr;

/* internal reference block has fields on top of RefBlock fields */

typedef struct int_ref_block {
  RefBlock   rb;
  DatePtr    date;     /* internal sorting use only */
  SeqLocPtr  loc;      /* final location on target bioseq */
  CharPtr    authstr;  /* author string */
  Uint2      index;    /* index if feature on target bioseq */
  Boolean    justuids; /* gibb pub with uids and Figure, etc. */
  CharPtr    fig;      /* figure string from equivalent gibb pub */
  CharPtr    maploc;   /* maploc string from equivalent gibb pub */
  Boolean    poly_a;   /* poly_a field from equivalent gibb pub */
  Int4       left;
  Int4       right;
} IntRefBlock, PNTR IntRefBlockPtr;

/* internal source block has fields on top of BaseBlock fields */

typedef struct int_src_block {
  BaseBlock         bb;
  Boolean           is_descriptor;
  Boolean           is_focus;
  Boolean           is_synthetic;
  BioSourcePtr      biop;
  Uint4             orghash;
  Uint4             modhash;
  Uint4             subhash;
  Uint4             xrfhash;
  SeqLocPtr         loc;     /* final location on target bioseq */
  CharPtr           taxname;
  CharPtr           comment;
  OrgModPtr         omp;
  SubSourcePtr      ssp;
  ValNodePtr        vnp;
  Int4              left;
  Int4              right;
  Int4              source_count;
} IntSrcBlock, PNTR IntSrcBlockPtr;

/* internal feature block has fields on top of FeatBlock fields */

typedef struct int_feat_block {
  FeatBlock  fb;
  Boolean    mapToNuc;
  Boolean    mapToProt;
  Boolean    mapToGen;
  Boolean    mapToMrna;
  Boolean    mapToPep;
  Boolean    isCDS;     /* set if using IntCdsBlock */
  Boolean    isPrt;     /* set if using IntPrtBlock */
  Boolean    firstfeat;
  Int4       left;
  Int4       right;
  Int4       feat_count; /* unique in combination with feature type */
} IntFeatBlock, PNTR IntFeatBlockPtr;

/* internal cds block has fields on top of IntFeatBlock fields */

typedef struct int_cds_block {
  IntFeatBlock  ifb;
  CharPtr       fig;    /* figure string from pub */
  CharPtr       maploc; /* maploc string from pub */
} IntCdsBlock, PNTR IntCdsBlockPtr;

/* internal protein block has fields on top of IntFeatBlock fields */

typedef struct int_prt_block {
  IntFeatBlock  ifb;
  Boolean       is_whole_loc;
  Boolean       suppress_mol_wt;
  Boolean       trim_initial_met;
  Int2          sig_pept_trim_len;
} IntPrtBlock, PNTR IntPrtBlockPtr;


/* enumerated qualifier category definitions */

typedef enum {
  Qual_class_ignore = 0,
  Qual_class_string,
  Qual_class_tilde,
  Qual_class_sgml,
  Qual_class_boolean,
  Qual_class_int,
  Qual_class_evidence,
  Qual_class_exception,
  Qual_class_valnode,
  Qual_class_EC_valnode,
  Qual_class_xtraprds,
  Qual_class_quote,
  Qual_class_EC_quote,
  Qual_class_noquote,
  Qual_class_label,
  Qual_class_number,
  Qual_class_paren,
  Qual_class_usedin,
  Qual_class_region,
  Qual_class_replace,
  Qual_class_consplice,
  Qual_class_bond,
  Qual_class_site,
  Qual_class_L_R_B,
  Qual_class_rpt,
  Qual_class_organelle,
  Qual_class_orgmod,
  Qual_class_subsource,
  Qual_class_code_break,
  Qual_class_anti_codon,
  Qual_class_codon,
  Qual_class_compare,
  Qual_class_method,
  Qual_class_pubset,
  Qual_class_db_xref,
  Qual_class_nuc_id,
  Qual_class_prt_id,
  Qual_class_seq_loc,
  Qual_class_its,
  Qual_class_sec_str,
  Qual_class_trna_codons,
  Qual_class_translation,
  Qual_class_transcription,
  Qual_class_peptide,
  Qual_class_protnames,
  Qual_class_encodes,
  Qual_class_illegal,
  Qual_class_note,
  Qual_class_rpt_unit,
  Qual_class_product,
  Qual_class_model_ev,
  Qual_class_gene_syn,
  Qual_class_sep_gene_syn,
  Qual_class_locus_tag,
  Qual_class_map,
  Qual_class_go,
  Qual_class_nomenclature,
  Qual_class_gene_nomen,
  Qual_class_pcr,
  Qual_class_pcr_react,
  Qual_class_mol_wt,
  Qual_class_voucher,
  Qual_class_lat_lon,
  Qual_class_mobile_element,
  Qual_class_tag_peptide,
  Qual_class_variation_id,
  Qual_class_delta_item,
  Qual_class_variation_set,
  Qual_class_experiment
}  QualType;

/* source 'feature' */

/* some qualifiers will require additional content verification not
   explicitly indicated by the class type */

typedef enum {
  SCQUAL_acronym = 1,
  SCQUAL_altitude,
  SCQUAL_anamorph,
  SCQUAL_authority,
  SCQUAL_biotype,
  SCQUAL_biovar,
  SCQUAL_bio_material,
  SCQUAL_breed,
  SCQUAL_cell_line,
  SCQUAL_cell_type,
  SCQUAL_chemovar,
  SCQUAL_chromosome,
  SCQUAL_citation,
  SCQUAL_clone,
  SCQUAL_clone_lib,
  SCQUAL_collected_by,
  SCQUAL_collection_date,
  SCQUAL_common,
  SCQUAL_common_name,
  SCQUAL_country,
  SCQUAL_cultivar,
  SCQUAL_culture_collection,
  SCQUAL_db_xref,
  SCQUAL_org_xref,
  SCQUAL_dev_stage,
  SCQUAL_dosage,
  SCQUAL_ecotype,
  SCQUAL_endogenous_virus_name,
  SCQUAL_environmental_sample,
  SCQUAL_extrachrom,
  SCQUAL_focus,
  SCQUAL_forma,
  SCQUAL_forma_specialis,
  SCQUAL_frequency,
  SCQUAL_fwd_primer_name,
  SCQUAL_fwd_primer_seq,
  SCQUAL_gb_acronym,
  SCQUAL_gb_anamorph,
  SCQUAL_gb_synonym,
  SCQUAL_genotype,
  SCQUAL_germline,
  SCQUAL_group,
  SCQUAL_haplogroup,
  SCQUAL_haplotype,
  SCQUAL_identified_by,
  SCQUAL_ins_seq_name,
  SCQUAL_isolate,
  SCQUAL_isolation_source,
  SCQUAL_lab_host,
  SCQUAL_label,
  SCQUAL_lat_lon,
  SCQUAL_linkage_group,
  SCQUAL_macronuclear,
  SCQUAL_map,
  SCQUAL_mating_type,
  SCQUAL_metagenome_note,
  SCQUAL_metagenome_source,
  SCQUAL_metagenomic,
  SCQUAL_mol_type,
  SCQUAL_note,
  SCQUAL_old_lineage,
  SCQUAL_old_name,
  SCQUAL_organism,
  SCQUAL_organelle,
  SCQUAL_orgmod_note,
  SCQUAL_pathovar,
  SCQUAL_PCR_primers,
  SCQUAL_PCR_primer_note,
  SCQUAL_PCR_reaction,
  SCQUAL_phenotype,
  SCQUAL_plasmid_name,
  SCQUAL_plastid_name,
  SCQUAL_pop_variant,
  SCQUAL_rearranged,
  SCQUAL_rev_primer_name,
  SCQUAL_rev_primer_seq,
  SCQUAL_segment,
  SCQUAL_seqfeat_note,
  SCQUAL_sequenced_mol,
  SCQUAL_serogroup,
  SCQUAL_serotype,
  SCQUAL_serovar,
  SCQUAL_sex,
  SCQUAL_spec_or_nat_host,
  SCQUAL_specimen_voucher,
  SCQUAL_strain,
  SCQUAL_sub_clone,
  SCQUAL_sub_group,
  SCQUAL_sub_species,
  SCQUAL_sub_strain,
  SCQUAL_sub_type,
  SCQUAL_subsource_note,
  SCQUAL_synonym,
  SCQUAL_teleomorph,
  SCQUAL_tissue_lib,
  SCQUAL_tissue_type,
  SCQUAL_transgenic,
  SCQUAL_transposon_name,
  SCQUAL_type,
  SCQUAL_type_material,
  SCQUAL_unstructured,
  SCQUAL_usedin,
  SCQUAL_variety,
  SCQUAL_whole_replicon,
  SCQUAL_zero_orgmod,
  SCQUAL_one_orgmod,
  SCQUAL_zero_subsrc,
  ASN2GNBK_TOTAL_SOURCE
}  SourceType;

NLM_EXTERN SourceType orgModToSourceIdx [42];

typedef enum {
  FTQUAL_allele = 1,
  FTQUAL_anticodon,
  FTQUAL_artificial_location,
  FTQUAL_artificial_location_str,
  FTQUAL_bond,
  FTQUAL_bond_type,
  FTQUAL_bound_moiety,
  FTQUAL_cdd_definition,
  FTQUAL_cds_product,
  FTQUAL_citation,
  FTQUAL_clone,
  FTQUAL_coded_by,
  FTQUAL_compare,
  FTQUAL_codon,
  FTQUAL_codon_start,
  FTQUAL_cons_splice,
  FTQUAL_db_xref,
  FTQUAL_delta_item,
  FTQUAL_derived_from,
  FTQUAL_direction,
  FTQUAL_EC_number,
  FTQUAL_encodes,
  FTQUAL_estimated_length,
  FTQUAL_evidence,
  FTQUAL_exception,
  FTQUAL_exception_note,
  FTQUAL_experiment,
  FTQUAL_experiment_string,
  FTQUAL_extra_products,
  FTQUAL_figure,
  FTQUAL_frequency,
  FTQUAL_function,
  FTQUAL_gap_type,
  FTQUAL_gene,
  FTQUAL_gene_desc,
  FTQUAL_gene_allele,
  FTQUAL_gene_map,
  FTQUAL_gene_cyt_map,
  FTQUAL_gene_gen_map,
  FTQUAL_gene_rad_map,
  FTQUAL_gene_syn,
  FTQUAL_gene_syn_refseq,
  FTQUAL_gene_note,
  FTQUAL_gene_xref,
  FTQUAL_go_component,
  FTQUAL_go_function,
  FTQUAL_go_process,
  FTQUAL_heterogen,
  FTQUAL_illegal_qual,
  FTQUAL_inference,
  FTQUAL_inference_string,
  FTQUAL_inference_good,
  FTQUAL_inference_bad,
  FTQUAL_insertion_seq,
  FTQUAL_label,
  FTQUAL_linkage_evidence,
  FTQUAL_locus_tag,
  FTQUAL_map,
  FTQUAL_maploc,
  FTQUAL_mobile_element,
  FTQUAL_mobile_element_type,
  FTQUAL_mod_base,
  FTQUAL_modelev,
  FTQUAL_mol_wt,
  FTQUAL_ncRNA_class,
  FTQUAL_ncRNA_note,
  FTQUAL_ncRNA_other,
  FTQUAL_nomenclature,
  FTQUAL_gene_nomen,
  FTQUAL_note,
  FTQUAL_number,
  FTQUAL_old_locus_tag,
  FTQUAL_operon,
  FTQUAL_organism,
  FTQUAL_partial,
  FTQUAL_PCR_conditions,
  FTQUAL_peptide,
  FTQUAL_phenotype,
  FTQUAL_product,
  FTQUAL_product_quals,
  FTQUAL_prot_activity,
  FTQUAL_prot_comment,
  FTQUAL_prot_EC_number,
  FTQUAL_prot_note,
  FTQUAL_prot_method,
  FTQUAL_prot_conflict,
  FTQUAL_prot_desc,
  FTQUAL_prot_missing,
  FTQUAL_prot_name,
  FTQUAL_prot_names,
  FTQUAL_protein_id,
  FTQUAL_pseudo,
  FTQUAL_pseudogene,
  FTQUAL_pyrrolysine,
  FTQUAL_pyrrolysine_note,
  FTQUAL_recombination_class,
  FTQUAL_recombination_note,
  FTQUAL_recombination_other,
  FTQUAL_region,
  FTQUAL_region_name,
  FTQUAL_regulatory_class,
  FTQUAL_regulatory_note,
  FTQUAL_regulatory_other,
  FTQUAL_replace,
  FTQUAL_ribosomal_slippage,
  FTQUAL_rpt_family,
  FTQUAL_rpt_type,
  FTQUAL_rpt_unit,
  FTQUAL_rpt_unit_range,
  FTQUAL_rpt_unit_seq,
  FTQUAL_rrna_its,
  FTQUAL_satellite,
  FTQUAL_sec_str_type,
  FTQUAL_selenocysteine,
  FTQUAL_selenocysteine_note,
  FTQUAL_seqannot_note,
  FTQUAL_seqfeat_note,
  FTQUAL_site,
  FTQUAL_site_type,
  FTQUAL_standard_name,
  FTQUAL_tag_peptide,
  FTQUAL_tag_peptide_str,
  FTQUAL_transcription,
  FTQUAL_transcript_id,
  FTQUAL_transcript_id_note,
  FTQUAL_transl_except,
  FTQUAL_transl_table,
  FTQUAL_translation,
  FTQUAL_transposon,
  FTQUAL_trans_splicing,
  FTQUAL_trna_aa,
  FTQUAL_trna_codons,
  FTQUAL_trna_codons_note,
  FTQUAL_UniProtKB_evidence,
  FTQUAL_usedin,
  FTQUAL_variation_id,
  FTQUAL_variation_set,
  FTQUAL_xtra_prod_quals,
  ASN2GNBK_TOTAL_FEATUR
}  FtQualType;

NLM_EXTERN void FF_www_db_xref(
  IntAsn2gbJobPtr ajp,
  StringItemPtr ffstring,
  CharPtr db,
  CharPtr identifier,
  BioseqPtr bsp
);

NLM_EXTERN void FF_www_specimen_voucher (
  IntAsn2gbJobPtr ajp,
  StringItemPtr ffstring,
  CharPtr subname
);

NLM_EXTERN void FF_Add_NCBI_Base_URL (
  StringItemPtr ffstring,
  CharPtr url
);

NLM_EXTERN Boolean StringIsJustQuotes (
  CharPtr str
);


typedef struct sourcequal {
  CharPtr   name;
  QualType  qualclass;
} SourceQual, PNTR SourceQualPtr;

NLM_EXTERN SourceQual asn2gnbk_source_quals [ASN2GNBK_TOTAL_SOURCE];

NLM_EXTERN SourceType subSourceToSourceIdx [45];

NLM_EXTERN void DoOneSection (
  BioseqPtr target,
  BioseqPtr parent,
  BioseqPtr bsp,
  BioseqPtr refs,
  SeqLocPtr slp,
  Uint2 seg,
  Int4 from,
  Int4 to,
  Boolean contig,
  Boolean onePartOfSeg,
  Asn2gbWorkPtr awp
);

NLM_EXTERN void DoOneBioseq (
  BioseqPtr bsp,
  Pointer userdata
);

NLM_EXTERN BaseBlockPtr Asn2gbAddBlock (
  Asn2gbWorkPtr awp,
  BlockType blocktype,
  size_t size
);

NLM_EXTERN void InitWWW (IntAsn2gbJobPtr ajp);
NLM_EXTERN void FiniWWW (IntAsn2gbJobPtr ajp);
NLM_EXTERN Boolean GetWWW (IntAsn2gbJobPtr ajp);

NLM_EXTERN Boolean CommentHasSuspiciousHtml (IntAsn2gbJobPtr ajp, CharPtr searchString);

NLM_EXTERN StringItemPtr FFGetString (IntAsn2gbJobPtr ajp);
NLM_EXTERN void FFRecycleString (IntAsn2gbJobPtr ajp, StringItemPtr ffstring);
NLM_EXTERN void FFAddOneChar (
  StringItemPtr sip, 
  Char ch,
  Boolean convertQuotes
);
NLM_EXTERN void FFAddNewLine(StringItemPtr ffstring);
NLM_EXTERN void FFAddNChar (
  StringItemPtr sip, 
  Char ch,
  Int4 n,
  Boolean convertQuotes
);
NLM_EXTERN void FFExpandTildes (StringItemPtr sip, CharPtr PNTR cpp);
NLM_EXTERN void FFSemicolonSeparateTildes (StringItemPtr sip, CharPtr PNTR cpp);
NLM_EXTERN void FFReplaceTildesWithSpaces (StringItemPtr ffstring, CharPtr PNTR cpp);
NLM_EXTERN void FFOldExpand (StringItemPtr sip, CharPtr PNTR cpp);
NLM_EXTERN void AddCommentStringWithTildes (StringItemPtr ffstring, CharPtr string);
NLM_EXTERN void AddCommentWithURLlinks (
  IntAsn2gbJobPtr ajp,
  StringItemPtr ffstring,
  CharPtr prefix,
  CharPtr str,
  CharPtr suffix
);
NLM_EXTERN CharPtr GetStrForStructuredComment (
  IntAsn2gbJobPtr ajp,
  UserObjectPtr uop
);
NLM_EXTERN void AddStringWithTildes (StringItemPtr ffstring, CharPtr string);
NLM_EXTERN void FFProcessTildes (StringItemPtr sip, CharPtr PNTR cpp, Int2 tildeAction);
NLM_EXTERN void FFAddPeriod (StringItemPtr sip);
NLM_EXTERN void FFAddOneString (
  StringItemPtr sip, 
  CharPtr string,
  Boolean addPeriod, 
  Boolean convertQuotes,
  Int2 tildeAction
);
NLM_EXTERN void FFCatenateSubString (
  StringItemPtr dest,
  StringItemPtr start_sip, Int4 start_pos,
  StringItemPtr end_sip, Int4 end_pos,
  Uint4 line_max
);
NLM_EXTERN CharPtr FFToCharPtr (StringItemPtr sip);
NLM_EXTERN CharPtr FFToCharPtrEx (StringItemPtr sip, CharPtr pfx, CharPtr sfx);
NLM_EXTERN void FFSkipLink (StringItemPtr PNTR iterp, Int4Ptr ip);
NLM_EXTERN void FFSkipHTMLAmpersandEscape (StringItemPtr PNTR iterp, Int4Ptr ip);

NLM_EXTERN Boolean FFIsStartOfLink (
    StringItemPtr iter,
    Int4 pos );

NLM_EXTERN Boolean FFIsStartOfHTMLAmpersandEscape (
    StringItemPtr iter,
    Int4 pos );

NLM_EXTERN void FFSavePosition(StringItemPtr ffstring, StringItemPtr PNTR bufptr, Int4 PNTR posptr);
NLM_EXTERN void FFTrim (
    StringItemPtr ffstring,
    StringItemPtr line_start,
    Int4 line_pos,
    Int4 line_prefix_len
);
NLM_EXTERN int FFNextChar(
  StringItemPtr start_sip,
  Int4 start_pos
);
NLM_EXTERN void FFAdvanceChar(
  StringItemPtr* start_sip,
  Int4* start_pos
);
NLM_EXTERN void FFCalculateLineBreak (
  StringItemPtr PNTR break_sip, Int4 PNTR break_pos,
  Int4 init_indent, Int4 visible,
  Boolean is_html
);
NLM_EXTERN void FFLineWrap (
  IntAsn2gbJobPtr ajp,
  StringItemPtr dest, 
  StringItemPtr src, 
  Int4 init_indent,
  Int4 cont_indent, 
  Int4 line_max,
  CharPtr eb_line_prefix
);
NLM_EXTERN void FFStartPrint (
  StringItemPtr sip,
  FmtType format,
  Int4 gb_init_indent,
  Int4 gb_cont_indent,
  CharPtr gb_label,
  Int4 gb_tab_to,
  Int4 eb_init_indent,
  Int4 eb_cont_indent,
  CharPtr eb_line_prefix,
  Boolean eb_print_xx 
);
NLM_EXTERN void FFAddTextToString (
  StringItemPtr ffstring, 
  CharPtr prefix,
  CharPtr string,
  CharPtr suffix,
  Boolean addPeriod,
  Boolean convertQuotes,
  Int2 tildeAction
);
NLM_EXTERN CharPtr FFEndPrint (
  IntAsn2gbJobPtr ajp,
  StringItemPtr ffstring,
  FmtType format,
  Int2 gb_init_indent,
  Int2 gb_cont_indent,
  Int2 eb_init_indent,
  Int2 eb_cont_indent,
  CharPtr eb_line_prefix
);
NLM_EXTERN CharPtr FFEndPrintEx (
  IntAsn2gbJobPtr ajp,
  StringItemPtr ffstring,
  FmtType format,
  Int2 gb_init_indent,
  Int2 gb_cont_indent,
  Int2 eb_init_indent,
  Int2 eb_cont_indent,
  CharPtr eb_line_prefix,
  CharPtr pfx,
  CharPtr sfx
);
NLM_EXTERN Uint4 FFLength(StringItemPtr ffstring);
NLM_EXTERN Char FFCharAt(StringItemPtr ffstring, Uint4 pos);
NLM_EXTERN Char FFFindChar (
  StringItemPtr ffstring,
  StringItemPtr start_buf,
  Uint4 start_pos,
  Uint4 old_pos,
  Uint4 new_pos
);
NLM_EXTERN Boolean FFEmpty(StringItemPtr ffstring);
NLM_EXTERN Int4 FFStringSearch (
  StringItemPtr text,
  const CharPtr pattern,
  Uint4 position
);
NLM_EXTERN Boolean FFStartsWith( 
  StringItemPtr text,
  Int4 text_pos,
  const CharPtr pattern,
  Boolean case_insens
);

/*
 * Scans the given buffer from a given scan position, for the next occurrence of 
 * the indicated character. The search breaks when the character is found, or the
 * supplied break position is reached.
 * On exit, the scan position will either be on the character found, or at the 
 * given break position.
 */
NLM_EXTERN Boolean FFFindSingleChar(
  StringItemPtr* p_line_sip,
  Int4* p_line_pos,
  StringItemPtr break_sip,
  Int4 break_pos,
  char c 
);

 /*
 * Returns the number of bytes remaining in the buffer chain, starting from the 
 * given buffer and a read mark inside it.
 */
NLM_EXTERN Int4 FFRemainingLength(
  StringItemPtr sip,
  Int4 cur_pos
);

 /*
 * Scans the given line for the next opening tag of an HTML hyperlink. Ajusts 
 * the line position to immediately after the opening tag (if such a tag is 
 * found) or the the end of the line (if no such tag is found).
 * If a character buffer is supplied, this function will copy any opening tag
 * it finds into that buffer.
 */
NLM_EXTERN Boolean FFExtractNextOpenLink(
  StringItemPtr* p_line_sip,
  Int4* p_line_pos,
  StringItemPtr break_sip,
  Int4 break_pos,
  char* buf_open_link 
);

 /*
 * Scans the given line for the next closing tag of an HTML hyperlink. Ajusts 
 * the line position to immediately after the closing tag (if such a tag is 
 * found) or the the end of the line (if no such tag is found).
 */
NLM_EXTERN Boolean FFExtractNextCloseLink(
  StringItemPtr* p_line_sip,
  Int4* p_line_pos,
  StringItemPtr break_sip,
  Int4 break_pos 
);

/*
 * Tests whether the line ends between the opening and closing tag of an HTML 
 * hyper link.
 */
NLM_EXTERN Boolean FFLineBreakSplitsHtmlLink( 
  StringItemPtr start_sip, 
  Int4 start_pos, 
  StringItemPtr break_sip, 
  Int4 break_pos,
  char* buf_link_open, 
  Int4* html_open_link_counter
); 

NLM_EXTERN Boolean IsWholeWordSubstr (
  StringItemPtr searchStr,
  Uint4 foundPos,
  CharPtr subStr
);

NLM_EXTERN ValNodePtr ValNodeCopyStrToHead (ValNodePtr PNTR head, Int2 choice, CharPtr str);
NLM_EXTERN CharPtr MergeFFValNodeStrs (
  ValNodePtr list
);
NLM_EXTERN void AddValNodeString (
  ValNodePtr PNTR head,
  CharPtr prefix,
  CharPtr string,
  CharPtr suffix
);
NLM_EXTERN void FFAddString_NoRedund (
  StringItemPtr unique,
  CharPtr prefix,
  CharPtr string,
  CharPtr suffix,
  Boolean convertQuotes
);
NLM_EXTERN void s_AddPeriodToEnd (CharPtr someString);
NLM_EXTERN Boolean s_RemovePeriodFromEnd (CharPtr someString);
NLM_EXTERN Boolean IsEllipsis (
  CharPtr str
);
NLM_EXTERN void A2GBSeqLocReplaceID (
  SeqLocPtr newloc,
  SeqLocPtr ajpslp
);
NLM_EXTERN CharPtr asn2gb_PrintDate (
  DatePtr dp
);
NLM_EXTERN CharPtr DateToFF (
  CharPtr buf,
  DatePtr dp,
  Boolean citSub
);

NLM_EXTERN CharPtr FFFlatLoc (
  IntAsn2gbJobPtr ajp,
  BioseqPtr bsp,
  SeqLocPtr location,
  Boolean masterStyle,
  Boolean isGap
);

NLM_EXTERN void FF_www_featloc(StringItemPtr ffstring, CharPtr loc);

NLM_EXTERN void FF_asn2gb_www_featkey (
  IntAsn2gbJobPtr ajp,
  StringItemPtr ffstring,
  CharPtr key,
  SeqFeatPtr sfp,
  SeqLocPtr slp,
  Int4 from,
  Int4 to,
  Uint1 strand,
  Uint4 itemID
);

NLM_EXTERN void FF_asn2gb_www_featkey_Ex (
  IntAsn2gbJobPtr ajp,
  StringItemPtr ffstring,
  CharPtr key,
  SeqFeatPtr sfp,
  SeqLocPtr slp,
  Int4 from,
  Int4 to,
  Uint1 strand,
  Uint4 itemID,
  Int2 sat,
  Int4 sat_key
);

NLM_EXTERN CharPtr AddJsInterval (
  IntAsn2gbSectPtr iasp,
  CharPtr pfx,
  BioseqPtr target,
  Uint1 featdeftype,
  SeqLocPtr location,
  CharPtr currAccVer
);

NLM_EXTERN SeqFeatPtr GetGeneByXref (
  BioseqPtr bsp,
  GeneRefPtr grp
);

NLM_EXTERN GeneRefPtr GetGeneByFeat (
  SeqFeatPtr sfp,
  BoolPtr pseudoP,
  BoolPtr suppressedP
);

NLM_EXTERN CharPtr GetMolTypeQual (
  BioseqPtr bsp
);

NLM_EXTERN void AddFeatureToGbseq (
  GBSeqPtr gbseq,
  GBFeaturePtr gbfeat,
  CharPtr str,
  SeqFeatPtr sfp
);

NLM_EXTERN void AddIntervalsToGbfeat (
  GBFeaturePtr gbfeat,
  SeqLocPtr location,
  BioseqPtr target
);

NLM_EXTERN SeqIdPtr SeqLocIdForProduct (
  SeqLocPtr product
);

NLM_EXTERN CharPtr GetAuthorsString (
  FmtType format,
  AuthListPtr alp,
  CharPtr PNTR consortP,
  IndxPtr index,
  GBReferencePtr gbref
);

NLM_EXTERN AuthListPtr GetAuthListPtr (
  PubdescPtr pdp,
  CitSubPtr csp
);

NLM_EXTERN Int2 MatchRef (
  ValNodePtr ppr,
  RefBlockPtr PNTR rbpp,
  Int2 numReferences
);

NLM_EXTERN SeqLocPtr SeqLocReMapEx (
  SeqIdPtr newid,
  SeqLocPtr seq_loc,
  SeqLocPtr location,
  Int4 offset,
  Boolean rev,
  Boolean masterStyle,
  Boolean relaxed
);

NLM_EXTERN CharPtr Get3LetterSymbol (
  IntAsn2gbJobPtr  ajp,
  Uint1 seq_code,
  SeqCodeTablePtr table,
  Uint1 residue
);

NLM_EXTERN CharPtr CleanQualValue (
  CharPtr str
);
NLM_EXTERN CharPtr Asn2gnbkCompressSpaces (CharPtr str);
NLM_EXTERN CharPtr StripAllSpaces (
  CharPtr str
);

NLM_EXTERN Boolean GetAccnVerFromServer (BIG_ID gi, CharPtr buf);

NLM_EXTERN CharPtr bondList [];
NLM_EXTERN CharPtr siteList [];
NLM_EXTERN CharPtr secStrText [];

NLM_EXTERN CharPtr goQualType [];
NLM_EXTERN CharPtr goFieldType [];

NLM_EXTERN CharPtr legalDbXrefs [];
NLM_EXTERN CharPtr legalSrcDbXrefs [];
NLM_EXTERN CharPtr legalRefSeqDbXrefs [];

NLM_EXTERN Boolean DbxrefIsValid (
  CharPtr name,
  BoolPtr is_refseq_P,
  BoolPtr is_source_P,
  BoolPtr is_badcap_P,
  CharPtr PNTR goodcapP
);

NLM_EXTERN void AddAllDbxrefsToBioseq (
  BioseqPtr bsp
);

NLM_EXTERN void AddRefStatsBlock (
  Asn2gbWorkPtr awp
);
NLM_EXTERN Boolean AddReferenceBlock (
  Asn2gbWorkPtr awp,
  Boolean isRefSeq
);
NLM_EXTERN void AddSourceFeatBlock (
  Asn2gbWorkPtr awp
);
NLM_EXTERN void AddFeatStatsBlock (
  Asn2gbWorkPtr awp
);
NLM_EXTERN void AddFeatureBlock (
  Asn2gbWorkPtr awp
);
NLM_EXTERN void AddLocusBlock (
  Asn2gbWorkPtr awp,
  Boolean willshowwgs,
  Boolean willshowtsa,
  Boolean willshowtls,
  Boolean willshowcage,
  Boolean willshowgenome,
  Boolean willshowcontig,
  Boolean willshowsequence
);
NLM_EXTERN void AddAccessionBlock (
  Asn2gbWorkPtr awp
);
NLM_EXTERN void AddVersionBlock (
  Asn2gbWorkPtr awp
);
NLM_EXTERN void AddDblinkBlock (
  Asn2gbWorkPtr awp
);
NLM_EXTERN void AddDbsourceBlock (
  Asn2gbWorkPtr awp
);
NLM_EXTERN void AddDateBlock (
  Asn2gbWorkPtr awp
);
NLM_EXTERN void AddDeflineBlock (
  Asn2gbWorkPtr awp
);
NLM_EXTERN void AddKeywordsBlock (
  Asn2gbWorkPtr awp
);
NLM_EXTERN void AddSegmentBlock (
  Asn2gbWorkPtr awp,
  Boolean onePartOfSeg,
  Boolean is_na
);
NLM_EXTERN void AddSourceOrganismBlock (
  Asn2gbWorkPtr awp
);
NLM_EXTERN void AddCommentBlock (
  Asn2gbWorkPtr awp
);
NLM_EXTERN void AddPrimaryBlock (
  Asn2gbWorkPtr awp
);
NLM_EXTERN void AddFeatHeaderBlock (
  Asn2gbWorkPtr awp
);
NLM_EXTERN void AddSourceFeatBlock (
  Asn2gbWorkPtr awp
);
NLM_EXTERN void AddWGSBlock (
  Asn2gbWorkPtr awp
);
NLM_EXTERN void AddTSABlock (
  Asn2gbWorkPtr awp
);
NLM_EXTERN void AddTLSBlock (
  Asn2gbWorkPtr awp
);
NLM_EXTERN void AddCAGEBlock (
  Asn2gbWorkPtr awp
);
NLM_EXTERN void AddGenomeBlock (
  Asn2gbWorkPtr awp
);
NLM_EXTERN void AddContigBlock (
  Asn2gbWorkPtr awp
);
NLM_EXTERN void AddBasecountBlock (
  Asn2gbWorkPtr awp
);
NLM_EXTERN void AddOriginBlock (
  Asn2gbWorkPtr awp
);
NLM_EXTERN void AddSequenceBlock (
  Asn2gbWorkPtr awp
);
NLM_EXTERN void AddSlashBlock (
  Asn2gbWorkPtr awp
);

NLM_EXTERN CharPtr DefaultFormatBlock (
  Asn2gbFormatPtr afp,
  BaseBlockPtr bbp
);
NLM_EXTERN CharPtr FormatSourceBlock (
  Asn2gbFormatPtr afp,
  BaseBlockPtr bbp
);
NLM_EXTERN CharPtr FormatOrganismBlock (
  Asn2gbFormatPtr afp,
  BaseBlockPtr bbp
);
NLM_EXTERN CharPtr FormatReferenceBlock (
  Asn2gbFormatPtr afp,
  BaseBlockPtr bbp
);
NLM_EXTERN CharPtr FormatCommentBlock (
  Asn2gbFormatPtr afp,
  BaseBlockPtr bbp
);
NLM_EXTERN CharPtr FormatFeatHeaderBlock (
  Asn2gbFormatPtr afp,
  BaseBlockPtr bbp
);
NLM_EXTERN CharPtr FormatSourceFeatBlock (
  Asn2gbFormatPtr afp,
  BaseBlockPtr bbp
);
NLM_EXTERN CharPtr FormatFeatureBlock (
  Asn2gbFormatPtr afp,
  BaseBlockPtr bbp
);
NLM_EXTERN CharPtr FormatBasecountBlock (
  Asn2gbFormatPtr afp,
  BaseBlockPtr bbp
);
NLM_EXTERN CharPtr FormatSequenceBlock (
  Asn2gbFormatPtr afp,
  BaseBlockPtr bbp
);
NLM_EXTERN CharPtr FormatContigBlock (
  Asn2gbFormatPtr afp,
  BaseBlockPtr bbp
);
NLM_EXTERN CharPtr FormatSlashBlock (
  Asn2gbFormatPtr afp,
  BaseBlockPtr bbp
);

NLM_EXTERN void PrintFtableIntervals (
  ValNodePtr PNTR head,
  BioseqPtr target,
  SeqLocPtr location,
  CharPtr label,
  Boolean relaxed
);
NLM_EXTERN void PrintFtableLocAndQuals (
  IntAsn2gbJobPtr ajp,
  ValNodePtr PNTR head,
  BioseqPtr target,
  SeqFeatPtr sfp,
  SeqMgrFeatContextPtr context
);
NLM_EXTERN CharPtr FormatFtableSourceFeatBlock (
  BaseBlockPtr bbp,
  BioseqPtr target
);

NLM_EXTERN void DoImmediateRemoteFeatureFormat (
  Asn2gbFormatPtr afp,
  BaseBlockPtr bbp,
  SeqFeatPtr sfp
);

NLM_EXTERN void DoImmediateFormat (
  Asn2gbFormatPtr afp,
  BaseBlockPtr bbp
);

NLM_EXTERN void DoQuickLinkFormat (
  Asn2gbFormatPtr afp,
  CharPtr str
);

NLM_EXTERN Boolean DeltaLitOnly (
  BioseqPtr bsp
);

NLM_EXTERN Boolean SegHasParts (
  BioseqPtr bsp
);

NLM_EXTERN void SetIfpFeatCount (
  IntFeatBlockPtr ifp,
  IntAsn2gbJobPtr ajp,
  Asn2gbWorkPtr awp,
  Boolean isProt
);

NLM_EXTERN Boolean GetAccVerForBioseq (
  BioseqPtr bsp,
  CharPtr buf,
  size_t buflen,
  Boolean hideGi,
  Boolean isSpan
);

#ifdef __cplusplus
}
#endif

#undef NLM_EXTERN
#ifdef NLM_EXPORT
#define NLM_EXTERN NLM_EXPORT
#else
#define NLM_EXTERN
#endif

#endif /* ndef _ASN2NGNBI_ */

