~ubuntu-branches/ubuntu/precise/ncbi-tools6/precise

« back to all changes in this revision

Viewing changes to desktop/cdrgn.c

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2005-03-27 12:00:15 UTC
  • mfrom: (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050327120015-embhesp32nj73p9r
Tags: 6.1.20041020-3
* Fix FTBFS under GCC 4.0 caused by inconsistent use of "static" on
  functions.  (Closes: #295110.)
* Add a watch file, now that we can.  (Upstream's layout needs version=3.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
*
30
30
* Version Creation Date:   1/22/95
31
31
*
32
 
* $Revision: 6.46 $
 
32
* $Revision: 6.67 $
33
33
*
34
34
* File Description: 
35
35
*
56
56
#include <toasn3.h>
57
57
#include <subutil.h>
58
58
#include <explore.h>
 
59
#include <pmfapi.h>
59
60
 
60
61
#define CODING_REGION_PAGE    0
61
62
#define GENE_PAGE             0
512
513
 
513
514
static SeqIdPtr  globalid;
514
515
 
 
516
static CodeBreakPtr RemoveNullLocationCodeBreaks (CodeBreakPtr cbp)
 
517
{
 
518
  CodeBreakPtr this_cbp, prev_cbp, next_cbp;
 
519
  
 
520
  prev_cbp = NULL;
 
521
  for (this_cbp = cbp; this_cbp != NULL; this_cbp = next_cbp)
 
522
  {
 
523
        next_cbp = this_cbp->next;
 
524
        if (this_cbp->loc == NULL)
 
525
        {
 
526
          Message (MSG_ERROR, "A code break was removed because the location is now invalid");
 
527
          if (prev_cbp == NULL)
 
528
          {
 
529
                cbp = this_cbp->next;
 
530
          }
 
531
          else
 
532
          {
 
533
                prev_cbp->next = this_cbp->next;
 
534
          }
 
535
          this_cbp->next = NULL;
 
536
          CodeBreakFree (this_cbp);
 
537
        }
 
538
  }
 
539
  return cbp;
 
540
}
 
541
 
515
542
static Pointer CdRgnPageToCdRegionPtr (DialoG d)
516
543
 
517
544
{
518
 
  BioseqPtr     bsp;
 
545
  BioseqPtr     bsp = NULL;
519
546
  CodeBreakPtr  cbp;
520
547
  CdRgnFormPtr  cfp;
521
548
  ValNodePtr    code;
580
607
        if (globalid != NULL) {
581
608
          cbp = DialogToPointer (cpp->cdBrk);
582
609
          ConvertToNTCodeBreak (cpp->cfp, crp, cbp);
 
610
          /* remove any code breaks that have fallen off the end of the protein */
 
611
          cbp = RemoveNullLocationCodeBreaks (cbp);
583
612
          crp->code_break = cbp;
584
613
        }
585
614
      }
1614
1643
          }
1615
1644
          bsp = BioseqNew ();
1616
1645
          if (bsp != NULL) {
 
1646
            bsp->id = SeqIdParse ("lcl|CdRgnTransl");
1617
1647
            bsp->repr = Seq_repr_raw;
1618
1648
            bsp->mol = Seq_mol_aa;
1619
1649
            bsp->seq_data_type = Seq_code_ncbieaa;
1924
1954
  }
1925
1955
}
1926
1956
 
 
1957
static Int4 AccessionToGi (CharPtr string)
 
1958
{
 
1959
   /*
 
1960
   CharPtr str;
 
1961
   LinkSetPtr lsp;
 
1962
   Int4 gi;
 
1963
 
 
1964
   str = MemNew (StringLen (string) + 10);
 
1965
   sprintf (str, "\"%s\" [ACCN]", string);
 
1966
   lsp = EntrezTLEvalString (str, TYP_NT, -1, NULL, NULL);
 
1967
   MemFree (str);
 
1968
   if (lsp == NULL) return 0;
 
1969
   if (lsp->num <= 0) {
 
1970
       LinkSetFree (lsp);
 
1971
       return 0;
 
1972
   }
 
1973
   gi = lsp->uids [0];
 
1974
   LinkSetFree (lsp);
 
1975
   return gi;
 
1976
   */
 
1977
   Int4      gi;
 
1978
   SeqIdPtr  sip;
 
1979
 
 
1980
   sip = SeqIdFromAccessionDotVersion (string);
 
1981
   if (sip == NULL) return 0;
 
1982
   gi = GetGIForSeqId (sip);
 
1983
   SeqIdFree (sip);
 
1984
   return gi;
 
1985
}
 
1986
 
 
1987
static void SetGeneAndProtFields (CdRgnFormPtr cfp, CharPtr title);
 
1988
 
 
1989
static BioseqPtr GetProteinFromSep (SeqEntryPtr sep)
 
1990
{
 
1991
  BioseqPtr query_bsp;
 
1992
 
 
1993
  query_bsp = NULL;
 
1994
  SeqEntryExplore(sep, &query_bsp, FindProt);
 
1995
  return query_bsp;
 
1996
}
 
1997
 
 
1998
typedef struct proteinimportformdata {
 
1999
  CdRgnFormPtr cfp;
 
2000
  WindoW       w;
 
2001
  TexT         accession;
 
2002
  GrouP        accntype;
 
2003
  ButtoN       DownloadProtein;
 
2004
} ProteinImportFormData, PNTR ProteinImportFormPtr;
 
2005
 
 
2006
static void AddProteinToCDSDialog (
 
2007
  BioseqPtr bsp,
 
2008
  CdRgnFormPtr  cfp
 
2009
)
 
2010
{
 
2011
  ValNodePtr vnp;
 
2012
  CharPtr    vnpstr;
 
2013
  SeqLocPtr  slp;
 
2014
  Char          str [128];
 
2015
 
 
2016
  PointerToDialog (cfp->protseq, bsp);
 
2017
  SetProteinLengthDisplay (cfp->protlen, bsp->length);
 
2018
  SeqIdWrite (bsp->id, str, PRINTID_REPORT, sizeof (str));
 
2019
  SafeSetTitle (cfp->protSeqIdTxt, str);
 
2020
  if (bsp->descr != NULL) {
 
2021
    vnp = ValNodeFindNext (bsp->descr, NULL, Seq_descr_title);
 
2022
    if (vnp != NULL && vnp->data.ptrvalue != NULL) {
 
2023
      vnpstr = (CharPtr) vnp->data.ptrvalue;
 
2024
      SetGeneAndProtFields (cfp, vnpstr);
 
2025
    }
 
2026
  }
 
2027
  slp = DialogToPointer (cfp->location);
 
2028
  if (slp == NULL || (! cfp->locvisited)) {
 
2029
    DoPredictCdRegion (cfp);
 
2030
  }
 
2031
  SeqLocFree (slp);
 
2032
}
 
2033
 
 
2034
static void DownloadProteinFromEntrez (ButtoN b)
 
2035
{
 
2036
  SeqEntryPtr   sep;
 
2037
  Int4          uid;
 
2038
  BioseqPtr     bsp;
 
2039
  CdRgnFormPtr  cfp;
 
2040
  Char          str [128];
 
2041
  ProteinImportFormPtr pif;
 
2042
 
 
2043
  pif = (ProteinImportFormPtr) GetObjectExtra (b);
 
2044
  if (pif == NULL) return; 
 
2045
  cfp = pif->cfp;
 
2046
  if (cfp == NULL) return;
 
2047
  GetTitle (pif->accession, str, sizeof (str));
 
2048
  if (StringHasNoText (str))
 
2049
  {
 
2050
    return;
 
2051
  }
 
2052
  WatchCursor ();
 
2053
  if (GetValue (pif->accntype) == 1) {
 
2054
    uid = AccessionToGi (str);
 
2055
  } else {
 
2056
    if (! StrToLong (str, &uid)) {
 
2057
     uid = 0;
 
2058
    }
 
2059
  }
 
2060
 
 
2061
  if (uid > 0) {
 
2062
    sep = PubSeqSynchronousQuery (uid, 0, -1);
 
2063
    if (sep == NULL) {
 
2064
      Message (MSG_OK, "Unable to find this record in the database.");
 
2065
      return;
 
2066
    }
 
2067
    if (IS_Bioseq (sep)) {
 
2068
    } else if (IS_Bioseq_set (sep)) {
 
2069
    } else {
 
2070
      Message (MSG_OK, "Unable to find this record in the database.");
 
2071
      return;
 
2072
    }
 
2073
  }
 
2074
  bsp = GetProteinFromSep (sep);
 
2075
  if (bsp == NULL)
 
2076
  {
 
2077
    Message (MSG_ERROR, "No protein in record!");
 
2078
  }
 
2079
  else
 
2080
  {
 
2081
    AddProteinToCDSDialog (bsp, cfp);
 
2082
  }
 
2083
  SeqEntryFree (sep);
 
2084
  Remove (pif->w);
 
2085
  ArrowCursor ();
 
2086
  Update ();
 
2087
}
 
2088
 
 
2089
static void FetchTextProc (TexT t)
 
2090
 
 
2091
{
 
2092
  Boolean       alldigits;
 
2093
  Char          ch;
 
2094
  ProteinImportFormPtr  pif;
 
2095
  CharPtr       ptr;
 
2096
  Char          str [32];
 
2097
 
 
2098
  pif = (ProteinImportFormPtr) GetObjectExtra (t);
 
2099
  if (pif == NULL) return;
 
2100
  GetTitle (t, str, sizeof (str));
 
2101
  if (StringHasNoText (str)) {
 
2102
    SafeDisable (pif->DownloadProtein);
 
2103
  } else {
 
2104
    SafeEnable (pif->DownloadProtein);
 
2105
    TrimSpacesAroundString (str);
 
2106
    alldigits = TRUE;
 
2107
    ptr = str;
 
2108
    ch = *ptr;
 
2109
    while (ch != '\0') {
 
2110
      if (! IS_DIGIT (ch)) {
 
2111
        alldigits = FALSE;
 
2112
      }
 
2113
      ptr++;
 
2114
      ch = *ptr;
 
2115
    }
 
2116
    if (alldigits) {
 
2117
      SafeSetValue (pif->accntype, 2);
 
2118
    } else {
 
2119
      SafeSetValue (pif->accntype, 1);
 
2120
    }
 
2121
  }
 
2122
}
 
2123
 
 
2124
static void LoadFASTAProteinFromFile (ButtoN b)
 
2125
{
 
2126
  CdRgnFormPtr  cfp;
 
2127
  CharPtr       extension;
 
2128
  FILE *        fp;
 
2129
  SeqEntryPtr   sep;
 
2130
  BioseqPtr     bsp;
 
2131
  Char          path [PATH_MAX];
 
2132
  ProteinImportFormPtr pif;
 
2133
 
 
2134
  pif = (ProteinImportFormPtr) GetObjectExtra (b);
 
2135
  if (pif == NULL) return; 
 
2136
  cfp = pif->cfp;
 
2137
  if (cfp == NULL) return;
 
2138
 
 
2139
  path [0] = 0;
 
2140
  extension = GetAppProperty ("FastaProtExtension");
 
2141
  if (GetInputFileName (path, sizeof (path), extension, "TEXT"))
 
2142
  {
 
2143
    fp = FileOpen (path, "r");
 
2144
    if (fp != NULL) {
 
2145
      sep = FastaToSeqEntry (fp, FALSE);
 
2146
      if (sep != NULL && sep->choice == 1 && sep->data.ptrvalue != NULL) {
 
2147
        bsp = (BioseqPtr) sep->data.ptrvalue;
 
2148
        AddProteinToCDSDialog (bsp, cfp);
 
2149
      }
 
2150
      SeqEntryFree (sep);
 
2151
    }
 
2152
    FileClose (fp);
 
2153
  }
 
2154
  Remove (pif->w);
 
2155
}
 
2156
 
 
2157
static void ShowImportProteinDialog ( CdRgnFormPtr  cfp)
 
2158
{
 
2159
  WindoW w;
 
2160
  GrouP  c, f, g, h;
 
2161
  ButtoN b;
 
2162
  ProteinImportFormPtr pif;
 
2163
 
 
2164
  pif = (ProteinImportFormPtr) MemNew ( sizeof (ProteinImportFormData));
 
2165
  if (pif == NULL) return;
 
2166
  pif->cfp = cfp;
 
2167
  w = FixedWindow (-50, -33, -10, -10, "Import Protein", StdCloseWindowProc);
 
2168
  pif->w = w;
 
2169
  SetObjectExtra (w, pif, NULL);
 
2170
 
 
2171
  h = HiddenGroup (w, -1, 0, NULL);
 
2172
  SetGroupSpacing (h, 10, 10);
 
2173
 
 
2174
  g = HiddenGroup (h, 4, 0, NULL);
 
2175
 
 
2176
  pif->accntype = HiddenGroup (g, 4, 0, NULL);
 
2177
  RadioButton (pif->accntype, "Accession");
 
2178
  RadioButton (pif->accntype, "GI");
 
2179
  SetValue (pif->accntype, 1);
 
2180
  pif->accession = DialogText (g, "", 6, FetchTextProc);
 
2181
  SetObjectExtra (pif->accession, pif, NULL);
 
2182
  pif->DownloadProtein = PushButton (g, "Download Protein From Entrez",
 
2183
                                     DownloadProteinFromEntrez);
 
2184
  SetObjectExtra (pif->DownloadProtein, pif, NULL);
 
2185
  Disable (pif->DownloadProtein);
 
2186
 
 
2187
  f = HiddenGroup (h, 4, 0, NULL);
 
2188
  b = PushButton (f, "Load FASTA Protein From File", LoadFASTAProteinFromFile);
 
2189
  SetObjectExtra (b, pif, NULL);
 
2190
 
 
2191
  c = HiddenGroup (w, 2, 0, NULL);
 
2192
  PushButton (c, "Cancel", StdCancelButtonProc);
 
2193
  AlignObjects (ALIGN_CENTER, (HANDLE) g, (HANDLE) f, (HANDLE) c, NULL);
 
2194
  RealizeWindow (w);
 
2195
  Show (w);
 
2196
  Update ();
 
2197
 
 
2198
}
 
2199
 
1927
2200
static DialoG CreateCdRgnDialog (GrouP h, CharPtr title, Int2 genCode,
1928
2201
                                 SeqFeatPtr sfp, CdRgnFormPtr cfp)
1929
2202
 
2001
2274
 
2002
2275
    x = HiddenGroup (g, -1, 0, NULL);
2003
2276
    f = HiddenGroup (x, 6, 0, NULL);
2004
 
    cfp->product = CreateProteinOrMRNAProductDialog (f, NULL, "Product", FALSE, cfp->sep, cfp, NULL, (BaseFormPtr) cfp);
 
2277
    cfp->product = CreateProteinOrMRNAProductDialog (f, NULL, "Protein Product", FALSE, cfp->sep, cfp, NULL, (BaseFormPtr) cfp);
2005
2278
    cfp->protSeqIdGrp = HiddenGroup (f, -2, 0, NULL);
2006
2279
    StaticPrompt (cfp->protSeqIdGrp, "SeqID", 0, dialogTextHeight, programFont, 'l');
2007
2280
    cfp->protSeqIdTxt = DialogText (cfp->protSeqIdGrp, "", 6, NULL);
2027
2300
    x = HiddenGroup (cfp->protTextGrp, 2, 0, NULL);
2028
2301
    SetGroupSpacing (x, 3, 5);
2029
2302
    StaticPrompt (x, "Name", 0, dialogTextHeight, programFont, 'l');
2030
 
    cfp->protNameText = DialogText (x, "", 15, NULL);
 
2303
    cfp->protNameText = DialogText (x, "", 25, NULL);
2031
2304
    StaticPrompt (x, "Description", 0, dialogTextHeight, programFont, 'l');
2032
 
    cfp->protDescText = DialogText (x, "", 15, NULL);
 
2305
    cfp->protDescText = DialogText (x, "", 25, NULL);
2033
2306
    cfp->protPromptGrp = HiddenGroup (f, -1, 0, NULL);
2034
2307
    StaticPrompt (cfp->protPromptGrp,
2035
2308
                  "Press Edit Protein Feature to change protein name",
2233
2506
    }
2234
2507
  }
2235
2508
}
2236
 
 
2237
2509
static Boolean ImportCdRgnForm (ForM f, CharPtr filename)
2238
2510
 
2239
2511
{
2240
 
  BioseqPtr     bsp;
2241
2512
  CdRgnFormPtr  cfp;
2242
 
  CharPtr       extension;
2243
 
  FILE          *fp;
2244
2513
  Char          path [PATH_MAX];
2245
 
  SeqEntryPtr   sep;
2246
 
  SeqLocPtr     slp;
2247
 
  Char          str [128];
2248
 
  ValNodePtr    vnp;
2249
 
  CharPtr       vnpstr;
2250
2514
 
2251
2515
  path [0] = '\0';
2252
2516
  StringNCpy_0 (path, filename, sizeof (path));
2254
2518
  if (cfp != NULL) {
2255
2519
    switch (cfp->currentPage) {
2256
2520
      case CODING_REGION_PAGE :
2257
 
        extension = GetAppProperty ("FastaProtExtension");
2258
 
        if (path [0] != '\0' || GetInputFileName (path, sizeof (path), extension, "TEXT")) {
2259
 
          fp = FileOpen (path, "r");
2260
 
          if (fp != NULL) {
2261
 
            sep = FastaToSeqEntry (fp, FALSE);
2262
 
            if (sep != NULL && sep->choice == 1 && sep->data.ptrvalue != NULL) {
2263
 
              bsp = (BioseqPtr) sep->data.ptrvalue;
2264
 
              PointerToDialog (cfp->protseq, bsp);
2265
 
              SetProteinLengthDisplay (cfp->protlen, bsp->length);
2266
 
              SeqIdWrite (bsp->id, str, PRINTID_REPORT, sizeof (str));
2267
 
              SafeSetTitle (cfp->protSeqIdTxt, str);
2268
 
              if (bsp->descr != NULL) {
2269
 
                vnp = ValNodeFindNext (bsp->descr, NULL, Seq_descr_title);
2270
 
                if (vnp != NULL && vnp->data.ptrvalue != NULL) {
2271
 
                  vnpstr = (CharPtr) vnp->data.ptrvalue;
2272
 
                  SetGeneAndProtFields (cfp, vnpstr);
2273
 
                }
2274
 
              }
2275
 
              slp = DialogToPointer (cfp->location);
2276
 
              if (slp == NULL || (! cfp->locvisited)) {
2277
 
                DoPredictCdRegion (cfp);
2278
 
              }
2279
 
              SeqLocFree (slp);
2280
 
            }
2281
 
            SeqEntryFree (sep);
2282
 
          }
2283
 
          FileClose (fp);
2284
 
        }
 
2521
        ShowImportProteinDialog ( cfp);
2285
2522
        break;
2286
2523
      case COMMON_PAGE :
2287
2524
        break;
2409
2646
and to remove any protein product attached to the CDS.\n\
2410
2647
Are you sure you want to trigger this conversion now?";
2411
2648
 
 
2649
static void SetComment (CharPtr new_comment, WindoW w)
 
2650
{
 
2651
  FeatureFormPtr ffp;
 
2652
  
 
2653
  if (new_comment == NULL || w == NULL) return;
 
2654
  ffp = (FeatureFormPtr) GetObjectExtra (w);
 
2655
  if (ffp == NULL) return;
 
2656
 
 
2657
  SafeSetTitle (ffp->comment, new_comment);
 
2658
}
 
2659
 
2412
2660
static void CdRgnFormAcceptButtonProc (ButtoN b)
2413
2661
 
2414
2662
{
2425
2673
  SeqLocPtr      slp;
2426
2674
  Char           str [128];
2427
2675
  WindoW         w;
 
2676
  SeqLocPtr      prod_slp;
 
2677
  Boolean        delete_old_product = FALSE;
2428
2678
 
2429
2679
  if (b != NULL) {
2430
2680
    w = ParentWindow (b);
2490
2740
      if (cfp->autoRetranslate) {
2491
2741
        DoTranslateProtein (cfp);
2492
2742
      }
 
2743
      
2493
2744
      pseudo = FALSE;
2494
 
      qual = (GBQualPtr) DialogToPointer (cfp->gbquals);
2495
 
      gbq = qual;
2496
 
      while (gbq != NULL) {
2497
 
        if (StringICmp (gbq->qual, "pseudo") == 0) {
2498
 
          pseudo = TRUE;
2499
 
        }
2500
 
        gbq = gbq->next;
2501
 
      }
2502
 
      GBQualFree (qual);
2503
 
      bsp = (BioseqPtr) DialogToPointer (cfp->protseq);
2504
 
      if (bsp == NULL) {
2505
 
        if (! pseudo) {
 
2745
      if (GetStatus (cfp->pseudo))
 
2746
      {
 
2747
        pseudo = TRUE;
 
2748
      }
 
2749
      else
 
2750
      {
 
2751
        qual = (GBQualPtr) DialogToPointer (cfp->gbquals);
 
2752
        gbq = qual;
 
2753
        while (gbq != NULL) {
 
2754
          if (StringICmp (gbq->qual, "pseudo") == 0) {
 
2755
            pseudo = TRUE;
 
2756
          }
 
2757
          gbq = gbq->next;
 
2758
        }
 
2759
        GBQualFree (qual);
 
2760
      }
 
2761
      
 
2762
      if (pseudo)
 
2763
      {
 
2764
        /* remove old product, if there is one */
 
2765
        prod_slp = DialogToPointer (cfp->product);
 
2766
        if (prod_slp != NULL)
 
2767
        {
 
2768
          bsp = BioseqFind (SeqLocId (prod_slp));
 
2769
          if (bsp != NULL) {
 
2770
            bsp->idx.deleteme = TRUE;
 
2771
            delete_old_product = TRUE;
 
2772
          }
 
2773
          prod_slp = SeqLocFree (prod_slp);
 
2774
        }
 
2775
        /* do not create new product */
 
2776
        PointerToDialog (cfp->product, NULL);
 
2777
        PointerToDialog (cfp->protseq, NULL);
 
2778
        
 
2779
        /* if the protein name is set, move it to a note */
 
2780
        GetTitle (cfp->protNameText, str, sizeof (str) - 1);
 
2781
        if (! StringHasNoText (str))
 
2782
        {
 
2783
          SetComment (str, w);
 
2784
          SetTitle (cfp->protNameText, "");
 
2785
        }
 
2786
      }
 
2787
      else
 
2788
      {
 
2789
        bsp = (BioseqPtr) DialogToPointer (cfp->protseq);
 
2790
        if (bsp == NULL) 
 
2791
        {
2506
2792
          ans = Message (MSG_OKC, "The coding region has no peptide sequence.  Are you sure?");
 
2793
          if (ans != ANS_OK)
 
2794
          {
 
2795
            SeqLocFree (slp);
 
2796
            return;
 
2797
          }
2507
2798
        }
2508
 
      } else if (pseudo) {
2509
 
        /* ask about deleting the product bioseq? */
2510
 
      }
2511
 
      BioseqFree (bsp);
2512
 
      if (ans == ANS_OK) {
 
2799
        bsp = BioseqFree (bsp);
2513
2800
        Hide (w);
2514
2801
        Update ();
2515
2802
        if (Visible (cfp->protSeqIdGrp)) {
2530
2817
            cfp->protXrefName = cfp->protNameText;
2531
2818
          }
2532
2819
        }
2533
 
        (cfp->actproc) (cfp->form);
2534
 
        SeqLocFree (slp);
2535
 
      } else {
2536
 
        SeqLocFree (slp);
2537
 
        return;
2538
2820
      }
2539
 
    }
 
2821
      (cfp->actproc) (cfp->form);
 
2822
    }
 
2823
    SeqLocFree (slp);
 
2824
    if (delete_old_product)
 
2825
    {
 
2826
      DeleteMarkedObjects (cfp->input_entityID, 0, NULL);
 
2827
      sep = GetBestTopParentForItemID (cfp->input_entityID,
 
2828
                                       cfp->input_itemID,
 
2829
                                       cfp->input_itemtype);
 
2830
      RenormalizeNucProtSets (sep, TRUE);
 
2831
      ObjMgrSendMsg (OM_MSG_UPDATE, cfp->input_entityID,
 
2832
                       cfp->input_itemID, cfp->input_itemtype);
 
2833
      ObjMgrDeSelect (0, 0, 0, 0, NULL);
 
2834
    }
 
2835
    
2540
2836
    Update ();
2541
2837
    Remove (w);
2542
2838
  }
2632
2928
                                                  StdFeatIntEdPartialCallback);
2633
2929
    cfp->pages [LOCATION_PAGE] = s;
2634
2930
    Hide (cfp->pages [LOCATION_PAGE]);
2635
 
    cfp->locvisited = FALSE;
 
2931
    cfp->locvisited = TRUE;
2636
2932
 
2637
2933
    AlignObjects (ALIGN_CENTER, (HANDLE) cfp->pages [CODING_REGION_PAGE],
2638
2934
                  (HANDLE) cfp->pages [COMMON_PAGE],
3193
3489
  TexT          allele;
3194
3490
  TexT          desc;
3195
3491
  TexT          maploc;
 
3492
  TexT          locus_tag;
3196
3493
  ButtoN        pseudo;
3197
3494
  DialoG        db;
3198
3495
  DialoG        syn;
3221
3518
      SafeSetTitle (gpp->allele, grp->allele);
3222
3519
      SafeSetTitle (gpp->desc, grp->desc);
3223
3520
      SafeSetTitle (gpp->maploc, grp->maploc);
 
3521
      SafeSetTitle (gpp->locus_tag, grp->locus_tag);
3224
3522
      SafeSetStatus (gpp->pseudo, grp->pseudo);
3225
3523
      PointerToDialog (gpp->db, grp->db);
3226
3524
      PointerToDialog (gpp->syn, grp->syn);
3229
3527
      SafeSetTitle (gpp->allele, "");
3230
3528
      SafeSetTitle (gpp->desc, "");
3231
3529
      SafeSetTitle (gpp->maploc, "");
 
3530
      SafeSetTitle (gpp->locus_tag, "");
3232
3531
      SafeSetStatus (gpp->pseudo, FALSE);
3233
3532
      PointerToDialog (gpp->db, NULL);
3234
3533
      PointerToDialog (gpp->syn, NULL);
3251
3550
      grp->allele = SaveStringFromText (gpp->allele);
3252
3551
      grp->desc = SaveStringFromText (gpp->desc);
3253
3552
      grp->maploc = SaveStringFromText (gpp->maploc);
 
3553
      grp->locus_tag = SaveStringFromText (gpp->locus_tag);
3254
3554
      grp->pseudo = GetStatus (gpp->pseudo);
3255
3555
      grp->db = DialogToPointer (gpp->db);
3256
3556
      grp->syn = DialogToPointer (gpp->syn);
3346
3646
    gpp->desc = DialogText (f, "", 15, NULL);
3347
3647
    StaticPrompt (f, "Map Location", 0, dialogTextHeight, programFont, 'l');
3348
3648
    gpp->maploc = DialogText (f, "", 15, NULL);
 
3649
    StaticPrompt (f, "Locus Tag", 0, dialogTextHeight, programFont, 'l');
 
3650
    gpp->locus_tag = DialogText (f, "", 15, NULL);
3349
3651
 
3350
3652
    gpp->pseudo = CheckBox (gpp->geneGrp [0], "PseudoGene", NULL);
3351
3653
    AlignObjects (ALIGN_CENTER, (HANDLE) f, (HANDLE) gpp->pseudo, NULL);
3915
4217
  }
3916
4218
}
3917
4219
 
3918
 
static DialoG CreateProtDialog (GrouP h, CharPtr title, ProtRefPtr prp)
 
4220
static void ChangeProtProcessed (PopuP p)
 
4221
 
 
4222
{
 
4223
  ProtFormPtr  pfp;
 
4224
  Int2         val;
 
4225
 
 
4226
  pfp = (ProtFormPtr) GetObjectExtra (p);
 
4227
  if (pfp == NULL) return;
 
4228
  val = GetValue (p);
 
4229
  switch (val) {
 
4230
    case 1 :
 
4231
      SafeHide (pfp->product);
 
4232
      break;
 
4233
    case 2 :
 
4234
    case 3 :
 
4235
    case 4 :
 
4236
    case 5 :
 
4237
      SafeShow (pfp->product);
 
4238
      break;
 
4239
    default :
 
4240
      break;
 
4241
  }
 
4242
}
 
4243
 
 
4244
static DialoG CreateProtDialog (GrouP h, CharPtr title, ProtRefPtr prp, SeqFeatPtr sfp, ProtFormPtr pfp)
3919
4245
 
3920
4246
{
3921
4247
  GrouP        f;
3971
4297
    ppp->protGrp [0] = HiddenGroup (k, -1, 0, NULL);
3972
4298
    g = HiddenGroup (ppp->protGrp [0], 0, 10, NULL);
3973
4299
    StaticPrompt (g, "Protein Names", 0, 0, programFont, 'c');
3974
 
    ppp->name = CreateVisibleStringDialog (g, 3, -1, 15);
 
4300
    ppp->name = CreateVisibleStringDialog (g, 3, -1, 25);
3975
4301
 
3976
4302
    f = HiddenGroup (ppp->protGrp [0], 0, 4, NULL);
3977
4303
    StaticPrompt (f, "Description", 0, dialogTextHeight, programFont, 'c');
3978
 
    ppp->desc = DialogText (f, "", 20, NULL);
 
4304
    ppp->desc = DialogText (f, "", 25, NULL);
3979
4305
 
3980
4306
    r = HiddenGroup (ppp->protGrp [0], 2, 0, NULL);
3981
4307
    StaticPrompt (r, "Processing", 0, dialogTextHeight, programFont, 'l');
3982
 
    ppp->processed = PopupList (r, TRUE, NULL);
 
4308
    ppp->processed = PopupList (r, TRUE, ChangeProtProcessed);
 
4309
    SetObjectExtra (ppp->processed, (Pointer) pfp, NULL);
3983
4310
    PopupItem (ppp->processed, " ");
3984
4311
    PopupItem (ppp->processed, "Proprotein");
3985
4312
    PopupItem (ppp->processed, "Mature");
3987
4314
    PopupItem (ppp->processed, "Transit peptide");
3988
4315
    SetValue (ppp->processed, 1);
3989
4316
 
 
4317
    pfp->product = CreateProteinOrMRNAProductDialog (ppp->protGrp [0], NULL, "Processing Product", FALSE,
 
4318
                                                     pfp->sep, NULL, NULL, (BaseFormPtr) pfp);
 
4319
    if (sfp == NULL || sfp->product == NULL) {
 
4320
      if (prp == NULL || prp->processed < 2) {
 
4321
        SafeHide (pfp->product);
 
4322
      }
 
4323
    }
 
4324
 
3990
4325
    ppp->protGrp [1] = HiddenGroup (k, 0, 10, NULL);
3991
4326
    StaticPrompt (ppp->protGrp [1], "Enzyme Commission Number", 0, 0, programFont, 'c');
3992
4327
    ppp->ec = CreateVisibleStringDialog (ppp->protGrp [1], 3, -1, 15);
3994
4329
 
3995
4330
    ppp->protGrp [2] = HiddenGroup (k, 0, 10, NULL);
3996
4331
    StaticPrompt (ppp->protGrp [2], "Activity", 0, 0, programFont, 'c');
3997
 
    ppp->activity = CreateVisibleStringDialog (ppp->protGrp [2], 3, -1, 15);
 
4332
    ppp->activity = CreateVisibleStringDialog (ppp->protGrp [2], 3, -1, 25);
3998
4333
    Hide (ppp->protGrp [2]);
3999
4334
 
4000
4335
    ppp->protGrp [3] = HiddenGroup (k, -1, 0, NULL);
4180
4515
  }
4181
4516
}
4182
4517
 
 
4518
static void ProtRefPtrToForm (ForM f, Pointer data)
 
4519
 
 
4520
{
 
4521
  SeqEntryPtr  oldsep;
 
4522
  ProtFormPtr  pfp;
 
4523
  SeqEntryPtr  sep;
 
4524
  SeqFeatPtr   sfp;
 
4525
  Int4         val;
 
4526
 
 
4527
  pfp = (ProtFormPtr) GetObjectExtra (f);
 
4528
  if (pfp != NULL) {
 
4529
    sep = GetTopSeqEntryForEntityID (pfp->input_entityID);
 
4530
    oldsep = SeqEntrySetScope (sep);
 
4531
    sfp = (SeqFeatPtr) data;
 
4532
    if (sfp != NULL) {
 
4533
      switch (sfp->data.choice) {
 
4534
        case SEQFEAT_BOND :
 
4535
        case SEQFEAT_SITE :
 
4536
        case SEQFEAT_PSEC_STR :
 
4537
          val = (Int4) sfp->data.value.intvalue;
 
4538
          PointerToDialog (pfp->data, (Pointer) &(val));
 
4539
          break;
 
4540
        case SEQFEAT_COMMENT:
 
4541
          break;
 
4542
        default :
 
4543
          PointerToDialog (pfp->data, sfp->data.value.ptrvalue);
 
4544
          break;
 
4545
      }
 
4546
      SeqFeatPtrToCommon ((FeatureFormPtr) pfp, sfp);
 
4547
      PointerToDialog (pfp->location, sfp->location);
 
4548
      PointerToDialog (pfp->product, sfp->product);
 
4549
    }
 
4550
    SeqEntrySetScope (oldsep);
 
4551
  }
 
4552
}
 
4553
 
4183
4554
extern ForM CreateProtForm (Int2 left, Int2 top, CharPtr title,
4184
4555
                            SeqFeatPtr sfp, SeqEntryPtr sep,
4185
4556
                            FormActnFunc actproc)
4202
4573
    SetObjectExtra (w, pfp, StdFeatFormCleanupProc);
4203
4574
    pfp->form = (ForM) w;
4204
4575
    pfp->actproc = actproc;
4205
 
    pfp->toform = StdSeqFeatPtrToFeatFormProc;
 
4576
    pfp->toform = ProtRefPtrToForm;
4206
4577
    pfp->fromform = NULL;
4207
4578
    pfp->formmessage = ProtFormMessage;
4208
4579
    pfp->testform = NULL;
4237
4608
    if (sfp != NULL && sfp->data.choice == SEQFEAT_PROT) {
4238
4609
      prp = sfp->data.value.ptrvalue;
4239
4610
    }
4240
 
    pfp->data = CreateProtDialog (s, NULL, prp);
 
4611
    pfp->data = CreateProtDialog (s, NULL, prp, sfp, pfp);
4241
4612
    pfp->pages [PROT_PAGE] = s;
4242
4613
    Hide (pfp->pages [PROT_PAGE]);
4243
4614
 
4244
4615
    s = HiddenGroup (h, -1, 0, NULL);
4245
 
    CreateCommonFeatureGroupEx (s, (FeatureFormPtr) pfp, sfp, FALSE, TRUE, TRUE);
 
4616
    CreateCommonFeatureGroupEx (s, (FeatureFormPtr) pfp, sfp, /* FALSE */ TRUE, TRUE, TRUE);
4246
4617
    pfp->pages [COMMON_PAGE] = s;
4247
4618
    Hide (pfp->pages [COMMON_PAGE]);
4248
4619
 
4412
4783
  {"snRNA",        5},
4413
4784
  {"scRNA",        6},
4414
4785
  {"snoRNA",       7},
4415
 
  {"Other RNA",  255},
 
4786
  {"misc_RNA",   255},
4416
4787
END_ENUM_ALIST
4417
4788
 
4418
4789
static Uint1 check_rna_type (Uint1 type)
4534
4905
 
4535
4906
  rpp = (RnaPagePtr) GetObjectExtra (d);
4536
4907
  rrp = (RnaRefPtr) data;
 
4908
 
4537
4909
  if (rpp != NULL) {
4538
4910
    SetEnumPopup (rpp->type, rna_type_alist,
4539
4911
                  (UIEnum) check_rna_type (rrp->type));
4590
4962
                shift = 2;
4591
4963
              } else {
4592
4964
                shift = 1;
4593
 
              } 
4594
 
              i = aa - (64 + shift);
 
4965
              }
 
4966
              if (aa != '*') {
 
4967
                i = aa - (64 + shift);
 
4968
              } else {
 
4969
                i = 25;
 
4970
              }
4595
4971
              SetValue (rpp->AAitem, (Int2) i + 1);
4596
4972
            }
4597
4973
            head = NULL;
4598
4974
            for (j = 0; j < 6; j++) {
4599
4975
              if (trna->codon [j] < 64) {
 
4976
                                /* Note - it is important to set the fourth character in the codon array to NULL
 
4977
                                 * because CodonForIndex only fills in the three characters of actual codon,
 
4978
                                 * so if you StringCpy the codon array and the NULL character is not found after
 
4979
                                 * the three codon characters, you will write in memory you did not intend to.
 
4980
                                 */
 
4981
                                codon [3] = 0;
4600
4982
                if (CodonForIndex (trna->codon [j], Seq_code_iupacna, codon)) {
4601
4983
                  StringCpy (str, (CharPtr) codon);
4602
4984
                  str [3] = '\0';
4614
4996
              PointerToDialog (rpp->codons, head);
4615
4997
              ValNodeFreeData (head);
4616
4998
            }
4617
 
            PointerToDialog (rpp->anticodon, trna->anticodon);
 
4999
            if (trna->anticodon == NULL)
 
5000
            {
 
5001
              /* attempt to provide default location */
 
5002
              SeqLocPtr tmp_loc = NULL;
 
5003
              tmp_loc = DialogToPointer (rpp->rfp->location);
 
5004
              PointerToDialog (rpp->anticodon, tmp_loc);
 
5005
              SetSequenceAndStrandForIntervalPage (rpp->anticodon);
 
5006
              SeqLocFree (tmp_loc);              
 
5007
            }
 
5008
            else
 
5009
            {
 
5010
              PointerToDialog (rpp->anticodon, trna->anticodon);                
 
5011
            }
4618
5012
          }
4619
5013
        }
4620
5014
        SafeShow (rpp->trnaGrp);
4710
5104
                shift = 1;
4711
5105
              } 
4712
5106
              trna->aa = (Uint1) i + 64 + shift;
 
5107
              if (trna->aa == 91) {
 
5108
                trna->aa = (Uint1) '*';
 
5109
              }
4713
5110
            }
4714
5111
            for (j = 0; j < 6; j++) {
4715
5112
              trna->codon [j] = 255;
4839
5236
          SafeHide (rpp->rrnaPrompt);
4840
5237
          SafeHide (rpp->ornaPrompt);
4841
5238
          SafeShow (rpp->trnaGrp);
4842
 
          SafeHide (rfp->product);
 
5239
          SafeShow (rfp->product);
4843
5240
          SafeHide (rfp->usrobjext);
4844
5241
          break;
4845
5242
        case 4 :
4847
5244
          SafeHide (rpp->ornaPrompt);
4848
5245
          SafeShow (rpp->rrnaPrompt);
4849
5246
          SafeShow (rpp->nameGrp);
4850
 
          SafeHide (rfp->product);
 
5247
          SafeShow (rfp->product);
 
5248
          SafeHide (rfp->usrobjext);
 
5249
          break;
 
5250
        case 5 :
 
5251
          SafeHide (rpp->trnaGrp);
 
5252
          SafeHide (rpp->rrnaPrompt);
 
5253
          SafeHide (rpp->ornaPrompt);
 
5254
          SafeShow (rpp->nameGrp);
 
5255
          SafeShow (rfp->product);
 
5256
          SafeHide (rfp->usrobjext);
 
5257
          break;
 
5258
        case 6 :
 
5259
          SafeHide (rpp->trnaGrp);
 
5260
          SafeHide (rpp->rrnaPrompt);
 
5261
          SafeHide (rpp->ornaPrompt);
 
5262
          SafeShow (rpp->nameGrp);
 
5263
          SafeShow (rfp->product);
 
5264
          SafeHide (rfp->usrobjext);
 
5265
          break;
 
5266
        case 7 :
 
5267
          SafeHide (rpp->trnaGrp);
 
5268
          SafeHide (rpp->rrnaPrompt);
 
5269
          SafeHide (rpp->ornaPrompt);
 
5270
          SafeShow (rpp->nameGrp);
 
5271
          SafeShow (rfp->product);
4851
5272
          SafeHide (rfp->usrobjext);
4852
5273
          break;
4853
5274
        case 255 :
4855
5276
          SafeHide (rpp->rrnaPrompt);
4856
5277
          SafeShow (rpp->ornaPrompt);
4857
5278
          SafeShow (rpp->nameGrp);
4858
 
          SafeHide (rfp->product);
 
5279
          SafeShow (rfp->product);
4859
5280
          SafeHide (rfp->usrobjext);
4860
5281
          break;
4861
5282
        default :
4896
5317
    str = (CharPtr) GetNameForResidue (sctp, i);
4897
5318
    sprintf (item, "%c    %s", ch, str);
4898
5319
    PopupItem (AAitem, item);
4899
 
  } 
 
5320
  }
4900
5321
  SetValue (AAitem, 1); 
4901
5322
}
4902
5323
 
5057
5478
        SafeHide (rpp->rrnaPrompt);
5058
5479
        SafeHide (rpp->ornaPrompt);
5059
5480
        SafeShow (rpp->trnaGrp);
5060
 
        SafeHide (rfp->product);
 
5481
        SafeShow (rfp->product);
5061
5482
        SafeHide (rfp->usrobjext);
5062
5483
        break;
5063
5484
      case FEATDEF_rRNA :
5065
5486
        SafeHide (rpp->ornaPrompt);
5066
5487
        SafeShow (rpp->rrnaPrompt);
5067
5488
        SafeShow (rpp->nameGrp);
5068
 
        SafeHide (rfp->product);
 
5489
        SafeShow (rfp->product);
 
5490
        SafeHide (rfp->usrobjext);
 
5491
        break;
 
5492
      case FEATDEF_snRNA :
 
5493
        SafeHide (rpp->trnaGrp);
 
5494
        SafeHide (rpp->ornaPrompt);
 
5495
        SafeHide (rpp->rrnaPrompt);
 
5496
        SafeShow (rpp->nameGrp);
 
5497
        SafeShow (rfp->product);
 
5498
        SafeHide (rfp->usrobjext);
 
5499
        break;
 
5500
      case FEATDEF_scRNA :
 
5501
        SafeHide (rpp->trnaGrp);
 
5502
        SafeHide (rpp->ornaPrompt);
 
5503
        SafeHide (rpp->rrnaPrompt);
 
5504
        SafeShow (rpp->nameGrp);
 
5505
        SafeShow (rfp->product);
 
5506
        SafeHide (rfp->usrobjext);
 
5507
        break;
 
5508
      case FEATDEF_snoRNA :
 
5509
        SafeHide (rpp->trnaGrp);
 
5510
        SafeHide (rpp->ornaPrompt);
 
5511
        SafeHide (rpp->rrnaPrompt);
 
5512
        SafeShow (rpp->nameGrp);
 
5513
        SafeShow (rfp->product);
5069
5514
        SafeHide (rfp->usrobjext);
5070
5515
        break;
5071
5516
      case FEATDEF_otherRNA :
5073
5518
        SafeHide (rpp->rrnaPrompt);
5074
5519
        SafeShow (rpp->ornaPrompt);
5075
5520
        SafeShow (rpp->nameGrp);
5076
 
        SafeHide (rfp->product);
 
5521
        SafeShow (rfp->product);
5077
5522
        SafeHide (rfp->usrobjext);
5078
5523
        break;
5079
5524
      default :
5298
5743
    oldsep = SeqEntrySetScope (sep);
5299
5744
    sfp = (SeqFeatPtr) data;
5300
5745
    if (sfp != NULL) {
 
5746
      PointerToDialog (rfp->location, sfp->location);
5301
5747
      switch (sfp->data.choice) {
5302
5748
        case SEQFEAT_BOND :
5303
5749
        case SEQFEAT_SITE :
5312
5758
          break;
5313
5759
      }
5314
5760
      SeqFeatPtrToCommon ((FeatureFormPtr) rfp, sfp);
5315
 
      PointerToDialog (rfp->location, sfp->location);
5316
5761
      PointerToDialog (rfp->product, sfp->product);
5317
5762
      if (sfp->product != NULL) {
5318
5763
        sip = SeqLocId (sfp->product);
5540
5985
    } else {
5541
5986
      rpp = (RnaPagePtr) GetObjectExtra (rfp->data);
5542
5987
      if (rpp != NULL) {
 
5988
        SetNewFeatureDefaultInterval ((FeatureFormPtr) rfp);
5543
5989
        if (subtype >= FEATDEF_preRNA && subtype <= FEATDEF_scRNA) {
5544
5990
          SetEnumPopup (rpp->type, rna_type_alist,
5545
5991
                        (UIEnum) check_rna_type (subtype - FEATDEF_preRNA + 1));
 
5992
          if (subtype == FEATDEF_tRNA)
 
5993
          {
 
5994
            /* attempt to provide default location for anticodons */
 
5995
            SeqLocPtr tmp_loc = NULL;
 
5996
            
 
5997
            tmp_loc = DialogToPointer (rpp->rfp->location);
 
5998
            PointerToDialog (rpp->anticodon, tmp_loc);
 
5999
            SetSequenceAndStrandForIntervalPage (rpp->anticodon);
 
6000
            SeqLocFree (tmp_loc);              
 
6001
          }
5546
6002
        } else if (subtype == FEATDEF_snoRNA) {
5547
6003
          SetEnumPopup (rpp->type, rna_type_alist,
5548
6004
                        (UIEnum) check_rna_type (7));
5553
6009
          SetEnumPopup (rpp->type, rna_type_alist, (UIEnum) 0);
5554
6010
        }
5555
6011
      }
5556
 
      SetNewFeatureDefaultInterval ((FeatureFormPtr) rfp);
5557
6012
    }
5558
6013
  }
5559
6014
  Show (w);