/*   sqnutils.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:  sqnutils.h
*
* Author:  Jonathan Kans
*
* Version Creation Date:   9/2/97
*
* $Revision: 6.747 $
*
* File Description: 
*
* Modifications:  
* --------------------------------------------------------------------------
* Date     Name        Description of modification
* -------  ----------  -----------------------------------------------------
*
*
* ==========================================================================
*/

#ifndef _SQNUTILS_
#define _SQNUTILS_

#include <ncbi.h>
#include <sequtil.h>
#include <objpubme.h>
#include <objentgene.h>
#include <util/creaders/alnread.h>
#include <subutil.h>

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

#ifdef __cplusplus
extern "C" {
#endif

typedef  void  (*Nlm_ChangeNotifyProc) PROTO ((Pointer));

NLM_EXTERN SeqEntryPtr LIBCALL GetTopSeqEntryForEntityID (Uint2 entityID);
NLM_EXTERN SeqEntryPtr LIBCALL GetBestTopParentForData (Uint2 entityID, BioseqPtr bsp);
NLM_EXTERN SeqEntryPtr LIBCALL GetBestTopParentForItemID (Uint2 entityID, Uint4 itemID, Uint2 itemtype);

NLM_EXTERN SeqEntryPtr LIBCALL GetBestTopParentForDataEx (Uint2 entityID, BioseqPtr bsp, Boolean skipGenProdSet);
NLM_EXTERN SeqEntryPtr LIBCALL GetBestTopParentForItemIDEx (Uint2 entityID, Uint4 itemID, Uint2 itemtype, Boolean skipGenProdSet);

NLM_EXTERN SeqIdPtr SeqIdFindWorst (SeqIdPtr sip);
NLM_EXTERN void ChangeSeqIdToWorstID (SeqIdPtr sip);
NLM_EXTERN void ChangeSeqLocToWorstID (SeqLocPtr slp);

NLM_EXTERN SeqIdPtr MakeSeqID (CharPtr str);
NLM_EXTERN SeqIdPtr MakeUniqueSeqID (CharPtr prefix);

NLM_EXTERN DatePtr DateAdvance (DatePtr dp, Uint1 monthsToAdd);

NLM_EXTERN SeqEntryPtr LIBCALL FindNthSeqEntry (SeqEntryPtr sep, Int2 seq);
NLM_EXTERN SeqEntryPtr LIBCALL FindNthBioseq (SeqEntryPtr sep, Int2 seq);
NLM_EXTERN SeqEntryPtr LIBCALL FindNthSequinEntry (SeqEntryPtr sep, Int2 seq);
NLM_EXTERN SeqEntryPtr LIBCALL FindNucSeqEntry (SeqEntryPtr sep);
NLM_EXTERN BioseqPtr LIBCALL FindNucBioseq (SeqEntryPtr sep);
NLM_EXTERN SeqEntryPtr LIBCALL FindBioseqSetByClass (SeqEntryPtr sep, Uint1 _class);

NLM_EXTERN Boolean LIBCALL SeqEntryHasNucs (SeqEntryPtr sep);
NLM_EXTERN Boolean LIBCALL SeqEntryHasProts (SeqEntryPtr sep);
NLM_EXTERN Boolean LIBCALL SeqEntryHasAligns (Uint2 entityID, SeqEntryPtr sep);
NLM_EXTERN Boolean LIBCALL PowerBLASTASN1Detected (SeqEntryPtr sep);

NLM_EXTERN Int2 EntityIDToGeneticCode (Uint2 entityID, BoolPtr mito, CharPtr taxname, size_t maxsize);
NLM_EXTERN Int2 SeqEntryToGeneticCode (SeqEntryPtr sep, BoolPtr mito, CharPtr taxname, size_t maxsize);
NLM_EXTERN Int2 SeqEntryToBioSource (SeqEntryPtr sep, BoolPtr mito, CharPtr taxname, size_t maxsize, BioSourcePtr PNTR biopp);

NLM_EXTERN Boolean BioseqToGeneticCode (
  BioseqPtr bsp,
  Int2Ptr gencodep,
  BoolPtr mitop,
  BoolPtr plastidp,
  CharPtr taxnamep,
  size_t maxsize,
  BioSourcePtr PNTR biopp
);

NLM_EXTERN SeqLocPtr   CreateWholeInterval (SeqEntryPtr sep);
NLM_EXTERN SeqFeatPtr  CreateNewFeature (SeqEntryPtr sep, SeqEntryPtr placeHere, Uint1 choice, SeqFeatPtr useThis);
NLM_EXTERN ValNodePtr  CreateNewDescriptor (SeqEntryPtr sep, Uint1 choice);

NLM_EXTERN SeqLocPtr WholeIntervalFromSeqId (SeqIdPtr sip);

NLM_EXTERN Boolean IsPopPhyEtcSet (Uint1 _class);

/* Variants that call SeqMgrGetSeqEntryForData. The feature version allows a location
to be specified, overriding the default full-length seq-int location.  (If location is
not NULL, it copies it after deleting the existing sfp->location.)  For both functions
you still need to set the sfp->data.value.ptrvalue of the sdp->data.ptrvalue. */
NLM_EXTERN SeqFeatPtr CreateNewFeatureOnBioseq (BioseqPtr bsp, Uint1 choice, SeqLocPtr slp);
NLM_EXTERN ValNodePtr CreateNewDescriptorOnBioseq (BioseqPtr bsp, Uint1 choice);

NLM_EXTERN void        UpdateLocalId (BioseqPtr bsp, CharPtr localId);
NLM_EXTERN void        UpdateTitle (BioseqPtr bsp, CharPtr title);

NLM_EXTERN GeneRefPtr  CreateNewGeneRef (CharPtr locus, CharPtr allele,
                                     CharPtr desc, Boolean pseudo);
NLM_EXTERN ProtRefPtr  CreateNewProtRef (CharPtr name, CharPtr desc,
                                     CharPtr ec, CharPtr activity);
NLM_EXTERN CdRegionPtr CreateNewCdRgn (Uint1 frame, Boolean orf, Int2 genCode);

NLM_EXTERN void        SetSeqFeatData (SeqFeatPtr sfp, Pointer data);
NLM_EXTERN void        SetSeqFeatProduct (SeqFeatPtr sfp, BioseqPtr bsp);
NLM_EXTERN void        ResetSeqFeatInterval (SeqFeatPtr sfp);

NLM_EXTERN void        AddSeqFeatInterval (SeqFeatPtr sfp, BioseqPtr bsp, Int4 from, Int4 to,
                                       Boolean partial5, Boolean partial3);

NLM_EXTERN void        AddSeqLocPoint (SeqLocPtr PNTR old_slp, SeqIdPtr sip, Int4 location,
                                       Boolean fuzz_before, Boolean fuzz_after, Int2 strand);
NLM_EXTERN void        AddSeqFeatPoint (SeqFeatPtr sfp, BioseqPtr bsp, Int4 location, Boolean fuzz_before, Boolean fuzz_after, Int2 strand);

/* AddSeqEntryToSeqEntry and ReplaceSeqEntryWithSeqEntry leave
   the original target sep pointing to the new structure. */

NLM_EXTERN void        AddSeqEntryToSeqEntry (SeqEntryPtr target, SeqEntryPtr insert, Boolean relink);
NLM_EXTERN void        ReplaceSeqEntryWithSeqEntry (SeqEntryPtr target, SeqEntryPtr replaceWith, Boolean relink);

NLM_EXTERN void        RemoveSeqEntryFromSeqEntry (SeqEntryPtr top, SeqEntryPtr del, Boolean relink);
NLM_EXTERN Int4        RenormalizeNucProtSets (SeqEntryPtr sep, Boolean relink);
NLM_EXTERN Int4        RemoveSingleItemSet (SeqEntryPtr sep, Boolean relink);

/* The following functions are called by the above when relink is TRUE.  Examine the
   code of ReplaceSeqEntryWithSeqEntry (in dlgutil2.c) to see how relink is treated. */

NLM_EXTERN void        GetSeqEntryParent (SeqEntryPtr target, Pointer PNTR parentptr, Uint2Ptr parenttype);

NLM_EXTERN void        SaveSeqEntryObjMgrData (SeqEntryPtr target, ObjMgrDataPtr PNTR omdptopptr, ObjMgrData PNTR omdataptr);
NLM_EXTERN void        RestoreSeqEntryObjMgrData (SeqEntryPtr target, ObjMgrDataPtr omdptop, ObjMgrData PNTR omdataptr);

/* If relink FALSE, call SeqMgrLinkSeqEntry (target, parenttype, parentptr)
   with original parent after all sequences have been added to the target. */

/* If relink FALSE, call SaveSeqEntryObjMgrData with the address of temporary
   ObjMgrDataPtr and ObjMgrData variables, and after calling SeqMgrLinkSeqEntry to
   update the link table, call RestoreSeqEntryObjMgrData with the value of the
   temporary ObjMgrDataPtr and the address of the ObjMgrData variable. */

/* ExtractBioSourceAndPubs and ReplaceBioSourceAndPubs can be called before and
   after AddSeqEntryToSeqEntry to propagate source and pub descriptors to top level. */

NLM_EXTERN ValNodePtr  ExtractBioSourceAndPubs (SeqEntryPtr sep);
NLM_EXTERN void        ReplaceBioSourceAndPubs (SeqEntryPtr sep, ValNodePtr descr);

/* SeqLocMerge combines feature intervals.  It can be used to extend the gene feature
   intervals, and (eventually) to fuse mutliple features into one. */

NLM_EXTERN SeqLocPtr SeqLocMerge (BioseqPtr target,
                                  SeqLocPtr to, SeqLocPtr from,
                                  Boolean single_interval, Boolean fuse_joints,
                                  Boolean add_null);

NLM_EXTERN SeqLocPtr SeqLocMergeEx (BioseqPtr target, SeqLocPtr to, SeqLocPtr from,
                                    Boolean single_interval, Boolean fuse_joints,
                                    Boolean merge_overlaps, Boolean add_null);

NLM_EXTERN SeqLocPtr SeqLocMergeExEx (
  BioseqPtr target,
  SeqLocPtr to,
  SeqLocPtr from,
  Boolean single_interval,
  Boolean fuse_joints,
  Boolean merge_overlaps,
  Boolean add_null,
  Boolean ignore_mixed,
  Boolean ignore_out_of_order,
  Boolean relaxed
);

NLM_EXTERN Boolean CheckSeqLocForPartial (SeqLocPtr location, BoolPtr p5ptr, BoolPtr p3ptr);
NLM_EXTERN void SetSeqLocPartial (SeqLocPtr location, Boolean partial5, Boolean partial3);
NLM_EXTERN void FreeAllFuzz (SeqLocPtr location);
NLM_EXTERN Boolean LocationHasNullsBetween (SeqLocPtr location);
NLM_EXTERN void NormalizeNullsBetween (SeqLocPtr location);
NLM_EXTERN ValNodePtr GetSeqLocPartialSet (SeqLocPtr location);
NLM_EXTERN void SetSeqLocPartialSet (SeqLocPtr location, ValNodePtr vnp);
NLM_EXTERN Boolean SeqLocBadSortOrder (BioseqPtr bsp, SeqLocPtr slp);
NLM_EXTERN Boolean SeqLocMixedStrands (BioseqPtr bsp, SeqLocPtr slp);
/* Check/SetSeqLocPartialEx take lim argument - 3 is tr, 4 is tl */
NLM_EXTERN Boolean CheckSeqLocForPartialEx (SeqLocPtr location, BoolPtr p5ptr, BoolPtr p3ptr, Int4Ptr limptr);
NLM_EXTERN void SetSeqLocPartialEx (SeqLocPtr location, Boolean partial5, Boolean partial3, Int4 lim);

/* GetBioseqGivenSeqLoc returns a segmented bioseq if the SeqLoc is to the parts */

NLM_EXTERN BioseqPtr GetBioseqGivenSeqLoc (SeqLocPtr slp, Uint2 entityID);

NLM_EXTERN BioseqPtr GetBioseqGivenIDs (Uint2 entityID, Uint4 itemID, Uint2 itemtype);
NLM_EXTERN Uint4 GetItemIDGivenPointer (Uint2 entityID, Uint2 itemtype, Pointer lookfor);

NLM_EXTERN Uint1 FindFeatFromFeatDefType (Uint2 subtype);
NLM_EXTERN Uint1 FindFeatDefTypeFromKey (CharPtr key);
NLM_EXTERN CharPtr FindKeyFromFeatDefType (Uint1 type, Boolean forGBFF);

NLM_EXTERN Uint1 CodonToGcIndex (CharPtr codon);
NLM_EXTERN CharPtr GcIndextoCodon (Uint1 index);

NLM_EXTERN GBQualPtr SortFeatureGBQuals (GBQualPtr list);
NLM_EXTERN void CleanupDuplicateGBQuals (GBQualPtr PNTR prevgbq);

/* finds bioseq from (cds) product, gets largest protein feature packaged on it */

NLM_EXTERN SeqFeatPtr LIBCALL GetBestProteinFeatureUnindexed (SeqLocPtr product);

/* set coding region partial flags by initial dash and final star in translation */

NLM_EXTERN void CodingRegionPartialsFromTranslation (SeqEntryPtr sep);

/* impose coding region partial flags onto appropriate mRNA and gene features */

NLM_EXTERN void ImposeCodingRegionPartials (SeqEntryPtr sep);

/* resynchronizes coding regions with product protein bioseq molinfo and protein feature */

NLM_EXTERN void ResynchCodingRegionPartials (SeqEntryPtr sep);
NLM_EXTERN Boolean ResynchCodingRegionPartialsEx (SeqEntryPtr sep, FILE *log_fp);

/* resynchronizes mRNAs with product cDNA bioseq */

NLM_EXTERN void ResynchMessengerRNAPartials (SeqEntryPtr sep);

/* resynchronizes protein feature with product peptide bioseq */

NLM_EXTERN void ResynchProteinPartials (SeqEntryPtr sep);

/* individual feature callbacks for above functions */

NLM_EXTERN void CDSPartialsFromTranslation (SeqFeatPtr sfp, Pointer userdata);
NLM_EXTERN void ImposeCDSPartials (SeqFeatPtr sfp, Pointer userdata);
NLM_EXTERN void ImposeGenePartials (SeqFeatPtr sfp, Pointer userdata);
NLM_EXTERN void ResynchMRNAPartials (SeqFeatPtr sfp, Pointer userdata);
NLM_EXTERN void ResynchCDSPartials (SeqFeatPtr sfp, Pointer userdata);
NLM_EXTERN void ResynchPeptidePartials (SeqFeatPtr sfp, Pointer userdata);

/* functions for associating CDS and parent mRNA using featureIDs */

NLM_EXTERN void ClearFeatIDs (SeqFeatPtr sfp);
NLM_EXTERN void ClearFeatIDXrefs (SeqFeatPtr sfp);

NLM_EXTERN void ClearFeatureIDs (SeqEntryPtr sep);
NLM_EXTERN Int4 FindHighestFeatureID (SeqEntryPtr sep);

NLM_EXTERN void AssignFeatureIDs (SeqEntryPtr sep);
NLM_EXTERN void AssignFeatureIDsWithOffset (SeqEntryPtr sep, Int4Ptr last_used_id, Int4Ptr last_used_ref);

NLM_EXTERN void OffsetFeatureIDs (SeqEntryPtr sep, Int4 offset);
NLM_EXTERN void OffsetFeatureIDXrefs (SeqEntryPtr sep, Int4 offset);

NLM_EXTERN void ReassignFeatureIDs (SeqEntryPtr sep);

NLM_EXTERN void LinkCDSmRNAbyOverlap (SeqEntryPtr sep);
NLM_EXTERN void LinkCDSmRNAbyProduct (SeqEntryPtr sep);
NLM_EXTERN void LinkCDSmRNAbyLabel (SeqEntryPtr sep);
NLM_EXTERN void LinkCDSmRNAbyLabelAndLocation (SeqEntryPtr sep);

NLM_EXTERN void StripFeatIDXrefAsnFilter (AsnIoPtr aip, AsnIoPtr aop);
NLM_EXTERN void StripSeqDataGapAsnFilter (AsnIoPtr aip, AsnIoPtr aop);
NLM_EXTERN void StripNewFeatMolInfoFieldsAsnFilter (AsnIoPtr aip, AsnIoPtr aop);
NLM_EXTERN void StripPCRPrimerAsnFilter (AsnIoPtr aip, AsnIoPtr aop);
NLM_EXTERN void StripOrgNamePgcodeAsnFilter (AsnIoPtr aip, AsnIoPtr aop);
NLM_EXTERN void StripGeneRnaPcrAsnFilter (AsnIoPtr aip, AsnIoPtr aop);
NLM_EXTERN void StripSeqFeatSupportAsnFilter (AsnIoPtr aip, AsnIoPtr aop);

/* functions to parse [org=Drosophila melanogaster] and [gene=lacZ] from titles */
/* for example, passing "gene" to SqnTagFind returns "lacZ" */

#define MAX_SQN_TAGS  200

typedef struct sqntag {
  CharPtr  query;
  Int2     num_tags;
  CharPtr  tag [MAX_SQN_TAGS];
  CharPtr  val [MAX_SQN_TAGS];
  Boolean  used [MAX_SQN_TAGS];
} SqnTag, PNTR SqnTagPtr;

NLM_EXTERN SqnTagPtr SqnTagParse (CharPtr ttl);
NLM_EXTERN SqnTagPtr SqnTagFree (SqnTagPtr stp);

NLM_EXTERN CharPtr SqnTagFind (SqnTagPtr stp, CharPtr tag);
NLM_EXTERN ValNodePtr SqnTagFindMultiple (SqnTagPtr stp, CharPtr tag);
NLM_EXTERN CharPtr SqnTagFindUnused (SqnTagPtr stp, CharPtr tag);

NLM_EXTERN void ReadTechFromString (CharPtr str, MolInfoPtr mip);
NLM_EXTERN void ReadCompletenessFromString (CharPtr str, MolInfoPtr mip);

extern Boolean StringsAreEquivalent (CharPtr str1, CharPtr str2);
NLM_EXTERN Uint1 EquivalentSubSource (CharPtr str);
NLM_EXTERN Uint1 EquivalentOrgMod (CharPtr str);
NLM_EXTERN Uint1 EquivalentSubSourceEx (CharPtr str, Boolean allow_discouraged_and_discontinued);
NLM_EXTERN Uint1 EquivalentOrgModEx (CharPtr str, Boolean allow_discouraged_and_discontinued);

/* functions to extract BioSource, MolInfo, and Bioseq information from parsed titles */

NLM_EXTERN BioSourcePtr ParseTitleIntoBioSource (
  SqnTagPtr stp,
  CharPtr organism,
  BioSourcePtr biop
);

NLM_EXTERN MolInfoPtr ParseTitleIntoMolInfo (
  SqnTagPtr stp,
  MolInfoPtr mip
);

NLM_EXTERN BioseqPtr ParseTitleIntoBioseq (
  SqnTagPtr stp,
  BioseqPtr bsp
);

NLM_EXTERN GeneRefPtr ParseTitleIntoGeneRef (
  SqnTagPtr stp,
  GeneRefPtr grp
);

NLM_EXTERN ProtRefPtr ParseTitleIntoProtRef (
  SqnTagPtr stp,
  ProtRefPtr prp
);

NLM_EXTERN GBBlockPtr ParseTitleIntoGenBank (
  SqnTagPtr stp,
  GBBlockPtr gbp
);

NLM_EXTERN SeqHistPtr ParseTitleIntoSeqHist (
  SqnTagPtr stp,
  SeqHistPtr shp
);

NLM_EXTERN SeqHistPtr ParseStringIntoSeqHist (
  SeqHistPtr shp,
  CharPtr str
);

NLM_EXTERN void ParseTitleIntoSubmitBlock (
  SqnTagPtr stp,
  SubmitBlockPtr sbp
);

NLM_EXTERN UserObjectPtr ParseTitleIntoTpaAssembly (
  SqnTagPtr stp,
  UserObjectPtr uop
);

NLM_EXTERN UserObjectPtr ParseTitleIntoGenomeProjectsDB (
  SqnTagPtr stp,
  UserObjectPtr uop
);

NLM_EXTERN void AddFieldStringToDbLinkUserObject (
  CharPtr str,
  CharPtr field_name,
  UserObjectPtr uop
);

NLM_EXTERN UserObjectPtr ParseTitleIntoDBLinkBioProject (
  SqnTagPtr stp,
  UserObjectPtr uop
);

NLM_EXTERN UserObjectPtr ParseTitleIntoDBLinkBioSample (
  SqnTagPtr stp,
  UserObjectPtr uop
);

NLM_EXTERN UserObjectPtr ParseTitleIntoDBLinkSeqReadArch (
  SqnTagPtr stp,
  UserObjectPtr uop
);

NLM_EXTERN Boolean IsGenomeProjectIDDescriptor (SeqDescrPtr sdp); 
NLM_EXTERN SeqDescrPtr GetGenomeProjectIDDescriptor (BioseqPtr bsp);
NLM_EXTERN Int4 GetGenomeProjectID (BioseqPtr bsp);

NLM_EXTERN CharPtr GetTSAIDDB (BioseqPtr bsp);


NLM_EXTERN void AddPubsFromTitle (
  SqnTagPtr stp,
  SeqDescrPtr PNTR desc_list
);

/* structured comment user object for flatfile presentation */

NLM_EXTERN UserObjectPtr ParseStringIntoStructuredComment (
  UserObjectPtr uop,
  CharPtr str,
  CharPtr prefix,
  CharPtr suffix
);


/* UseLocalAsnloadDataAndErrMsg transiently sets paths to asnload, data, and errmsg
  if they are packaged in the same directory as the executing program. */

NLM_EXTERN Boolean UseLocalAsnloadDataAndErrMsg (void);

/* GetRidOfLocusInSeqIds strips locus from all feature location and product seqIds */

NLM_EXTERN void GetRidOfLocusInSeqIds (Uint2 entityID, SeqEntryPtr sep);

NLM_EXTERN SeqLocPtr StripLocusFromSeqLoc (SeqLocPtr location);
NLM_EXTERN SeqIdPtr SeqIdStripLocus (SeqIdPtr sip);

/* LeaveBestCDD removes all but best CDD region in an area of overlapping features */

NLM_EXTERN void LeaveBestCDD (SeqEntryPtr sep);

/* ConvertPubSrcComDescsToFeats is useful when merging records */

NLM_EXTERN Boolean ConvertPubSrcComDescsToFeats (SeqEntryPtr sep, Boolean pub, Boolean src, Boolean com, Boolean toProts, Boolean PNTR asked_about_prop, Boolean PNTR propagate_descriptions, CharPtr findstring);

NLM_EXTERN void DeleteMultipleTitles (SeqEntryPtr sep, Pointer mydata, Int4 index, Int2 indent);

NLM_EXTERN Uint1 FindTrnaAA (CharPtr str);
NLM_EXTERN Uint1 FindTrnaAA3 (CharPtr str);
NLM_EXTERN CharPtr GetLongSymbolForAA (Char aa);
NLM_EXTERN Uint1 ParseTRnaString (CharPtr strx, BoolPtr justTrnaText, Uint1Ptr codon, Boolean noSingleLetter);
NLM_EXTERN CharPtr FindTrnaAAIndex (CharPtr str);
NLM_EXTERN Char FindResidueByName (CharPtr res_name, SeqCodeTablePtr sctp);
NLM_EXTERN ValNodePtr TokenizeTRnaString (CharPtr strx);
NLM_EXTERN Boolean ParseDegenerateCodon (tRNAPtr trp, Uint1Ptr codon);
NLM_EXTERN Boolean SerialNumberInString (CharPtr str);

/* ModernizeRNAFields uses new RNAGenPtr choice of RnaRef.ext for misc_RNA, ncRNA, tmRNA */

NLM_EXTERN void ModernizeRNAFields (
  SeqFeatPtr sfp
);

/* ModernizeGeneFields populates new GeneNomenclaturePtr field from OfficialNomenclature user object */

NLM_EXTERN void ModernizeGeneFields (
  SeqFeatPtr sfp
);

/* for sorting and uniquing valnode list by (charptr) data.ptrvalue (with case sensitive/insensitive variants) */

NLM_EXTERN int LIBCALLBACK SortVnpByStringCS (VoidPtr ptr1, VoidPtr ptr2);
NLM_EXTERN int LIBCALLBACK SortVnpByStringCI (VoidPtr ptr1, VoidPtr ptr2);
NLM_EXTERN int LIBCALLBACK SortVnpByStringCIUCFirst (VoidPtr ptr1, VoidPtr ptr2);
NLM_EXTERN int LIBCALLBACK SortVnpByStringCILCFirst (VoidPtr ptr1, VoidPtr ptr2);

NLM_EXTERN ValNodePtr UniqueStringValNodeCS (ValNodePtr list);
NLM_EXTERN ValNodePtr UniqueStringValNodeCI (ValNodePtr list);

NLM_EXTERN int LIBCALLBACK SortVnpByNaturalCS (VoidPtr ptr1, VoidPtr ptr2);
NLM_EXTERN int LIBCALLBACK SortVnpByNaturalCI (VoidPtr ptr1, VoidPtr ptr2);

NLM_EXTERN int LIBCALLBACK SortVnpByString (VoidPtr ptr1, VoidPtr ptr2);
NLM_EXTERN ValNodePtr UniqueValNode (ValNodePtr list);

/* for sorting valnode list by choice */

NLM_EXTERN int LIBCALLBACK SortByChoice (VoidPtr ptr1, VoidPtr ptr2);

/* for sorting and uniquing valnode list by data.intvalue */

NLM_EXTERN int LIBCALLBACK SortByIntvalue (VoidPtr ptr1, VoidPtr ptr2);
NLM_EXTERN ValNodePtr UniqueIntValNode (ValNodePtr list);

/* for sorting and uniquing valnode list by data.ptrvalue */

NLM_EXTERN int LIBCALLBACK SortByPtrvalue (VoidPtr ptr1, VoidPtr ptr2);
NLM_EXTERN ValNodePtr UniquePtrValNode (ValNodePtr list);

/* keytag sorts/uniques and then owns valnode character list */

typedef struct keytag {
  Int2               num;
  ValNodePtr         list;
  CharPtr PNTR       index; /* elements point into above valnode list */
} KeyTag;                   /* used as substructure, not allocated separately */

NLM_EXTERN void KeyTagInit (KeyTag PNTR ktp, ValNodePtr list);
NLM_EXTERN void KeyTagClear (KeyTag PNTR ktp);

NLM_EXTERN Int2 KeyFromTag (KeyTag PNTR ktp, CharPtr tag);
NLM_EXTERN CharPtr TagFromKey (KeyTag PNTR ktp, Int2 key);

/* inference qualifier utility */

#define VALID_INFERENCE            0
#define EMPTY_INFERENCE_STRING     1
#define BAD_INFERENCE_PREFIX       2
#define BAD_INFERENCE_BODY         3
#define SINGLE_INFERENCE_FIELD     4
#define SPACES_IN_INFERENCE        5
#define INFERENCE_HAS_COMMENT      6
#define SAME_SPECIES_MISUSED       7
#define BAD_INFERENCE_ACCESSION    8
#define BAD_INFERENCE_ACC_VERSION  9
#define ACC_VERSION_NOT_PUBLIC    10
#define BAD_ACCESSION_TYPE        11
#define UNRECOGNIZED_DATABASE     12

NLM_EXTERN Int2 ValidateInferenceQualifier (CharPtr val, Boolean fetchAccn);


/* from Colombe */
NLM_EXTERN SeqLocPtr StringSearchInBioseq (SeqIdPtr sip, CharPtr sub);

/*****************************************************************************
*
*   SequinEntryList (sep, mydata, mycallback, index, indent)
*       traverses all Seq-entry nodes beginning with sep
*       calls mycallback () at each node
*       Does enter BioseqSets of _class "parts", but ignores the
*       parts set itself
*
*****************************************************************************/

NLM_EXTERN Int4 SequinEntryList (SeqEntryPtr sep, Pointer mydata, SeqEntryFunc mycallback, Int4 index, Int2 indent);

#define SequinEntryCount( a )  SequinEntryList( a ,NULL,NULL,0,0)
#define SequinEntryExplore(a,b,c) SequinEntryList(a, b, c, 0L, 0)

/* Phrap reading function, based on sample code supplied by C. Magness, returns a SeqEntry list
of Bioseqs containing SeqGraphs, with individual reads removed and only contigs remaining */

NLM_EXTERN SeqEntryPtr ReadPhrapFile (FILE *fp);

/* Internal function to read quality scores, made available to parse separate DNA and quality score files */

NLM_EXTERN SeqGraphPtr ReadPhrapQuality (FILE *fp, BioseqPtr bsp);
NLM_EXTERN SeqGraphPtr ReadPhrapQualityFC (FileCachePtr fcp, BioseqPtr bsp);

/* SetPhrapContigOrder takes the results of ReadPhrapFile and a string indicating the order
of contigs, and returns a SeqEntryList in the desired order, with all other contigs removed */

NLM_EXTERN SeqEntryPtr SetPhrapContigOrder (SeqEntryPtr head, CharPtr contigs);

NLM_EXTERN void PrintQualityScores (BioseqPtr bsp, FILE *fp);

NLM_EXTERN void TrimSeqGraph (SeqGraphPtr sgp, Int4 num_to_trim, Boolean from_left);
NLM_EXTERN void TrimQualityScores (BioseqPtr bsp, Int4 num_to_trim, Boolean from_left);

NLM_EXTERN void ReverseSeqGraph (SeqGraphPtr sgp);
NLM_EXTERN void ReverseQualityScores (BioseqPtr bsp);


typedef void (*QualityWriteFunc) (CharPtr buf, Uint4 buflen, Pointer userdata);

NLM_EXTERN void PrintQualityScoresToBuffer (BioseqPtr bsp, Boolean gapIsZero, Pointer userdata, QualityWriteFunc callback);

/* special function for genome contig delta sequences with far pointers */

NLM_EXTERN void PrintQualityScoresForContig (BioseqPtr bsp, Boolean gapIsZero, FILE* fp);

/* more efficient function for far genomic contig, makes separate graphs */

NLM_EXTERN SeqAnnotPtr PhrapGraphForContig (BioseqPtr bsp);

/* ReadContigList builds a far segmented bioseq from a table of accessions, starts, stops,
lengths, and (optional) strands.  Gaps of a given length (with 0 start and stop) are also
allowed. */

NLM_EXTERN SeqEntryPtr ReadContigList (FILE *fp, Boolean coordinatesOnMaster);
NLM_EXTERN SeqEntryPtr ReadContigListEx (FILE *fp, Boolean coordinatesOnMaster, CharPtr seqid, CharPtr title);

/* ReadAsnFastaOrFlatFile reads object manager-registered ASN.1, FASTA, GenBank, EMBL, GenPept,
Feature table, Restriction table, Contig table, Message response, or saved UID list, with the
option of saving FASTA results as OBJ_FASTA (SimpleSeq) to avoid ID collisions */

NLM_EXTERN Pointer ReadAsnFastaOrFlatFileEx (FILE *fp, Uint2Ptr datatypeptr, Uint2Ptr entityIDptr,
                                           Boolean forceNuc, Boolean forceProt,
                                           Boolean parseFastaSeqId, Boolean fastaAsSimpleSeq,
                                           BoolPtr chars_stripped);
NLM_EXTERN Pointer ReadAsnFastaOrFlatFile (FILE *fp, Uint2Ptr datatypeptr, Uint2Ptr entityIDptr,
                                           Boolean forceNuc, Boolean forceProt,
                                           Boolean parseFastaSeqId, Boolean fastaAsSimpleSeq);

/* ReadFeatureTableFile only handles >Feature tables */

NLM_EXTERN Pointer ReadFeatureTableFile (
  FILE *fp,
  Uint2Ptr datatypeptr,
  Uint2Ptr entityIDptr,
  Int4Ptr lineP,
  BoolPtr failP,
  Boolean ignore_web_comments
);

NLM_EXTERN BioseqPtr GetBioseqReferencedByAnnot (
  SeqAnnotPtr sap,
  Uint2 entityID
);

/* ReadDeltaFasta reads a FASTA file, combining raw sequence and >?unk100 lines into
a delta Bioseq.  The file pointer stops at the next FASTA with a real SeqID. */

NLM_EXTERN BioseqPtr ReadDeltaFasta (FILE *fp, Uint2Ptr entityIDptr);

/* This function is identical to ReadDeltaFasta, except that the contents of 
 * chars_stripped will be set to TRUE if characters other than digits were stripped from
 * the sequence, or FALSE if not.
 */
NLM_EXTERN BioseqPtr ReadDeltaFastaEx (FILE *fp, Uint2Ptr entityIDptr, BoolPtr chars_stripped);
NLM_EXTERN BioseqPtr ReadDeltaFastaExEx (FILE *fp, Uint2Ptr entityIDptr, BoolPtr chars_stripped, BoolPtr cache_failed);

/* ReadDeltaFastaWithEmptyDefline reads just one delta sequence with an empty
 * definition line.
 * Calling function should make sure that fp is set to the start of the line 
 * with the empty definition line and that there is a "gap sequence ID"
 * present as the next definition line in the file.
 */
NLM_EXTERN BioseqPtr ReadDeltaFastaWithEmptyDefline (FILE *fp, Uint2Ptr entityIDptr, BoolPtr chars_stripped);

/* PromoteXrefs expands generef or protref feature cross-references (made by reading a
feature table with ReadAsnFastaOrFlatFile) to stand-alone gene features or protein features
and protein bioseqs.  It processes ALL features in the list - you give it the FIRST sfp. */

NLM_EXTERN void PromoteXrefs (
  SeqFeatPtr sfp,
  BioseqPtr bsp,
  Uint2 entityID
);
NLM_EXTERN void PromoteXrefsEx (
  SeqFeatPtr sfp,
  BioseqPtr bsp,
  Uint2 entityID,
  Boolean include_stop,
  Boolean remove_trailingX,
  Boolean gen_prod_set
);
NLM_EXTERN void PromoteXrefsExEx (
  SeqFeatPtr sfp,
  BioseqPtr bsp,
  Uint2 entityID,
  Boolean include_stop,
  Boolean remove_trailingX,
  Boolean gen_prod_set,
  Boolean force_local_id,
  BoolPtr seq_fetch_failP
);

/* SetEmptyGeneticCodes imposes genetic code on all coding regions within a feature table */

NLM_EXTERN void SetEmptyGeneticCodes (SeqAnnotPtr sap, Int2 genCode);

/* AddIntervalToLocation is a convenience function to add a single interval, and is called by
ReadAsnFastaOrFlatFile internally. */

NLM_EXTERN SeqLocPtr AddIntervalToLocation (SeqLocPtr loc, SeqIdPtr sip, Int4 start,
                                            Int4 stop, Boolean partial5, Boolean partial3);

/* AddQualifierToFeature applies cds product and gene qualifiers as protref or generef stored
as feature xrefs.  Most others (e.g., protein_id) are stored as gbquals.  PromoteXrefs can then
turn these special cases into the appropriate structures in fully expanded records. */

NLM_EXTERN void AddQualifierToFeature (SeqFeatPtr sfp, CharPtr qual, CharPtr val);

/* specialized string trimming functions */

NLM_EXTERN CharPtr TrimSpacesAndSemicolons (CharPtr str);
NLM_EXTERN CharPtr TrimSpacesAndJunkFromEnds (CharPtr str, Boolean allowEllipsis);

/* specialized cleanup for subsource and orgmod lists */
NLM_EXTERN void CleanSubSourceList (SubSourcePtr PNTR sspp, Uint1 location);
NLM_EXTERN void CleanOrgModList (OrgModPtr PNTR ompp);

/* used by original BankIt to merge multiple primer subsources */
NLM_EXTERN void CleanSubSourcePrimers (SubSourcePtr PNTR sspp);

NLM_EXTERN Boolean PubIsEffectivelyEmpty (PubdescPtr pdp);

/* extracts and reinserts descriptors in a standard order */
NLM_EXTERN void NormalizeDescriptorOrder (SeqEntryPtr sep);

/* BasicSeqEntryCleanup cleans up strings, moves gbquals to the appropriate field, and
does several other conversions, all without changing the itemID structure (which would
require reindexing) */

NLM_EXTERN void BasicSeqEntryCleanup (SeqEntryPtr sep);

/* AdvancedSeqEntryCleanup also resynchronizes CDS, mRNA, and protein partials */

NLM_EXTERN void AdvancedSeqEntryCleanup (SeqEntryPtr sep);

/* cleanup for a single descriptor, after editing */
NLM_EXTERN void CleanupStringsForOneDescriptor (SeqDescPtr sdp, SeqEntryPtr sep);

/* Selective components of BasicSeqEntryCleanup can be called for QA filtering */

NLM_EXTERN void CleanUpSeqFeat (SeqFeatPtr sfp, Boolean isEmblOrDdbj, Boolean isJscan, Boolean stripSerial, Boolean modernizeFeats, ValNodePtr PNTR publist);

NLM_EXTERN void CleanUpSeqLoc (SeqLocPtr slp);

NLM_EXTERN Boolean FixWrongFuzzOnPlusStrand (SeqLocPtr location);
NLM_EXTERN Boolean FixWrongFuzzOnMinusStrand (SeqLocPtr location);

NLM_EXTERN void CleanupSubSourceOrgModOtherFeat (SeqFeatPtr sfp, Pointer userdata);
NLM_EXTERN void CleanupSubSourceOrgModOtherDesc (SeqDescrPtr sdp, Pointer userdata);

NLM_EXTERN void CleanUpPubdescAuthors (PubdescPtr pdp);
NLM_EXTERN void CleanUpPubdescBody (PubdescPtr pdp, Boolean stripSerial);

NLM_EXTERN void CleanStructuredComment (UserObjectPtr uop);

NLM_EXTERN void SortSeqEntryQualifiers (SeqEntryPtr sep);

NLM_EXTERN void CleanUpProteinTitles (SeqEntryPtr sep);

/* BasicSeqAnnotCleanup is for cleaning up contents of separate named Seq-annot objects */

NLM_EXTERN void BasicSeqAnnotCleanup (SeqAnnotPtr sap);

NLM_EXTERN void RemoveUnnecessaryGeneXrefs (SeqFeatPtr sfp, Pointer userdata);

/* CautiousSeqEntryCleanup is a gradual consolidation and replacement of functions in SeriousSeqEntryCleanup,
which does change the itemID structure, and is intended to be safe for a retrofit of the ID database */

NLM_EXTERN void CautiousSeqEntryCleanup (SeqEntryPtr sep, SeqEntryFunc taxfun, SeqEntryFunc taxmerge);

/* Convert a segmented or delta Bioseq to a raw Bioseq */

NLM_EXTERN void SegOrDeltaBioseqToRaw (BioseqPtr bsp);

NLM_EXTERN void ConvertSegSetsToDeltaSequences (SeqEntryPtr sep);

NLM_EXTERN Boolean IsDeltaSeqWithFarpointers (BioseqPtr bsp);

/* UserFieldSort is similar to ValNodeSort but for user fields within a user object */
NLM_EXTERN UserFieldPtr LIBCALL UserFieldSort (UserFieldPtr list, int (LIBCALLBACK *compar ) PROTO((VoidPtr, VoidPtr)));

/* general purpose text finite state machine */
/* based on Practical Algorithms for Programmers by Binstock and Rex */

struct TextFsa;
typedef struct TextFsa* TextFsaPtr;

NLM_EXTERN TextFsaPtr TextFsaNew (void);
NLM_EXTERN void TextFsaAdd (TextFsaPtr tbl, CharPtr word);
NLM_EXTERN Int4 TextFsaNext (TextFsaPtr tbl, Int4 currState, Char ch, ValNodePtr PNTR matches);
NLM_EXTERN TextFsaPtr TextFsaFree (TextFsaPtr tbl);
NLM_EXTERN Boolean TextFsaGetStats (TextFsaPtr tbl, Int4Ptr highStateP, Int4Ptr numWordsP, Int4Ptr longestWordP);

/* PCR_primer manipulation functions */

typedef struct pcrset {
  CharPtr  fwd_seq;
  CharPtr  rev_seq;
  CharPtr  fwd_name;
  CharPtr  rev_name;
  Int2     orig_order;
} PcrSet, PNTR PcrSetPtr;

NLM_EXTERN ValNodePtr ParsePCRSet (BioSourcePtr biop);
NLM_EXTERN ValNodePtr ParsePCRStrings (
  CharPtr fwd_primer_seq,
  CharPtr rev_primer_seq,
  CharPtr fwd_primer_name,
  CharPtr rev_primer_name
);
NLM_EXTERN SubSourcePtr WritePCRSet (ValNodePtr pset);
NLM_EXTERN ValNodePtr FreePCRSet (ValNodePtr pset);

NLM_EXTERN int LIBCALLBACK SortVnpByPCRSetSeq (VoidPtr ptr1, VoidPtr ptr2);
NLM_EXTERN int LIBCALLBACK SortVnpByPCRSetOrder (VoidPtr ptr1, VoidPtr ptr2);

NLM_EXTERN ValNodePtr UniqueVnpByPCRSetSeq (ValNodePtr pset);

NLM_EXTERN void ModernizePCRPrimers (
  BioSourcePtr biop
);

/*
   very simple explore functions - VisitOn only does one chain, VisitIn goes into set components,
   they now return a count of the number of nodes visited, and the callback can be NULL if the purpose
   is simply to count nodes
*/

typedef void (*VisitDescriptorsFunc) (SeqDescrPtr sdp, Pointer userdata);
NLM_EXTERN Int4 VisitDescriptorsOnBsp (BioseqPtr bsp, Pointer userdata, VisitDescriptorsFunc callback);
NLM_EXTERN Int4 VisitDescriptorsOnSet (BioseqSetPtr bssp, Pointer userdata, VisitDescriptorsFunc callback);
NLM_EXTERN Int4 VisitDescriptorsInSet (BioseqSetPtr bssp, Pointer userdata, VisitDescriptorsFunc callback);
NLM_EXTERN Int4 VisitDescriptorsOnSep (SeqEntryPtr sep, Pointer userdata, VisitDescriptorsFunc callback);
NLM_EXTERN Int4 VisitDescriptorsInSep (SeqEntryPtr sep, Pointer userdata, VisitDescriptorsFunc callback);

typedef void (*VisitFeaturesFunc) (SeqFeatPtr sfp, Pointer userdata);
NLM_EXTERN Int4 VisitFeaturesOnSap (SeqAnnotPtr sap, Pointer userdata, VisitFeaturesFunc callback);
NLM_EXTERN Int4 VisitFeaturesOnBsp (BioseqPtr bsp, Pointer userdata, VisitFeaturesFunc callback);
NLM_EXTERN Int4 VisitFeaturesOnSet (BioseqSetPtr bssp, Pointer userdata, VisitFeaturesFunc callback);
NLM_EXTERN Int4 VisitFeaturesInSet (BioseqSetPtr bssp, Pointer userdata, VisitFeaturesFunc callback);
NLM_EXTERN Int4 VisitFeaturesOnSep (SeqEntryPtr sep, Pointer userdata, VisitFeaturesFunc callback);
NLM_EXTERN Int4 VisitFeaturesInSep (SeqEntryPtr sep, Pointer userdata, VisitFeaturesFunc callback);

typedef void (*VisitAlignmentsFunc) (SeqAlignPtr sap, Pointer userdata);
NLM_EXTERN Int4 VisitAlignmentsOnSap (SeqAnnotPtr sap, Pointer userdata, VisitAlignmentsFunc callback);
NLM_EXTERN Int4 VisitAlignmentsOnBsp (BioseqPtr bsp, Pointer userdata, VisitAlignmentsFunc callback);
NLM_EXTERN Int4 VisitAlignmentsOnSet (BioseqSetPtr bssp, Pointer userdata, VisitAlignmentsFunc callback);
NLM_EXTERN Int4 VisitAlignmentsInSet (BioseqSetPtr bssp, Pointer userdata, VisitAlignmentsFunc callback);
NLM_EXTERN Int4 VisitAlignmentsOnSep (SeqEntryPtr sep, Pointer userdata, VisitAlignmentsFunc callback);
NLM_EXTERN Int4 VisitAlignmentsInSep (SeqEntryPtr sep, Pointer userdata, VisitAlignmentsFunc callback);

typedef void (*VisitGraphsFunc) (SeqGraphPtr sgp, Pointer userdata);
NLM_EXTERN Int4 VisitGraphsOnSap (SeqAnnotPtr sap, Pointer userdata, VisitGraphsFunc callback);
NLM_EXTERN Int4 VisitGraphsOnBsp (BioseqPtr bsp, Pointer userdata, VisitGraphsFunc callback);
NLM_EXTERN Int4 VisitGraphsOnSet (BioseqSetPtr bssp, Pointer userdata, VisitGraphsFunc callback);
NLM_EXTERN Int4 VisitGraphsInSet (BioseqSetPtr bssp, Pointer userdata, VisitGraphsFunc callback);
NLM_EXTERN Int4 VisitGraphsOnSep (SeqEntryPtr sep, Pointer userdata, VisitGraphsFunc callback);
NLM_EXTERN Int4 VisitGraphsInSep (SeqEntryPtr sep, Pointer userdata, VisitGraphsFunc callback);

typedef void (*VisitAnnotsFunc) (SeqAnnotPtr sap, Pointer userdata);
NLM_EXTERN Int4 VisitAnnotsOnBsp (BioseqPtr bsp, Pointer userdata, VisitAnnotsFunc callback);
NLM_EXTERN Int4 VisitAnnotsOnSet (BioseqSetPtr bssp, Pointer userdata, VisitAnnotsFunc callback);
NLM_EXTERN Int4 VisitAnnotsInSet (BioseqSetPtr bssp, Pointer userdata, VisitAnnotsFunc callback);
NLM_EXTERN Int4 VisitAnnotsOnSep (SeqEntryPtr sep, Pointer userdata, VisitAnnotsFunc callback);
NLM_EXTERN Int4 VisitAnnotsInSep (SeqEntryPtr sep, Pointer userdata, VisitAnnotsFunc callback);

typedef void (*VisitBioseqsFunc) (BioseqPtr bsp, Pointer userdata);
NLM_EXTERN Int4 VisitBioseqsInSet (BioseqSetPtr bssp, Pointer userdata, VisitBioseqsFunc callback);
NLM_EXTERN Int4 VisitBioseqsInSep (SeqEntryPtr sep, Pointer userdata, VisitBioseqsFunc callback);

/* VisitSequences allows you to limit visitation to nucs or prots that aren't parts, or just to parts */

#define VISIT_MAINS 1
#define VISIT_NUCS  2
#define VISIT_PROTS 3
#define VISIT_PARTS 4

typedef void (*VisitSequencesFunc) (BioseqPtr bsp, Pointer userdata);
NLM_EXTERN Int4 VisitSequencesInSet (BioseqSetPtr bssp, Pointer userdata, Int2 filter, VisitSequencesFunc callback);
NLM_EXTERN Int4 VisitSequencesInSep (SeqEntryPtr sep, Pointer userdata, Int2 filter, VisitSequencesFunc callback);

typedef void (*VisitSetsFunc) (BioseqSetPtr bssp, Pointer userdata);
NLM_EXTERN Int4 VisitSetsInSep (SeqEntryPtr sep, Pointer userdata, VisitSetsFunc callback);
NLM_EXTERN Int4 VisitSetsInSet (BioseqSetPtr bssp, Pointer userdata, VisitSetsFunc callback);

/* visits components of pop/phy/mut/genbank sets, callback is at most nuc-prot set, can then call above functions */

typedef void (*VisitElementsFunc) (SeqEntryPtr sep, Pointer userdata);
NLM_EXTERN Int4 VisitElementsInSep (SeqEntryPtr sep, Pointer userdata, VisitElementsFunc callback);

/* visits all SeqIds within a SeqLoc, or within features, alignments, graphs, or annots */

typedef void (*VisitSeqIdFunc) (SeqIdPtr sip, Pointer userdata);
NLM_EXTERN Int4 VisitSeqIdsInSeqLoc (SeqLocPtr slp, Pointer userdata, VisitSeqIdFunc callback);

NLM_EXTERN Int4 VisitSeqIdsInBioseq (BioseqPtr bsp, Pointer userdata, VisitSeqIdFunc callback);
NLM_EXTERN Int4 VisitSeqIdsInSeqFeat (SeqFeatPtr sfp, Pointer userdata, VisitSeqIdFunc callback);
NLM_EXTERN Int4 VisitSeqIdsInSeqAlign (SeqAlignPtr sap, Pointer userdata, VisitSeqIdFunc callback);
NLM_EXTERN Int4 VisitSeqIdsInSeqGraph (SeqGraphPtr sgp, Pointer userdata, VisitSeqIdFunc callback);
NLM_EXTERN Int4 VisitSeqIdsInSeqAnnot (SeqAnnotPtr annot, Pointer userdata, VisitSeqIdFunc callback);

/* visits all sub UserFields - if the data type is 11, VisitUserFieldsInUfp recurses */

typedef void (*VisitUserFieldsFunc) (UserFieldPtr ufp, Pointer userdata);
NLM_EXTERN Int4 VisitUserFieldsInUfp (UserFieldPtr ufp, Pointer userdata, VisitUserFieldsFunc callback);
NLM_EXTERN Int4 VisitUserFieldsInUop (UserObjectPtr uop, Pointer userdata, VisitUserFieldsFunc callback);

/* visits all sub UserObjects if the data type is 12 - needed to pack multiple user objects on a single feature.  Does not visit user objects which contain other user objects. */

typedef void (*VisitUserObjectFunc) (UserObjectPtr uop, Pointer userdata);
NLM_EXTERN Int4 VisitUserObjectsInUop (UserObjectPtr uop, Pointer userdata, VisitUserObjectFunc callback);
/* Visits all user objects, even if they contain other user objects */
NLM_EXTERN Int4 VisitAllUserObjectsInUop (UserObjectPtr uop, Pointer userdata, VisitUserObjectFunc callback);

/* explores sub UserObjects including "CombinedFeatureUserObjects" and finds by label  */

NLM_EXTERN UserObjectPtr FindUopByTag (UserObjectPtr top, CharPtr tag);

/* creates "CombinedFeatureUserObjects" sfp->ext to combine two user objects */

NLM_EXTERN UserObjectPtr CombineUserObjects (UserObjectPtr origuop, UserObjectPtr newuop);

/* visits all publication descriptors or features */

typedef void (*VisitPubdescsFunc) (PubdescPtr pdp, Pointer userdata);
NLM_EXTERN Int4 VisitPubdescsOnBsp (BioseqPtr bsp, Pointer userdata, VisitPubdescsFunc callback);
NLM_EXTERN Int4 VisitPubdescsOnSet (BioseqSetPtr bssp, Pointer userdata, VisitPubdescsFunc callback);
NLM_EXTERN Int4 VisitPubdescsInSet (BioseqSetPtr bssp, Pointer userdata, VisitPubdescsFunc callback);
NLM_EXTERN Int4 VisitPubdescsOnSep (SeqEntryPtr sep, Pointer userdata, VisitPubdescsFunc callback);
NLM_EXTERN Int4 VisitPubdescsInSep (SeqEntryPtr sep, Pointer userdata, VisitPubdescsFunc callback);

/* visits all authors in a publication */

typedef void (*VisitAuthorFunc) (NameStdPtr nsp, Pointer userdata);
NLM_EXTERN Int4 VisitAuthorsInPub (PubdescPtr pdp, Pointer userdata, VisitAuthorFunc callback);

/* visits all biosource descriptors or features */

typedef void (*VisitBioSourcesFunc) (BioSourcePtr biop, Pointer userdata);
NLM_EXTERN Int4 VisitBioSourcesOnBsp (BioseqPtr bsp, Pointer userdata, VisitBioSourcesFunc callback);
NLM_EXTERN Int4 VisitBioSourcesOnSet (BioseqSetPtr bssp, Pointer userdata, VisitBioSourcesFunc callback);
NLM_EXTERN Int4 VisitBioSourcesInSet (BioseqSetPtr bssp, Pointer userdata, VisitBioSourcesFunc callback);
NLM_EXTERN Int4 VisitBioSourcesOnSep (SeqEntryPtr sep, Pointer userdata, VisitBioSourcesFunc callback);
NLM_EXTERN Int4 VisitBioSourcesInSep (SeqEntryPtr sep, Pointer userdata, VisitBioSourcesFunc callback);

/* function to scan binary ASN.1 file of entire release as Bioseq-set, simple explore from successive top seps */
/* compressed can be TRUE only on UNIX, where it does a popen on zcat to decompress on-the-fly */
/* although it now returns a count of components visited, the callback cannot be NULL for this function */

typedef void (*ScanBioseqSetFunc) (SeqEntryPtr sep, Pointer userdata);
NLM_EXTERN Int4 ScanBioseqSetRelease (
  CharPtr inputFile,
  Boolean binary,
  Boolean compressed,
  Pointer userdata,
  ScanBioseqSetFunc callback
);

/* multi-thread safe version does not free SeqEntryPtr after calling callback, use FreeScanSeqEntryMT */
NLM_EXTERN Int4 ScanBioseqSetReleaseMT (
  CharPtr inputFile,
  Boolean binary,
  Boolean compressed,
  Pointer userdata,
  ScanBioseqSetFunc callback
);
NLM_EXTERN SeqEntryPtr LIBCALL FreeScanSeqEntryMT (
  SeqEntryPtr sep
);

/* More automatic version of ReadAsnFastaOrFlatFile, can read BioseqSet release file */

NLM_EXTERN Int4 ReadSequenceAsnFile (
  CharPtr inputFile,
  Boolean binary,
  Boolean compressed,
  Pointer userdata,
  ScanBioseqSetFunc callback
);

/* function to scan binary ASN.1 file of entrezgene release as Entrezgene-Set */

typedef void (*ScanEntrezgeneSetFunc) (EntrezgenePtr egp, Pointer userdata);
NLM_EXTERN Int4 ScanEntrezgeneSetRelease (
  CharPtr inputFile,
  Boolean binary,
  Boolean compressed,
  Pointer userdata,
  ScanEntrezgeneSetFunc callback
);

/* PubMed registered fetch functionality */

NLM_EXTERN PubmedEntryPtr LIBCALL GetPubMedForUid (Int4 uid);

/* internal support type, registration function */

typedef PubmedEntryPtr (LIBCALLBACK * PubMedFetchFunc) (Int4 uid);

NLM_EXTERN void LIBCALL PubMedSetFetchFunc (PubMedFetchFunc func);

NLM_EXTERN void FirstNameToInitials (CharPtr first, CharPtr inits, size_t maxsize);

extern CharPtr MyFGetLine (FILE *fp, ValNodePtr PNTR current_data);

#if defined (WIN32)
extern char * __stdcall AbstractReadFunction (Pointer userdata);
extern void __stdcall AbstractReportError (TErrorInfoPtr err_ptr, Pointer userdata);
#else
extern char * AbstractReadFunction (Pointer userdata);
extern void AbstractReportError (TErrorInfoPtr err_ptr, Pointer userdata);
#endif

typedef struct readbuffer {
  FILE *fp;
  ValNodePtr current_data;
} ReadBufferData, PNTR ReadBufferPtr;

extern void FreeBufferedReadList (ValNodePtr vnp);

extern CharPtr AlignmentStringToSequenceString (CharPtr aln_str, Uint1 moltype);
extern SeqEntryPtr MakeSequinDataFromAlignment (TAlignmentFilePtr afp, Uint1 moltype);
extern SeqEntryPtr MakeSequinDataFromAlignmentEx (TAlignmentFilePtr afp, Uint1 moltype, Boolean check_ids);
extern SeqEntryPtr make_seqentry_for_seqentry (SeqEntryPtr sep);
extern Boolean ConvertOnePseudoCDSToMiscFeat (SeqFeatPtr sfp);
NLM_EXTERN Boolean ConvertOnePseudoCDSToMiscFeatEx (SeqFeatPtr sfp, Boolean remove_product);
extern void ConvertPseudoCDSToMiscFeatsForEntityID (Uint2 entityID);

extern SeqAlignPtr FindAlignmentsForBioseq (BioseqPtr bsp);
extern ValNodePtr FindAlignSeqAnnotsForBioseq (BioseqPtr bsp);
extern Boolean IsSequenceFirstInPairwise (SeqEntryPtr sep, SeqIdPtr sip);
extern SeqAlignPtr RemoveOneSequenceFromAlignment (SeqIdPtr sip, SeqAlignPtr salphead);
extern Boolean RemoveSequenceFromAlignments (SeqEntryPtr sep, SeqIdPtr sip);
extern BioseqPtr ReadFastaOnly (FILE *fp,
                              Boolean forceNuc, Boolean forceProt,
                              BoolPtr chars_stripped,
                              CharPtr lastchar);
extern void MergeFeatureIntervalsToParts (SeqFeatPtr sfp, Boolean ordered);

extern void ExtendSingleGeneOnMRNA (BioseqPtr bsp, Pointer userdata);

typedef struct loginfo 
{
  FILE *fp;
  Boolean data_in_log;
  CharPtr display_title;
  Char path[PATH_MAX];  
} LogInfoData, PNTR LogInfoPtr;

extern LogInfoPtr OpenLog (CharPtr display_title);
extern LogInfoPtr FreeLog (LogInfoPtr lip);

NLM_EXTERN void FixNonWGSSets (ValNodePtr item_list, Pointer data, LogInfoPtr lip);

/* structures and functions for the Discrepancy Report */
typedef void (*ClickableCallback) (ValNodePtr item_list, Pointer userdata);
typedef void (*ClickableCallbackDataFree) (Pointer userdata);
typedef void (*AutofixCallback) (ValNodePtr item_list, Pointer userdata, LogInfoPtr lip);

typedef struct clickableitem 
{
  Uint4                     clickable_item_type;
  CharPtr                   description;
  ValNodePtr                item_list;
  ClickableCallback         callback_func; 
  ClickableCallbackDataFree datafree_func; 
  Pointer                   callback_data;
  Boolean                   chosen;
  ValNodePtr                subcategories;
  Boolean                   expanded;
  Int4                      level;
  AutofixCallback           autofix_func;  /* note - autofix functions can be set for an 
                                            * entire category or for an individual clickable
                                            * item.  Don't set autofix functions in both
                                            * places or they will both be called.
                                            */
  Pointer                   autofix_data;  /* data for item-specific autofixes */
} ClickableItemData, PNTR ClickableItemPtr;

extern ClickableItemPtr 
NewClickableItem 
(Uint4           clickable_item_type,
 CharPtr         description_fmt,
 ValNodePtr      item_list);

extern ClickableItemPtr 
NewClickableItemNoList 
(Uint4           clickable_item_type,
 CharPtr         description);

extern ValNodePtr ClickableItemObjectListFree (ValNodePtr vnp);
extern ValNodePtr ClickableItemObjectListCopy (ValNodePtr orig);
extern ClickableItemPtr ClickableItemFree (ClickableItemPtr cip);
extern ValNodePtr FreeClickableList (ValNodePtr list);
extern Boolean AnyDiscrepanciesChosen (ValNodePtr cip_list);
NLM_EXTERN void ChooseAllDiscrepancies (ValNodePtr cip_list);

extern int LIBCALLBACK SortVnpByClickableItemDescription (VoidPtr ptr1, VoidPtr ptr2);
NLM_EXTERN int LIBCALLBACK SortVnpByClickableItemChosen (VoidPtr ptr1, VoidPtr ptr2);

extern void ExpandClickableItemList (ValNodePtr vnp);
extern void ContractClickableItemList (ValNodePtr vnp);

NLM_EXTERN void RemoveDuplicateItems (ValNodePtr PNTR item_list);

/* To add a new type of test, do ALL Of the following:
 * 1. add an item to the DiscrepancyType enum (this will fill the clickable_item_type value)
 * 2. add a collection function and declare it with the others
 * 3. add an item to discrepancy_info_list that corresponds with the position of the
 *    new enum value.  If you are combining multiple types in one collection function,
 *    be sure to list them together.
 */

/* SHOW_TRANSL_EXCEPT added by J. Chen */
/* SHOW_HYPOTHETICAL_CDS_HAVING_GENE_NAME added, J. Chen */
/* TEST_DEFLINE_EXIST added, J. Chen */
typedef enum {
  DISC_GENE_MISSING = 0,
  DISC_SUPERFLUOUS_GENE,
  DISC_GENE_MISSING_LOCUS_TAG,
  DISC_GENE_DUPLICATE_LOCUS_TAG,
  DISC_GENE_LOCUS_TAG_BAD_FORMAT,
  DISC_GENE_LOCUS_TAG_INCONSISTENT_PREFIX,
  DISC_NON_GENE_LOCUS_TAG,
  DISC_COUNT_NUCLEOTIDES,
  DISC_MISSING_PROTEIN_ID,
  DISC_INCONSISTENT_PROTEIN_ID_PREFIX,
  DISC_GENE_CDS_mRNA_LOCATION_CONFLICT,
  DISC_GENE_PRODUCT_CONFLICT,
  DISC_GENE_DUPLICATE_LOCUS,
  DISC_EC_NUMBER_NOTE,
  DISC_PSEUDO_MISMATCH,
  DISC_JOINED_FEATURES,
  DISC_OVERLAPPING_GENES,
  DISC_OVERLAPPING_CDS,
  DISC_CONTAINED_CDS,
  DISC_RNA_CDS_OVERLAP,
  DISC_SHORT_CONTIG,
  DISC_INCONSISTENT_BIOSRC,
  DISC_SUSPECT_PRODUCT_NAME,
  DISC_PRODUCT_NAME_TYPO,
  DISC_PRODUCT_NAME_QUICKFIX,
  DISC_INCONSISTENT_BIOSRC_DEFLINE,
  DISC_PARTIAL_CDS_IN_COMPLETE_SEQUENCE,
  DISC_EC_NUMBER_ON_HYPOTHETICAL_PROTEIN,
  DISC_NO_TAXLOOKUP,
  DISC_BAD_TAXLOOKUP,
  DISC_SHORT_SEQUENCE,
  DISC_SUSPECT_PHRASES,
  DISC_SUSPICIOUS_NOTE_TEXT,
  DISC_COUNT_TRNA,
  DISC_DUP_TRNA,
  DISC_BADLEN_TRNA,
  DISC_STRAND_TRNA,
  DISC_COUNT_RRNA,
  DISC_DUP_RRNA,
  DISC_RNA_NO_PRODUCT,
  DISC_TRANSL_NO_NOTE,
  DISC_NOTE_NO_TRANSL,
  DISC_TRANSL_TOO_LONG,
  DISC_CDS_OVERLAP_TRNA,
  DISC_COUNT_PROTEINS,
  DISC_FEAT_OVERLAP_SRCFEAT,
  DISC_MISSING_GENPRODSET_PROTEIN,
  DISC_DUP_GENPRODSET_PROTEIN,
  DISC_MISSING_GENPRODSET_TRANSCRIPT_ID,
  DISC_DUP_GENPRODSET_TRANSCRIPT_ID,
  DISC_PERCENTN,
  DISC_N_RUNS,
  DISC_ZERO_BASECOUNT,
  DISC_ADJACENT_PSEUDOGENE,
  DISC_LONG_NO_ANNOTATION,
  DISC_NO_ANNOTATION,
  DISC_INFLUENZA_DATE_MISMATCH,
  DISC_SHORT_INTRON,
  DISC_MISSING_VIRAL_QUALS,
  DISC_SRC_QUAL_PROBLEM,
  DISC_MISSING_SRC_QUAL,
  DISC_DUP_SRC_QUAL,
  DISC_DUP_SRC_QUAL_DATA,
  DISC_HAPLOTYPE_MISMATCH,
  DISC_FEATURE_MOLTYPE_MISMATCH,
  DISC_CDS_WITHOUT_MRNA,
  DISC_EXON_INTRON_CONFLICT,
  DISC_FEATURE_COUNT,
  DISC_SPECVOUCHER_TAXNAME_MISMATCH,
  DISC_GENE_PARTIAL_CONFLICT,
  DISC_FLATFILE_FIND_ONCALLER,
  DISC_FLATFILE_FIND_ONCALLER_FIXABLE,
  DISC_FLATFILE_FIND_ONCALLER_UNFIXABLE,
  DISC_CDS_PRODUCT_FIND,
  DISC_DUP_DEFLINE,
  DUP_DISC_ATCC_CULTURE_CONFLICT,
  DISC_USA_STATE,
  DISC_INCONSISTENT_MOLTYPES,
  DISC_SUBMITBLOCK_CONFLICT,
  DISC_POSSIBLE_LINKER,
  DISC_TITLE_AUTHOR_CONFLICT,
  DISC_BAD_GENE_STRAND,
  DISC_MAP_CHROMOSOME_CONFLICT,
  DISC_RBS_WITHOUT_GENE,
  DISC_CITSUBAFFIL_CONFLICT,
  DISC_REQUIRED_CLONE,
  DISC_SOURCE_QUALS_ASNDISC,
  DISC_mRNA_ON_WRONG_SEQUENCE_TYPE,
  DISC_RETROVIRIDAE_DNA,
  DISC_CHECK_AUTH_CAPS,
  DISC_CHECK_RNA_PRODUCTS_AND_COMMENTS,
  DISC_MICROSATELLITE_REPEAT_TYPE,
  DISC_MITOCHONDRION_REQUIRED,
  DISC_UNPUB_PUB_WITHOUT_TITLE,
  DISC_QUALITY_SCORES,
  DISC_INTERNAL_TRANSCRIBED_SPACER_RRNA,
  DISC_PARTIAL_PROBLEMS,
  DISC_BACTERIAL_PARTIAL_NONEXTENDABLE_PROBLEMS,
  DISC_BACTERIAL_PARTIAL_NONEXTENDABLE_EXCEPTION,
  DISC_SUSPECT_RRNA_PRODUCTS,
  DISC_SUSPECT_MISC_FEATURES,
  DISC_BACTERIA_MISSING_STRAIN,
  DISC_MISSING_DEFLINES,
  DISC_MISSING_AFFIL,
  DISC_BACTERIA_SHOULD_NOT_HAVE_ISOLATE,
  DISC_BACTERIA_SHOULD_NOT_HAVE_MRNA,
  DISC_CDS_HAS_NEW_EXCEPTION,
  DISC_TRINOMIAL_SHOULD_HAVE_QUALIFIER,
  DISC_METAGENOMIC,
  DISC_METAGENOME_SOURCE,
  ONCALLER_GENE_MISSING,
  ONCALLER_SUPERFLUOUS_GENE,
  DISC_SHORT_RRNA,
  ONCALLER_CHECK_AUTHORITY,
  ONCALLER_CONSORTIUM,
  ONCALLER_STRAIN_CULTURE_COLLECTION_MISMATCH,
  ONCALLER_MULTISRC,
  ONCALLER_MULTIPLE_CULTURE_COLLECTION,
  DISC_SEGSETS_PRESENT,
  DISC_NONWGS_SETS_PRESENT,
  DISC_FEATURE_LIST,
  DISC_CATEGORY_HEADER,
  DISC_MISMATCHED_COMMENTS,
  DISC_STRAIN_TAXNAME_MISMATCH,
  DISC_HUMAN_HOST,
  DISC_BAD_BACTERIAL_GENE_NAME,
  TEST_BAD_GENE_NAME,
  ONCALLER_ORDERED_LOCATION,
  ONCALLER_COMMENT_PRESENT,
  ONCALLER_DEFLINE_ON_SET,
  ONCALLER_HIV_RNA_INCONSISTENT,
  SHORT_PROT_SEQUENCES,
  TEST_EXON_ON_MRNA,
  TEST_HAS_PROJECT_ID,
  ONCALLER_HAS_STANDARD_NAME,
  ONCALLER_MISSING_STRUCTURED_COMMENTS,
  DISC_REQUIRED_STRAIN,
  MISSING_GENOMEASSEMBLY_COMMENTS,
  DISC_BACTERIAL_TAX_STRAIN_MISMATCH,
  TEST_CDS_HAS_CDD_XREF,
  TEST_UNUSUAL_NT,
  TEST_LOW_QUALITY_REGION,
  TEST_ORGANELLE_NOT_GENOMIC,
  TEST_UNWANTED_SPACER,
  TEST_ORGANELLE_PRODUCTS,
  TEST_SP_NOT_UNCULTURED,
  TEST_BAD_MRNA_QUAL,
  TEST_UNNECESSARY_ENVIRONMENTAL,
  TEST_UNNECESSARY_VIRUS_GENE,
  TEST_UNWANTED_SET_WRAPPER,
  TEST_MISSING_PRIMER,
  TEST_UNUSUAL_MISC_RNA,
  TEST_AMPLIFIED_PRIMERS_NO_ENVIRONMENTAL_SAMPLE,
  TEST_DUP_GENES_OPPOSITE_STRANDS,
  TEST_SMALL_GENOME_SET_PROBLEM,
  TEST_OVERLAPPING_RRNAS,
  TEST_MRNA_SEQUENCE_MINUS_STRAND_FEATURES,
  TEST_TAXNAME_NOT_IN_DEFLINE,
  TEST_COUNT_UNVERIFIED,
  SHOW_TRANSL_EXCEPT,
  SHOW_HYPOTHETICAL_CDS_HAVING_GENE_NAME,
  TEST_DEFLINE_PRESENT,
  TEST_MRNA_OVERLAPPING_PSEUDO_GENE,
  FIND_OVERLAPPED_GENES,
  DISC_BIOMATERIAL_TAXNAME_MISMATCH,
  DISC_CULTURE_TAXNAME_MISMATCH,
  DISC_CHECK_AUTH_NAME,
  NON_RETROVIRIDAE_PROVIRAL,
  RNA_PROVIRAL,
  SHORT_SEQUENCES_200,
  DISC_10_PERCENTN,
  N_RUNS_14,
  MOLTYPE_NOT_MRNA,
  TECHNIQUE_NOT_TSA,
  MISSING_STRUCTURED_COMMENT,
  MISSING_PROJECT,
  MULTIPLE_CDS_ON_MRNA,
  DUP_DISC_CBS_CULTURE_CONFLICT,
  DIVISION_CODE_CONFLICTS,
  RRNA_NAME_CONFLICTS,
  EUKARYOTE_SHOULD_HAVE_MRNA,
  MRNA_SHOULD_HAVE_PROTEIN_TRANSCRIPT_IDS,
  ONCALLER_COUNTRY_COLON,
  ONCALLER_BIOPROJECT_ID,
  ONCALLER_STRAIN_TAXNAME_CONFLICT,
  ONCALLER_MORE_NAMES_COLLECTED_BY,
  ONCALLER_MORE_OR_SPEC_NAMES_IDENTIFIED_BY,
  ONCALLER_SUSPECTED_ORG_IDENTIFIED,
  ONCALLER_SUSPECTED_ORG_COLLECTED,
  ONCALLER_SWITCH_STRUCTURED_COMMENT_PREFIX,
  ONCALLER_CITSUB_AFFIL_DUP_TEXT,
  ONCALLER_DUPLICATE_PRIMER_SET,
  END_COLON_IN_COUNTRY,
  DISC_PROTEIN_NAMES,
  DISC_TITLE_ENDS_WITH_SEQUENCE,
  DISC_INCONSISTENT_STRUCTURED_COMMENTS,
  DISC_INCONSISTENT_DBLINK,
  DISC_INCONSISTENT_MOLINFO_TECH,
  DISC_GAPS,
  DISC_BAD_BGPIPE_QUALS,
  TEST_SHORT_LNCRNA,
  TEST_TERMINAL_NS,
  TEST_ALIGNMENT_HAS_SCORE,
  UNCULTURED_NOTES_ONCALLER,
  SEQ_ID_PHRASES,
  NO_PRODUCT_STRING,
  MAX_DISC_TYPE
} DiscrepancyType;

typedef enum {
  eReportTypeDiscrepancy = 1,
  eReportTypeOnCaller,
  eReportTypeMegaReport,
  eReportTypeTSA,
  eReportType_End
} EDiscrepancyReportType;

extern Boolean IsTestTypeAppropriateForReportType (Int4 test_type, EDiscrepancyReportType report_type);

extern void PrintDiscrepancyTestList (FILE *fp);

extern void SetDiscrepancyLevels (ValNodePtr discrepancy_list, Int4 level);

extern CharPtr GetDiscrepancyTestConfName (DiscrepancyType dtype);
extern CharPtr GetDiscrepancyTestSettingName (DiscrepancyType dtype);
extern DiscrepancyType GetDiscrepancyTypeFromSettingName (CharPtr setting_name);
extern Boolean DiscrepancyTestHasAutofix (DiscrepancyType dtype);

typedef struct discrepancyconfig
{
  Boolean conf_list[MAX_DISC_TYPE];
  Boolean use_feature_table_format;
  Boolean use_big_test_set;
  Boolean is_big_sequence;
} DiscrepancyConfigData, PNTR DiscrepancyConfigPtr;

extern DiscrepancyConfigPtr DiscrepancyConfigFree (DiscrepancyConfigPtr dcp);
extern DiscrepancyConfigPtr DiscrepancyConfigNew (void);
extern DiscrepancyConfigPtr DiscrepancyConfigCopy (DiscrepancyConfigPtr dcp);
extern DiscrepancyConfigPtr ReadDiscrepancyConfig (void);
extern DiscrepancyConfigPtr ReadDiscrepancyConfigEx (CharPtr report_config_name);
extern void SaveDiscrepancyConfig (DiscrepancyConfigPtr dcp);
extern void SaveDiscrepancyConfigEx (DiscrepancyConfigPtr dcp, CharPtr report_name);
extern void DisableTRNATests (DiscrepancyConfigPtr dcp);
extern CharPtr SetDiscrepancyReportTestsFromString (CharPtr list, Boolean enable, DiscrepancyConfigPtr dcp);
extern void ConfigureForBigSequence (DiscrepancyConfigPtr dcp);
extern void ConfigureForGenomes (DiscrepancyConfigPtr dcp);
extern void ConfigureForReportType (DiscrepancyConfigPtr dcp, EDiscrepancyReportType report_type);

typedef void (*PerformDiscrepancyTest) PROTO ((ValNodePtr PNTR, ValNodePtr));

extern ValNodePtr CollectDiscrepancies (DiscrepancyConfigPtr dcp, ValNodePtr sep_list, PerformDiscrepancyTest taxlookup);
extern void AutofixDiscrepancies (ValNodePtr vnp, Boolean fix_all, LogInfoPtr lip);
extern void ChooseFixableDiscrepancies (ValNodePtr vnp);
extern CharPtr GetDiscrepancyItemText (ValNodePtr vnp);
extern CharPtr GetDiscrepancyItemTextEx (ValNodePtr vnp, CharPtr filename);
extern void VisitGenProdSetFeatures (SeqEntryPtr sep, Pointer userdata, VisitFeaturesFunc callback);
extern ValNodePtr ReplaceDiscrepancyItemWithFeatureTableStrings (ValNodePtr feat_list);
extern CharPtr GetParentLabelForDiscrepancyItem (ValNodePtr vnp);
extern void WriteDiscrepancy (FILE *fp, ClickableItemPtr dip, Boolean use_feature_table_fmt);
extern void WriteDiscrepancyEx (FILE *fp, ClickableItemPtr dip, Boolean use_feature_table_fmt, Boolean cmd_line, CharPtr descr_prefix, Boolean list_features_if_subcat);
extern int LIBCALLBACK SortVnpByDiscrepancyDescription (VoidPtr ptr1, VoidPtr ptr2);
extern int LIBCALLBACK SortVnpByDiscrepancyItemText (VoidPtr ptr1, VoidPtr ptr2);
extern void ValNodeReverse (ValNodePtr PNTR list);

/* Individual discrepancy test function declarations */
extern const CharPtr kOverlappingCDSNoteText;
extern const CharPtr kOverlappingCDSNeedsNoteFmt;
extern void AddOverlappingCodingRegionDiscrepancies (ValNodePtr PNTR discrepancy_list, ValNodePtr sep_list);
extern void AddDiscrepanciesForMissingOrNonUniqueGeneLocusTagsEx (ValNodePtr PNTR discrepancy_list, ValNodePtr sep_list, Boolean exclude_dirsub);
extern void AddDiscrepanciesForMissingOrNonUniqueGeneLocusTags (ValNodePtr PNTR discrepancy_list, ValNodePtr sep_list);
extern void FindShortIntronsEx (ValNodePtr PNTR discrepancy_list, ValNodePtr sep_list, Boolean check_organelles);
extern void FindShortIntrons (ValNodePtr PNTR discrepancy_list, ValNodePtr sep_list);
extern void CheckBioSourceQuals (ValNodePtr PNTR discrepancy_list, ValNodePtr sep_list);
extern void FindExtendablePartials (ValNodePtr PNTR discrepancy_list, ValNodePtr sep_list);
extern void FindBacterialNonExtendablePartials (ValNodePtr PNTR discrepancy_list, ValNodePtr sep_list);
NLM_EXTERN void FindMismatchedComments (ValNodePtr PNTR discrepancy_list, ValNodePtr sep_list);

/* autofix functions */
NLM_EXTERN void MarkOverlappingCDSs (ValNodePtr item_list, Pointer data, LogInfoPtr lip);
NLM_EXTERN void FixBacterialNonExtendablePartials (ValNodePtr item_list, Pointer data, LogInfoPtr lip);
NLM_EXTERN void FixExtendablePartials (ValNodePtr item_list, Pointer data, LogInfoPtr lip);
NLM_EXTERN void FixMismatchedComments (ValNodePtr item_list, Pointer data, LogInfoPtr lip);
NLM_EXTERN void FixHumanHosts (ValNodePtr item_list, Pointer data, LogInfoPtr lip);
NLM_EXTERN void FixOrderedLocations (ValNodePtr item_list, Pointer data, LogInfoPtr lip);
NLM_EXTERN void OncallerToolPseudoDiscrepanciesFix (ValNodePtr item_list, Pointer data, LogInfoPtr lip);
NLM_EXTERN void OncallerToolFindEcoNoEnvFix (ValNodePtr item_list, Pointer data, LogInfoPtr lip);
NLM_EXTERN void AddExceptionsToShortIntrons (ValNodePtr item_list, Pointer data, LogInfoPtr lip);

NLM_EXTERN Boolean IsShortrRNA (SeqFeatPtr sfp);

/* structure shared by tbl2asn and discrepancy report functions */
typedef struct genprodsetdiscrepancylists {
  ValNodePtr cds_product_list;
  ValNodePtr mrna_product_list;
  ValNodePtr missing_mrna_product;
  ValNodePtr missing_protein_id;
} GenProdSetDiscrepancyListsData, PNTR GenProdSetDiscrepancyListsPtr;

extern void CheckGenProdSetsInSeqEntry (SeqEntryPtr sep, GenProdSetDiscrepancyListsPtr lists);  


typedef struct protidlists {
  ValNodePtr missing_gnl_list;
  ValNodePtr gnl_list;
} ProtIdListsData, PNTR ProtIdListsPtr;

/* structure shared by tbl2asn and discrepancy report functions */
typedef struct globaldiscrepancy {
  CharPtr str;
  Uint1   data_choice;
  Pointer data;
} GlobalDiscrepancyData, PNTR GlobalDiscrepancyPtr;

extern GlobalDiscrepancyPtr GlobalDiscrepancyNew (CharPtr str, Uint1 data_choice, Pointer data);
extern GlobalDiscrepancyPtr GlobalDiscrepancyFree (GlobalDiscrepancyPtr g);
extern ValNodePtr FreeGlobalDiscrepancyList (ValNodePtr vnp);
extern void ConvertGlobalDiscrepancyToText (GlobalDiscrepancyPtr g, Boolean use_feature_fmt, CharPtr filename);
extern void ConvertGlobalDiscrepancyListToText (ValNodePtr vnp, Boolean use_feature_fmt, CharPtr filename);
extern ValNodePtr GetGlobalDiscrepancyItem (GlobalDiscrepancyPtr g);
extern CharPtr GetGlobalDiscrepancyStr (GlobalDiscrepancyPtr g);
NLM_EXTERN int LIBCALLBACK SortVnpByGlobalDiscrepancyString (VoidPtr ptr1, VoidPtr ptr2);
NLM_EXTERN int LIBCALLBACK SortVnpByGlobalDiscrepancyStringCaseSensitive (VoidPtr ptr1, VoidPtr ptr2);
extern ClickableItemPtr
ReportNonUniqueGlobalDiscrepancy 
(ValNodePtr vnp, 
 CharPtr    label_fmt,
 CharPtr    ind_cat_fmt,
 Uint4      clickable_item_type,
 Boolean    keep_top_category);
extern ValNodePtr ReportInconsistentGlobalDiscrepancyPrefixes
(ValNodePtr vnp, 
 CharPtr    label_fmt,
 Uint4      clickable_item_type);
extern ValNodePtr ReportInconsistentGlobalDiscrepancyStrings
(ValNodePtr vnp, 
 CharPtr    label_fmt,
 Uint4      clickable_item_type);
extern ClickableItemPtr ReportMissingFields (ValNodePtr list, CharPtr label_fmt, Uint4 clickable_item_type);
extern ClickableItemPtr ReportBadLocusTagFormat (ValNodePtr list);
extern ClickableItemPtr FindAdjacentDuplicateLocusTagGenes (ValNodePtr locus_tag_list);
extern void FindProteinIDCallback (BioseqPtr bsp, Pointer userdata);


/* formats for global discrepancies also used by tbl2asn */
extern CharPtr discReportDuplicateLocusTagFmt;
extern CharPtr discReportOneDuplicateLocusTagFmt;
extern CharPtr discReportDuplicateProteinIDFmt;
extern CharPtr discReportOneDuplicateProteinIDFmt;
extern CharPtr discReportDuplicateTranscriptIdFmt;
extern CharPtr discReportOneDuplicateTranscriptIdFmt;
extern CharPtr discReportInconsistentLocusTagPrefixFmt;
extern CharPtr discReportMissingLocusTags;
extern CharPtr discReportInconsistentProteinIDPrefixFmt;
extern CharPtr discReportBadProteinIdFmt;
extern CharPtr discReportMissingTranscriptIDFmt;

extern CharPtr GetBioseqLabel (BioseqPtr bsp);
extern CharPtr GetBioseqSetLabel (BioseqSetPtr bssp);

NLM_EXTERN ValNodePtr ValNodeDupStringList (ValNodePtr vnp);
NLM_EXTERN ValNodePtr ValNodeDupIntList (ValNodePtr vnp);

typedef enum {
  eLocusTagErrorBadFormat,
  eLocusTagErrorDuplicate,
  eLocusTagErrorInconsistentPrefix
} ELocusTagError;

NLM_EXTERN ValNodePtr FindBadLocusTagsInList (ValNodePtr list);


typedef struct discreportoutputconfig {
  Boolean use_feature_table_format;
  Boolean expand_report_categories[MAX_DISC_TYPE];
  Boolean summary_report;
  Boolean add_output_tag;
  Boolean add_extra_output_tag;
  Int4 num_nucs;
} DiscReportOutputConfigData, PNTR DiscReportOutputConfigPtr;

NLM_EXTERN void AddToOutputConfig(SeqEntryPtr sep, DiscReportOutputConfigPtr c);
NLM_EXTERN void AddListToOutputConfig(ValNodePtr list, DiscReportOutputConfigPtr c);

typedef struct globaldiscrepreport {
  ValNodeBlock  locus_tag_list;
  ValNodeBlock  missing_locus_tag;
  ValNodeBlock  cds_product_list;
  ValNodeBlock  missing_cds_product;
  ValNodeBlock  mrna_product_list;
  ValNodeBlock  missing_mrna_product;
  ValNodePtr  adjacent_locus_tag_disc_list;
  ValNodeBlock  missing_gnl_list;
  ValNodeBlock  gnl_list;
  ValNodePtr  global_src_qual_vals;
  ValNodePtr  global_srcs;
  ValNodeBlock  global_prot_name_list;

  ValNodePtr  src_qual_repeated_list;
  ValNodePtr  src_qual_multi_list;
  ValNodeBlock  feature_count_list;
  ValNodeBlock  discrepancy_list;

  PerformDiscrepancyTest    taxlookup;
  DiscrepancyConfigPtr      test_config;
  DiscReportOutputConfigPtr output_config;
} GlobalDiscrepReportData, PNTR GlobalDiscrepReportPtr;

NLM_EXTERN GlobalDiscrepReportPtr GlobalDiscrepReportNew ();
NLM_EXTERN GlobalDiscrepReportPtr GlobalDiscrepReportFree (GlobalDiscrepReportPtr g);
NLM_EXTERN void AddSeqEntryToGlobalDiscrepReport (SeqEntryPtr sep, GlobalDiscrepReportPtr g, CharPtr filename);
NLM_EXTERN Boolean WriteGlobalDiscrepancyReportEx (GlobalDiscrepReportPtr g, FILE *fp, CharPtr extra_comment);
NLM_EXTERN void WriteGlobalDiscrepancyReport (GlobalDiscrepReportPtr g, FILE *fp);

NLM_EXTERN Boolean CollectionDateIsInTheFuture (CharPtr name);
NLM_EXTERN Boolean CollectionDateIsValid (CharPtr name);
NLM_EXTERN Boolean CollectionDatesInOrder (CharPtr name);

/* for the Barcode Discrepancy Test */
typedef enum {
  eBarcodeTest_Length = 0,
  eBarcodeTest_Primers,
  eBarcodeTest_Country,
  eBarcodeTest_SpecimenVoucher,
  eBarcodeTest_PercentN,
  eBarcodeTest_CollectionDate,
  eBarcodeTest_OrderAssignment,
  eBarcodeTest_LowTrace,
  eBarcodeTest_FrameShift,
  eBarcodeTest_StructuredSpecimenVoucher,
  eBarcodeTest_LAST
} EBarcodeTest;

typedef struct barcodetestconfig
{
  Boolean conf_list[eBarcodeTest_LAST];
  Int4    min_length;
  FloatLo min_n_percent;
  Boolean require_keyword;
} BarcodeTestConfigData, PNTR BarcodeTestConfigPtr;

extern BarcodeTestConfigPtr BarcodeTestConfigNew();
extern BarcodeTestConfigPtr BarcodeTestConfigFree (BarcodeTestConfigPtr cfg);

extern CharPtr GetBarcodeTestName (Int4 i);

extern Int4 GetBarcodeTestNumFromBarcodeTestName (CharPtr test_name);

typedef struct barcodetestresults
{
  Boolean failed_tests[eBarcodeTest_LAST];
  BioseqPtr bsp;
  FloatLo   n_percent;
  Int4      num_trace;
} BarcodeTestResultsData, PNTR BarcodeTestResultsPtr;

extern BarcodeTestResultsPtr BarcodeTestResultsNew ();
extern BarcodeTestResultsPtr BarcodeTestResultsFree (BarcodeTestResultsPtr res);
extern BarcodeTestResultsPtr BarcodeTestResultsCopy (BarcodeTestResultsPtr res);
extern ValNodePtr            BarcodeTestResultsListFree (ValNodePtr res_list);
extern ValNodePtr            BarcodeTestResultsExtractPass (ValNodePtr PNTR res_list);

extern Boolean IsBarcodeID (SeqIdPtr sip);

extern CharPtr BarcodeTestBarcodeIdString (BioseqPtr bsp);
extern CharPtr BarcodeTestGenbankIdString (BioseqPtr bsp);

/* This one gets discrepancies by category */
extern ValNodePtr GetBarcodeDiscrepancies (ValNodePtr sep_list, BarcodeTestConfigPtr cfg);
extern ValNodePtr GetBarcodePassFail (SeqEntryPtr sep, BarcodeTestConfigPtr cfg);
NLM_EXTERN CharPtr GetBarcodeTestFailureReasons (BarcodeTestResultsPtr res);
/* This one lists passes and failures, with reasons for failures */
extern void WriteBarcodeTestComprehensive (FILE *fp, ValNodePtr results_list);
extern void WriteBarcodeDiscrepancies (FILE *fp, ValNodePtr results_list);
extern void WriteBarcodeFailureReport (FILE *fp, ValNodePtr results_list);
extern void WriteBarcodeTestCompliance (FILE *fp, ValNodePtr results_list);
extern void WriteBarcodeTestComplianceEx (FILE *fp, ValNodePtr results_list, Boolean low_trace_fail);
extern void WriteBarcodeTagTable (FILE *fp, ValNodePtr results_list);
NLM_EXTERN Boolean IsIBOL (BioseqPtr bsp);

NLM_EXTERN Boolean 
BarcodeValidateOneSeqEntry 
(FILE *ofp,
 SeqEntryPtr sep,
 Boolean show_all,
 Boolean use_xml,
 Boolean show_header,
 CharPtr xml_header_text);
extern void RemoveBarcodeTech (FILE *fp, ValNodePtr results_list);
extern void RemoveBarcodeKeywords (FILE *fp, ValNodePtr results_list);
extern void ApplyBarcodeKeywords (FILE *fp, ValNodePtr results_list);
extern void ApplyBarcodeTech (FILE *fp, ValNodePtr results_list);
extern Boolean PassBarcodeTests (BarcodeTestResultsPtr res);
extern Boolean HasBARCODETech (BioseqPtr bsp);
NLM_EXTERN void ApplyBarcodeKeywordToBioseq (BioseqPtr bsp);
NLM_EXTERN Boolean BioseqHasBarcodeKeyword (BioseqPtr bsp);
NLM_EXTERN Boolean BioseqHasKeyword (BioseqPtr bsp, CharPtr keyword);
NLM_EXTERN void RemoveBarcodeKeywordsFromObjectList (FILE *fp, ValNodePtr object_list);
NLM_EXTERN Boolean RemoveBarcodeTechFromBioseq (BioseqPtr bsp);
extern Int4 CountPolymorphismsInBioseq (BioseqPtr bsp);
NLM_EXTERN Boolean RemoveBarcodeKeywordFromBioseq (BioseqPtr bsp);


extern CharPtr ExpandDiscrepancyReportTestsFromString (CharPtr list, Boolean expand, DiscReportOutputConfigPtr dcp);
extern void CollateDiscrepancyReports (ValNodePtr PNTR discrepancy_reports);
extern void WriteAsnDiscReport (ValNodePtr discrepancy_list, FILE *ofp, DiscReportOutputConfigPtr oc, Boolean use_flag);


/* extern to allow access to subsource_subtype_alist */
typedef struct Nlm_qual_name_assoc {
   Nlm_CharPtr name; 
   Uint1       value;
} Nlm_QualNameAssoc, PNTR Nlm_QualNameAssocPtr, Nlm_QualNameAlist[];

typedef struct Nlm_name_name_assoc {
   Nlm_CharPtr name; 
   Nlm_CharPtr alias; 
   Uint1       value;
} Nlm_NameNameAssoc, PNTR Nlm_NameNameAssocPtr, Nlm_NameNameAlist[];

extern Nlm_QualNameAssoc current_orgmod_subtype_alist[];
extern Nlm_QualNameAssoc discouraged_orgmod_subtype_alist[];
extern Nlm_QualNameAssoc discontinued_orgmod_subtype_alist[];
extern Nlm_NameNameAssoc orgmod_aliases[];
extern CharPtr GetOrgModQualName (Uint1 subtype);
extern void BioSourceHasOldOrgModQualifiers (BioSourcePtr biop, BoolPtr has_discouraged, BoolPtr has_discontinued);
NLM_EXTERN void StringHasOrgModPrefix (CharPtr str, CharPtr PNTR pval, Uint1Ptr p_subtypeval, Boolean skippref);
NLM_EXTERN CharPtr StringHasPrefix (CharPtr str, CharPtr pref, Boolean novalneeded, Boolean skippref);

extern Nlm_QualNameAssoc  current_subsource_subtype_alist [];
extern Nlm_QualNameAssoc  discouraged_subsource_subtype_alist[];
extern Nlm_QualNameAssoc  discontinued_subsource_subtype_alist[];
extern Nlm_NameNameAssoc  subsource_aliases [];
extern CharPtr GetSubsourceQualName (Uint1 subtype);
extern void BioSourceHasOldSubSourceQualifiers (BioSourcePtr biop, BoolPtr has_discouraged, BoolPtr has_discontinued);
extern Boolean GeneRefMatch (GeneRefPtr grp1, GeneRefPtr grp2);
extern Boolean DbxrefsMatch (ValNodePtr vnp1, ValNodePtr vnp2, Boolean case_sensitive);
extern Boolean XrefsMatch (SeqFeatXrefPtr x1, SeqFeatXrefPtr x2);
extern Boolean ProtRefMatch (ProtRefPtr prp1, ProtRefPtr prp2);

extern void IsCorrectLatLonFormat (CharPtr lat_lon, BoolPtr format_correct, BoolPtr precision_correct, BoolPtr lat_in_range, BoolPtr lon_in_range);
extern CharPtr FixLatLonFormat (CharPtr orig_lat_lon);
extern Boolean ParseLatLon (CharPtr lat_lon, FloatHi PNTR latP, FloatHi PNTR lonP);
extern void ApplyBarcodeDbxrefsToBioseq (BioseqPtr bsp, Pointer data);
extern void ApplyFBOLDbxrefsToBioseq (BioseqPtr bsp, Pointer data);

extern CharPtr GetCountryFix (CharPtr country, CharPtr PNTR country_list);

extern CharPtr ncrnaClassList[];
extern Int4 NcrnaOTHER;
extern Boolean IsStringInNcRNAClassList (CharPtr str);
extern Boolean IsStringInRegulatoryClassList (CharPtr str);
extern Boolean IsStringInRecombinationClassList (CharPtr str);
extern ValNodePtr ListFeaturesInLocation (BioseqPtr bsp, SeqLocPtr slp, Uint1 seqfeatChoice, Uint1 featdefChoice);
extern ValNodePtr ListCodingRegionsContainedInSourceFeatures (SeqEntryPtr sep);
extern ValNodePtr ListFeaturesOverlappingLocationEx (BioseqPtr bsp, SeqLocPtr slp, Uint1 seqfeatChoice, Uint1 featdefChoice, ValNodePtr constraint);
extern ValNodePtr ListFeaturesOverlappingLocation (BioseqPtr bsp, SeqLocPtr slp, Uint1 seqfeatChoice, Uint1 featdefChoice);

extern void ConvertSourceFeatDescProc (SeqFeatPtr sfp, Pointer userdata);

/* for correcting capitalization */
NLM_EXTERN void 
FixCapitalizationInElement 
(CharPtr PNTR pEl,
 Boolean      bAbbrev, 
 Boolean      bShortWords,
 Boolean      bApostrophes);

NLM_EXTERN void FixCapitalizationInAuthor (AuthorPtr pAuthor);
NLM_EXTERN void FixCapsInPubAffil (AffilPtr affil);
NLM_EXTERN void FixCapsInPubAffilEx (AffilPtr affil, Boolean punct_only);
NLM_EXTERN void FixCapitalizationInCountryString (CharPtr PNTR pCountry);
NLM_EXTERN void FixCapitalizationInCountryStringEx (CharPtr PNTR pCountry, Boolean punct_only);
NLM_EXTERN void FixStateAbbreviationsInAffil (AffilPtr affil, LogInfoPtr lip);

NLM_EXTERN void FixAffiliationShortWordsInElement (CharPtr PNTR pEl);
NLM_EXTERN void FixKnownAbbreviationsInElement (CharPtr PNTR pEl);

NLM_EXTERN void FixAbbreviationsInElement (CharPtr PNTR pEl);
NLM_EXTERN void FixOrgNamesInString (CharPtr str, ValNodePtr org_names);
NLM_EXTERN void ResetCapitalization (Boolean first_is_upper, CharPtr pString);

NLM_EXTERN SeqIdPtr CreateSeqIdFromText (CharPtr id_str, SeqEntryPtr sep);
NLM_EXTERN SeqLocPtr SeqLocWholeNew (BioseqPtr bsp);
NLM_EXTERN Int4 GetDeltaSeqLen (DeltaSeqPtr dsp);
NLM_EXTERN DeltaSeqPtr GetDeltaSeqForPosition(Int4 pos, BioseqPtr bsp, Int4Ptr pStart);

typedef SeqAlignPtr (*GlobalAlignFunc) PROTO ((BioseqPtr, BioseqPtr, BoolPtr));

typedef enum {
  eAdjustFeatForGap_unknown_gaps = 0x01,
  eAdjustFeatForGap_known_gaps = 0x02,
  eAdjustFeatForGap_make_partial = 0x04,
  eAdjustFeatForGap_partial_for_pseudo = 0x08,
  eAdjustFeatForGap_trim_ends = 0x10,
  eAdjustFeatForGap_split_internal = 0x20,
  eAdjustFeatForGap_split_in_intron = 0x40
} EAdjustFeatForGap;

typedef struct adjustfeatforgap {
  ValNodePtr feature_list;
  Uint4      options;
  GlobalAlignFunc align_func;
  ValNodePtr features_in_gap;
} AdjustFeatForGapData, PNTR AdjustFeatForGapPtr;

NLM_EXTERN AdjustFeatForGapPtr AdjustFeatForGapFree (AdjustFeatForGapPtr agp);
NLM_EXTERN Boolean FeatureOkForFeatureList (SeqFeatPtr sfp, ValNodePtr feature_list);
NLM_EXTERN void
LocationContainsGaps
(SeqLocPtr slp,
 BioseqPtr bsp,
 Uint4     options,
 BoolPtr   terminal_gaps,
 BoolPtr   internal_gaps,
 BoolPtr   entirely_in_gap);

NLM_EXTERN void SetPartialsAfterSplittingAtGap (SeqLocPtr before, SeqLocPtr after, Boolean set_partial_ends, Boolean partial5, Boolean partial3);
NLM_EXTERN void AdjustFeatureForGapsCallback (SeqFeatPtr sfp, Pointer data);
NLM_EXTERN void MarkFeaturesInGapsForDeletion (AdjustFeatForGapPtr afgp);
NLM_EXTERN void AdjustCDSLocationsForUnknownGapsCallback (SeqFeatPtr sfp, Pointer data);
NLM_EXTERN Boolean GapInLocation (Int4 seq_offset, Int4 length, SeqLocPtr loc);
NLM_EXTERN BioseqPtr 
AddProteinSequenceCopy 
(BioseqPtr  protbsp, 
 BioseqPtr  featbsp,
 SeqFeatPtr new_sfp,
 Uint2      entityID);
NLM_EXTERN void AdjustFrame (SeqFeatPtr sfp, BioseqPtr oldprot);
NLM_EXTERN void SetProductSequencePartials (BioseqPtr protbsp, Boolean partial5, Boolean partial3);
NLM_EXTERN void AddCDSGapComment (SeqFeatPtr sfp);


NLM_EXTERN Boolean SeqEdFixProteinFeatures (BioseqPtr oldbsp, BioseqPtr newbsp, Boolean force_fix, GlobalAlignFunc align_func);
NLM_EXTERN void SeqEdTranslateOneCDS (SeqFeatPtr sfp, BioseqPtr featbsp, Uint2 entityID, GlobalAlignFunc align_func);
NLM_EXTERN void SeqEdRemapLocation (SeqAlignPtr salp, SeqLocPtr slp, Int4 seq_len);

NLM_EXTERN CharPtr GetStateAbbreviation (CharPtr state);

typedef SeqAlignPtr (*LocalAlignFunc) PROTO ((BioseqPtr, BioseqPtr));

extern void ReverseAlignmentStrand (SeqAlignPtr salp, Int4 nth);

NLM_EXTERN SeqAlignPtr SortPairwiseAlignmentsByFirstSeqRange (SeqAlignPtr salp);
NLM_EXTERN ValNodePtr ReportCoverageForBioseqSeqHist (BioseqPtr bsp);

NLM_EXTERN void ConvertLocalIdsToBarcodeIds (SeqEntryPtr sep);

NLM_EXTERN ValNodePtr MakeTokensFromLine (CharPtr line);

NLM_EXTERN SeqFeatPtr GetGeneForFeature (SeqFeatPtr sfp);
NLM_EXTERN SeqFeatPtr GetmRNAforCDS (SeqFeatPtr cds);
NLM_EXTERN SeqFeatPtr GetCDSformRNA (SeqFeatPtr mrna);

NLM_EXTERN Boolean IsStringInSpanInList (CharPtr str, CharPtr list);

NLM_EXTERN void ParseGoTermsFromFields (SeqEntryPtr sep);

/* for autodef */
typedef enum {
  RemovableExon = 0,
  RemovableIntron,
  Removable5UTR,
  Removable3UTR,
  RemovableuORF,
  RemovableCDS,
  RemovablePromoter,
  RemovableLTR,
  RemovableNoncodingProductFeat,
  RemovableMobileElement,
  RemovablePrecursorRNA,
  RemovablencRNA,
  RemovableRepeatRegion,
  NumRemovableItems
} RemovableList;
NLM_EXTERN CharPtr GetRemovableItemName (Int4 i);

typedef enum {
  DEFLINE_USE_FEATURES = 1,
  DEFLINE_COMPLETE_SEQUENCE,
  DEFLINE_PARTIAL_SEQUENCE,
  DEFLINE_COMPLETE_GENOME,
  DEFLINE_PARTIAL_GENOME,
  DEFLINE_SEQUENCE
} DefLineType;

typedef struct deflinefeaturerequestlist {
  Boolean      keep_items[NumRemovableItems];
  Boolean      add_fake_promoters;
  Boolean      suppress_alt_splice_phrase;
  Boolean      remove_subfeatures;
  DefLineType  feature_list_type;
  Int4         misc_feat_parse_rule;
  Boolean      suppress_locus_tags;
  ValNodePtr   suppressed_feature_list;
  Boolean      use_ncrna_note;
  Boolean      suppress_allele;
} DeflineFeatureRequestList, PNTR DeflineFeatureRequestListPtr;

NLM_EXTERN void InitFeatureRequests (DeflineFeatureRequestListPtr feature_requests);


/* ModifierItemLocalData is used to store information about the results of
 * a search of the set of organisms in a record and the results of user
 * input to a dialog for deciding which modifiers should be used in the
 * organism description.
 */
typedef struct modifieritemlocal {
/*  ButtoN        button; */
  Boolean       any_present;
  Boolean       all_present;
  Boolean       is_unique;
  CharPtr       first_value_seen;
  ValNodePtr    values_seen;
  Boolean       all_unique;
  CharPtr       status;
  Boolean       required;
} ModifierItemLocalData, PNTR ModifierItemLocalPtr;

typedef enum {
  DEFLINE_POS_Bio_material = 0,
  DEFLINE_POS_Biotype,
  DEFLINE_POS_Biovar,
  DEFLINE_POS_Breed,
  DEFLINE_POS_Cell_line,
  DEFLINE_POS_Chemovar,
  DEFLINE_POS_Chromosome,
  DEFLINE_POS_Clone,
  DEFLINE_POS_Country,
  DEFLINE_POS_Cultivar,
  DEFLINE_POS_Culture_collection,
  DEFLINE_POS_Dev_stage,
  DEFLINE_POS_Ecotype,
  DEFLINE_POS_Endogenous_virus_name,
  DEFLINE_POS_Genotype,
  DEFLINE_POS_Haplogroup,
  DEFLINE_POS_Haplotype,
  DEFLINE_POS_Isolate,
  DEFLINE_POS_Linkage_group,
  DEFLINE_POS_Map,
  DEFLINE_POS_Pathovar,
  DEFLINE_POS_Plasmid_name,
  DEFLINE_POS_Pop_variant,
  DEFLINE_POS_Segment,
  DEFLINE_POS_Serogroup,
  DEFLINE_POS_Serotype,
  DEFLINE_POS_Serovar,
  DEFLINE_POS_Specimen_voucher,
  DEFLINE_POS_Strain,
  DEFLINE_POS_Subclone,
  DEFLINE_POS_Substrain,
  DEFLINE_POS_Transgenic
} DefLinePos;

NLM_EXTERN Int4 GetDeflinePosForFieldName(CharPtr name);
NLM_EXTERN Int4 GetDeflinePosForFieldType (ValNodePtr field);

/* ModifierItemGlobalData is used to store information about the available
 * modifiers - the name to use when displaying a list of checkboxes, whether
 * the modifier is an Organism modifier or a Source modifier, the subtype
 * to use when looking for the modifier in the organism qualifier list,
 * and whether this modifier is required by default.
 */
typedef struct modifieritemglobal {
  CharPtr       name;
  Boolean       isOrgMod;
  Uint1         subtype;
} ModifierItemGlobalData, PNTR ModifierItemGlobalPtr;

extern ModifierItemGlobalData DefLineModifiers[];
NLM_EXTERN size_t NumDefLineModifiers (void);

/* OrganismDescriptionModifiers is used to apply specific user preferences
 * for how to construct the organism descriptions - whether or not to use
 * labels for the modifiers, whether and how to limit the number of modifiers
 * used in any one organism description, whether to keep or remove modifier
 * information in parentheses in the organism taxonomy name, and whether or
 * not to apply modifiers to organisms with "sp." in the middle of the
 * taxonomy name.
 */
typedef struct organismdescriptionmodifiers {
  Boolean  use_labels;
  Int2     max_mods;
  Boolean  keep_paren;
  Boolean  exclude_sp;
  Boolean  exclude_cf;
  Boolean  exclude_aff;
  Boolean  exclude_nr;
  Boolean  include_country_extra;
  Int4     clone_isolate_HIV_rule_num;
  Boolean  use_modifiers;
  Boolean  allow_semicolon_in_modifier;
  Boolean  allow_mod_at_end_of_taxname;
} OrganismDescriptionModifiers, PNTR OrganismDescriptionModifiersPtr;

NLM_EXTERN Boolean ShouldExcludeSp (SeqEntryPtr sep);
NLM_EXTERN void InitOrganismDescriptionModifiers(OrganismDescriptionModifiersPtr odmp, SeqEntryPtr sep);

/* These values are used for the clone_isolate_HIV_rule_num value in OrganismDescriptionModifiers */
typedef enum {
  clone_isolate_HIV_rule_prefer_clone = 1,
  clone_isolate_HIV_rule_prefer_isolate,
  clone_isolate_HIV_rule_want_both
} clone_isolate_HIV_rule_values;
  

typedef struct sourcequaldesc
{
  CharPtr       name;
  Boolean       isOrgMod;
  Uint1         subtype;
  Uint1         subfield;
} SourceQualDescData, PNTR SourceQualDescPtr;

NLM_EXTERN int LIBCALLBACK SortVnpBySourceQualDesc (VoidPtr ptr1, VoidPtr ptr2);

NLM_EXTERN void SetRequiredModifiers (ModifierItemLocalPtr modList);
NLM_EXTERN void CountModifiers (ModifierItemLocalPtr ItemList, SeqEntryPtr sep);
NLM_EXTERN ValNodePtr FindBestModifiersEx(SeqEntryPtr sep, ModifierItemLocalPtr ItemList, Boolean use_new);
NLM_EXTERN ValNodePtr FindBestModifiers(SeqEntryPtr sep, ModifierItemLocalPtr ItemList);
NLM_EXTERN ValNodePtr FindBestModifiersForDeflineClauseList (ValNodePtr defline_clauses, ModifierItemLocalPtr ItemList);

NLM_EXTERN ValNodePtr GetModifierIndicesFromModList (ModifierItemLocalPtr modList);
extern void TestFindBestQualCombo (FILE *fp);


NLM_EXTERN CharPtr MergeValNodeStrings (ValNodePtr list, Boolean useReturn);

NLM_EXTERN ValNodePtr FindExactStringListMatch (ValNodePtr list, CharPtr value);

NLM_EXTERN void BuildDefLineFeatClauseList 
( SeqEntryPtr sep,
  Uint2 entityID,
  DeflineFeatureRequestList PNTR feature_requests,
  Int2 product_flag,
  Boolean alternate_splice_flag,
  Boolean gene_cluster_opp_strand,
  ValNodePtr PNTR list);

NLM_EXTERN Boolean AreFeatureClausesUnique (ValNodePtr list);
NLM_EXTERN void DefLineFeatClauseListFree (ValNodePtr vnp);

NLM_EXTERN void 
BuildDefinitionLinesFromFeatureClauseLists 
(ValNodePtr list,
 ModifierItemLocalPtr modList,
 ValNodePtr modifier_indices,
 OrganismDescriptionModifiersPtr odmp);

NLM_EXTERN void 
BuildDefLinesFromFeatClauseListsForOneBsp 
(ValNodePtr list,
 ModifierItemLocalPtr modList,
 ValNodePtr modifier_indices,
 OrganismDescriptionModifiersPtr odmp,
 BioseqPtr bsp);

NLM_EXTERN void 
AutoDefForSeqEntry 
(SeqEntryPtr sep,
 Uint2 entityID,
 OrganismDescriptionModifiersPtr odmp,
 ModifierItemLocalPtr modList,
 ValNodePtr modifier_indices,
 DeflineFeatureRequestListPtr feature_requests,
 Int2 product_flag,
 Boolean alternate_splice_flag,
 Boolean gene_cluster_opp_strand);

NLM_EXTERN void
AutoDefForSeqEntryEx
(SeqEntryPtr sep,
Uint2 entityID,
OrganismDescriptionModifiersPtr odmp,
ModifierItemLocalPtr modList,
ValNodePtr modifier_indices,
DeflineFeatureRequestListPtr feature_requests,
Int2 product_flag,
Boolean alternate_splice_flag,
Boolean gene_cluster_opp_strand,
Boolean update_options);

NLM_EXTERN void RegenerateAutoDef(BioseqPtr bsp);
NLM_EXTERN void RemoveAutodefObjects(SeqEntryPtr sep);
NLM_EXTERN void RemoveAutodefObjectsForDesc(SeqDescPtr sdp);

NLM_EXTERN void AddPopsetTitles 
(SeqEntryPtr sep,
 DeflineFeatureRequestListPtr feature_requests,
 Int2 product_flag,
 Boolean alternate_splice_flag,
 Boolean gene_cluster_opp_strand);

NLM_EXTERN void RemovePopsetTitles(SeqEntryPtr sep); 

NLM_EXTERN UserObjectPtr MakeAutoDefOptionsUserObject
(OrganismDescriptionModifiersPtr odmp,
ModifierItemLocalPtr modList,
ValNodePtr modifier_indices,
DeflineFeatureRequestListPtr feature_requests,
Int2 product_flag,
Boolean alternate_splice_flag,
Boolean gene_cluster_opp_strand);

NLM_EXTERN void AddAutoDefUserObjectToSeqEntry(SeqEntryPtr sep, UserObjectPtr uop);

NLM_EXTERN void DoTbl2AsnAutoDef(SeqEntryPtr sep, Uint2 entityID);

typedef struct popsetretrostat {
  Int4 feature_clause;
  Int4 common_title;
  Int4 uncalculatable; 
  Boolean title_added;
} PopSetRetroStatData, PNTR PopSetRetroStatPtr;

NLM_EXTERN void PopSetAutoDefRetro (SeqEntryPtr sep, PopSetRetroStatPtr stat);

NLM_EXTERN Boolean IsSpName (CharPtr taxName);

#define DEFAULT_ORGANELLE_CLAUSE 10
NLM_EXTERN BioSourcePtr GetBiopForBsp (BioseqPtr bsp);
NLM_EXTERN Boolean IsLocAInBonSameStrand (SeqLocPtr slp1, SeqLocPtr slp2);
NLM_EXTERN void CleanUpTaxName (CharPtr taxName, Boolean keep_in_paren);
NLM_EXTERN Boolean UseOrgModifier (OrgModPtr mod, CharPtr taxName, Boolean allow_at_end);
NLM_EXTERN Boolean UseSubSrcModifier (SubSourcePtr ssp, CharPtr taxName, Boolean allow_at_end);
NLM_EXTERN void AddModifierLabel 
( Boolean use_labels,
  Boolean is_orgmod,
  Uint1   subtype,
  CharPtr modifier_text);
NLM_EXTERN Boolean LIBCALLBACK IsMobileElement (SeqFeatPtr sfp);
NLM_EXTERN void RemoveNucProtSetTitles (SeqEntryPtr sep);
NLM_EXTERN void RemoveMRnaTitles (SeqEntryPtr sep);
NLM_EXTERN void RemoveProteinTitles (SeqEntryPtr sep);
NLM_EXTERN void SetAutoDefIDModifiers (ModifierItemLocalPtr modList);


NLM_EXTERN ValNodePtr ReadTabTableFromFile (FILE *fp);
NLM_EXTERN ValNodePtr FlipTabTableAxes (ValNodePtr row_list);
NLM_EXTERN ValNodePtr FreeTabTable (ValNodePtr row_list);
NLM_EXTERN ValNodePtr CopyTabTable (ValNodePtr row_list);
NLM_EXTERN void WriteTabTableToFile (ValNodePtr table, FILE *fp);
NLM_EXTERN ValNodePtr CountTabTableBlanks (ValNodePtr row_list);
NLM_EXTERN ValNodePtr ScanTabTableForSpecialCharacters (ValNodePtr row_list);
NLM_EXTERN ValNodePtr AutoReplaceSpecialCharactersInText (CharPtr PNTR text);
NLM_EXTERN void AutoReplaceSpecialCharactersWithMessage (CharPtr PNTR text);
NLM_EXTERN ValNodePtr AutoReplaceSpecialCharactersInTabTable (ValNodePtr row_list);
NLM_EXTERN void AutoFixSpecialCharactersInEntity (Uint2 entityID);

NLM_EXTERN void RemoveQuotesFromTabTable (ValNodePtr row_list);
NLM_EXTERN void ReparseTabTableConvertFirstSpaceToTab (ValNodePtr row_list);
NLM_EXTERN void ReparseTabTableConvertMultiSpaceToTab (ValNodePtr row_list);
NLM_EXTERN void CombineTabTableColumns (ValNodePtr row_list, ValNodePtr column_pos, CharPtr delimiter);
NLM_EXTERN void ReparseTabTableSeparateColumnAtDelimiter (ValNodePtr row_list, Char delimiter, Int4 col, Boolean stop_after_first);
NLM_EXTERN void AddTextToTabTableColumn (ValNodePtr row_list, Int4 col, CharPtr text, Uint2 existing_text);
NLM_EXTERN ValNodePtr ReadOneColumnList (CharPtr line);
NLM_EXTERN ValNodePtr SortTableRowByAnyColumn (ValNodePtr table, Int4 column);
NLM_EXTERN void AdjustInfluenzaSourceTable (ValNodePtr table);

NLM_EXTERN void SpecialCharFindWithContext (CharPtr PNTR strp, Pointer userdata, BoolPtr did_find, BoolPtr did_change);
NLM_EXTERN ValNodePtr FreeContextList (ValNodePtr context_list);

typedef struct twostringhash {
  CharPtr PNTR table;
  Int4 num_lines;
} TwoStringHashData, PNTR TwoStringHashPtr;

NLM_EXTERN TwoStringHashPtr TwoStringHashFree (TwoStringHashPtr tsh);
NLM_EXTERN TwoStringHashPtr MakeTwoStringHashFromTabTable (ValNodePtr line_list, Int4 column1, Int4 column2);
NLM_EXTERN CharPtr GetValueFromTwoStringHash (CharPtr key, TwoStringHashPtr tsh);

NLM_EXTERN Int4 ExtendSeqLocToEnd (SeqLocPtr slp, BioseqPtr bsp, Boolean end5);

NLM_EXTERN void PromoteAllToBestID (SeqEntryPtr sep);
NLM_EXTERN void PromoteAllToWorstID (SeqEntryPtr sep);
NLM_EXTERN void RemoveAllVersionLocusGIFromID (SeqEntryPtr sep);

/* functions for converting features */
NLM_EXTERN Boolean IsBioseqSetInGPS (BioseqSetPtr bssp);
NLM_EXTERN Boolean IsBioseqInGPS (BioseqPtr bsp);
NLM_EXTERN Boolean IsFeatInGPS (SeqFeatPtr sfp);
NLM_EXTERN void 
ApplyCDSOptionsToFeature
(SeqFeatPtr sfp,
 Boolean remove_mRNA,
 Boolean remove_gene,
 Boolean remove_transcript_id,
 Boolean keep_original);

NLM_EXTERN Boolean 
ConvertCDSToRNA 
(SeqFeatPtr  sfp,
 Uint2       rna_type);

NLM_EXTERN Boolean ConvertGeneToRNA (SeqFeatPtr sfp, Uint2 featdef_to);
NLM_EXTERN Boolean ConvertBioSrcToRepeatRegion (SeqFeatPtr sfp, Uint2 featdef_to);
NLM_EXTERN CharPtr SubSourceText (BioSourcePtr biop, Uint1 subtype, BoolPtr found);
NLM_EXTERN CharPtr OrgModText (BioSourcePtr biop, Uint1 subtype, BoolPtr found);
NLM_EXTERN CharPtr NoteText (BioSourcePtr biop, CharPtr comment);
NLM_EXTERN Boolean ConvertNonPseudoCDSToMiscFeat (SeqFeatPtr sfp, Boolean viral);

NLM_EXTERN CharPtr GetImportFeatureName (Uint2 featdef_key);
NLM_EXTERN RnaRefPtr RnaRefFromLabel (Uint2 featdef_to, CharPtr label, BoolPtr add_label_to_comment);

NLM_EXTERN SeqLocPtr GetProteinLocationForNucleotideFeatureConversion (SeqLocPtr nuc_slp, BoolPtr no_cds);
NLM_EXTERN SeqLocPtr FindNucleotideLocationForProteinFeatureConversion (SeqLocPtr slp);
NLM_EXTERN SeqLocPtr BuildProtLoc (SeqFeatPtr overlapping_cds, SeqLocPtr slp, Int4Ptr frame);
NLM_EXTERN Boolean ConvertImpToProtFunc (SeqFeatPtr sfp, Uint2 featdef_to);
NLM_EXTERN Boolean ConvertProtToImpFunc (SeqFeatPtr  sfp, Uint2 featdef_to);
NLM_EXTERN Boolean ConvertRegionToProtFunc (SeqFeatPtr sfp, Uint2 featdef_to);
NLM_EXTERN Boolean ConvertRegionToImpFunc (SeqFeatPtr sfp, Uint2 featdef_to);
NLM_EXTERN Boolean ConvertImpToImpFunc (SeqFeatPtr sfp, Uint2 featdef_to);
NLM_EXTERN Boolean ConvertRegionToRNAFunc (SeqFeatPtr sfp, Uint2 featdef_to);
NLM_EXTERN Boolean ConvertGeneToImpFeatFunc (SeqFeatPtr sfp, Uint2 featdef_to);
NLM_EXTERN Boolean ConvertProtToProtFunc (SeqFeatPtr sfp, Uint2 featdef_to);
NLM_EXTERN Boolean ConvertMiscFeatToGene (SeqFeatPtr sfp);
NLM_EXTERN Boolean ConvertMiscFeatToCodingRegion (SeqFeatPtr sfp);
NLM_EXTERN Boolean ConvertmRNAToCodingRegion (SeqFeatPtr sfp);
NLM_EXTERN Boolean ConverttRNAToGene(SeqFeatPtr sfp);
NLM_EXTERN void ExtraCDSCreationActions (SeqFeatPtr cds, SeqEntryPtr parent_sep);
NLM_EXTERN SeqFeatPtr GetProtFeature (BioseqPtr protbsp);

NLM_EXTERN void InstantiateMatPeptideProducts (SeqEntryPtr sep);

NLM_EXTERN Boolean CodingRegionHasTranslExcept (SeqFeatPtr sfp);

NLM_EXTERN SeqEntryPtr SequenceStringToSeqEntry (CharPtr str, SeqIdPtr sip, Uint1 mol_type);

NLM_EXTERN void RevCompOneFeatForBioseq (SeqFeatPtr sfp, BioseqPtr bsp);
NLM_EXTERN void RevCompFeats (SeqEntryPtr sep, Pointer mydata, Int4 index, Int2 indent);

/* for parsing collection dates */
NLM_EXTERN CharPtr ReformatDateStringEx (CharPtr orig_date, Boolean month_first, BoolPtr month_ambiguous);
NLM_EXTERN CharPtr ReformatDateWithMonthNames (CharPtr orig_date);
NLM_EXTERN Int4 GetYearFromToken (CharPtr token, Int4 token_len);
NLM_EXTERN Int4 ReadNumberFromToken (CharPtr token, Int4 token_len);
NLM_EXTERN CharPtr GetMonthFromToken (CharPtr token, Int4 token_len);
NLM_EXTERN Int4 GetMonthNumFromAbbrev (CharPtr month_abbrev);
NLM_EXTERN CharPtr GetMonthAbbrev (Int4 n);
NLM_EXTERN Int4 GetDaysInMonth (Int4 n);

/* for reformatting assembly date */
NLM_EXTERN CharPtr AssemblyDateFromCollectionDate (CharPtr collection_date, Boolean ambiguous);
NLM_EXTERN Boolean ReformatAssemblyDate (CharPtr PNTR orig_date);

NLM_EXTERN void CreateStructuredCommentsForAllFromTable (SeqEntryPtr sep, ValNodePtr header, ValNodePtr line, ValNodePtr PNTR err_list);
NLM_EXTERN ValNodePtr CreateStructuredCommentsFromFile (FILE *fp, SeqEntryPtr sep, Boolean apply_to_all);
NLM_EXTERN void AddDatabaseNameToStructuredComment (UserObjectPtr uop, CharPtr dbname);
NLM_EXTERN ValNodePtr CreateStructuredCommentTableFromSeqEntry (SeqEntryPtr sep);

#define ALNMGR_GAP           -2
#define ALNMGR_ROW_UNDEFINED -1

NLM_EXTERN void 
AlignmentIntervalToString 
(SeqAlignPtr salp,
 Int4        row,
 Int4        start,
 Int4        stop,
 Int4        target_row,
 Boolean     view_whole_entity,
 Uint1Ptr    seqbuf,
 Uint1Ptr    alnbuf,
 Int4 PNTR   alnbuffer_len,
 Boolean     show_substitutions);

extern void CountNsInSequence (
  BioseqPtr bsp,
  Int4Ptr p_totalN,
  Int4Ptr p_totalDash,
  Int4Ptr p_totalTilde,
  Int4Ptr p_max_stretch,
  Boolean expand_gaps,
  Boolean no_stretch_in_assembly_gap
);
NLM_EXTERN Boolean IsTSA (BioseqPtr bsp);

NLM_EXTERN Boolean IsPseudo (SeqFeatPtr sfp);

NLM_EXTERN Boolean ExtendPartialsToEndOrGap (SeqFeatPtr sfp);
NLM_EXTERN Boolean RetranslateOneCDS 
( SeqFeatPtr sfp,
  Uint2 entityID,
  Boolean include_stop,
  Boolean no_stop_at_end_of_complete_cds);
NLM_EXTERN SeqFeatPtr FindBestProtein (Uint2 entityID, SeqLocPtr product);
NLM_EXTERN void AddNonExtendableException (SeqFeatPtr sfp);
NLM_EXTERN SeqLocPtr GetmRNALocationFromCDSLocation (SeqLocPtr slp, Uint2 entityID);
NLM_EXTERN SeqFeatPtr AddmRNAForCDS (SeqFeatPtr sfp);
NLM_EXTERN Boolean ProductsMatchForRefSeq (CharPtr cds_str, CharPtr mrna_str);
NLM_EXTERN SeqSubmitPtr FindSeqSubmitForSeqEntry (SeqEntryPtr sep);
NLM_EXTERN Boolean CreateMatPeptideFromCDS (SeqFeatPtr sfp);
NLM_EXTERN Boolean ConvertCDSToMatPeptideForOverlappingCDS (SeqFeatPtr sfp, SeqFeatPtr top_cds, Boolean remove_original);
NLM_EXTERN Boolean AutoConvertCDSToMiscFeat (SeqFeatPtr cds, Boolean remove_original);

NLM_EXTERN AuthListPtr PNTR GetAuthListForPub (PubPtr the_pub);
NLM_EXTERN void RemoveConsortiumFromPub (PubPtr pub);

NLM_EXTERN Int4 Extend5PartialSeqIntToEndOrGap (SeqIntPtr sint, BioseqPtr bsp, Boolean short_only);
NLM_EXTERN Int4 Extend3PartialSeqIntToEndOrGap (SeqIntPtr sint, BioseqPtr bsp, Boolean short_only);
NLM_EXTERN Int4 ExtendSeqLocToEndOrGap (SeqLocPtr slp, BioseqPtr bsp, Boolean end5);
NLM_EXTERN FloatLo PercentNInBioseq (BioseqPtr bsp, Boolean include_gaps);
NLM_EXTERN FloatLo PercentNInBioseqInterval (BioseqPtr bsp, Int4 start, Int4 stop, Boolean include_gaps);

NLM_EXTERN SeqEntryPtr GetBestSeqEntryForItem (ValNodePtr vnp);
NLM_EXTERN void AddNewUniqueDescriptors (SeqDescrPtr PNTR new_set, SeqDescrPtr parent_set);
NLM_EXTERN void AddNewUniqueAnnotations (SeqAnnotPtr PNTR new_set, SeqAnnotPtr parent_set);
NLM_EXTERN BioseqSetPtr MakeGroupsForUniqueValues (BioseqSetPtr bssp, ValNodePtr value_lists);
NLM_EXTERN ValNodePtr PrepareSequenceListForSegregateByNumberOfSets (Int4 num_sets, SeqEntryPtr sep);
NLM_EXTERN void SegregateSetsByNumber (SeqEntryPtr sep, Int4 num_sets);
NLM_EXTERN ValNodePtr PrepareSequenceListForSegregateByNumberPerSet (Int4 num_per_set, SeqEntryPtr sep);
NLM_EXTERN void SegregateSetsByNumberPerSet (SeqEntryPtr sep, Int4 num_per_set);

NLM_EXTERN void MoveSequencesFromSetToWrapper (ValNodePtr list, Uint2 entityID);

NLM_EXTERN ValNodePtr CreateStructuredCommentsFromRow (ValNodePtr header, ValNodePtr values, CharPtr id_str, ValNodePtr PNTR err_list);

NLM_EXTERN void MergeAdjacentAnnotsInList (SeqAnnotPtr sap);

NLM_EXTERN Boolean GetsDocsumTitle(Uint1 set_class);
NLM_EXTERN void PromoteCommonTitlesToSet (SeqEntryPtr sep);

NLM_EXTERN void SetDescriptorPropagate (BioseqSetPtr bssp);

typedef Boolean (*DescriptorTestFunc) PROTO ((SeqDescPtr, Pointer));
NLM_EXTERN void PropagateSomeDescriptors (SeqEntryPtr sep, DescriptorTestFunc test_func, Pointer extradata);
NLM_EXTERN void PropagateDblinkDescriptors (SeqEntryPtr sep);

NLM_EXTERN Boolean RemoveDuplicateNestedSetsForEntityID (Uint2 entityID);
NLM_EXTERN Boolean RemoveDuplicateNestedSetsForEntityIDNoUpdate (Uint2 entityID);

NLM_EXTERN void AddStructuredCommentKeywords (Uint2 entityID);
NLM_EXTERN CharPtr KeywordForStructuredCommentPrefix (CharPtr prefix);
NLM_EXTERN CharPtr StructuredCommentPrefixForKeyword (CharPtr keyword);
NLM_EXTERN CharPtr KeywordForStructuredCommentName (UserObjectPtr uop);
NLM_EXTERN Boolean HasKeywordForStructuredCommentName (BioseqPtr bsp, UserObjectPtr uop);
NLM_EXTERN Boolean HasAllKeywordsForStructuredComment (BioseqPtr bsp, CharPtr keyword);
NLM_EXTERN Boolean HasAnyKeywordForStructuredComment (BioseqPtr bsp, CharPtr keyword);
NLM_EXTERN ValNodePtr GetAllStructuredCommentKeywords (void);
NLM_EXTERN void RemoveStructuredCommentKeywords (Uint2 entityID);
NLM_EXTERN void RemoveAllStructuredCommentKeywords (Uint2 entityID);
NLM_EXTERN ValNodePtr SplitStringAtSemicolon (CharPtr keyword);

NLM_EXTERN void ParseTaxNameToQuals (OrgRefPtr org, TextFsaPtr tags);

NLM_EXTERN ValNodePtr GetLocusTagPrefixList (SeqEntryPtr sep);

NLM_EXTERN Boolean IsProductNameOk (CharPtr product_name);
NLM_EXTERN Boolean ReportProductNameProblems (CharPtr product_name, FILE *output_file, CharPtr prefix);
NLM_EXTERN Boolean FixProductNameProblems (CharPtr PNTR product_name);

NLM_EXTERN SeqEntryPtr ReadFilteredAsn (FILE *fp, Boolean is_binary, CharPtr accn_list, Uint2Ptr entityIDptr);
NLM_EXTERN void ReintegrateFilteredAsn (SeqEntryPtr sep, FILE *orig_file, FILE *output, Boolean is_binary);

typedef struct descstream {
  SeqDescPtr orig;
  SeqDescPtr replace;
  SeqIdPtr   owners;
  SeqIdPtr   last_owner;
  Boolean    on_all;
  CharPtr    text;
  Int4       num_dependent;
} DescStreamData, PNTR DescStreamPtr;

NLM_EXTERN DescStreamPtr DescStreamNew (SeqDescPtr sdp, BioseqPtr parent);
NLM_EXTERN DescStreamPtr DescStreamFree (DescStreamPtr ds);
NLM_EXTERN ValNodePtr DescStreamListFree (ValNodePtr vnp);

NLM_EXTERN ValNodePtr StreamAsnForDescriptors (FILE *fp, Boolean is_binary, Boolean is_batch, Boolean is_submit, SeqIdPtr PNTR sip_list);
NLM_EXTERN void WriteAsnWithReplacedDescriptors (ValNodePtr desc_stream_list, FILE *orig_file, FILE *output, Boolean is_binary, Boolean is_batch, Boolean is_submit);
NLM_EXTERN Boolean IdListsMatch (SeqIdPtr sip_list, ValNodePtr all_sip);
NLM_EXTERN void SetOnAllValsForDescStreamList (ValNodePtr desc_list, ValNodePtr all_sip);

extern Boolean ParseCodeBreak (SeqFeatPtr sfp, CharPtr val, Int4 offset);

NLM_EXTERN void CleanupOneSeqFeat (SeqFeatPtr sfp);

NLM_EXTERN Uint1 GetSpecialPlastidGenCode (
  CharPtr taxname,
  CharPtr lineage
);


NLM_EXTERN Boolean TrimPrimerSeqJunkInSeqEntry (SeqEntryPtr sep, FILE *log_fp);
NLM_EXTERN Boolean FixUsaAndStateAbbreviations (Uint2 entityID, FILE *log_fp);
NLM_EXTERN void AdjustSeqEntryForConsensusSplice (SeqEntryPtr sep);
NLM_EXTERN Boolean AdjustSeqEntryForConsensusSpliceEx (SeqEntryPtr sep, FILE *log_fp, Boolean strict);

NLM_EXTERN void 
FixCapitalizationInTitle 
(CharPtr PNTR pTitle,
 Boolean      first_is_upper,
 ValNodePtr   org_names);

NLM_EXTERN Int4 ConvertCommentsWithSpacesToStructuredCommentsForSeqEntry (SeqEntryPtr sep);

NLM_EXTERN void ParseExtractorResultsTableToFeatures (FILE *fp, SeqEntryPtr sep);
NLM_EXTERN void ParseRNAFeatListTableToFeatures (FILE *fp, SeqEntryPtr sep, LogInfoPtr lip);


#ifdef OS_MSWIN
NLM_EXTERN Int4 RunSilent(const char *cmdline);
#endif


NLM_EXTERN CharPtr ValNodeSeqIdName (ValNodePtr vnp);
NLM_EXTERN void ValNodeSeqIdFree (ValNodePtr vnp);
NLM_EXTERN ValNodePtr ValNodeSeqIdCopy (ValNodePtr vnp);
NLM_EXTERN Boolean ValNodeSeqIdMatch (ValNodePtr vnp1, ValNodePtr vnp2);
NLM_EXTERN ValNodePtr ValNodeSeqIdListFree (ValNodePtr list);
NLM_EXTERN ValNodePtr ValNodeSeqIdListCopy (ValNodePtr list);
NLM_EXTERN ValNodePtr SeqIdListToValNodeSeqIdList (SeqIdPtr sip_list);
NLM_EXTERN SeqIdPtr ValNodeSeqIdListToSeqIdList (ValNodePtr vnp_list);

NLM_EXTERN void StringToLower (CharPtr str);

NLM_EXTERN ValNodePtr FixupCountryQuals (SeqEntryPtr sep, Boolean fix_after_colon);
NLM_EXTERN Boolean FixupCountryQualsWithLog (SeqEntryPtr sep, Boolean fix_after_colon, FILE *log_fp);
NLM_EXTERN Boolean FixupMouseStrains (SeqEntryPtr sep, FILE *log_fp);

NLM_EXTERN CharPtr StructuredCommentDbnameFromString (CharPtr string);
NLM_EXTERN ValNodePtr GetStructuredCommentPrefixList (void);
NLM_EXTERN void SetStructuredCommentPrefixAndSuffix (UserObjectPtr uop, CharPtr string);

extern ValNodePtr GetSourceQualDescListEx (Boolean get_subsrc, Boolean get_orgmod, Boolean get_discouraged, Boolean get_discontinued, Boolean get_subfields);

NLM_EXTERN Boolean RemoveCultureNotes (SeqEntryPtr sep);

NLM_EXTERN AuthListPtr GetAuthorListForPub (PubPtr the_pub);

NLM_EXTERN void FixProductWordCapitalization (CharPtr PNTR pProduct);
NLM_EXTERN Boolean FixSrcQualCaps (SeqEntryPtr sep, Int4 src_qual, FILE *log_fp);
NLM_EXTERN Boolean IsNCBIFileID (SeqIdPtr sip);

NLM_EXTERN Boolean IsLocationOrganelle (Uint1 genome);
NLM_EXTERN Boolean IsBioseqOrganelle (BioseqPtr bsp);

NLM_EXTERN void RemoveFeatureLink (SeqFeatPtr sfp1, SeqFeatPtr sfp2);
NLM_EXTERN void LinkTwoFeatures (SeqFeatPtr dst, SeqFeatPtr sfp);
NLM_EXTERN void MakeFeatureXrefsFromProteinIdQuals (SeqEntryPtr sep);
NLM_EXTERN void MakeFeatureXrefsFromTranscriptIdQuals (SeqEntryPtr sep);
NLM_EXTERN void FinishHalfXrefs (SeqEntryPtr sep);
NLM_EXTERN void FlipCodonRecognizedInSeqEntry (SeqEntryPtr sep, LogInfoPtr lip);
NLM_EXTERN void RemoveBadCodonRecognizedInSeqEntry (SeqEntryPtr sep, LogInfoPtr lip);
NLM_EXTERN Uint1 GetAaFromtRNA (tRNAPtr trp);
NLM_EXTERN CharPtr GetCodesFortRNA (SeqFeatPtr sfp, Int2 *pCode);

NLM_EXTERN void ReverseBioseqInAlignment (SeqAlignPtr salp, Pointer userdata);
NLM_EXTERN void FlipAlignment (SeqAlignPtr salp);
NLM_EXTERN void FlipEntireAlignmentIfAllSequencesFlipped (SeqAnnotPtr sap, Pointer userdata);
NLM_EXTERN ValNodePtr ListSequencesWithAlignments (ValNodePtr bsp_list);
typedef Boolean (LIBCALL *BioseqFunc) (BioseqPtr);
NLM_EXTERN void RevCompBioseqList (ValNodePtr bsp_list, 
                                   Uint2 entityID, 
                                   BioseqFunc func,
                                   Boolean revCompFeats,
                                   Boolean check_for_aln);
NLM_EXTERN Boolean IsBioseqInAnyAlignment (BioseqPtr bsp, Uint2 input_entityID);
NLM_EXTERN Boolean AreAnyElementsOfSetInAnyAlignment (BioseqSetPtr bssp, Uint2 input_entityID);
NLM_EXTERN void RemoveAlignmentsWithSequence (BioseqPtr bsp, Uint2 input_entityID);
NLM_EXTERN void RemoveAlignmentsWithElementsOfSet (BioseqSetPtr bssp, Uint2 input_entityID);

NLM_EXTERN void ReplaceComplexLocation (SeqLocPtr slp, SeqAlignPtr salp, Int4 new_len, Int4 begin, Int4 fin);
NLM_EXTERN void ReplaceOneSequence (SeqAlignPtr salp, BioseqPtr oldbsp, BioseqPtr newbsp);
NLM_EXTERN Boolean AreSequenceResiduesIdentical (BioseqPtr bsp1, BioseqPtr bsp2);
NLM_EXTERN SeqAlignPtr AlignForSequenceUpdate (BioseqPtr bsp1, BioseqPtr bsp2, BoolPtr revcomp, GlobalAlignFunc align_func);
NLM_EXTERN void AddCitSubToUpdatedSequence (BioseqPtr upd_bsp, Uint2 input_entityID, CharPtr update_txt);
NLM_EXTERN ValNodePtr CreateUpdateCitSubFromBestTemplate (SeqEntryPtr top_sep, SeqEntryPtr upd_sep, CharPtr update_txt);
NLM_EXTERN void RemoveQualityScores (BioseqPtr bsp, FILE *log_fp, BoolPtr data_in_log);
NLM_EXTERN void ReplaceFakeIDWithIDFromTitle (BioseqPtr bsp);

typedef  void  (*Nlm_ImportSeqCallbackProc) PROTO ((Int4, Int4, Pointer));

NLM_EXTERN SeqEntryPtr 
ImportNucleotideFASTASequencesFromFileEx
(FILE           *fp, 
 Boolean         parse_id,
 CharPtr         supplied_id_txt,
 ValNodePtr PNTR err_msg_list,
 BoolPtr         chars_stripped,
 Boolean         allow_char_stripping,
 Nlm_ImportSeqCallbackProc callback,
 Pointer         callback_data);

NLM_EXTERN SeqEntryPtr 
ImportNucleotideFASTASequencesFromFile
(FILE           *fp, 
 Boolean         parse_id,
 CharPtr         supplied_id_txt,
 ValNodePtr PNTR err_msg_list,
 BoolPtr         chars_stripped,
 Boolean         allow_char_stripping);
NLM_EXTERN SeqEntryPtr ImportProteinFASTASequences 
(FILE            *fp,
 Boolean         parse_id,
 CharPtr         supplied_id_txt,
 ValNodePtr PNTR err_msg_list,
 BoolPtr         chars_stripped);
NLM_EXTERN void AddUniqueUpdateSequenceIDs (SeqEntryPtr sep);
NLM_EXTERN void ListBioseqsInSeqEntry (SeqEntryPtr sep, Boolean is_na, Int4Ptr seq_num, ValNodePtr PNTR bioseq_list);
NLM_EXTERN ValNodePtr ShuffleUpdateBioseqList (ValNodePtr PNTR update_bioseq_list, ValNodePtr orig_bioseq_list);
NLM_EXTERN ValNodePtr GetNthValNode (ValNodePtr list, Int4 n);
NLM_EXTERN ValNodePtr ExtractNthValNode (ValNodePtr PNTR list, Int4 nth);
NLM_EXTERN BioseqPtr FindBioseqInList (ValNodePtr bioseq_list, SeqIdPtr sip, Int4Ptr position);
NLM_EXTERN void ReplaceCollidingUpdateIDs (ValNodePtr update_bioseq_list, ValNodePtr orig_bioseq_list);
NLM_EXTERN Boolean RelaxedSeqIdIn (SeqIdPtr sip, SeqIdPtr sip_list);
NLM_EXTERN void RemoveSequencesWithoutUpdates (ValNodePtr PNTR orig_bioseq_list, ValNodePtr PNTR update_bioseq_list);
extern CharPtr kSubmitterUpdateText;

NLM_EXTERN SeqLocPtr MakeGeneLocForFeatureLoc (SeqLocPtr floc, Uint2 entityID, Boolean trans_spliced);

typedef struct lclidlist {
  BioseqPtr  firstbsp;
  SeqIdPtr   firstsip;
  CharPtr    key;
  Int2       count;
  struct lclidlist PNTR left;
  struct lclidlist PNTR right;
} LclIdList, PNTR LclIdListPtr;

NLM_EXTERN void ResolveExistingIDsCallback (SeqEntryPtr sep, Pointer mydata, Int4 index, Int2 indent);
NLM_EXTERN void FreeLclTree (LclIdListPtr PNTR head);
NLM_EXTERN Boolean HasAlignmentsWithLocalIDs (SeqEntryPtr sep);
NLM_EXTERN Boolean DoesStringContainPhrase (CharPtr str, CharPtr phrase, Boolean case_sensitive, Boolean whole_word);

NLM_EXTERN Int4 UpdateReplacedECNumbers (SeqEntryPtr sep);
NLM_EXTERN Int4 UpdateReplacedECNumbersEx (SeqEntryPtr sep, ValNodePtr PNTR head, ValNodePtr PNTR tail, Boolean only_unambig, Boolean justwarn);
NLM_EXTERN Int4 DeleteBadECNumbers (SeqEntryPtr sep);
NLM_EXTERN Int4 DeleteBadECNumbersEx (SeqEntryPtr sep, ValNodePtr PNTR head, ValNodePtr PNTR tail, Boolean justwarn);

NLM_EXTERN void SegregateSetsByPlantGroup (SeqEntryPtr sep);
NLM_EXTERN void SegregateSetsByFungusGroup (SeqEntryPtr sep);
NLM_EXTERN ValNodePtr PrepareSequenceListForSegregateByBioseqList (SeqEntryPtr sep, ValNodePtr bsp_list);
NLM_EXTERN void SegregateSetsByBioseqList (SeqEntryPtr sep, ValNodePtr vnp);
NLM_EXTERN Boolean SeqEntryHasPairwiseAlignments (SeqEntryPtr sep);
NLM_EXTERN int LIBCALLBACK SortVnpByChoiceAndPtrvalue (VoidPtr ptr1, VoidPtr ptr2);
NLM_EXTERN int CompareSequences (BioseqPtr bsp1, BioseqPtr bsp2, Boolean allow_Ndiff);

NLM_EXTERN Int2 GetGenCodeForBsp (BioseqPtr bsp);

/* for unverified user objects */
typedef enum unverifiedtype {
  eUnverifiedType_Organism  = 0,
  eUnverifiedType_Features ,
  eUnverifiedType_Misassembled ,
  eUnverifiedType_Max
} UnverifiedMatchType;
NLM_EXTERN CharPtr GetUnverifiedMatchName (Int4 unverified_type);

NLM_EXTERN CharPtr GetRepliconChromosomeName (BioSourcePtr biop);
NLM_EXTERN CharPtr GetRepliconType (BioSourcePtr biop);
NLM_EXTERN CharPtr GetRepliconLocation (BioSourcePtr biop);

NLM_EXTERN PubPtr ParsePubFromEndnote (FILE *fp);
NLM_EXTERN CharPtr GetDefinitionLineFASTAModifiers (BioseqPtr bsp, Boolean include_subsource);
NLM_EXTERN CharPtr GetDefinitionLineFASTAModifiersByList (BioseqPtr bsp, ValNodePtr list);

/* for finding frameshifts */
typedef enum {
  eFrameShiftReport_NoReport = 0,
  eFrameShiftReport_Intron = 1,
  eFrameShiftReport_Exon = 2,
  eFrameShiftReport_ExonMult3 = 3
} EFrameShiftReport;

typedef struct frameshiftreport {
  CharPtr msg;
  Int4    aln_pos;
  Int4    first_related_seq;
} FrameShiftReportData, PNTR FrameShiftReportPtr;

NLM_EXTERN ValNodePtr FrameShiftReportListFree (ValNodePtr vnp);
NLM_EXTERN void PrintFrameShiftReportList (ValNodePtr list, Boolean has_exons, Boolean print_exons_only, LogInfoPtr lip);
NLM_EXTERN ValNodePtr FindFrameShiftsInAlignment (SeqAlignPtr salp, BoolPtr has_exons);
NLM_EXTERN Boolean PropagateMissingOldNames (ValNodePtr sep_list);
NLM_EXTERN CharPtr DescribeBioSourceDifferences (BioSourcePtr biop1, BioSourcePtr biop2);
NLM_EXTERN CharPtr DescribeStructuredCommentDifferences (UserObjectPtr uop1, UserObjectPtr uop2);
NLM_EXTERN Boolean RemoveDuplicateStructuredCommentsInSeqEntry (SeqEntryPtr sep);
NLM_EXTERN ValNodePtr GetSUCCommonList (SeqEntryPtr sep, Boolean reverse, Boolean byblock, Boolean showsequence, Boolean byqual);

NLM_EXTERN ValNodePtr LookupArticlesWithEutils (ValNodePtr orig_pub, LogInfoPtr lip);
NLM_EXTERN Int4 LookupPubsInSeqEntry (SeqEntryPtr sep, LogInfoPtr lip);

NLM_EXTERN void LogTrimmedLocation (LogInfoPtr lip, SeqLocPtr slp);

NLM_EXTERN void AddListOutputTags(ValNodePtr discrepancy_list, DiscReportOutputConfigPtr oc);
NLM_EXTERN Boolean IsMrnaSequence (BioseqPtr bsp);
NLM_EXTERN BioseqPtr BioseqFromAlignmentID (CharPtr PNTR id_str);

NLM_EXTERN Int4 TrimNsFromNucsInSeqEntry (SeqEntryPtr sep, LogInfoPtr lip);
NLM_EXTERN void CorrectGenCodes (SeqEntryPtr sep, Uint2 entityID);
NLM_EXTERN int CompareUserFields (UserFieldPtr ufp1, UserFieldPtr ufp2);

NLM_EXTERN void RemoveEmptyStructuredComments (Uint2 entityID);

NLM_EXTERN Boolean IsStructuredCommentPrefix (UserFieldPtr ufp);
NLM_EXTERN Boolean IsStructuredCommentSuffix (UserFieldPtr ufp);
NLM_EXTERN CharPtr GetStructuredCommentPrefix (UserObjectPtr uop);


typedef struct fielddiff {
  ValNodePtr field;
  CharPtr seq_id;
  CharPtr biosample_id;
  CharPtr val1;
  CharPtr val2;
  ValNodePtr src;
} FieldDiffData, PNTR FieldDiffPtr;

NLM_EXTERN FieldDiffPtr FieldDiffFree (FieldDiffPtr diff);
NLM_EXTERN ValNodePtr LIBCALL FieldDiffListFree (ValNodePtr list);
NLM_EXTERN ValNodePtr GetBioSourceFieldDiffs (CharPtr seq_id, CharPtr biosample_id, BioSourcePtr biop1, BioSourcePtr biop2, ValNodePtr field_list, Uint1 src_type, Pointer src_data);
NLM_EXTERN ValNodePtr GetStructuredCommentFieldDiffs (CharPtr seq_id, CharPtr biosample_id, UserObjectPtr uop1, UserObjectPtr uop2, ValNodePtr field_list, Uint1 src_type, Pointer src_data);
NLM_EXTERN int LIBCALLBACK SortVnpByFieldDiffField (VoidPtr ptr1, VoidPtr ptr2);
NLM_EXTERN int LIBCALLBACK SortVnpByFieldDiffBioIdThenField (VoidPtr ptr1, VoidPtr ptr2);
NLM_EXTERN int LIBCALLBACK SortVnpByFieldDiffBiosampleIdThenFieldThenVal (VoidPtr ptr1, VoidPtr ptr2);

NLM_EXTERN Boolean FindFlankingGenes (SeqLocPtr location, SeqFeatPtr PNTR firstP, SeqFeatPtr PNTR lastP);
NLM_EXTERN void AssignGeneXrefToFeat (SeqFeatPtr sfp, SeqFeatPtr gene);


/* for cleanup of BioSources */
NLM_EXTERN void ConsolidateBioSourceNotes (BioSourcePtr biop);
NLM_EXTERN void ConsolidateOneLikeOrganismModifier (OrgModPtr match_to, Boolean use_semicolon);
NLM_EXTERN void ConsolidateOneLikeSubSourceModifier (SubSourcePtr match_to, Boolean use_semicolon);

#define kAllowManualGenCodeException "genetic code exception"


NLM_EXTERN Boolean ReplaceStopsWithSelenocysteineInSeqEntry (SeqEntryPtr sep, FILE *log_fp);
NLM_EXTERN Boolean JoinShortTrnas (SeqEntryPtr sep, FILE *log_fp);

NLM_EXTERN Boolean IsDBLinkObject (UserObjectPtr uop);

typedef struct gaplocdata {
  Int4     start;
  Int4     length;
  CharPtr  estimated_length;
  CharPtr  gap_type;
  CharPtr  linkage_evidence;
  Boolean  unknown_length;
} GapLocData, PNTR GapLocPtr;


void PopulateGapLocQuals(GapLocPtr glp, SeqFeatPtr sfp, Int4 left, Int4 len);
GapLocPtr GapLocFromSeqFeat(SeqFeatPtr sfp, Int4 left);
Boolean IncompatibleGapFeatQuals (SeqFeatPtr sfp);
void BioseqToDeltaByGapFeat (BioseqPtr bsp, Pointer userdata);
void BioseqToDeltaMergeGapFeat (BioseqPtr bsp, Pointer userdata);
Boolean DeltaLitOnly (BioseqPtr bsp);
Boolean MergeAssemblyGapFeats (BioseqPtr bsp);

NLM_EXTERN Boolean IsRegulatorySubtype (Uint1 key);


#ifdef __cplusplus
}
#endif

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

#endif /* ndef _SQNUTILS_ */

