~ubuntu-branches/ubuntu/oneiric/ncbi-tools6/oneiric

« back to all changes in this revision

Viewing changes to sequin/sequin5.c

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2008-07-14 19:43:15 UTC
  • mfrom: (2.1.12 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080714194315-ed44u9ek7txva2rz
Tags: 6.1.20080302-3
tools/readdb.c: enable madvise()-based code on all glibc (hence all
Debian) systems, not just Linux.  (Closes: #490437.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
*
30
30
* Version Creation Date:   8/26/97
31
31
*
32
 
* $Revision: 6.470 $
 
32
* $Revision: 6.637 $
33
33
*
34
34
* File Description:
35
35
*
72
72
#include <salutil.h>
73
73
 
74
74
#include <asn2gnbp.h> /* added for  parse to flatfile */
75
 
#include <seqpanel.h> /* added to include SeqEdTranslateOneCDS */
 
75
#include <sqnutils.h> /* added to include SeqEdTranslateOneCDS */
 
76
#include <seqpanel.h>
76
77
#include <salpanel.h>
 
78
#include <tax3api.h> /* added for specific-host corrections */
 
79
#include <findrepl.h>
 
80
#include <valid.h> /* added for latloncountry conflict checking */
77
81
 
78
82
static void CommonLaunchBioseqViewer (SeqEntryPtr sep, CharPtr path, Boolean directToEditor)
79
83
 
2164
2168
  return;
2165
2169
}
2166
2170
 
2167
 
static void FeatConvertImpToSpecialRNA (SeqFeatPtr sfp,
2168
 
                                        Int2       toFeatSubType)
 
2171
static Boolean ConvertImpToSpecialRNA 
 
2172
(SeqFeatPtr sfp,
 
2173
 Uint2      featdef_to,
 
2174
 Pointer    extradata)
2169
2175
{
2170
2176
  RnaRefPtr          rrp;
2171
2177
 
 
2178
  if (sfp == NULL || sfp->data.choice != SEQFEAT_IMP)
 
2179
  {
 
2180
    return FALSE;
 
2181
  }
2172
2182
  rrp = RnaRefNew ();
2173
2183
  if (rrp != NULL) {
2174
2184
    sfp->data.value.ptrvalue = ImpFeatFree ((ImpFeatPtr) sfp->data.value.ptrvalue);
2175
2185
    sfp->data.choice = SEQFEAT_RNA;
2176
2186
    sfp->data.value.ptrvalue = (Pointer) rrp;
2177
 
    if (toFeatSubType == FEATDEF_precursor_RNA) {
 
2187
    if (featdef_to == FEATDEF_precursor_RNA) {
2178
2188
      rrp->type = 1;
2179
2189
    } else {
2180
2190
      rrp->type = 255;
2181
2191
    }
2182
2192
  }
2183
 
}
2184
 
 
2185
 
static void FeatConvertRegionToImp (SeqFeatPtr sfp,
2186
 
                                    Int2       toFeatSubType,
2187
 
                                    EnumFieldAssoc PNTR alist)
2188
 
{
2189
 
  EnumFieldAssocPtr  ap;
2190
 
  GBQualPtr          gbqual;
2191
 
  Int2               i;
2192
 
  ImpFeatPtr         ifp;
2193
 
  CharPtr            str;
2194
 
 
2195
 
  ifp = ImpFeatNew ();
2196
 
  if (NULL == ifp)
2197
 
    return;
2198
 
 
2199
 
  str = (CharPtr) sfp->data.value.ptrvalue;
2200
 
  sfp->data.choice = SEQFEAT_IMP;
2201
 
  sfp->data.value.ptrvalue = (Pointer) ifp;
2202
 
  for (i = 1, ap = alist; ap->name != NULL; i++, ap++) {
2203
 
    if (ap->value == toFeatSubType) {
2204
 
      ifp->key = MemFree (ifp->key);
2205
 
      ifp->key = StringSave (ap->name);
2206
 
    }
2207
 
  }
2208
 
 
2209
 
  if (ifp->key == NULL) {
2210
 
    ifp->key = StringSave ("misc_feature");
2211
 
  }
2212
 
 
2213
 
  if (! StringHasNoText (str)) {
2214
 
    gbqual = GBQualNew ();
2215
 
    if (gbqual != NULL) {
2216
 
      gbqual->qual = StringSave ("note");
2217
 
      gbqual->val = str;
2218
 
      gbqual->next = sfp->qual;
2219
 
      sfp->qual = gbqual;
2220
 
    }
2221
 
  }
2222
 
  
2223
 
}
2224
 
 
2225
 
static void FeatConvertRegionToRNA (SeqFeatPtr sfp,
2226
 
                                    Int2       toFeatSubType)
 
2193
  return TRUE;
 
2194
}
 
2195
 
 
2196
static Boolean ConvertRegionToRNA 
 
2197
(SeqFeatPtr sfp,
 
2198
 Uint2      featdef_to,
 
2199
 Pointer    extradata)
2227
2200
{
2228
2201
  RnaRefPtr  rrp;
2229
2202
  CharPtr    str;
2230
2203
 
 
2204
  if (sfp == NULL || sfp->data.choice != SEQFEAT_REGION)
 
2205
  {
 
2206
    return FALSE;
 
2207
  }
 
2208
 
2231
2209
  rrp = RnaRefNew ();
2232
2210
  if (NULL == rrp)
2233
 
    return;
 
2211
  {
 
2212
    return FALSE;
 
2213
  }
2234
2214
 
2235
2215
  str = (CharPtr) sfp->data.value.ptrvalue;
2236
2216
  sfp->data.choice = SEQFEAT_RNA;
2237
2217
  sfp->data.value.ptrvalue = (Pointer) rrp;
2238
2218
 
2239
 
  if (toFeatSubType == FEATDEF_precursor_RNA) {
 
2219
  if (featdef_to == FEATDEF_precursor_RNA) {
2240
2220
    rrp->type = 1;
2241
2221
  } else {
2242
2222
    rrp->type = 255;
2246
2226
    rrp->ext.choice = 1;
2247
2227
    rrp->ext.value.ptrvalue = str;
2248
2228
  }
2249
 
 
 
2229
  return TRUE;
2250
2230
}
2251
2231
 
2252
 
static void FeatConvertImpToRNA (SeqFeatPtr sfp,
2253
 
                                 Int2       toFeatSubType)
 
2232
static Boolean ConvertImpToRNA 
 
2233
(SeqFeatPtr sfp,
 
2234
 Uint2      featdef_to,
 
2235
 Pointer    extradata)
2254
2236
{
2255
2237
  RnaRefPtr  rrp;
2256
2238
 
 
2239
  if (sfp == NULL || sfp->data.choice != SEQFEAT_IMP)
 
2240
  {
 
2241
    return FALSE;
 
2242
  }
 
2243
 
2257
2244
  rrp = RnaRefNew ();
2258
2245
  if (NULL == rrp)
2259
 
    return;
 
2246
    return FALSE;
2260
2247
 
2261
2248
  sfp->data.value.ptrvalue =
2262
2249
    ImpFeatFree ((ImpFeatPtr) sfp->data.value.ptrvalue);
2263
2250
  sfp->data.choice = SEQFEAT_RNA;
2264
2251
  sfp->data.value.ptrvalue = (Pointer) rrp;
2265
2252
 
2266
 
  switch (toFeatSubType) {
 
2253
  switch (featdef_to) {
2267
2254
  case FEATDEF_preRNA :
2268
2255
    rrp->type = 1;
2269
2256
    break;
2285
2272
  case FEATDEF_snoRNA :
2286
2273
    rrp->type = 7;
2287
2274
    break;
 
2275
  case FEATDEF_ncRNA :
 
2276
    rrp->type = 255;
 
2277
    rrp->ext.choice = 1;
 
2278
    rrp->ext.value.ptrvalue = StringSave ("ncRNA");
 
2279
    break;
2288
2280
  case FEATDEF_otherRNA :
2289
2281
    rrp->type = 255;
2290
2282
    break;
2291
2283
  default :
2292
2284
    break;
2293
2285
  }
2294
 
 
 
2286
  return TRUE;
2295
2287
}
2296
2288
 
2297
 
static void FeatConvertCommentToMiscFeature (SeqFeatPtr sfp)
 
2289
static Boolean ConvertCommentToMiscFeat (SeqFeatPtr sfp, Uint2 featdef_to, Pointer extradata)
2298
2290
{
2299
2291
  ImpFeatPtr ifp;
2300
2292
 
2301
 
  if (sfp->data.value.ptrvalue == NULL) {
2302
 
    ifp = ImpFeatNew ();
2303
 
    if (ifp != NULL) {
2304
 
      ifp->key = StringSave ("misc_feature");
2305
 
      sfp->data.choice = SEQFEAT_IMP;
2306
 
      sfp->data.value.ptrvalue = (Pointer) ifp;
2307
 
    }
2308
 
  }
 
2293
  if (sfp == NULL || sfp->data.choice != SEQFEAT_COMMENT || sfp->data.value.ptrvalue != NULL)
 
2294
  {
 
2295
    return FALSE;
 
2296
  }
 
2297
  
 
2298
  ifp = ImpFeatNew ();
 
2299
  if (ifp != NULL) {
 
2300
    ifp->key = StringSave ("misc_feature");
 
2301
    sfp->data.choice = SEQFEAT_IMP;
 
2302
    sfp->data.value.ptrvalue = (Pointer) ifp;
 
2303
    return TRUE;
 
2304
  }
 
2305
  return FALSE;
2309
2306
}
2310
2307
 
2311
 
static void FeatConvertGeneToMiscFeature (SeqFeatPtr sfp)
 
2308
static Boolean ConvertGeneToMiscFeat 
 
2309
(SeqFeatPtr sfp,
 
2310
 Uint2      featdef_to,
 
2311
 Pointer    extradata)
2312
2312
{
2313
2313
  ImpFeatPtr  ifp;
2314
 
  GBQualPtr   gbqual;
2315
 
  CharPtr     genelocus;
 
2314
  CharPtr     new_comment;
2316
2315
  GeneRefPtr  grp;
 
2316
  Int4        comment_len = 0;
2317
2317
 
 
2318
  if (sfp == NULL || sfp->data.choice != SEQFEAT_GENE)
 
2319
  {
 
2320
    return FALSE;
 
2321
  }
2318
2322
  ifp = ImpFeatNew ();
2319
2323
  if (NULL == ifp)
2320
 
    return;
 
2324
  {
 
2325
    return FALSE;
 
2326
  }
2321
2327
 
2322
 
  genelocus = NULL;
2323
2328
  grp = (GeneRefPtr) sfp->data.value.ptrvalue;
2324
 
  if (grp != NULL) {
2325
 
    genelocus = grp->locus;
2326
 
    grp->locus = NULL;
 
2329
  if (grp != NULL) 
 
2330
  {
 
2331
    if (!StringHasNoText (grp->locus))
 
2332
    {
 
2333
      comment_len += StringLen (grp->locus) + 2;
 
2334
    }
 
2335
    if (!StringHasNoText (grp->desc))
 
2336
    {
 
2337
      comment_len += StringLen (grp->desc) + 2;
 
2338
    }
 
2339
  }
 
2340
  if (comment_len == 0) 
 
2341
  {
 
2342
    /* nothing to add to comment */
 
2343
  }
 
2344
  else
 
2345
  {
 
2346
    /* add one for terminating NULL */
 
2347
    comment_len++;
 
2348
    if (!StringHasNoText (sfp->comment))
 
2349
    {
 
2350
      comment_len += StringLen (sfp->comment) + 2;
 
2351
    }
 
2352
 
 
2353
    new_comment = (CharPtr) MemNew (sizeof (Char) * comment_len);
 
2354
    /* NOTE - I don't have to check for grp == NULL because
 
2355
     * comment_len would only have been > 0 if grp had existed
 
2356
     * and had nonempty fields.
 
2357
     */
 
2358
    if (!StringHasNoText (grp->desc))
 
2359
    {
 
2360
      StringCat (new_comment, grp->desc);
 
2361
      StringCat (new_comment, "; ");    
 
2362
    }
 
2363
    if (!StringHasNoText (grp->locus))
 
2364
    {
 
2365
      StringCat (new_comment, grp->locus);
 
2366
      StringCat (new_comment, "; ");    
 
2367
    }
 
2368
    if (!StringHasNoText (sfp->comment))
 
2369
    {
 
2370
      StringCat (new_comment, sfp->comment);
 
2371
      StringCat (new_comment, "; ");    
 
2372
    }
 
2373
    /* remove last semicolon */
 
2374
    new_comment[StringLen (new_comment) - 2] = 0;
 
2375
    sfp->comment = MemFree (sfp->comment);
 
2376
    sfp->comment = new_comment;
2327
2377
  }
2328
2378
 
2329
2379
  sfp->data.value.ptrvalue =
2331
2381
  sfp->data.choice = SEQFEAT_IMP;
2332
2382
  sfp->data.value.ptrvalue = (Pointer) ifp;
2333
2383
  ifp->key = StringSave ("misc_feature");
2334
 
 
2335
 
  if (! StringHasNoText (genelocus)) {
2336
 
    gbqual = GBQualNew ();
2337
 
    if (gbqual != NULL) {
2338
 
      gbqual->qual = StringSave ("gene");
2339
 
      gbqual->val = genelocus;
2340
 
      gbqual->next = sfp->qual;
2341
 
      sfp->qual = gbqual;
2342
 
    }
2343
 
  }
2344
 
 
 
2384
  return TRUE;
2345
2385
}
2346
2386
 
2347
 
static void FeatConvertRNAToMiscFeature (SeqFeatPtr sfp)
 
2387
static Boolean ConvertRNAToMiscFeat
 
2388
(SeqFeatPtr sfp,
 
2389
 Uint2      featdef_to,
 
2390
 Pointer    extradata)
2348
2391
{
2349
 
  GBQualPtr  gbqual;
 
2392
  GBQualPtr  gbqual, q_p, q_n;
2350
2393
  ImpFeatPtr ifp;
2351
 
  CharPtr    rnaname;
 
2394
  CharPtr    rnaname, newnote;
2352
2395
  RnaRefPtr  rrp;
 
2396
  Int4       note_len = 0;
 
2397
 
 
2398
  if (sfp == NULL || sfp->data.choice != SEQFEAT_RNA)
 
2399
  {
 
2400
    return FALSE;
 
2401
  }
2353
2402
 
2354
2403
  ifp = ImpFeatNew ();
2355
2404
  if (NULL == ifp)
2356
 
    return;
 
2405
  {
 
2406
    return FALSE;
 
2407
  }
2357
2408
 
2358
2409
  rnaname = NULL;
2359
2410
  rrp = (RnaRefPtr) sfp->data.value.ptrvalue;
2360
 
  if (rrp != NULL) {
 
2411
  if (rrp != NULL && rrp->type != 255 && rrp->ext.choice == 1) {
2361
2412
    if (rrp->ext.choice == 1) {
2362
2413
      rnaname = (CharPtr) rrp->ext.value.ptrvalue;
2363
2414
      rrp->ext.value.ptrvalue = NULL;
 
2415
      note_len = StringLen (rnaname) + 2;
2364
2416
    }
2365
2417
  }
2366
2418
 
2370
2422
  sfp->data.value.ptrvalue = (Pointer) ifp;
2371
2423
  ifp->key = StringSave ("misc_feature");
2372
2424
 
2373
 
  if (! StringHasNoText (rnaname)) {
2374
 
    gbqual = GBQualNew ();
2375
 
    if (gbqual != NULL) {
2376
 
      gbqual->qual = StringSave ("product");
2377
 
      gbqual->val = rnaname;
2378
 
      gbqual->next = sfp->qual;
2379
 
      sfp->qual = gbqual;
2380
 
    }
 
2425
  for (gbqual = sfp->qual; gbqual != NULL; gbqual = gbqual->next) {
 
2426
    if (StringCmp (gbqual->qual, "product") == 0) {
 
2427
      note_len += StringLen (gbqual->val) + 2;
 
2428
    }
 
2429
  }
 
2430
  
 
2431
  if (note_len > 0) {
 
2432
    if (!StringHasNoText (sfp->comment)) {
 
2433
      note_len += StringLen (sfp->comment) + 2;
 
2434
    }
 
2435
    newnote = (CharPtr) MemNew (sizeof (Char) * (note_len + 1));
 
2436
    if (!StringHasNoText (sfp->comment)) {
 
2437
      StringCpy (newnote, sfp->comment);
 
2438
      StringCat (newnote, "; ");
 
2439
    }
 
2440
    if (rnaname != NULL) {
 
2441
      StringCat (newnote, rnaname);
 
2442
      StringCat (newnote, "; ");
 
2443
      rnaname = MemFree (rnaname);
 
2444
    }
 
2445
    gbqual = sfp->qual;
 
2446
    q_p = NULL;
 
2447
    while (gbqual != NULL) {
 
2448
      q_n = gbqual->next;
 
2449
      if (StringCmp (gbqual->qual, "product") == 0) {
 
2450
        StringCat (newnote, gbqual->val);
 
2451
        if (q_p == NULL) {
 
2452
          sfp->qual = q_n;
 
2453
        } else {
 
2454
          q_p->next = q_n;
 
2455
        }
 
2456
        gbqual->next = NULL;
 
2457
        gbqual = GBQualFree (gbqual);
 
2458
      } else {
 
2459
        q_p = gbqual;
 
2460
      }
 
2461
      gbqual = q_n;
 
2462
    }
 
2463
    /* trim trailing semicolon */
 
2464
    newnote[note_len - 2] = 0;
 
2465
    sfp->comment = MemFree (sfp->comment);
 
2466
    sfp->comment = newnote;
2381
2467
  }
2382
2468
 
 
2469
  return TRUE;
2383
2470
}
2384
2471
 
2385
 
static void FeatConvertSiteToMiscFeature (SeqFeatPtr sfp)
 
2472
static Boolean ConvertSiteToMiscFeat
 
2473
(SeqFeatPtr sfp,
 
2474
 Uint2      featdef_to,
 
2475
 Pointer    extradata)
2386
2476
{
2387
2477
  GBQualPtr  gbqual;
2388
2478
  ImpFeatPtr ifp;
2389
2479
  Int2       sitetype;
2390
2480
 
 
2481
  if (sfp == NULL || sfp->data.choice != SEQFEAT_SITE)
 
2482
  {
 
2483
    return FALSE;
 
2484
  }
 
2485
 
2391
2486
  ifp = ImpFeatNew ();
2392
2487
  if (NULL == ifp)
2393
 
    return;
 
2488
  {
 
2489
    return FALSE;
 
2490
  }
2394
2491
 
2395
2492
  sitetype = (Int2) sfp->data.value.intvalue;
2396
2493
  sfp->data.choice = SEQFEAT_IMP;
2405
2502
      sfp->qual = gbqual;
2406
2503
    }
2407
2504
  }
2408
 
 
 
2505
  return TRUE;
2409
2506
}
2410
2507
 
2411
 
static void FeatConvertPeptideToRegion (SeqFeatPtr sfp)
 
2508
static Boolean ConvertProtToRegion 
 
2509
(SeqFeatPtr sfp,
 
2510
 Uint2      featdef_to,
 
2511
 Pointer    extradata)
2412
2512
{
2413
2513
  ProtRefPtr prp;
2414
2514
  ValNodePtr vnp;
2415
2515
  CharPtr    str;
2416
2516
 
 
2517
  if (sfp == NULL || sfp->data.choice != SEQFEAT_PROT)
 
2518
  {
 
2519
    return FALSE;
 
2520
  }
2417
2521
  prp = (ProtRefPtr) sfp->data.value.ptrvalue;
2418
2522
  if (NULL == prp)
2419
 
    return;
 
2523
  {
 
2524
    return FALSE;
 
2525
  }
2420
2526
 
2421
2527
  vnp = prp->name;
2422
2528
  if (vnp != NULL && vnp->next == NULL) {
2428
2534
      sfp->data.value.ptrvalue = (Pointer) str;
2429
2535
    }
2430
2536
  }
2431
 
 
2432
 
}
2433
 
 
2434
 
 
2435
 
static void FeatConvertImpToImp (SeqFeatPtr     sfp,
2436
 
                                 Int2           toFeatSubType,
2437
 
                                 EnumFieldAssoc PNTR alist)
2438
 
{
2439
 
  EnumFieldAssocPtr  ap;
2440
 
  Int2               i;
2441
 
  ImpFeatPtr         ifp;
2442
 
 
2443
 
  ifp = (ImpFeatPtr) sfp->data.value.ptrvalue;
2444
 
  if (NULL == ifp)
 
2537
  return TRUE;
 
2538
}
 
2539
 
 
2540
static Boolean ConvertRNAToNcRNA
 
2541
(SeqFeatPtr sfp)
 
2542
{
 
2543
  RnaRefPtr  rrp;
 
2544
  GBQualPtr  gbq;
 
2545
  tRNAPtr    trp; 
 
2546
  
 
2547
  if (sfp == NULL || sfp->data.choice != SEQFEAT_RNA) return FALSE;
 
2548
  
 
2549
  rrp = (RnaRefPtr) sfp->data.value.ptrvalue;
 
2550
  if (NULL == rrp) {
 
2551
    rrp = RnaRefNew ();
 
2552
    sfp->data.value.ptrvalue = rrp;
 
2553
  }
 
2554
 
 
2555
  if (rrp->ext.choice == 2) {
 
2556
    trp = (tRNAPtr) rrp->ext.value.ptrvalue;
 
2557
    if (trp != NULL) {
 
2558
      trp->anticodon = SeqLocFree (trp->anticodon);
 
2559
      trp = MemFree (trp);
 
2560
      rrp->ext.value.ptrvalue = trp;
 
2561
    }
 
2562
    rrp->ext.choice = 0;
 
2563
  } 
 
2564
 
 
2565
  /* might be converting from other ncRNA, tmRNA, or misc_RNA */
 
2566
  if (rrp->ext.choice == 1) {
 
2567
    if (StringCmp (rrp->ext.value.ptrvalue, "ncRNA") == 0) {
 
2568
      /* already ncRNA */
 
2569
    } else if (StringCmp (rrp->ext.value.ptrvalue, "tmRNA") == 0) {
 
2570
      rrp->ext.value.ptrvalue = MemFree (rrp->ext.value.ptrvalue);
 
2571
      rrp->ext.value.ptrvalue = StringSave ("ncRNA");
 
2572
    } else if (StringCmp (rrp->ext.value.ptrvalue, "misc_RNA") == 0) {
 
2573
      rrp->ext.value.ptrvalue = MemFree (rrp->ext.value.ptrvalue);
 
2574
      rrp->ext.value.ptrvalue = StringSave ("ncRNA");
 
2575
    } else {
 
2576
      /* not one of the specified types, copy to product gbqual */
 
2577
      gbq = GBQualNew ();
 
2578
      gbq->qual = StringSave ("product");
 
2579
      gbq->val = rrp->ext.value.ptrvalue;
 
2580
      gbq->next = sfp->qual;
 
2581
      sfp->qual = gbq;
 
2582
      rrp->ext.value.ptrvalue = StringSave ("ncRNA");
 
2583
    }
 
2584
  } else {
 
2585
    rrp->ext.choice = 1;
 
2586
    rrp->ext.value.ptrvalue = StringSave ("ncRNA");
 
2587
  }
 
2588
  
 
2589
  if (rrp->type == 5) {
 
2590
    gbq = GBQualNew ();
 
2591
    gbq->qual = StringSave ("ncRNA_class");
 
2592
    gbq->val = StringSave ("snRNA");
 
2593
    gbq->next = sfp->qual;
 
2594
    sfp->qual = gbq;
 
2595
  } else if (rrp->type == 6) {
 
2596
    gbq = GBQualNew ();
 
2597
    gbq->qual = StringSave ("ncRNA_class");
 
2598
    gbq->val = StringSave ("scRNA");
 
2599
    gbq->next = sfp->qual;
 
2600
    sfp->qual = gbq;
 
2601
  } else if (rrp->type == 7) {
 
2602
    gbq = GBQualNew ();
 
2603
    gbq->qual = StringSave ("ncRNA_class");
 
2604
    gbq->val = StringSave ("snoRNA");
 
2605
    gbq->next = sfp->qual;
 
2606
    sfp->qual = gbq;
 
2607
  }
 
2608
 
 
2609
  rrp->type = 255;
 
2610
  return TRUE;
 
2611
}
 
2612
 
 
2613
 
 
2614
static void ConvertFromncRNAtoMiscRNA (SeqFeatPtr sfp)
 
2615
{
 
2616
  RnaRefPtr rrp;
 
2617
  GBQualPtr gbq, gbq_prev = NULL;
 
2618
  CharPtr tmp;
 
2619
 
 
2620
  if (sfp == NULL || sfp->data.choice != SEQFEAT_RNA) return;
 
2621
  rrp = (RnaRefPtr) sfp->data.value.ptrvalue;
 
2622
  if (rrp == NULL || rrp->ext.choice != 1 || StringCmp (rrp->ext.value.ptrvalue, "ncRNA") != 0) {
2445
2623
    return;
2446
 
 
2447
 
  for (i = 1, ap = alist; ap->name != NULL; i++, ap++) {
2448
 
    if (ap->value == toFeatSubType) {
2449
 
      ifp->key = MemFree (ifp->key);
2450
 
      ifp->key = StringSave (ap->name);
2451
 
    }
2452
 
  }
2453
 
 
 
2624
  }
 
2625
  rrp->ext.value.ptrvalue = MemFree (rrp->ext.value.ptrvalue);
 
2626
  rrp->ext.choice = 0;
 
2627
  /* find new value for product */
 
2628
  gbq = sfp->qual;
 
2629
  while (gbq != NULL && StringCmp (gbq->qual, "product") != 0) {
 
2630
    gbq_prev = gbq;
 
2631
    gbq = gbq->next;
 
2632
  }
 
2633
 
 
2634
  if (gbq != NULL) {
 
2635
    rrp->ext.choice = 1;
 
2636
    rrp->ext.value.ptrvalue = StringSave (gbq->val);
 
2637
    if (gbq_prev == NULL) {
 
2638
      sfp->qual = gbq->next;
 
2639
    } else {
 
2640
      gbq_prev->next = gbq->next;
 
2641
    }
 
2642
    gbq->next = NULL;
 
2643
    gbq = GBQualFree (gbq);
 
2644
  } else if (!StringHasNoText (sfp->comment)) {
 
2645
    rrp->ext.choice = 1;
 
2646
    rrp->ext.value.ptrvalue = StringSave (sfp->comment);
 
2647
    sfp->comment = MemFree (sfp->comment);
 
2648
  }
 
2649
 
 
2650
  /* move ncRNA_class elsewhere */
 
2651
  gbq = sfp->qual;
 
2652
  gbq_prev = NULL;
 
2653
  while (gbq != NULL && StringCmp (gbq->qual, "ncRNA_class") != 0) {
 
2654
    gbq_prev = gbq;
 
2655
    gbq = gbq->next;
 
2656
  }
 
2657
 
 
2658
  if (gbq != NULL) {
 
2659
    if (StringCmp (gbq->val, "other") != 0) {
 
2660
      if (rrp->ext.choice == 0) {
 
2661
        rrp->ext.choice = 1;
 
2662
        rrp->ext.value.ptrvalue = StringSave (gbq->val);
 
2663
      } else {
 
2664
        if (StringHasNoText (sfp->comment)) {
 
2665
          sfp->comment = MemFree (sfp->comment);
 
2666
          sfp->comment = StringSave (gbq->val);
 
2667
        } else {
 
2668
          tmp = (CharPtr) MemNew (sizeof (Char) * (StringLen (sfp->comment) + StringLen (gbq->val) + 3));
 
2669
          sprintf (tmp, "%s; %s", sfp->comment, gbq->val);
 
2670
          sfp->comment = MemFree (sfp->comment);
 
2671
          sfp->comment = tmp;
 
2672
        }
 
2673
      }
 
2674
    }
 
2675
    if (gbq_prev == NULL) {
 
2676
      sfp->qual = gbq->next;
 
2677
    } else {
 
2678
      gbq_prev->next = gbq->next;
 
2679
    }
 
2680
    gbq->next = NULL;
 
2681
    gbq = GBQualFree (gbq);
 
2682
  }    
2454
2683
}
2455
2684
 
2456
 
static void FeatConvertRNAToRNA (SeqFeatPtr sfp,
2457
 
                                 Int2       toFeatSubType)
 
2685
 
 
2686
static Boolean ConvertRNAToRNA 
 
2687
(SeqFeatPtr sfp,
 
2688
 Uint2      featdef_to,
 
2689
 Pointer    extradata)
2458
2690
{
2459
2691
  RnaRefPtr  rrp;
 
2692
  Boolean    from_misc = FALSE, to_misc = FALSE;
 
2693
  GBQualPtr  gbq, gbq_p = NULL;
2460
2694
 
2461
2695
  rrp = (RnaRefPtr) sfp->data.value.ptrvalue;
2462
2696
  if (NULL == rrp)
2463
 
    return;
2464
 
 
2465
 
  switch (toFeatSubType) {
2466
 
  case FEATDEF_preRNA :
2467
 
    rrp->type = 1;
2468
 
    break;
2469
 
  case FEATDEF_mRNA :
2470
 
    rrp->type = 2;
2471
 
    break;
2472
 
  case FEATDEF_tRNA :
2473
 
    rrp->type = 3;
2474
 
    break;
2475
 
  case FEATDEF_rRNA :
2476
 
    rrp->type = 4;
2477
 
    break;
2478
 
  case FEATDEF_snRNA :
2479
 
    rrp->type = 5;
2480
 
    break;
2481
 
  case FEATDEF_scRNA :
2482
 
    rrp->type = 6;
2483
 
    break;
2484
 
  case FEATDEF_snoRNA :
2485
 
    rrp->type = 7;
2486
 
    break;
2487
 
  case FEATDEF_otherRNA :
2488
 
    rrp->type = 255;
2489
 
    break;
2490
 
  default:
2491
 
    break;
2492
 
  }
2493
 
 
 
2697
    return FALSE;
 
2698
 
 
2699
  if (rrp->type == 255) {
 
2700
    from_misc = TRUE;
 
2701
  }
 
2702
 
 
2703
  switch (featdef_to) {
 
2704
    case FEATDEF_preRNA :
 
2705
      rrp->type = 1;
 
2706
      break;
 
2707
    case FEATDEF_mRNA :
 
2708
      rrp->type = 2;
 
2709
      break;
 
2710
    case FEATDEF_tRNA :
 
2711
      rrp->type = 3;
 
2712
      break;
 
2713
    case FEATDEF_rRNA :
 
2714
      rrp->type = 4;
 
2715
      break;
 
2716
    case FEATDEF_snRNA :
 
2717
      rrp->type = 5;
 
2718
      to_misc = TRUE;
 
2719
      break;
 
2720
    case FEATDEF_scRNA :
 
2721
      rrp->type = 6;
 
2722
      to_misc = TRUE;
 
2723
      break;
 
2724
    case FEATDEF_snoRNA :
 
2725
      rrp->type = 7;
 
2726
      to_misc = TRUE;
 
2727
      break;
 
2728
    case FEATDEF_ncRNA :
 
2729
      return ConvertRNAToNcRNA (sfp);
 
2730
      break;
 
2731
    case FEATDEF_otherRNA :
 
2732
      rrp->type = 255;
 
2733
      ConvertFromncRNAtoMiscRNA (sfp);
 
2734
      break;
 
2735
    default:
 
2736
      break;
 
2737
  }
 
2738
  if (from_misc && !to_misc && rrp->ext.choice == 1 && StringCmp (rrp->ext.value.ptrvalue, "misc_RNA") == 0) {
 
2739
    /* move product qual to string */
 
2740
    gbq = sfp->qual;
 
2741
    while (gbq != NULL && StringCmp (gbq->qual, "product") != 0) {
 
2742
      gbq_p = gbq;
 
2743
      gbq = gbq->next;
 
2744
    }
 
2745
    if (gbq == NULL) {
 
2746
      rrp->ext.value.ptrvalue = MemFree (rrp->ext.value.ptrvalue);
 
2747
      rrp->ext.choice = 0;
 
2748
    } else {
 
2749
      rrp->ext.value.ptrvalue = MemFree (rrp->ext.value.ptrvalue);
 
2750
      rrp->ext.value.ptrvalue = gbq->val;
 
2751
      gbq->val = NULL;
 
2752
      if (gbq_p == NULL) {
 
2753
        sfp->qual = gbq->next;
 
2754
      } else {
 
2755
        gbq_p->next = gbq->next;
 
2756
      }
 
2757
      gbq->next = NULL;
 
2758
      gbq = GBQualFree (gbq);
 
2759
    }
 
2760
  }
 
2761
  return TRUE;
2494
2762
}
2495
2763
 
2496
 
static void FeatConvertProtToProt (SeqFeatPtr sfp,
2497
 
                                   Int2       toFeatSubType)
 
2764
static Boolean ConvertProtToProt 
 
2765
(SeqFeatPtr sfp,
 
2766
 Uint2      featdef_to,
 
2767
 Pointer    extradata)
2498
2768
{
2499
2769
  ProtRefPtr prp;
2500
2770
 
2501
2771
  prp = (ProtRefPtr) sfp->data.value.ptrvalue;
2502
2772
  if (NULL == prp)
2503
 
    return;
 
2773
    return FALSE;
2504
2774
 
2505
 
  switch (toFeatSubType) {
2506
 
  case FEATDEF_PROT :
2507
 
    prp->processed = 0;
2508
 
    break;
2509
 
  case FEATDEF_preprotein :
2510
 
    prp->processed = 1;
2511
 
    break;
2512
 
  case FEATDEF_mat_peptide_aa :
2513
 
    prp->processed = 2;
2514
 
    break;
2515
 
  case FEATDEF_sig_peptide_aa :
2516
 
    prp->processed = 3;
2517
 
    break;
2518
 
  case FEATDEF_transit_peptide_aa :
2519
 
    prp->processed = 4;
2520
 
    break;
2521
 
  default :
2522
 
    break;
 
2775
  switch (featdef_to) {
 
2776
    case FEATDEF_PROT :
 
2777
      prp->processed = 0;
 
2778
      break;
 
2779
    case FEATDEF_preprotein :
 
2780
      prp->processed = 1;
 
2781
      break;
 
2782
    case FEATDEF_mat_peptide_aa :
 
2783
      prp->processed = 2;
 
2784
      break;
 
2785
    case FEATDEF_sig_peptide_aa :
 
2786
      prp->processed = 3;
 
2787
      break;
 
2788
    case FEATDEF_transit_peptide_aa :
 
2789
      prp->processed = 4;
 
2790
      break;
 
2791
    default :
 
2792
      break;
2523
2793
  }
2524
 
 
2525
 
}
2526
 
 
 
2794
  return TRUE;
 
2795
}
 
2796
 
 
2797
/* copied from seqport.c, for the benefit of load_fuzz_to_DNA */
 
2798
static Boolean add_fuzziness_to_loc (SeqLocPtr slp, Boolean less)
 
2799
{
 
2800
        IntFuzzPtr ifp;
 
2801
        SeqIntPtr sint;
 
2802
        SeqPntPtr spnt; 
 
2803
 
 
2804
        sint = NULL;
 
2805
        spnt = NULL;
 
2806
 
 
2807
        if(slp->choice == SEQLOC_INT)
 
2808
                sint = (SeqIntPtr) slp->data.ptrvalue;
 
2809
        else
 
2810
        {
 
2811
                if(slp->choice == SEQLOC_PNT)
 
2812
                        spnt = (SeqPntPtr) slp->data.ptrvalue;
 
2813
                else
 
2814
                        return FALSE;
 
2815
        }
 
2816
        ifp = IntFuzzNew();
 
2817
        ifp->choice = 4;
 
2818
        ifp->a = less ? 2 : 1;
 
2819
 
 
2820
        if(spnt != NULL)
 
2821
                spnt->fuzz = ifp;
 
2822
        else
 
2823
        {
 
2824
                if(less)
 
2825
                        sint->if_from = ifp;
 
2826
                else
 
2827
                        sint->if_to = ifp;
 
2828
        }
 
2829
 
 
2830
        return TRUE;
 
2831
}
 
2832
 
 
2833
 
 
2834
/* copied from seqport.c, for the benefit of MYdnaLoc_to_aaLoc */
 
2835
static Boolean load_fuzz_to_DNA(SeqLocPtr dnaLoc, SeqLocPtr aaLoc, Boolean 
 
2836
first)
 
2837
{
 
2838
        Uint1 strand;
 
2839
        SeqPntPtr spnt;
 
2840
        SeqIntPtr sint;
 
2841
        IntFuzzPtr ifp;
 
2842
        Boolean load, less;
 
2843
 
 
2844
        load = FALSE;
 
2845
        strand = SeqLocStrand(aaLoc);
 
2846
        if(aaLoc->choice == SEQLOC_INT)
 
2847
        {
 
2848
                sint = (SeqIntPtr) aaLoc->data.ptrvalue;
 
2849
                if((first && strand != Seq_strand_minus ) || 
 
2850
                        (!first && strand == Seq_strand_minus)) /*the first 
 
2851
Seq-loc*/
 
2852
                {
 
2853
                        ifp = sint->if_from;
 
2854
                        if(ifp && ifp->choice == 4 )
 
2855
                                load = (ifp->a == 2);
 
2856
                }
 
2857
                else
 
2858
                {
 
2859
                        ifp = sint->if_to;
 
2860
                        if(ifp && ifp->choice == 4)
 
2861
                                load = (ifp->a == 1);
 
2862
                }
 
2863
        }
 
2864
        else if(aaLoc->choice == SEQLOC_PNT)
 
2865
        {
 
2866
                spnt = (SeqPntPtr) aaLoc->data.ptrvalue;
 
2867
                ifp = spnt->fuzz;
 
2868
                if(ifp && ifp->choice == 4)
 
2869
                {
 
2870
                        if(first)
 
2871
                                load = (ifp->a == 2);
 
2872
                        else
 
2873
                                load = (ifp->a == 1);
 
2874
                }
 
2875
        }
 
2876
 
 
2877
        if(load)
 
2878
        {
 
2879
                if(SeqLocStrand(dnaLoc) == Seq_strand_minus)
 
2880
                        less = (first == FALSE);
 
2881
                else
 
2882
                        less = first;
 
2883
                add_fuzziness_to_loc (dnaLoc, less);
 
2884
                return TRUE;
 
2885
        }
 
2886
        else
 
2887
                return FALSE;
 
2888
}       
 
2889
 
 
2890
static SeqLocPtr MYdnaLoc_to_aaLoc(SeqFeatPtr sfp, 
 
2891
                                   SeqLocPtr location_loc, 
 
2892
                                   Boolean merge, 
 
2893
                                   Int4Ptr frame, 
 
2894
                                   Boolean allowTerminator)
 
2895
{
 
2896
        SeqLocPtr aa_loc = NULL, loc;
 
2897
        CdRegionPtr crp;
 
2898
        Int4 product_len, end_pos, frame_offset;
 
2899
        GatherRange gr;
 
2900
        Int4 a_left = 0, a_right, last_aa = -20, aa_from, aa_to;
 
2901
        SeqLocPtr slp, slp1, slp2;
 
2902
        Int2 cmpval;
 
2903
        SeqIdPtr aa_sip;
 
2904
        BioseqPtr bsp;
 
2905
 
 
2906
        if ((sfp == NULL) || (location_loc == NULL)) return aa_loc;
 
2907
        if (sfp->data.choice != 3) return aa_loc;
 
2908
        if (sfp->product == NULL) return aa_loc;
 
2909
 
 
2910
        crp = (CdRegionPtr) sfp->data.value.ptrvalue;
 
2911
        if(crp == NULL) return aa_loc;
 
2912
 
 
2913
    /* each interval of location_loc must be equal to or contained in
 
2914
     * an interval of sfp->location
 
2915
     */
 
2916
    slp1 = SeqLocFindNext (sfp->location, NULL);
 
2917
    slp2 = SeqLocFindNext (location_loc, NULL);
 
2918
    while (slp2 != NULL && slp1 != NULL) {
 
2919
      cmpval = SeqLocCompare (slp2, slp1);
 
2920
      if (cmpval == SLC_A_IN_B || cmpval == SLC_A_EQ_B) {
 
2921
        slp2 = SeqLocFindNext (location_loc, slp2);
 
2922
      } else {
 
2923
        slp1 = SeqLocFindNext (sfp->location, slp1);
 
2924
      }
 
2925
    }
 
2926
    if (slp1 == NULL) return aa_loc;
 
2927
      
 
2928
        aa_sip = SeqLocId(sfp->product);
 
2929
        if (aa_sip == NULL) return aa_loc;
 
2930
        bsp = BioseqLockById(aa_sip);
 
2931
        if (bsp == NULL) return aa_loc;
 
2932
        end_pos = bsp->length - 1;
 
2933
        BioseqUnlock(bsp);
 
2934
 
 
2935
        if(crp->frame == 0)
 
2936
                frame_offset = 0;
 
2937
        else
 
2938
                frame_offset = (Int4)crp->frame-1;
 
2939
 
 
2940
        slp = NULL;
 
2941
        product_len = 0;
 
2942
        loc = NULL;
 
2943
        while ((slp = SeqLocFindNext(sfp->location, slp))!=NULL)
 
2944
        {
 
2945
           if (SeqLocOffset(location_loc, slp, &gr, 0))
 
2946
           {
 
2947
                        SeqLocOffset(slp, location_loc, &gr, 0);
 
2948
                
 
2949
                        a_left = gr.left + product_len - frame_offset;
 
2950
                        a_right = gr.right + product_len - frame_offset;
 
2951
 
 
2952
                        aa_from = a_left / 3;
 
2953
                        aa_to = a_right / 3;
 
2954
 
 
2955
                        if (aa_from < 0)
 
2956
                                aa_from = 0;
 
2957
                        if (aa_to > end_pos)
 
2958
                                aa_to = end_pos;
 
2959
 
 
2960
                        if (merge)
 
2961
                        {
 
2962
                                if (aa_from <= last_aa)  /* overlap due to 
 
2963
codons */
 
2964
                                        aa_from = last_aa+1;  /* set up to merge 
 
2965
*/
 
2966
                        }
 
2967
 
 
2968
                        if (aa_from <= aa_to || (allowTerminator && aa_from == aa_to + 1))
 
2969
                        {
 
2970
                                if(loc != NULL)
 
2971
                                {
 
2972
                                        if(aa_loc == NULL)
 
2973
                                                load_fuzz_to_DNA(loc, location_loc, 
 
2974
TRUE);
 
2975
                                        SeqLocAdd(&aa_loc, loc, merge, FALSE);
 
2976
                                }
 
2977
                                loc = SeqLocIntNew(aa_from, aa_to, 0, aa_sip);
 
2978
                                last_aa = aa_to;
 
2979
                        }
 
2980
             }
 
2981
 
 
2982
             product_len += SeqLocLen(slp);             
 
2983
        }
 
2984
 
 
2985
        if(loc != NULL)
 
2986
        {
 
2987
                if(aa_loc == NULL)
 
2988
                        load_fuzz_to_DNA(loc, location_loc, TRUE);
 
2989
                load_fuzz_to_DNA(loc, location_loc, FALSE);
 
2990
                SeqLocAdd(&aa_loc, loc, merge, FALSE);
 
2991
        }
 
2992
        if (frame != NULL)
 
2993
            *frame = a_left % 3;
 
2994
 
 
2995
        return SeqLocPackage(aa_loc);
 
2996
}
2527
2997
 
2528
2998
static SeqLocPtr BuildProtLoc (SeqFeatPtr overlapping_cds, SeqLocPtr slp, Int4Ptr frame)
2529
2999
{
2544
3014
      is_ordered = TRUE;
2545
3015
    } else {
2546
3016
      if (first) {
2547
 
        aa_loc = dnaLoc_to_aaLoc (overlapping_cds, tmp_loc, FALSE, frame, FALSE);
 
3017
        aa_loc = MYdnaLoc_to_aaLoc (overlapping_cds, tmp_loc, FALSE, frame, FALSE);
2548
3018
        first = FALSE;
2549
3019
      } else {
2550
 
        aa_loc = dnaLoc_to_aaLoc (overlapping_cds, tmp_loc, FALSE, NULL, FALSE);
 
3020
        aa_loc = MYdnaLoc_to_aaLoc (overlapping_cds, tmp_loc, FALSE, NULL, FALSE);
2551
3021
      }
2552
3022
    }
2553
3023
    if (last_loc == NULL) {
2581
3051
 
2582
3052
/*---------------------------------------------------------------------*/
2583
3053
/*                                                                     */
2584
 
/* FeatConvertImpToPeptide () - Convert a given import feature to a    */
 
3054
/* ConvertImpToProt () - Convert a given import feature to a    */
2585
3055
/*                           protein feature.                          */
2586
3056
/*                                                                     */
2587
3057
/*    Note : Any of the Import feature's gbquals that can be converted */
2591
3061
/*                                                                     */
2592
3062
/*---------------------------------------------------------------------*/
2593
3063
 
2594
 
static void FeatConvertImpToPeptide (SeqFeatPtr  sfp,
2595
 
                                     Uint1        toFeatSubType,
2596
 
                                     Uint2       entityID)
 
3064
static Boolean ConvertImpToProt 
 
3065
(SeqFeatPtr  sfp,
 
3066
 Uint2       featdef_to,
 
3067
 Pointer     extradata)
2597
3068
{
2598
3069
  ImpFeatPtr ifp;
2599
3070
  SeqFeatPtr cds;
2603
3074
  ProtRefPtr prp;
2604
3075
  SeqIdPtr   sip;
2605
3076
  BioseqPtr  bsp;
 
3077
  SeqMgrFeatContext fcontext;
2606
3078
 
 
3079
  if (sfp == NULL || sfp->data.choice != SEQFEAT_IMP)
 
3080
  {
 
3081
    return FALSE;
 
3082
  }
2607
3083
  /* Get the Import Feature */
2608
3084
 
2609
3085
  ifp = (ImpFeatPtr) sfp->data.value.ptrvalue;
2610
3086
  if (NULL == ifp)
2611
 
    return;
 
3087
  {
 
3088
    return FALSE;
 
3089
  }
2612
3090
 
2613
3091
  /* Convert the location to a protein location */
2614
 
 
2615
 
  cds = FindBestCds (entityID, sfp->location, NULL, NULL);
 
3092
  cds = SeqMgrGetOverlappingCDS (sfp->location, &fcontext);
2616
3093
  if (cds == NULL)
2617
 
    return;
 
3094
  {
 
3095
    return FALSE;
 
3096
  }
2618
3097
 
2619
3098
  slp = BuildProtLoc (cds, sfp->location, &frame);
2620
3099
  if (slp == NULL)
2621
 
    return;
 
3100
  {
 
3101
    return FALSE;
 
3102
  }
2622
3103
 
2623
3104
  /* Create a new generic feature */
2624
3105
 
2625
3106
  sip = SeqLocId (cds->product);
2626
3107
  if (sip == NULL)
2627
 
    return;
 
3108
  {
 
3109
    slp = SeqLocFree (slp);
 
3110
    return FALSE;
 
3111
  }
2628
3112
 
2629
3113
  bsp = BioseqLockById (sip);
2630
3114
  if (bsp == NULL)
2631
 
    return;
 
3115
  {
 
3116
    slp = SeqLocFree (slp);
 
3117
    return FALSE;
 
3118
  }
2632
3119
 
2633
3120
  newSfp = CreateNewFeatureOnBioseq (bsp, SEQFEAT_PROT, slp);
2634
3121
  BioseqUnlock (bsp);
2635
3122
  if (newSfp == NULL)
2636
 
    return;
 
3123
  {
 
3124
    slp = SeqLocFree (slp);
 
3125
    return FALSE;
 
3126
  }
2637
3127
 
2638
3128
  /* Make it into a protein feature */
2639
3129
 
2640
3130
  prp = ProtRefNew ();
2641
3131
  newSfp->data.value.ptrvalue = (Pointer) prp;
2642
3132
  if (NULL == prp)
2643
 
    return;
 
3133
  {
 
3134
    slp = SeqLocFree (slp);
 
3135
    newSfp = SeqFeatFree (newSfp);
 
3136
    return FALSE;
 
3137
  }
2644
3138
 
2645
 
  switch (toFeatSubType) {
 
3139
  switch (featdef_to) {
2646
3140
    case FEATDEF_mat_peptide_aa :
2647
3141
      prp->processed = 2;
2648
3142
      break;
2654
3148
      break;
2655
3149
  }
2656
3150
 
2657
 
  sfp->idx.subtype = toFeatSubType;
2658
 
 
2659
3151
  /* Transfer unchanged fields from old feature */
2660
3152
 
2661
3153
  newSfp->partial     = sfp->partial;
2686
3178
  /* Mark the old feature for deletion */
2687
3179
 
2688
3180
  sfp->idx.deleteme = TRUE;
2689
 
}
2690
 
 
2691
 
/*---------------------------------------------------------------------*/
2692
 
/*                                                                     */
2693
 
/* FeatConvertPeptideToImp () -                                        */
2694
 
/*                                                                     */
2695
 
/*---------------------------------------------------------------------*/
2696
 
 
2697
 
static void FeatConvertPeptideToImp (SeqFeatPtr  sfp, Uint2 entityID)
 
3181
  return TRUE;
 
3182
}
 
3183
 
 
3184
 
 
3185
static SeqLocPtr FindNucleotideLocationForProteinFeatureConversion (SeqLocPtr slp, Uint2 entityID)
 
3186
{
 
3187
  SeqFeatPtr cds;
 
3188
 
 
3189
  cds = FindBestCds (entityID, NULL, slp, NULL);
 
3190
  if (NULL == cds)
 
3191
  {
 
3192
    return NULL;
 
3193
  }
 
3194
 
 
3195
  return aaLoc_to_dnaLoc (cds, slp);
 
3196
}
 
3197
 
 
3198
/*---------------------------------------------------------------------*/
 
3199
/*                                                                     */
 
3200
/* ConvertProtToImp () -                                        */
 
3201
/*                                                                     */
 
3202
/*---------------------------------------------------------------------*/
 
3203
 
 
3204
static Boolean ConvertProtToImp (SeqFeatPtr  sfp, Uint2 featdef_to, Pointer extradata)
2698
3205
{
2699
3206
  ProtRefPtr    prp;
2700
 
  SeqFeatPtr    cds;
2701
3207
  SeqLocPtr     slp;
2702
3208
  ImpFeatPtr    ifp;
2703
3209
  CharPtr       name;
2710
3216
  DbtagPtr      dbt;
2711
3217
  Char          idStr[64];
2712
3218
  ObjectIdPtr   oip;
 
3219
  Uint2         entityID;
2713
3220
 
2714
3221
  /* Make sure that we have a matching peptide feature */
2715
3222
 
2716
 
  if (sfp->data.choice != SEQFEAT_PROT)
2717
 
    return;
 
3223
  if (sfp == NULL || sfp->data.choice != SEQFEAT_PROT)
 
3224
  {
 
3225
    return FALSE;
 
3226
  }
 
3227
  entityID = sfp->idx.entityID;
2718
3228
 
2719
3229
  prp = (ProtRefPtr) sfp->data.value.ptrvalue;
2720
3230
  if (NULL == prp)
2721
 
    return;
 
3231
  {
 
3232
    return FALSE;
 
3233
  }
2722
3234
 
2723
3235
  switch (sfp->idx.subtype) {
2724
3236
    case FEATDEF_mat_peptide_aa :
2725
3237
      if (2 != prp->processed)
2726
 
        return;
 
3238
        return FALSE;
2727
3239
      break;
2728
3240
    case FEATDEF_sig_peptide_aa :
2729
3241
      if (3 != prp->processed)
2730
 
        return;
 
3242
        return FALSE;
2731
3243
      break;
2732
3244
    case FEATDEF_transit_peptide_aa :
2733
3245
      if (4 != prp->processed)
2734
 
        return;
 
3246
        return FALSE;
2735
3247
      break;
2736
3248
  }
2737
3249
 
2738
3250
  /* Convert the location from the protein */
2739
3251
  /* to the nucleotide Bioseq.             */
2740
3252
 
2741
 
  cds = FindBestCds (entityID, NULL, sfp->location, NULL);
2742
 
  if (NULL == cds)
2743
 
    return;
 
3253
  slp = FindNucleotideLocationForProteinFeatureConversion (sfp->location, entityID);
2744
3254
 
2745
 
  slp = aaLoc_to_dnaLoc (cds, sfp->location);
2746
3255
  if (NULL == slp)
2747
 
    return;
 
3256
    return FALSE;
2748
3257
  sfp->location = SeqLocFree (sfp->location);
2749
3258
  sfp->location = slp;
2750
3259
 
2753
3262
 
2754
3263
  ifp = ImpFeatNew ();
2755
3264
  if (NULL == ifp)
2756
 
    return;
 
3265
  {
 
3266
    return FALSE;
 
3267
  }
2757
3268
 
2758
3269
  switch (sfp->idx.subtype) {
2759
3270
    case FEATDEF_mat_peptide_aa :
2783
3294
  if (name != NULL) {
2784
3295
    gbqual = GBQualNew ();
2785
3296
    if (NULL == gbqual)
2786
 
      return;
 
3297
      return FALSE;
2787
3298
    topOfGbqList = gbqual;
2788
3299
    gbqual->qual = StringSave ("product");
2789
3300
    gbqual->val = StringSave (name);
2799
3310
  if (ec != NULL) {
2800
3311
    gbqual = GBQualNew ();
2801
3312
    if (NULL == gbqual)
2802
 
      return;
 
3313
      return FALSE;
2803
3314
    prevGbq->next = gbqual;
2804
3315
    gbqual->qual = StringSave ("EC_number");
2805
3316
    gbqual->val = StringSave (ec);
2815
3326
  if (NULL != activity) {
2816
3327
    gbqual = GBQualNew ();
2817
3328
    if (NULL == gbqual)
2818
 
      return;
 
3329
      return FALSE;
2819
3330
    prevGbq->next = gbqual;
2820
3331
    gbqual->qual = StringSave ("function");
2821
3332
    gbqual->val = StringSave (activity);
2826
3337
  for (vnp = prp->db; vnp != NULL; vnp = vnp->next) {
2827
3338
    dbt = (DbtagPtr) vnp->data.ptrvalue;
2828
3339
    if (NULL == dbt ) 
2829
 
      return;
 
3340
      continue;
2830
3341
    if (! StringHasNoText (dbt->db)) {
2831
3342
      gbqual = GBQualNew ();
2832
3343
      if (NULL == gbqual)
2833
 
        return;
 
3344
        continue;
2834
3345
      prevGbq->next = gbqual;
2835
3346
      oip = dbt->tag;
2836
3347
      if (oip->str != NULL && (! StringHasNoText (oip->str))) {
2837
 
        sprintf (idStr, "%s:%s", (CharPtr)dbt->tag, oip->str);
2838
 
        gbqual->qual = StringSave ("db_xref");
2839
 
        gbqual->val = StringSave (idStr);
 
3348
        sprintf (idStr, "%s:%s", (CharPtr)dbt->tag, oip->str);
 
3349
        gbqual->qual = StringSave ("db_xref");
 
3350
        gbqual->val = StringSave (idStr);
2840
3351
      } else {
2841
 
        sprintf (idStr, "%s:%ld", (CharPtr)dbt->tag, (long) oip->id);
2842
 
        gbqual->qual = StringSave ("db_xref");
2843
 
        gbqual->val = StringSave (idStr);
 
3352
        sprintf (idStr, "%s:%ld", (CharPtr)dbt->tag, (long) oip->id);
 
3353
        gbqual->qual = StringSave ("db_xref");
 
3354
        gbqual->val = StringSave (idStr);
2844
3355
      }
2845
3356
      prevGbq = gbqual;
2846
3357
    }
2854
3365
  /* Free the obsolete Protein reference */
2855
3366
 
2856
3367
  ProtRefFree (prp);
 
3368
  return TRUE;
 
3369
}
 
3370
 
 
3371
static CharPtr SubSourceText (BioSourcePtr biop, Uint1 subtype, BoolPtr found)
 
3372
{
 
3373
  Int4 subtype_len = 0;
 
3374
  SubSourcePtr ssp;
 
3375
  CharPtr subtype_txt = NULL;
 
3376
  
 
3377
  if (biop == NULL || biop->subtype == NULL) return NULL;
 
3378
  for (ssp = biop->subtype; ssp != NULL; ssp = ssp->next) {
 
3379
    if (ssp->subtype == subtype) {
 
3380
      if (found != NULL) *found = TRUE;
 
3381
      if (!StringHasNoText (ssp->name)) {
 
3382
        subtype_len += StringLen (ssp->name) + 1;
 
3383
      }
 
3384
    }
 
3385
  }
 
3386
  if (subtype_len == 0) return NULL;
 
3387
  subtype_txt = (CharPtr) MemNew (sizeof (Char) * subtype_len);
 
3388
  for (ssp = biop->subtype; ssp != NULL; ssp = ssp->next) {
 
3389
    if (ssp->subtype == subtype && !StringHasNoText (ssp->name)) {
 
3390
      if (!StringHasNoText (subtype_txt)) {
 
3391
        StringCat (subtype_txt, ";");
 
3392
      }
 
3393
      StringCat (subtype_txt, ssp->name);
 
3394
    }
 
3395
  }
 
3396
  return subtype_txt;
 
3397
}
 
3398
 
 
3399
static CharPtr OrgModText (BioSourcePtr biop, Uint1 subtype, BoolPtr found)
 
3400
{
 
3401
  Int4 subtype_len = 0;
 
3402
  OrgModPtr omp;
 
3403
  CharPtr subtype_txt = NULL;
 
3404
  
 
3405
  if (biop == NULL
 
3406
     || biop->org == NULL 
 
3407
     || biop->org->orgname == NULL 
 
3408
     || biop->org->orgname->mod == NULL) {
 
3409
    return NULL;
 
3410
  }
 
3411
     
 
3412
  for (omp = biop->org->orgname->mod; omp != NULL; omp = omp->next) {
 
3413
    if (omp->subtype == subtype) {
 
3414
      if (found != NULL) *found = TRUE;
 
3415
      if (!StringHasNoText (omp->subname)) {
 
3416
        subtype_len += StringLen (omp->subname) + 1;
 
3417
      }
 
3418
    }
 
3419
  }
 
3420
  if (subtype_len == 0) return NULL;
 
3421
  subtype_txt = (CharPtr) MemNew (sizeof (Char) * subtype_len);
 
3422
  for (omp = biop->org->orgname->mod; omp != NULL; omp = omp->next) {
 
3423
    if (omp->subtype == subtype && !StringHasNoText (omp->subname)) {
 
3424
      if (!StringHasNoText (subtype_txt)) {
 
3425
        StringCat (subtype_txt, ";");
 
3426
      }
 
3427
      StringCat (subtype_txt, omp->subname);
 
3428
    }
 
3429
  }
 
3430
  return subtype_txt;
 
3431
}
 
3432
 
 
3433
static CharPtr NoteText (BioSourcePtr biop, CharPtr comment)
 
3434
{
 
3435
  CharPtr orgmod_note, subsource_note;
 
3436
  Int4    text_len = 0;
 
3437
  CharPtr note_text = NULL;
 
3438
  
 
3439
  orgmod_note = OrgModText(biop, ORGMOD_other, NULL);
 
3440
  if (!StringHasNoText (orgmod_note)) {
 
3441
    text_len += StringLen (orgmod_note) + 1;
 
3442
  }
 
3443
  subsource_note = SubSourceText (biop, SUBSRC_other, NULL);
 
3444
  if (!StringHasNoText (subsource_note)) {
 
3445
    text_len += StringLen (subsource_note) + 1;
 
3446
  }
 
3447
  if (!StringHasNoText (comment)) {
 
3448
    text_len += StringLen (comment) + 1;
 
3449
  }
 
3450
  
 
3451
  if (text_len == 0) return NULL;  
 
3452
  
 
3453
  note_text = (CharPtr) MemNew (sizeof(Char) * text_len);
 
3454
  if (!StringHasNoText (orgmod_note)) {
 
3455
    StringCat (note_text, orgmod_note);
 
3456
  }
 
3457
  orgmod_note = MemFree (orgmod_note);
 
3458
  if (!StringHasNoText (subsource_note)) {
 
3459
    if (!StringHasNoText (note_text)) {
 
3460
      StringCat (note_text, ";");
 
3461
    }
 
3462
    StringCat (note_text, subsource_note);
 
3463
  }
 
3464
  subsource_note = MemFree (subsource_note);
 
3465
  
 
3466
  if (!StringHasNoText (comment)) {
 
3467
    if (!StringHasNoText (note_text)) {
 
3468
      StringCat (note_text, ";");
 
3469
    }
 
3470
    StringCat (note_text, comment);
 
3471
  }
 
3472
  return note_text;
2857
3473
}
2858
3474
 
2859
3475
/*---------------------------------------------------------------------*/
2860
3476
/*                                                                     */
2861
 
/* FeatConvertBioSrcToRepeatRegion ()                                  */
 
3477
/* ConvertBioSrcToRepeatRegion ()                                  */
2862
3478
/*                                                                     */
2863
3479
/* 9/28/2004: Changed to convert all BioSource features with notes     */
2864
3480
/* instead of ones with transposon or insertion_seq qualifiers.        */
2865
3481
/*---------------------------------------------------------------------*/
2866
3482
 
2867
 
static void FeatConvertBioSrcToRepeatRegion (SeqFeatPtr sfp)
 
3483
static Boolean ConvertBioSrcToRepeatRegion (SeqFeatPtr sfp, Uint2 featdef_to, Pointer extradata)
2868
3484
{
2869
3485
  BioSourcePtr  biop;
2870
3486
  GBQualPtr     gbqual;
2871
3487
  ImpFeatPtr    ifp;
2872
 
  OrgModPtr     omp = NULL;
2873
 
  SubSourcePtr  ssp = NULL;
2874
 
  CharPtr       text_to_use = NULL;
2875
 
  Int4          text_len = 0;
 
3488
  CharPtr       transposon_txt, insertion_seq_txt, note_txt;
 
3489
  Boolean       is_transposon = FALSE, is_insertion_seq = FALSE;
2876
3490
 
2877
 
  /* Only convert transposon and insertion_seq features */
 
3491
  if (sfp == NULL || sfp->idx.subtype != FEATDEF_BIOSRC) return FALSE;
2878
3492
 
2879
3493
  biop = (BioSourcePtr) sfp->data.value.ptrvalue;
2880
 
  for (ssp = biop->subtype; 
2881
 
       ssp != NULL && ssp->subtype != SUBSRC_other; 
2882
 
       ssp = ssp->next)
2883
 
  {
2884
 
  }
2885
 
  if (biop->org != NULL && biop->org->orgname != NULL)
2886
 
  {
2887
 
    for (omp = biop->org->orgname->mod; 
2888
 
         omp != NULL && omp->subtype != ORGMOD_other; 
2889
 
         omp = omp->next)
2890
 
    {
2891
 
    }
2892
 
  }
2893
 
 
 
3494
  
 
3495
  transposon_txt = SubSourceText (biop, SUBSRC_transposon_name, &is_transposon);
 
3496
  insertion_seq_txt = SubSourceText (biop, SUBSRC_insertion_seq_name, &is_insertion_seq);
 
3497
  note_txt = NoteText (biop, sfp->comment);
 
3498
  
2894
3499
  
2895
3500
  /* Create a new Import Feature */
2896
3501
 
2897
3502
  ifp = ImpFeatNew ();
2898
3503
  if (NULL == ifp)
2899
 
    return;
 
3504
    return FALSE;
2900
3505
  ifp->key = StringSave ("repeat_region");
2901
3506
 
2902
3507
  /* Copy relevant info from the BioSource */
2903
3508
  /* feature to the Import feature.        */
2904
3509
 
2905
 
  if (ssp != NULL)
2906
 
  {
2907
 
    text_len += StringLen (ssp->name) + 1;
2908
 
  }
2909
 
  if (omp != NULL)
2910
 
  {
2911
 
    text_len += StringLen (omp->subname) + 1;
2912
 
  }
2913
 
  if (text_len > 0)
2914
 
  {
2915
 
    text_to_use = (CharPtr) MemNew (text_len * sizeof (Char));
2916
 
    if (text_to_use != NULL)
2917
 
    {
2918
 
      text_to_use [0] = 0;
2919
 
      if (ssp != NULL)
2920
 
      {
2921
 
        StringCat (text_to_use, ssp->name);
2922
 
      }
2923
 
      if (omp != NULL)
2924
 
      {
2925
 
        if (!StringHasNoText (text_to_use))
2926
 
        {
2927
 
          StringCat (text_to_use, ";");
2928
 
        }
2929
 
        StringCat (text_to_use, omp->subname);
2930
 
      }
2931
 
            gbqual = GBQualNew ();
2932
 
            if (gbqual != NULL) 
2933
 
            {
2934
 
                    gbqual->qual = StringSave ("note");
2935
 
                    gbqual->val = text_to_use;
2936
 
              gbqual->next = sfp->qual;
2937
 
                    sfp->qual = gbqual;
2938
 
            }
2939
 
    }
2940
 
  }
2941
3510
    
2942
3511
  /* Delete the old BioSource feature */
2943
3512
 
2947
3516
 
2948
3517
  sfp->data.choice = SEQFEAT_IMP;
2949
3518
  sfp->data.value.ptrvalue = ifp;
 
3519
  
 
3520
  if (is_transposon) {
 
3521
    gbqual = GBQualNew ();
 
3522
    gbqual->qual = StringSave ("mobile_element");
 
3523
    gbqual->val = (CharPtr) MemNew (sizeof(Char) * (StringLen (transposon_txt) + 12));
 
3524
    StringCat (gbqual->val, "transposon:");
 
3525
    StringCat (gbqual->val, transposon_txt);
 
3526
    gbqual->next = sfp->qual;
 
3527
    sfp->qual = gbqual;
 
3528
  }
 
3529
  transposon_txt = MemFree (transposon_txt); 
 
3530
 
 
3531
  if (is_insertion_seq) {
 
3532
    gbqual = GBQualNew ();
 
3533
    gbqual->qual = StringSave ("mobile_element");
 
3534
    gbqual->val = (CharPtr) MemNew (sizeof(Char) * (StringLen (insertion_seq_txt) + 19));
 
3535
    StringCat (gbqual->val, "insertion sequence:");
 
3536
    StringCat (gbqual->val, insertion_seq_txt);
 
3537
    gbqual->next = sfp->qual;
 
3538
    sfp->qual = gbqual;
 
3539
  }
 
3540
  insertion_seq_txt = MemFree (insertion_seq_txt); 
 
3541
  
 
3542
  sfp->comment = MemFree (sfp->comment);
 
3543
  sfp->comment = note_txt;
 
3544
  return TRUE;
2950
3545
}
2951
3546
 
2952
3547
 
2953
 
static void FeatConvertRegionToProt (SeqFeatPtr sfp, Int2 toFeatSubType)
 
3548
static Boolean ConvertRegionToProt (SeqFeatPtr sfp, Uint2 featdef_to, Pointer extradata)
2954
3549
{
2955
3550
  BioseqPtr  bsp;
2956
3551
  ProtRefPtr prp;
2959
3554
  
2960
3555
  if (sfp == NULL || sfp->data.choice != SEQFEAT_REGION)
2961
3556
  {
2962
 
    return; 
 
3557
    return FALSE; 
2963
3558
  }
2964
3559
  
2965
3560
  /* only convert features that are on protein sequences */
2969
3564
    cds = SeqMgrGetOverlappingCDS (sfp->location, NULL);
2970
3565
    if (cds == NULL)
2971
3566
    {
2972
 
      return;
 
3567
      return FALSE;
2973
3568
    }
2974
3569
    else
2975
3570
    {
2987
3582
    {
2988
3583
      /* use region name for protein name */
2989
3584
      prp->name->data.ptrvalue = sfp->data.value.ptrvalue;
2990
 
      switch (toFeatSubType) 
 
3585
      switch (featdef_to) 
2991
3586
      {
2992
3587
        case FEATDEF_PROT :
2993
3588
          prp->processed = 0;
3012
3607
      sfp->data.choice = SEQFEAT_PROT;
3013
3608
    }
3014
3609
  }  
 
3610
  return TRUE;
3015
3611
}
3016
3612
 
3017
3613
extern EnumFieldAssoc  enum_bond_alist [];
3038
3634
 {"function", Class_text},
3039
3635
 {"gene", Class_text}, 
3040
3636
 {"gdb_xref", Class_text},
3041
 
 {"insertion_seq", Class_text},
3042
3637
 {"label", Class_token},
3043
3638
 {"map", Class_text},
 
3639
 {"mobile_element", Class_text}, 
3044
3640
 {"mod_base", Class_token}, {"note", Class_note},
3045
3641
 {"number", Class_number}, 
3046
3642
#ifdef INTERNAL_NCBI_SEQUIN
3047
3643
 {"old_locus_tag", Class_text},
3048
3644
#endif
 
3645
 {"operon", Class_text},
3049
3646
 {"organism", Class_text},
3050
3647
 {"partial", Class_none}, {"PCR_conditions", Class_text},
3051
3648
 {"phenotype", Class_text},
3057
3654
 {"sequenced_mol", Class_text},
3058
3655
 {"standard_name", Class_text},
3059
3656
 {"translation", Class_text}, {"transl_except", Class_pos_aa},
3060
 
 {"transl_table", Class_int}, {"transposon", Class_text},
 
3657
 {"transl_table", Class_int},
3061
3658
 {"usedin", Class_token},
3062
3659
 {"focus", Class_none},
3063
3660
 {"protein_id", Class_text},
3071
3668
#define QUAL_EVIDENCE 13
3072
3669
#define QUAL_EXPERIMENT 15
3073
3670
 
3074
 
static ENUM_ALIST(subsource_and_orgmod_subtype_alistX)
3075
 
  {" ",                       0},
3076
 
  {"Acronym",                19},
3077
 
  {"Anamorph",               29},
3078
 
  {"Authority",              24},
3079
 
  {"Biotype",                14},
3080
 
  {"Biovar",                 13},
3081
 
  {"Breed",                  31},
3082
 
  {"Cell-line",             108},
3083
 
  {"Cell-type",             109},
3084
 
  {"Chemovar",               12},
3085
 
  {"Chromosome",            101},
3086
 
  {"Clone",                 103},
3087
 
  {"Clone-lib",             111},
3088
 
  {"Collected-by",          131},
3089
 
  {"Collection-date",       130},
3090
 
  {"Common",                 18},
3091
 
  {"Country",               123},
3092
 
  {"Cultivar",               10},
3093
 
  {"Dev-stage",             112},
3094
 
  {"Dosage",                 20},
3095
 
  {"Ecotype",                27},
3096
 
  {"Endogenous-virus-name", 125},
3097
 
  {"Environmental-sample",  127},
3098
 
  {"Forma",                  25},
3099
 
  {"Forma-specialis",        26},
3100
 
  {"Frequency",             113},
3101
 
  {"Fwd-PCR-primer-name",   135},
3102
 
  {"Fwd-PCR-primer-seq",    133},
3103
 
  {"Genotype",              106},
3104
 
  {"Germline",              114},
3105
 
  {"Group",                  15},
3106
 
  {"Haplotype",             105},
3107
 
  {"Identified_by",         132},
3108
 
  {"Ins-seq-name",          121},
3109
 
  {"Isolate",                17},
3110
 
  {"Isolation-source",      128},
3111
 
  {"Lab-host",              116},
3112
 
  {"Lat-lon",               129},
3113
 
  {"Map",                   102},
3114
 
  {"Note - OrgMod",          55},
3115
 
  {"Note - SubSource",      155},
3116
 
  {"Old Lineage",            53}, /* 253 */
3117
 
  {"Old Name",               54}, /* 254 */
3118
 
  {"Pathovar",               11},
3119
 
  {"Plasmid-name",          119},
3120
 
  {"Plastid-name",          122},
3121
 
  {"Pop-variant",           117},
3122
 
  {"Rearranged",            115},
3123
 
  {"Rev-PCR-primer-name",   136},
3124
 
  {"Rev-PCR-primer-seq",    134},
3125
 
  {"Segment",               124},
3126
 
  {"Serogroup",               8},
3127
 
  {"Serotype",                7},
3128
 
  {"Serovar",                 9},
3129
 
  {"Sex",                   107},
3130
 
  {"Specific-host",          21},
3131
 
  {"Specimen-voucher",       23},
3132
 
  {"Strain",                  2},
3133
 
  {"Sub-species",            22},
3134
 
  {"Subclone",              104},
3135
 
  {"Subgroup",               16},
3136
 
  {"Substrain",               3},
3137
 
  {"Subtype",                 5},
3138
 
  {"Synonym",                28},
3139
 
  {"Teleomorph",             30},
3140
 
  {"Tissue-lib",            118},
3141
 
  {"Tissue-type",           110},
3142
 
  {"Transgenic",            126},
3143
 
  {"Transposon-name",       120},
3144
 
  {"Type",                    4},
3145
 
  {"Variety",                 6},
3146
 
END_ENUM_ALIST
3147
3671
 
3148
3672
static ENUM_ALIST(biosource_genome_alistX)
3149
3673
  {" ",                    0},
3294
3818
 
3295
3819
extern Uint1 FindTypeForModNameText (CharPtr cp)
3296
3820
{
3297
 
  EnumFieldAssocPtr  ap;
3298
 
  
3299
 
  for (ap = subsource_and_orgmod_subtype_alistX; ap->name != NULL; ap++) 
3300
 
  {
3301
 
    if (DoModNamesMatch (ap->name, cp))
3302
 
    {
3303
 
      return ap->value;
 
3821
  Uint1 subtype;
 
3822
 
 
3823
  subtype = EquivalentSubSource (cp);
 
3824
  if (subtype == 0) {
 
3825
    subtype = EquivalentOrgMod (cp);
 
3826
    if (subtype > 200) {
 
3827
      /* function that calls this expects less than 100 vals for orgmod */
 
3828
      /* need to adjust for old-lineage and old-name */
 
3829
      subtype -= 200;
3304
3830
    }
3305
 
  }
3306
 
  return 255;
 
3831
  } else {
 
3832
    /* function that calls this uses >100 to decide if subsource */
 
3833
    subtype += 100;
 
3834
  }
 
3835
  if (subtype == 0) {
 
3836
    subtype = SUBSRC_other;
 
3837
  }
 
3838
  return subtype;
3307
3839
}
3308
3840
 
3309
3841
static CharPtr GetValueNameFromEnum (Int4 val, EnumFieldAssocPtr list)
3447
3979
  }
3448
3980
}
3449
3981
 
3450
 
static void LocationConstraintClearText (LocationConstraintPtr lcp)
 
3982
static void LocationConstraintXClearText (LocationConstraintXPtr lcp)
3451
3983
{
3452
3984
  if (lcp != NULL)
3453
3985
  {
3456
3988
  }
3457
3989
}
3458
3990
 
3459
 
static LocationConstraintPtr LocationConstraintFree (LocationConstraintPtr lcp)
 
3991
static LocationConstraintXPtr LocationConstraintXFree (LocationConstraintXPtr lcp)
3460
3992
{
3461
3993
  lcp = MemFree (lcp);
3462
3994
  return lcp;
3463
3995
}
3464
3996
 
3465
 
static LocationConstraintPtr LocationConstraintCopy (LocationConstraintPtr lcp)
 
3997
static LocationConstraintXPtr LocationConstraintXCopy (LocationConstraintXPtr lcp)
3466
3998
{
3467
 
  LocationConstraintPtr lcp_new;
 
3999
  LocationConstraintXPtr lcp_new;
3468
4000
  if (lcp == NULL)
3469
4001
  {
3470
4002
    return NULL;
3471
4003
  }
3472
 
  lcp_new = (LocationConstraintPtr) MemNew (sizeof (LocationConstraintData));
 
4004
  lcp_new = (LocationConstraintXPtr) MemNew (sizeof (LocationConstraintXData));
3473
4005
  if (lcp_new != NULL)
3474
4006
  {
3475
4007
    lcp_new->left = lcp->left;
3482
4014
  return lcp_new;
3483
4015
}
3484
4016
 
3485
 
extern StringConstraintPtr StringConstraintFree (StringConstraintPtr scp)
 
4017
extern StringConstraintXPtr StringConstraintXFree (StringConstraintXPtr scp)
3486
4018
{
3487
4019
  if (scp == NULL) return NULL;
3488
4020
  scp->match_text = MemFree (scp->match_text);
3490
4022
  return scp;  
3491
4023
}
3492
4024
 
3493
 
static void StringConstraintClearText (StringConstraintPtr scp)
 
4025
static void StringConstraintClearText (StringConstraintXPtr scp)
3494
4026
{
3495
4027
  if (scp != NULL)
3496
4028
  {
3498
4030
  }
3499
4031
}
3500
4032
 
3501
 
static StringConstraintPtr StringConstraintCopy (StringConstraintPtr scp)
 
4033
static StringConstraintXPtr StringConstraintCopy (StringConstraintXPtr scp)
3502
4034
{
3503
 
  StringConstraintPtr scp_new;
 
4035
  StringConstraintXPtr scp_new;
3504
4036
  if (scp == NULL)
3505
4037
  {
3506
4038
    return NULL;
3507
4039
  }
3508
4040
  
3509
 
  scp_new = (StringConstraintPtr) MemNew (sizeof (StringConstraintData));
 
4041
  scp_new = (StringConstraintXPtr) MemNew (sizeof (StringConstraintData));
3510
4042
  if (scp_new != NULL)
3511
4043
  {
3512
4044
    scp_new->match_text = StringSave (scp->match_text);
3537
4069
{
3538
4070
  if (scp == NULL) return NULL;
3539
4071
  scp->qual_choice = ValNodeFuncFree (scp->qual_choice, scp->free_vn_proc);
3540
 
  scp->string_constraint = StringConstraintFree (scp->string_constraint);
 
4072
  scp->qual_choice_match = ValNodeFuncFree (scp->qual_choice, scp->free_vn_proc);
 
4073
  scp->string_constraint = StringConstraintXFree (scp->string_constraint);
3541
4074
  scp->pseudo_constraint = MemFree (scp->pseudo_constraint);
3542
4075
  scp = MemFree (scp);
3543
4076
  return scp;
3569
4102
  {
3570
4103
    ccp_new->constraint_type = ccp->constraint_type;
3571
4104
    ccp_new->qual_choice = QualChoiceCopy (ccp->qual_choice, ccp->copy_vn_proc);
 
4105
    ccp_new->qual_choice_match = QualChoiceCopy (ccp->qual_choice_match, ccp->copy_vn_proc);
3572
4106
    ccp_new->string_constraint = StringConstraintCopy (ccp->string_constraint);
3573
4107
    ccp_new->copy_vn_proc = ccp->copy_vn_proc;
3574
4108
    ccp_new->free_vn_proc = ccp->free_vn_proc;
3591
4125
  {
3592
4126
    StringConstraintClearText (fsp->scp);
3593
4127
    ChoiceConstraintClearText (fsp->ccp);
3594
 
    LocationConstraintClearText (fsp->lcp);
 
4128
    LocationConstraintXClearText (fsp->lcp);
 
4129
    StringConstraintClearText (fsp->id_list);
3595
4130
  }
3596
4131
}
3597
4132
 
3605
4140
    fsp_new->ccp = NULL;
3606
4141
    fsp_new->lcp = NULL;
3607
4142
    fsp_new->cgp = NULL;
 
4143
    fsp_new->id_list = NULL;
3608
4144
  }
3609
4145
  return fsp_new;
3610
4146
}
3613
4149
{
3614
4150
  if (fsp != NULL)
3615
4151
  {
3616
 
    fsp->scp = StringConstraintFree (fsp->scp);
 
4152
    fsp->scp = StringConstraintXFree (fsp->scp);
3617
4153
    fsp->ccp = ChoiceConstraintFree (fsp->ccp);
3618
 
    fsp->lcp = LocationConstraintFree (fsp->lcp);
 
4154
    fsp->lcp = LocationConstraintXFree (fsp->lcp);
3619
4155
    fsp->cgp = ChoiceConstraintFree (fsp->cgp);
 
4156
    fsp->id_list = StringConstraintXFree (fsp->id_list);
3620
4157
    fsp = MemFree (fsp);
3621
4158
  }
3622
4159
  return fsp;
3635
4172
  {
3636
4173
    fsp_new->scp = StringConstraintCopy (fsp->scp);
3637
4174
    fsp_new->ccp = ChoiceConstraintCopy (fsp->ccp);
3638
 
    fsp_new->lcp = LocationConstraintCopy (fsp->lcp);
 
4175
    fsp_new->lcp = LocationConstraintXCopy (fsp->lcp);
3639
4176
    fsp_new->cgp = ChoiceConstraintCopy (fsp->cgp);
 
4177
    fsp_new->id_list = StringConstraintCopy (fsp->id_list);
3640
4178
  }
3641
4179
  return fsp_new;
3642
4180
}
3706
4244
#define PARSE_FIELD_BIOSRC_STRING 2
3707
4245
#define PARSE_FIELD_SOURCE_QUAL   3
3708
4246
#define PARSE_FIELD_GENE_FIELD    4
3709
 
#define PARSE_FIELD_MRNA_FIELD    5
 
4247
#define PARSE_FIELD_RNA_FIELD    5
3710
4248
#define PARSE_FIELD_CDS_COMMENT   6
3711
4249
#define PARSE_FIELD_PROTEIN_FIELD 7
3712
4250
#define PARSE_FIELD_IMPORT_QUAL   8
3713
4251
#define PARSE_FIELD_FEATURE_NOTE  9
3714
4252
#define PARSE_FIELD_COMMENT_DESC  10
 
4253
#define PARSE_FIELD_DBXREF        11
3715
4254
 
3716
 
#define MAX_PARSE_FIELD_TYPE   10
 
4255
#define MAX_PARSE_FIELD_TYPE   11
 
4256
#define SEARCH_FIELD_PUBLICATION  12
3717
4257
 
3718
4258
#define PARSE_FIELD_FIRST_FEATURE 4
3719
4259
#define PARSE_FIELD_LAST_FEATURE  9
3720
4260
 
3721
 
extern Boolean DoesLocationMatchConstraint (SeqLocPtr slp, LocationConstraintPtr lcp);
 
4261
extern Boolean DoesLocationMatchConstraint (SeqLocPtr slp, LocationConstraintXPtr lcp);
3722
4262
 
3723
4263
typedef struct acceptpolicy 
3724
4264
{
3972
4512
  type_list[sfp->idx.subtype] = TRUE;
3973
4513
}
3974
4514
 
 
4515
 
 
4516
static void AddFeatureToList (ValNodePtr PNTR list, FeatDefPtr curr)
 
4517
{
 
4518
  Char        str [256];
 
4519
 
 
4520
  if (list == NULL || curr == NULL) return;
 
4521
  
 
4522
  if (curr->featdef_key == FEATDEF_PUB)
 
4523
  {
 
4524
    StringNCpy_0 (str, curr->typelabel, sizeof (str) - 15);
 
4525
    StringCat (str, " (Publication)");
 
4526
    ValNodeAddPointer (list, curr->featdef_key, StringSave (str));
 
4527
  }
 
4528
  else if (curr->featdef_key == FEATDEF_BIOSRC)
 
4529
  {
 
4530
    ValNodeAddPointer (list, FEATDEF_BIOSRC, StringSave ("BioSource"));
 
4531
  }
 
4532
  else if (curr->featdef_key == FEATDEF_otherRNA)
 
4533
  {
 
4534
    ValNodeAddPointer (list, FEATDEF_otherRNA, StringSave ("misc_RNA"));
 
4535
  }
 
4536
  else if (curr->featdef_key == FEATDEF_misc_RNA ||
 
4537
           curr->featdef_key == FEATDEF_precursor_RNA ||
 
4538
           curr->featdef_key == FEATDEF_mat_peptide ||
 
4539
           curr->featdef_key == FEATDEF_sig_peptide ||
 
4540
           curr->featdef_key == FEATDEF_transit_peptide ||
 
4541
           curr->featdef_key == FEATDEF_Imp_CDS)
 
4542
  {
 
4543
    StringNCpy_0 (str, curr->typelabel, sizeof (str) - 10);
 
4544
    StringCat (str, "_imp");
 
4545
    ValNodeAddPointer (list, curr->featdef_key, StringSave (str));
 
4546
  }
 
4547
  else
 
4548
  {
 
4549
    ValNodeAddPointer (list, curr->featdef_key, StringSave (curr->typelabel));
 
4550
  }
 
4551
}
 
4552
 
3975
4553
extern ValNodePtr BuildFeatureDialogList (Boolean list_most_used_first, SeqEntryPtr sep)
3976
4554
{
3977
4555
  ValNodePtr  feature_choice_list = NULL;
3978
4556
  ValNodePtr  import_feature_list = NULL;
3979
4557
  ValNodePtr  least_liked_feature_list = NULL;
3980
4558
  ValNodePtr  most_used_feature_list = NULL;
 
4559
  ValNodePtr  unused_list = NULL;
3981
4560
  FeatDefPtr  curr;
3982
4561
  Uint1       key;
3983
4562
  CharPtr     label = NULL;
3984
 
  Char        str [256];
3985
4563
  Boolean     feature_type_list[256];
3986
4564
  Boolean     only_most_used = TRUE;
3987
4565
  Int4        i;
4002
4580
    if (key == FEATDEF_BAD
4003
4581
        || key == FEATDEF_Imp_CDS
4004
4582
        || key == FEATDEF_source
4005
 
        || key == FEATDEF_ORG
4006
 
        || !feature_type_list[key])
4007
 
    {
4008
 
      curr = FeatDefFindNext (curr, &key, &label, FEATDEF_ANY, TRUE);
4009
 
      continue;
4010
 
    }
4011
 
      
4012
 
    if (curr->featdef_key == FEATDEF_PUB)
4013
 
    {
4014
 
      StringNCpy_0 (str, curr->typelabel, sizeof (str) - 15);
4015
 
      StringCat (str, " (Publication)");
4016
 
      ValNodeAddPointer (&feature_choice_list, curr->featdef_key, StringSave (str));
4017
 
    }
4018
 
    else if (curr->featdef_key == FEATDEF_BIOSRC)
4019
 
    {
4020
 
      ValNodeAddPointer (&feature_choice_list, FEATDEF_BIOSRC, StringSave ("BioSource"));
4021
 
    }
4022
 
    else if (curr->featdef_key == FEATDEF_otherRNA)
4023
 
    {
4024
 
      ValNodeAddPointer (&feature_choice_list, FEATDEF_otherRNA, StringSave ("misc_RNA"));
4025
 
      if (list_most_used_first)
4026
 
      {
4027
 
        /* also add to most used list */
4028
 
        ValNodeAddPointer (&most_used_feature_list, curr->featdef_key, 
4029
 
                           StringSave ("misc_RNA"));
 
4583
        || key == FEATDEF_ORG)
 
4584
    {
 
4585
      curr = FeatDefFindNext (curr, &key, &label, FEATDEF_ANY, TRUE);
 
4586
      continue;
 
4587
    }
 
4588
    else if (!feature_type_list[key]) 
 
4589
    {
 
4590
      AddFeatureToList (&unused_list, curr);
 
4591
      curr = FeatDefFindNext (curr, &key, &label, FEATDEF_ANY, TRUE);
 
4592
      continue;
 
4593
    }
 
4594
    
 
4595
    if (curr->featdef_key == FEATDEF_otherRNA) {
 
4596
      AddFeatureToList (&feature_choice_list, curr);
 
4597
      if (list_most_used_first) {
 
4598
        AddFeatureToList (&most_used_feature_list, curr);
4030
4599
      }
4031
4600
    }
4032
4601
    else if (curr->featdef_key == FEATDEF_misc_RNA ||
4036
4605
            curr->featdef_key == FEATDEF_transit_peptide ||
4037
4606
            curr->featdef_key == FEATDEF_Imp_CDS)
4038
4607
    {
4039
 
      StringNCpy_0 (str, curr->typelabel, sizeof (str) - 10);
4040
 
      StringCat (str, "_imp");
4041
 
      ValNodeAddPointer (&import_feature_list, curr->featdef_key, StringSave (str));
 
4608
      AddFeatureToList (&import_feature_list, curr);
4042
4609
    }
4043
4610
    else if (curr->featdef_key == FEATDEF_TXINIT)
4044
4611
    {
4045
 
      ValNodeAddPointer (&least_liked_feature_list, FEATDEF_TXINIT, StringSave (curr->typelabel));
 
4612
      AddFeatureToList (&least_liked_feature_list, curr);
4046
4613
    }
4047
4614
    else
4048
4615
    {
4080
4647
                                     CompareFeatureValNodeStrings);
4081
4648
  least_liked_feature_list = SortValNode (least_liked_feature_list,
4082
4649
                                          CompareFeatureValNodeStrings);
 
4650
  unused_list = SortValNode (unused_list, CompareFeatureValNodeStrings);       
4083
4651
 
4084
4652
  if (most_used_feature_list != NULL && only_most_used) {
4085
4653
    feature_choice_list = ValNodeFreeData (feature_choice_list);
4091
4659
    feature_choice_list = ValNodeAppend (feature_choice_list, least_liked_feature_list);
4092
4660
    feature_choice_list = ValNodeAppend (feature_choice_list, import_feature_list);
4093
4661
  }
 
4662
  feature_choice_list = ValNodeAppend (feature_choice_list, unused_list);
4094
4663
  
4095
4664
  return feature_choice_list;
4096
4665
}
4257
4826
  return FeatureSelectionDialogEx(h, allow_multi, NULL, change_notify, change_userdata);
4258
4827
}
4259
4828
 
 
4829
extern DialoG
 
4830
DescriptorSelectionDialog
 
4831
(GrouP                    h,
 
4832
 Boolean                  allow_multi,
 
4833
 Nlm_ChangeNotifyProc     change_notify,
 
4834
 Pointer                  change_userdata)
 
4835
{
 
4836
  ValNodePtr descriptor_list = BuildDescriptorValNodeList ();
 
4837
  return ValNodeSelectionDialogEx (h, descriptor_list, TALL_SELECTION_LIST,
 
4838
                                ValNodeStringName,
 
4839
                                ValNodeSimpleDataFree, ValNodeStringCopy,
 
4840
                                ValNodeChoiceMatch, "descriptor list", 
 
4841
                                change_notify, change_userdata, allow_multi, FALSE,
 
4842
                                NULL);
 
4843
}
 
4844
 
 
4845
 
4260
4846
extern CharPtr SourceQualValNodeName (ValNodePtr vnp)
4261
4847
{
4262
4848
  SourceQualDescPtr           sqdp;
4351
4937
 Nlm_ChangeNotifyProc     change_notify,
4352
4938
 Pointer                  change_userdata,
4353
4939
 Int2                     list_height,
 
4940
 Boolean                  show_discouraged,
4354
4941
 Boolean                  show_discontinued)
4355
4942
 
4356
4943
{
4362
4949
    qual_choice_list = ValNodeNew (NULL);
4363
4950
    qual_choice_list->choice = 1;
4364
4951
    qual_choice_list->data.ptrvalue = StringSave ("All Notes");
4365
 
    qual_choice_list->next = GetSourceQualDescList (TRUE, TRUE, show_discontinued);
 
4952
    qual_choice_list->next = GetSourceQualDescList (TRUE, TRUE, show_discouraged, show_discontinued);
4366
4953
  }
4367
4954
  else
4368
4955
  {
4369
 
    qual_choice_list = GetSourceQualDescList (TRUE, TRUE, show_discontinued);
 
4956
    qual_choice_list = GetSourceQualDescList (TRUE, TRUE, show_discouraged, show_discontinued);
4370
4957
  }
4371
4958
  /* note - the ValNodeSelectionDialog will free the qual_choice_list when done */                                            
4372
4959
  dlg = ValNodeSelectionDialog (h, qual_choice_list, list_height, SourceQualValNodeName,
4385
4972
 
4386
4973
{
4387
4974
  return SourceQualTypeSelectionDialogEx (h, allow_multi, change_notify,
4388
 
                                          change_userdata, 6, FALSE);
 
4975
                                          change_userdata, 6, FALSE, FALSE);
4389
4976
}
4390
4977
 
4391
4978
static DialoG SourceQualTypeDiscSelectionDialog 
4396
4983
 
4397
4984
{
4398
4985
  return SourceQualTypeSelectionDialogEx (h, allow_multi, change_notify,
4399
 
                                          change_userdata, 6, TRUE);
 
4986
                                          change_userdata, 6, TRUE, TRUE);
4400
4987
}
4401
4988
 
4402
4989
static DialoG SourceQualTypeConstraintSelectionDialog
4407
4994
 
4408
4995
{
4409
4996
  return SourceQualTypeSelectionDialogEx (h, allow_multi, change_notify,
4410
 
                                          change_userdata, 4, TRUE);
 
4997
                                          change_userdata, 4, TRUE, FALSE);
4411
4998
}
4412
4999
 
4413
5000
static DialoG SourceStringConstraintSelectionDialog
4424
5011
  
4425
5012
  ValNodeAddPointer (&qual_choice_list, 1, StringSave ("Organism or Any Qual"));
4426
5013
  ValNodeAddPointer (&qual_choice_list, 1, StringSave ("Organism"));
4427
 
  qual_choice_list->next->next = GetSourceQualDescList (TRUE, TRUE, TRUE);
 
5014
  qual_choice_list->next->next = GetSourceQualDescList (TRUE, TRUE, TRUE, FALSE);
4428
5015
  ValNodeAddPointer (&qual_choice_list, 1, StringSave ("Lineage"));
 
5016
  ValNodeAddPointer (&qual_choice_list, 1, StringSave ("Location"));
4429
5017
 
4430
5018
  /* note - the ValNodeSelectionDialog will free the qual_choice_list when done */                                            
4431
5019
  dlg = ValNodeSelectionDialog (h, qual_choice_list, 4, SourceQualValNodeName,
4460
5048
    return TRUE;
4461
5049
  }
4462
5050
  
4463
 
  if (DoesStringMatchConstraint (mod->subname, fsp->ccp->string_constraint))
 
5051
  if (DoesStringMatchConstraintX (mod->subname, fsp->ccp->string_constraint))
4464
5052
  {
4465
5053
    if (fsp->ccp->string_constraint->not_present)
4466
5054
    {
4507
5095
  {
4508
5096
    return TRUE;
4509
5097
  }
4510
 
  if (DoesStringMatchConstraint (ssp->name, fsp->ccp->string_constraint))
 
5098
  if (DoesStringMatchConstraintX (ssp->name, fsp->ccp->string_constraint))
4511
5099
  {
4512
5100
    if (fsp->ccp->string_constraint->not_present)
4513
5101
    {
4531
5119
  }
4532
5120
}
4533
5121
 
 
5122
 
 
5123
static CharPtr GetSubfield (CharPtr str, Uint1 subfield)
 
5124
{
 
5125
  CharPtr cp, cp2;
 
5126
  Int4    num_colons = 0;
 
5127
  CharPtr new_val = NULL;
 
5128
 
 
5129
  if (StringHasNoText (str)) {
 
5130
    return NULL;
 
5131
  }
 
5132
 
 
5133
  cp = StringChr (str, ':');
 
5134
  while (cp != NULL) {
 
5135
    num_colons ++;
 
5136
    cp = StringChr (cp + 1, ':');
 
5137
  }
 
5138
 
 
5139
  if (subfield == 0) {
 
5140
    new_val = StringSave (str);
 
5141
  } else if (subfield == 1) {
 
5142
    if (num_colons == 0) {
 
5143
      return NULL;
 
5144
    } else {
 
5145
      cp = StringChr (str, ':');
 
5146
      new_val = (CharPtr) MemNew (sizeof (Char) * (cp - str + 1));
 
5147
      StringNCpy (new_val, str, cp - str);
 
5148
      new_val[cp - str] = 0;
 
5149
    }
 
5150
  } else if (subfield == 2) {
 
5151
    if (num_colons == 0 || num_colons == 1) {
 
5152
      return NULL;
 
5153
    } else {
 
5154
      cp = StringChr (str, ':');
 
5155
      cp2 = StringChr (cp + 1, ':');
 
5156
      new_val = (CharPtr) MemNew (sizeof (Char) * (cp2 - cp));
 
5157
      StringNCpy (new_val, cp + 1, cp2 - cp - 1);
 
5158
      new_val[cp2 - cp - 1] = 0;
 
5159
    }
 
5160
  } else {
 
5161
    if (num_colons == 0) {
 
5162
      new_val = StringSave (str);
 
5163
    } else {
 
5164
      cp = StringRChr (str, ':');
 
5165
      new_val = StringSave (cp + 1);
 
5166
    }
 
5167
  }
 
5168
  return new_val;
 
5169
}
 
5170
 
 
5171
 
4534
5172
static CharPtr 
4535
5173
GetSourceQualQualValueFromBiop 
4536
5174
(BioSourcePtr      biop,
4537
5175
 SourceQualDescPtr sqdp,
4538
5176
 FilterSetPtr      fsp)
4539
5177
{
4540
 
  CharPtr            str = NULL, tmp_str;
 
5178
  CharPtr            str = NULL, field, tmp_str;
4541
5179
  OrgModPtr          mod;
4542
5180
  SubSourcePtr       ssp;
4543
5181
  
4557
5195
            && !StringHasNoText (mod->subname)
4558
5196
            && OrgModSpecialMatch (mod, fsp))
4559
5197
        {
4560
 
          if (str == NULL) {
4561
 
            str = StringSave (mod->subname);
 
5198
          field = GetSubfield (mod->subname, sqdp->subfield);
 
5199
          if (!StringHasNoText (field)) {
 
5200
            if (str == NULL) {
 
5201
              str = field;
 
5202
            } else {
 
5203
              tmp_str = (CharPtr) MemNew ((StringLen (str) + StringLen (field) + 3) * sizeof (Char));
 
5204
              StringCpy (tmp_str, str);
 
5205
              StringCat (tmp_str, "; ");
 
5206
              StringCat (tmp_str, field);
 
5207
              field = MemFree (field);
 
5208
              str = MemFree (str);
 
5209
              str = tmp_str;
 
5210
            }
4562
5211
          } else {
4563
 
            tmp_str = (CharPtr) MemNew ((StringLen (str) + StringLen (mod->subname) + 3) * sizeof (Char));
4564
 
            StringCpy (tmp_str, str);
4565
 
            StringCat (tmp_str, "; ");
4566
 
            StringCat (tmp_str, mod->subname);
4567
 
            str = MemFree (str);
4568
 
            str = tmp_str;
 
5212
            field = MemFree (field);
4569
5213
          }
4570
5214
        }
4571
5215
        mod = mod->next;
4581
5225
          && !StringHasNoText (ssp->name)
4582
5226
          && SubSrcSpecialMatch (ssp, fsp))
4583
5227
      {
 
5228
        field = GetSubfield (ssp->name, sqdp->subfield);
 
5229
        if (!StringHasNoText (field)) {
4584
5230
          if (str == NULL) {
4585
 
            str = StringSave (ssp->name);
 
5231
            str = field;
4586
5232
          } else {
4587
 
            tmp_str = (CharPtr) MemNew ((StringLen (str) + StringLen (ssp->name) + 3) * sizeof (Char));
 
5233
            tmp_str = (CharPtr) MemNew ((StringLen (str) + StringLen (field) + 3) * sizeof (Char));
4588
5234
            StringCpy (tmp_str, str);
4589
5235
            StringCat (tmp_str, "; ");
4590
 
            StringCat (tmp_str, ssp->name);
 
5236
            StringCat (tmp_str, field);
 
5237
            field = MemFree (field);
4591
5238
            str = MemFree (str);
4592
5239
            str = tmp_str;
4593
5240
          }
 
5241
        } else {
 
5242
          field = MemFree (field);
 
5243
        }
4594
5244
      }
4595
5245
      ssp = ssp->next;
4596
5246
    }
4896
5546
  }
4897
5547
  
4898
5548
  if (avp->etp == NULL 
4899
 
      || avp->etp->existing_text_choice == EXISTING_TEXT_CHOICE_REPLACE_OLD
 
5549
      || avp->etp->existing_text_choice == eExistingTextChoiceReplaceOld
4900
5550
      || biop->genome == 0)
4901
5551
  {
4902
5552
    biop->genome = avp->field_list->choice;
4956
5606
  }
4957
5607
  
4958
5608
  if (avp->etp == NULL 
4959
 
      || avp->etp->existing_text_choice == EXISTING_TEXT_CHOICE_REPLACE_OLD
 
5609
      || avp->etp->existing_text_choice == eExistingTextChoiceReplaceOld
4960
5610
      || biop->origin == 0)
4961
5611
  {
4962
5612
    biop->origin = avp->field_list->choice;
5011
5661
static void ApplyStringToSource (BioSourcePtr biop, Pointer userdata)
5012
5662
{
5013
5663
  ApplyValuePtr         avp;
5014
 
  Boolean               found = FALSE;
5015
5664
 
5016
5665
  if (biop == NULL || userdata == NULL)
5017
5666
  {
5030
5679
    {
5031
5680
      biop->org = OrgRefNew();
5032
5681
    }
5033
 
    if (avp->field_list->choice == 3
5034
 
        || avp->field_list->choice == 4)
 
5682
    if (biop->org->orgname == NULL 
 
5683
        && (avp->field_list->choice == 3
 
5684
            || avp->field_list->choice == 4))
5035
5685
    {
5036
5686
      biop->org->orgname = OrgNameNew ();
5037
5687
    }
5126
5776
 
5127
5777
static void RemoveSourceQualFromBioSource (BioSourcePtr biop, Pointer userdata, FilterSetPtr fsp);
5128
5778
 
 
5779
static CharPtr RemoveSubfield (CharPtr orig, Uint1 subfield)
 
5780
{
 
5781
  CharPtr cp, cp2;
 
5782
  Int4    num_colons = 0;
 
5783
  CharPtr new_val;
 
5784
 
 
5785
  cp = StringChr (orig, ':');
 
5786
  while (cp != NULL) {
 
5787
    num_colons ++;
 
5788
    cp = StringChr (cp + 1, ':');
 
5789
  }
 
5790
  new_val = orig;
 
5791
 
 
5792
  if (subfield == 0) {
 
5793
    new_val = MemFree (new_val);
 
5794
  } else if (subfield == 1) {
 
5795
    if (num_colons == 0) {
 
5796
      /* no INST, just specID, nothing to remove */
 
5797
    } else if (num_colons == 1) {
 
5798
      cp = StringChr (orig, ':');
 
5799
      new_val = StringSave (cp + 1);
 
5800
      orig = MemFree (orig);
 
5801
    } else {
 
5802
      cp = StringChr (orig, ':');
 
5803
      new_val = StringSave (cp);
 
5804
      orig = MemFree (orig);
 
5805
    }
 
5806
  } else if (subfield == 2) {
 
5807
    if (num_colons == 0 || num_colons == 1) {
 
5808
      /* no COLL, nothing to remove */
 
5809
    } else {
 
5810
      cp = StringChr (orig, ':');
 
5811
      cp2 = StringChr (cp + 1, ':');
 
5812
      new_val = (CharPtr) MemNew (sizeof (Char) * (cp - orig + StringLen (cp2) + 1));
 
5813
      StringNCpy (new_val, orig, cp - orig);
 
5814
      StringCat (new_val, cp2);
 
5815
      orig = MemFree (orig);
 
5816
      if (StringCmp (new_val, ":") == 0) {
 
5817
        new_val = MemFree (new_val);
 
5818
      }
 
5819
    }
 
5820
  } else {
 
5821
    /* specid */
 
5822
    if (num_colons == 0) {
 
5823
      new_val = MemFree (new_val);
 
5824
    } else {
 
5825
      cp = StringRChr (new_val, ':');
 
5826
      *(cp + 1) = 0;
 
5827
    }
 
5828
  }
 
5829
  return new_val;
 
5830
}
 
5831
 
 
5832
 
 
5833
static CharPtr ApplyToSubfield (CharPtr orig, ApplyValuePtr avp, Uint1 subfield)
 
5834
{
 
5835
  CharPtr cp, cp2;
 
5836
  Int4    num_colons = 0, len;
 
5837
  CharPtr new_field, new_val;
 
5838
 
 
5839
  cp = StringChr (orig, ':');
 
5840
  while (cp != NULL) {
 
5841
    num_colons ++;
 
5842
    cp = StringChr (cp + 1, ':');
 
5843
  }
 
5844
 
 
5845
  new_val = orig;
 
5846
  if (subfield == 0) {
 
5847
    /* whole field */
 
5848
    new_val = HandleApplyValue (orig, avp);
 
5849
  } else if (subfield == 1) {
 
5850
    /* INST */
 
5851
    if (num_colons == 0) {
 
5852
      /* all we have is the specID, we are adding INST */
 
5853
      new_field = HandleApplyValue (NULL, avp);
 
5854
      if (!StringHasNoText (new_field)) {
 
5855
        new_val = (CharPtr) MemNew (sizeof (Char) * (StringLen (new_field) + StringLen (orig) + 2));
 
5856
        sprintf (new_val, "%s:%s", new_field, orig == NULL ? "" : orig);
 
5857
        orig = MemFree (orig);
 
5858
      } else {
 
5859
        new_val = orig;
 
5860
      }
 
5861
      new_field = MemFree (new_field);
 
5862
    } else {
 
5863
      cp = StringChr (orig, ':');
 
5864
      len = cp - orig + 1;
 
5865
      new_field = (CharPtr) MemNew (sizeof (Char) * len);
 
5866
      StringNCpy (new_field, orig, len - 1);
 
5867
      new_field[len - 1] = 0;
 
5868
      new_field = HandleApplyValue (new_field, avp);
 
5869
      new_val = (CharPtr) MemNew (sizeof (Char) * (StringLen (new_field) + StringLen (cp) + 1));
 
5870
      sprintf (new_val, "%s%s", new_field == NULL ? "" : new_field, cp);
 
5871
      orig = MemFree (orig);
 
5872
      new_field = MemFree (new_field);
 
5873
    }
 
5874
  } else if (subfield == 2) {
 
5875
    /* COLL */
 
5876
    if (num_colons == 0) {
 
5877
      /* add blank INST, then COLL, then existing specID */
 
5878
      new_field = HandleApplyValue (NULL, avp);
 
5879
      if (!StringHasNoText (new_field)) {
 
5880
        new_val = (CharPtr) MemNew (sizeof (Char) * (3 + StringLen (new_field) +  StringLen (orig)));
 
5881
        sprintf (new_val, ":%s:%s", new_field, orig == NULL ? "" : orig);
 
5882
        orig = MemFree (orig);
 
5883
      } else {
 
5884
        new_val = orig;
 
5885
      }
 
5886
      new_field = MemFree (new_field);
 
5887
    } else if (num_colons == 1) {
 
5888
      /* have INST and specID */
 
5889
      new_field = HandleApplyValue (NULL, avp);
 
5890
      if (!StringHasNoText (new_field)) {
 
5891
        new_val = (CharPtr) MemNew (sizeof (Char) * (3 + StringLen (new_field) +  StringLen (orig)));
 
5892
        cp = StringChr (orig, ':');
 
5893
        len = cp - orig;
 
5894
        StringNCpy (new_val, orig, len);
 
5895
        StringCat (new_val, ":");
 
5896
        StringCat (new_val, new_field);
 
5897
        StringCat (new_val, cp);
 
5898
        orig = MemFree (orig);
 
5899
      } else {
 
5900
        new_val = orig;
 
5901
      }
 
5902
      new_field = MemFree (new_field);
 
5903
    } else {
 
5904
      cp = StringChr (orig, ':');
 
5905
      cp2 = StringChr (cp + 1, ':');
 
5906
      len = cp2 - cp;
 
5907
      new_field = (CharPtr) MemNew (sizeof (Char) * len);
 
5908
      StringNCpy (new_field, cp + 1, len - 1);
 
5909
      new_field[len - 1] = 0;
 
5910
      new_field = HandleApplyValue (new_field, avp);
 
5911
      new_val = (CharPtr) MemNew (sizeof (Char) * (cp - orig + 1 + StringLen (new_field) + StringLen (cp2) + 1));
 
5912
      StringNCpy (new_val, orig, cp - orig + 1);
 
5913
      StringCat (new_val, new_field);
 
5914
      StringCat (new_val, cp2);
 
5915
      orig = MemFree (orig);
 
5916
      new_field = MemFree (new_field);
 
5917
    }
 
5918
  } else {
 
5919
    /* specid */
 
5920
    if (num_colons == 0) {
 
5921
      new_val = HandleApplyValue (orig, avp);
 
5922
    } else {
 
5923
      cp = StringRChr (orig, ':');
 
5924
      new_field = StringSave (cp + 1);
 
5925
      new_field = HandleApplyValue (new_field, avp);
 
5926
      new_val = (CharPtr) MemNew (sizeof (Char) + (cp - orig + 1 + StringLen (new_field) + 1));
 
5927
      StringNCpy (new_val, orig, cp - orig + 1);
 
5928
      StringCat (new_val, new_field);
 
5929
      orig = MemFree (orig);
 
5930
      new_field = MemFree (new_field);
 
5931
    }
 
5932
  }
 
5933
  return new_val;
 
5934
}
 
5935
 
 
5936
 
5129
5937
static void ApplySourceQualBioSourceCallback (BioSourcePtr biop, Pointer userdata, FilterSetPtr fsp)
5130
5938
{
5131
5939
  ApplyValuePtr         avp;
5185
5993
        {
5186
5994
          if (!is_nontext)
5187
5995
          {
5188
 
            mod->subname = HandleApplyValue (mod->subname, avp); 
 
5996
            mod->subname = ApplyToSubfield (mod->subname, avp, sqdp->subfield);
5189
5997
          }
5190
5998
          found = TRUE;
5191
5999
        }
5202
6010
        }
5203
6011
        else
5204
6012
        {
5205
 
          mod->subname = StringSave (avp->new_text);
 
6013
          mod->subname = ApplyToSubfield (mod->subname, avp, sqdp->subfield);
5206
6014
        }
5207
6015
        if (last_mod == NULL)
5208
6016
        {
5224
6032
      {
5225
6033
        if (! is_nontext)
5226
6034
        {
5227
 
          ssp->name = HandleApplyValue (ssp->name, avp);
 
6035
          ssp->name = ApplyToSubfield (ssp->name, avp, sqdp->subfield);
5228
6036
        }
5229
6037
        found = TRUE;
5230
6038
      }
5241
6049
      }
5242
6050
      else
5243
6051
      {
5244
 
        ssp->name = StringSave (avp->new_text);
 
6052
        ssp->name = ApplyToSubfield (ssp->name, avp, sqdp->subfield);
5245
6053
      }
5246
6054
      if (last_ssp == NULL)
5247
6055
      {
5273
6081
  ApplySourceQualBioSourceCallback (sdp->data.ptrvalue, userdata, fsp);
5274
6082
}
5275
6083
 
5276
 
static void RemoveOrgModFromBioSource (BioSourcePtr biop, Uint1 subtype, FilterSetPtr fsp)
 
6084
static void RemoveOrgModFromBioSource (BioSourcePtr biop, Uint1 subtype, Uint1 subfield, FilterSetPtr fsp)
5277
6085
{
5278
6086
  OrgModPtr mod = NULL, prev_mod = NULL, next_mod;
5279
6087
  
5286
6094
      if (mod->subtype == subtype
5287
6095
          && OrgModSpecialMatch (mod, fsp))
5288
6096
      {
5289
 
        if (prev_mod == NULL)
5290
 
        {
5291
 
          biop->org->orgname->mod = mod->next;
5292
 
        }
5293
 
        else
5294
 
        {
5295
 
          prev_mod->next = mod->next;
5296
 
        }
5297
 
        mod->next = NULL;
5298
 
        OrgModFree (mod);
 
6097
        mod->subname = RemoveSubfield (mod->subname, subfield);
 
6098
        if (StringHasNoText (mod->subname)) {
 
6099
          if (prev_mod == NULL)
 
6100
          {
 
6101
            biop->org->orgname->mod = mod->next;
 
6102
          }
 
6103
          else
 
6104
          {
 
6105
            prev_mod->next = mod->next;
 
6106
          }
 
6107
          mod->next = NULL;
 
6108
          OrgModFree (mod);
 
6109
        } else {
 
6110
          prev_mod = mod;
 
6111
        }
5299
6112
      }
5300
6113
      else
5301
6114
      {
5306
6119
  }
5307
6120
}
5308
6121
 
5309
 
static void RemoveSubSourceFromBioSource (BioSourcePtr biop, Uint2 subtype, FilterSetPtr fsp)
 
6122
static void RemoveSubSourceFromBioSource (BioSourcePtr biop, Uint2 subtype, Uint1 subfield, FilterSetPtr fsp)
5310
6123
{
5311
6124
  SubSourcePtr ssp = NULL, prev_ssp = NULL, next_ssp;
5312
6125
 
5319
6132
      if (ssp->subtype == subtype
5320
6133
          && SubSrcSpecialMatch (ssp, fsp))
5321
6134
      {
5322
 
        if (prev_ssp == NULL)
5323
 
        {
5324
 
          biop->subtype = ssp->next;
5325
 
        }
5326
 
        else
5327
 
        {
5328
 
          prev_ssp->next = ssp->next;
5329
 
        }
5330
 
        ssp->next = NULL;
5331
 
        SubSourceFree (ssp);
 
6135
        ssp->name = RemoveSubfield (ssp->name, subfield);
 
6136
        if (StringHasNoText (ssp->name)) {
 
6137
          if (prev_ssp == NULL)
 
6138
          {
 
6139
            biop->subtype = ssp->next;
 
6140
          }
 
6141
          else
 
6142
          {
 
6143
            prev_ssp->next = ssp->next;
 
6144
          }
 
6145
          ssp->next = NULL;
 
6146
          SubSourceFree (ssp);
 
6147
        } else {
 
6148
          prev_ssp = ssp;
 
6149
        }
5332
6150
      }
5333
6151
      else
5334
6152
      {
5359
6177
    sqdp = (SourceQualDescPtr) avp->field_list->data.ptrvalue;
5360
6178
    if (sqdp->isOrgMod)
5361
6179
    {
5362
 
      RemoveOrgModFromBioSource (biop, sqdp->subtype, fsp);
 
6180
      RemoveOrgModFromBioSource (biop, sqdp->subtype, sqdp->subfield, fsp);
5363
6181
    }
5364
6182
    else
5365
6183
    {
5366
 
      RemoveSubSourceFromBioSource (biop, sqdp->subtype, fsp);
 
6184
      RemoveSubSourceFromBioSource (biop, sqdp->subtype, sqdp->subfield, fsp);
5367
6185
    }
5368
6186
  }
5369
6187
  else if (avp->field_list->choice == 1 
5370
6188
           && StringCmp (avp->field_list->data.ptrvalue, "All Notes") == 0)
5371
6189
  {
5372
 
    RemoveOrgModFromBioSource (biop, 255, fsp);
5373
 
    RemoveSubSourceFromBioSource (biop, 255, fsp);
 
6190
    RemoveOrgModFromBioSource (biop, 255, 0, fsp);
 
6191
    RemoveSubSourceFromBioSource (biop, 255, 0, fsp);
5374
6192
  }
5375
6193
}
5376
6194
 
5888
6706
    /* this is an apply */
5889
6707
    if (avp->etp != NULL)
5890
6708
    {
5891
 
      if (avp->etp->existing_text_choice == EXISTING_TEXT_CHOICE_LEAVE_OLD
 
6709
      if (avp->etp->existing_text_choice == eExistingTextChoiceLeaveOld
5892
6710
          && sfp->dbxref != NULL)
5893
6711
      {
5894
6712
        return;
5895
6713
      }
5896
 
      else if (avp->etp->existing_text_choice == EXISTING_TEXT_CHOICE_REPLACE_OLD)
 
6714
      else if (avp->etp->existing_text_choice == eExistingTextChoiceReplaceOld)
5897
6715
      {
5898
6716
        sfp->dbxref = RemoveDbxrefList (sfp->dbxref);
5899
6717
      }
5912
6730
  
5913
6731
}
5914
6732
 
 
6733
static void SetRNAProduct (SeqFeatPtr sfp, ApplyValuePtr avp);
 
6734
 
5915
6735
static void SetGBQualString (SeqFeatPtr sfp, Pointer userdata, FilterSetPtr fsp)
5916
6736
{
5917
6737
  GBQualPtr     gbqual, gbqual_last = NULL;
5918
6738
  ApplyValuePtr avp;
5919
6739
  Boolean       found = FALSE;
5920
 
  RnaRefPtr     rrp;
5921
6740
  GeneRefPtr    grp;
5922
6741
  
5923
6742
  if (sfp == NULL || userdata == NULL)
5945
6764
  else if (StringICmp (EditQualifierList[avp->field_list->data.intvalue - 1].name, "product") == 0
5946
6765
           && sfp->data.choice == SEQFEAT_RNA)
5947
6766
  {
5948
 
    rrp = (RnaRefPtr) sfp->data.value.ptrvalue;
5949
 
    if (rrp != NULL)
5950
 
    {
5951
 
      if (rrp->ext.choice == 0)
5952
 
      {
5953
 
        rrp->ext.choice = 1;
5954
 
        rrp->ext.value.ptrvalue = NULL;
5955
 
      }
5956
 
      if (rrp->ext.choice == 1)
5957
 
      {
5958
 
        rrp->ext.value.ptrvalue = HandleApplyValue (rrp->ext.value.ptrvalue, avp);        
5959
 
      }
5960
 
    }
 
6767
    SetRNAProduct (sfp, avp);
5961
6768
    return;
5962
6769
  }
5963
6770
  else if (StringICmp (EditQualifierList [avp->field_list->data.intvalue - 1].name, "map") == 0
6180
6987
  GBQualPtr           gbqual, gbqual_last = NULL, gbqual_next;
6181
6988
  RnaRefPtr           rrp;
6182
6989
  GeneRefPtr          grp;
6183
 
  StringConstraintPtr scp;
 
6990
  StringConstraintXPtr scp;
6184
6991
  
6185
6992
  if (sfp == NULL || userdata == NULL)
6186
6993
  {
6187
6994
    return;
6188
6995
  }
6189
 
  scp = (StringConstraintPtr) userdata;
 
6996
  scp = (StringConstraintXPtr) userdata;
6190
6997
  if (scp == NULL)
6191
6998
  {
6192
6999
    return;
6193
7000
  }
6194
7001
  
6195
 
  if (DoesStringMatchConstraint ("note", scp))
 
7002
  if (DoesStringMatchConstraintX ("note", scp))
6196
7003
  {
6197
7004
    sfp->comment = MemFree (sfp->comment);
6198
7005
  }
6199
7006
  
6200
 
  if (DoesStringMatchConstraint ("exception", scp))
 
7007
  if (DoesStringMatchConstraintX ("exception", scp))
6201
7008
  {
6202
7009
    sfp->except_text = MemFree (sfp->except_text);
6203
7010
  }
6204
7011
 
6205
 
  if (DoesStringMatchConstraint ("product", scp) && sfp->data.choice == SEQFEAT_RNA)
 
7012
  if (DoesStringMatchConstraintX ("product", scp) && sfp->data.choice == SEQFEAT_RNA)
6206
7013
  {
6207
7014
    rrp = (RnaRefPtr) sfp->data.value.ptrvalue;
6208
7015
    if (rrp != NULL && rrp->ext.choice == 1)
6212
7019
    }
6213
7020
  }
6214
7021
  
6215
 
  if (DoesStringMatchConstraint ("map", scp) && sfp->data.choice == SEQFEAT_GENE)
 
7022
  if (DoesStringMatchConstraintX ("map", scp) && sfp->data.choice == SEQFEAT_GENE)
6216
7023
  {
6217
7024
    grp = (GeneRefPtr) sfp->data.value.ptrvalue;
6218
7025
    if (grp != NULL)
6221
7028
    }
6222
7029
  }
6223
7030
  
6224
 
  if (DoesStringMatchConstraint ("db_xref", scp))
 
7031
  if (DoesStringMatchConstraintX ("db_xref", scp))
6225
7032
  {
6226
7033
    sfp->dbxref = RemoveDbxrefList (sfp->dbxref);
6227
7034
  }
6228
7035
  
6229
 
  if (DoesStringMatchConstraint ("go_process", scp))
 
7036
  if (DoesStringMatchConstraintX ("go_process", scp))
6230
7037
  {
6231
7038
    RemoveGoTerm (sfp, "process");
6232
7039
  }
6233
7040
  
6234
 
  if (DoesStringMatchConstraint ("go_function", scp))
 
7041
  if (DoesStringMatchConstraintX ("go_function", scp))
6235
7042
  {
6236
7043
    RemoveGoTerm (sfp, "function");
6237
7044
  }
6238
7045
 
6239
 
  if (DoesStringMatchConstraint ("go_component", scp))
 
7046
  if (DoesStringMatchConstraintX ("go_component", scp))
6240
7047
  {
6241
7048
    RemoveGoTerm (sfp, "component");
6242
7049
  }
6245
7052
  while (gbqual != NULL)
6246
7053
  {
6247
7054
    gbqual_next = gbqual->next;
6248
 
    if (DoesStringMatchConstraint (gbqual->qual, scp))
 
7055
    if (DoesStringMatchConstraintX (gbqual->qual, scp))
6249
7056
    {
6250
7057
      if (gbqual_last == NULL)
6251
7058
      {
6338
7145
}
6339
7146
 
6340
7147
 
6341
 
static CharPtr ReplaceStringForParse(CharPtr src_text, TextPortionPtr text_portion)
 
7148
static CharPtr ReplaceStringForParse(CharPtr src_text, TextPortionXPtr text_portion)
6342
7149
{
6343
7150
  CharPtr         found_loc;
6344
7151
  Int4            found_len;
6347
7154
  if (src_text == NULL || text_portion == NULL) {
6348
7155
    return NULL;
6349
7156
  }
6350
 
  // for parse, replace the source text with the portion we want
 
7157
  /* for parse, replace the source text with the portion we want */
6351
7158
  found_loc = NULL;
6352
7159
  found_len = 0;
6353
 
  FindTextPortionInString (src_text, text_portion, &found_loc, &found_len);
 
7160
  FindTextPortionXInString (src_text, text_portion, &found_loc, &found_len);
6354
7161
  if (found_loc != NULL) 
6355
7162
  {
6356
7163
    dst_txt = (CharPtr)MemNew (found_len + 1);
6390
7197
  }
6391
7198
  
6392
7199
  avd.text_to_replace = NULL;
 
7200
  avd.where_to_replace = EditApplyFindLocation_anywhere;
6393
7201
  src_text = (cfp->get_str_func)(sfp, cfp->src_field_list, cfp->fsp);
6394
7202
  
6395
7203
  if (cfp->strip_name_from_text)
6417
7225
  }
6418
7226
  else if (cfp->convert_type == CONVERT_TYPE_PARSE)
6419
7227
  {
6420
 
    // for parse, replace the source text with the portion we want
 
7228
    /* for parse, replace the source text with the portion we want */
6421
7229
    dst_text = src_text;
6422
7230
    src_text = ReplaceStringForParse(src_text, cfp->text_portion);
6423
7231
    if (src_text == NULL) 
6481
7289
  }
6482
7290
  
6483
7291
  avd.text_to_replace = NULL;
 
7292
  avd.where_to_replace = EditApplyFindLocation_anywhere;
6484
7293
  src_text = (cfp->get_d_str_func)(sdp, cfp->src_field_list, cfp->fsp);
6485
7294
  if (cfp->strip_name_from_text)
6486
7295
  {
6508
7317
  }
6509
7318
  else if (cfp->convert_type == CONVERT_TYPE_PARSE)
6510
7319
  {
6511
 
    // for parse, replace the source text with the portion we want
 
7320
    /* for parse, replace the source text with the portion we want */
6512
7321
    dst_text = src_text;
6513
7322
    src_text = ReplaceStringForParse(src_text, cfp->text_portion);
6514
7323
    if (src_text == NULL) 
6535
7344
      || (cfp->convert_type == CONVERT_TYPE_PARSE && cfp->remove_parsed))
6536
7345
  {
6537
7346
    /* put dst_text in the src_field */
 
7347
    avd.etp = NULL;
6538
7348
    avd.field_list = cfp->src_field_list;
6539
7349
    avd.new_text = dst_text;
6540
7350
    (cfp->set_d_str_func) (sdp, &avd, cfp->fsp);
6574
7384
  src_val = (cfp->name_field_func)(cfp->src_field_list);
6575
7385
  if (StringCmp (curr_val, src_val) == 0)
6576
7386
  {
 
7387
    avd.where_to_replace = EditApplyFindLocation_anywhere;
6577
7388
    avd.field_list = cfp->dst_field_list;
6578
7389
    avd.etp = NULL;
6579
7390
    (cfp->set_str_func) (sfp, &avd, cfp->fsp);
6607
7418
  src_val = (cfp->name_field_func)(cfp->src_field_list);
6608
7419
  if (StringCmp (curr_val, src_val) == 0)
6609
7420
  {
 
7421
    avd.where_to_replace = EditApplyFindLocation_anywhere;
6610
7422
    avd.field_list = cfp->dst_field_list;
6611
7423
    avd.etp = NULL;
6612
7424
    (cfp->set_d_str_func) (sdp, &avd, cfp->fsp);
7140
7952
      grp->maploc = HandleApplyValue (grp->maploc, avp);            
7141
7953
      break;
7142
7954
    case GENEFIELD_SYNONYM:
7143
 
      grp->syn = ApplyValueToValNodeStringList (grp->syn, 0, avp);
 
7955
      if (grp->syn == NULL || !StringHasNoText (avp->text_to_replace)) {
 
7956
        grp->syn = ApplyValueToValNodeStringList (grp->syn, 0, avp);
 
7957
      } else {
 
7958
        grp->syn->data.ptrvalue = HandleApplyValue (grp->syn->data.ptrvalue, avp);
 
7959
      }
7144
7960
      break;
7145
7961
    case GENEFIELD_LOCUS_TAG:
7146
7962
      grp->locus_tag = HandleApplyValue (grp->locus_tag, avp);
7369
8185
  sfp->comment = MemFree (sfp->comment);
7370
8186
}
7371
8187
 
 
8188
extern CharPtr 
 
8189
GetCDSFieldString 
 
8190
(SeqFeatPtr   sfp,
 
8191
 ValNodePtr   cds_field,
 
8192
 FilterSetPtr fsp)
 
8193
{
 
8194
  ValNodePtr vnp;
 
8195
  CharPtr    str = NULL;
 
8196
  BioseqPtr  prot_bsp;
 
8197
  SeqFeatPtr prot_sfp;
 
8198
  SeqMgrFeatContext prot_context;
 
8199
  ProtRefPtr        prp;
 
8200
  
 
8201
  if (sfp == NULL || cds_field == NULL || sfp->idx.subtype != FEATDEF_CDS)
 
8202
  {
 
8203
    return NULL;
 
8204
  }
 
8205
  
 
8206
  vnp = cds_field;
 
8207
 
 
8208
  while (vnp != NULL && vnp->data.intvalue != FEATUREFIELD_NONE && StringHasNoText (str))
 
8209
  {
 
8210
    str = NULL;
 
8211
    switch (vnp->data.intvalue)
 
8212
    {
 
8213
      case MRNAFIELD_PRODUCT:
 
8214
        prot_bsp = BioseqFind (SeqLocId (sfp->product));
 
8215
        prot_sfp = SeqMgrGetNextFeature (prot_bsp, NULL, SEQFEAT_PROT, 0, &prot_context);
 
8216
        if (prot_sfp != NULL && prot_sfp->data.value.ptrvalue != NULL) {
 
8217
          prp = (ProtRefPtr) prot_sfp->data.value.ptrvalue;
 
8218
          if (prp->name != NULL && !StringHasNoText (prp->name->data.ptrvalue)) {
 
8219
            str = prp->name->data.ptrvalue;
 
8220
          }
 
8221
        }
 
8222
        break;
 
8223
      case MRNAFIELD_COMMENT:
 
8224
        str = sfp->comment;
 
8225
        break;
 
8226
    }
 
8227
    vnp = vnp->next;
 
8228
  }
 
8229
  if (StringHasNoText (str))
 
8230
  {
 
8231
    str = NULL;
 
8232
  }
 
8233
  else
 
8234
  {
 
8235
    str = StringSave (str);
 
8236
  }
 
8237
  return str;
 
8238
}
 
8239
 
 
8240
extern void RemoveCDSFieldString (SeqFeatPtr sfp, ValNodePtr cds_field)
 
8241
{
 
8242
  ValNodePtr vnp;
 
8243
  Boolean    found_nonempty = FALSE;
 
8244
  BioseqPtr  prot_bsp;
 
8245
  SeqFeatPtr prot_sfp;
 
8246
  SeqMgrFeatContext prot_context;
 
8247
  ProtRefPtr        prp;
 
8248
  
 
8249
  if (sfp == NULL || cds_field == NULL || sfp->idx.subtype != FEATDEF_CDS)
 
8250
  {
 
8251
    return;
 
8252
  }
 
8253
  
 
8254
  vnp = cds_field;
 
8255
  while (vnp != NULL && vnp->data.intvalue != FEATUREFIELD_NONE && !found_nonempty)
 
8256
  {
 
8257
    switch (vnp->data.intvalue)
 
8258
    {
 
8259
      case MRNAFIELD_PRODUCT:
 
8260
        prot_bsp = BioseqFind (SeqLocId (sfp->product));
 
8261
        prot_sfp = SeqMgrGetNextFeature (prot_bsp, NULL, SEQFEAT_PROT, 0, &prot_context);
 
8262
        if (prot_sfp != NULL && prot_sfp->data.value.ptrvalue != NULL) {
 
8263
          prp = (ProtRefPtr) prot_sfp->data.value.ptrvalue;
 
8264
          if (prp->name != NULL && !StringHasNoText (prp->name->data.ptrvalue)) {
 
8265
            found_nonempty = TRUE;
 
8266
            if (vnp->choice != 0) {
 
8267
              prp->name = ValNodeFreeData (prp->name);
 
8268
            }
 
8269
          }
 
8270
        }
 
8271
        break;
 
8272
      case MRNAFIELD_COMMENT:
 
8273
        if (!StringHasNoText (sfp->comment))
 
8274
        {
 
8275
          found_nonempty = TRUE;
 
8276
          if (vnp->choice != 0)
 
8277
          {
 
8278
            sfp->comment = MemFree (sfp->comment);
 
8279
          }
 
8280
        }
 
8281
        break;
 
8282
    }
 
8283
    vnp = vnp->next;
 
8284
  }
 
8285
}
 
8286
 
7372
8287
#define PROTEINFIELD_NAME               1
7373
8288
#define PROTEINFIELD_DESC               2
7374
8289
#define PROTEINFIELD_EC_NUM             3
7375
8290
#define PROTEINFIELD_ACTIVITY           4
7376
8291
#define PROTEINFIELD_COMMENT            5
7377
8292
#define PROTEINFIELD_MATPEPTIDE_NAME    6
7378
 
#define PROTEINFIELD_MATPEPTIDE_COMMENT 7
 
8293
#define PROTEINFIELD_MATPEPTIDE_DESC    7
 
8294
#define PROTEINFIELD_MATPEPTIDE_COMMENT 8
7379
8295
 
7380
8296
static CharPtr protein_field_list [] =
7381
8297
{
7382
 
  "name", "description", "E.C. number", "activity", "comment", "mat_peptide name", "mat_peptide comment"
 
8298
  "name", "description", "E.C. number", "activity", "comment", "mat_peptide name", "mat_peptide description", "mat_peptide comment"
7383
8299
};
7384
8300
 
7385
8301
static int num_protein_fields = sizeof (protein_field_list) / sizeof (CharPtr);
7469
8385
          str = val_vnp->data.ptrvalue;
7470
8386
        }
7471
8387
        break;
 
8388
      case PROTEINFIELD_MATPEPTIDE_DESC:
 
8389
        if (sfp->idx.subtype == FEATDEF_mat_peptide_aa && prp != NULL)
 
8390
        {
 
8391
           str = prp->desc;
 
8392
        }
 
8393
        break;
7472
8394
      case PROTEINFIELD_MATPEPTIDE_COMMENT:
7473
8395
        if (sfp->idx.subtype == FEATDEF_mat_peptide_aa)
7474
8396
        {
7494
8416
  ValNodePtr vnp;
7495
8417
  ProtRefPtr prp = NULL;
7496
8418
  Int4       field_choice;
7497
 
  SeqFeatXrefPtr xref, prev;
 
8419
  SeqFeatXrefPtr xref = NULL, prev;
7498
8420
  
7499
8421
  if (sfp == NULL || protein_field == NULL)
7500
8422
  {
7502
8424
  }
7503
8425
  
7504
8426
  vnp = protein_field;
7505
 
  if (sfp->idx.subtype == FEATDEF_PROT) {
 
8427
  if (sfp->idx.subtype == FEATDEF_PROT
 
8428
      || sfp->idx.subtype == FEATDEF_mat_peptide_aa) {
7506
8429
      prp = (ProtRefPtr) sfp->data.value.ptrvalue;
7507
8430
  } else if (sfp->idx.subtype == FEATDEF_CDS) {
7508
8431
      xref = sfp->xref;
7520
8443
    switch (field_choice)
7521
8444
    {
7522
8445
      case PROTEINFIELD_NAME:
7523
 
        if (prp != NULL && prp->name != NULL)
 
8446
        if (prp != NULL && prp->name != NULL && sfp->idx.subtype == FEATDEF_PROT)
7524
8447
        {
7525
8448
          prp->name = ValNodeFreeData (prp->name);
7526
8449
        }
7555
8478
          prp->name = ValNodeFreeData (prp->name);
7556
8479
        }
7557
8480
        break;
 
8481
      case PROTEINFIELD_MATPEPTIDE_DESC:
 
8482
        if (prp != NULL && sfp->idx.subtype == FEATDEF_mat_peptide_aa)
 
8483
        {
 
8484
          prp->desc = MemFree (prp->desc);
 
8485
        }
 
8486
        break;
7558
8487
      case PROTEINFIELD_MATPEPTIDE_COMMENT:
7559
8488
        if (sfp->idx.subtype == FEATDEF_mat_peptide_aa)
7560
8489
        {
7589
8518
  }      
7590
8519
}
7591
8520
 
 
8521
extern ValNodePtr ApplyValueToValNodeStringListAsText (ValNodePtr list, Int2 choice, ApplyValuePtr avp);
 
8522
 
7592
8523
static void SetProteinFieldString (SeqFeatPtr sfp, Pointer userdata, FilterSetPtr fsp)
7593
8524
{
7594
8525
  ProtRefPtr    prp;
7598
8529
  {
7599
8530
    return;
7600
8531
  }
 
8532
  if (sfp->idx.subtype != FEATDEF_PROT && sfp->idx.subtype != FEATDEF_mat_peptide_aa)
 
8533
  {
 
8534
    return;
 
8535
  }
7601
8536
  
7602
8537
  avp = (ApplyValuePtr) userdata;
7603
8538
  if (avp->field_list == NULL)
7608
8543
  if (sfp->idx.subtype == FEATDEF_PROT)
7609
8544
  {
7610
8545
    if (avp->field_list->data.intvalue == PROTEINFIELD_MATPEPTIDE_NAME
 
8546
        || avp->field_list->data.intvalue == PROTEINFIELD_MATPEPTIDE_DESC
7611
8547
        || avp->field_list->data.intvalue == PROTEINFIELD_MATPEPTIDE_COMMENT)
7612
8548
    {
7613
8549
      return;
7616
8552
  else if (sfp->idx.subtype == FEATDEF_mat_peptide_aa)
7617
8553
  {
7618
8554
    if (avp->field_list->data.intvalue != PROTEINFIELD_MATPEPTIDE_NAME
 
8555
        && avp->field_list->data.intvalue != PROTEINFIELD_MATPEPTIDE_DESC
7619
8556
        && avp->field_list->data.intvalue != PROTEINFIELD_MATPEPTIDE_COMMENT)
7620
8557
    {
7621
8558
      return;
7641
8578
  {
7642
8579
    case PROTEINFIELD_NAME:
7643
8580
    case PROTEINFIELD_MATPEPTIDE_NAME:
7644
 
      if (prp->name == NULL )
 
8581
      if (prp->name == NULL || !StringHasNoText(avp->text_to_replace))
7645
8582
      {
7646
8583
        prp->name = ApplyValueToValNodeStringList (prp->name, 0, avp);
7647
8584
      }
7651
8588
      }
7652
8589
      break;
7653
8590
    case PROTEINFIELD_DESC:
7654
 
      prp->desc = HandleExistingText (prp->desc, StringSave (avp->new_text), avp->etp);
 
8591
    case PROTEINFIELD_MATPEPTIDE_DESC:
 
8592
      prp->desc = HandleApplyValue (prp->desc, avp);
7655
8593
      break;
7656
8594
    case PROTEINFIELD_EC_NUM:
7657
 
      if (prp->ec == NULL)
7658
 
      {
7659
 
        prp->ec = ApplyValueToValNodeStringList (prp->ec, 0, avp);
7660
 
      }
7661
 
      else
7662
 
      {
7663
 
        prp->ec->data.ptrvalue = HandleApplyValue (prp->ec->data.ptrvalue, avp);
7664
 
      }
 
8595
      prp->ec = ApplyValueToValNodeStringListAsText (prp->ec, 0, avp);
7665
8596
      break;
7666
8597
    case PROTEINFIELD_ACTIVITY:
7667
 
      if (prp->activity == NULL)
 
8598
      if (prp->activity == NULL || !StringHasNoText(avp->text_to_replace))
7668
8599
      {
7669
8600
        prp->activity = ApplyValueToValNodeStringList (prp->activity, 0, avp);
7670
8601
      }
7675
8606
      break;
7676
8607
    case PROTEINFIELD_COMMENT:
7677
8608
    case PROTEINFIELD_MATPEPTIDE_COMMENT:
7678
 
      sfp->comment = HandleExistingText (sfp->comment, StringSave (avp->new_text), avp->etp);
 
8609
      sfp->comment = HandleApplyValue (sfp->comment, avp);
7679
8610
      break;
7680
8611
  }
7681
8612
}
7781
8712
  return d; 
7782
8713
}
7783
8714
 
 
8715
 
 
8716
extern Boolean IsCDSetProteinProductChoice (ValNodePtr vnp)
 
8717
{
 
8718
  if (vnp != NULL && vnp->data.intvalue == 2 + num_gene_fields + num_mrna_fields) {
 
8719
    return TRUE;
 
8720
  } else {
 
8721
    return FALSE;
 
8722
  }
 
8723
}
 
8724
 
 
8725
 
 
8726
static Boolean IsCDSetProteinQualChoice (ValNodePtr vnp)
 
8727
{
 
8728
  if (vnp != NULL 
 
8729
      && vnp->data.intvalue > 1 + num_gene_fields + num_mrna_fields
 
8730
      && vnp->data.intvalue <= 1 + num_gene_fields + num_mrna_fields + num_protein_fields) 
 
8731
  {
 
8732
    return TRUE;
 
8733
  } 
 
8734
  else 
 
8735
  {
 
8736
    return FALSE;
 
8737
  }
 
8738
}
 
8739
 
 
8740
static Boolean IsCDSetMatPeptideQualChoice (ValNodePtr vnp)
 
8741
{
 
8742
  if (IsCDSetProteinQualChoice (vnp)
 
8743
      && StringNICmp (protein_field_list[vnp->data.intvalue - num_gene_fields - num_mrna_fields - 2],
 
8744
                      "mat_peptide", 11) == 0) 
 
8745
  {
 
8746
    return TRUE;
 
8747
  }
 
8748
  else
 
8749
  {
 
8750
    return FALSE;
 
8751
  } 
 
8752
}
 
8753
 
 
8754
static Boolean IsCDSetMRNAQualChoice (ValNodePtr vnp)
 
8755
{
 
8756
  if (vnp != NULL 
 
8757
      && vnp->data.intvalue > 1 + num_gene_fields
 
8758
      && vnp->data.intvalue <= 1 + num_gene_fields + num_mrna_fields) 
 
8759
  {
 
8760
    return TRUE;
 
8761
  }
 
8762
  else
 
8763
  {
 
8764
    return FALSE;
 
8765
  }
 
8766
}
 
8767
 
 
8768
static Boolean IsCDSetGeneQualChoice (ValNodePtr vnp)
 
8769
{
 
8770
  if (vnp != NULL 
 
8771
      && vnp->data.intvalue > 1
 
8772
      && vnp->data.intvalue <= 1 + num_gene_fields)
 
8773
  {
 
8774
    return TRUE;
 
8775
  }
 
8776
  else
 
8777
  {
 
8778
    return FALSE;
 
8779
  }
 
8780
}
 
8781
 
 
8782
static Boolean IsCDSetCDSQualChoice (ValNodePtr vnp)
 
8783
{
 
8784
  if (vnp != NULL && vnp->data.intvalue == 1) 
 
8785
  {
 
8786
    return TRUE;
 
8787
  }
 
8788
  else
 
8789
  {
 
8790
    return FALSE;
 
8791
  }
 
8792
}
 
8793
 
7784
8794
extern CharPtr GetCDSGeneProtField (SeqFeatPtr sfp, ValNodePtr vnp, FilterSetPtr fsp)
7785
8795
{
7786
8796
  CharPtr str = NULL;
7799
8809
    
7800
8810
    field_choice = vnp->data.intvalue;
7801
8811
  
7802
 
    if (vnp->data.intvalue == 1)
 
8812
    if (IsCDSetCDSQualChoice(vnp))
7803
8813
    {
7804
8814
      /* CDS Comment */
7805
8815
      str = GetCDSComment (sfp, NULL, NULL);
7806
8816
    }
7807
 
    else if (vnp->data.intvalue <= 1 + num_gene_fields)
 
8817
    else if (IsCDSetGeneQualChoice (vnp))
7808
8818
    {
7809
8819
      vn.data.intvalue = vnp->data.intvalue - 1;
7810
8820
      str = GetGeneFieldString (sfp, &vn, NULL);
7811
8821
    }
7812
 
    else if (vnp->data.intvalue <= 1 + num_gene_fields + num_mrna_fields)
 
8822
    else if (IsCDSetMRNAQualChoice (vnp))
7813
8823
    {
7814
8824
      vn.data.intvalue = vnp->data.intvalue - num_gene_fields - 1;
7815
8825
      str = GetmRNAFieldString (sfp, &vn, NULL);
7816
8826
    }
7817
 
    else if (vnp->data.intvalue <= 1 + num_gene_fields + num_mrna_fields + num_protein_fields)
 
8827
    else if (IsCDSetProteinQualChoice (vnp))
7818
8828
    {
7819
8829
      vn.data.intvalue = vnp->data.intvalue - num_gene_fields - num_mrna_fields - 1;
7820
8830
      str = GetProteinFieldString (sfp, &vn, NULL);
7824
8834
  return str;
7825
8835
}
7826
8836
 
7827
 
static void RemoveCDSGeneProtField (SeqFeatPtr sfp, ValNodePtr vnp)
 
8837
/* we could have multiple mat_peptides in a CDSset, some that match the constraint and some that do not */
 
8838
static Boolean DoesConstraintDisqualifyFeature (SeqFeatPtr sfp, ChoiceConstraintPtr ccp)
 
8839
{
 
8840
  Boolean is_disqualified = FALSE;
 
8841
  Boolean does_match = FALSE;
 
8842
  CharPtr str;
 
8843
 
 
8844
  if (sfp == NULL || ccp == NULL 
 
8845
      || ccp->constraint_type == CHOICE_CONSTRAINT_ANY
 
8846
      || sfp->idx.subtype != FEATDEF_mat_peptide_aa 
 
8847
      || !IsCDSetMatPeptideQualChoice(ccp->qual_choice))
 
8848
  {
 
8849
    is_disqualified = FALSE;
 
8850
  }
 
8851
  else if (ccp->constraint_type == CHOICE_CONSTRAINT_QUAL_PRESENT && ccp->qual_choice != NULL)
 
8852
  {
 
8853
    str = GetCDSGeneProtField (sfp, ccp->qual_choice, NULL);
 
8854
    if (str == NULL)
 
8855
    {
 
8856
      is_disqualified = TRUE;
 
8857
    }
 
8858
    MemFree (str);
 
8859
  }
 
8860
  else if (ccp->constraint_type == CHOICE_CONSTRAINT_STRING)
 
8861
  {
 
8862
    str = GetCDSGeneProtField (sfp, ccp->qual_choice, NULL);
 
8863
    does_match = DoesStringMatchConstraintX (str, ccp->string_constraint);
 
8864
    MemFree (str);
 
8865
    if (ccp->string_constraint != NULL && ccp->string_constraint->not_present)
 
8866
    {
 
8867
      does_match = ! does_match;
 
8868
    }
 
8869
    if (!does_match)
 
8870
    {
 
8871
      is_disqualified = TRUE;
 
8872
    }
 
8873
  }
 
8874
  return is_disqualified;
 
8875
 
 
8876
}
 
8877
 
 
8878
extern void RemoveCDSGeneProtField (SeqFeatPtr sfp, ValNodePtr vnp, FilterSetPtr fsp)
7828
8879
{
7829
8880
  ValNode vn;
7830
8881
  
7832
8883
  {
7833
8884
    return;
7834
8885
  }
 
8886
 
 
8887
  if (fsp != NULL && fsp->cgp != NULL && DoesConstraintDisqualifyFeature (sfp, fsp->cgp)) 
 
8888
  {
 
8889
    return;
 
8890
  }
7835
8891
  
7836
8892
  while (vnp != NULL)
7837
8893
  {
7862
8918
  }
7863
8919
}
7864
8920
 
7865
 
static void 
 
8921
 
 
8922
extern Uint2 FeatDefTypeFromFieldList (ValNodePtr vnp)
 
8923
{
 
8924
  if (vnp == NULL) 
 
8925
  {
 
8926
    return 0;
 
8927
  }
 
8928
  else if (IsCDSetCDSQualChoice(vnp))
 
8929
  {
 
8930
    return FEATDEF_CDS;
 
8931
  }
 
8932
  else if (IsCDSetGeneQualChoice (vnp))
 
8933
  {
 
8934
    return FEATDEF_GENE;
 
8935
  }
 
8936
  else if (IsCDSetMRNAQualChoice(vnp))
 
8937
  {
 
8938
    return FEATDEF_mRNA;
 
8939
  }
 
8940
  else if (IsCDSetProteinQualChoice (vnp))
 
8941
  {
 
8942
    if (IsCDSetMatPeptideQualChoice (vnp))
 
8943
    {
 
8944
      return FEATDEF_mat_peptide_aa;
 
8945
    }
 
8946
    else
 
8947
    {
 
8948
      return FEATDEF_PROT;
 
8949
    }
 
8950
  }
 
8951
  else
 
8952
  {
 
8953
    return 0;
 
8954
  }
 
8955
}
 
8956
 
 
8957
 
 
8958
/* return TRUE if actually set field, FALSE otherwise */
 
8959
extern Boolean 
7866
8960
SetCDSGeneProtField 
7867
8961
(SeqFeatPtr      sfp,
7868
8962
 ValNodePtr      vnp, 
7869
 
 CharPtr         new_text, 
7870
 
 ExistingTextPtr etp)
 
8963
 ApplyValuePtr   avp,
 
8964
 FilterSetPtr    fsp)
7871
8965
{
7872
 
  ValNode vn;
7873
 
  ApplyValueData avd;
 
8966
  ValNode        vn;
 
8967
  ApplyValueData local_avd;
 
8968
  Uint2          choice;
7874
8969
  
7875
 
  if (sfp == NULL || vnp == NULL)
7876
 
  {
7877
 
    return;
 
8970
  if (sfp == NULL || vnp == NULL || avp == NULL)
 
8971
  {
 
8972
    return FALSE;
 
8973
  }
 
8974
 
 
8975
  choice = FeatDefTypeFromFieldList (vnp);
 
8976
  if (FindFeatFromFeatDefType(choice) != sfp->data.choice)
 
8977
  {
 
8978
    return FALSE;
 
8979
  }
 
8980
 
 
8981
  if (fsp != NULL && fsp->cgp != NULL && DoesConstraintDisqualifyFeature (sfp, fsp->cgp)) 
 
8982
  {
 
8983
    return FALSE;
7878
8984
  }
7879
8985
  
7880
8986
  vn.choice = vnp->choice;
7881
8987
  vn.next = NULL;
7882
 
  avd.field_list = &vn;
7883
 
  avd.new_text = StringSave (new_text);
7884
 
  avd.etp = etp;
7885
 
  avd.text_to_replace = NULL;
 
8988
  local_avd.field_list = &vn;
 
8989
  local_avd.new_text = avp->new_text;
 
8990
  local_avd.etp = avp->etp;
 
8991
  local_avd.text_to_replace = avp->text_to_replace;
 
8992
  local_avd.where_to_replace = avp->where_to_replace;
7886
8993
 
7887
8994
  if (vnp->data.intvalue == 1)
7888
8995
  {
7889
8996
    /* CDS Comment */
7890
 
    SetCDSComment (sfp, &avd, NULL);
 
8997
    SetCDSComment (sfp, &local_avd, NULL);
7891
8998
  }
7892
8999
  else if (vnp->data.intvalue <= 1 + num_gene_fields)
7893
9000
  {
7894
9001
    vn.data.intvalue = vnp->data.intvalue - 1;
7895
 
    SetGeneFieldString (sfp, &avd, NULL);
 
9002
    SetGeneFieldString (sfp, &local_avd, NULL);
7896
9003
  }
7897
9004
  else if (vnp->data.intvalue <= 1 + num_gene_fields + num_mrna_fields)
7898
9005
  {
7899
9006
    vn.data.intvalue = vnp->data.intvalue - num_gene_fields - 1;
7900
 
    SetmRNAFieldString (sfp, &avd, NULL);
 
9007
    SetmRNAFieldString (sfp, &local_avd, NULL);
7901
9008
  }
7902
9009
  else if (vnp->data.intvalue <= 1 + num_gene_fields + num_mrna_fields + num_protein_fields)
7903
9010
  {
7904
9011
    vn.data.intvalue = vnp->data.intvalue - num_gene_fields - num_mrna_fields - 1;
7905
 
    SetProteinFieldString (sfp, &avd, NULL);
 
9012
    SetProteinFieldString (sfp, &local_avd, NULL);
7906
9013
  }
7907
9014
  
7908
 
  avd.new_text = MemFree (avd.new_text);
 
9015
  /* no need to free any part of local_avd */
 
9016
 
 
9017
  return TRUE;
7909
9018
}
7910
9019
 
7911
 
#define RNAFIELD_NAME              1
 
9020
#define RNAFIELD_PRODUCT           1
7912
9021
#define RNAFIELD_COMMENT           2
7913
 
#define RNAFIELD_PRODUCT           3
7914
 
#define RNAFIELD_CODONS_RECOGNIZED 4
 
9022
#define RNAFIELD_CODONS_RECOGNIZED 3
 
9023
#define RNAFIELD_NCRNA_CLASS       4
7915
9024
#define RNAFIELD_ANTICODON         5
7916
9025
#define RNAFIELD_TRANSCRIPT_ID     6
7917
9026
 
7918
9027
static CharPtr rna_field_list [] = 
7919
9028
{
7920
 
  "Name", "Comment", "Product GBQual", "Codons Recognized", "Anticodon", "Transcript ID"
 
9029
  "Product", "Comment", "Codons Recognized", "ncRNA class", "Anticodon", "Transcript ID"
7921
9030
};
7922
9031
 
7923
9032
static Int4 num_rna_fields = sizeof (rna_field_list) / sizeof (CharPtr);
8013
9122
  DialoG     dlg;
8014
9123
  Int4       i;
8015
9124
  
8016
 
  for (i = 0; i < 3; i++)
 
9125
  for (i = 0; i < 4; i++)
8017
9126
  {
8018
9127
    ValNodeAddInt (&choice_list, 0, i + 1);
8019
9128
  }
8032
9141
}
8033
9142
 
8034
9143
static CharPtr rna_subtype_list [] = { "misc_RNA", "preRna", "mRNA", "tRNA",
8035
 
                                        "rRNA", "snRNA", "scRNA", "snoRNA"};
 
9144
                                        "rRNA", "ncRNA", "tmRNA"};
8036
9145
static Int2    num_rna_subtypes = sizeof (rna_subtype_list) / sizeof (CharPtr); 
8037
9146
 
8038
9147
static CharPtr GetRNASubtypeName (ValNodePtr vnp)
8061
9170
  ValNodeAddInt (&choice_list, 2, FEATDEF_mRNA);
8062
9171
  ValNodeAddInt (&choice_list, 3, FEATDEF_tRNA);
8063
9172
  ValNodeAddInt (&choice_list, 4, FEATDEF_rRNA);
8064
 
  ValNodeAddInt (&choice_list, 5, FEATDEF_snRNA);
8065
 
  ValNodeAddInt (&choice_list, 6, FEATDEF_scRNA);
8066
 
  ValNodeAddInt (&choice_list, 7, FEATDEF_snoRNA);
 
9173
  ValNodeAddInt (&choice_list, 5, FEATDEF_ncRNA);
 
9174
  ValNodeAddInt (&choice_list, 6, FEATDEF_tmRNA);
8067
9175
 
8068
9176
  dlg = ValNodeSelectionDialog (h, choice_list, TALL_SELECTION_LIST,
8069
9177
                                GetRNASubtypeName, NULL, 
8074
9182
}
8075
9183
 
8076
9184
 
8077
 
static CharPtr GetRNANameString (SeqFeatPtr sfp)
 
9185
static CharPtr GetRNAProductString (SeqFeatPtr sfp)
8078
9186
{
8079
9187
  RnaRefPtr  rrp;
8080
9188
  SeqMgrFeatContext context;
8081
9189
  CharPtr    str = NULL;
 
9190
  GBQualPtr  gbqual;
8082
9191
 
8083
9192
  if (sfp == NULL || sfp->data.choice != SEQFEAT_RNA || sfp->data.value.ptrvalue == NULL)
8084
9193
  {
8085
9194
    return NULL;
8086
9195
  }
 
9196
 
8087
9197
  rrp = sfp->data.value.ptrvalue;
8088
 
  if (rrp->ext.choice == 1 && !StringHasNoText (rrp->ext.value.ptrvalue))
 
9198
  if (rrp->ext.choice == 0 
 
9199
      || (rrp->ext.choice == 1 && StringHasNoText (rrp->ext.value.ptrvalue))
 
9200
      || (rrp->ext.choice == 1 
 
9201
          && (StringCmp (rrp->ext.value.ptrvalue, "ncRNA") == 0 
 
9202
              || StringCmp (rrp->ext.value.ptrvalue, "tmRNA") == 0
 
9203
              || StringCmp (rrp->ext.value.ptrvalue, "misc_RNA") == 0)))
8089
9204
  {
8090
 
    str = StringSave (rrp->ext.value.ptrvalue);        
 
9205
    gbqual = sfp->qual;
 
9206
    while (gbqual != NULL && str == NULL) {
 
9207
    if (StringICmp (gbqual->qual, "product") == 0
 
9208
        && !StringHasNoText (gbqual->val)) 
 
9209
    {
 
9210
      str = StringSave (gbqual->val);
 
9211
      }
 
9212
      gbqual = gbqual->next;
 
9213
    }
8091
9214
  }
8092
 
  else if (rrp->ext.choice == 2 && rrp->ext.value.ptrvalue != NULL)
 
9215
 
 
9216
  if (str == NULL)
8093
9217
  {
8094
 
    if (SeqMgrGetDesiredFeature (sfp->idx.entityID, NULL, 0, 0, sfp, &context) != NULL
8095
 
        && !StringHasNoText (context.label))
8096
 
    {
8097
 
      str = (CharPtr) MemNew (sizeof (Char) + (StringLen (context.label) + 6));
8098
 
      sprintf (str, "tRNA-%s", context.label);
 
9218
    if (rrp->ext.choice == 1 && !StringHasNoText (rrp->ext.value.ptrvalue)
 
9219
        && StringCmp (rrp->ext.value.ptrvalue, "ncRNA") != 0
 
9220
        && StringCmp (rrp->ext.value.ptrvalue, "tmRNA") != 0
 
9221
        && StringCmp (rrp->ext.value.ptrvalue, "misc_RNA") != 0)
 
9222
    {
 
9223
      str = StringSave (rrp->ext.value.ptrvalue);        
 
9224
    }
 
9225
    else if (rrp->ext.choice == 2 && rrp->ext.value.ptrvalue != NULL)
 
9226
    {
 
9227
      if (SeqMgrGetDesiredFeature (sfp->idx.entityID, NULL, 0, 0, sfp, &context) != NULL
 
9228
          && !StringHasNoText (context.label)
 
9229
          && StringCmp (context.label, "tRNA") != 0)
 
9230
      {
 
9231
        str = (CharPtr) MemNew (sizeof (Char) + (StringLen (context.label) + 6));
 
9232
        sprintf (str, "tRNA-%s", context.label);
 
9233
      }
8099
9234
    }
8100
9235
  }
8101
9236
  return str;
8105
9240
{
8106
9241
  RnaRefPtr  rrp;
8107
9242
  CharPtr    str = NULL;
8108
 
  GBQualPtr  gbqual;
8109
9243
  ValNode    vn;
8110
9244
  GeneRefPtr grp;
8111
9245
  SeqFeatPtr gene;
8112
9246
  SeqMgrFeatContext context;
8113
9247
  Int4              field_choice;
 
9248
  GBQualPtr         qual;
8114
9249
  
8115
9250
  if (sfp == NULL || sfp->data.choice != SEQFEAT_RNA || vnp == NULL)
8116
9251
  {
8124
9259
    field_choice = vnp->data.intvalue;
8125
9260
    switch (vnp->data.intvalue)
8126
9261
    {
8127
 
      case RNAFIELD_NAME :
8128
 
        str = GetRNANameString (sfp);
 
9262
      case RNAFIELD_PRODUCT :        
 
9263
        str = GetRNAProductString (sfp);
8129
9264
        break;
8130
9265
      case RNAFIELD_COMMENT :
8131
9266
        if (!StringHasNoText (sfp->comment))
8133
9268
          str = StringSave (sfp->comment);
8134
9269
        }
8135
9270
        break;
8136
 
      case RNAFIELD_PRODUCT :
8137
 
        gbqual = sfp->qual;
8138
 
        while (gbqual != NULL && str == NULL) {
8139
 
          if (StringICmp (gbqual->qual, "product") == 0
8140
 
              && !StringHasNoText (gbqual->val)) 
 
9271
      case RNAFIELD_NCRNA_CLASS :
 
9272
        for (qual = sfp->qual; qual != NULL && str == NULL; qual = qual->next)
 
9273
        {
 
9274
          if (StringCmp (qual->qual, "ncRNA_class") == 0
 
9275
              && !StringHasNoText (qual->val))
8141
9276
          {
8142
 
            str = StringSave (gbqual->val);
 
9277
            str = StringSave (qual->val);
8143
9278
          }
8144
 
          gbqual = gbqual->next;
8145
9279
        }
8146
9280
        break;
8147
9281
      default:
8206
9340
  GBQualPtr         gbqual, gbqual_last = NULL;
8207
9341
 
8208
9342
  if (sfp == NULL || sfp->data.value.ptrvalue == NULL 
8209
 
      || sfp->data.choice != SEQFEAT_RNA
 
9343
      || sfp->idx.subtype != FEATDEF_tRNA
8210
9344
      || avp == NULL)
8211
9345
  {
8212
9346
    return;
8213
9347
  }
8214
9348
  
8215
9349
  rrp = sfp->data.value.ptrvalue;
 
9350
  if (rrp->ext.choice == 0)
 
9351
  {
 
9352
    trp = MemNew (sizeof (tRNA));
 
9353
    trp->aatype = 0;
 
9354
    MemSet (trp->codon, 255, sizeof (trp->codon));
 
9355
    trp->anticodon = NULL;
 
9356
    rrp->ext.value.ptrvalue = trp;
 
9357
    rrp->ext.choice = 2;
 
9358
  }
8216
9359
  if (rrp->ext.choice != 2)
8217
9360
  {
8218
9361
    return;
8219
9362
  }
8220
9363
  trp = (tRNAPtr) rrp->ext.value.ptrvalue;
8221
9364
  
8222
 
  name_string = GetRNANameString (sfp);
 
9365
  name_string = GetRNAProductString (sfp);
8223
9366
  name_string = HandleApplyValue (name_string, avp);
8224
9367
  if (!IsParseabletRNAName(name_string))
8225
9368
  {
8262
9405
  {
8263
9406
    new_aa = ParseTRnaString (name_string, &justTrnaText, codon, TRUE);
8264
9407
    trp->aa = new_aa;
 
9408
    trp->aatype = 2;
8265
9409
    name_string = MemFree (name_string);
8266
9410
  }
8267
9411
}
8268
9412
 
8269
9413
 
 
9414
static void SetRNAProduct (SeqFeatPtr sfp, ApplyValuePtr avp)
 
9415
{
 
9416
  RnaRefPtr rrp;
 
9417
  GBQualPtr gbq, prev_gbq = NULL;
 
9418
 
 
9419
  if (sfp == NULL || sfp->data.choice != SEQFEAT_RNA || sfp->data.value.ptrvalue == NULL || avp == NULL)
 
9420
  {
 
9421
    return;
 
9422
  }
 
9423
 
 
9424
  rrp = (RnaRefPtr) sfp->data.value.ptrvalue;
 
9425
 
 
9426
  gbq = sfp->qual;
 
9427
  while (gbq != NULL && StringCmp (gbq->qual, "product") != 0)
 
9428
  {
 
9429
    prev_gbq = gbq;
 
9430
    gbq = gbq->next;
 
9431
  }
 
9432
  if (gbq != NULL)
 
9433
  {
 
9434
    gbq->val = HandleApplyValue (gbq->val, avp);
 
9435
    if (StringHasNoText (gbq->val))
 
9436
    {
 
9437
      if (prev_gbq == NULL)
 
9438
      {
 
9439
        sfp->qual = gbq->next;
 
9440
      }
 
9441
      else
 
9442
      {
 
9443
        prev_gbq->next = gbq->next;
 
9444
      }
 
9445
      gbq->next = NULL;
 
9446
      gbq = GBQualFree (gbq);
 
9447
    }
 
9448
  }
 
9449
  else if (sfp->idx.subtype == FEATDEF_tRNA || rrp->ext.choice == 2)
 
9450
  {
 
9451
    SettRNAName (sfp, avp);
 
9452
  }
 
9453
  else if (rrp->ext.choice == 1
 
9454
           && (StringCmp (rrp->ext.value.ptrvalue, "ncRNA") == 0
 
9455
               || StringCmp (rrp->ext.value.ptrvalue, "tmRNA") == 0
 
9456
               || StringCmp (rrp->ext.value.ptrvalue, "misc_RNA") == 0))
 
9457
  {
 
9458
    gbq = GBQualNew();
 
9459
    gbq->qual = StringSave ("product");
 
9460
    gbq->val = HandleApplyValue (gbq->val, avp);
 
9461
    gbq->next = sfp->qual;
 
9462
    sfp->qual = gbq;
 
9463
  }
 
9464
  else if (rrp->ext.choice == 1 || rrp->ext.choice == 0)
 
9465
  {
 
9466
    rrp->ext.value.ptrvalue = HandleApplyValue (rrp->ext.value.ptrvalue, avp);
 
9467
    if (StringHasNoText (rrp->ext.value.ptrvalue))
 
9468
    {
 
9469
      rrp->ext.value.ptrvalue = MemFree (rrp->ext.value.ptrvalue);
 
9470
      rrp->ext.choice = 0;
 
9471
    }
 
9472
    else
 
9473
    {
 
9474
      rrp->ext.choice = 1;
 
9475
    }
 
9476
  }
 
9477
}
 
9478
 
 
9479
 
8270
9480
static void SetRNAFieldString (SeqFeatPtr sfp, Pointer userdata, FilterSetPtr fsp)
8271
9481
{
8272
9482
  RnaRefPtr     rrp;
8273
9483
  ApplyValuePtr avp;
8274
 
  GBQualPtr     gbqual, gbqual_last = NULL;
8275
9484
  SeqFeatPtr    gene;
8276
9485
  GeneRefPtr    grp;
8277
9486
  SeqMgrFeatContext context;
 
9487
  GBQualPtr         qual;
 
9488
  Boolean           found = FALSE;
8278
9489
  
8279
9490
  if (sfp == NULL || sfp->data.choice != SEQFEAT_RNA || userdata == NULL)
8280
9491
  {
8291
9502
    
8292
9503
  switch (avp->field_list->data.intvalue)
8293
9504
  {
8294
 
    case RNAFIELD_NAME :
8295
 
      if (rrp != NULL)
8296
 
      {
8297
 
        if (rrp->ext.choice == 0)
8298
 
        {
8299
 
          rrp->ext.choice = 1;
8300
 
          rrp->ext.value.ptrvalue = NULL;
8301
 
        }
8302
 
        if (rrp->ext.choice == 1)
8303
 
        {
8304
 
          rrp->ext.value.ptrvalue = HandleApplyValue (rrp->ext.value.ptrvalue, avp);        
8305
 
        }
8306
 
        else if (rrp->ext.choice == 2)
8307
 
        {
8308
 
          SettRNAName (sfp, avp);
8309
 
        }
8310
 
      }
 
9505
    case RNAFIELD_PRODUCT :
 
9506
      SetRNAProduct (sfp, avp);
8311
9507
      break;
8312
9508
    case RNAFIELD_COMMENT :
8313
9509
      sfp->comment = HandleApplyValue (sfp->comment, avp);
8314
9510
      break;
8315
 
    case RNAFIELD_PRODUCT :
8316
 
      gbqual = sfp->qual;
8317
 
      while (gbqual != NULL && StringICmp (gbqual->qual, "product") != 0)
8318
 
      {
8319
 
        gbqual_last = gbqual;
8320
 
        gbqual = gbqual->next;
8321
 
      }
8322
 
      if (gbqual == NULL)
8323
 
      {
8324
 
        if (StringHasNoText (avp->text_to_replace))
8325
 
        {
8326
 
          gbqual = GBQualNew ();
8327
 
          if (gbqual == NULL)
8328
 
          {
8329
 
            return;
8330
 
          }
8331
 
          gbqual->qual = StringSave ("product");
8332
 
          gbqual->val = StringSave (avp->new_text);
8333
 
          if (gbqual_last == NULL)
8334
 
          {
8335
 
            sfp->qual = gbqual;
8336
 
          }
8337
 
          else
8338
 
          {
8339
 
            gbqual->next = gbqual_last->next;
8340
 
            gbqual_last->next = gbqual;
8341
 
          }
8342
 
        }
8343
 
        else
8344
 
        {
8345
 
          /* don't create new product for edit/replace */
8346
 
        }
8347
 
      }
8348
 
      else
8349
 
      {        
8350
 
        gbqual->val = HandleApplyValue (gbqual->val, avp);
 
9511
    case RNAFIELD_NCRNA_CLASS :
 
9512
      for (qual = sfp->qual; qual != NULL; qual = qual->next)
 
9513
      {
 
9514
        if (StringCmp (qual->qual, "ncRNA_class") == 0)
 
9515
        {
 
9516
          qual->val = HandleApplyValue (qual->val, avp);
 
9517
          found = TRUE;
 
9518
        }
 
9519
      }
 
9520
      if (!found)
 
9521
      {
 
9522
        qual = GBQualNew ();
 
9523
        qual->qual = StringSave ("ncRNA_class");
 
9524
        qual->val = StringSave (avp->new_text);
 
9525
        qual->next = sfp->qual;
 
9526
        sfp->qual = qual;
8351
9527
      }
8352
9528
      break;
8353
9529
    default:
8370
9546
  }
8371
9547
}
8372
9548
 
 
9549
 
 
9550
static void RemoveRNAProduct (SeqFeatPtr sfp)
 
9551
{
 
9552
  RnaRefPtr rrp;
 
9553
  GBQualPtr gbq, prev_gbq = NULL;
 
9554
  tRNAPtr     trp;
 
9555
 
 
9556
  if (sfp == NULL || sfp->data.choice != SEQFEAT_RNA || sfp->data.value.ptrvalue == NULL)
 
9557
  {
 
9558
    return;
 
9559
  }
 
9560
 
 
9561
  rrp = (RnaRefPtr) sfp->data.value.ptrvalue;
 
9562
 
 
9563
  gbq = sfp->qual;
 
9564
  while (gbq != NULL && StringCmp (gbq->qual, "product") != 0)
 
9565
  {
 
9566
    prev_gbq = gbq;
 
9567
    gbq = gbq->next;
 
9568
  }
 
9569
  if (gbq != NULL)
 
9570
  {
 
9571
    if (prev_gbq == NULL)
 
9572
    {
 
9573
      sfp->qual = gbq->next;
 
9574
    }
 
9575
    else
 
9576
    {
 
9577
      prev_gbq->next = gbq->next;
 
9578
    }
 
9579
    gbq->next = NULL;
 
9580
    gbq = GBQualFree (gbq);
 
9581
  }
 
9582
  else if (rrp->ext.choice == 1
 
9583
           && (StringCmp (rrp->ext.value.ptrvalue, "ncRNA") == 0
 
9584
               || StringCmp (rrp->ext.value.ptrvalue, "tmRNA") == 0
 
9585
               || StringCmp (rrp->ext.value.ptrvalue, "misc_RNA") == 0))
 
9586
  {
 
9587
    /* do nothing - already have no product */
 
9588
  }
 
9589
  else if (rrp->ext.choice == 0)
 
9590
  {
 
9591
    /* do nothing - already have no product */
 
9592
  }
 
9593
  else if (rrp->ext.choice == 1)
 
9594
  {
 
9595
    rrp->ext.value.ptrvalue = MemFree (rrp->ext.value.ptrvalue);
 
9596
    rrp->ext.choice = 0;
 
9597
  }
 
9598
  else if (rrp->ext.choice == 2)
 
9599
  {
 
9600
    trp = (tRNAPtr) rrp->ext.value.ptrvalue;
 
9601
    if (trp != NULL)
 
9602
    {
 
9603
      trp->aatype = 0;
 
9604
    }
 
9605
  }
 
9606
}
 
9607
 
 
9608
 
8373
9609
static void RemoveRNAField (SeqFeatPtr sfp, Pointer userdata, FilterSetPtr fsp)
8374
9610
{
8375
9611
  RnaRefPtr     rrp;
8376
 
  GBQualPtr     gbqual, prev_qual = NULL, next_qual;
8377
9612
  tRNAPtr       trp;
8378
9613
  ApplyValuePtr avp;
8379
9614
  SeqFeatPtr    gene;
8380
9615
  GeneRefPtr    grp;
8381
9616
  ValNode       vn;
8382
9617
  SeqMgrFeatContext context;
 
9618
  GBQualPtr         qual, qual_prev = NULL, qual_next;
8383
9619
  
8384
9620
  if (sfp == NULL || sfp->data.choice != SEQFEAT_RNA || userdata == NULL)
8385
9621
  {
8396
9632
 
8397
9633
  switch (avp->field_list->data.intvalue)
8398
9634
  {
8399
 
    case RNAFIELD_NAME :
8400
 
      if (rrp != NULL && rrp->ext.value.ptrvalue != NULL)
8401
 
      {
8402
 
        if (rrp->ext.choice == 1)
8403
 
        {
8404
 
          rrp->ext.value.ptrvalue = MemFree (rrp->ext.value.ptrvalue);
8405
 
        }
8406
 
        else if (rrp->ext.choice == 2)
8407
 
        {
8408
 
          trp = (tRNAPtr) rrp->ext.value.ptrvalue;
8409
 
          if (trp != NULL)
8410
 
          {
8411
 
            trp->aatype = 0;
8412
 
          }
8413
 
        }
8414
 
      }
 
9635
    case RNAFIELD_PRODUCT :
 
9636
      RemoveRNAProduct (sfp);
8415
9637
      break;
8416
9638
    case RNAFIELD_COMMENT :
8417
9639
      sfp->comment = MemFree (sfp->comment);
8418
9640
      break;
8419
 
    case RNAFIELD_PRODUCT :
8420
 
      gbqual = sfp->qual;
8421
 
      while (gbqual != NULL) 
 
9641
    case RNAFIELD_NCRNA_CLASS :
 
9642
      qual = sfp->qual;
 
9643
      while (qual != NULL)
8422
9644
      {
8423
 
        next_qual = gbqual->next;
8424
 
        if (StringICmp (gbqual->qual, "product") == 0)
 
9645
        qual_next = qual->next;
 
9646
        if (StringCmp (qual->qual, "ncRNA_class") == 0)
8425
9647
        {
8426
 
          if (prev_qual == NULL)
 
9648
          if (qual_prev == NULL)
8427
9649
          {
8428
 
            sfp->qual = sfp->qual->next;
 
9650
            sfp->qual = qual_next;
8429
9651
          }
8430
9652
          else
8431
9653
          {
8432
 
            prev_qual->next = gbqual->next;
 
9654
            qual_prev->next = qual_next;
8433
9655
          }
8434
 
          gbqual->next = NULL;
8435
 
          GBQualFree (gbqual);
 
9656
          qual->next = NULL;
 
9657
          qual = GBQualFree (qual);
8436
9658
        }
8437
9659
        else
8438
9660
        {
8439
 
          prev_qual = gbqual;
 
9661
          qual_prev = qual;
8440
9662
        }
8441
 
        gbqual = next_qual;
 
9663
        qual = qual_next;
8442
9664
      }
8443
 
      break;    
 
9665
      break;
8444
9666
    case RNAFIELD_ANTICODON :
8445
9667
      if (rrp->ext.choice == 2) {
8446
9668
        trp = (tRNAPtr) rrp->ext.value.ptrvalue;
8547
9769
      gbqual = sfp->qual;
8548
9770
      while (gbqual != NULL && StringHasNoText (str))
8549
9771
      {
8550
 
        if (vnp->data.intvalue < NUM_EXON_FIELDS + 2
8551
 
            && vnp->data.intvalue >= 2
8552
 
            && StringCmp (gbqual->qual, exon_field_list[vnp->data.intvalue - 2]) == 0)
 
9772
        if (vnp->data.intvalue < NUM_EXON_FIELDS + 1
 
9773
            && vnp->data.intvalue >= 1
 
9774
            && StringCmp (gbqual->qual, exon_field_list[vnp->data.intvalue - 1]) == 0)
8553
9775
        {
8554
9776
          str = gbqual->val;
8555
9777
        }
8600
9822
      prev_qual = NULL;
8601
9823
      while (gbqual != NULL)
8602
9824
      {
8603
 
        if (vnp->data.intvalue < NUM_EXON_FIELDS + 2
8604
 
            && vnp->data.intvalue >= 2
8605
 
            && StringCmp (gbqual->qual, exon_field_list[vnp->data.intvalue - 2]) == 0)
 
9825
        if (vnp->data.intvalue <= NUM_EXON_FIELDS + 1
 
9826
            && vnp->data.intvalue >= 1
 
9827
            && StringCmp (gbqual->qual, exon_field_list[vnp->data.intvalue - 1]) == 0)
8606
9828
        {
8607
9829
           if (!StringHasNoText (gbqual->val))
8608
9830
           {
8612
9834
              if (prev_qual == NULL)
8613
9835
              {
8614
9836
                sfp->qual = gbqual->next;
8615
 
                gbqual->next = NULL;
8616
 
                GBQualFree (gbqual);
8617
 
                return;
 
9837
              } else {
 
9838
                prev_qual->next = gbqual->next;
8618
9839
              }
 
9840
              gbqual->next = NULL;
 
9841
              GBQualFree (gbqual);
 
9842
              return;
8619
9843
            }
8620
9844
          }
8621
9845
        }
 
9846
        prev_qual = gbqual;
8622
9847
        gbqual = gbqual->next;
8623
9848
      }
8624
9849
    }
8639
9864
  
8640
9865
  avp = (ApplyValuePtr) userdata;
8641
9866
  if (avp->field_list == NULL 
8642
 
      || avp->field_list->data.intvalue >= NUM_EXON_FIELDS + 2
8643
 
      || avp->field_list->data.intvalue < 2)
 
9867
      || avp->field_list->data.intvalue >= NUM_EXON_FIELDS + 1
 
9868
      || avp->field_list->data.intvalue < 1)
8644
9869
  {
8645
9870
    return;
8646
9871
  }
8654
9879
  while (gbqual != NULL)
8655
9880
  {
8656
9881
    if (StringCmp (gbqual->qual, 
8657
 
                   exon_field_list[avp->field_list->data.intvalue - 2]) == 0)
 
9882
                   exon_field_list[avp->field_list->data.intvalue - 1]) == 0)
8658
9883
    {
8659
9884
      gbqual->val = HandleApplyValue (gbqual->val, avp);
8660
9885
      found = TRUE;
8665
9890
  if (!found)
8666
9891
  {
8667
9892
    gbqual = GBQualNew ();
8668
 
    gbqual->qual = StringSave (exon_field_list[avp->field_list->data.intvalue - 2]);
 
9893
    gbqual->qual = StringSave (exon_field_list[avp->field_list->data.intvalue - 1]);
8669
9894
    gbqual->val = StringSave (avp->new_text);
8670
9895
    if (prev_qual == NULL)
8671
9896
    {
8816
10041
}
8817
10042
 
8818
10043
 
 
10044
static CharPtr GetDbxrefFromBioSource (BioSourcePtr biop, ValNodePtr vnp)
 
10045
{
 
10046
  ValNodePtr dbx;
 
10047
  DbtagPtr   dbtag;
 
10048
  Char       buf[20];
 
10049
 
 
10050
  if (biop == NULL || vnp == NULL || vnp->data.ptrvalue == NULL || biop->org == NULL)
 
10051
  {
 
10052
    return NULL;
 
10053
  }
 
10054
  
 
10055
  dbx = biop->org->db;
 
10056
  while (dbx != NULL)
 
10057
  {
 
10058
    dbtag = (DbtagPtr) dbx->data.ptrvalue;
 
10059
    if (dbtag != NULL && dbtag->tag != NULL
 
10060
        && StringCmp (dbtag->db, vnp->data.ptrvalue) == 0)
 
10061
    {
 
10062
      if (dbtag->tag->str == NULL)
 
10063
      {
 
10064
        sprintf (buf, "%d", dbtag->tag->id);
 
10065
        return StringSave (buf);
 
10066
      }
 
10067
      else
 
10068
      {
 
10069
        return StringSave (dbtag->tag->str);
 
10070
      }
 
10071
    }
 
10072
    dbx = dbx->next;
 
10073
  }
 
10074
  return NULL;
 
10075
}
 
10076
 
 
10077
static CharPtr 
 
10078
GetBioSourceFeatureDbxrefString 
 
10079
(SeqFeatPtr   sfp,
 
10080
 ValNodePtr   vnp,
 
10081
 FilterSetPtr fsp)
 
10082
{
 
10083
  if (sfp == NULL || sfp->data.choice != SEQFEAT_BIOSRC || vnp == NULL)
 
10084
  {
 
10085
    return NULL;
 
10086
  }
 
10087
  
 
10088
  return GetDbxrefFromBioSource (sfp->data.value.ptrvalue, vnp);
 
10089
}
 
10090
 
 
10091
static CharPtr 
 
10092
GetBioSourceDescriptorDbxrefString 
 
10093
(SeqDescrPtr  sdp,
 
10094
 ValNodePtr   vnp,
 
10095
 FilterSetPtr fsp)
 
10096
{
 
10097
  if (sdp == NULL || sdp->choice != Seq_descr_source || vnp == NULL)
 
10098
  {
 
10099
    return NULL;
 
10100
  }
 
10101
  return GetDbxrefFromBioSource (sdp->data.ptrvalue, vnp);
 
10102
}
 
10103
 
 
10104
 
 
10105
static void ApplyBioSourceDbxrefBioSourceCallback (BioSourcePtr biop, Pointer userdata)
 
10106
{
 
10107
  ApplyValuePtr avp;
 
10108
  ValNodePtr    dbx;
 
10109
  DbtagPtr      dbtag;
 
10110
  Boolean       found = FALSE;
 
10111
  Char          buf[20];
 
10112
  
 
10113
  if (biop == NULL || userdata == NULL)
 
10114
  {
 
10115
    return;
 
10116
  }
 
10117
  
 
10118
  avp = (ApplyValuePtr) userdata;
 
10119
  if (avp->field_list != NULL && !StringHasNoText (avp->new_text))
 
10120
  {
 
10121
    if (biop->org == NULL)
 
10122
    {
 
10123
      biop->org = OrgRefNew();
 
10124
    }
 
10125
    dbx = biop->org->db;
 
10126
    while (dbx != NULL && !found)
 
10127
    {
 
10128
      dbtag = (DbtagPtr) dbx->data.ptrvalue;
 
10129
      if (dbtag != NULL && dbtag->tag != NULL
 
10130
          && StringCmp (dbtag->db, avp->field_list->data.ptrvalue) == 0)
 
10131
      {
 
10132
        found = TRUE;
 
10133
      }
 
10134
      if (!found)
 
10135
      {
 
10136
        dbx = dbx->next;
 
10137
      }
 
10138
    }
 
10139
    if (!found)
 
10140
    {
 
10141
      dbtag = DbtagNew();
 
10142
      dbtag->db = StringSave (avp->field_list->data.ptrvalue);      
 
10143
      ValNodeAddPointer (&(biop->org->db), 0, dbtag);
 
10144
    }
 
10145
    if (dbtag->tag == NULL)
 
10146
    {
 
10147
      dbtag->tag = ObjectIdNew();
 
10148
    }
 
10149
    /* if it was a number before, make it a string now */
 
10150
    if (dbtag->tag->id > 0 && dbtag->tag->str == NULL)
 
10151
    {
 
10152
      sprintf (buf, "%s", dbtag->tag->id);
 
10153
      dbtag->tag->id = 0;
 
10154
      dbtag->tag->str = StringSave (buf);
 
10155
    }
 
10156
    dbtag->tag->str = HandleApplyValue (dbtag->tag->str, avp);
 
10157
  }
 
10158
  
 
10159
}
 
10160
 
 
10161
static void ApplyBioSourceDbxrefFeatureCallback (SeqFeatPtr sfp, Pointer userdata, FilterSetPtr fsp)
 
10162
{
 
10163
  if (sfp == NULL || sfp->data.choice != SEQFEAT_BIOSRC || userdata == NULL)
 
10164
  {
 
10165
    return;
 
10166
  }
 
10167
  ApplyBioSourceDbxrefBioSourceCallback (sfp->data.value.ptrvalue, userdata);
 
10168
}
 
10169
 
 
10170
static void ApplyBioSourceDbxrefDescriptorCallback (SeqDescrPtr sdp, Pointer userdata, FilterSetPtr fsp)
 
10171
{
 
10172
  if (sdp == NULL || sdp->choice != Seq_descr_source || userdata == NULL)
 
10173
  {
 
10174
    return;
 
10175
  }
 
10176
  ApplyBioSourceDbxrefBioSourceCallback (sdp->data.ptrvalue, userdata);
 
10177
}
 
10178
 
 
10179
 
 
10180
 
8819
10181
#define TEXT_PORTION_START_AFTER 1
8820
10182
#define TEXT_PORTION_START_WITH  2
8821
10183
#define TEXT_PORTION_END_AFTER   1
8829
10191
  TexT   start_text;
8830
10192
  GrouP  end_choice;
8831
10193
  TexT   end_text;
 
10194
  ButtoN rem_before;
 
10195
  ButtoN also_rem_before;
 
10196
  ButtoN rem_after;
 
10197
  ButtoN also_rem_after;
8832
10198
  ButtoN insensitive;
8833
10199
  ButtoN whole_word;
8834
 
} TextPortionDialogData, PNTR TextPortionDialogPtr;
8835
 
 
8836
 
static void ResetTextPortionDialog (TextPortionDialogPtr tp)
 
10200
 
 
10201
  Boolean inside;
 
10202
 
 
10203
  Nlm_ChangeNotifyProc     change_notify;
 
10204
  Pointer                  change_userdata;
 
10205
} TextPortionXDialogData, PNTR TextPortionXDialogPtr;
 
10206
 
 
10207
 
 
10208
static void OutsideEnableDisable (TextPortionXDialogPtr tp)
 
10209
{
 
10210
  if (tp == NULL || tp->inside)
 
10211
  {
 
10212
    return;
 
10213
  }
 
10214
  if (GetStatus (tp->rem_before)) 
 
10215
  {
 
10216
    Enable (tp->start_text);
 
10217
    Enable (tp->also_rem_before);
 
10218
  }
 
10219
  else
 
10220
  {
 
10221
    Disable (tp->start_text);
 
10222
    Disable (tp->also_rem_before);
 
10223
  }
 
10224
  if (GetStatus (tp->rem_after)) 
 
10225
  {
 
10226
    Enable (tp->end_text);
 
10227
    Enable (tp->also_rem_after);
 
10228
  }
 
10229
  else
 
10230
  {
 
10231
    Disable (tp->end_text);
 
10232
    Disable (tp->also_rem_after);
 
10233
  }
 
10234
}
 
10235
 
 
10236
static void ResetTextPortionXDialog (TextPortionXDialogPtr tp)
8837
10237
{
8838
10238
  if (tp == NULL)
8839
10239
  {
8840
10240
    return;
8841
10241
  }
8842
 
  SetValue (tp->start_choice, TEXT_PORTION_START_AFTER);
 
10242
  if (tp->inside)
 
10243
  {
 
10244
    SetValue (tp->start_choice, TEXT_PORTION_START_AFTER);
 
10245
    SetValue (tp->end_choice, TEXT_PORTION_END_AFTER);
 
10246
  }
 
10247
  else
 
10248
  {
 
10249
    SetStatus (tp->rem_before, FALSE);
 
10250
    SetStatus (tp->also_rem_before, FALSE);
 
10251
    SetStatus (tp->rem_after, FALSE);
 
10252
    SetStatus (tp->also_rem_after, FALSE);
 
10253
  }
8843
10254
  SetTitle (tp->start_text, "");
8844
 
  SetValue (tp->end_choice, TEXT_PORTION_END_AFTER);
8845
10255
  SetTitle (tp->end_text, "");
8846
10256
  SetStatus (tp->insensitive, FALSE);
8847
10257
  SetStatus (tp->whole_word, FALSE);
 
10258
  OutsideEnableDisable (tp);
8848
10259
}
8849
10260
 
8850
 
static void TextPortionToDialog (DialoG d, Pointer data)
 
10261
static void TextPortionXToDialog (DialoG d, Pointer data)
8851
10262
{
8852
 
  TextPortionDialogPtr tdlg;
8853
 
  TextPortionPtr       tdata;
 
10263
  TextPortionXDialogPtr tdlg;
 
10264
  TextPortionXPtr       tdata;
8854
10265
  Int4                 start_choice, end_choice;
8855
10266
  
8856
 
  tdlg = (TextPortionDialogPtr) GetObjectExtra (d);
 
10267
  tdlg = (TextPortionXDialogPtr) GetObjectExtra (d);
8857
10268
  if (tdlg == NULL)
8858
10269
  {
8859
10270
    return;
8860
10271
  }
8861
 
  tdata = (TextPortionPtr) data;
8862
 
  ResetTextPortionDialog (tdlg);  
 
10272
  tdata = (TextPortionXPtr) data;
 
10273
  ResetTextPortionXDialog (tdlg);  
8863
10274
  if (tdata != NULL)
8864
10275
  {
8865
10276
    start_choice = tdata->end_choice;
8872
10283
    {
8873
10284
      end_choice = TEXT_PORTION_END_AFTER;
8874
10285
    }
8875
 
    SetValue (tdlg->start_choice, start_choice);
8876
 
    SetValue (tdlg->end_choice, end_choice);
 
10286
    if (tdlg->inside)
 
10287
    {
 
10288
      SetValue (tdlg->start_choice, start_choice);
 
10289
      SetValue (tdlg->end_choice, end_choice);
 
10290
    }
 
10291
    else
 
10292
    {
 
10293
      SetStatus (tdlg->rem_before, StringHasNoText (tdata->start_text));
 
10294
      SetStatus (tdlg->rem_after, StringHasNoText (tdata->end_text));
 
10295
      if (start_choice == TEXT_PORTION_START_AFTER)
 
10296
      {
 
10297
        SetStatus (tdlg->also_rem_before, TRUE);
 
10298
      }
 
10299
      else
 
10300
      {
 
10301
        SetStatus (tdlg->also_rem_before, FALSE);
 
10302
      }
 
10303
      if (end_choice == TEXT_PORTION_END_AFTER)
 
10304
      {
 
10305
        SetStatus (tdlg->also_rem_after, TRUE);
 
10306
      }
 
10307
      else
 
10308
      {
 
10309
        SetStatus (tdlg->also_rem_after, FALSE);
 
10310
      }
 
10311
    }
8877
10312
    if (tdata->start_text != NULL)
8878
10313
    {
8879
10314
      SetTitle (tdlg->start_text, tdata->start_text);
8885
10320
    SetStatus (tdlg->insensitive, tdata->insensitive);
8886
10321
    SetStatus (tdlg->whole_word, tdata->whole_word);
8887
10322
  }
 
10323
  OutsideEnableDisable (tdlg);
8888
10324
}
8889
10325
 
8890
 
static Pointer DialogToTextPortion (DialoG d)
 
10326
static Pointer DialogToTextPortionX (DialoG d)
8891
10327
{
8892
 
  TextPortionDialogPtr tdlg;
8893
 
  TextPortionPtr       tdata;
 
10328
  TextPortionXDialogPtr tdlg;
 
10329
  TextPortionXPtr       tdata;
8894
10330
 
8895
 
  tdlg = (TextPortionDialogPtr) GetObjectExtra (d);
 
10331
  tdlg = (TextPortionXDialogPtr) GetObjectExtra (d);
8896
10332
  if (tdlg == NULL)
8897
10333
  {
8898
10334
    return NULL;
8899
10335
  }
8900
10336
 
8901
 
  tdata = (TextPortionPtr) MemNew (sizeof (TextPortionData));
 
10337
  tdata = (TextPortionXPtr) MemNew (sizeof (TextPortionXData));
8902
10338
  if (tdata != NULL)
8903
10339
  {
8904
 
    tdata->start_choice = GetValue (tdlg->start_choice);
8905
 
    tdata->end_choice = GetValue (tdlg->end_choice);
8906
 
    tdata->start_text = JustSaveStringFromText (tdlg->start_text);
8907
 
    tdata->end_text = JustSaveStringFromText (tdlg->end_text);
 
10340
    if (tdlg->inside)
 
10341
    {
 
10342
      tdata->start_choice = GetValue (tdlg->start_choice);
 
10343
      tdata->end_choice = GetValue (tdlg->end_choice);
 
10344
      tdata->start_text = JustSaveStringFromText (tdlg->start_text);
 
10345
      tdata->end_text = JustSaveStringFromText (tdlg->end_text);
 
10346
    }
 
10347
    else
 
10348
    {
 
10349
      if (GetStatus (tdlg->rem_before))
 
10350
      {
 
10351
        tdata->start_text = JustSaveStringFromText (tdlg->start_text);
 
10352
      }
 
10353
      else
 
10354
      {
 
10355
        tdata->start_text = NULL;
 
10356
      }
 
10357
      if (GetStatus (tdlg->rem_after))
 
10358
      {
 
10359
        tdata->end_text = JustSaveStringFromText (tdlg->end_text);
 
10360
      }
 
10361
      else
 
10362
      {
 
10363
        tdata->end_text = NULL;
 
10364
      }
 
10365
 
 
10366
      if (GetStatus (tdlg->also_rem_before))
 
10367
      {
 
10368
        tdata->start_choice = TEXT_PORTION_START_AFTER;
 
10369
      }
 
10370
      else
 
10371
      {
 
10372
        tdata->start_choice = TEXT_PORTION_START_WITH;
 
10373
      }
 
10374
      if (GetStatus (tdlg->also_rem_after))
 
10375
      {
 
10376
        tdata->end_choice = TEXT_PORTION_END_AFTER;
 
10377
      }
 
10378
      else
 
10379
      {
 
10380
        tdata->end_choice = TEXT_PORTION_END_WITH;
 
10381
      }
 
10382
 
 
10383
    }
 
10384
        
8908
10385
    tdata->insensitive = GetStatus (tdlg->insensitive);
8909
10386
    tdata->whole_word = GetStatus (tdlg->whole_word);
8910
10387
  }
8911
10388
  return tdata;
8912
10389
}
8913
10390
 
8914
 
static void TextPortionMessage (DialoG d, Int2 mssg)
 
10391
static void TextPortionXMessage (DialoG d, Int2 mssg)
8915
10392
 
8916
10393
{
8917
 
  TextPortionDialogPtr tp;
 
10394
  TextPortionXDialogPtr tp;
8918
10395
 
8919
 
  tp = (TextPortionDialogPtr) GetObjectExtra (d);
 
10396
  tp = (TextPortionXDialogPtr) GetObjectExtra (d);
8920
10397
  if (tp != NULL) {
8921
10398
    switch (mssg) {
8922
10399
      case VIB_MSG_INIT :
8923
 
        ResetTextPortionDialog (tp);        
 
10400
        ResetTextPortionXDialog (tp);        
8924
10401
        break;
8925
10402
      case VIB_MSG_ENTER :
8926
10403
        Select (tp->start_text);
8931
10408
  }
8932
10409
}
8933
10410
 
8934
 
static ValNodePtr TestTextPortionDialog (DialoG d)
 
10411
static ValNodePtr TestTextPortionXDialog (DialoG d)
8935
10412
 
8936
10413
{
8937
10414
  return NULL;
8938
10415
}
8939
10416
 
8940
 
extern DialoG TextPortionDialog (GrouP h)
8941
 
{
8942
 
  TextPortionDialogPtr tp;
 
10417
static void ChangeTextPortionXGroup (GrouP g)
 
10418
{
 
10419
  TextPortionXDialogPtr tp;
 
10420
 
 
10421
  tp = (TextPortionXDialogPtr) GetObjectExtra (g);
 
10422
  if (tp == NULL) return;
 
10423
 
 
10424
  if (tp->change_notify != NULL)
 
10425
  {
 
10426
    (tp->change_notify) (tp->change_userdata);
 
10427
  }
 
10428
}
 
10429
 
 
10430
static void ChangeTextPortionXText (TexT t)
 
10431
{
 
10432
  TextPortionXDialogPtr tp;
 
10433
 
 
10434
  tp = (TextPortionXDialogPtr) GetObjectExtra (t);
 
10435
  if (tp == NULL) return;
 
10436
 
 
10437
  if (tp->change_notify != NULL)
 
10438
  {
 
10439
    (tp->change_notify) (tp->change_userdata);
 
10440
  }
 
10441
}
 
10442
 
 
10443
 
 
10444
static void ChangeTextPortionXBtn (ButtoN b)
 
10445
{
 
10446
  TextPortionXDialogPtr tp;
 
10447
 
 
10448
  tp = (TextPortionXDialogPtr) GetObjectExtra (b);
 
10449
  if (tp == NULL) return;
 
10450
  OutsideEnableDisable (tp);
 
10451
 
 
10452
  if (tp->change_notify != NULL)
 
10453
  {
 
10454
    (tp->change_notify) (tp->change_userdata);
 
10455
  }
 
10456
}
 
10457
 
 
10458
 
 
10459
 
 
10460
extern DialoG TextPortionXDialogEx (GrouP h, Boolean inside, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
 
10461
{
 
10462
  TextPortionXDialogPtr tp;
8943
10463
  GrouP                p, g1, g2;
8944
10464
  
8945
 
  tp = (TextPortionDialogPtr) MemNew (sizeof (TextPortionDialogData));
 
10465
  tp = (TextPortionXDialogPtr) MemNew (sizeof (TextPortionXDialogData));
8946
10466
  if (tp == NULL)
8947
10467
  {
8948
10468
    return NULL;
8952
10472
  SetObjectExtra (p, tp, StdCleanupExtraProc);
8953
10473
 
8954
10474
  tp->dialog = (DialoG) p;
8955
 
  tp->todialog = TextPortionToDialog;
8956
 
  tp->fromdialog = DialogToTextPortion;
8957
 
  tp->dialogmessage = TextPortionMessage;
8958
 
  tp->testdialog = TestTextPortionDialog;
8959
 
 
8960
 
  g1 = HiddenGroup (p, 2, 0, NULL);
 
10475
  tp->todialog = TextPortionXToDialog;
 
10476
  tp->fromdialog = DialogToTextPortionX;
 
10477
  tp->dialogmessage = TextPortionXMessage;
 
10478
  tp->testdialog = TestTextPortionXDialog;
 
10479
 
 
10480
  tp->change_notify = change_notify;
 
10481
  tp->change_userdata = change_userdata;
 
10482
  tp->inside = inside;
 
10483
 
 
10484
  g1 = HiddenGroup (p, 3, 0, NULL);
8961
10485
  SetGroupSpacing (g1, 10, 10);
8962
10486
 
8963
 
  tp->start_choice = HiddenGroup (g1, 2, 0, NULL);
8964
 
  RadioButton (tp->start_choice, "just after");
8965
 
  RadioButton (tp->start_choice, "starting at");
8966
 
  SetValue (tp->start_choice, TEXT_PORTION_START_AFTER);
 
10487
  if (inside) 
 
10488
  {
 
10489
    StaticPrompt (g1, "Between", 0, popupMenuHeight, programFont, 'r');
 
10490
    tp->start_choice = HiddenGroup (g1, 2, 0, ChangeTextPortionXGroup);
 
10491
    RadioButton (tp->start_choice, "just after");
 
10492
    RadioButton (tp->start_choice, "starting at");
 
10493
    SetValue (tp->start_choice, TEXT_PORTION_START_AFTER);
 
10494
    SetObjectExtra (tp->start_choice, tp, NULL);
8967
10495
 
8968
 
  tp->start_text = DialogText (g1, "", 10, NULL);
8969
 
  
8970
 
  tp->end_choice = HiddenGroup (g1, 2, 0, NULL);
8971
 
  RadioButton (tp->end_choice, "up to");
8972
 
  RadioButton (tp->end_choice, "including");
8973
 
  SetValue (tp->end_choice, TEXT_PORTION_END_AFTER);
 
10496
    tp->start_text = DialogText (g1, "", 10, ChangeTextPortionXText);
 
10497
    SetObjectExtra (tp->start_text, tp, NULL);
8974
10498
    
8975
 
  tp->end_text = DialogText (g1, "", 10, NULL);
 
10499
    StaticPrompt (g1, "And", 0, popupMenuHeight, programFont, 'r');
 
10500
    tp->end_choice = HiddenGroup (g1, 2, 0, ChangeTextPortionXGroup);
 
10501
    RadioButton (tp->end_choice, "up to");
 
10502
    RadioButton (tp->end_choice, "including");
 
10503
    SetValue (tp->end_choice, TEXT_PORTION_END_AFTER);
 
10504
    SetObjectExtra (tp->start_choice, tp, NULL);
 
10505
      
 
10506
    tp->end_text = DialogText (g1, "", 10, ChangeTextPortionXText);
 
10507
    SetObjectExtra (tp->start_text, tp, NULL);
 
10508
  }
 
10509
  else
 
10510
  {
 
10511
    tp->rem_before = CheckBox (g1, "Before", ChangeTextPortionXBtn);
 
10512
    SetObjectExtra (tp->rem_before, tp, NULL);
 
10513
    tp->start_text = DialogText (g1, "", 10, ChangeTextPortionXText);
 
10514
    SetObjectExtra (tp->start_text, tp, NULL);
 
10515
    tp->also_rem_before = CheckBox (g1, "Also Remove Entered Text", ChangeTextPortionXBtn);
 
10516
 
 
10517
    tp->rem_after = CheckBox (g1, "After", ChangeTextPortionXBtn);
 
10518
    SetObjectExtra (tp->rem_after, tp, NULL);
 
10519
    tp->end_text = DialogText (g1, "", 10, ChangeTextPortionXText);
 
10520
    SetObjectExtra (tp->end_text, tp, NULL);
 
10521
    tp->also_rem_after = CheckBox (g1, "Also Remove Entered Text", ChangeTextPortionXBtn);    
 
10522
  }
8976
10523
  
8977
10524
  g2 = HiddenGroup (p, 2, 0, NULL);
8978
 
  tp->insensitive = CheckBox (g2, "Case insensitive", NULL);
8979
 
  tp->whole_word = CheckBox (g2, "Whole word", NULL);
 
10525
  tp->insensitive = CheckBox (g2, "Case insensitive", ChangeTextPortionXBtn);
 
10526
  SetObjectExtra (tp->insensitive, tp, NULL);
 
10527
  tp->whole_word = CheckBox (g2, "Whole word", ChangeTextPortionXBtn);
 
10528
  SetObjectExtra (tp->whole_word, tp, NULL);
8980
10529
  
8981
10530
  AlignObjects (ALIGN_CENTER, (HANDLE) g1, (HANDLE) g2, NULL);
8982
10531
  
8983
 
  ResetTextPortionDialog (tp);
 
10532
  ResetTextPortionXDialog (tp);
8984
10533
  return (DialoG) p;
8985
10534
}
8986
10535
 
8987
 
extern TextPortionPtr TextPortionFree (TextPortionPtr tp)
 
10536
extern DialoG TextPortionXDialog (GrouP h)
 
10537
{
 
10538
  return TextPortionXDialogEx (h, TRUE, NULL, NULL);
 
10539
}
 
10540
 
 
10541
extern TextPortionXPtr TextPortionXFree (TextPortionXPtr tp)
8988
10542
{
8989
10543
  if (tp == NULL) return NULL;
8990
10544
  tp->start_text = MemFree (tp->start_text);
9027
10581
}
9028
10582
 
9029
10583
extern void 
9030
 
FindTextPortionInString 
 
10584
FindTextPortionXInString 
9031
10585
(CharPtr        str, 
9032
 
 TextPortionPtr tp, 
 
10586
 TextPortionXPtr tp, 
9033
10587
 CharPtr PNTR   ploc, 
9034
10588
 Int4Ptr        plen)
9035
10589
{
9130
10684
  PointerToDialog (d, NULL);
9131
10685
}
9132
10686
 
 
10687
typedef struct changecasedlg {
 
10688
  DIALOG_MESSAGE_BLOCK
 
10689
  GrouP change_case;
 
10690
} ChangeCaseDlgData, PNTR ChangeCaseDlgPtr;
 
10691
 
 
10692
typedef enum {
 
10693
  eChangeCaseNone = 1,
 
10694
  eChangeCaseAllLower,
 
10695
  eChangeCaseCapFirst
 
10696
} EChangeCaseRule;
 
10697
 
 
10698
typedef struct changecase {
 
10699
  EChangeCaseRule change;
 
10700
} ChangeCaseData, PNTR ChangeCasePtr;
 
10701
 
 
10702
static void DataToChangeCaseDialog (DialoG d, Pointer data)
 
10703
{
 
10704
  ChangeCasePtr    ccp = (ChangeCasePtr) data;
 
10705
  ChangeCaseDlgPtr dlg = (ChangeCaseDlgPtr) GetObjectExtra (d);
 
10706
  if (dlg == NULL) return;
 
10707
 
 
10708
  if (ccp == NULL || ccp->change == eChangeCaseNone) {
 
10709
    SetValue (dlg->change_case, eChangeCaseNone);
 
10710
  } else {
 
10711
    SetValue (dlg->change_case, ccp->change);
 
10712
  }
 
10713
}
 
10714
 
 
10715
static Pointer ChangeCaseDialogToData (DialoG d)
 
10716
{
 
10717
  ChangeCaseDlgPtr dlg = (ChangeCaseDlgPtr) GetObjectExtra (d);
 
10718
  ChangeCasePtr    ccp = (ChangeCasePtr) MemNew (sizeof (ChangeCaseData));
 
10719
 
 
10720
  if (dlg == NULL) {
 
10721
    ccp->change = eChangeCaseNone;
 
10722
  } else {
 
10723
    ccp->change = GetValue (dlg->change_case);
 
10724
  }
 
10725
  return ccp;
 
10726
}
 
10727
 
 
10728
static DialoG ChangeCaseDialog (GrouP h)
 
10729
{
 
10730
  ChangeCaseDlgPtr dlg;
 
10731
  GrouP            p;
 
10732
  
 
10733
  dlg = (ChangeCaseDlgPtr) MemNew (sizeof (ChangeCaseDlgData));
 
10734
  if (dlg == NULL)
 
10735
  {
 
10736
    return NULL;
 
10737
  }
 
10738
 
 
10739
  p = HiddenGroup (h, -1, 0, NULL);
 
10740
  SetObjectExtra (p, dlg, StdCleanupExtraProc);
 
10741
  SetGroupSpacing (p, 10, 10);
 
10742
 
 
10743
  dlg->dialog = (DialoG) p;
 
10744
  dlg->todialog = DataToChangeCaseDialog;
 
10745
  dlg->fromdialog = ChangeCaseDialogToData;
 
10746
  dlg->dialogmessage = NULL;
 
10747
  dlg->testdialog = NULL;
 
10748
 
 
10749
  dlg->change_case = NormalGroup (p, 3, 0, "Capitalization", programFont, NULL);
 
10750
  SetGroupSpacing (dlg->change_case, 10, 10);
 
10751
 
 
10752
  RadioButton (dlg->change_case, "No change");
 
10753
  RadioButton (dlg->change_case, "To lower");
 
10754
  RadioButton (dlg->change_case, "First cap, rest lower");
 
10755
  SetValue (dlg->change_case, eChangeCaseNone);
 
10756
  
 
10757
  return (DialoG) p;
 
10758
}
 
10759
 
 
10760
 
 
10761
static void ChangeCase (CharPtr PNTR pText, ChangeCasePtr ccp, ValNodePtr orgnames)
 
10762
{
 
10763
  if (ccp != NULL) {
 
10764
    switch (ccp->change) {
 
10765
      case eChangeCaseNone:
 
10766
        break;
 
10767
      case eChangeCaseAllLower:
 
10768
        FixCapitalizationInTitle (pText, FALSE, orgnames);
 
10769
        break;
 
10770
      case eChangeCaseCapFirst:
 
10771
        FixCapitalizationInTitle (pText, TRUE, orgnames);
 
10772
        break;
 
10773
    }
 
10774
  }
 
10775
}
 
10776
 
9133
10777
typedef struct stringconstraintdialog 
9134
10778
{
9135
10779
  DIALOG_MESSAGE_BLOCK
9137
10781
  TexT   match_text;
9138
10782
  ButtoN insensitive;
9139
10783
  ButtoN whole_word;   
9140
 
} StringConstraintDialogData, PNTR StringConstraintDialogPtr;
 
10784
} StringConstraintDialogXData, PNTR StringConstraintDialogXPtr;
9141
10785
 
9142
 
static void ResetStringConstraintDialog (StringConstraintDialogPtr scdp)
 
10786
static void ResetStringConstraintDialogX (StringConstraintDialogXPtr scdp)
9143
10787
{
9144
10788
  if (scdp == NULL) return;
9145
10789
  
9149
10793
  SetStatus (scdp->whole_word, FALSE);
9150
10794
}
9151
10795
 
 
10796
 
 
10797
static Int4 GetPopupPosForStringConstraint (StringConstraintXPtr scp)
 
10798
{
 
10799
  Int4 rval = 1;
 
10800
 
 
10801
  if (scp == NULL) return 1;
 
10802
 
 
10803
  switch (scp->match_location)
 
10804
  {
 
10805
    case eStringConstraintContains:
 
10806
      if (scp->not_present) 
 
10807
      {
 
10808
        rval = 2;
 
10809
      } else {
 
10810
        rval = 1;
 
10811
      }
 
10812
      break;
 
10813
    case eStringConstraintEquals:
 
10814
      if (scp->not_present) {
 
10815
        rval = 4;
 
10816
      } else {
 
10817
        rval = 3;
 
10818
      }
 
10819
      break;
 
10820
    case eStringConstraintStarts:
 
10821
      if (scp->not_present) {
 
10822
        rval = 9;
 
10823
      } else {
 
10824
        rval = 5;
 
10825
      }
 
10826
      break;
 
10827
    case eStringConstraintEnds:
 
10828
      if (scp->not_present) {
 
10829
        rval = 10;
 
10830
      } else {
 
10831
        rval = 6;
 
10832
      }
 
10833
      break;
 
10834
    case eStringConstraintInList:
 
10835
      if (scp->not_present) {
 
10836
        rval = 8;
 
10837
      } else {
 
10838
        rval = 7;
 
10839
      }
 
10840
      break;
 
10841
  }
 
10842
  return rval;
 
10843
}
 
10844
 
 
10845
 
9152
10846
static void StringConstraintToDialog (DialoG d, Pointer data)
9153
10847
 
9154
10848
{
9155
 
  StringConstraintDialogPtr scdp;
9156
 
  StringConstraintPtr       scp;
9157
 
  Int4                      match_location;
 
10849
  StringConstraintDialogXPtr scdp;
 
10850
  StringConstraintXPtr       scp;
9158
10851
 
9159
 
  scdp = (StringConstraintDialogPtr) GetObjectExtra (d);
9160
 
  scp = (StringConstraintPtr) data;
 
10852
  scdp = (StringConstraintDialogXPtr) GetObjectExtra (d);
 
10853
  scp = (StringConstraintXPtr) data;
9161
10854
  if (scdp == NULL)
9162
10855
  {
9163
10856
    return;
9165
10858
 
9166
10859
  if (scp == NULL)
9167
10860
  {
9168
 
    ResetStringConstraintDialog (scdp);
 
10861
    ResetStringConstraintDialogX (scdp);
9169
10862
  }
9170
10863
  else
9171
10864
  {
9172
 
    match_location = scp->match_location;
9173
 
    if (match_location < STRING_CONSTRAINT_CONTAINS || match_location > STRING_CONSTRAINT_ENDS)
9174
 
    {
9175
 
      match_location = STRING_CONSTRAINT_CONTAINS;
9176
 
    }
9177
 
    
9178
 
    if (scp->not_present)
9179
 
    {
9180
 
      match_location += STRING_CONSTRAINT_ENDS;
9181
 
    }
9182
 
 
9183
 
    SetValue (scdp->match_choice, match_location);
 
10865
    SetValue (scdp->match_choice, GetPopupPosForStringConstraint (scp));
9184
10866
    
9185
10867
    if (StringHasNoText (scp->match_text))
9186
10868
    {
9199
10881
static Pointer DialogToStringConstraint (DialoG d)
9200
10882
 
9201
10883
{
9202
 
  StringConstraintDialogPtr scdp;
9203
 
  StringConstraintPtr       scp;
 
10884
  StringConstraintDialogXPtr scdp;
 
10885
  StringConstraintXPtr       scp;
9204
10886
  Int4                      match_choice;
9205
10887
 
9206
 
  scdp = (StringConstraintDialogPtr) GetObjectExtra (d);
 
10888
  scdp = (StringConstraintDialogXPtr) GetObjectExtra (d);
9207
10889
  if (scdp == NULL)
9208
10890
  {
9209
10891
    return NULL;
9210
10892
  }
9211
 
  scp = (StringConstraintPtr) MemNew (sizeof (StringConstraintData));
 
10893
  scp = (StringConstraintXPtr) MemNew (sizeof (StringConstraintData));
9212
10894
  if (scp != NULL)
9213
10895
  {
9214
10896
    scp->match_text = SaveStringFromText (scdp->match_text);
9218
10900
    switch (match_choice)
9219
10901
    {
9220
10902
      case 1:
9221
 
        scp->match_location = STRING_CONSTRAINT_CONTAINS;
 
10903
        scp->match_location = eStringConstraintContains;
9222
10904
        scp->not_present = FALSE;
9223
10905
        break;
9224
10906
      case 2:
9225
 
        scp->match_location = STRING_CONSTRAINT_CONTAINS;
 
10907
        scp->match_location = eStringConstraintContains;
9226
10908
        scp->not_present = TRUE;
9227
10909
        break;
9228
10910
      case 3:
9229
 
        scp->match_location = STRING_CONSTRAINT_EQUALS;
 
10911
        scp->match_location = eStringConstraintEquals;
9230
10912
        scp->not_present = FALSE;
9231
10913
        break;
9232
10914
      case 4:
9233
 
        scp->match_location = STRING_CONSTRAINT_EQUALS;
 
10915
        scp->match_location = eStringConstraintEquals;
9234
10916
        scp->not_present = TRUE;
9235
10917
        break;
9236
10918
      case 5:
9237
 
        scp->match_location = STRING_CONSTRAINT_STARTS;
 
10919
        scp->match_location = eStringConstraintStarts;
9238
10920
        scp->not_present = FALSE;
9239
10921
        break;
9240
10922
      case 6:
9241
 
        scp->match_location = STRING_CONSTRAINT_ENDS;
 
10923
        scp->match_location = eStringConstraintEnds;
9242
10924
        scp->not_present = FALSE;
9243
10925
        break;
9244
10926
      case 7:
9245
 
        scp->match_location = STRING_CONSTRAINT_STARTS;
9246
 
        scp->not_present = TRUE;
 
10927
        scp->match_location = eStringConstraintInList;
 
10928
        scp->not_present = FALSE;
9247
10929
        break;
9248
10930
      case 8:
9249
 
        scp->match_location = STRING_CONSTRAINT_ENDS;
 
10931
        scp->match_location = eStringConstraintInList;
 
10932
        scp->not_present = TRUE;
 
10933
        break;
 
10934
      case 9:
 
10935
        scp->match_location = eStringConstraintStarts;
 
10936
        scp->not_present = TRUE;
 
10937
        break;
 
10938
      case 10:
 
10939
        scp->match_location = eStringConstraintEnds;
9250
10940
        scp->not_present = TRUE;
9251
10941
        break;
9252
10942
      default:
9253
 
        scp->match_location = STRING_CONSTRAINT_CONTAINS;
 
10943
        scp->match_location = eStringConstraintContains;
9254
10944
        scp->not_present = FALSE;
9255
10945
        break;
9256
10946
    }
9261
10951
static void StringConstraintMessage (DialoG d, Int2 mssg)
9262
10952
 
9263
10953
{
9264
 
  StringConstraintDialogPtr scdp;
 
10954
  StringConstraintDialogXPtr scdp;
9265
10955
 
9266
 
  scdp = (StringConstraintDialogPtr) GetObjectExtra (d);
 
10956
  scdp = (StringConstraintDialogXPtr) GetObjectExtra (d);
9267
10957
  if (scdp != NULL) {
9268
10958
    switch (mssg) {
9269
10959
      case VIB_MSG_INIT :
9270
 
        ResetStringConstraintDialog (scdp);        
 
10960
        ResetStringConstraintDialogX (scdp);        
9271
10961
        break;
9272
10962
      case VIB_MSG_ENTER :
9273
10963
        Select (scdp->match_text);
9278
10968
  }
9279
10969
}
9280
10970
 
9281
 
static ValNodePtr TestStringConstraintDialog (DialoG d)
 
10971
static ValNodePtr TestStringConstraintDialogX (DialoG d)
9282
10972
 
9283
10973
{
9284
10974
  return NULL;
9285
10975
}
9286
10976
 
9287
 
extern DialoG StringConstraintDialog (GrouP h, CharPtr label, Boolean clear_btn)
 
10977
extern DialoG StringConstraintDialogX (GrouP h, CharPtr label, Boolean clear_btn)
9288
10978
 
9289
10979
{
9290
 
  StringConstraintDialogPtr scdp;
 
10980
  StringConstraintDialogXPtr scdp;
9291
10981
  GrouP                     p, g, k;
9292
10982
  ButtoN                    b = NULL;
9293
10983
  
9294
 
  scdp = (StringConstraintDialogPtr) MemNew (sizeof (StringConstraintDialogData));
 
10984
  scdp = (StringConstraintDialogXPtr) MemNew (sizeof (StringConstraintDialogXData));
9295
10985
  if (scdp == NULL)
9296
10986
  {
9297
10987
    return NULL;
9304
10994
  scdp->todialog = StringConstraintToDialog;
9305
10995
  scdp->fromdialog = DialogToStringConstraint;
9306
10996
  scdp->dialogmessage = StringConstraintMessage;
9307
 
  scdp->testdialog = TestStringConstraintDialog;
 
10997
  scdp->testdialog = TestStringConstraintDialogX;
9308
10998
 
9309
10999
  g = HiddenGroup (p, 3, 0, NULL);
9310
11000
  SetGroupSpacing (g, 10, 10);
9321
11011
  PopupItem (scdp->match_choice, "Does not equal");
9322
11012
  PopupItem (scdp->match_choice, "Starts with");
9323
11013
  PopupItem (scdp->match_choice, "Ends with");
 
11014
  PopupItem (scdp->match_choice, "Is one of");
 
11015
  PopupItem (scdp->match_choice, "Is not one of");
9324
11016
  PopupItem (scdp->match_choice, "Does not start with");
9325
11017
  PopupItem (scdp->match_choice, "Does not end with");
9326
11018
  SetValue (scdp->match_choice, 1);
9495
11187
  DialoG              string_qual_choice;
9496
11188
  DialoG              string_constraint;
9497
11189
  DialoG              pseudo_constraint;
 
11190
  DialoG              match_1;
 
11191
  DialoG              match_2;
9498
11192
  FreeValNodeProc     free_vn_proc;
9499
11193
  CopyValNodeDataProc copy_vn_proc;
9500
11194
} ChoiceConstraintDialogData, PNTR ChoiceConstraintDialogPtr;
9516
11210
    Enable (scdp->present_qual_choice);
9517
11211
    Disable (scdp->string_qual_choice);
9518
11212
    Disable (scdp->string_constraint);
 
11213
    Disable (scdp->match_1);
 
11214
    Disable (scdp->match_2);
9519
11215
    SafeDisable (scdp->pseudo_constraint);
9520
11216
  }
9521
11217
  else if (constraint_type == CHOICE_CONSTRAINT_STRING)
9523
11219
    Enable (scdp->string_qual_choice);
9524
11220
    Enable (scdp->string_constraint);
9525
11221
    Disable (scdp->present_qual_choice);
 
11222
    Disable (scdp->match_1);
 
11223
    Disable (scdp->match_2);
 
11224
    SafeDisable (scdp->pseudo_constraint);
 
11225
  }
 
11226
  else if (constraint_type == CHOICE_CONSTRAINT_MATCH)
 
11227
  {
 
11228
    Enable (scdp->match_1);
 
11229
    Enable (scdp->match_2);
 
11230
    Disable (scdp->string_qual_choice);
 
11231
    Disable (scdp->string_constraint);
 
11232
    Disable (scdp->present_qual_choice);
9526
11233
    SafeDisable (scdp->pseudo_constraint);
9527
11234
  }
9528
11235
  else if (constraint_type == CHOICE_CONSTRAINT_PSEUDO)
9530
11237
    Disable (scdp->present_qual_choice);
9531
11238
    Disable (scdp->string_qual_choice);
9532
11239
    Disable (scdp->string_constraint);
 
11240
    Disable (scdp->match_1);
 
11241
    Disable (scdp->match_2);
9533
11242
    Enable (scdp->pseudo_constraint);
9534
11243
  }
9535
11244
  else
9537
11246
    Disable (scdp->present_qual_choice);
9538
11247
    Disable (scdp->string_qual_choice);
9539
11248
    Disable (scdp->string_constraint);
 
11249
    Disable (scdp->match_1);
 
11250
    Disable (scdp->match_2);
9540
11251
    SafeDisable (scdp->pseudo_constraint);
9541
11252
  }
9542
11253
}
9587
11298
      PointerToDialog (src_dlg->string_qual_choice, src_data->qual_choice);
9588
11299
      PointerToDialog (src_dlg->string_constraint, src_data->string_constraint);
9589
11300
    }
 
11301
    else if (constraint_type == CHOICE_CONSTRAINT_MATCH)
 
11302
    {
 
11303
      PointerToDialog (src_dlg->match_1, src_data->qual_choice);
 
11304
      PointerToDialog (src_dlg->match_2, src_data->qual_choice_match);
 
11305
    }
9590
11306
    else if (constraint_type == CHOICE_CONSTRAINT_PSEUDO)
9591
11307
    {
9592
11308
      PointerToDialog (src_dlg->pseudo_constraint, src_data->pseudo_constraint);
9619
11335
      src_data->qual_choice = DialogToPointer (src_dlg->string_qual_choice);
9620
11336
      src_data->string_constraint = DialogToPointer (src_dlg->string_constraint);
9621
11337
    }
 
11338
    else if (src_data->constraint_type == CHOICE_CONSTRAINT_MATCH)
 
11339
    {
 
11340
      src_data->qual_choice = DialogToPointer (src_dlg->match_1);
 
11341
      src_data->qual_choice_match = DialogToPointer (src_dlg->match_2);
 
11342
    }
9622
11343
    else if (src_data->constraint_type == CHOICE_CONSTRAINT_PSEUDO)
9623
11344
    {
9624
11345
      src_data->pseudo_constraint = DialogToPointer (src_dlg->pseudo_constraint);
9697
11418
  RadioButton (scdp->constraint_type, "When");
9698
11419
  q = HiddenGroup (scdp->constraint_type, 2, 0, NULL);
9699
11420
  scdp->string_qual_choice = func_string (q, TRUE, NULL, NULL);
9700
 
  scdp->string_constraint = StringConstraintDialog (q, NULL, FALSE);
 
11421
  scdp->string_constraint = StringConstraintDialogX (q, NULL, FALSE);
9701
11422
  
 
11423
  RadioButton (scdp->constraint_type, "When");
 
11424
  q = HiddenGroup (scdp->constraint_type, 3, 0, NULL);
 
11425
  scdp->match_1 = func_string (q, TRUE, NULL, NULL);
 
11426
  StaticPrompt (q, "Equals", 0, dialogTextHeight, systemFont, 'l');
 
11427
  scdp->match_2 = func_string (q, TRUE, NULL, NULL);
 
11428
 
9702
11429
  if (use_pseudo)
9703
11430
  {
9704
11431
    RadioButton (scdp->constraint_type, "When");
9715
11442
  Disable (scdp->present_qual_choice);
9716
11443
  Disable (scdp->string_qual_choice);
9717
11444
  Disable (scdp->string_constraint);
 
11445
  Disable (scdp->match_1);
 
11446
  Disable (scdp->match_2);
9718
11447
  
9719
11448
  scdp->free_vn_proc = free_vn_proc;
9720
11449
  scdp->copy_vn_proc = copy_vn_proc;
9730
11459
  return (DialoG) p;
9731
11460
}
9732
11461
 
9733
 
extern DialoG SourceConstraintDialog (GrouP h, Boolean clear_btn)
 
11462
extern DialoG SourceConstraintDialogX (GrouP h, Boolean clear_btn)
9734
11463
{
9735
11464
  return ConstraintChoiceDialog (h, SourceQualTypeConstraintSelectionDialog, 
9736
11465
                                 SourceStringConstraintSelectionDialog,
9762
11491
                                 clear_btn, TRUE);
9763
11492
}
9764
11493
 
9765
 
typedef struct locationconstraintdialog 
 
11494
typedef struct LocationConstraintXdialog 
9766
11495
{
9767
11496
  DIALOG_MESSAGE_BLOCK
9768
11497
  PopuP  interval_end_choice;
9775
11504
  PopuP  strand;
9776
11505
  PopuP  sequence_type;
9777
11506
  Boolean show_interval_controls;
9778
 
} LocationConstraintDialogData, PNTR LocationConstraintDialogPtr;
 
11507
} LocationConstraintXDialogData, PNTR LocationConstraintXDialogPtr;
9779
11508
 
9780
11509
static void ShowLocationChoiceControls (PopuP p)
9781
11510
 
9782
11511
{
9783
 
  LocationConstraintDialogPtr lcdp;
 
11512
  LocationConstraintXDialogPtr lcdp;
9784
11513
  Int4                        match_choice;
9785
11514
 
9786
 
  lcdp = (LocationConstraintDialogPtr) GetObjectExtra (p);
 
11515
  lcdp = (LocationConstraintXDialogPtr) GetObjectExtra (p);
9787
11516
  if (lcdp == NULL || lcdp->interval_end_choice == NULL) return;
9788
11517
  
9789
11518
  if (GetValue (lcdp->interval_end_choice) == LOCATION_CONSTRAINT_WHOLE_INTERVAL)
9834
11563
  }
9835
11564
}
9836
11565
 
9837
 
static void ResetLocationConstraintDialog (LocationConstraintDialogPtr lcdp)
 
11566
static void ResetLocationConstraintXDialog (LocationConstraintXDialogPtr lcdp)
9838
11567
{
9839
11568
  if (lcdp == NULL) return;
9840
11569
  
9848
11577
  ShowLocationChoiceControls (lcdp->interval_end_choice);
9849
11578
}
9850
11579
 
9851
 
static void LocationConstraintToDialog (DialoG d, Pointer data)
 
11580
static void LocationConstraintXToDialog (DialoG d, Pointer data)
9852
11581
 
9853
11582
{
9854
 
  LocationConstraintDialogPtr lcdp;
9855
 
  LocationConstraintPtr       lcp;
 
11583
  LocationConstraintXDialogPtr lcdp;
 
11584
  LocationConstraintXPtr       lcp;
9856
11585
  Int4                        interval_end_choice;
9857
11586
  Int4                        match_choice;
9858
11587
  Char                        tmp [15];
9859
11588
  Int4                        strand;
9860
11589
  Int4                        sequence_type;
9861
11590
 
9862
 
  lcdp = (LocationConstraintDialogPtr) GetObjectExtra (d);
 
11591
  lcdp = (LocationConstraintXDialogPtr) GetObjectExtra (d);
9863
11592
  if (lcdp == NULL)
9864
11593
  {
9865
11594
    return;
9866
11595
  }
9867
 
  lcp = (LocationConstraintPtr) data;
 
11596
  lcp = (LocationConstraintXPtr) data;
9868
11597
  
9869
 
  ResetLocationConstraintDialog (lcdp);
 
11598
  ResetLocationConstraintXDialog (lcdp);
9870
11599
  if (lcp != NULL)
9871
11600
  {
9872
11601
    interval_end_choice = lcp->interval_end_choice;
9942
11671
  ShowLocationChoiceControls (lcdp->interval_match_choice);
9943
11672
}
9944
11673
 
9945
 
static Pointer DialogToLocationConstraint (DialoG d)
 
11674
static Pointer DialogToLocationConstraintX (DialoG d)
9946
11675
 
9947
11676
{
9948
 
  LocationConstraintDialogPtr lcdp;
9949
 
  LocationConstraintPtr       lcp;
 
11677
  LocationConstraintXDialogPtr lcdp;
 
11678
  LocationConstraintXPtr       lcp;
9950
11679
  CharPtr                     tmp;
9951
11680
 
9952
 
  lcdp = (LocationConstraintDialogPtr) GetObjectExtra (d);
 
11681
  lcdp = (LocationConstraintXDialogPtr) GetObjectExtra (d);
9953
11682
  if (lcdp == NULL)
9954
11683
  {
9955
11684
    return NULL;
9956
11685
  }
9957
 
  lcp = (LocationConstraintPtr) MemNew (sizeof (LocationConstraintData));
 
11686
  lcp = (LocationConstraintXPtr) MemNew (sizeof (LocationConstraintXData));
9958
11687
  if (lcp != NULL)
9959
11688
  {
9960
11689
    if (lcdp->show_interval_controls)
10024
11753
  return lcp;
10025
11754
}
10026
11755
 
10027
 
static void LocationConstraintMessage (DialoG d, Int2 mssg)
 
11756
static void LocationConstraintXMessage (DialoG d, Int2 mssg)
10028
11757
 
10029
11758
{
10030
 
  LocationConstraintDialogPtr lcdp;
 
11759
  LocationConstraintXDialogPtr lcdp;
10031
11760
 
10032
 
  lcdp = (LocationConstraintDialogPtr) GetObjectExtra (d);
 
11761
  lcdp = (LocationConstraintXDialogPtr) GetObjectExtra (d);
10033
11762
  if (lcdp != NULL) {
10034
11763
    switch (mssg) {
10035
11764
      case VIB_MSG_INIT :
10036
 
        ResetLocationConstraintDialog (lcdp);        
 
11765
        ResetLocationConstraintXDialog (lcdp);        
10037
11766
        break;
10038
11767
      case VIB_MSG_ENTER :
10039
11768
        if (lcdp->show_interval_controls)
10051
11780
  }
10052
11781
}
10053
11782
 
10054
 
static ValNodePtr TestLocationConstraintDialog (DialoG d)
 
11783
static ValNodePtr TestLocationConstraintXDialog (DialoG d)
10055
11784
 
10056
11785
{
10057
11786
  return NULL;
10059
11788
 
10060
11789
 
10061
11790
extern DialoG 
10062
 
LocationConstraintDialog 
 
11791
LocationConstraintXDialog 
10063
11792
(GrouP   h,
10064
11793
 Boolean show_interval_controls, 
10065
11794
 Boolean clear_btn)
10066
11795
 
10067
11796
{
10068
 
  LocationConstraintDialogPtr lcdp;
 
11797
  LocationConstraintXDialogPtr lcdp;
10069
11798
  GrouP                       p, g, k, val_grp, strand_grp, g2, g3, g4;
10070
11799
  ButtoN                      b = NULL;
10071
11800
  
10072
 
  lcdp = (LocationConstraintDialogPtr) MemNew (sizeof (LocationConstraintDialogData));
 
11801
  lcdp = (LocationConstraintXDialogPtr) MemNew (sizeof (LocationConstraintXDialogData));
10073
11802
  if (lcdp == NULL)
10074
11803
  {
10075
11804
    return NULL;
10079
11808
  SetObjectExtra (p, lcdp, StdCleanupExtraProc);
10080
11809
 
10081
11810
  lcdp->dialog = (DialoG) p;
10082
 
  lcdp->todialog = LocationConstraintToDialog;
10083
 
  lcdp->fromdialog = DialogToLocationConstraint;
10084
 
  lcdp->dialogmessage = LocationConstraintMessage;
10085
 
  lcdp->testdialog = TestLocationConstraintDialog;
 
11811
  lcdp->todialog = LocationConstraintXToDialog;
 
11812
  lcdp->fromdialog = DialogToLocationConstraintX;
 
11813
  lcdp->dialogmessage = LocationConstraintXMessage;
 
11814
  lcdp->testdialog = TestLocationConstraintXDialog;
10086
11815
  
10087
11816
  lcdp->show_interval_controls = show_interval_controls;
10088
11817
 
10164
11893
  return (DialoG) p;
10165
11894
}
10166
11895
 
10167
 
static Boolean DoesStrandMatchConstraint (SeqLocPtr slp, LocationConstraintPtr lcp)
 
11896
static Boolean DoesStrandMatchConstraint (SeqLocPtr slp, LocationConstraintXPtr lcp)
10168
11897
{
10169
11898
  Uint2 strand;
10170
11899
  Boolean rval = FALSE;
10206
11935
  return rval;
10207
11936
}
10208
11937
 
10209
 
static Boolean DoesSequenceTypeMatchContraint (SeqLocPtr slp, LocationConstraintPtr lcp)
 
11938
static Boolean DoesSequenceTypeMatchContraint (SeqLocPtr slp, LocationConstraintXPtr lcp)
10210
11939
{
10211
11940
  Boolean   rval = FALSE;
10212
11941
  BioseqPtr bsp;
10237
11966
  return rval;
10238
11967
}
10239
11968
 
10240
 
extern Boolean DoesLocationMatchConstraint (SeqLocPtr slp, LocationConstraintPtr lcp)
 
11969
extern Boolean DoesLocationMatchConstraint (SeqLocPtr slp, LocationConstraintXPtr lcp)
10241
11970
 
10242
11971
{
10243
11972
  Boolean rval = FALSE;
10382
12111
  DialoG source_constraint;
10383
12112
  DialoG location_constraint;
10384
12113
  DialoG cds_gene_prot_constraint;
 
12114
  DialoG id_list_constraint;
10385
12115
  
10386
12116
  DialoG tbs;
10387
 
  DialoG pages[4];
 
12117
  DialoG pages[6];
10388
12118
  Int4   current_page;
10389
12119
  
10390
12120
} FilterFormData, PNTR FilterFormPtr;
10405
12135
  PointerToDialog (dlg->source_constraint, NULL);
10406
12136
  PointerToDialog (dlg->location_constraint, NULL);
10407
12137
  PointerToDialog (dlg->cds_gene_prot_constraint, NULL);
 
12138
  PointerToDialog (dlg->id_list_constraint, NULL);
10408
12139
  
10409
12140
  if (dlg_data != NULL)
10410
12141
  {
10412
12143
    PointerToDialog (dlg->source_constraint, dlg_data->ccp);
10413
12144
    PointerToDialog (dlg->location_constraint, dlg_data->lcp);
10414
12145
    PointerToDialog (dlg->cds_gene_prot_constraint, dlg_data->cgp);
10415
 
  }
10416
 
}
 
12146
    PointerToDialog (dlg->id_list_constraint, dlg_data->id_list);
 
12147
  }
 
12148
}
 
12149
 
 
12150
static void ApplyNthPage (FilterFormPtr dlg, FilterSetPtr dlg_data, Int4 page)
 
12151
{
 
12152
  if (page < 0) return;
 
12153
 
 
12154
  /* adjust page value to reflect missing pages */
 
12155
  if (dlg->source_constraint == NULL)
 
12156
  {
 
12157
    page++;
 
12158
  }
 
12159
  if (dlg->string_constraint == NULL && page >= 1)
 
12160
  {
 
12161
    page++;
 
12162
  }
 
12163
  if (dlg->location_constraint == NULL && page >= 2)
 
12164
  {
 
12165
    page++;
 
12166
  }
 
12167
  if (dlg->cds_gene_prot_constraint == NULL && page >= 3)
 
12168
  {
 
12169
    page++;
 
12170
  }
 
12171
  if (dlg->id_list_constraint == NULL && page >= 4)
 
12172
  {
 
12173
    page++;
 
12174
  }
 
12175
  
 
12176
  switch (page)
 
12177
  {
 
12178
    case 0:
 
12179
      dlg_data->ccp = DialogToPointer (dlg->source_constraint);
 
12180
      break;
 
12181
    case 1:
 
12182
      dlg_data->scp = DialogToPointer (dlg->string_constraint);
 
12183
      break;
 
12184
    case 2:
 
12185
      dlg_data->lcp = DialogToPointer (dlg->location_constraint);
 
12186
      break;
 
12187
    case 3:
 
12188
      dlg_data->cgp = DialogToPointer (dlg->cds_gene_prot_constraint);
 
12189
      break;
 
12190
    case 4:
 
12191
      dlg_data->id_list = DialogToPointer (dlg->id_list_constraint);
 
12192
      break;
 
12193
  }
 
12194
  
 
12195
}
 
12196
 
10417
12197
 
10418
12198
static Pointer DialogToFilter (DialoG d)
10419
12199
{
10430
12210
  
10431
12211
  if (dlg_data != NULL)
10432
12212
  {
10433
 
    dlg_data->scp = DialogToPointer (dlg->string_constraint);
10434
 
    dlg_data->ccp = DialogToPointer (dlg->source_constraint);
10435
 
    dlg_data->lcp = DialogToPointer (dlg->location_constraint);
10436
 
    dlg_data->cgp = DialogToPointer (dlg->cds_gene_prot_constraint);
 
12213
    if (dlg->tbs == NULL) 
 
12214
    {
 
12215
      dlg_data->scp = DialogToPointer (dlg->string_constraint);
 
12216
      dlg_data->ccp = DialogToPointer (dlg->source_constraint);
 
12217
      dlg_data->lcp = DialogToPointer (dlg->location_constraint);
 
12218
      dlg_data->cgp = DialogToPointer (dlg->cds_gene_prot_constraint);
 
12219
      dlg_data->id_list = DialogToPointer (dlg->id_list_constraint);
 
12220
    }
 
12221
    else
 
12222
    {
 
12223
      /* only take one value */
 
12224
      ApplyNthPage (dlg, dlg_data, dlg->current_page);
 
12225
    }
10437
12226
  }
10438
12227
  return dlg_data;
10439
12228
}
10482
12271
 Boolean has_source_constraint,
10483
12272
 Boolean has_location_constraint,
10484
12273
 Boolean has_cds_gene_prot_constraint,
 
12274
 Boolean has_id_list_constraint,
10485
12275
 CharPtr string_constraint_label)
10486
12276
{
10487
12277
  GrouP         g, k;
10494
12284
  if (! has_string_constraint
10495
12285
      && ! has_source_constraint
10496
12286
      && ! has_location_constraint
10497
 
      && ! has_cds_gene_prot_constraint)
 
12287
      && ! has_cds_gene_prot_constraint
 
12288
      && ! has_id_list_constraint)
10498
12289
  {
10499
12290
    return NULL;
10500
12291
  }
10532
12323
  {
10533
12324
    filterTabs [num_pages++] = "CDS-Gene-Prot-mRNA Set Constraint";
10534
12325
  }
 
12326
  if (has_id_list_constraint)
 
12327
  {
 
12328
    filterTabs [num_pages++] = "Sequence ID Constraint";
 
12329
  }
10535
12330
  filterTabs [num_pages] = NULL;
10536
12331
  
10537
12332
  if (num_pages > 1)
10544
12339
    num_pages = 0;
10545
12340
    if (has_source_constraint)
10546
12341
    {
10547
 
      ffp->source_constraint = SourceConstraintDialog (k, FALSE);
 
12342
      ffp->source_constraint = SourceConstraintDialogX (k, FALSE);
10548
12343
      ffp->pages [num_pages++] = ffp->source_constraint;
10549
12344
    }
10550
12345
    if (has_string_constraint)
10551
12346
    {
10552
 
      ffp->string_constraint = StringConstraintDialog (k, string_constraint_label, FALSE);
 
12347
      ffp->string_constraint = StringConstraintDialogX (k, string_constraint_label, FALSE);
10553
12348
      ffp->pages [num_pages++] = ffp->string_constraint;
10554
12349
    }
10555
12350
    if (has_location_constraint)
10556
12351
    {
10557
 
      ffp->location_constraint = LocationConstraintDialog (k, FALSE, FALSE);
 
12352
      ffp->location_constraint = LocationConstraintXDialog (k, FALSE, FALSE);
10558
12353
      ffp->pages [num_pages++] = ffp->location_constraint;
10559
12354
    }
10560
12355
    if (has_cds_gene_prot_constraint)
10562
12357
      ffp->cds_gene_prot_constraint = CDSGeneProtConstraintDialog (k, FALSE);
10563
12358
      ffp->pages [num_pages++] = ffp->cds_gene_prot_constraint;
10564
12359
    }
 
12360
    if (has_id_list_constraint)
 
12361
    {
 
12362
      ffp->id_list_constraint = StringConstraintDialogX (k, "Where sequence ID", FALSE);
 
12363
      ffp->pages[num_pages++] = ffp->id_list_constraint;
 
12364
    }
10565
12365
    for (i = 1; i < num_pages; i++)
10566
12366
    {
10567
12367
      Hide (ffp->pages [i]);
10569
12369
    AlignObjects (ALIGN_CENTER, (HANDLE) ffp->pages [0],
10570
12370
                                (HANDLE) ffp->pages [1],
10571
12371
                                (HANDLE) ffp->pages [2],
 
12372
                                (HANDLE) ffp->pages [3],
10572
12373
                                NULL);
10573
12374
    clear_constraints = PushButton (g, "Clear Constraints", ClearAllConstraints);
10574
12375
    SetObjectExtra (clear_constraints, ffp, NULL);
10578
12379
  {
10579
12380
    if (has_source_constraint)
10580
12381
    {
10581
 
      ffp->source_constraint = SourceConstraintDialog (g, TRUE);
 
12382
      ffp->source_constraint = SourceConstraintDialogX (g, TRUE);
10582
12383
    }
10583
12384
    else if (has_string_constraint)
10584
12385
    {
10585
 
      ffp->string_constraint = StringConstraintDialog (g, string_constraint_label, TRUE);
 
12386
      ffp->string_constraint = StringConstraintDialogX (g, string_constraint_label, TRUE);
10586
12387
    }
10587
12388
    else if (has_location_constraint)
10588
12389
    {
10589
 
      ffp->location_constraint = LocationConstraintDialog (g, FALSE, TRUE);
 
12390
      ffp->location_constraint = LocationConstraintXDialog (g, FALSE, TRUE);
10590
12391
    }
10591
12392
    else if (has_cds_gene_prot_constraint)
10592
12393
    {
10593
12394
      ffp->cds_gene_prot_constraint = CDSGeneProtConstraintDialog (g, TRUE);
10594
12395
    }
 
12396
    else if (has_id_list_constraint)
 
12397
    {
 
12398
      ffp->id_list_constraint = StringConstraintDialogX (g, "Where sequence ID", TRUE);
 
12399
    }
10595
12400
  }
10596
12401
  return (DialoG) g;
10597
12402
}
10599
12404
/* Operations on constrained features and descriptors */
10600
12405
typedef struct objecthasstring
10601
12406
{
10602
 
  StringConstraintPtr scp;
 
12407
  StringConstraintXPtr scp;
10603
12408
  Boolean             found;
10604
12409
} ObjectHasStringData, PNTR ObjectHasStringPtr;
10605
12410
 
10619
12424
  Uint1                  descriptorChoice;
10620
12425
} ConstraintOpData, PNTR ConstraintOpPtr;
10621
12426
 
10622
 
extern Boolean DoesStringMatchConstraint (CharPtr pchSource, StringConstraintPtr scp)
 
12427
extern Boolean DoesStringMatchConstraintX (CharPtr pchSource, StringConstraintXPtr scp)
10623
12428
{
10624
12429
  CharPtr pFound;
10625
12430
  Boolean rval = FALSE;
10626
 
  Char    char_after;
 
12431
  Char    char_after = 0;
10627
12432
  
10628
12433
  if (pchSource == NULL) return FALSE;
10629
12434
  
10630
12435
  if (scp == NULL || StringHasNoText (scp->match_text)) return TRUE;
10631
 
 
10632
 
        if (scp->insensitive)
10633
 
        {
10634
 
          pFound = StringISearch (pchSource, scp->match_text);
10635
 
        }
10636
 
        else
10637
 
        {
10638
 
          pFound = StringSearch (pchSource, scp->match_text);
10639
 
        }
10640
 
          
10641
 
        if (pFound != NULL)
10642
 
        {
10643
 
          rval = TRUE;
10644
 
          char_after = *(pFound + StringLen (scp->match_text));
10645
 
          if (scp->match_location == STRING_CONSTRAINT_STARTS && pFound != pchSource)
10646
 
          {
10647
 
            rval = FALSE;
10648
 
          }
10649
 
          else if (scp->match_location == STRING_CONSTRAINT_ENDS && char_after != 0)
10650
 
          {
10651
 
            rval = FALSE;
10652
 
          }
10653
 
          else if (scp->match_location == STRING_CONSTRAINT_EQUALS
10654
 
                   && (pFound != pchSource || char_after != 0))
10655
 
          {
10656
 
            rval = FALSE;
10657
 
          }
10658
 
          else if (scp->whole_word)
10659
 
          {
10660
 
            rval = IsWholeWordMatch (pchSource, pFound, StringLen (scp->match_text));
10661
 
          }
 
12436
 
 
12437
  switch (scp->match_location) 
 
12438
  {
 
12439
    case eStringConstraintContains:
 
12440
            if (scp->insensitive)
 
12441
            {
 
12442
              pFound = StringISearch (pchSource, scp->match_text);
 
12443
            }
 
12444
            else
 
12445
            {
 
12446
              pFound = StringSearch (pchSource, scp->match_text);
 
12447
            }
 
12448
      if (pFound == NULL) 
 
12449
      {
 
12450
        rval = FALSE;
 
12451
      }
 
12452
      else if (scp->whole_word) 
 
12453
      {
 
12454
        rval = IsWholeWordMatch (pchSource, pFound, StringLen (scp->match_text));
 
12455
        while (!rval && pFound != NULL) 
 
12456
        {
 
12457
                if (scp->insensitive)
 
12458
                {
 
12459
                  pFound = StringISearch (pFound + 1, scp->match_text);
 
12460
                }
 
12461
                else
 
12462
                {
 
12463
                  pFound = StringSearch (pFound + 1, scp->match_text);
 
12464
                }
 
12465
          if (pFound != NULL)
 
12466
          {
 
12467
            rval = IsWholeWordMatch (pchSource, pFound, StringLen (scp->match_text));
 
12468
          }
 
12469
        }
 
12470
      }
 
12471
      else
 
12472
      {
 
12473
        rval = TRUE;
 
12474
      }
 
12475
      break;
 
12476
    case eStringConstraintStarts:
 
12477
            if (scp->insensitive)
 
12478
            {
 
12479
              pFound = StringISearch (pchSource, scp->match_text);
 
12480
            }
 
12481
            else
 
12482
            {
 
12483
              pFound = StringSearch (pchSource, scp->match_text);
 
12484
            }
 
12485
      if (pFound == pchSource)
 
12486
      {
 
12487
        if (scp->whole_word) 
 
12488
        {
 
12489
          rval = IsWholeWordMatch (pchSource, pFound, StringLen (scp->match_text));
 
12490
        }
 
12491
        else
 
12492
        {
 
12493
          rval = TRUE;
 
12494
        }
 
12495
      }
 
12496
      break;
 
12497
    case eStringConstraintEnds:
 
12498
            if (scp->insensitive)
 
12499
            {
 
12500
              pFound = StringISearch (pchSource, scp->match_text);
 
12501
            }
 
12502
            else
 
12503
            {
 
12504
              pFound = StringSearch (pchSource, scp->match_text);
 
12505
            }
 
12506
      while (pFound != NULL && !rval) {
 
12507
            char_after = *(pFound + StringLen (scp->match_text));
 
12508
        if (char_after == 0)
 
12509
        {
 
12510
          if (scp->whole_word) 
 
12511
          {
 
12512
            rval = IsWholeWordMatch (pchSource, pFound, StringLen (scp->match_text));
 
12513
          }
 
12514
          else
 
12515
          {
 
12516
            rval = TRUE;
 
12517
          }
 
12518
          /* stop the search, we're at the end of the string */
 
12519
          pFound = NULL;
 
12520
        }
 
12521
        else
 
12522
        {
 
12523
                if (scp->insensitive)
 
12524
                {
 
12525
                  pFound = StringISearch (pFound + 1, scp->match_text);
 
12526
                }
 
12527
                else
 
12528
                {
 
12529
                  pFound = StringSearch (pFound + 1, scp->match_text);
 
12530
                }
 
12531
        }
 
12532
      }
 
12533
      break;
 
12534
    case eStringConstraintEquals:
 
12535
      if (scp->insensitive) 
 
12536
      {
 
12537
        if (StringICmp (pchSource, scp->match_text) == 0) 
 
12538
        {
 
12539
          rval = TRUE;
 
12540
        }
 
12541
      }
 
12542
      else
 
12543
      {
 
12544
        if (StringCmp (pchSource, scp->match_text) == 0) 
 
12545
        {
 
12546
          rval = TRUE;
 
12547
        }
 
12548
      }
 
12549
      break;
 
12550
    case eStringConstraintInList:
 
12551
            if (scp->insensitive)
 
12552
            {
 
12553
              pFound = StringISearch (scp->match_text, pchSource);
 
12554
            }
 
12555
            else
 
12556
            {
 
12557
              pFound = StringSearch (scp->match_text, pchSource);
 
12558
            }
 
12559
      if (pFound == NULL) 
 
12560
      {
 
12561
        rval = FALSE;
 
12562
      }
 
12563
      else
 
12564
      {
 
12565
        rval = IsWholeWordMatch (scp->match_text, pFound, StringLen (pchSource));
 
12566
        while (!rval && pFound != NULL) 
 
12567
        {
 
12568
                if (scp->insensitive)
 
12569
                {
 
12570
                  pFound = StringISearch (pFound + 1, pchSource);
 
12571
                }
 
12572
                else
 
12573
                {
 
12574
                  pFound = StringSearch (pFound + 1, pchSource);
 
12575
                }
 
12576
          if (pFound != NULL)
 
12577
          {
 
12578
            rval = IsWholeWordMatch (scp->match_text, pFound, StringLen (pchSource));
 
12579
          }
 
12580
        }
 
12581
      }
 
12582
      if (!rval) {
 
12583
        /* look for spans */
 
12584
        rval = IsStringInSpanInList (pchSource, scp->match_text);
 
12585
      }
 
12586
      break;
10662
12587
        }
10663
12588
        return rval;
10664
12589
}
10673
12598
  if (ISA_STRINGTYPE (AsnFindBaseIsa (pAEOS->atp))) 
10674
12599
  {
10675
12600
          pchSource = (CharPtr) pAEOS->dvp->ptrvalue;
10676
 
          ohsp->found |= DoesStringMatchConstraint (pchSource, ohsp->scp);
 
12601
          ohsp->found |= DoesStringMatchConstraintX (pchSource, ohsp->scp);
10677
12602
  }
10678
12603
}
10679
12604
 
10699
12624
  if (!ohsp->found && omtp->datatype == OBJ_SEQFEAT)
10700
12625
  {
10701
12626
    sfp = (SeqFeatPtr) ptr;
10702
 
    sfp = SeqMgrGetDesiredFeature (sfp->idx.entityID, NULL, 0, 0, sfp, &fcontext);
10703
 
    ohsp->found = DoesStringMatchConstraint (fcontext.label, ohsp->scp);
10704
 
    if (!ohsp->found && sfp->idx.subtype == FEATDEF_tRNA)
 
12627
    if (SeqMgrFeaturesAreIndexed(sfp->idx.entityID) == 0) {
 
12628
      SeqMgrIndexFeatures (sfp->idx.entityID, NULL);
 
12629
    }
 
12630
 
 
12631
    sfp = SeqMgrGetDesiredFeature (sfp->idx.entityID, NULL, sfp->idx.itemID, 0, sfp, &fcontext);
 
12632
    ohsp->found = DoesStringMatchConstraintX (fcontext.label, ohsp->scp);
 
12633
    if (!ohsp->found && sfp != NULL && sfp->idx.subtype == FEATDEF_tRNA)
10705
12634
    {
10706
12635
      search_txt = (CharPtr) MemNew ((StringLen (fcontext.label) + 6) * sizeof (Char));
10707
12636
      if (search_txt != NULL)
10708
12637
      {
10709
12638
        sprintf (search_txt, "tRNA-%s", fcontext.label);
10710
 
        ohsp->found = DoesStringMatchConstraint (search_txt, ohsp->scp);
 
12639
        ohsp->found = DoesStringMatchConstraintX (search_txt, ohsp->scp);
10711
12640
        search_txt = MemFree (search_txt);
10712
12641
      }
10713
12642
    }
10715
12644
  return ohsp->found;
10716
12645
}
10717
12646
 
10718
 
static Boolean DoesDbtagMatchStringConstraint (DbtagPtr db_tag, StringConstraintPtr scp)
 
12647
static Boolean DoesDbtagMatchStringConstraint (DbtagPtr db_tag, StringConstraintXPtr scp)
10719
12648
{
10720
12649
  Boolean rval = FALSE;
10721
12650
  Char    tmp_str [15];
10728
12657
  {
10729
12658
    rval = TRUE;
10730
12659
  }
10731
 
  else if (DoesStringMatchConstraint (db_tag->db, scp))
 
12660
  else if (DoesStringMatchConstraintX (db_tag->db, scp))
10732
12661
  {
10733
12662
    rval = TRUE;
10734
12663
  }
10735
12664
  else if (db_tag->tag != NULL)
10736
12665
  {
10737
 
    if (DoesStringMatchConstraint (db_tag->tag->str, scp))
 
12666
    if (DoesStringMatchConstraintX (db_tag->tag->str, scp))
10738
12667
    {
10739
12668
      rval = TRUE;
10740
12669
    }
10741
12670
    else if (db_tag->tag->str == NULL)
10742
12671
    {
10743
12672
      sprintf (tmp_str, "%d", db_tag->tag->id);
10744
 
      if (DoesStringMatchConstraint (tmp_str, scp))
 
12673
      if (DoesStringMatchConstraintX (tmp_str, scp))
10745
12674
      {
10746
12675
        rval = TRUE;
10747
12676
      }
10763
12692
  
10764
12693
  if (sqdp->isOrgMod)
10765
12694
  {
10766
 
    if (biop->org != NULL || biop->org->orgname != NULL)
 
12695
    if (biop->org != NULL && biop->org->orgname != NULL)
10767
12696
    {
10768
12697
      mod = biop->org->orgname->mod;
10769
12698
      while (mod != NULL && mod->subtype != sqdp->subtype)
10813
12742
  return qual_found;
10814
12743
}
10815
12744
 
 
12745
static Boolean IsMatchAny (ValNodePtr vnp)
 
12746
{
 
12747
  if (vnp == NULL
 
12748
      || vnp->data.ptrvalue == NULL
 
12749
      || (vnp->choice > 0 && StringICmp (vnp->data.ptrvalue, "Organism or Any Qual") == 0))
 
12750
  {
 
12751
    return TRUE;
 
12752
  } else {
 
12753
    return FALSE;
 
12754
  }
 
12755
}
 
12756
 
 
12757
static Boolean DoFieldsMatch (BioSourcePtr biop, ChoiceConstraintPtr ccp)
 
12758
{
 
12759
  ValNodePtr swap, swap2;
 
12760
  ValNodePtr qual_choice_list = NULL, vnp1, vnp2;
 
12761
  Boolean    rval = FALSE;
 
12762
  ChoiceConstraintData tmp_const;
 
12763
  StringConstraintData scd;
 
12764
  SourceQualDescPtr sqdp;
 
12765
  CharPtr    location;
 
12766
  OrgModPtr              mod = NULL;
 
12767
  SubSourcePtr           ssp;
 
12768
 
 
12769
  if (biop == NULL) return FALSE;
 
12770
  if (ccp == NULL) return TRUE;
 
12771
 
 
12772
  /* Init temporary choice constraint */
 
12773
  MemSet (&tmp_const, 0, sizeof (ChoiceConstraintData));
 
12774
  MemSet (&scd, 0, sizeof (StringConstraintData));
 
12775
  scd.match_location = eStringConstraintEquals;
 
12776
  tmp_const.string_constraint = &scd;
 
12777
  tmp_const.constraint_type = CHOICE_CONSTRAINT_STRING;
 
12778
 
 
12779
  if (IsMatchAny (ccp->qual_choice) && IsMatchAny (ccp->qual_choice_match)) {
 
12780
    /* both are wildcards */
 
12781
    ValNodeAddPointer (&qual_choice_list, 1, StringSave ("Organism"));
 
12782
    qual_choice_list->next = GetSourceQualDescList (TRUE, TRUE, TRUE, FALSE);
 
12783
    ValNodeAddPointer (&qual_choice_list, 1, StringSave ("Lineage"));
 
12784
    ValNodeAddPointer (&qual_choice_list, 1, StringSave ("Location"));
 
12785
 
 
12786
    /* save original wildcards */
 
12787
    swap = ccp->qual_choice;
 
12788
    swap2 = ccp->qual_choice_match;
 
12789
    for (vnp1 = qual_choice_list; vnp1 != NULL && vnp1->next != NULL && !rval; vnp1 = vnp1->next) {
 
12790
      ccp->qual_choice = vnp1;
 
12791
      for (vnp2 = vnp1->next; vnp2 != NULL && !rval; vnp2 = vnp2->next) {
 
12792
        ccp->qual_choice_match = vnp2;
 
12793
        if (DoFieldsMatch (biop, ccp)) {
 
12794
          rval = TRUE;
 
12795
        }
 
12796
      }
 
12797
    }
 
12798
    /* put original wildcards back */
 
12799
    ccp->qual_choice = swap;
 
12800
    ccp->qual_choice_match = swap2;
 
12801
    qual_choice_list = ValNodeFreeData (qual_choice_list);
 
12802
  } else if (IsMatchAny (ccp->qual_choice) || IsMatchAny (ccp->qual_choice_match)) {
 
12803
    /* one is a wild card */
 
12804
    ValNodeAddPointer (&qual_choice_list, 1, StringSave ("Organism"));
 
12805
    qual_choice_list->next = GetSourceQualDescList (TRUE, TRUE, TRUE, FALSE);
 
12806
    ValNodeAddPointer (&qual_choice_list, 1, StringSave ("Lineage"));
 
12807
    ValNodeAddPointer (&qual_choice_list, 1, StringSave ("Location"));
 
12808
 
 
12809
    /* if one wild card, make it the first one */    
 
12810
    if (IsMatchAny (ccp->qual_choice_match)) {
 
12811
      swap = ccp->qual_choice;
 
12812
      ccp->qual_choice = ccp->qual_choice_match;
 
12813
      ccp->qual_choice_match = swap;
 
12814
    }
 
12815
    /* save original wildcard */
 
12816
    swap = ccp->qual_choice;
 
12817
    for (vnp1 = qual_choice_list; vnp1 != NULL && !rval; vnp1 = vnp1->next) {
 
12818
      if (SourceQualValNodeMatch (vnp1, ccp->qual_choice_match)) {
 
12819
        /* don't compare something to itself */
 
12820
        continue;
 
12821
      } else {
 
12822
        ccp->qual_choice = vnp1;
 
12823
        rval = DoFieldsMatch (biop, ccp);
 
12824
      }
 
12825
    }
 
12826
    /* put original wildcard back */
 
12827
    ccp->qual_choice = swap;
 
12828
    qual_choice_list = ValNodeFreeData (qual_choice_list);
 
12829
  } 
 
12830
  else if (ccp->qual_choice->choice > 0) 
 
12831
  {  
 
12832
    tmp_const.qual_choice = ccp->qual_choice_match;
 
12833
    if (StringICmp (ccp->qual_choice->data.ptrvalue, "Organism") == 0)
 
12834
    {
 
12835
      if (biop->org != NULL && !StringHasNoText (biop->org->taxname))
 
12836
      {
 
12837
        tmp_const.string_constraint->match_text = biop->org->taxname;
 
12838
        rval = DoesOneSourceMatchConstraint (biop, &tmp_const);
 
12839
      }
 
12840
    }
 
12841
    else if (StringICmp (ccp->qual_choice->data.ptrvalue, "Lineage") == 0)
 
12842
    {
 
12843
      if (biop->org != NULL && biop->org->orgname != NULL && !StringHasNoText (biop->org->orgname->lineage))
 
12844
      {
 
12845
        tmp_const.string_constraint->match_text = biop->org->orgname->lineage;
 
12846
        rval = DoesOneSourceMatchConstraint (biop, &tmp_const);
 
12847
      }
 
12848
    }
 
12849
    else if (StringICmp (ccp->qual_choice->data.ptrvalue, "Location") == 0)
 
12850
    {
 
12851
      location = GetLocationFromSource (biop, NULL);
 
12852
      tmp_const.string_constraint->match_text = location;
 
12853
      if (!StringHasNoText (location)) {
 
12854
        rval = DoesOneSourceMatchConstraint (biop, &tmp_const);
 
12855
      }
 
12856
      location = MemFree (location);
 
12857
    }
 
12858
  }
 
12859
  else
 
12860
  {
 
12861
    tmp_const.qual_choice = ccp->qual_choice_match;
 
12862
    sqdp = (SourceQualDescPtr) ccp->qual_choice->data.ptrvalue;
 
12863
    if (sqdp->isOrgMod)
 
12864
    {
 
12865
      if (biop->org != NULL && biop->org->orgname != NULL)
 
12866
      {
 
12867
        mod = biop->org->orgname->mod;
 
12868
      }
 
12869
      while (! rval && mod != NULL)
 
12870
      {
 
12871
        if (mod->subtype == sqdp->subtype && !StringHasNoText (mod->subname))
 
12872
        {
 
12873
          tmp_const.string_constraint->match_text = mod->subname;
 
12874
          rval = DoesOneSourceMatchConstraint (biop, &tmp_const);
 
12875
        }
 
12876
        mod = mod->next;
 
12877
      }
 
12878
    }
 
12879
    else
 
12880
    {
 
12881
      ssp = biop->subtype;
 
12882
      while (!rval && ssp != NULL)
 
12883
      {
 
12884
        if (ssp->subtype == sqdp->subtype && !StringHasNoText (ssp->name))
 
12885
        {
 
12886
          tmp_const.string_constraint->match_text = ssp->name;
 
12887
          rval = DoesOneSourceMatchConstraint (biop, &tmp_const);
 
12888
        }
 
12889
        ssp = ssp->next;
 
12890
      }
 
12891
    }
 
12892
  }
 
12893
  return rval;
 
12894
}
 
12895
 
10816
12896
extern Boolean 
10817
12897
DoesOneSourceMatchConstraint 
10818
12898
(BioSourcePtr biop, ChoiceConstraintPtr scp)
10821
12901
  OrgModPtr              mod = NULL;
10822
12902
  SubSourcePtr           ssp;
10823
12903
  SourceQualDescPtr      sqdp;
 
12904
  CharPtr                location;
10824
12905
  
10825
12906
  if (scp == NULL || scp->constraint_type == CHOICE_CONSTRAINT_ANY)
10826
12907
  {
10833
12914
  
10834
12915
  if (scp->constraint_type == CHOICE_CONSTRAINT_STRING)
10835
12916
  {
10836
 
    if (scp->qual_choice == NULL
10837
 
        || scp->qual_choice->data.ptrvalue == NULL
10838
 
        || StringICmp (scp->qual_choice->data.ptrvalue, "Organism or Any Qual") == 0)
 
12917
    if (IsMatchAny (scp->qual_choice))
10839
12918
    {
10840
12919
      if (biop->org != NULL)
10841
12920
      {
10842
 
        does_match = DoesStringMatchConstraint (biop->org->taxname, scp->string_constraint);
 
12921
        does_match = DoesStringMatchConstraintX (biop->org->taxname, scp->string_constraint);
10843
12922
        if (biop->org->orgname != NULL)
10844
12923
        {
10845
12924
          mod = biop->org->orgname->mod;
10846
12925
        }
10847
12926
        while (! does_match && mod != NULL)
10848
12927
        {
10849
 
          does_match = DoesStringMatchConstraint (mod->subname, scp->string_constraint);
 
12928
          does_match = DoesStringMatchConstraintX (mod->subname, scp->string_constraint);
10850
12929
          mod = mod->next;
10851
12930
        }
10852
12931
      }
10853
12932
      ssp = biop->subtype;
10854
12933
      while (!does_match && ssp != NULL)
10855
12934
      {
10856
 
        does_match = DoesStringMatchConstraint (ssp->name, scp->string_constraint);
 
12935
        does_match = DoesStringMatchConstraintX (ssp->name, scp->string_constraint);
10857
12936
        ssp = ssp->next;
10858
12937
      }
10859
12938
    }
10860
 
    else if (StringICmp (scp->qual_choice->data.ptrvalue, "Organism") == 0)
 
12939
    else if (scp->qual_choice->choice > 0 && StringICmp (scp->qual_choice->data.ptrvalue, "Organism") == 0)
10861
12940
    {
10862
12941
      if (biop->org != NULL)
10863
12942
      {
10864
 
        does_match = DoesStringMatchConstraint (biop->org->taxname, scp->string_constraint);
 
12943
        does_match = DoesStringMatchConstraintX (biop->org->taxname, scp->string_constraint);
10865
12944
      }
10866
12945
    }
10867
 
    else if (StringICmp (scp->qual_choice->data.ptrvalue, "Lineage") == 0)
 
12946
    else if (scp->qual_choice->choice > 0 && StringICmp (scp->qual_choice->data.ptrvalue, "Lineage") == 0)
10868
12947
    {
10869
12948
      if (biop->org != NULL && biop->org->orgname != NULL)
10870
12949
      {
10871
 
        does_match = DoesStringMatchConstraint (biop->org->orgname->lineage,
 
12950
        does_match = DoesStringMatchConstraintX (biop->org->orgname->lineage,
10872
12951
                                                scp->string_constraint);
10873
12952
      }
10874
12953
    }
 
12954
    else if (scp->qual_choice->choice > 0 && StringICmp (scp->qual_choice->data.ptrvalue, "Location") == 0)
 
12955
    {
 
12956
      location = GetLocationFromSource (biop, NULL);
 
12957
      does_match = DoesStringMatchConstraintX (location, scp->string_constraint);
 
12958
      location = MemFree (location);
 
12959
    }
10875
12960
    else
10876
12961
    {
10877
12962
      sqdp = (SourceQualDescPtr) scp->qual_choice->data.ptrvalue;
10885
12970
        {
10886
12971
          if (mod->subtype == sqdp->subtype)
10887
12972
          {
10888
 
            does_match = DoesStringMatchConstraint (mod->subname, scp->string_constraint);
 
12973
            does_match = DoesStringMatchConstraintX (mod->subname, scp->string_constraint);
10889
12974
          }
10890
12975
          mod = mod->next;
10891
12976
        }
10897
12982
        {
10898
12983
          if (ssp->subtype == sqdp->subtype)
10899
12984
          {
10900
 
            does_match = DoesStringMatchConstraint (ssp->name, scp->string_constraint);
 
12985
            does_match = DoesStringMatchConstraintX (ssp->name, scp->string_constraint);
10901
12986
          }
10902
12987
          ssp = ssp->next;
10903
12988
        }
10908
12993
      does_match = ! does_match;
10909
12994
    }
10910
12995
  }
 
12996
  else if (scp->constraint_type == CHOICE_CONSTRAINT_MATCH)
 
12997
  {
 
12998
    does_match = DoFieldsMatch (biop, scp);
 
12999
  }
10911
13000
  else
10912
13001
  {
10913
13002
    does_match = DoesSourceHaveQualPresent (biop, scp->qual_choice);
10934
13023
    if (cop->fsp->scp->not_present)
10935
13024
    {
10936
13025
      if (DoesObjectMatchStringConstraint (cop->omtp, cop->aip, (Pointer) sfp, &(cop->ohsd))
10937
 
          || DoesStringMatchConstraint (fcontext.label, cop->fsp->scp))
 
13026
          || DoesStringMatchConstraintX (fcontext.label, cop->fsp->scp))
10938
13027
      {
10939
13028
        feature_matches = FALSE; 
10940
13029
      }
10942
13031
    else
10943
13032
    {
10944
13033
      if (! DoesObjectMatchStringConstraint (cop->omtp, cop->aip, (Pointer) sfp, &(cop->ohsd))
10945
 
          && ! DoesStringMatchConstraint (fcontext.label, cop->fsp->scp))
 
13034
          && ! DoesStringMatchConstraintX (fcontext.label, cop->fsp->scp))
10946
13035
      {
10947
13036
        feature_matches = FALSE;
10948
13037
      }
10962
13051
  }
10963
13052
}
10964
13053
 
 
13054
 
 
13055
static void BioseqConstrainedFeaturesCallback (BioseqPtr bsp, Pointer userdata)
 
13056
{
 
13057
  ConstraintOpPtr   cop;
 
13058
  SeqFeatPtr        sfp;
 
13059
  ObjMgrDataPtr     omdp;
 
13060
  BioseqExtraPtr    bspextra;
 
13061
  Int4              index;
 
13062
  
 
13063
  if (bsp == NULL || userdata == NULL) return;
 
13064
  cop = (ConstraintOpPtr) userdata;
 
13065
 
 
13066
  omdp = SeqMgrGetOmdpForBioseq (bsp);
 
13067
  if (omdp == NULL || omdp->datatype != OBJ_BIOSEQ) return;
 
13068
 
 
13069
  bspextra = (BioseqExtraPtr) omdp->extradata;
 
13070
  if (bspextra == NULL) {
 
13071
    SeqMgrIndexFeatures (bsp->idx.entityID, NULL);
 
13072
    omdp = SeqMgrGetOmdpForBioseq (bsp);
 
13073
    if (omdp == NULL || omdp->datatype != OBJ_BIOSEQ) return;
 
13074
 
 
13075
    bspextra = (BioseqExtraPtr) omdp->extradata;
 
13076
  }
 
13077
  if (bspextra == NULL) return;
 
13078
 
 
13079
  for (index = 0; index < bspextra->numfeats; index++)
 
13080
  {
 
13081
    sfp = bspextra->featsByPos[index]->sfp;
 
13082
    SeqEntryConstrainedFeaturesCallback (sfp, userdata);
 
13083
  }
 
13084
}
 
13085
 
 
13086
 
10965
13087
static void SeqEntryConstrainedDescriptorsCallback (SeqDescrPtr sdp, Pointer userdata)
10966
13088
{
10967
13089
  ConstraintOpPtr cop;
11059
13181
      cop->omtp = ObjMgrTypeFind (cop->omp, OBJ_SEQFEAT, NULL, NULL);
11060
13182
      if (cop->omtp != NULL)
11061
13183
      {
11062
 
        VisitFeaturesInSep (sep, cop, SeqEntryConstrainedFeaturesCallback);
 
13184
        VisitBioseqsInSep (sep, cop, BioseqConstrainedFeaturesCallback);
11063
13185
      }
11064
13186
    }
11065
13187
  
11079
13201
  ConstrainedSourceCallback (sep->next, cop);
11080
13202
}
11081
13203
 
 
13204
 
 
13205
static void ConstrainedBioseqCallback (SeqEntryPtr sep, ConstraintOpPtr cop)
 
13206
{
 
13207
  BioseqPtr       bsp = NULL;
 
13208
  BioseqSetPtr    bssp = NULL;
 
13209
  SeqFeatPtr      sfp;
 
13210
  SeqDescPtr      sdp;
 
13211
  SeqMgrFeatContext fcontext;
 
13212
  SeqMgrDescContext dcontext;
 
13213
  
 
13214
  if (sep == NULL || sep->data.ptrvalue == NULL || cop == NULL || cop->fsp == NULL)
 
13215
  {
 
13216
    return;
 
13217
  }
 
13218
   
 
13219
  if (IS_Bioseq (sep))
 
13220
  {
 
13221
    bsp = (BioseqPtr) sep->data.ptrvalue;
 
13222
  }
 
13223
  else if (IS_Bioseq_set (sep))
 
13224
  {
 
13225
    bssp = (BioseqSetPtr) sep->data.ptrvalue;
 
13226
  }
 
13227
 
 
13228
  if (bsp != NULL && DoesIDListMeetStringConstraint (bsp->id, cop->fsp->id_list))
 
13229
  {
 
13230
    if (cop->feature_action != NULL)
 
13231
    {
 
13232
      cop->omtp = ObjMgrTypeFind (cop->omp, OBJ_SEQFEAT, NULL, NULL);
 
13233
      if (cop->omtp != NULL)
 
13234
      {
 
13235
        for (sfp = SeqMgrGetNextFeature (bsp, NULL, 0, 0, &fcontext);
 
13236
             sfp != NULL;
 
13237
             sfp = SeqMgrGetNextFeature (bsp, sfp, 0, 0, &fcontext))
 
13238
        {
 
13239
          SeqEntryConstrainedFeaturesCallback (sfp, cop);
 
13240
        }
 
13241
      }
 
13242
    }
 
13243
  
 
13244
    if (cop->descriptor_action != NULL)
 
13245
    {
 
13246
      cop->omtp = ObjMgrTypeFind (cop->omp, OBJ_SEQDESC, NULL, NULL);
 
13247
      if (cop->omtp != NULL)
 
13248
      {
 
13249
        for (sdp = SeqMgrGetNextDescriptor (bsp, NULL, 0, &dcontext);
 
13250
             sdp != NULL;
 
13251
             sdp = SeqMgrGetNextDescriptor (bsp, sdp, 0, &dcontext))
 
13252
        {
 
13253
          SeqEntryConstrainedDescriptorsCallback (sdp, cop);
 
13254
        }
 
13255
      }
 
13256
    }
 
13257
  }
 
13258
  else if (bssp != NULL)
 
13259
  {
 
13260
    ConstrainedBioseqCallback (bssp->seq_set, cop);
 
13261
  }
 
13262
  ConstrainedBioseqCallback (sep->next, cop);
 
13263
}
 
13264
 
 
13265
 
11082
13266
extern void 
11083
13267
OperateOnSeqEntryConstrainedObjects 
11084
13268
(SeqEntryPtr           sep,
11136
13320
    bsp = (BioseqPtr) sep->data.ptrvalue;
11137
13321
  }
11138
13322
  
11139
 
  if (fsp == NULL || fsp->ccp == NULL || fsp->ccp->constraint_type == CHOICE_CONSTRAINT_ANY)
 
13323
  if (fsp == NULL || (fsp->ccp == NULL && fsp->id_list == NULL)
 
13324
      || (fsp->ccp != NULL && fsp->ccp->constraint_type == CHOICE_CONSTRAINT_ANY)
 
13325
      || (fsp->id_list != NULL && bsp != NULL && DoesIDListMeetStringConstraint (bsp->id, fsp->id_list)))
11140
13326
  {
11141
13327
    if (feature_action != NULL)
11142
13328
    {
11145
13331
      {
11146
13332
        if (bsp == NULL)
11147
13333
        {
11148
 
          VisitFeaturesInSep (sep, &cod, SeqEntryConstrainedFeaturesCallback);
 
13334
          VisitBioseqsInSep (sep, &cod, BioseqConstrainedFeaturesCallback);
11149
13335
        }
11150
13336
        else
11151
13337
        {
11180
13366
      }
11181
13367
    }
11182
13368
  }
 
13369
  else if (fsp->id_list != NULL)
 
13370
  {
 
13371
    ConstrainedBioseqCallback (sep, &cod);
 
13372
  }
11183
13373
  else
11184
13374
  {
11185
13375
    ConstrainedSourceCallback (sep, &cod);
11530
13720
                                         seqfeat_choice, featdef_choice, descr_choice);
11531
13721
}
11532
13722
 
11533
 
typedef struct existingtextdlg 
11534
 
{
11535
 
  GrouP pre_app_grp;
11536
 
  GrouP delim_grp;
11537
 
} ExistingTextDlgData, PNTR ExistingTextDlgPtr;
11538
 
 
11539
 
static void ChangePreAppIgnoreChoice (GrouP g)
11540
 
{
11541
 
  ExistingTextDlgPtr etdp;
11542
 
  Int4               handle_choice;
11543
 
  
11544
 
  etdp = (ExistingTextDlgPtr) GetObjectExtra (g);
11545
 
  if (etdp == NULL)
11546
 
  {
11547
 
    return;
11548
 
  }
11549
 
  
11550
 
  handle_choice = GetValue (etdp->pre_app_grp);
11551
 
  if (handle_choice == 1 || handle_choice == 2)
11552
 
  {
11553
 
    Enable (etdp->delim_grp);
11554
 
  }
11555
 
  else
11556
 
  {
11557
 
    Disable (etdp->delim_grp);
11558
 
  }
11559
 
}
11560
 
 
11561
 
extern ExistingTextPtr GetExistingTextHandlerInfo (GetSamplePtr gsp, Boolean non_text)
11562
 
{
11563
 
  WindoW                w;
11564
 
  GrouP                 h, c;
11565
 
  ExistingTextDlgData   etdd;
11566
 
  ButtoN                b;
11567
 
  ModalAcceptCancelData acd;
11568
 
  ExistingTextPtr       etp;
11569
 
  Char                  txt [128];
11570
 
  MsgAnswer             ans;
11571
 
  PrompT                ppt;
11572
 
  Int4                  handle_choice;
11573
 
 
11574
 
  if (gsp == NULL || gsp->num_found == 0)
11575
 
  {
11576
 
    return NULL;
11577
 
  }
11578
 
  
11579
 
  sprintf (txt, "%d affected fields already contain a value.  Do you wish to overwrite existing text?",
11580
 
           gsp->num_found);
11581
 
  ans = Message (MSG_YNC, txt, 0, dialogTextHeight, systemFont, 'l');
11582
 
  if (ans == ANS_CANCEL)
11583
 
  {
11584
 
    etp = (ExistingTextPtr) MemNew (sizeof (ExistingTextData));
11585
 
    etp->existing_text_choice = EXISTING_TEXT_CHOICE_CANCEL;
11586
 
    return etp;
11587
 
  }
11588
 
  else if (ans == ANS_YES)
11589
 
  {
11590
 
    etp = (ExistingTextPtr) MemNew (sizeof (ExistingTextData));
11591
 
    etp->existing_text_choice = EXISTING_TEXT_CHOICE_REPLACE_OLD;
11592
 
    return etp;
11593
 
  }
11594
 
    
11595
 
  w = MovableModalWindow(-20, -13, -10, -10, "How to Add New Text", NULL);
11596
 
  h = HiddenGroup (w, -1, 0, NULL);
11597
 
  SetGroupSpacing (h, 10, 10);
11598
 
  etdd.pre_app_grp = HiddenGroup (h, 0, 3, ChangePreAppIgnoreChoice);
11599
 
  SetGroupSpacing (etdd.pre_app_grp, 10, 10);
11600
 
  RadioButton (etdd.pre_app_grp, "Append");
11601
 
  RadioButton (etdd.pre_app_grp, "Prefix");
11602
 
  RadioButton (etdd.pre_app_grp, "Ignore new text");
11603
 
  SetValue (etdd.pre_app_grp, 1);
11604
 
  SetObjectExtra (etdd.pre_app_grp, &etdd, NULL);
11605
 
  
11606
 
  ppt = StaticPrompt (h, "Separate new text and old text with", 
11607
 
                      0, dialogTextHeight, programFont, 'c');
11608
 
  etdd.delim_grp = HiddenGroup (h, 0, 3, NULL);
11609
 
  SetGroupSpacing (etdd.delim_grp, 10, 10);
11610
 
  RadioButton (etdd.delim_grp, "Semicolon");
11611
 
  RadioButton (etdd.delim_grp, "Space");
11612
 
  RadioButton (etdd.delim_grp, "Do not separate");
11613
 
  SetValue (etdd.delim_grp, 1);
11614
 
  
11615
 
  c = HiddenGroup (h, 2, 0, NULL);
11616
 
  SetGroupSpacing (c, 10, 10);
11617
 
  b = PushButton (c, "Accept", ModalAcceptButton);
11618
 
  SetObjectExtra (b, &acd, NULL);
11619
 
  b = PushButton (c, "Cancel", ModalCancelButton);
11620
 
  SetObjectExtra (b, &acd, NULL);
11621
 
  AlignObjects (ALIGN_CENTER, (HANDLE) etdd.pre_app_grp,
11622
 
                              (HANDLE) ppt, 
11623
 
                              (HANDLE) etdd.delim_grp, 
11624
 
                              (HANDLE) c, 
11625
 
                              NULL);
11626
 
  Show (w);
11627
 
  Select (w);
11628
 
  acd.accepted = FALSE;
11629
 
  acd.cancelled = FALSE;
11630
 
  while (!acd.accepted && ! acd.cancelled)
11631
 
  {
11632
 
    ProcessExternalEvent ();
11633
 
    Update ();
11634
 
  }
11635
 
  ProcessAnEvent ();
11636
 
  etp = (ExistingTextPtr) MemNew (sizeof (ExistingTextData));
11637
 
  if (acd.cancelled)
11638
 
  {
11639
 
    etp->existing_text_choice = EXISTING_TEXT_CHOICE_CANCEL;
11640
 
  }
11641
 
  else
11642
 
  {
11643
 
    handle_choice = GetValue (etdd.pre_app_grp);
11644
 
    if (handle_choice == 1)
11645
 
    {
11646
 
      switch (GetValue (etdd.delim_grp))
11647
 
      {
11648
 
        case 1:
11649
 
          etp->existing_text_choice = EXISTING_TEXT_CHOICE_APPEND_SEMI;
11650
 
          break;
11651
 
        case 2:
11652
 
          etp->existing_text_choice = EXISTING_TEXT_CHOICE_APPEND_SPACE;
11653
 
          break;
11654
 
        case 3:
11655
 
          etp->existing_text_choice = EXISTING_TEXT_CHOICE_APPEND_NONE;
11656
 
          break;
11657
 
      }
11658
 
    }
11659
 
    else if (handle_choice == 2)
11660
 
    {
11661
 
      switch (GetValue (etdd.delim_grp))
11662
 
      {
11663
 
        case 1:
11664
 
          etp->existing_text_choice = EXISTING_TEXT_CHOICE_PREFIX_SEMI;
11665
 
          break;
11666
 
        case 2:
11667
 
          etp->existing_text_choice = EXISTING_TEXT_CHOICE_PREFIX_SPACE;
11668
 
          break;
11669
 
        case 3:
11670
 
          etp->existing_text_choice = EXISTING_TEXT_CHOICE_PREFIX_NONE;
11671
 
          break;
11672
 
      }
11673
 
    }
11674
 
    else
11675
 
    {
11676
 
      etp->existing_text_choice = EXISTING_TEXT_CHOICE_LEAVE_OLD;
11677
 
    }
11678
 
  }
11679
 
  Remove (w);
11680
 
  return etp;
11681
 
}
11682
 
 
11683
 
extern CharPtr HandleExistingText (CharPtr existing_text, CharPtr new_text, ExistingTextPtr etp)
11684
 
{
11685
 
  CharPtr rstring = NULL;
11686
 
  Int4    len;
11687
 
  
11688
 
  if (StringHasNoText (existing_text) || etp == NULL)
11689
 
  {
11690
 
    MemFree (existing_text);
11691
 
    return new_text;
11692
 
  }
11693
 
  switch (etp->existing_text_choice)
11694
 
  {
11695
 
    case EXISTING_TEXT_CHOICE_REPLACE_OLD:
11696
 
      /* replace current text with new text */
11697
 
      MemFree (existing_text);
11698
 
      rstring = new_text;
11699
 
      break;
11700
 
    case EXISTING_TEXT_CHOICE_LEAVE_OLD:
11701
 
      /* do not change current text */
11702
 
      MemFree (new_text);
11703
 
      rstring = existing_text;
11704
 
      break;
11705
 
    case EXISTING_TEXT_CHOICE_APPEND_SEMI:
11706
 
      /* Append new text to current text, separated by semicolon */
11707
 
      len = StringLen (new_text) + StringLen (existing_text) + 4;
11708
 
      rstring = MemNew (len);
11709
 
      if (rstring != NULL) {
11710
 
        StringCpy (rstring, existing_text);
11711
 
        StringCat (rstring, "; ");
11712
 
        StringCat (rstring, new_text);
11713
 
        MemFree (new_text);
11714
 
        MemFree (existing_text);
11715
 
      }
11716
 
      break;
11717
 
    case EXISTING_TEXT_CHOICE_APPEND_SPACE:
11718
 
      /* Append new text to current text, separated by space */
11719
 
      len = StringLen (new_text) + StringLen (existing_text) + 3;
11720
 
      rstring = MemNew (len);
11721
 
      if (rstring != NULL) {
11722
 
        StringCpy (rstring, existing_text);
11723
 
        StringCat (rstring, " ");
11724
 
        StringCat (rstring, new_text);
11725
 
        MemFree (new_text);
11726
 
        MemFree (existing_text);
11727
 
      }
11728
 
      break;
11729
 
    case EXISTING_TEXT_CHOICE_APPEND_NONE:
11730
 
      /* Append new text to current text, no delimiter */
11731
 
      len = StringLen (new_text) + StringLen (existing_text) + 1;
11732
 
      rstring = MemNew (len);
11733
 
      if (rstring != NULL) {
11734
 
        StringCpy (rstring, existing_text);
11735
 
        StringCat (rstring, new_text);
11736
 
        MemFree (new_text);
11737
 
        MemFree (existing_text);
11738
 
      }
11739
 
      break;
11740
 
    case EXISTING_TEXT_CHOICE_PREFIX_SEMI:
11741
 
      /* Prepend new text to current text, separated by semicolon */
11742
 
      len = StringLen (new_text) + StringLen (existing_text) + 4;
11743
 
      rstring = MemNew (len);
11744
 
      if (rstring != NULL) {
11745
 
        StringCpy (rstring, new_text);
11746
 
        StringCat (rstring, "; ");
11747
 
        StringCat (rstring, existing_text);
11748
 
        MemFree (new_text);
11749
 
        MemFree (existing_text);
11750
 
      }
11751
 
      break;
11752
 
    case EXISTING_TEXT_CHOICE_PREFIX_SPACE:
11753
 
      /* Prepend new text to current text, separated by semicolon */
11754
 
      len = StringLen (new_text) + StringLen (existing_text) + 3;
11755
 
      rstring = MemNew (len);
11756
 
      if (rstring != NULL) {
11757
 
        StringCpy (rstring, new_text);
11758
 
        StringCat (rstring, " ");
11759
 
        StringCat (rstring, existing_text);
11760
 
        MemFree (new_text);
11761
 
        MemFree (existing_text);
11762
 
      }
11763
 
      break;
11764
 
    case EXISTING_TEXT_CHOICE_PREFIX_NONE:
11765
 
      /* prefix current text with new text */
11766
 
      len = StringLen (new_text) + StringLen (existing_text) + 1;
11767
 
      rstring = MemNew (len);
11768
 
      if (rstring != NULL) {
11769
 
        StringCpy (rstring, new_text);
11770
 
        StringCat (rstring, existing_text);
11771
 
        MemFree (new_text);
11772
 
        MemFree (existing_text);
11773
 
      }
11774
 
      break;    
11775
 
  }
11776
 
  return rstring;
11777
 
}
11778
 
 
11779
13723
extern CharPtr HandleApplyValue (CharPtr orig_text, ApplyValuePtr avp)
11780
13724
{
11781
13725
  CharPtr new_str, cp_found;
11806
13750
    found_len = StringLen (avp->text_to_replace);
11807
13751
    replace_len = StringLen (avp->new_text);
11808
13752
    cp_found = StringISearch (orig_text, avp->text_to_replace);
 
13753
    if (avp->where_to_replace == EditApplyFindLocation_beginning
 
13754
        && cp_found != orig_text) {
 
13755
      cp_found = NULL;
 
13756
    } 
11809
13757
    while (cp_found != NULL)
11810
13758
    {
11811
 
      new_len = StringLen (orig_text) + 1 - found_len + replace_len;
11812
 
      new_str = (CharPtr) MemNew (new_len * sizeof (Char));
11813
 
      if (new_str != NULL)
11814
 
      {
11815
 
        if (cp_found != orig_text)
 
13759
      if (avp->where_to_replace == EditApplyFindLocation_end
 
13760
          && cp_found != orig_text + StringLen (orig_text) - found_len) {
 
13761
        cp_found = StringISearch (cp_found + found_len, avp->text_to_replace);
 
13762
      } else {
 
13763
        new_len = StringLen (orig_text) + 1 - found_len + replace_len;
 
13764
        new_str = (CharPtr) MemNew (new_len * sizeof (Char));
 
13765
        if (new_str != NULL)
11816
13766
        {
11817
 
          StringNCpy (new_str, orig_text, cp_found - orig_text);
 
13767
          if (cp_found != orig_text)
 
13768
          {
 
13769
            StringNCpy (new_str, orig_text, cp_found - orig_text);
 
13770
          }
 
13771
          StringCat (new_str, avp->new_text);
 
13772
          StringCat (new_str, cp_found + found_len);
 
13773
          cp_found = new_str + (cp_found - orig_text) + replace_len;
 
13774
          orig_text = MemFree (orig_text);
 
13775
          orig_text = new_str;
11818
13776
        }
11819
 
        StringCat (new_str, avp->new_text);
11820
 
        StringCat (new_str, cp_found + found_len);
11821
 
        cp_found = new_str + (cp_found - orig_text) + replace_len;
11822
 
        orig_text = MemFree (orig_text);
11823
 
        orig_text = new_str;
 
13777
        cp_found = StringISearch (cp_found, avp->text_to_replace);
11824
13778
      }
11825
 
      cp_found = StringISearch (cp_found, avp->text_to_replace);
11826
13779
    }
11827
13780
    return orig_text;
11828
13781
  }
11851
13804
  return list;
11852
13805
}
11853
13806
 
 
13807
 
 
13808
 
 
13809
static void MakeSemicolonStringsIntoSeparateItems (ValNodePtr PNTR list)
 
13810
{
 
13811
  ValNodePtr prev = NULL, vnp_next, vnp, vnp_new;
 
13812
  CharPtr    cp;
 
13813
 
 
13814
  if (list == NULL || *list == NULL) return;
 
13815
 
 
13816
  vnp = *list;
 
13817
  while (vnp != NULL)
 
13818
  {
 
13819
    vnp_next = vnp->next;
 
13820
    if (StringHasNoText (vnp->data.ptrvalue))
 
13821
    {
 
13822
      if (prev == NULL)
 
13823
      {
 
13824
        *list = vnp_next;
 
13825
      }
 
13826
      else
 
13827
      {
 
13828
        prev->next = vnp_next;
 
13829
      }
 
13830
      vnp->next = NULL;
 
13831
      vnp = ValNodeFreeData (vnp);
 
13832
    }
 
13833
    else if ((cp = StringChr (vnp->data.ptrvalue, ';')) != NULL)
 
13834
    {
 
13835
      vnp_new = ValNodeNew (NULL);
 
13836
      vnp_new->choice = vnp->choice;
 
13837
      vnp_new->data.ptrvalue = StringSave (cp + 1);
 
13838
      vnp_new->next = vnp_next;
 
13839
      *cp = 0;
 
13840
      vnp->next = vnp_new;
 
13841
      vnp_next = vnp_new;
 
13842
      prev = vnp;
 
13843
    }
 
13844
    else
 
13845
    {
 
13846
      prev = vnp;
 
13847
    }
 
13848
    vnp = vnp_next;
 
13849
  }
 
13850
}
 
13851
 
 
13852
 
 
13853
extern ValNodePtr ApplyValueToValNodeStringListAsText (ValNodePtr list, Int2 choice, ApplyValuePtr avp)
 
13854
{
 
13855
  ValNodePtr vnp;
 
13856
  
 
13857
  if (avp == NULL)
 
13858
  {
 
13859
    return NULL;
 
13860
  }
 
13861
  
 
13862
  if (!StringHasNoText (avp->text_to_replace))
 
13863
  {
 
13864
    for (vnp = list; vnp != NULL; vnp = vnp->next)
 
13865
    {
 
13866
      vnp->data.ptrvalue = HandleApplyValue (vnp->data.ptrvalue, avp);
 
13867
    }
 
13868
  }
 
13869
  else
 
13870
  {
 
13871
    if (avp->etp == NULL
 
13872
        || avp->etp->existing_text_choice == eExistingTextChoiceReplaceOld)
 
13873
    {
 
13874
      list = ValNodeFree (list);
 
13875
      ValNodeAddPointer (&list, choice, StringSave (avp->new_text));
 
13876
    }
 
13877
    else if (avp->etp->existing_text_choice == eExistingTextChoiceAppendSemi)
 
13878
    {
 
13879
      ValNodeAddPointer (&list, choice, StringSave (avp->new_text));
 
13880
    }
 
13881
    else if (avp->etp->existing_text_choice == eExistingTextChoicePrefixSemi)
 
13882
    {
 
13883
      vnp = ValNodeNew(NULL);
 
13884
      vnp->choice = (Uint1) choice;
 
13885
      vnp->data.ptrvalue = StringSave (avp->new_text);
 
13886
      vnp->next = list;
 
13887
      list = vnp;
 
13888
    }
 
13889
    else if (avp->etp->existing_text_choice == eExistingTextChoiceLeaveOld)
 
13890
    {
 
13891
      if (list == NULL)
 
13892
      {
 
13893
        ValNodeAddPointer (&list, choice, StringSave (avp->new_text));
 
13894
      }
 
13895
    } else {
 
13896
      for (vnp = list; vnp != NULL; vnp = vnp->next)
 
13897
      {
 
13898
        vnp->data.ptrvalue = HandleApplyValue (vnp->data.ptrvalue, avp);
 
13899
      }
 
13900
    }
 
13901
  }
 
13902
 
 
13903
  if (avp->etp == NULL || avp->etp->existing_text_choice != eExistingTextChoiceLeaveOld) 
 
13904
  {
 
13905
    MakeSemicolonStringsIntoSeparateItems (&list);
 
13906
  }
 
13907
  return list;
 
13908
}
 
13909
 
 
13910
 
11854
13911
typedef struct parsefielddialog
11855
13912
{
11856
13913
  DIALOG_MESSAGE_BLOCK
11857
 
  PopuP                    parse_field_type;
 
13914
  DialoG                   parse_field_type;
11858
13915
  DialoG                   biosrc_string_choice;
11859
13916
  DialoG                   source_qual_choice;
11860
13917
  DialoG                   gene_field;
11861
 
  DialoG                   mrna_field;
 
13918
  DialoG                   rna_subtype;
 
13919
  DialoG                   rna_field;
11862
13920
  DialoG                   protein_field;
11863
13921
  DialoG                   import_feature;
11864
13922
  DialoG                   import_qual;
11865
13923
  DialoG                   feature;
 
13924
  GrouP                    dbxref_grp;
 
13925
  TexT                     dbxref_db;
 
13926
  GrouP                    feat_or_desc;
11866
13927
  Nlm_ChangeNotifyProc     change_notify;
11867
13928
  Pointer                  change_userdata;
 
13929
  Boolean                  is_search_field;
11868
13930
} ParseFieldDialogData, PNTR ParseFieldDialogPtr;
11869
13931
 
11870
 
static void ChangeParseFieldType (PopuP p)
 
13932
static void ChangeParseFieldType (Pointer data)
11871
13933
{
11872
13934
  ParseFieldDialogPtr dlg;
11873
 
  Int4                parse_field_type;
 
13935
  ValNodePtr          vnp;
11874
13936
 
11875
 
  dlg = (ParseFieldDialogPtr) GetObjectExtra (p);
 
13937
  dlg = (ParseFieldDialogPtr) data;
11876
13938
  if (dlg == NULL)
11877
13939
  {
11878
13940
    return;
11879
13941
  }
11880
 
  parse_field_type = GetValue (dlg->parse_field_type);
 
13942
  vnp = DialogToPointer (dlg->parse_field_type);
11881
13943
  Hide (dlg->biosrc_string_choice);
 
13944
  Hide (dlg->feat_or_desc);
11882
13945
  Hide (dlg->source_qual_choice);
11883
13946
  Hide (dlg->gene_field);
11884
 
  Hide (dlg->mrna_field);
 
13947
  Hide (dlg->rna_subtype);
 
13948
  Hide (dlg->rna_field);
11885
13949
  Hide (dlg->protein_field);
11886
13950
  Hide (dlg->import_feature);
11887
13951
  Hide (dlg->import_qual);
11888
13952
  Hide (dlg->feature);
11889
 
  switch (parse_field_type)
 
13953
  Hide (dlg->dbxref_grp);
 
13954
  if (vnp != NULL)
11890
13955
  {
11891
 
    case PARSE_FIELD_BIOSRC_STRING:
11892
 
      Show (dlg->biosrc_string_choice);
11893
 
      break;
11894
 
    case PARSE_FIELD_SOURCE_QUAL:
11895
 
      Show (dlg->source_qual_choice);
11896
 
      break;
11897
 
    case PARSE_FIELD_GENE_FIELD:
11898
 
      Show (dlg->gene_field);
11899
 
      break;
11900
 
    case PARSE_FIELD_MRNA_FIELD:
11901
 
      Show (dlg->mrna_field);
11902
 
      break;
11903
 
    case PARSE_FIELD_PROTEIN_FIELD:
11904
 
      Show (dlg->protein_field);
11905
 
      break;
11906
 
    case PARSE_FIELD_IMPORT_QUAL:
11907
 
      Show (dlg->import_feature);
11908
 
      Show (dlg->import_qual);
11909
 
      break;
11910
 
    case PARSE_FIELD_FEATURE_NOTE:
11911
 
      Show (dlg->feature);
11912
 
      break;
 
13956
    switch (vnp->choice)
 
13957
    {
 
13958
      case PARSE_FIELD_BIOSRC_STRING:
 
13959
        Show (dlg->biosrc_string_choice);
 
13960
        Show (dlg->feat_or_desc);
 
13961
        break;
 
13962
      case PARSE_FIELD_SOURCE_QUAL:
 
13963
        Show (dlg->source_qual_choice);
 
13964
        Show (dlg->feat_or_desc);
 
13965
        break;
 
13966
      case PARSE_FIELD_GENE_FIELD:
 
13967
        Show (dlg->gene_field);
 
13968
        break;
 
13969
      case PARSE_FIELD_RNA_FIELD:
 
13970
        Show (dlg->rna_subtype);
 
13971
        Show (dlg->rna_field);
 
13972
        break;
 
13973
      case PARSE_FIELD_PROTEIN_FIELD:
 
13974
        Show (dlg->protein_field);
 
13975
        break;
 
13976
      case PARSE_FIELD_IMPORT_QUAL:
 
13977
        Show (dlg->import_feature);
 
13978
        Show (dlg->import_qual);
 
13979
        break;
 
13980
      case PARSE_FIELD_FEATURE_NOTE:
 
13981
        Show (dlg->feature);
 
13982
        break;
 
13983
      case PARSE_FIELD_DBXREF:
 
13984
        Show (dlg->dbxref_grp);
 
13985
        break;
 
13986
    }
11913
13987
  }
11914
13988
  if (dlg->change_notify != NULL)
11915
13989
  {
11919
13993
 
11920
13994
static void ResetParseFieldDialog (ParseFieldDialogPtr dlg)
11921
13995
{
 
13996
  ValNode vn;
 
13997
 
11922
13998
  if (dlg == NULL)
11923
13999
  {
11924
14000
    return;
11925
14001
  }
11926
 
  SetValue (dlg->parse_field_type, PARSE_FIELD_DEFLINE);
11927
 
  ChangeParseFieldType (dlg->parse_field_type);
 
14002
  vn.choice = PARSE_FIELD_DEFLINE;
 
14003
  vn.data.ptrvalue = NULL;
 
14004
  vn.next = NULL;
 
14005
  PointerToDialog (dlg->parse_field_type, &vn);
 
14006
  ChangeParseFieldType (dlg);
11928
14007
}
11929
14008
 
11930
14009
static void ParseFieldToDialog (DialoG d, Pointer data)
11932
14011
  ParseFieldDialogPtr dlg;
11933
14012
  ParseFieldPtr       parse_field;
11934
14013
  Int4                parse_field_type;
 
14014
  ValNode             vn;
11935
14015
 
11936
14016
  dlg = (ParseFieldDialogPtr) GetObjectExtra (d);
11937
14017
  if (dlg == NULL)
11943
14023
  if (parse_field != NULL)
11944
14024
  {
11945
14025
    parse_field_type = parse_field->parse_field_type;
11946
 
    if (parse_field_type < PARSE_FIELD_DEFLINE || parse_field_type > MAX_PARSE_FIELD_TYPE)
 
14026
    if (parse_field_type < PARSE_FIELD_DEFLINE 
 
14027
        || (dlg->is_search_field && parse_field_type > SEARCH_FIELD_PUBLICATION)
 
14028
        || (!dlg->is_search_field && parse_field_type > MAX_PARSE_FIELD_TYPE))
11947
14029
    {
11948
14030
      parse_field_type = PARSE_FIELD_DEFLINE;
11949
14031
    }
11950
 
    SetValue (dlg->parse_field_type, parse_field_type);
 
14032
    vn.choice = parse_field_type;
 
14033
    vn.data.ptrvalue = NULL;
 
14034
    vn.next = NULL;
 
14035
    PointerToDialog (dlg->parse_field_type, &vn);
11951
14036
    switch (parse_field_type)
11952
14037
    {
11953
14038
      case PARSE_FIELD_BIOSRC_STRING:
11954
14039
        PointerToDialog (dlg->biosrc_string_choice, parse_field->feature_field);
 
14040
        if (parse_field->do_desc && parse_field->do_feat)
 
14041
        {
 
14042
          SetValue (dlg->feat_or_desc, 1);
 
14043
        }
 
14044
        else if (parse_field->do_desc)
 
14045
        {
 
14046
          SetValue (dlg->feat_or_desc, 2);
 
14047
        }
 
14048
        else if (parse_field->do_feat)
 
14049
        {
 
14050
          SetValue (dlg->feat_or_desc, 3);
 
14051
        }
 
14052
        else
 
14053
        {
 
14054
          SetValue (dlg->feat_or_desc, 1);
 
14055
        }
11955
14056
        break;
11956
14057
      case PARSE_FIELD_SOURCE_QUAL:
11957
14058
        PointerToDialog (dlg->source_qual_choice, parse_field->feature_field);
 
14059
        if (parse_field->do_desc && parse_field->do_feat)
 
14060
        {
 
14061
          SetValue (dlg->feat_or_desc, 1);
 
14062
        }
 
14063
        else if (parse_field->do_desc)
 
14064
        {
 
14065
          SetValue (dlg->feat_or_desc, 2);
 
14066
        }
 
14067
        else if (parse_field->do_feat)
 
14068
        {
 
14069
          SetValue (dlg->feat_or_desc, 3);
 
14070
        }
 
14071
        else
 
14072
        {
 
14073
          SetValue (dlg->feat_or_desc, 1);
 
14074
        }
 
14075
        break;
 
14076
      case PARSE_FIELD_DBXREF:
 
14077
        if (parse_field->feature_field == NULL || parse_field->feature_field->data.ptrvalue == NULL)
 
14078
        {
 
14079
          SetTitle (dlg->dbxref_db, "");
 
14080
        }
 
14081
        else
 
14082
        {
 
14083
          SetTitle (dlg->dbxref_db, parse_field->feature_field->data.ptrvalue);
 
14084
        }
 
14085
        if (parse_field->do_desc && parse_field->do_feat)
 
14086
        {
 
14087
          SetValue (dlg->feat_or_desc, 1);
 
14088
        }
 
14089
        else if (parse_field->do_desc)
 
14090
        {
 
14091
          SetValue (dlg->feat_or_desc, 2);
 
14092
        }
 
14093
        else if (parse_field->do_feat)
 
14094
        {
 
14095
          SetValue (dlg->feat_or_desc, 3);
 
14096
        }
 
14097
        else
 
14098
        {
 
14099
          SetValue (dlg->feat_or_desc, 1);
 
14100
        }
11958
14101
        break;
11959
14102
      case PARSE_FIELD_GENE_FIELD:
11960
14103
        PointerToDialog (dlg->gene_field, parse_field->feature_field);
11961
14104
        break;
11962
 
      case PARSE_FIELD_MRNA_FIELD:
11963
 
        PointerToDialog (dlg->mrna_field, parse_field->feature_field);
 
14105
      case PARSE_FIELD_RNA_FIELD:
 
14106
        PointerToDialog (dlg->rna_subtype, parse_field->feature_subtype);
 
14107
        PointerToDialog (dlg->rna_field, parse_field->feature_field);
11964
14108
        break;
11965
14109
      case PARSE_FIELD_PROTEIN_FIELD:
11966
14110
        PointerToDialog (dlg->protein_field, parse_field->feature_field);
11972
14116
      case PARSE_FIELD_FEATURE_NOTE:
11973
14117
        PointerToDialog (dlg->feature, parse_field->feature_field);
11974
14118
        break;
 
14119
      case SEARCH_FIELD_PUBLICATION:
 
14120
        /* nothing to do here */
 
14121
        break;
11975
14122
    }
11976
14123
  }
11977
 
  ChangeParseFieldType (dlg->parse_field_type);
 
14124
  ChangeParseFieldType (dlg);
11978
14125
}
11979
14126
 
11980
14127
static Pointer DialogToParseField (DialoG d)
11981
14128
{
11982
14129
  ParseFieldDialogPtr dlg;
11983
14130
  ParseFieldPtr       parse_field;
 
14131
  Int4                val;
 
14132
  ValNodePtr          vnp;
11984
14133
 
11985
14134
  dlg = (ParseFieldDialogPtr) GetObjectExtra (d);
11986
14135
  if (dlg == NULL)
11987
14136
  {
11988
14137
    return NULL;
11989
14138
  }
 
14139
  vnp = DialogToPointer (dlg->parse_field_type);
 
14140
  if (vnp == NULL)
 
14141
  {
 
14142
    return NULL;
 
14143
  }
 
14144
 
11990
14145
  parse_field = (ParseFieldPtr) MemNew (sizeof (ParseFieldData));
11991
14146
  if (parse_field != NULL)
11992
14147
  {
11993
 
    parse_field->parse_field_type = GetValue (dlg->parse_field_type);
 
14148
    parse_field->parse_field_type = vnp->choice;
11994
14149
    parse_field->feature_field = NULL;
11995
14150
    switch (parse_field->parse_field_type)
11996
14151
    {
11997
14152
      case PARSE_FIELD_BIOSRC_STRING:
11998
14153
        parse_field->feature_field = DialogToPointer (dlg->biosrc_string_choice);
 
14154
        val = GetValue (dlg->feat_or_desc);
 
14155
        switch (val)
 
14156
        {
 
14157
          case 2:
 
14158
            parse_field->do_desc = TRUE;
 
14159
            parse_field->do_feat = FALSE;
 
14160
            break;
 
14161
          case 3:
 
14162
            parse_field->do_desc = FALSE;
 
14163
            parse_field->do_feat = TRUE;
 
14164
            break;
 
14165
          case 1:
 
14166
          default:
 
14167
            parse_field->do_desc = TRUE;
 
14168
            parse_field->do_feat = TRUE;
 
14169
            break;
 
14170
        }
11999
14171
        break;
12000
14172
      case PARSE_FIELD_SOURCE_QUAL:
12001
14173
        parse_field->feature_field = DialogToPointer (dlg->source_qual_choice);
 
14174
        val = GetValue (dlg->feat_or_desc);
 
14175
        switch (val)
 
14176
        {
 
14177
          case 2:
 
14178
            parse_field->do_desc = TRUE;
 
14179
            parse_field->do_feat = FALSE;
 
14180
            break;
 
14181
          case 3:
 
14182
            parse_field->do_desc = FALSE;
 
14183
            parse_field->do_feat = TRUE;
 
14184
            break;
 
14185
          case 1:
 
14186
          default:
 
14187
            parse_field->do_desc = TRUE;
 
14188
            parse_field->do_feat = TRUE;
 
14189
            break;
 
14190
        }
 
14191
        break;
 
14192
      case PARSE_FIELD_DBXREF:        
 
14193
        if (!TextHasNoText (dlg->dbxref_db))
 
14194
        {
 
14195
          ValNodeAddPointer (&(parse_field->feature_field), 0, SaveStringFromText (dlg->dbxref_db));
 
14196
        }
 
14197
        val = GetValue (dlg->feat_or_desc);
 
14198
        switch (val)
 
14199
        {
 
14200
          case 2:
 
14201
            parse_field->do_desc = TRUE;
 
14202
            parse_field->do_feat = FALSE;
 
14203
            break;
 
14204
          case 3:
 
14205
            parse_field->do_desc = FALSE;
 
14206
            parse_field->do_feat = TRUE;
 
14207
            break;
 
14208
          case 1:
 
14209
          default:
 
14210
            parse_field->do_desc = TRUE;
 
14211
            parse_field->do_feat = TRUE;
 
14212
            break;
 
14213
        }
12002
14214
        break;
12003
14215
      case PARSE_FIELD_GENE_FIELD:
12004
14216
        parse_field->feature_field = DialogToPointer (dlg->gene_field);
12005
14217
        break;
12006
 
      case PARSE_FIELD_MRNA_FIELD:
12007
 
        parse_field->feature_field = DialogToPointer (dlg->mrna_field);
 
14218
      case PARSE_FIELD_RNA_FIELD:
 
14219
        parse_field->feature_subtype = DialogToPointer (dlg->rna_subtype);
 
14220
        parse_field->feature_field = DialogToPointer (dlg->rna_field);
12008
14221
        break;
12009
14222
      case PARSE_FIELD_PROTEIN_FIELD:
12010
14223
        parse_field->feature_field = DialogToPointer (dlg->protein_field);
12016
14229
      case PARSE_FIELD_FEATURE_NOTE:
12017
14230
        parse_field->feature_field = DialogToPointer (dlg->feature);
12018
14231
        break;
 
14232
      case SEARCH_FIELD_PUBLICATION:
 
14233
        /* nothing to do here */
 
14234
        break;
12019
14235
    }
12020
14236
  }
 
14237
  vnp = ValNodeFreeData (vnp);
12021
14238
  return parse_field;
12022
14239
}
12023
14240
 
12053
14270
  
12054
14271
  if (dlg != NULL)
12055
14272
  {
12056
 
    parse_field_type = GetValue (dlg->parse_field_type);
12057
 
    switch (parse_field_type)
12058
 
    {
12059
 
      case PARSE_FIELD_DEFLINE:
12060
 
      case PARSE_FIELD_CDS_COMMENT:
12061
 
      case PARSE_FIELD_COMMENT_DESC:
12062
 
        /* don't need any extra information */
12063
 
        break;
12064
 
      case PARSE_FIELD_BIOSRC_STRING:
12065
 
        vnp = DialogToPointer (dlg->biosrc_string_choice);
12066
 
        if (vnp == NULL)
12067
 
        {
12068
 
          head = AddStringToValNodeChain (head, "biosrc string type", 1);
12069
 
        }
12070
 
        ValNodeFree (vnp);
12071
 
        break;
12072
 
      case PARSE_FIELD_SOURCE_QUAL:
12073
 
        vnp = DialogToPointer (dlg->source_qual_choice);
12074
 
        if (vnp == NULL)
12075
 
        {
12076
 
          head = AddStringToValNodeChain (head, "source qual type", 1);
12077
 
        }
12078
 
        ValNodeFree (vnp);
12079
 
        break;
12080
 
      case PARSE_FIELD_GENE_FIELD:
12081
 
        vnp = DialogToPointer (dlg->gene_field);
12082
 
        if (vnp == NULL || vnp->data.intvalue == FEATUREFIELD_NONE)
12083
 
        {
12084
 
          head = AddStringToValNodeChain (head, "gene field", 1);
12085
 
        }
12086
 
        ValNodeFree (vnp);
12087
 
        break;
12088
 
      case PARSE_FIELD_MRNA_FIELD:
12089
 
        vnp = DialogToPointer (dlg->mrna_field);
12090
 
        if (vnp == NULL || vnp->data.intvalue == FEATUREFIELD_NONE)
12091
 
        {
12092
 
          head = AddStringToValNodeChain (head, "mRNA field", 1);
12093
 
        }
12094
 
        ValNodeFree (vnp);
12095
 
        break;
12096
 
      case PARSE_FIELD_PROTEIN_FIELD:
12097
 
        vnp = DialogToPointer (dlg->protein_field);
12098
 
        if (vnp == NULL || vnp->data.intvalue == FEATUREFIELD_NONE)
12099
 
        {
12100
 
          head = AddStringToValNodeChain (head, "protein field", 1);
12101
 
        }
12102
 
        ValNodeFree (vnp);
12103
 
        break;
12104
 
      case PARSE_FIELD_IMPORT_QUAL:
12105
 
        vnp = DialogToPointer (dlg->import_qual);
12106
 
        if (vnp == NULL)
12107
 
        {
12108
 
          ValNodeAddPointer (&head, 1, "import qualifier");
12109
 
        }
12110
 
        ValNodeFree (vnp);
12111
 
        vnp = DialogToPointer (dlg->import_feature);
12112
 
        if (vnp == NULL)
12113
 
        {
12114
 
          ValNodeAddPointer (&head, 1, "import feature");
12115
 
        }
12116
 
        ValNodeFree (vnp);
12117
 
        break;
12118
 
      case PARSE_FIELD_FEATURE_NOTE:
12119
 
        vnp = DialogToPointer (dlg->feature);
12120
 
        if (vnp == NULL)
12121
 
        {
12122
 
          ValNodeAddPointer (&head, 1, "feature");
12123
 
          ValNodeFree (vnp);
12124
 
        }
12125
 
        break;
12126
 
      default:
12127
 
        head = AddStringToValNodeChain (head, "field type", 1);
12128
 
        break;
 
14273
    vnp = DialogToPointer (dlg->parse_field_type);
 
14274
    if (vnp == NULL) 
 
14275
    {
 
14276
      head = AddStringToValNodeChain (head, "destination type", 1);
 
14277
    }
 
14278
    else
 
14279
    {
 
14280
      parse_field_type = vnp->choice;
 
14281
      vnp = ValNodeFreeData (vnp);
 
14282
      switch (parse_field_type)
 
14283
      {
 
14284
        case PARSE_FIELD_DEFLINE:
 
14285
        case PARSE_FIELD_CDS_COMMENT:
 
14286
        case PARSE_FIELD_COMMENT_DESC:
 
14287
          /* don't need any extra information */
 
14288
          break;
 
14289
        case PARSE_FIELD_BIOSRC_STRING:
 
14290
          vnp = DialogToPointer (dlg->biosrc_string_choice);
 
14291
          if (vnp == NULL)
 
14292
          {
 
14293
            head = AddStringToValNodeChain (head, "biosrc string type", 1);
 
14294
          }
 
14295
          ValNodeFree (vnp);
 
14296
          break;
 
14297
        case PARSE_FIELD_SOURCE_QUAL:
 
14298
          vnp = DialogToPointer (dlg->source_qual_choice);
 
14299
          if (vnp == NULL)
 
14300
          {
 
14301
            head = AddStringToValNodeChain (head, "source qual type", 1);
 
14302
          }
 
14303
          ValNodeFree (vnp);
 
14304
          break;
 
14305
        case PARSE_FIELD_GENE_FIELD:
 
14306
          vnp = DialogToPointer (dlg->gene_field);
 
14307
          if (vnp == NULL || vnp->data.intvalue == FEATUREFIELD_NONE)
 
14308
          {
 
14309
            head = AddStringToValNodeChain (head, "gene field", 1);
 
14310
          }
 
14311
          ValNodeFree (vnp);
 
14312
          break;
 
14313
        case PARSE_FIELD_RNA_FIELD:
 
14314
          vnp = DialogToPointer (dlg->rna_subtype);
 
14315
          if (vnp == NULL)
 
14316
          {
 
14317
            head = AddStringToValNodeChain (head, "RNA subtype", 1);
 
14318
          }
 
14319
          ValNodeFree (vnp);
 
14320
          vnp = DialogToPointer (dlg->rna_field);
 
14321
          if (vnp == NULL || vnp->data.intvalue == FEATUREFIELD_NONE)
 
14322
          {
 
14323
            head = AddStringToValNodeChain (head, "RNA field", 1);
 
14324
          }
 
14325
          ValNodeFree (vnp);          
 
14326
          break;
 
14327
        case PARSE_FIELD_PROTEIN_FIELD:
 
14328
          vnp = DialogToPointer (dlg->protein_field);
 
14329
          if (vnp == NULL || vnp->data.intvalue == FEATUREFIELD_NONE)
 
14330
          {
 
14331
            head = AddStringToValNodeChain (head, "protein field", 1);
 
14332
          }
 
14333
          ValNodeFree (vnp);
 
14334
          break;
 
14335
        case PARSE_FIELD_IMPORT_QUAL:
 
14336
          vnp = DialogToPointer (dlg->import_qual);
 
14337
          if (vnp == NULL)
 
14338
          {
 
14339
            ValNodeAddPointer (&head, 1, "import qualifier");
 
14340
          }
 
14341
          ValNodeFree (vnp);
 
14342
          vnp = DialogToPointer (dlg->import_feature);
 
14343
          if (vnp == NULL)
 
14344
          {
 
14345
            ValNodeAddPointer (&head, 1, "import feature");
 
14346
          }
 
14347
          ValNodeFree (vnp);
 
14348
          break;
 
14349
        case PARSE_FIELD_FEATURE_NOTE:
 
14350
          vnp = DialogToPointer (dlg->feature);
 
14351
          if (vnp == NULL)
 
14352
          {
 
14353
            ValNodeAddPointer (&head, 1, "feature");
 
14354
            ValNodeFree (vnp);
 
14355
          }
 
14356
          break;
 
14357
        case PARSE_FIELD_DBXREF:
 
14358
          if (TextHasNoText (dlg->dbxref_db))
 
14359
          {
 
14360
            ValNodeAddPointer (&head, 1, "specify database");
 
14361
          }
 
14362
          break;
 
14363
        case SEARCH_FIELD_PUBLICATION:
 
14364
          if (!dlg->is_search_field) 
 
14365
          {
 
14366
            head = AddStringToValNodeChain (head, "field type", 1);
 
14367
          }
 
14368
          break;
 
14369
        default:
 
14370
          head = AddStringToValNodeChain (head, "field type", 1);
 
14371
          break;
 
14372
      }
12129
14373
    }
12130
14374
  }      
12131
14375
 
12132
14376
  return head;
12133
14377
}
12134
14378
 
12135
 
extern DialoG ParseFieldDestDialog 
 
14379
 
 
14380
static ValNodePtr GetParseFieldDestList (Boolean include_pub, Boolean include_dbxref)
 
14381
{
 
14382
  ValNodePtr list = NULL;
 
14383
 
 
14384
  ValNodeAddPointer (&list, PARSE_FIELD_DEFLINE, StringSave ("Definition Line"));
 
14385
  ValNodeAddPointer (&list, PARSE_FIELD_BIOSRC_STRING, StringSave ("Biosource"));
 
14386
  ValNodeAddPointer (&list, PARSE_FIELD_SOURCE_QUAL, StringSave ("Source Qualifier"));
 
14387
  ValNodeAddPointer (&list, PARSE_FIELD_GENE_FIELD, StringSave ("Gene Field"));
 
14388
  ValNodeAddPointer (&list, PARSE_FIELD_RNA_FIELD, StringSave ("RNA Field"));
 
14389
  ValNodeAddPointer (&list, PARSE_FIELD_CDS_COMMENT, StringSave ("CDS Comment"));
 
14390
  ValNodeAddPointer (&list, PARSE_FIELD_PROTEIN_FIELD, StringSave ("Protein Field"));
 
14391
  ValNodeAddPointer (&list, PARSE_FIELD_IMPORT_QUAL, StringSave ("Import Feature"));
 
14392
  ValNodeAddPointer (&list, PARSE_FIELD_FEATURE_NOTE, StringSave ("Feature Note"));
 
14393
  ValNodeAddPointer (&list, PARSE_FIELD_COMMENT_DESC, StringSave ("Comment Descriptor"));
 
14394
  if (include_dbxref)
 
14395
  {
 
14396
    ValNodeAddPointer (&list, PARSE_FIELD_DBXREF, StringSave ("Dbxref"));
 
14397
  }
 
14398
  if (include_pub)
 
14399
  {
 
14400
    ValNodeAddPointer (&list, SEARCH_FIELD_PUBLICATION, StringSave ("Publication"));
 
14401
  }
 
14402
  return list;  
 
14403
}
 
14404
 
 
14405
 
 
14406
static void ChangeParseFieldDestText (TexT t)
 
14407
{
 
14408
  ParseFieldDialogPtr dlg;
 
14409
 
 
14410
  dlg = (ParseFieldDialogPtr) GetObjectExtra (t);
 
14411
  if (dlg != NULL && dlg->change_notify != NULL)
 
14412
  {
 
14413
    (dlg->change_notify) (dlg->change_userdata);
 
14414
  }
 
14415
}
 
14416
 
 
14417
 
 
14418
extern DialoG ParseFieldDestDialogEx 
12136
14419
(GrouP                    h,
12137
14420
 Nlm_ChangeNotifyProc     change_notify,
12138
 
 Pointer                  change_userdata)
 
14421
 Pointer                  change_userdata,
 
14422
 Boolean                  is_search_field,
 
14423
 Boolean                  include_dbxref)
12139
14424
{
12140
14425
  ParseFieldDialogPtr dlg;
12141
 
  GrouP               p, g;
 
14426
  GrouP               p, m, g;
12142
14427
  GrouP               subgrp;
 
14428
  ValNodePtr          choice_list;
 
14429
  ValNode             vn;
12143
14430
  
12144
14431
  dlg = (ParseFieldDialogPtr) MemNew (sizeof (ParseFieldDialogData));
12145
14432
  if (dlg == NULL)
12147
14434
    return NULL;
12148
14435
  }
12149
14436
  
12150
 
  p = HiddenGroup (h, 2, 0, NULL);
 
14437
  p = HiddenGroup (h, -1, 0, NULL);
12151
14438
  SetObjectExtra (p, dlg, StdCleanupExtraProc);
12152
14439
 
12153
14440
  dlg->dialog = (DialoG) p;
12157
14444
  dlg->testdialog = TestParseFieldDialog;
12158
14445
  dlg->change_notify = change_notify;
12159
14446
  dlg->change_userdata = change_userdata;
12160
 
  
12161
 
  dlg->parse_field_type = PopupList (p, TRUE, ChangeParseFieldType);  
12162
 
  PopupItem (dlg->parse_field_type, "Definition Line");
12163
 
  PopupItem (dlg->parse_field_type, "Biosource");
12164
 
  PopupItem (dlg->parse_field_type, "Source Qualifier");
12165
 
  PopupItem (dlg->parse_field_type, "Gene Field");
12166
 
  PopupItem (dlg->parse_field_type, "mRNA Field");
12167
 
  PopupItem (dlg->parse_field_type, "CDS Comment");
12168
 
  PopupItem (dlg->parse_field_type, "Protein Field");
12169
 
  PopupItem (dlg->parse_field_type, "Import Feature");
12170
 
  PopupItem (dlg->parse_field_type, "Feature Note");
12171
 
  PopupItem (dlg->parse_field_type, "Comment Descriptor");
12172
 
  SetValue (dlg->parse_field_type, PARSE_FIELD_DEFLINE);
12173
 
  SetObjectExtra (dlg->parse_field_type, dlg, NULL);
12174
 
  
12175
 
  subgrp = HiddenGroup (p, 0, 0, NULL);
 
14447
  dlg->is_search_field = is_search_field;
 
14448
  
 
14449
  m = HiddenGroup (p, 2, 0, NULL);
 
14450
 
 
14451
  choice_list = GetParseFieldDestList (is_search_field, include_dbxref);
 
14452
  dlg->parse_field_type = ValNodeSelectionDialog (m, choice_list, TALL_SELECTION_LIST, ValNodeStringName,
 
14453
                                ValNodeSimpleDataFree, ValNodeStringCopy,
 
14454
                                ValNodeChoiceMatch, "parse destination", 
 
14455
                                ChangeParseFieldType, dlg, FALSE);
 
14456
 
 
14457
  subgrp = HiddenGroup (m, 0, 0, NULL);
12176
14458
  dlg->biosrc_string_choice = BioSourceStringDialog (subgrp, FALSE, change_notify, change_userdata);
12177
14459
  Hide (dlg->biosrc_string_choice);
12178
14460
  dlg->source_qual_choice = SourceQualTypeSelectionDialog (subgrp, FALSE, change_notify, change_userdata);
12179
14461
  Hide (dlg->source_qual_choice);
12180
14462
  dlg->gene_field = GeneFieldSelectionDialog (subgrp, FALSE, change_notify, change_userdata);
12181
14463
  Hide (dlg->gene_field);
12182
 
  dlg->mrna_field = MRNAFieldSelectionDialog (subgrp, FALSE, change_notify, change_userdata);
12183
 
  Hide (dlg->mrna_field);
 
14464
  g = HiddenGroup (subgrp, 2, 0, NULL);
 
14465
  dlg->rna_subtype = RNASubtypeSelectionDialog (g, FALSE, NULL, change_notify, change_userdata);
 
14466
  Hide (dlg->rna_subtype);
 
14467
  dlg->rna_field = RNAFieldSelectionDialog (g, FALSE, 
 
14468
                                            change_notify, 
 
14469
                                            change_userdata);
 
14470
  Hide (dlg->rna_field);
12184
14471
  dlg->protein_field = ProteinFieldSelectionDialog (subgrp, FALSE, change_notify, change_userdata);
12185
14472
  Hide (dlg->protein_field);
12186
14473
  g = HiddenGroup (subgrp, 2, 0, NULL);
12190
14477
  Hide (dlg->import_qual);
12191
14478
  dlg->feature = FeatureSelectionDialog (subgrp, TRUE, change_notify, change_userdata);
12192
14479
  Hide (dlg->feature);
 
14480
  if (include_dbxref)
 
14481
  {
 
14482
    dlg->dbxref_grp = HiddenGroup (subgrp, 2, 0, NULL);
 
14483
    StaticPrompt (dlg->dbxref_grp, "Database:", 0, 0, programFont, 'r');
 
14484
    dlg->dbxref_db = DialogText (dlg->dbxref_grp, "", 5, ChangeParseFieldDestText);
 
14485
    SetObjectExtra (dlg->dbxref_db, dlg, NULL);
 
14486
    Hide (dlg->dbxref_grp);
 
14487
  }
 
14488
  else
 
14489
  {
 
14490
    dlg->dbxref_db = NULL;
 
14491
  }
 
14492
 
 
14493
  vn.choice = PARSE_FIELD_DEFLINE;
 
14494
  vn.data.ptrvalue = NULL;
 
14495
  vn.next = NULL;
 
14496
  PointerToDialog (dlg->parse_field_type, &vn);
 
14497
 
 
14498
  dlg->feat_or_desc = HiddenGroup (p, 3, 0, NULL);
 
14499
  RadioButton (dlg->feat_or_desc, "Descriptors and Features");
 
14500
  RadioButton (dlg->feat_or_desc, "Descriptors Only");
 
14501
  RadioButton (dlg->feat_or_desc, "Features Only");
 
14502
  SetValue (dlg->feat_or_desc, 1);
 
14503
  Hide (dlg->feat_or_desc);
 
14504
  
 
14505
  AlignObjects (ALIGN_CENTER, (HANDLE) m, (HANDLE) dlg->feat_or_desc, NULL);
12193
14506
 
12194
14507
  return (DialoG) p;  
12195
14508
}
12196
14509
 
12197
 
#define PARSE_FIELD_SRC_DEFLINE          1
12198
 
#define PARSE_FIELD_SRC_GENBANK_FLATFILE 2
12199
 
#define PARSE_FIELD_SRC_LOCAL_ID         3
12200
 
#define PARSE_FIELD_SRC_TAXNAME          4
12201
 
#define PARSE_FIELD_SRC_COMMENT          5
12202
 
#define PARSE_FIELD_BANKIT_COMMENT       6
12203
 
#define PARSE_FIELD_STRUCTURED_COMMENT   7
12204
 
#define MAX_PARSE_FIELD                  7
 
14510
extern DialoG ParseFieldDestDialog 
 
14511
(GrouP                    h,
 
14512
 Nlm_ChangeNotifyProc     change_notify,
 
14513
 Pointer                  change_userdata)
 
14514
{
 
14515
  return ParseFieldDestDialogEx (h, change_notify, change_userdata, FALSE, FALSE);
 
14516
}
 
14517
/* Search Field dialog is identical to ParseFieldDestDialog except that it allows
 
14518
 * an additional option, Publication.
 
14519
 */
 
14520
extern DialoG SearchFieldDialog 
 
14521
(GrouP                    h,
 
14522
 Nlm_ChangeNotifyProc     change_notify,
 
14523
 Pointer                  change_userdata)
 
14524
{
 
14525
  return ParseFieldDestDialogEx (h, change_notify, change_userdata, TRUE, FALSE);
 
14526
}
 
14527
 
 
14528
 
 
14529
typedef enum
 
14530
{
 
14531
 eParseFieldSrcDefLine = 1,
 
14532
 eParseFieldSrcGenBankFlatFile,
 
14533
 eParseFieldSrcLocalID,
 
14534
 eParseFieldSrcTaxName,
 
14535
 eParseFieldSrcSourceQual,
 
14536
 eParseFieldSrcComment,
 
14537
 eParseFieldSrcBankitComment,
 
14538
 eParseFieldSrcStructuredComment,
 
14539
 eParseFieldSrcTaxNameAfterNomial,
 
14540
 eParseFieldSrcFileID
 
14541
} EParseFieldSrc;
 
14542
 
 
14543
const Int4 MAX_PARSE_FIELD = eParseFieldSrcFileID;
12205
14544
 
12206
14545
static CharPtr parse_src_field_list [] = 
12207
14546
{
12208
 
  "Definition Line", "GenBank Flatfile", "Local ID", "Organism Name", "Comment", "Bankit Comment", "Structured Comment"
 
14547
  "Definition Line", "GenBank Flatfile", "Local ID", "Organism Name", "Source Qualifier", "Comment", "Bankit Comment", 
 
14548
  "Structured Comment", "Taxname after Binomial/Trinomial", "File ID"
12209
14549
};
12210
14550
 
12211
14551
static int num_parse_src_fields = sizeof (parse_src_field_list) / sizeof (CharPtr);
12212
14552
 
12213
14553
typedef struct parsefieldsrc 
12214
14554
{
12215
 
  Int4    parse_field;
12216
 
  CharPtr comment_field;
 
14555
  Int4              parse_field;
 
14556
  SourceQualDescPtr sqdp;
 
14557
  CharPtr           comment_field;
12217
14558
} ParseFieldSrcData, PNTR ParseFieldSrcPtr;
12218
14559
 
12219
14560
static ParseFieldSrcPtr ParseFieldSrcFree (ParseFieldSrcPtr pfsp)
12220
14561
{
12221
14562
  if (pfsp != NULL) {
12222
14563
    pfsp->comment_field = MemFree (pfsp->comment_field);
 
14564
    pfsp->sqdp = MemFree (pfsp->sqdp);
12223
14565
    pfsp = MemFree (pfsp);
12224
14566
  }
12225
14567
  return pfsp;
12231
14573
  DialoG     parse_field;
12232
14574
  PopuP      comment_field;
12233
14575
  ValNodePtr comment_field_list;
 
14576
  DialoG     src_qual;
12234
14577
  Nlm_ChangeNotifyProc     change_notify;
12235
14578
  Pointer                  change_userdata;      
12236
14579
} ParseFieldSrcDlgData, PNTR ParseFieldSrcDlgPtr;
12283
14626
  if (dlg == NULL) return;
12284
14627
   
12285
14628
  vnp = DialogToPointer (dlg->parse_field);
12286
 
  if (vnp == NULL || vnp->data.intvalue != PARSE_FIELD_STRUCTURED_COMMENT) {
 
14629
  if (vnp == NULL || vnp->data.intvalue != eParseFieldSrcStructuredComment) {
12287
14630
    Hide (dlg->comment_field);
12288
14631
  } else {
12289
14632
    Show (dlg->comment_field);
12290
14633
  }
 
14634
  if (vnp == NULL || vnp->data.intvalue != eParseFieldSrcSourceQual) {
 
14635
    Hide (dlg->src_qual);
 
14636
  } else {
 
14637
    Show (dlg->src_qual);
 
14638
  }
12291
14639
  
12292
14640
  if (dlg->change_notify != NULL) {
12293
14641
    (dlg->change_notify)(dlg->change_userdata);
12331
14679
      vn.choice = 0;
12332
14680
      PointerToDialog (dlg->parse_field, &vn);
12333
14681
      SetValue (dlg->comment_field, FindCommentFieldPosition (pfsp->comment_field, dlg->comment_field_list));
 
14682
      vn.data.ptrvalue = pfsp->sqdp;
 
14683
      PointerToDialog (dlg->src_qual, &vn);
12334
14684
    }
12335
14685
  }
12336
14686
  ParseFieldChange (dlg);     
12355
14705
    vnp = ValNodeFree (vnp);
12356
14706
  }
12357
14707
  pfsp->comment_field = NULL;
12358
 
  if (pfsp->parse_field == PARSE_FIELD_STRUCTURED_COMMENT) {
 
14708
  pfsp->sqdp = NULL;
 
14709
  if (pfsp->parse_field == eParseFieldSrcStructuredComment) {
12359
14710
    field_pos = GetValue (dlg->comment_field);
12360
14711
    if (field_pos > 0) {
12361
14712
      vnp = dlg->comment_field_list;
12368
14719
        pfsp->comment_field = StringSave (vnp->data.ptrvalue);
12369
14720
      }
12370
14721
    }
 
14722
  } else if (pfsp->parse_field == eParseFieldSrcSourceQual) {
 
14723
    vnp = DialogToPointer (dlg->src_qual);
 
14724
    if (vnp != NULL) {
 
14725
      pfsp->sqdp = vnp->data.ptrvalue;
 
14726
      vnp->data.ptrvalue = NULL;
 
14727
      vnp = ValNodeFreeData (vnp);
 
14728
    }
12371
14729
  }
 
14730
  
12372
14731
  return pfsp;
12373
14732
}
12374
14733
 
12413
14772
  }
12414
14773
}
12415
14774
 
 
14775
 
 
14776
static ValNodePtr TestParseFieldSource (DialoG d)
 
14777
 
 
14778
{
 
14779
  ParseFieldSrcDlgPtr dlg;
 
14780
  ValNodePtr          head = NULL, vnp, vnp2;
 
14781
 
 
14782
  dlg = (ParseFieldSrcDlgPtr) GetObjectExtra (d);
 
14783
  
 
14784
  vnp = DialogToPointer (dlg->parse_field);
 
14785
  if (vnp == NULL)
 
14786
  {
 
14787
    head = AddStringToValNodeChain (head, "field choice", 1);
 
14788
  }
 
14789
  else if (vnp->data.intvalue == eParseFieldSrcSourceQual)
 
14790
  {
 
14791
    vnp2 = DialogToPointer (dlg->src_qual);
 
14792
    if (vnp2 == NULL)
 
14793
    {
 
14794
      head = AddStringToValNodeChain (head, "source qual", 1);
 
14795
    }
 
14796
    vnp2 = ValNodeFree (vnp2);
 
14797
  }
 
14798
 
 
14799
  vnp = ValNodeFree (vnp);
 
14800
  
 
14801
  return head;  
 
14802
}
 
14803
 
 
14804
 
12416
14805
extern DialoG ParseFieldSourceDialog
12417
14806
(GrouP                    h,
12418
14807
 SeqEntryPtr              sep,
12420
14809
 Pointer                  change_userdata)
12421
14810
{
12422
14811
  ParseFieldSrcDlgPtr dlg;
12423
 
  GrouP               p;
 
14812
  GrouP               p, k;
12424
14813
  ValNodePtr          vnp;
12425
14814
  
12426
14815
  dlg = (ParseFieldSrcDlgPtr) MemNew (sizeof (ParseFieldSrcDlgData));
12437
14826
  dlg->todialog = DataToParseFieldSrcDialog;
12438
14827
  dlg->fromdialog = ParseFieldSrcDialogToData;
12439
14828
  dlg->dialogmessage = ParseFieldSourceDialogMessage;
12440
 
  dlg->testdialog = NULL;
 
14829
  dlg->testdialog = TestParseFieldSource;
12441
14830
  dlg->change_notify = change_notify;
12442
14831
  dlg->change_userdata = change_userdata;
12443
14832
 
12445
14834
                                                  num_parse_src_fields, parse_src_field_list, 
12446
14835
                                                  ParseFieldChange, dlg);
12447
14836
 
12448
 
  dlg->comment_field = PopupList (p, TRUE, NULL);
 
14837
  k = HiddenGroup (p, 0, 0, NULL);
 
14838
  dlg->comment_field = PopupList (k, TRUE, NULL);
 
14839
  dlg->src_qual = SourceQualTypeSelectionDialogEx (k, FALSE, change_notify,
 
14840
                                                   change_userdata, 6, FALSE, FALSE);
 
14841
  AlignObjects (ALIGN_CENTER, (HANDLE) dlg->comment_field, (HANDLE) dlg->src_qual, NULL);
12449
14842
  
12450
 
  // Add to comment_field list all user fields found in SeqEntry sep
 
14843
  /* Add to comment_field list all user fields found in SeqEntry sep */
12451
14844
  VisitDescriptorsInSep (sep, &(dlg->comment_field_list), AddCommentFieldName);
12452
14845
  for (vnp = dlg->comment_field_list; vnp != NULL; vnp = vnp->next) {
12453
14846
    PopupItem (dlg->comment_field, vnp->data.ptrvalue);
12523
14916
  Char              tmp[128];
12524
14917
  CharPtr           val_str = NULL, new_val_str, tmp_val_str;
12525
14918
  ValNodePtr        sample_field, sample_field_next;
12526
 
  Boolean           found_text = FALSE;
12527
14919
  ValNodePtr        new_row = NULL;
12528
14920
  SeqIdPtr          sip;
12529
14921
  
12744
15136
  ValNodePtr      sample_field, sample_field_next;
12745
15137
  CharPtr         sample_label = NULL;
12746
15138
  Int4            max_char_per_line;
12747
 
  FonT            currentFont=NULL;
12748
15139
 
12749
15140
  if (dlg == NULL)
12750
15141
  {
12836
15227
  ssp = (SetSamplePtr) userdata;
12837
15228
  dlg->ssp = SetSampleFree (dlg->ssp);
12838
15229
  dlg->ssp = SetSampleCopy (ssp);
12839
 
//  RefreshSampleDialog (dlg);
12840
15230
}
12841
15231
 
12842
15232
static void 
13533
15923
 
13534
15924
typedef struct parseaction
13535
15925
{
13536
 
  TextPortionPtr tp;
 
15926
  TextPortionXPtr tp;
13537
15927
  FilterSetPtr   fsp;
13538
15928
  Int4           src_field;
13539
15929
  CharPtr        comment_field;
13573
15963
  }
13574
15964
}
13575
15965
 
13576
 
static void DoParseAction (CharPtr src_str, ParseActionOpPtr paop)
13577
 
{
13578
 
  CharPtr          found_loc = NULL;
13579
 
  Int4             found_len = 0;
13580
 
 
13581
 
  if (StringHasNoText (src_str) || paop == NULL 
13582
 
      || paop->parse_action_data == NULL
13583
 
      || paop->parse_action == NULL)
13584
 
  {
13585
 
    return;
13586
 
  }
13587
 
  
13588
 
  FindTextPortionInString (src_str, paop->parse_action_data->tp, &found_loc, &found_len);
13589
 
  
13590
 
  if (found_loc != NULL)
13591
 
  {
13592
 
    (paop->parse_action) (paop->parse_action_data, paop->parse_userdata, found_loc, found_len);
13593
 
    paop->parse_complete = TRUE;
13594
 
  }
13595
 
  
13596
 
}
13597
 
 
13598
 
static void ParseActionDeflineText (SeqDescrPtr sdp, Pointer userdata)
13599
 
{
13600
 
  ParseActionOpPtr paop;
13601
 
  CharPtr          tmp_string;
13602
 
  Int4             last_pos;
13603
 
  
13604
 
  paop = (ParseActionOpPtr) userdata;
13605
 
  if (paop == NULL || paop->parse_action_data == NULL || paop->parse_action == NULL
13606
 
      || sdp == NULL || sdp->choice != Seq_descr_title)
13607
 
  {
13608
 
    return;
13609
 
  }
13610
 
  
13611
 
  tmp_string = StringSave (sdp->data.ptrvalue);
13612
 
  if (tmp_string != NULL)
13613
 
  {
13614
 
    last_pos = StringLen (tmp_string) - 1;
13615
 
    if (tmp_string [last_pos] == '.')
13616
 
    {
13617
 
      tmp_string [last_pos] = 0;
13618
 
    }
13619
 
  }
13620
 
  DoParseAction (tmp_string, paop);
13621
 
  tmp_string = MemFree (tmp_string);
13622
 
}
13623
 
 
13624
 
static void ParseActionTaxnameText (BioSourcePtr biop, Pointer userdata)
13625
 
{
13626
 
  ParseActionOpPtr paop;
13627
 
  
13628
 
  paop = (ParseActionOpPtr) userdata;
13629
 
  if (paop == NULL || paop->parse_action_data == NULL || paop->parse_action == NULL
13630
 
      || biop == NULL || biop->org == NULL)
13631
 
  {
13632
 
    return;
13633
 
  }
13634
 
  
13635
 
  if (paop->parse_action_data->fsp != NULL
13636
 
      && ! DoesOneSourceMatchConstraint (biop, paop->parse_action_data->fsp->ccp))
13637
 
  {
13638
 
    return;
13639
 
  }
13640
 
  
13641
 
  DoParseAction (biop->org->taxname, paop);
13642
 
}
13643
 
 
13644
 
static void ParseActionLocalIDText (BioseqPtr bsp, Pointer userdata)
13645
 
{
13646
 
  ParseActionOpPtr paop;
13647
 
  SeqIdPtr         sip;
13648
 
  ObjectIdPtr      oip;
13649
 
  Char             tmp_str [128];
13650
 
  
13651
 
  paop = (ParseActionOpPtr) userdata;
13652
 
  if (paop == NULL || paop->parse_action_data == NULL || paop->parse_action == NULL
13653
 
      || bsp == NULL || ISA_aa (bsp->mol))
13654
 
  {
13655
 
    return;
13656
 
  }
13657
 
  
13658
 
  for (sip = bsp->id; sip != NULL; sip = sip->next)
13659
 
  {
13660
 
    if (sip->choice == SEQID_LOCAL && sip->data.ptrvalue != NULL)
13661
 
    {
13662
 
      oip = (ObjectIdPtr) sip->data.ptrvalue;
13663
 
      if (oip->str == NULL)
13664
 
      {
13665
 
        sprintf (tmp_str, "%d", oip->id);
13666
 
        DoParseAction (tmp_str, paop);
13667
 
      }
13668
 
      else
13669
 
      {
13670
 
        DoParseAction (oip->str, paop);
13671
 
      }
13672
 
    }
13673
 
  }
13674
 
}
13675
 
 
13676
 
static void ParseActionBankitComment (SeqDescrPtr sdp, Pointer userdata)
13677
 
{
13678
 
  ParseActionOpPtr paop;
13679
 
  UserObjectPtr    uop;
13680
 
  ObjectIdPtr      oip;
13681
 
  UserFieldPtr     ufp;
13682
 
  
13683
 
  if (sdp == NULL || userdata == NULL || sdp->data.ptrvalue == NULL)
13684
 
  {
13685
 
    return;
13686
 
  }
13687
 
  
13688
 
  paop = (ParseActionOpPtr) userdata;
13689
 
  if (paop == NULL || paop->parse_action_data == NULL || paop->parse_action == NULL)
13690
 
  {
13691
 
    return;
13692
 
  }
13693
 
 
13694
 
  if (sdp->choice == Seq_descr_user && sdp->extended != 0)
13695
 
  {
13696
 
    /* Bankit Comments */
13697
 
    uop = (UserObjectPtr) sdp->data.ptrvalue;
13698
 
    oip = uop->type;
13699
 
    if (oip != NULL && StringCmp (oip->str, "Submission") == 0)
13700
 
    {
13701
 
      for (ufp = uop->data; ufp != NULL; ufp = ufp->next)
13702
 
      {
13703
 
        oip = ufp->label;
13704
 
        if (oip != NULL && StringCmp (oip->str, "AdditionalComment") == 0)
13705
 
        {
13706
 
          DoParseAction (ufp->data.ptrvalue, paop);
13707
 
        }
13708
 
      }
13709
 
    }
13710
 
  }
13711
 
}
13712
 
 
13713
 
static void ParseActionCommentDescriptor (SeqDescrPtr sdp, Pointer userdata)
13714
 
{
13715
 
  ParseActionOpPtr paop;
13716
 
  UserObjectPtr    uop;
13717
 
  ObjectIdPtr      oip;
13718
 
  UserFieldPtr     ufp;
13719
 
  
13720
 
  if (sdp == NULL || userdata == NULL || sdp->data.ptrvalue == NULL)
13721
 
  {
13722
 
    return;
13723
 
  }
13724
 
  
13725
 
  paop = (ParseActionOpPtr) userdata;
13726
 
  if (paop == NULL || paop->parse_action_data == NULL || paop->parse_action == NULL)
13727
 
  {
13728
 
    return;
13729
 
  }
13730
 
 
13731
 
  if (sdp->choice == Seq_descr_comment)
13732
 
  {
13733
 
    DoParseAction (sdp->data.ptrvalue, paop);
13734
 
  }
13735
 
  else if (sdp->choice == Seq_descr_user && sdp->extended != 0)
13736
 
  {
13737
 
    /* Bankit Comments */
13738
 
    uop = (UserObjectPtr) sdp->data.ptrvalue;
13739
 
    oip = uop->type;
13740
 
    if (oip != NULL && StringCmp (oip->str, "Submission") == 0)
13741
 
    {
13742
 
      for (ufp = uop->data; ufp != NULL; ufp = ufp->next)
13743
 
      {
13744
 
        oip = ufp->label;
13745
 
        if (oip != NULL && StringCmp (oip->str, "AdditionalComment") == 0)
13746
 
        {
13747
 
          DoParseAction (ufp->data.ptrvalue, paop);
13748
 
        }
13749
 
      }
13750
 
    }
13751
 
  }
13752
 
}
13753
 
 
13754
 
static void ParseActionCommentFeature (SeqFeatPtr sfp, Pointer userdata)
13755
 
{
13756
 
  ParseActionOpPtr paop;
13757
 
 
13758
 
  if (sfp == NULL || sfp->data.choice != SEQFEAT_COMMENT || userdata == NULL)
13759
 
  {
13760
 
    return;
13761
 
  }
13762
 
  paop = (ParseActionOpPtr) userdata;
13763
 
  DoParseAction (sfp->comment, paop);
13764
 
}
13765
 
 
13766
 
 
13767
 
static void ParseActionStructuredComment(SeqDescrPtr sdp, Pointer userdata)
13768
 
{
13769
 
  ParseActionOpPtr paop;
13770
 
  UserObjectPtr    uop;
13771
 
  ObjectIdPtr      oip;
13772
 
  UserFieldPtr     ufp;
13773
 
  
13774
 
  if (sdp == NULL || userdata == NULL || sdp->data.ptrvalue == NULL)
13775
 
  {
13776
 
    return;
13777
 
  }
13778
 
  
13779
 
  paop = (ParseActionOpPtr) userdata;
13780
 
  if (paop == NULL || paop->parse_action_data == NULL || paop->parse_action == NULL)
13781
 
  {
13782
 
    return;
13783
 
  }
13784
 
 
13785
 
  if (sdp->choice == Seq_descr_comment)
13786
 
  {
13787
 
    DoParseAction (sdp->data.ptrvalue, paop);
13788
 
  }
13789
 
  else if (sdp->choice == Seq_descr_user && sdp->extended != 0)
13790
 
  {
13791
 
    /* Bankit Comments */
13792
 
    uop = (UserObjectPtr) sdp->data.ptrvalue;
13793
 
    oip = uop->type;
13794
 
    if (oip != NULL && StringCmp (oip->str, "Submission") == 0)
13795
 
    {
13796
 
      for (ufp = uop->data; ufp != NULL; ufp = ufp->next)
13797
 
      {
13798
 
        oip = ufp->label;
13799
 
        if (oip != NULL && StringCmp (oip->str, "AdditionalComment") == 0)
13800
 
        {
13801
 
          DoParseAction (ufp->data.ptrvalue, paop);
13802
 
        }
13803
 
      }
13804
 
    }
13805
 
  }
13806
 
}
13807
 
 
13808
15966
static void SetSourceAndTitle (ParseActionPtr pap, SeqDescrPtr sdp, SeqAnnotPtr sap)
13809
15967
{
13810
15968
  SeqFeatPtr sfp;
13855
16013
  }
13856
16014
}
13857
16015
 
13858
 
static void ParseFromSource (BioSourcePtr biop, ParseActionPtr pap, ParseActionOpPtr paop)
13859
 
{
13860
 
  if (biop == NULL || pap == NULL || paop == NULL)
13861
 
  {
13862
 
    return;
13863
 
  }
13864
 
 
13865
 
  if (pap->src_field == PARSE_FIELD_SRC_TAXNAME)
13866
 
  {
13867
 
    ParseActionTaxnameText (biop, paop);
13868
 
  }
13869
 
}
13870
 
 
13871
16016
typedef struct parsesourceinfo 
13872
16017
{
13873
16018
  BioseqPtr   bsp;
13940
16085
typedef struct parsesource
13941
16086
{
13942
16087
  Int4           src_field;
 
16088
  SourceQualDescPtr sqdp;
13943
16089
  CharPtr        comment_field;
13944
16090
  FilterSetPtr   fsp;
13945
16091
  ParseFieldPtr  dst_field_data;
13946
16092
  ValNodePtr     source_list; /* ptrvalue points to ParseSourceInfo struct */
13947
 
  TextPortionPtr tp;
 
16093
  TextPortionXPtr tp;
13948
16094
} ParseSourceData, PNTR ParseSourcePtr;
13949
16095
 
13950
16096
 
13952
16098
GetDeflineSourcesForBioseq 
13953
16099
(BioseqPtr       bsp,
13954
16100
 FilterSetPtr    fsp, 
13955
 
 TextPortionPtr  tp,
 
16101
 TextPortionXPtr  tp,
13956
16102
 ValNodePtr PNTR source_list)
13957
16103
{
13958
16104
  SeqDescrPtr        sdp;
13971
16117
  {
13972
16118
    if (fsp == NULL
13973
16119
        || fsp->ccp == NULL
13974
 
        || DoesStringMatchConstraint (sdp->data.ptrvalue, fsp->ccp->string_constraint))
 
16120
        || DoesStringMatchConstraintX (sdp->data.ptrvalue, fsp->ccp->string_constraint))
13975
16121
    {
13976
 
      FindTextPortionInString (sdp->data.ptrvalue, tp, &found_loc, &found_len);
 
16122
      FindTextPortionXInString (sdp->data.ptrvalue, tp, &found_loc, &found_len);
13977
16123
      if (found_loc != NULL)
13978
16124
      {
13979
16125
        parse_src_txt = (CharPtr) MemNew (sizeof (Char) + (found_len + 1));
14001
16147
  }
14002
16148
}
14003
16149
 
 
16150
 
 
16151
static CharPtr GetIDSrc (SeqIdPtr sip, Uint1 id_type, CharPtr tag, FilterSetPtr fsp)
 
16152
{
 
16153
  DbtagPtr    dbt = NULL;
 
16154
  ObjectIdPtr oip = NULL;
 
16155
  Char        id_str[128];
 
16156
  CharPtr     str_src = NULL;
 
16157
 
 
16158
  if (sip == NULL || sip->choice != id_type) return NULL;
 
16159
 
 
16160
  if (id_type == SEQID_GENERAL)
 
16161
  {
 
16162
    dbt = (DbtagPtr) sip->data.ptrvalue;
 
16163
    if (dbt == NULL || (tag != NULL && StringCmp (dbt->db, tag) != 0)) return NULL;
 
16164
    oip = dbt->tag;
 
16165
  }
 
16166
  else if (id_type == SEQID_LOCAL)
 
16167
  {
 
16168
    oip = sip->data.ptrvalue;
 
16169
  }
 
16170
 
 
16171
  id_str[0] = 0;
 
16172
  if (fsp != NULL && fsp->ccp != NULL)
 
16173
  {
 
16174
    SeqIdWrite (sip, id_str, PRINTID_REPORT, sizeof (id_str));
 
16175
    if (!DoesStringMatchConstraintX (id_str, fsp->ccp->string_constraint))
 
16176
    {
 
16177
      return NULL;
 
16178
    }
 
16179
  }
 
16180
 
 
16181
  if (oip == NULL)
 
16182
  {
 
16183
    if (id_str[0] == 0)
 
16184
    {
 
16185
      SeqIdWrite (sip, id_str, PRINTID_REPORT, sizeof (id_str));
 
16186
    }
 
16187
    str_src = StringSave (id_str);
 
16188
  }
 
16189
  else
 
16190
  {
 
16191
    if (oip->str == NULL)
 
16192
    {
 
16193
      sprintf (id_str, "%d", oip->id);
 
16194
      str_src = StringSave (id_str);
 
16195
    }
 
16196
    else
 
16197
    {
 
16198
      str_src = StringSave (oip->str);
 
16199
    }
 
16200
  }
 
16201
  return str_src;
 
16202
}
 
16203
 
 
16204
 
14004
16205
static void
14005
 
GetLocalIDSourcesForBioseq
 
16206
GetIDSourcesForBioseq
14006
16207
(BioseqPtr       bsp,
14007
16208
 FilterSetPtr    fsp, 
14008
 
 TextPortionPtr  tp,
 
16209
 TextPortionXPtr  tp,
 
16210
 Uint1           id_type,
 
16211
 CharPtr         tag,
14009
16212
 ValNodePtr PNTR source_list)
14010
16213
{
14011
16214
  SeqIdPtr           sip;
14012
16215
  ParseSourceInfoPtr psip;
14013
 
  Char               id_str [128];
14014
16216
  CharPtr            src_str, found_loc = NULL, parse_src_txt;
14015
16217
  Int4               found_len;
14016
 
  ObjectIdPtr        oip;
14017
16218
  
14018
16219
  if (bsp == NULL || source_list == NULL)
14019
16220
  {
14023
16224
  sip = bsp->id;
14024
16225
  while (sip != NULL)
14025
16226
  {
14026
 
    if (sip->choice == SEQID_LOCAL)
14027
 
    {
14028
 
      SeqIdWrite (sip, id_str, PRINTID_REPORT, sizeof (id_str));
14029
 
      if (fsp == NULL
14030
 
          || fsp->ccp == NULL
14031
 
          || DoesStringMatchConstraint (id_str, fsp->ccp->string_constraint))
 
16227
    if ((src_str = GetIDSrc (sip, id_type, tag, fsp)) != NULL)
 
16228
    {          
 
16229
      FindTextPortionXInString (src_str, tp, &found_loc, &found_len);
 
16230
      if (found_loc != NULL)
14032
16231
      {
14033
 
        oip = (ObjectIdPtr) sip->data.ptrvalue;
14034
 
        if (oip->str == NULL)
 
16232
        parse_src_txt = (CharPtr) MemNew (sizeof (Char) + (found_len + 1));
 
16233
        StringNCpy (parse_src_txt, found_loc, found_len);
 
16234
        parse_src_txt [found_len] = 0;
 
16235
        psip = (ParseSourceInfoPtr) MemNew (sizeof (ParseSourceInfoData));
 
16236
        if (psip != NULL)
14035
16237
        {
14036
 
          sprintf (id_str, "%d", oip->id);
14037
 
          src_str = id_str;
 
16238
          psip->bsp = bsp;
 
16239
          psip->sdp = NULL;
 
16240
          psip->sfp = NULL;
 
16241
          psip->sip = sip;
 
16242
          psip->dest_list = NULL;
 
16243
          psip->parse_src_txt = parse_src_txt;
 
16244
          ValNodeAddPointer (source_list, 0, psip);
14038
16245
        }
14039
16246
        else
14040
16247
        {
14041
 
          src_str = oip->str;
14042
 
        }
14043
 
        FindTextPortionInString (src_str, tp, &found_loc, &found_len);
14044
 
        if (found_loc != NULL)
14045
 
        {
14046
 
          parse_src_txt = (CharPtr) MemNew (sizeof (Char) + (found_len + 1));
14047
 
          StringNCpy (parse_src_txt, found_loc, found_len);
14048
 
          parse_src_txt [found_len] = 0;
14049
 
          psip = (ParseSourceInfoPtr) MemNew (sizeof (ParseSourceInfoData));
14050
 
          if (psip != NULL)
14051
 
          {
14052
 
            psip->bsp = bsp;
14053
 
            psip->sdp = NULL;
14054
 
            psip->sfp = NULL;
14055
 
            psip->sip = sip;
14056
 
            psip->dest_list = NULL;
14057
 
            psip->parse_src_txt = parse_src_txt;
14058
 
            ValNodeAddPointer (source_list, 0, psip);
14059
 
          }
14060
 
          else
14061
 
          {
14062
 
            parse_src_txt = MemFree (parse_src_txt);
14063
 
          }
 
16248
          parse_src_txt = MemFree (parse_src_txt);
14064
16249
        }
14065
16250
      }
 
16251
      src_str = MemFree (src_str);
14066
16252
    }
14067
16253
    sip = sip->next;
14068
16254
  }
14069
16255
}
14070
16256
 
 
16257
 
 
16258
static void
 
16259
GetLocalIDSourcesForBioseq
 
16260
(BioseqPtr       bsp,
 
16261
 FilterSetPtr    fsp, 
 
16262
 TextPortionXPtr  tp,
 
16263
 ValNodePtr PNTR source_list)
 
16264
{
 
16265
  GetIDSourcesForBioseq (bsp, fsp, tp, SEQID_LOCAL, NULL, source_list);
 
16266
}
 
16267
 
 
16268
 
 
16269
static void GetNcbiFileSourceForBioseq
 
16270
(BioseqPtr       bsp,
 
16271
 FilterSetPtr    fsp, 
 
16272
 TextPortionXPtr  tp,
 
16273
 ValNodePtr PNTR source_list)
 
16274
{
 
16275
  GetIDSourcesForBioseq (bsp, fsp, tp, SEQID_GENERAL, "NCBIFILE", source_list);
 
16276
}
 
16277
 
 
16278
 
 
16279
const CharPtr nomial_keywordsx[] = {
 
16280
"f. sp. ",
 
16281
"var.",
 
16282
"pv.",
 
16283
"bv.",
 
16284
"serovar",
 
16285
"subsp." };
 
16286
 
 
16287
const Int4 num_nomial_keywordsx = sizeof(nomial_keywordsx) / sizeof (CharPtr);
 
16288
 
 
16289
static CharPtr GetTextAfterNomial (CharPtr taxname)
 
16290
 
 
16291
{
 
16292
  CharPtr ptr, nomial_end;
 
16293
  Int4    i;
 
16294
  Boolean found_keyword = TRUE;
 
16295
  
 
16296
  ptr = StringChr (taxname, ' ');
 
16297
  if (ptr == NULL) return NULL;
 
16298
  /* skip over the first word and the spaces after it. */
 
16299
  while (*ptr == ' ') 
 
16300
  {
 
16301
    ptr++;
 
16302
  }
 
16303
  ptr = StringChr (ptr, ' ');
 
16304
  /* if there are only two words, give up. */
 
16305
  if (ptr == NULL) 
 
16306
  {
 
16307
    return NULL;
 
16308
  }
 
16309
  nomial_end = ptr;
 
16310
  while (*ptr == ' ')
 
16311
  {
 
16312
    ptr++;
 
16313
  }
 
16314
  
 
16315
  while (found_keyword) {
 
16316
    found_keyword = FALSE;
 
16317
    /* if the next word is a nomial keyword, skip that plus the first word that follows it. */
 
16318
    for (i = 0; i < num_nomial_keywordsx && *nomial_end != 0; i++) {
 
16319
      if (StringNCmp (ptr, nomial_keywordsx[i], StringLen(nomial_keywordsx[i])) == 0)
 
16320
      {
 
16321
        ptr += StringLen(nomial_keywordsx[i]);
 
16322
        while (*ptr == ' ' )
 
16323
        {
 
16324
          ptr++;
 
16325
        }
 
16326
        nomial_end = StringChr (ptr, ' ');
 
16327
        if (nomial_end == NULL)
 
16328
        {
 
16329
          nomial_end = ptr + StringLen (ptr);
 
16330
        }
 
16331
        else 
 
16332
        {          
 
16333
          ptr = nomial_end;
 
16334
          while (*ptr == ' ') {
 
16335
            ptr++;
 
16336
          }
 
16337
          found_keyword = TRUE;
 
16338
        }
 
16339
      }
 
16340
    }
 
16341
  }
 
16342
  return nomial_end;
 
16343
}
 
16344
 
14071
16345
static void 
14072
 
GetTaxNameSourcesForBioseq 
 
16346
GetTaxNameSourcesForBioseqEx
14073
16347
(BioseqPtr       bsp,
14074
16348
 FilterSetPtr    fsp, 
14075
 
 TextPortionPtr  tp,
14076
 
 ValNodePtr PNTR source_list)
 
16349
 TextPortionXPtr  tp,
 
16350
 ValNodePtr PNTR source_list,
 
16351
 Boolean         skip_nomial)
14077
16352
{
14078
16353
  SeqDescrPtr        sdp;
14079
16354
  SeqFeatPtr         sfp;
14083
16358
  CharPtr            found_loc = NULL, parse_src_txt;
14084
16359
  Int4               found_len;
14085
16360
  BioSourcePtr       biop;
 
16361
  CharPtr            nomial;
14086
16362
  
14087
16363
  if (bsp == NULL || source_list == NULL)
14088
16364
  {
14098
16374
        || fsp->ccp == NULL
14099
16375
        || DoesOneSourceMatchConstraint (biop, fsp->ccp)))
14100
16376
    {
14101
 
      FindTextPortionInString (biop->org->taxname, tp, &found_loc, &found_len);
 
16377
      if (skip_nomial) {
 
16378
        nomial = GetTextAfterNomial(biop->org->taxname);
 
16379
        FindTextPortionXInString (nomial, tp, &found_loc, &found_len);
 
16380
      } else {
 
16381
        FindTextPortionXInString (biop->org->taxname, tp, &found_loc, &found_len);
 
16382
      }
14102
16383
      if (found_loc != NULL)
14103
16384
      {
14104
16385
        parse_src_txt = (CharPtr) MemNew (sizeof (Char) + (found_len + 1));
14134
16415
        || fsp->ccp == NULL
14135
16416
        || DoesOneSourceMatchConstraint (sfp->data.value.ptrvalue, fsp->ccp)))
14136
16417
    {
14137
 
      FindTextPortionInString (biop->org->taxname, tp, &found_loc, &found_len);
 
16418
      FindTextPortionXInString (biop->org->taxname, tp, &found_loc, &found_len);
14138
16419
      if (found_loc != NULL)
14139
16420
      {
14140
16421
        parse_src_txt = (CharPtr) MemNew (sizeof (Char) + (found_len + 1));
14162
16443
  }
14163
16444
}
14164
16445
 
 
16446
 
 
16447
static void 
 
16448
GetTaxNameSourcesForBioseq 
 
16449
(BioseqPtr       bsp,
 
16450
 FilterSetPtr    fsp, 
 
16451
 TextPortionXPtr  tp,
 
16452
 ValNodePtr PNTR source_list)
 
16453
{
 
16454
  GetTaxNameSourcesForBioseqEx (bsp, fsp, tp, source_list, FALSE);
 
16455
}
 
16456
 
 
16457
 
 
16458
static void 
 
16459
GetTaxNameAfterNomialSourcesForBioseq
 
16460
(BioseqPtr       bsp,
 
16461
 FilterSetPtr    fsp, 
 
16462
 TextPortionXPtr  tp,
 
16463
 ValNodePtr PNTR source_list)
 
16464
{
 
16465
  GetTaxNameSourcesForBioseqEx (bsp, fsp, tp, source_list, TRUE);
 
16466
}
 
16467
 
 
16468
 
 
16469
static CharPtr 
 
16470
GetSourceQualSourceTextForBioSource
 
16471
(BioSourcePtr      biop,
 
16472
 SourceQualDescPtr sqdp,
 
16473
 FilterSetPtr      fsp, 
 
16474
 TextPortionXPtr    tp)
 
16475
{
 
16476
  CharPtr str;
 
16477
  CharPtr found_loc = NULL, parse_src_txt = NULL;
 
16478
  Int4    found_len;
 
16479
 
 
16480
  if (biop == NULL || biop->org == NULL || sqdp == NULL
 
16481
      || (fsp != NULL
 
16482
          && fsp->ccp != NULL
 
16483
          && !DoesOneSourceMatchConstraint (biop, fsp->ccp)))
 
16484
  {
 
16485
    return NULL;
 
16486
  }
 
16487
 
 
16488
  str = GetSourceQualQualValueFromBiop (biop, sqdp, fsp);
 
16489
  if (!StringHasNoText (str))
 
16490
  {
 
16491
    FindTextPortionXInString (str, tp, &found_loc, &found_len);
 
16492
    if (found_loc != NULL)
 
16493
    {
 
16494
      parse_src_txt = (CharPtr) MemNew (sizeof (Char) + (found_len + 1));
 
16495
      StringNCpy (parse_src_txt, found_loc, found_len);
 
16496
      parse_src_txt [found_len] = 0;
 
16497
    }
 
16498
  }
 
16499
  str = MemFree (str);
 
16500
  return parse_src_txt;
 
16501
}
 
16502
 
 
16503
 
 
16504
static void 
 
16505
GetSourceQualSourcesForBioseq
 
16506
(BioseqPtr       bsp,
 
16507
 SourceQualDescPtr sqdp,
 
16508
 FilterSetPtr    fsp, 
 
16509
 TextPortionXPtr  tp,
 
16510
 ValNodePtr PNTR source_list)
 
16511
{
 
16512
  SeqDescrPtr        sdp;
 
16513
  SeqFeatPtr         sfp;
 
16514
  SeqMgrFeatContext  fcontext;
 
16515
  SeqMgrDescContext  dcontext;
 
16516
  ParseSourceInfoPtr psip;
 
16517
  CharPtr            parse_src_txt;
 
16518
  BioSourcePtr       biop;
 
16519
  
 
16520
  if (bsp == NULL || source_list == NULL)
 
16521
  {
 
16522
    return;
 
16523
  }
 
16524
  
 
16525
  sdp = SeqMgrGetNextDescriptor (bsp, NULL, Seq_descr_source, &dcontext);
 
16526
  while (sdp != NULL)
 
16527
  {
 
16528
    if ((biop = sdp->data.ptrvalue) != NULL
 
16529
        && (parse_src_txt = GetSourceQualSourceTextForBioSource (biop, sqdp, fsp, tp)) != NULL) 
 
16530
    {      
 
16531
      psip = (ParseSourceInfoPtr) MemNew (sizeof (ParseSourceInfoData));
 
16532
      if (psip != NULL)
 
16533
      {
 
16534
        psip->bsp = bsp;
 
16535
        psip->sdp = sdp;
 
16536
        psip->sfp = NULL;
 
16537
        psip->sip = NULL;
 
16538
        psip->dest_list = NULL;
 
16539
        psip->parse_src_txt = parse_src_txt;
 
16540
        ValNodeAddPointer (source_list, 0, psip);
 
16541
      }
 
16542
      else
 
16543
      {
 
16544
        parse_src_txt = MemFree (parse_src_txt);
 
16545
      }
 
16546
    }
 
16547
    sdp = SeqMgrGetNextDescriptor (bsp, sdp, Seq_descr_source, &dcontext);
 
16548
  }
 
16549
  
 
16550
  sfp = SeqMgrGetNextFeature (bsp, NULL, SEQFEAT_BIOSRC, 0, &fcontext);
 
16551
  while (sfp != NULL)
 
16552
  {
 
16553
    if ((biop = sfp->data.value.ptrvalue) != NULL
 
16554
        && (parse_src_txt = GetSourceQualSourceTextForBioSource (biop, sqdp, fsp, tp)) != NULL) 
 
16555
    {      
 
16556
      psip = (ParseSourceInfoPtr) MemNew (sizeof (ParseSourceInfoData));
 
16557
      if (psip != NULL)
 
16558
      {
 
16559
        psip->bsp = bsp;
 
16560
        psip->sdp = NULL;
 
16561
        psip->sfp = sfp;
 
16562
        psip->sip = NULL;
 
16563
        psip->dest_list = NULL;
 
16564
        psip->parse_src_txt = parse_src_txt;
 
16565
        ValNodeAddPointer (source_list, 0, psip);
 
16566
      }
 
16567
      else
 
16568
      {
 
16569
        parse_src_txt = MemFree (parse_src_txt);
 
16570
      }
 
16571
    }
 
16572
    sfp = SeqMgrGetNextFeature (bsp, sfp, SEQFEAT_BIOSRC, 0, &fcontext);
 
16573
  }    
 
16574
}
 
16575
 
 
16576
 
14165
16577
static void
14166
16578
GetBankitCommentSourcesForBioseq 
14167
16579
(BioseqPtr       bsp,
14168
16580
 FilterSetPtr    fsp, 
14169
 
 TextPortionPtr  tp,
 
16581
 TextPortionXPtr  tp,
14170
16582
 ValNodePtr PNTR source_list)
14171
16583
{
14172
16584
  SeqDescrPtr        sdp;
14202
16614
            {
14203
16615
              if (fsp == NULL
14204
16616
                  || fsp->ccp == NULL
14205
 
                  || DoesStringMatchConstraint (ufp->data.ptrvalue, fsp->ccp->string_constraint))
 
16617
                  || DoesStringMatchConstraintX (ufp->data.ptrvalue, fsp->ccp->string_constraint))
14206
16618
              {
14207
 
                FindTextPortionInString (ufp->data.ptrvalue, tp, &found_loc, &found_len);
 
16619
                FindTextPortionXInString (ufp->data.ptrvalue, tp, &found_loc, &found_len);
14208
16620
                if (found_loc != NULL)
14209
16621
                {
14210
16622
                  parse_src_txt = (CharPtr) MemNew (sizeof (Char) + (found_len + 1));
14241
16653
GetCommentSourcesForBioseq 
14242
16654
(BioseqPtr       bsp,
14243
16655
 FilterSetPtr    fsp, 
14244
 
 TextPortionPtr  tp,
 
16656
 TextPortionXPtr  tp,
14245
16657
 ValNodePtr PNTR source_list)
14246
16658
{
14247
16659
  SeqDescrPtr        sdp;
14262
16674
  {
14263
16675
    if (fsp == NULL
14264
16676
        || fsp->ccp == NULL
14265
 
        || DoesStringMatchConstraint (sdp->data.ptrvalue, fsp->ccp->string_constraint))
 
16677
        || DoesStringMatchConstraintX (sdp->data.ptrvalue, fsp->ccp->string_constraint))
14266
16678
    {
14267
 
      FindTextPortionInString (sdp->data.ptrvalue, tp, &found_loc, &found_len);
 
16679
      FindTextPortionXInString (sdp->data.ptrvalue, tp, &found_loc, &found_len);
14268
16680
      if (found_loc != NULL)
14269
16681
      {
14270
16682
        parse_src_txt = (CharPtr) MemNew (sizeof (Char) + (found_len + 1));
14296
16708
  {
14297
16709
    if (fsp == NULL
14298
16710
        || fsp->ccp == NULL
14299
 
        || DoesStringMatchConstraint (sfp->data.value.ptrvalue, fsp->ccp->string_constraint))
 
16711
        || DoesStringMatchConstraintX (sfp->data.value.ptrvalue, fsp->ccp->string_constraint))
14300
16712
    {
14301
 
      FindTextPortionInString (sdp->data.ptrvalue, tp, &found_loc, &found_len);
 
16713
      FindTextPortionXInString (sdp->data.ptrvalue, tp, &found_loc, &found_len);
14302
16714
      if (found_loc != NULL)
14303
16715
      {
14304
16716
        parse_src_txt = (CharPtr) MemNew (sizeof (Char) + (found_len + 1));
14331
16743
GetStructuredCommentSourcesForBioseq 
14332
16744
(BioseqPtr       bsp,
14333
16745
 FilterSetPtr    fsp, 
14334
 
 TextPortionPtr  tp,
 
16746
 TextPortionXPtr  tp,
14335
16747
 CharPtr         comment_field,
14336
16748
 ValNodePtr PNTR source_list)
14337
16749
{
14364
16776
          if (oip != NULL && StringCmp (oip->str, comment_field) == 0
14365
16777
              && (fsp == NULL
14366
16778
                  || fsp->ccp == NULL
14367
 
                  || DoesStringMatchConstraint (sdp->data.ptrvalue, fsp->ccp->string_constraint)))
 
16779
                  || DoesStringMatchConstraintX (sdp->data.ptrvalue, fsp->ccp->string_constraint)))
14368
16780
          {
14369
 
            FindTextPortionInString (ufp->data.ptrvalue, tp, &found_loc, &found_len);
 
16781
            FindTextPortionXInString (ufp->data.ptrvalue, tp, &found_loc, &found_len);
14370
16782
            if (found_loc != NULL)
14371
16783
            {
14372
16784
              parse_src_txt = (CharPtr) MemNew (sizeof (Char) + (found_len + 1));
14393
16805
        }
14394
16806
      }
14395
16807
    }
14396
 
    sdp = SeqMgrGetNextDescriptor (bsp, sdp, Seq_descr_comment, &dcontext);
 
16808
    sdp = SeqMgrGetNextDescriptor (bsp, sdp, Seq_descr_user, &dcontext);
14397
16809
  }
14398
16810
}
14399
16811
 
14409
16821
  psp = (ParseSourcePtr) userdata;
14410
16822
  switch (psp->src_field)
14411
16823
  {
14412
 
    case PARSE_FIELD_SRC_DEFLINE:
 
16824
    case eParseFieldSrcDefLine:
14413
16825
      if (!ISA_aa (bsp->mol))
14414
16826
      {
14415
16827
        GetDeflineSourcesForBioseq (bsp, psp->fsp, psp->tp, &(psp->source_list));
14416
16828
      }
14417
16829
      break;
14418
 
    case PARSE_FIELD_SRC_LOCAL_ID:
 
16830
    case eParseFieldSrcLocalID:
14419
16831
      if (! ISA_aa (bsp->mol) && bsp->repr != Seq_repr_seg)
14420
16832
      {
14421
16833
        GetLocalIDSourcesForBioseq (bsp, psp->fsp, psp->tp, &(psp->source_list));
14422
16834
      }
14423
16835
      break;
14424
 
    case PARSE_FIELD_SRC_TAXNAME:
14425
 
      GetTaxNameSourcesForBioseq (bsp, psp->fsp, psp->tp, &(psp->source_list));
14426
 
      break;
14427
 
    case PARSE_FIELD_SRC_COMMENT:
 
16836
    case eParseFieldSrcFileID:
 
16837
      GetNcbiFileSourceForBioseq (bsp, psp->fsp, psp->tp, &(psp->source_list));
 
16838
      break;
 
16839
    case eParseFieldSrcTaxName:
 
16840
      if (! ISA_aa (bsp->mol))
 
16841
      {
 
16842
        GetTaxNameSourcesForBioseq (bsp, psp->fsp, psp->tp, &(psp->source_list));
 
16843
      }
 
16844
      break;
 
16845
    case eParseFieldSrcSourceQual:
 
16846
      if (! ISA_aa (bsp->mol))
 
16847
      {
 
16848
        GetSourceQualSourcesForBioseq (bsp, psp->sqdp, psp->fsp, psp->tp, &(psp->source_list));
 
16849
      }
 
16850
      break;
 
16851
    case eParseFieldSrcComment:
14428
16852
      GetCommentSourcesForBioseq (bsp, psp->fsp, psp->tp, &(psp->source_list));
14429
16853
      break;
14430
 
    case PARSE_FIELD_STRUCTURED_COMMENT:
 
16854
    case eParseFieldSrcStructuredComment:
14431
16855
      GetStructuredCommentSourcesForBioseq(bsp, psp->fsp, psp->tp, psp->comment_field, &(psp->source_list));
14432
16856
      break;
14433
 
    case PARSE_FIELD_BANKIT_COMMENT:
14434
 
      GetBankitCommentSourcesForBioseq (bsp, psp->fsp, psp->tp, &(psp->source_list));
 
16857
    case eParseFieldSrcBankitComment:
 
16858
      if (!ISA_aa (bsp->mol))
 
16859
      {
 
16860
        GetBankitCommentSourcesForBioseq (bsp, psp->fsp, psp->tp, &(psp->source_list));
 
16861
      }
 
16862
      break;
 
16863
    case eParseFieldSrcTaxNameAfterNomial:
 
16864
      if (! ISA_aa (bsp->mol))
 
16865
      {
 
16866
        GetTaxNameAfterNomialSourcesForBioseq (bsp, psp->fsp, psp->tp, &(psp->source_list));
 
16867
      }
14435
16868
      break;
14436
16869
  }
14437
16870
}
14438
16871
 
14439
16872
 
14440
 
static void StripFromParsedField (ParseSourceInfoPtr psip, TextPortionPtr tp, Int4 parse_field_type, CharPtr comment_field)
 
16873
static void StripFromParsedField (ParseSourceInfoPtr psip, TextPortionXPtr tp, Int4 parse_field_type, SourceQualDescPtr sqdp, CharPtr comment_field)
14441
16874
{
14442
 
  CharPtr       str_found;
 
16875
  CharPtr       str_found, tmp;
14443
16876
  BioSourcePtr  biop = NULL;
14444
16877
  UserObjectPtr uop;
14445
16878
  ObjectIdPtr   oip;
14446
16879
  UserFieldPtr  ufp;
 
16880
  ApplyValueData avd;
 
16881
  ValNode        vn;
14447
16882
  
14448
16883
  if (psip == NULL || tp == NULL) {
14449
16884
    return;
14450
16885
  }
14451
16886
  switch (parse_field_type) {
14452
 
    case PARSE_FIELD_SRC_DEFLINE:
14453
 
    case PARSE_FIELD_SRC_COMMENT:
 
16887
    case eParseFieldSrcDefLine:
 
16888
    case eParseFieldSrcComment:
14454
16889
      if (psip->sdp != NULL) {
14455
16890
        str_found = ReplaceStringForParse(psip->sdp->data.ptrvalue, tp);
14456
16891
        str_found = MemFree (str_found);
14457
16892
      }
14458
16893
      break;
14459
 
    case PARSE_FIELD_SRC_TAXNAME:
 
16894
    case eParseFieldSrcTaxName:
14460
16895
      if (psip->sdp != NULL) {
14461
16896
        biop = psip->sdp->data.ptrvalue;
14462
16897
      } else if (psip->sfp != NULL) {
14467
16902
        str_found = MemFree (str_found);
14468
16903
      }
14469
16904
      break;
14470
 
    case PARSE_FIELD_STRUCTURED_COMMENT:
 
16905
    case eParseFieldSrcSourceQual:
 
16906
      if (psip->sdp != NULL) {
 
16907
        biop = psip->sdp->data.ptrvalue;
 
16908
      } else if (psip->sfp != NULL) {
 
16909
        biop = psip->sfp->data.value.ptrvalue;
 
16910
      }
 
16911
      if (biop != NULL) {
 
16912
        tmp = GetSourceQualQualValueFromBiop (biop, sqdp, NULL);
 
16913
        str_found = ReplaceStringForParse (tmp, tp);
 
16914
        str_found = MemFree (str_found);
 
16915
        avd.etp = NULL;
 
16916
        vn.choice = 0;
 
16917
        vn.data.ptrvalue = sqdp;
 
16918
        vn.next = NULL;
 
16919
        avd.field_list = &vn;
 
16920
        avd.new_text = tmp;
 
16921
        avd.text_to_replace = NULL;
 
16922
        avd.where_to_replace = EditApplyFindLocation_anywhere;
 
16923
 
 
16924
        ApplySourceQualBioSourceCallback (biop, &avd, NULL);
 
16925
        tmp = MemFree (tmp);
 
16926
      }
 
16927
      break;
 
16928
    case eParseFieldSrcTaxNameAfterNomial:
 
16929
      if (psip->sdp != NULL) {
 
16930
        biop = psip->sdp->data.ptrvalue;
 
16931
      } else if (psip->sfp != NULL) {
 
16932
        biop = psip->sfp->data.value.ptrvalue;
 
16933
      }
 
16934
      if (biop != NULL && biop->org != NULL) {
 
16935
        str_found = GetTextAfterNomial(biop->org->taxname);
 
16936
        str_found = ReplaceStringForParse (str_found, tp);
 
16937
        str_found = MemFree (str_found);
 
16938
      }
 
16939
      break;
 
16940
    case eParseFieldSrcStructuredComment:
14471
16941
      if (psip->sdp != NULL
14472
16942
          && psip->sdp->extended != 0
14473
16943
          && psip->sdp->data.ptrvalue != NULL) {
14487
16957
        }
14488
16958
      }
14489
16959
      break;
14490
 
    case PARSE_FIELD_BANKIT_COMMENT:
 
16960
    case eParseFieldSrcBankitComment:
14491
16961
      if (psip->sdp != NULL
14492
16962
          && psip->sdp->extended != 0
14493
16963
          && psip->sdp->data.ptrvalue != NULL) {
14511
16981
}      
14512
16982
 
14513
16983
 
14514
 
static void GetBioSourceDestinationsForBioseq (BioseqPtr bsp, ValNodePtr PNTR dest_list)
 
16984
static void GetBioSourceDestinationsForBioseq (BioseqPtr bsp, Boolean do_feat, Boolean do_desc, ValNodePtr PNTR dest_list)
14515
16985
{
14516
16986
  SeqDescrPtr        sdp;
14517
16987
  SeqFeatPtr         sfp;
14523
16993
    return;
14524
16994
  }
14525
16995
  
14526
 
  sdp = SeqMgrGetNextDescriptor (bsp, NULL, Seq_descr_source, &dcontext);
14527
 
  while (sdp != NULL)
 
16996
  if (do_desc) 
14528
16997
  {
14529
 
    ValNodeAddPointer (dest_list, 2, sdp);
14530
 
    sdp = SeqMgrGetNextDescriptor (bsp, sdp, Seq_descr_source, &dcontext);
 
16998
    sdp = SeqMgrGetNextDescriptor (bsp, NULL, Seq_descr_source, &dcontext);
 
16999
    while (sdp != NULL)
 
17000
    {
 
17001
      ValNodeAddPointer (dest_list, 2, sdp);
 
17002
      sdp = SeqMgrGetNextDescriptor (bsp, sdp, Seq_descr_source, &dcontext);
 
17003
    }
14531
17004
  }
14532
17005
  
14533
 
  sfp = SeqMgrGetNextFeature (bsp, NULL, SEQFEAT_BIOSRC, 0, &fcontext);
14534
 
  while (sfp != NULL)
 
17006
  if (do_feat)
14535
17007
  {
14536
 
    ValNodeAddPointer (dest_list, 1, sfp);
14537
 
    sfp = SeqMgrGetNextFeature (bsp, sfp, SEQFEAT_BIOSRC, 0, &fcontext);
14538
 
  }  
 
17008
    sfp = SeqMgrGetNextFeature (bsp, NULL, SEQFEAT_BIOSRC, 0, &fcontext);
 
17009
    while (sfp != NULL)
 
17010
    {
 
17011
      ValNodeAddPointer (dest_list, 1, sfp);
 
17012
      sfp = SeqMgrGetNextFeature (bsp, sfp, SEQFEAT_BIOSRC, 0, &fcontext);
 
17013
    }  
 
17014
  }
14539
17015
}
14540
17016
 
14541
17017
static void GetDeflineDestinationsForBioseq (BioseqPtr bsp, ValNodePtr PNTR dest_list)
14580
17056
  SeqFeatPtr         sfp;
14581
17057
  SeqMgrFeatContext  fcontext;
14582
17058
  SeqAnnotPtr        sap;
 
17059
  ProtRefPtr         prp;
14583
17060
 
14584
17061
  if (bsp == NULL || dest_list == NULL)
14585
17062
  {
14587
17064
  }
14588
17065
  
14589
17066
  sfp = SeqMgrGetNextFeature (bsp, NULL, seqFeatChoice, featDefChoice, &fcontext);
14590
 
  while (sfp != NULL)
14591
 
  {
 
17067
  if (sfp == NULL 
 
17068
      && (featDefChoice == FEATDEF_PROT 
 
17069
          || (seqFeatChoice == SEQFEAT_PROT && featDefChoice == 0))) {
 
17070
    sfp = CreateNewFeatureOnBioseq (bsp, SEQFEAT_PROT, NULL);
 
17071
    prp = ProtRefNew ();
 
17072
    sfp->data.value.ptrvalue = prp;
 
17073
        SeqMgrIndexFeatures (bsp->idx.entityID, NULL);    
14592
17074
    ValNodeAddPointer (dest_list, 1, sfp);
14593
 
    sfp = SeqMgrGetNextFeature (bsp, sfp, seqFeatChoice, featDefChoice, &fcontext);
14594
 
  }  
 
17075
  } else {
 
17076
    while (sfp != NULL)
 
17077
    {
 
17078
      ValNodeAddPointer (dest_list, 1, sfp);
 
17079
      sfp = SeqMgrGetNextFeature (bsp, sfp, seqFeatChoice, featDefChoice, &fcontext);
 
17080
    }  
 
17081
  }
14595
17082
  
14596
17083
  sap = bsp->annot;
14597
17084
  while (sap != NULL)
14684
17171
  switch (dst_field_data->parse_field_type)
14685
17172
  {
14686
17173
    case PARSE_FIELD_SOURCE_QUAL:
14687
 
      GetBioSourceDestinationsForBioseq (psip->bsp, &(psip->dest_list));
 
17174
    case PARSE_FIELD_BIOSRC_STRING :
 
17175
    case PARSE_FIELD_DBXREF :
 
17176
      if ((dst_field_data->do_desc && psip->sdp != NULL && psip->sdp->choice == Seq_descr_source) 
 
17177
          || (dst_field_data->do_feat && psip->sfp != NULL && psip->sfp->data.choice == SEQFEAT_BIOSRC))
 
17178
      {
 
17179
        if (dst_field_data->do_desc && psip->sdp != NULL)
 
17180
        {
 
17181
          ValNodeAddPointer (&(psip->dest_list), 2, psip->sdp);
 
17182
        }
 
17183
        if (dst_field_data->do_feat && psip->sfp != NULL)
 
17184
        {
 
17185
          ValNodeAddPointer (&(psip->dest_list), 1, psip->sfp);
 
17186
        }
 
17187
      }
 
17188
      else
 
17189
      {
 
17190
        GetBioSourceDestinationsForBioseq (psip->bsp, dst_field_data->do_feat, dst_field_data->do_desc, &(psip->dest_list));
 
17191
      }
14688
17192
      break;
14689
17193
    case PARSE_FIELD_DEFLINE :
14690
17194
      GetDeflineDestinationsForBioseq (psip->bsp, &(psip->dest_list));
14691
17195
      break;
14692
 
    case PARSE_FIELD_BIOSRC_STRING :
14693
 
      GetBioSourceDestinationsForBioseq (psip->bsp, &(psip->dest_list));
14694
 
      break;
14695
17196
    case PARSE_FIELD_GENE_FIELD :
14696
17197
      GetFeatureDestinationsForBioseq (psip->bsp, SEQFEAT_GENE, 0, &(psip->dest_list));
14697
17198
      break;
14698
 
    case PARSE_FIELD_MRNA_FIELD :
14699
 
      GetFeatureDestinationsForBioseq (psip->bsp, SEQFEAT_RNA, FEATDEF_mRNA, &(psip->dest_list));
 
17199
    case PARSE_FIELD_RNA_FIELD :
 
17200
      GetFeatureDestinationsForBioseq (psip->bsp, SEQFEAT_RNA,
 
17201
                                       dst_field_data->feature_subtype == NULL ? 0 : dst_field_data->feature_subtype->data.intvalue,
 
17202
                                       &(psip->dest_list));
14700
17203
      break;
14701
17204
    case PARSE_FIELD_CDS_COMMENT:
14702
17205
      GetFeatureDestinationsForBioseq (psip->bsp, SEQFEAT_CDREGION, FEATDEF_CDS, &(psip->dest_list));
14710
17213
           vnp = vnp->next)
14711
17214
      {
14712
17215
        GetFeatureDestinationsForBioseq (psip->bsp, 
14713
 
                                         SEQFEAT_IMP, 
14714
 
                                         dst_field_data->parse_field_type, 
 
17216
                                         0, 
 
17217
                                         vnp->choice,
14715
17218
                                         &(psip->dest_list));
14716
17219
      }
14717
17220
      break;    
14985
17488
      gsp->copy_vn_proc = IntValNodeCopy;
14986
17489
      gsp->requested_field = IntValNodeCopy (psp->dst_field_data->feature_field);
14987
17490
      break;
14988
 
    case PARSE_FIELD_MRNA_FIELD:
14989
 
      gsp->fieldstring_func = GetmRNAFieldString;
 
17491
    case PARSE_FIELD_RNA_FIELD:
 
17492
      gsp->fieldstring_func = GetRNAFieldString;
14990
17493
      gsp->copy_vn_proc = IntValNodeCopy;
14991
17494
      gsp->requested_field = IntValNodeCopy (psp->dst_field_data->feature_field);
14992
17495
      break;
15016
17519
      gsp->copy_vn_proc = ValNodeStringCopy;
15017
17520
      gsp->requested_field = ValNodeStringCopy (psp->dst_field_data->feature_field);
15018
17521
      break;
 
17522
    case PARSE_FIELD_DBXREF:
 
17523
      gsp->fieldstring_func = GetBioSourceFeatureDbxrefString;
 
17524
      gsp->descrstring_func = GetBioSourceDescriptorDbxrefString;
 
17525
      gsp->free_vn_proc = ValNodeSimpleDataFree;
 
17526
      gsp->copy_vn_proc = ValNodeStringCopy;
 
17527
      gsp->requested_field = ValNodeStringCopy (psp->dst_field_data->feature_field);
 
17528
      break;
15019
17529
  }
15020
17530
  
15021
17531
  for (vnp = psp->source_list; vnp != NULL; vnp = vnp->next)
15064
17574
    case PARSE_FIELD_GENE_FIELD :
15065
17575
      set_string_func = SetGeneFieldString;
15066
17576
      break;
15067
 
    case PARSE_FIELD_MRNA_FIELD :
15068
 
      set_string_func = SetmRNAFieldString;
 
17577
    case PARSE_FIELD_RNA_FIELD :
 
17578
      set_string_func = SetRNAFieldString;
15069
17579
      break;
15070
17580
    case PARSE_FIELD_CDS_COMMENT:
15071
17581
      set_string_func = SetCDSComment;
15101
17611
      if (prot_bsp == NULL)
15102
17612
      {
15103
17613
        bsp = BioseqFindFromSeqLoc (sfp->location);
15104
 
            SeqEdTranslateOneCDS (sfp, bsp, sfp->idx.entityID);
 
17614
            SeqEdTranslateOneCDS (sfp, bsp, sfp->idx.entityID, Sequin_GlobalAlign2Seq);
15105
17615
            SeqMgrIndexFeatures (sfp->idx.entityID, NULL);
15106
17616
        prot_bsp = BioseqFindFromSeqLoc (sfp->product);
15107
17617
      }
15271
17781
(ParseSourceInfoPtr psip, 
15272
17782
 Int4               src_field,
15273
17783
 ParseFieldPtr      dst_field_data,
15274
 
 TextPortionPtr     tp,
 
17784
 TextPortionXPtr     tp,
15275
17785
 ExistingTextPtr    etp)
15276
17786
{
15277
17787
  ApplyValueData  avd;
15289
17799
  avd.new_text = psip->parse_src_txt;
15290
17800
  avd.etp = etp;
15291
17801
  avd.text_to_replace = NULL;
 
17802
  avd.where_to_replace = EditApplyFindLocation_anywhere;
15292
17803
  
15293
17804
  switch (dst_field_data->parse_field_type)
15294
17805
  {
15316
17827
#endif      
15317
17828
      break;
15318
17829
    case PARSE_FIELD_GENE_FIELD :
15319
 
    case PARSE_FIELD_MRNA_FIELD :
 
17830
    case PARSE_FIELD_RNA_FIELD :
15320
17831
    case PARSE_FIELD_CDS_COMMENT:
15321
17832
    case PARSE_FIELD_PROTEIN_FIELD:
15322
17833
    case PARSE_FIELD_IMPORT_QUAL :
15323
17834
    case PARSE_FIELD_FEATURE_NOTE :
15324
17835
      avd.field_list = dst_field_data->feature_field;
15325
17836
      break;
 
17837
    case PARSE_FIELD_DBXREF :
 
17838
      avd.field_list = dst_field_data->feature_field;
 
17839
      feature_action = ApplyBioSourceDbxrefFeatureCallback;
 
17840
      descriptor_action = ApplyBioSourceDbxrefDescriptorCallback;
 
17841
      break;
15326
17842
  }
15327
17843
  
15328
17844
  for (dest_vnp = psip->dest_list; dest_vnp != NULL; dest_vnp = dest_vnp->next)
15337
17853
    }
15338
17854
    else if (dest_vnp->choice == 1 
15339
17855
             && (dst_field_data->parse_field_type == PARSE_FIELD_GENE_FIELD
15340
 
                 || dst_field_data->parse_field_type == PARSE_FIELD_MRNA_FIELD
 
17856
                 || dst_field_data->parse_field_type == PARSE_FIELD_RNA_FIELD
15341
17857
                 || dst_field_data->parse_field_type == PARSE_FIELD_CDS_COMMENT
15342
17858
                 || dst_field_data->parse_field_type == PARSE_FIELD_PROTEIN_FIELD
15343
17859
                 || dst_field_data->parse_field_type == PARSE_FIELD_IMPORT_QUAL
15354
17870
FindParseActionPairList 
15355
17871
(SeqEntryPtr   sep, 
15356
17872
 Int4          src_field,
 
17873
 SourceQualDescPtr sqdp,
15357
17874
 CharPtr       comment_field,
15358
17875
 ParseFieldPtr dst_field_data,
15359
17876
 FilterSetPtr  fsp,
15360
 
 TextPortionPtr tp,
15361
 
 Boolean        remove_from_parsed)
 
17877
 TextPortionXPtr tp,
 
17878
 Boolean        remove_from_parsed,
 
17879
 ChangeCasePtr  ccp)
15362
17880
{
15363
17881
  ParseSourceData    psd;
15364
17882
  ValNodePtr         vnp;
15367
17885
  ExistingTextPtr    etp;
15368
17886
  Boolean            rval = FALSE;
15369
17887
  ValNodePtr         source_list_for_removal = NULL;
 
17888
  ValNodePtr         orgnames = NULL;
15370
17889
  
15371
17890
  psd.fsp = fsp;
15372
17891
  psd.source_list = NULL;
15373
17892
  psd.src_field = src_field;
15374
17893
  psd.comment_field = comment_field;
 
17894
  psd.sqdp = sqdp;
15375
17895
  psd.dst_field_data = dst_field_data;
15376
17896
  psd.fsp = fsp;
15377
17897
  psd.tp = tp;
15379
17899
  /* first, we need to get a list of the parse sources */
15380
17900
  VisitBioseqsInSep (sep, &psd, FindParseSourceBioseqCallback);
15381
17901
  
 
17902
  if (ccp != NULL && ccp->change != eChangeCaseNone) {
 
17903
    /* if we will be fixing capitalization, get org names to use in fixes */
 
17904
    VisitBioSourcesInSep (sep, &orgnames, GetOrgNamesInRecordCallback);
 
17905
  }
 
17906
 
15382
17907
  /* for each parse source, we need to get a list of the destinations */
15383
17908
  for (vnp = psd.source_list; vnp != NULL; vnp = vnp->next)
15384
17909
  {
15387
17912
    if (remove_from_parsed) {
15388
17913
        ValNodeAddPointer (&source_list_for_removal, 0, ParseSourceInfoCopy (psip));
15389
17914
    }
 
17915
    /* fix source text */
 
17916
    ChangeCase (&(psip->parse_src_txt), ccp, orgnames);
 
17917
 
15390
17918
    FindDestinationsForParseSourceInfo (psip, dst_field_data);    
15391
17919
  }
15392
17920
 
15406
17934
  
15407
17935
  /* check for existing text */
15408
17936
  gsp = CheckParseActionPairListForExistingText (&psd);
15409
 
  etp = GetExistingTextHandlerInfo (gsp, FALSE);
 
17937
  etp = GetExistingTextHandlerInfo (gsp == NULL ? 0 : gsp->num_found, FALSE);
15410
17938
  gsp = GetSampleFree (gsp);  
15411
17939
  
15412
 
  if (etp == NULL || etp->existing_text_choice != EXISTING_TEXT_CHOICE_CANCEL)
 
17940
  if (etp == NULL || etp->existing_text_choice != eExistingTextChoiceCancel)
15413
17941
  {
15414
17942
    if (dst_field_data->parse_field_type == PARSE_FIELD_SOURCE_QUAL)
15415
17943
    {
15429
17957
    {
15430
17958
      if (vnp->data.ptrvalue == NULL) continue;
15431
17959
      psip = (ParseSourceInfoPtr) vnp->data.ptrvalue;
15432
 
      StripFromParsedField (psip, tp, src_field, comment_field);      
 
17960
      StripFromParsedField (psip, tp, src_field, sqdp, comment_field);      
15433
17961
    }      
15434
17962
    
15435
17963
    rval = TRUE;
15436
17964
  }
15437
17965
  
15438
17966
  etp = MemFree (etp);
15439
 
  
 
17967
 
 
17968
  /* free orgname list if we created it */
 
17969
  orgnames = ValNodeFree (orgnames);
 
17970
 
 
17971
  comment_field = MemFree (comment_field);
 
17972
  sqdp = MemFree (sqdp);
 
17973
 
15440
17974
  psd.source_list = ParseSourceListFree (psd.source_list);
15441
17975
  source_list_for_removal = ParseSourceListFree (source_list_for_removal);
15442
17976
  return rval;
15443
17977
}
15444
17978
 
15445
 
static void 
15446
 
VisitSeqEntriesForParseAction 
15447
 
(SeqEntryPtr sep,
15448
 
 ParseActionPtr pap,
15449
 
 ParseActnProc   parse_action,
15450
 
 Pointer        parse_data,
15451
 
 Boolean        ok_to_parse)
15452
 
{
15453
 
  SeqDescrPtr       sdp, sdp_tmp;
15454
 
  SeqAnnotPtr       sap, sap_tmp;
15455
 
  SeqFeatPtr        sfp;
15456
 
  ParseActionOpData paod;
15457
 
  BioseqSetPtr      bssp = NULL;
15458
 
  
15459
 
  SeqEntryPtr       old_title_sep;
15460
 
  SeqEntryPtr       old_biop_sep;
15461
 
  
15462
 
  if (sep == NULL || pap == NULL || parse_action == NULL) 
15463
 
  {
15464
 
    return;
15465
 
  }
15466
 
  
15467
 
  paod.parse_action_data = pap;
15468
 
  paod.parse_action = parse_action;
15469
 
  paod.parse_userdata = parse_data;
15470
 
  paod.parse_complete = FALSE;
15471
 
  
15472
 
  pap->sep = sep;
15473
 
  if (IS_Bioseq (pap->sep))
15474
 
  {
15475
 
    pap->bsp = (BioseqPtr) pap->sep->data.ptrvalue;
15476
 
    sdp = pap->bsp->descr;
15477
 
    sap = pap->bsp->annot;
15478
 
  }
15479
 
  else if (IS_Bioseq_set (sep))
15480
 
  {
15481
 
    bssp = (BioseqSetPtr) sep->data.ptrvalue;
15482
 
    pap->bssp = bssp;
15483
 
    sdp = pap->bssp->descr;
15484
 
    sap = pap->bssp->annot;
15485
 
  }
15486
 
  
15487
 
  old_title_sep = pap->title_sep;
15488
 
  old_biop_sep = pap->biop_sep;
15489
 
  
15490
 
  if (pap->fsp != NULL
15491
 
      && pap->fsp->ccp != NULL 
15492
 
      && pap->fsp->ccp->constraint_type != CHOICE_CONSTRAINT_ANY)
15493
 
  {
15494
 
    ok_to_parse = FALSE;
15495
 
    /* try to find BioSource descriptor to match source constraint */
15496
 
    sdp_tmp = sdp;
15497
 
    while (sdp_tmp != NULL && ! ok_to_parse)
15498
 
    {
15499
 
      if (sdp_tmp->choice == Seq_descr_source)
15500
 
      {
15501
 
        if (DoesOneSourceMatchConstraint (sdp_tmp->data.ptrvalue, pap->fsp->ccp))
15502
 
        {
15503
 
          ok_to_parse = TRUE;
15504
 
        }
15505
 
      }
15506
 
      sdp_tmp = sdp_tmp->next;
15507
 
    }
15508
 
    /* try to find BioSource feature to match source constraint */
15509
 
    sap_tmp = sap;
15510
 
    while (sap_tmp != NULL && ! ok_to_parse)
15511
 
    {
15512
 
      if (sap_tmp->type == 1)
15513
 
      {
15514
 
        sfp = (SeqFeatPtr) sap_tmp->data;
15515
 
        while (sfp != NULL && !ok_to_parse)
15516
 
        {
15517
 
          if (sfp->data.choice == SEQFEAT_BIOSRC)
15518
 
          {
15519
 
            if (DoesOneSourceMatchConstraint (sfp->data.value.ptrvalue, pap->fsp->ccp))
15520
 
            {
15521
 
              ok_to_parse = TRUE;
15522
 
            }
15523
 
          }
15524
 
          sfp = sfp->next;
15525
 
        }
15526
 
      }
15527
 
      sap_tmp = sap_tmp->next;
15528
 
    }
15529
 
  }
15530
 
  else
15531
 
  {
15532
 
    ok_to_parse = TRUE;
15533
 
  }
15534
 
  if (ok_to_parse)
15535
 
  {
15536
 
    SetSourceAndTitle (pap, sdp, sap);
15537
 
    if (pap->biop_sep != old_biop_sep)
15538
 
    {
15539
 
      sdp_tmp = sdp;
15540
 
      while (sdp_tmp != NULL)
15541
 
      {
15542
 
        if (sdp_tmp->choice == Seq_descr_source)
15543
 
        {
15544
 
          ParseFromSource (sdp_tmp->data.ptrvalue, pap, &paod);
15545
 
        }
15546
 
        sdp_tmp = sdp_tmp->next;
15547
 
      }
15548
 
      sap_tmp = sap;
15549
 
      while (sap_tmp != NULL)
15550
 
      {
15551
 
        if (sap_tmp->type == 1)
15552
 
        {
15553
 
          sfp = sap_tmp->data;
15554
 
          while (sfp != NULL)
15555
 
          {
15556
 
            if (sfp->data.choice == SEQFEAT_BIOSRC)
15557
 
            {
15558
 
              ParseFromSource (sfp->data.value.ptrvalue, pap, &paod);
15559
 
            }
15560
 
            sfp = sfp->next;
15561
 
          }
15562
 
        }
15563
 
        sap_tmp = sap_tmp->next;
15564
 
      }
15565
 
    }
15566
 
    if (pap->title_sep != old_title_sep 
15567
 
        && pap->src_field == PARSE_FIELD_SRC_DEFLINE)
15568
 
    {
15569
 
      sdp_tmp = sdp;
15570
 
      while (sdp_tmp != NULL)
15571
 
      {
15572
 
        if (sdp_tmp->choice == Seq_descr_title)
15573
 
        {
15574
 
          ParseActionDeflineText (sdp_tmp, &paod);
15575
 
        }
15576
 
        sdp_tmp = sdp_tmp->next;
15577
 
      }
15578
 
    }
15579
 
      
15580
 
    if (pap->src_field == PARSE_FIELD_SRC_LOCAL_ID && IS_Bioseq (sep))
15581
 
    {
15582
 
      if (pap->biop_sep == NULL)
15583
 
      {
15584
 
        pap->biop_sep = sep;
15585
 
      }
15586
 
      if (pap->title_sep == NULL)
15587
 
      {
15588
 
        pap->title_sep = sep;
15589
 
      }
15590
 
      ParseActionLocalIDText (sep->data.ptrvalue, &paod);
15591
 
    }
15592
 
    if (pap->src_field == PARSE_FIELD_SRC_COMMENT)
15593
 
    {
15594
 
      sdp_tmp = sdp;
15595
 
      while (sdp_tmp != NULL)
15596
 
      {
15597
 
        ParseActionCommentDescriptor (sdp_tmp, &paod);
15598
 
        sdp_tmp = sdp_tmp->next;
15599
 
      }
15600
 
      
15601
 
      sap_tmp = sap;
15602
 
      while (sap_tmp != NULL)
15603
 
      {
15604
 
        if (sap_tmp->type == 1)
15605
 
        {
15606
 
          sfp = sap_tmp->data;
15607
 
          while (sfp != NULL)
15608
 
          {
15609
 
            ParseActionCommentFeature (sfp, &paod);
15610
 
            sfp = sfp->next;
15611
 
          }
15612
 
        }
15613
 
        sap_tmp = sap_tmp->next;
15614
 
      }
15615
 
    }
15616
 
    if (pap->src_field == PARSE_FIELD_BANKIT_COMMENT)
15617
 
    {
15618
 
      sdp_tmp = sdp;
15619
 
      while (sdp_tmp != NULL)
15620
 
      {
15621
 
        ParseActionBankitComment (sdp_tmp, &paod);
15622
 
        sdp_tmp = sdp_tmp->next;
15623
 
      }      
15624
 
    }
15625
 
  }
15626
 
  
15627
 
  if (bssp != NULL && !paod.parse_complete)
15628
 
  {
15629
 
    VisitSeqEntriesForParseAction (bssp->seq_set, pap, parse_action, parse_data, ok_to_parse);
15630
 
  }
15631
 
 
15632
 
  pap->title_sep = old_title_sep;
15633
 
  pap->biop_sep = old_biop_sep;
15634
 
  
15635
 
  VisitSeqEntriesForParseAction (sep->next, pap, parse_action, parse_data, ok_to_parse);
15636
 
}
15637
 
 
15638
 
typedef struct parseactionlog 
15639
 
{
15640
 
  FILE    *fp;
15641
 
  Boolean data_in_log;
15642
 
} ParseActionLogData, PNTR ParseActionLogPtr;
15643
 
 
15644
 
static void  ParseActionSample (ParseActionPtr pap, Pointer userdata, CharPtr found_text, Int4 found_len)
15645
 
{
15646
 
  CharPtr           log_text;
15647
 
  ParseActionLogPtr palp;
15648
 
  
15649
 
  palp = (ParseActionLogPtr) userdata;
15650
 
  if (palp == NULL || found_len == 0 || found_text == NULL || palp->fp == NULL)
15651
 
  {
15652
 
    return;
15653
 
  }
15654
 
  
15655
 
  log_text = (CharPtr) MemNew ((found_len + 1) * sizeof (Char));
15656
 
  if (log_text != NULL)
15657
 
  {
15658
 
    StringNCpy (log_text, found_text, found_len);
15659
 
    log_text[found_len] = 0;
15660
 
    fprintf (palp->fp, "%s\n", log_text);
15661
 
    palp->data_in_log = TRUE;
15662
 
    MemFree (log_text);
15663
 
  }
15664
 
}
 
17979
typedef ValNodePtr (*AdjustConvertFeatureListFunc) PROTO ((ValNodePtr, Pointer, BaseFormPtr, BoolPtr cancel));
 
17980
typedef Pointer (*CollectConvertFeatureOptionsFunc) PROTO ((ValNodePtr, BaseFormPtr, BoolPtr cancel));
 
17981
typedef Pointer (*FreeConvertFeatureOptionsFunc) PROTO ((Pointer));
 
17982
typedef Boolean (*ConvertFeatureTypeFunc) PROTO ((SeqFeatPtr, Uint2, Pointer));
 
17983
typedef void (*ConversionCleanupFunc) PROTO ((Uint2, Pointer));
 
17984
 
 
17985
typedef struct convertfeatureprocs {
 
17986
  Uint2 seqfeat_from;
 
17987
  Uint2 featdef_from;
 
17988
  Uint2 seqfeat_to;
 
17989
  Uint2 featdef_to;
 
17990
  AdjustConvertFeatureListFunc adjust_features;
 
17991
  CollectConvertFeatureOptionsFunc collect_options;
 
17992
  FreeConvertFeatureOptionsFunc    free_options;
 
17993
  ConvertFeatureTypeFunc           convert_func;
 
17994
  ConversionCleanupFunc            cleanup_func;
 
17995
  CharPtr                          help_text;
 
17996
} ConvertFeatureProcsData, PNTR ConvertFeatureProcsPtr;
 
17997
 
 
17998
static Pointer SimpleOptsFree (Pointer);
 
17999
static Boolean ConvertCDSToRNA (SeqFeatPtr, Uint2 featdef_to, Pointer extradata);
 
18000
static Boolean ConvertGeneToRNA (SeqFeatPtr, Uint2 featdef_to, Pointer extradata);
 
18001
static ValNodePtr AdjustConvertFeaturesForBioSrcToRepeatRegion (ValNodePtr feat_list, Pointer extradata, BaseFormPtr bfp, BoolPtr cancel);
 
18002
static Boolean ConvertBioSrcToRepeatRegion (SeqFeatPtr, Uint2 featdef_to, Pointer extradata);
 
18003
static ValNodePtr AdjustCDSToMiscFeatList (ValNodePtr feat_list, Pointer extradata, BaseFormPtr bfp, BoolPtr cancel);
 
18004
static Pointer GetCDSConversionOpts (ValNodePtr feat_list, BaseFormPtr bfp, BoolPtr cancel);
 
18005
static Boolean CDSToMiscFeatConvertFunc (SeqFeatPtr, Uint2 featdef_to, Pointer extradata);
 
18006
static void CDSToMiscFeatConversionCleanup (Uint2 entityID, Pointer extradata);
 
18007
static Boolean ConvertImpToProt (SeqFeatPtr, Uint2 featdef_to, Pointer extradata);
 
18008
static Boolean ConvertProtToImp (SeqFeatPtr, Uint2 featdef_to, Pointer extradata);
 
18009
static Boolean ConvertImpToSpecialRNA (SeqFeatPtr, Uint2 featdef_to, Pointer extradata);
 
18010
static Boolean ConvertRegionToImp (SeqFeatPtr, Uint2 featdef_to, Pointer extradata);
 
18011
static Boolean ConvertRegionToRNA (SeqFeatPtr, Uint2 featdef_to, Pointer extradata);
 
18012
static Boolean ConvertImpToRNA (SeqFeatPtr, Uint2 featdef_to, Pointer extradata);
 
18013
static Boolean ConvertCommentToMiscFeat (SeqFeatPtr, Uint2 featdef_to, Pointer extradata);
 
18014
static Boolean ConvertGeneToMiscFeat (SeqFeatPtr, Uint2 featdef_to, Pointer extradata);
 
18015
static Boolean ConvertRNAToMiscFeat (SeqFeatPtr, Uint2 featdef_to, Pointer extradata);
 
18016
static Boolean ConvertSiteToMiscFeat (SeqFeatPtr, Uint2 featdef_to, Pointer extradata);
 
18017
static Boolean ConvertProtToRegion (SeqFeatPtr, Uint2 featdef_to, Pointer extradata);
 
18018
static Boolean ConvertRegionToProt (SeqFeatPtr, Uint2 featdef_to, Pointer extradata);
 
18019
static Pointer GetBondOpts (ValNodePtr feat_list, BaseFormPtr bfp, BoolPtr cancel);
 
18020
static Pointer GetSiteOpts (ValNodePtr feat_list, BaseFormPtr bfp, BoolPtr cancel);
 
18021
static Boolean ConvertToSiteOrBond (SeqFeatPtr, Uint2 featdef_to, Pointer extradata);
 
18022
static Pointer GetRegionOpts (ValNodePtr feat_list, BaseFormPtr bfp, BoolPtr cancel);
 
18023
static ValNodePtr AdjustRegionConversionFeatures (ValNodePtr feat_list, Pointer extradata, BaseFormPtr bfp, BoolPtr cancel);
 
18024
static Boolean ConvertAnyToRegion (SeqFeatPtr, Uint2 featdef_to, Pointer extradata);
 
18025
static Boolean ConvertImpToImp (SeqFeatPtr, Uint2 featdef_to, Pointer extradata);
 
18026
static Boolean ConvertRNAToRNA (SeqFeatPtr, Uint2 featdef_to, Pointer extradata);
 
18027
static Boolean ConvertProtToProt (SeqFeatPtr, Uint2 featdef_to, Pointer extradata);
 
18028
 
 
18029
 
 
18030
static ConvertFeatureProcsData ConvertFeaturesTable[] = {
 
18031
  { SEQFEAT_CDREGION, FEATDEF_CDS,                SEQFEAT_RNA,    FEATDEF_ANY,
 
18032
        NULL,  GetCDSConversionOpts, SimpleOptsFree, ConvertCDSToRNA, NULL, 
 
18033
        "Delete protein product sequence.\nClear product field if transcript ID removal was requested.\nIf converting to tRNA and anticodon value can be parsed from label, set aa value, and add any text that could not be parsed into an anticodon value to the feature note.\nIf converting to other RNA, put label in RNA product." },
 
18034
  { SEQFEAT_GENE,     FEATDEF_GENE,               SEQFEAT_RNA,    FEATDEF_ANY,
 
18035
        NULL,  NULL,                   NULL,           ConvertGeneToRNA, NULL,
 
18036
        "If converting to tRNA and anticodon value can be parsed from label, set aa value, and add any text that could not be parsed into an anticodon value to the feature note.  If converting to other RNA, put label in RNA product.  Also append gene locus, allele, description, map location, and locus tag to comment (as long as these values are not already in the label and therefore in the RNA product)." },
 
18037
  { SEQFEAT_BIOSRC,   FEATDEF_BIOSRC,             SEQFEAT_IMP,    FEATDEF_repeat_region, 
 
18038
       AdjustConvertFeaturesForBioSrcToRepeatRegion, NULL, NULL, ConvertBioSrcToRepeatRegion, NULL,
 
18039
        "Creates a repeat_region with mobile_element qualifiers for the transposon and/or insertion sequence qualifiers on the BioSource.  All other BioSource information is discarded." },
 
18040
  { SEQFEAT_CDREGION, FEATDEF_CDS,                SEQFEAT_IMP,    FEATDEF_misc_feature, 
 
18041
       AdjustCDSToMiscFeatList, GetCDSConversionOpts, SimpleOptsFree, CDSToMiscFeatConvertFunc, CDSToMiscFeatConversionCleanup,
 
18042
       "Copy comment from coding region to new misc_feature and remove product field.  If not pseudo coding region, add product name from protein feature to new misc_feature comment and delete product sequence." },
 
18043
  { SEQFEAT_IMP,      FEATDEF_ANY,                SEQFEAT_PROT,   FEATDEF_ANY, 
 
18044
       NULL, NULL, NULL, ConvertImpToProt, NULL,
 
18045
       "Original feature must be on nucleotide sequence and be contained in coding region location.  Coding region must have product protein sequence.  New feature is created on product protein sequence so that the translated location will be as close as possible to the original nucleotide location (may not be exact because of codon boundaries)." },
 
18046
  { SEQFEAT_PROT,     FEATDEF_mat_peptide_aa,     SEQFEAT_IMP,    FEATDEF_ANY,
 
18047
       NULL, NULL, NULL, ConvertProtToImp, NULL,
 
18048
       "Original feature must be on a protein sequence that is a product of a coding region.\nNew feature will be created on same sequence as coding region.\n"
 
18049
       "If protein feature has name, this will be saved as /product qualifier on new feature.\nIf protein feature does not have name but does have description, this will be saved as /product qualifier on new feature.\n"
 
18050
       "EC_number values from the protein feature will be saved as /EC_number qualifiers on the new feature.\nActivity values will be saved as /function qualifiers on the new feature.\n"
 
18051
       "Db_xref values from the protein feature will be saved as /db_xref qualifers on the new feature." },
 
18052
  { SEQFEAT_PROT,     FEATDEF_sig_peptide_aa,     SEQFEAT_IMP,    FEATDEF_ANY,
 
18053
       NULL, NULL, NULL, ConvertProtToImp, NULL,
 
18054
       "Original feature must be on a protein sequence that is a product of a coding region.\nNew feature will be created on same sequence as coding region.\n"
 
18055
       "If protein feature has name, this will be saved as /product qualifier on new feature.\nIf protein feature does not have name but does have description, this will be saved as /product qualifier on new feature.\n"
 
18056
       "EC_number values from the protein feature will be saved as /EC_number qualifiers on the new feature.\nActivity values will be saved as /function qualifiers on the new feature.\n"
 
18057
       "Db_xref values from the protein feature will be saved as /db_xref qualifers on the new feature." },
 
18058
  { SEQFEAT_PROT,     FEATDEF_transit_peptide_aa, SEQFEAT_IMP,    FEATDEF_ANY,
 
18059
       NULL, NULL, NULL, ConvertProtToImp, NULL,
 
18060
       "Original feature must be on a protein sequence that is a product of a coding region.\nNew feature will be created on same sequence as coding region.\n"
 
18061
       "If protein feature has name, this will be saved as /product qualifier on new feature.\nIf protein feature does not have name but does have description, this will be saved as /product qualifier on new feature.\n"
 
18062
       "EC_number values from the protein feature will be saved as /EC_number qualifiers on the new feature.\nActivity values will be saved as /function qualifiers on the new feature.\n"
 
18063
       "Db_xref values from the protein feature will be saved as /db_xref qualifers on the new feature." },
 
18064
  { SEQFEAT_IMP,      FEATDEF_ANY,                SEQFEAT_RNA,    FEATDEF_misc_RNA,
 
18065
       NULL, NULL, NULL, ConvertImpToSpecialRNA, NULL,
 
18066
       "Creates a misc_RNA.  Import feature key is discarded." },
 
18067
  { SEQFEAT_IMP,      FEATDEF_ANY,                SEQFEAT_RNA,    FEATDEF_precursor_RNA,
 
18068
       NULL, NULL, NULL, ConvertImpToSpecialRNA, NULL,
 
18069
       "Creates a precursor RNA.  Import feature key is discarded." },
 
18070
  { SEQFEAT_REGION,   FEATDEF_REGION,             SEQFEAT_IMP,    FEATDEF_ANY,
 
18071
       NULL, NULL, NULL, ConvertRegionToImp, NULL,
 
18072
       "Creates a misc_feature with the region name saved as a /note qualifier." },
 
18073
  { SEQFEAT_REGION,   FEATDEF_REGION,             SEQFEAT_RNA,    FEATDEF_misc_RNA,
 
18074
       NULL, NULL, NULL, ConvertRegionToRNA, NULL,
 
18075
       "Creates a misc_RNA feature with the region name as the product name." },
 
18076
  { SEQFEAT_REGION,   FEATDEF_REGION,             SEQFEAT_RNA,    FEATDEF_precursor_RNA,
 
18077
       NULL, NULL, NULL, ConvertRegionToRNA, NULL,
 
18078
       "Creates a precursor RNA feature with the region name as the product name." },
 
18079
  { SEQFEAT_IMP,      FEATDEF_ANY,                SEQFEAT_RNA,    FEATDEF_ANY,
 
18080
       NULL, NULL, NULL, ConvertImpToRNA, NULL,
 
18081
       "Creates an RNA feature of the specified type." },
 
18082
  { SEQFEAT_COMMENT,  FEATDEF_ANY,                SEQFEAT_IMP,    FEATDEF_misc_feature,
 
18083
       NULL, NULL, NULL, ConvertCommentToMiscFeat, NULL,
 
18084
       "Creates a misc_feature with the same note as the original.  Note � the flatfile display for the feature is the same." },
 
18085
  { SEQFEAT_GENE,     FEATDEF_GENE,               SEQFEAT_IMP,    FEATDEF_misc_feature,
 
18086
       NULL, NULL, NULL, ConvertGeneToMiscFeat, NULL,
 
18087
       "Creates a misc_feature with the gene description and locus prepended to the original comment, separated by semicolons." },
 
18088
  { SEQFEAT_RNA,      FEATDEF_ANY,                SEQFEAT_IMP,    FEATDEF_misc_feature,
 
18089
       NULL, NULL, NULL, ConvertRNAToMiscFeat, NULL,
 
18090
       "Creates a misc_feature and adds the RNA product name to the comment." } ,
 
18091
  { SEQFEAT_SITE,     FEATDEF_ANY,                SEQFEAT_IMP,    FEATDEF_misc_feature,
 
18092
       NULL, NULL, NULL, ConvertSiteToMiscFeat, NULL,
 
18093
       "Creates a misc_feature with the site type name as a /note qualifier." } ,
 
18094
  { SEQFEAT_PROT,     FEATDEF_mat_peptide_aa,     SEQFEAT_REGION, FEATDEF_REGION,
 
18095
       NULL, NULL, NULL, ConvertProtToRegion, NULL,
 
18096
       "Creates a Region feature with the protein name as the region name." },
 
18097
  { SEQFEAT_PROT,     FEATDEF_sig_peptide_aa,     SEQFEAT_REGION, FEATDEF_REGION,
 
18098
       NULL, NULL, NULL, ConvertProtToRegion, NULL,
 
18099
       "Creates a Region feature with the protein name as the region name." },
 
18100
  { SEQFEAT_PROT,     FEATDEF_transit_peptide_aa, SEQFEAT_REGION, FEATDEF_REGION,
 
18101
       NULL, NULL, NULL, ConvertProtToRegion, NULL,
 
18102
       "Creates a Region feature with the protein name as the region name." },
 
18103
  { SEQFEAT_REGION,   FEATDEF_REGION,             SEQFEAT_PROT,   FEATDEF_mat_peptide_aa,
 
18104
       NULL, NULL, NULL, ConvertRegionToProt, NULL,
 
18105
       "If feature is on nucleotide sequence, will create feature on protein product sequence for overlapping coding region.  Protein name will be region name." },
 
18106
  { SEQFEAT_REGION,   FEATDEF_REGION,             SEQFEAT_PROT,   FEATDEF_sig_peptide_aa,
 
18107
       NULL, NULL, NULL, ConvertRegionToProt, NULL,
 
18108
       "If feature is on nucleotide sequence, will create feature on protein product sequence for overlapping coding region.  Protein name will be region name." },
 
18109
  { SEQFEAT_REGION,   FEATDEF_REGION,             SEQFEAT_PROT,   FEATDEF_transit_peptide_aa,
 
18110
       NULL, NULL, NULL, ConvertRegionToProt, NULL,
 
18111
       "If feature is on nucleotide sequence, will create feature on protein product sequence for overlapping coding region.  Protein name will be region name." },
 
18112
  { SEQFEAT_REGION,   FEATDEF_REGION,             SEQFEAT_PROT,   FEATDEF_preprotein,
 
18113
       NULL, NULL, NULL, ConvertRegionToProt, NULL,
 
18114
       "If feature is on nucleotide sequence, will create feature on protein product sequence for overlapping coding region.  Protein name will be region name." },
 
18115
  { 0,                FEATDEF_ANY,                SEQFEAT_BOND,    FEATDEF_BOND,
 
18116
       NULL, GetBondOpts, SimpleOptsFree, ConvertToSiteOrBond, NULL,
 
18117
       "Create Bond feature with specified bond type.  Location is a SeqLocBond with a point at the start of the original location and a point at the end of the original location.  All feature ID, partialness, except, comment, product, location, genbank qualifiers, title, citation, experimental evidence, gene xrefs, db xrefs, and pseudo-ness information is discarded." },
 
18118
  { 0,                FEATDEF_ANY,                SEQFEAT_SITE,    FEATDEF_SITE,
 
18119
       NULL, GetSiteOpts, SimpleOptsFree, ConvertToSiteOrBond, NULL,
 
18120
       "Create Site feature with specified site type.  All feature ID, partialness, except, comment, product, location, genbank qualifiers, title, citation, experimental evidence, gene xrefs, db xrefs, and pseudo-ness information is discarded." },
 
18121
  { 0,                FEATDEF_ANY,                SEQFEAT_REGION,    FEATDEF_REGION,
 
18122
       AdjustRegionConversionFeatures, GetRegionOpts, SimpleOptsFree, ConvertAnyToRegion, NULL,
 
18123
       "Create Region feature on nucleotide sequence or protein product sequence of overlapping coding region as specified.  Use comment on feature for region name.\n"
 
18124
       "All feature ID, partialness, except, comment, product, location, genbank qualifiers, title, citation, experimental evidence, gene xrefs, db xrefs, and pseudo-ness information is discarded." },
 
18125
  { SEQFEAT_IMP,      FEATDEF_ANY,                SEQFEAT_IMP,    FEATDEF_ANY,
 
18126
       NULL, NULL, NULL, ConvertImpToImp, NULL,
 
18127
       "Changes type of import feature." },
 
18128
  { SEQFEAT_RNA,      FEATDEF_ANY,                SEQFEAT_RNA,    FEATDEF_ANY,
 
18129
       NULL, NULL, NULL, ConvertRNAToRNA, NULL,
 
18130
       "Changes type of RNA feature." },
 
18131
  { SEQFEAT_PROT,     FEATDEF_ANY,                SEQFEAT_PROT,   FEATDEF_ANY,
 
18132
       NULL, NULL, NULL, ConvertProtToProt, NULL,
 
18133
       "Changes type of protein feature." },
 
18134
};
 
18135
 
 
18136
static Int4 num_convert_feature_table_lines = sizeof (ConvertFeaturesTable) / sizeof (ConvertFeatureProcsData);
 
18137
 
 
18138
static Int4 GetConvertFeatureTableLine (Uint2 seqfeat_from, Uint2 featdef_from, Uint2 seqfeat_to, Uint2 featdef_to)
 
18139
{
 
18140
  Int4 i, table_line_num = -1;
 
18141
 
 
18142
  for (i = 0; i < num_convert_feature_table_lines && table_line_num == -1; i++)
 
18143
  {
 
18144
    if ((ConvertFeaturesTable[i].seqfeat_from == 0 || ConvertFeaturesTable[i].seqfeat_from == seqfeat_from)
 
18145
        && (ConvertFeaturesTable[i].featdef_from == FEATDEF_ANY || ConvertFeaturesTable[i].featdef_from == featdef_from)
 
18146
        && (ConvertFeaturesTable[i].seqfeat_to == 0 || ConvertFeaturesTable[i].seqfeat_to == seqfeat_to)
 
18147
        && (ConvertFeaturesTable[i].featdef_to == FEATDEF_ANY || ConvertFeaturesTable[i].featdef_to == featdef_to))
 
18148
    {
 
18149
      table_line_num = i;
 
18150
    }
 
18151
  }
 
18152
  return table_line_num;
 
18153
}
 
18154
 
15665
18155
 
15666
18156
typedef struct featureselremconform
15667
18157
{
15678
18168
  GrouP   convert_grp;
15679
18169
  ButtoN  clear_constraints_on_action_change;
15680
18170
  ButtoN  leave_original_feature_btn;  /* checkbox for conversion only */
15681
 
  
 
18171
 
 
18172
  DoC     help_text; /* for conversion only - describes conversion */  
 
18173
 
15682
18174
  /* used for convert callback */
15683
18175
  Uint1      featdef_to;
15684
 
  CharPtr    featname_to;
15685
 
  Boolean    ask_for_transcript_id_removal;
15686
 
  Boolean    do_remove_transcript_ids;
15687
 
  ValNodePtr productbsp_list;
15688
 
  Int4       site_or_bond_type;
15689
 
  Boolean    abort_convert;
 
18176
  Boolean    renormalize_nucprot;
15690
18177
  Boolean    leave_original_feature;
15691
18178
  ValNodePtr feat_list;
 
18179
  BaseFormPtr bfp;
15692
18180
} FeatureSelRemConvFormData, PNTR FeatureSelRemConvFormPtr;
15693
18181
 
15694
18182
static void CleanupFeatureSelRemConvForm (GraphiC g, VoidPtr data)
15698
18186
 
15699
18187
  mrfp = (FeatureSelRemConvFormPtr) data;
15700
18188
  if (mrfp != NULL) {
15701
 
    mrfp->featname_to = MemFree (mrfp->featname_to);
15702
18189
  }
15703
18190
  StdCleanupFormProc (g, data);
15704
18191
}
15739
18226
static void FeatureRemoveChangeNotify (Pointer userdata)
15740
18227
{
15741
18228
  FeatureSelRemConvFormPtr mrfp;
15742
 
  ValNodePtr          err_list;
 
18229
  ValNodePtr          err_list, vnp_from, vnp_to;
 
18230
  Int4                table_line;
 
18231
  RecT                r;
 
18232
  Boolean             need_original = FALSE;
15743
18233
 
15744
18234
  mrfp = (FeatureSelRemConvFormPtr) userdata;
15745
18235
  if (mrfp == NULL) return;
15764
18254
    {
15765
18255
      err_list = TestDialog (mrfp->feature_select_to); 
15766
18256
    }
 
18257
    /* set help text */
 
18258
    Reset (mrfp->help_text);
 
18259
    vnp_from = (ValNodePtr) DialogToPointer (mrfp->feature_select_from);
 
18260
    vnp_to = (ValNodePtr) DialogToPointer (mrfp->feature_select_to);
 
18261
    if (vnp_from == NULL || vnp_to == NULL) 
 
18262
    {
 
18263
      AppendText (mrfp->help_text, "No conversion selected", NULL, NULL, systemFont);
 
18264
    }
 
18265
    else if (vnp_from->choice == vnp_to->choice)
 
18266
    {
 
18267
      AppendText (mrfp->help_text, "Can't convert from and to the same type", NULL, NULL, systemFont);
 
18268
      ValNodeAddPointer (&err_list, 0, "Can't convert from and to the same type");
 
18269
    }
 
18270
    else
 
18271
    {
 
18272
      /* set help text */
 
18273
      table_line = GetConvertFeatureTableLine (FindFeatFromFeatDefType (vnp_from->choice),
 
18274
                                               vnp_from->choice,
 
18275
                                               FindFeatFromFeatDefType (vnp_to->choice),
 
18276
                                               vnp_to->choice);
 
18277
      if (table_line < 0)
 
18278
      {
 
18279
        AppendText (mrfp->help_text, "Conversion not supported", NULL, NULL, systemFont);
 
18280
      }
 
18281
      else if (ConvertFeaturesTable[table_line].help_text == NULL)
 
18282
      {
 
18283
        AppendText (mrfp->help_text, "No description available", NULL, NULL, systemFont);
 
18284
      }
 
18285
      else
 
18286
      {
 
18287
        AppendText (mrfp->help_text, ConvertFeaturesTable[table_line].help_text, NULL, NULL, systemFont);
 
18288
      }
 
18289
 
 
18290
      /* if converting from CDS to site, bond, or region, "leave original" must be checked */
 
18291
      if ((vnp_from->choice == FEATDEF_CDS
 
18292
           || vnp_from->choice == FEATDEF_ANY)
 
18293
          && (vnp_to->choice == FEATDEF_SITE 
 
18294
              || vnp_to->choice == FEATDEF_BOND
 
18295
              || vnp_to->choice == FEATDEF_REGION))
 
18296
      {
 
18297
        need_original = TRUE;
 
18298
        AppendText (mrfp->help_text, "If converting from CDS to site or bond, or region, you must check Leave Original Feature.", NULL, NULL, systemFont);
 
18299
      }
 
18300
    }
 
18301
    vnp_from = ValNodeFreeData (vnp_from);
 
18302
    vnp_to = ValNodeFreeData (vnp_to);
 
18303
    ObjectRect (mrfp->help_text, &r);
 
18304
    InvalRect (&r);  
 
18305
 
15767
18306
  }
15768
18307
  else
15769
18308
  {
15774
18313
    }
15775
18314
  }
15776
18315
  
15777
 
  if (err_list == NULL)
 
18316
  if (err_list == NULL && (!need_original || GetStatus (mrfp->leave_original_feature_btn)))
15778
18317
  {
15779
18318
    EnableAcceptCancelDialogAccept (mrfp->accept_cancel);
15780
18319
  }
15785
18324
  ValNodeFree (err_list);
15786
18325
}
15787
18326
 
 
18327
 
 
18328
static void FeatureRemoveChangeButton (ButtoN b)
 
18329
{
 
18330
  FeatureSelRemConvFormPtr mrfp;
 
18331
  
 
18332
  mrfp = (FeatureSelRemConvFormPtr) GetObjectExtra (b);
 
18333
  if (mrfp == NULL) return;
 
18334
  FeatureRemoveChangeNotify (mrfp);
 
18335
}
 
18336
 
 
18337
 
15788
18338
static void FeatureRemoveOrConvertCenterAction (PopuP p)
15789
18339
{
15790
18340
  FeatureSelRemConvFormPtr mrfp;
15909
18459
}
15910
18460
 
15911
18461
 
15912
 
static void ConvertRegionToImp (SeqFeatPtr sfp, CharPtr featname_to)
 
18462
static CharPtr GetImportFeatureName (Uint2 featdef_key)
 
18463
{
 
18464
  FeatDefPtr  curr;
 
18465
  Uint1       key;
 
18466
  CharPtr     label = NULL;
 
18467
 
 
18468
  curr = FeatDefFindNext (NULL, &key, &label, FEATDEF_ANY, TRUE);
 
18469
  while (curr != NULL) 
 
18470
  {
 
18471
    if (featdef_key == key)
 
18472
    {
 
18473
      return curr->typelabel;
 
18474
    }
 
18475
    curr = FeatDefFindNext (curr, &key, &label, FEATDEF_ANY, TRUE);
 
18476
  }
 
18477
  return NULL;
 
18478
}
 
18479
 
 
18480
 
 
18481
static Boolean ConvertRegionToImp (SeqFeatPtr sfp, Uint2 featdef_to, Pointer extradata)
15913
18482
{
15914
18483
  GBQualPtr          gbqual;
15915
18484
  ImpFeatPtr         ifp;
15916
18485
  CharPtr            str;
 
18486
  CharPtr            featname_to;
15917
18487
 
 
18488
  if (sfp == NULL || sfp->data.choice != SEQFEAT_REGION) return FALSE;
 
18489
  featname_to = GetImportFeatureName (featdef_to);
15918
18490
  ifp = ImpFeatNew ();
15919
18491
  if (NULL == ifp)
15920
 
    return;
 
18492
    return FALSE;
15921
18493
 
15922
18494
  str = (CharPtr) sfp->data.value.ptrvalue;
15923
18495
  sfp->data.choice = SEQFEAT_IMP;
15939
18511
      gbqual->next = sfp->qual;
15940
18512
      sfp->qual = gbqual;
15941
18513
    }
15942
 
  }  
15943
 
}
15944
 
 
15945
 
static void AskForTranscriptionIdRemoval (BoolPtr ask, BoolPtr do_remove)
15946
 
{
15947
 
  if (ask == NULL || do_remove == NULL)
15948
 
  {
15949
 
    return;
15950
 
  }
15951
 
  if (*ask)
15952
 
  {
15953
 
    if (Message (MSG_YN, "Remove transcript IDs?") == ANS_YES)
15954
 
    {
15955
 
      *do_remove = TRUE;
15956
 
    }
15957
 
    *ask = FALSE;
15958
 
  }
15959
 
}
15960
 
 
15961
 
static void 
15962
 
ConvertGeneToRNA 
15963
 
(SeqFeatPtr  sfp,
15964
 
 Int2        toFeatSubType,
15965
 
 Int2        fromFeat,
15966
 
 Boolean     do_remove_transcript_ids,
15967
 
 ValNodePtr PNTR productbsp_list)
15968
 
{
15969
 
  Int2               j;
15970
 
  Char               label [256];
15971
 
  BioseqPtr          productbsp;
15972
 
  RnaRefPtr          rrp;
15973
 
  SeqIdPtr           sip;
15974
 
  tRNAPtr            trp;
15975
 
  Boolean            just_trna_text = FALSE;
15976
 
  Boolean            asked_for_replace = TRUE;
15977
 
  Boolean            do_replace = FALSE;
15978
 
  Boolean            use_semicolon = TRUE;
15979
 
  GeneRefPtr         grp = NULL;
15980
 
 
15981
 
  rrp = RnaRefNew ();
15982
 
  if (NULL == rrp)
15983
 
    return;
15984
 
 
15985
 
  FeatDefLabel (sfp, label, sizeof (label), OM_LABEL_CONTENT);
15986
 
  if (fromFeat == SEQFEAT_GENE) {
15987
 
    grp = (GeneRefPtr) sfp->data.value.ptrvalue;
15988
 
    sfp->data.value.ptrvalue = NULL;
15989
 
  } else if (fromFeat == SEQFEAT_CDREGION) {
15990
 
    if (sfp->product != NULL) {
15991
 
      sip = SeqLocId (sfp->product);
15992
 
      if (sip != NULL) {
15993
 
        productbsp = BioseqFind (sip);
15994
 
        if (productbsp != NULL) 
15995
 
        {
15996
 
                ValNodeAddPointer (productbsp_list, 0, (Pointer) productbsp);
15997
 
              }
15998
 
      }
15999
 
      if (do_remove_transcript_ids)
16000
 
      {
16001
 
        sfp->product = SeqLocFree (sfp->product);
16002
 
      }
16003
 
    }
16004
 
    sfp->data.value.ptrvalue =
16005
 
      CdRegionFree ((CdRegionPtr) sfp->data.value.ptrvalue);
16006
 
  }
16007
 
 
16008
 
  sfp->data.choice = SEQFEAT_RNA;
16009
 
  sfp->data.value.ptrvalue = (Pointer) rrp;
16010
 
  switch (toFeatSubType) {
16011
 
  case FEATDEF_preRNA :
16012
 
    rrp->type = 1;
16013
 
    break;
16014
 
  case FEATDEF_mRNA :
16015
 
    rrp->type = 2;
16016
 
    break;
16017
 
  case FEATDEF_tRNA :
16018
 
    rrp->type = 3;
16019
 
    break;
16020
 
  case FEATDEF_rRNA :
16021
 
    rrp->type = 4;
16022
 
    break;
16023
 
  case FEATDEF_snRNA :
16024
 
    rrp->type = 5;
16025
 
    break;
16026
 
  case FEATDEF_scRNA :
16027
 
    rrp->type = 6;
16028
 
    break;
16029
 
  case FEATDEF_snoRNA :
16030
 
    rrp->type = 7;
16031
 
    break;
16032
 
  case FEATDEF_otherRNA :
16033
 
    rrp->type = 255;
16034
 
    break;
16035
 
  default :
16036
 
    break;
16037
 
  }
16038
 
 
16039
 
  if (toFeatSubType == FEATDEF_tRNA) {
16040
 
    trp = (tRNAPtr) MemNew (sizeof (tRNA));
16041
 
    rrp->ext.choice = 2;
16042
 
    rrp->ext.value.ptrvalue = (Pointer) trp;
16043
 
    if (trp != NULL) {
16044
 
      trp->aa = ParseTRnaString (label, &just_trna_text, NULL, FALSE);
16045
 
      trp->aatype = 2;
16046
 
      for (j = 0; j < 6; j++) {
16047
 
              trp->codon [j] = 255;
16048
 
      }
16049
 
    }
16050
 
    if (!just_trna_text)
16051
 
    {
16052
 
      AppendOrReplaceString (&(sfp->comment), label,
16053
 
                           &asked_for_replace,
16054
 
                           &do_replace,
16055
 
                           &use_semicolon);
16056
 
    }
16057
 
  } else if (! StringHasNoText (label)) {
16058
 
    rrp->ext.choice = 1;
16059
 
    rrp->ext.value.ptrvalue = StringSave (label);
16060
 
  }
16061
 
  
16062
 
  if (grp != NULL)
16063
 
  {
16064
 
    /* append unused gene qualifiers */
16065
 
    if (StringCmp (grp->locus, label) != 0)
16066
 
    {
16067
 
      AppendOrReplaceString (&(sfp->comment), grp->locus,
16068
 
                           &asked_for_replace,
16069
 
                           &do_replace,
16070
 
                           &use_semicolon);
16071
 
    }
16072
 
    if (StringCmp (grp->allele, label) != 0)
16073
 
    {
16074
 
      AppendOrReplaceString (&(sfp->comment), grp->allele,
16075
 
                           &asked_for_replace,
16076
 
                           &do_replace,
16077
 
                           &use_semicolon);
16078
 
    }
16079
 
    if (StringCmp (grp->desc, label) != 0)
16080
 
    {
16081
 
      AppendOrReplaceString (&(sfp->comment), grp->desc,
16082
 
                           &asked_for_replace,
16083
 
                           &do_replace,
16084
 
                           &use_semicolon);
16085
 
    }
16086
 
    if (StringCmp (grp->maploc, label) != 0)
16087
 
    {
16088
 
      AppendOrReplaceString (&(sfp->comment), grp->maploc,
16089
 
                           &asked_for_replace,
16090
 
                           &do_replace,
16091
 
                           &use_semicolon);
16092
 
    }
16093
 
    if (StringCmp (grp->locus_tag, label) != 0)
16094
 
    {
16095
 
      AppendOrReplaceString (&(sfp->comment), grp->locus_tag,
16096
 
                           &asked_for_replace,
16097
 
                           &do_replace,
16098
 
                           &use_semicolon);
16099
 
    }
16100
 
 
16101
 
    /* free generef */
16102
 
    grp = GeneRefFree (grp);      
16103
 
  }
16104
 
}
16105
 
 
16106
 
static void GetSiteOrBondType (FeatureSelRemConvFormPtr mrfp, Uint2 toFeat)
16107
 
{
16108
 
  EnumFieldAssocPtr  al;
16109
 
  CharPtr            mssg;
16110
 
  UIEnum             val;
16111
 
  if (mrfp == NULL || mrfp->site_or_bond_type != -1 || toFeat == SEQFEAT_REGION)
16112
 
  {
16113
 
    return;
16114
 
  }
16115
 
  al = NULL;
16116
 
  mssg = NULL;
16117
 
  if (toFeat == SEQFEAT_BOND) {
16118
 
    al = enum_bond_alist;
16119
 
    mssg = "Select type of bond";
16120
 
  } else if (toFeat == SEQFEAT_SITE) {
16121
 
    al = enum_site_alist;
16122
 
    mssg = "Select type of site";
16123
 
  }
16124
 
  if (al == NULL) return;
16125
 
  if (! AlistMessage (al, &val, 1, mssg)) return;
16126
 
  mrfp->site_or_bond_type = (Int4) val; 
16127
 
}
16128
 
 
16129
 
static void 
 
18514
  }
 
18515
  return TRUE;
 
18516
}
 
18517
 
 
18518
 
 
18519
static SeqLocPtr GetProteinLocationForNucleotideFeatureConversion (SeqLocPtr nuc_slp, BoolPtr no_cds)
 
18520
{
 
18521
  SeqFeatPtr cds;
 
18522
  SeqMgrFeatContext cds_context;
 
18523
  SeqLocPtr  prot_slp;
 
18524
 
 
18525
  cds = SeqMgrGetOverlappingCDS (nuc_slp, &cds_context);
 
18526
  if (cds == NULL) {
 
18527
    if (no_cds != NULL) {
 
18528
      *no_cds = TRUE;
 
18529
    }
 
18530
    return NULL;
 
18531
  } else if (no_cds != NULL) {
 
18532
    *no_cds = FALSE;
 
18533
  }
 
18534
 
 
18535
  prot_slp = BuildProtLoc (cds, nuc_slp, NULL);
 
18536
  return prot_slp;
 
18537
}
 
18538
 
 
18539
 
 
18540
static Boolean 
16130
18541
ConvertToBondSiteOrRegion 
16131
18542
(SeqFeatPtr sfp, 
16132
18543
 Int4       site_or_bond_type,
16133
 
 Uint1      toFeat)
 
18544
 Uint2      featdef_to,
 
18545
 Boolean    create_prot_feats)
16134
18546
{
16135
 
  SeqFeatPtr         cds;
16136
18547
  BioseqPtr          bsp;
16137
18548
  SeqLocPtr          slp;
16138
18549
  SeqEntryPtr        sep;
16139
 
  SeqMgrFeatContext  context, cds_context;
 
18550
  SeqMgrFeatContext  context;
16140
18551
  SeqFeatPtr         newsfp;
16141
18552
  SeqIdPtr           sip;
16142
18553
  CharPtr            comment;
16143
18554
  SeqBondPtr         sbp;
16144
18555
  SeqPntPtr          spp;
 
18556
  Boolean            no_cds = FALSE;
16145
18557
  
16146
18558
  if (sfp == NULL)
16147
18559
  {
16148
 
    return;
 
18560
    return FALSE;
16149
18561
  }
16150
18562
  
16151
 
  if (site_or_bond_type == -1 && toFeat != SEQFEAT_REGION)
 
18563
  if (site_or_bond_type == -1 && featdef_to != FEATDEF_REGION)
16152
18564
  {
16153
 
    return;
 
18565
    return FALSE;
16154
18566
  }
16155
18567
  
16156
18568
  bsp = BioseqFindFromSeqLoc (sfp->location);
16157
18569
  sfp = SeqMgrGetDesiredFeature (0, bsp, 0, 0, sfp, &context);
16158
 
  if (sfp == NULL) return;
16159
 
 
16160
 
  
16161
 
  cds = SeqMgrGetOverlappingCDS (sfp->location, &cds_context);
16162
 
    if (cds == NULL) {
16163
 
    Message (MSG_ERROR, "Unable to find CDS covering %s", context.label);
16164
 
    return;
16165
 
  }
16166
 
  bsp = GetBioseqGivenSeqLoc (cds->location, context.entityID);
16167
 
  if (bsp == NULL || ISA_aa (bsp->mol)) {
16168
 
    Message (MSG_ERROR, "Unable to find DNA bioseq for %s", context.label);
16169
 
    return;
16170
 
  }
16171
 
  slp = BuildProtLoc (cds, sfp->location, NULL);
16172
 
  if (slp == NULL) {
16173
 
    Message (MSG_ERROR, "Unable to convert to protein coordinate for %s", context.label);
16174
 
    return;
16175
 
  }
 
18570
  if (sfp == NULL || bsp == NULL) return FALSE;
 
18571
 
 
18572
  if (ISA_aa (bsp->mol))
 
18573
  {
 
18574
    if (create_prot_feats)
 
18575
    {
 
18576
      slp = (SeqLocPtr) AsnIoMemCopy (sfp->location, (AsnReadFunc) SeqLocAsnRead, (AsnWriteFunc) SeqLocAsnWrite);
 
18577
    }
 
18578
    else
 
18579
    {
 
18580
      slp = FindNucleotideLocationForProteinFeatureConversion (sfp->location, sfp->idx.entityID);
 
18581
    }
 
18582
  }
 
18583
  else if (create_prot_feats) 
 
18584
  {
 
18585
    slp = GetProteinLocationForNucleotideFeatureConversion (sfp->location, &no_cds);
 
18586
    if (no_cds) {
 
18587
      Message (MSG_ERROR, "Unable to find CDS covering %s", context.label);
 
18588
      return FALSE;
 
18589
    }
 
18590
  } else {
 
18591
    slp = (SeqLocPtr) AsnIoMemCopy (sfp->location, (AsnReadFunc) SeqLocAsnRead, (AsnWriteFunc) SeqLocAsnWrite);
 
18592
  }
 
18593
 
16176
18594
  bsp = GetBioseqGivenSeqLoc (slp, context.entityID);
16177
18595
  if (bsp == NULL) {
16178
 
    Message (MSG_ERROR, "Unable to find target protein bioseq for %s", context.label);
16179
 
    return;
16180
 
  }
 
18596
    Message (MSG_ERROR, "Unable to find target %s bioseq for %s", create_prot_feats ? "protein" : "nucleotide", context.label);
 
18597
    slp = SeqLocFree (slp);
 
18598
    return FALSE;
 
18599
  } 
 
18600
 
16181
18601
  sep = SeqMgrGetSeqEntryForData (bsp);
16182
18602
  if (sep == NULL) {
16183
 
    Message (MSG_ERROR, "Unable to find target protein seq-entry for %s", context.label);
16184
 
    return;
 
18603
    Message (MSG_ERROR, "Unable to find target %s seq-entry for %s", create_prot_feats ? "protein" : "nucleotide", context.label);
 
18604
    return FALSE;
16185
18605
  }
16186
18606
  
16187
18607
  comment = sfp->comment;
16188
18608
 
16189
18609
  newsfp = NULL;
16190
 
  if (toFeat == SEQFEAT_BOND || toFeat == SEQFEAT_SITE) {
 
18610
  if (featdef_to == FEATDEF_BOND || featdef_to == FEATDEF_SITE) {
16191
18611
    newsfp = SeqFeatNew ();
16192
 
    if (newsfp != NULL) {
16193
 
      newsfp->data.choice = toFeat;
 
18612
    if (newsfp != NULL) 
 
18613
    {
 
18614
      newsfp->data.choice = FindFeatFromFeatDefType(featdef_to);
16194
18615
      newsfp->data.value.intvalue = site_or_bond_type;
16195
 
          sfp->comment = NULL;
 
18616
            sfp->comment = NULL;
16196
18617
    }
16197
 
  } else if (toFeat == SEQFEAT_REGION) {
 
18618
  } else if (featdef_to == FEATDEF_REGION) {
16198
18619
    newsfp = SeqFeatNew ();
16199
 
    if (newsfp != NULL) {
16200
 
      newsfp->data.choice = toFeat;
 
18620
    if (newsfp != NULL) 
 
18621
    {
 
18622
      newsfp->data.choice = FindFeatFromFeatDefType(featdef_to);
16201
18623
      newsfp->data.value.ptrvalue = sfp->comment;
16202
18624
      sfp->comment = NULL;
16203
 
          comment = NULL;
 
18625
            comment = NULL;
16204
18626
    }
16205
18627
  }
16206
18628
  if (newsfp != NULL) {
16207
18629
    sfp->idx.deleteme = TRUE;
16208
 
    DeleteMarkedObjects (context.entityID, 0, NULL);
16209
 
    CreateNewFeature (sep, NULL, toFeat, newsfp);
 
18630
    CreateNewFeature (sep, NULL, FindFeatFromFeatDefType(featdef_to), newsfp);
16210
18631
    newsfp->location = slp;
16211
18632
    newsfp->comment = comment;
16212
 
    if (toFeat == SEQFEAT_BOND) {
 
18633
    if (featdef_to == FEATDEF_BOND) {
16213
18634
      if (slp->choice != SEQLOC_BOND) {
16214
18635
        sip = SeqLocId (slp);
16215
18636
        if (sip != NULL) {
16241
18662
      }
16242
18663
    }
16243
18664
  }
16244
 
}
16245
 
 
16246
 
 
16247
 
static void ConvertImpToImp (SeqFeatPtr sfp, CharPtr featname_to)
16248
 
{
16249
 
  ImpFeatPtr         ifp;
16250
 
 
16251
 
  ifp = (ImpFeatPtr) sfp->data.value.ptrvalue;
16252
 
  if (NULL == ifp)
16253
 
    return;
16254
 
  
16255
 
  ifp->key = MemFree (ifp->key);
16256
 
  if (featname_to == NULL)
 
18665
  if (newsfp == NULL)
16257
18666
  {
16258
 
    ifp->key = StringSave ("misc_feature");
16259
 
  }
 
18667
    return FALSE;
 
18668
  } 
16260
18669
  else
16261
18670
  {
16262
 
    ifp->key = StringSave (featname_to);
 
18671
    return TRUE;
16263
18672
  }
16264
18673
}
16265
18674
 
16271
18680
} OrigFeatData, PNTR OrigFeatPtr;
16272
18681
 
16273
18682
 
16274
 
static void AddDuplicateFeature (SeqFeatPtr sfp_orig, ValNodePtr PNTR feat_list)
 
18683
static ValNodePtr AddDuplicateFeature (SeqFeatPtr sfp_orig, ValNodePtr PNTR feat_list)
16275
18684
{
16276
18685
  SeqEntryPtr sep;
16277
18686
  BioseqPtr   bsp;
16278
18687
  OrigFeatPtr ofp;
16279
18688
  
16280
 
  if (sfp_orig == NULL || feat_list == NULL) return;
 
18689
  if (sfp_orig == NULL || feat_list == NULL) return NULL;
16281
18690
  bsp = BioseqFindFromSeqLoc (sfp_orig->location);
16282
 
  if (bsp == NULL) return;
 
18691
  if (bsp == NULL) return NULL;
16283
18692
  sep = SeqMgrGetSeqEntryForData (bsp);
16284
 
  if (sep == NULL) return;
 
18693
  if (sep == NULL) return NULL;
16285
18694
  
16286
18695
  ofp = (OrigFeatPtr) MemNew (sizeof (OrigFeatData));
16287
 
  if (ofp == NULL) return;
 
18696
  if (ofp == NULL) return NULL;
16288
18697
  
16289
18698
  ofp->sep = sep;
16290
18699
  ofp->sfp = (SeqFeatPtr) AsnIoMemCopy (sfp_orig, (AsnReadFunc) SeqFeatAsnRead,
16291
18700
                                                 (AsnWriteFunc) SeqFeatAsnWrite);
16292
18701
  
16293
 
  ValNodeAddPointer (feat_list, 0, ofp);
16294
 
}
16295
 
 
16296
 
 
16297
 
static void ConvertFeatureCallback (SeqFeatPtr sfp, Pointer userdata, FilterSetPtr fsp)
16298
 
{
16299
 
  FeatureSelRemConvFormPtr   mrfp;
16300
 
  Uint1                 fromFeat;
16301
 
  Uint1                 toFeat;
16302
 
 
16303
 
  mrfp = (FeatureSelRemConvFormPtr) userdata;
16304
 
  
16305
 
  if (sfp == NULL || mrfp == NULL || mrfp->abort_convert)
16306
 
  {
16307
 
    return;
16308
 
  }
16309
 
  
16310
 
  fromFeat = sfp->data.choice;
16311
 
  toFeat   = FindFeatFromFeatDefType (mrfp->featdef_to);
16312
 
  
16313
 
  if (mrfp->leave_original_feature)
16314
 
  {
16315
 
    /* need a list of duplicate features that we can add to the appropriate SeqEntrys
16316
 
     * when we are done with the conversions.
16317
 
     */
16318
 
    AddDuplicateFeature (sfp, &(mrfp->feat_list)); 
16319
 
  }
16320
 
 
16321
 
  if (fromFeat == SEQFEAT_IMP 
16322
 
      && toFeat == SEQFEAT_CDREGION)
16323
 
  {
16324
 
    Message (MSG_ERROR, "Conversion not yet supported");
16325
 
    mrfp->abort_convert = TRUE;   
16326
 
  }
16327
 
  else if (fromFeat == SEQFEAT_IMP &&
16328
 
      toFeat   == SEQFEAT_PROT)
16329
 
    FeatConvertImpToPeptide (sfp, mrfp->featdef_to, mrfp->input_entityID);
16330
 
  else if (fromFeat == SEQFEAT_PROT &&
16331
 
           toFeat   == SEQFEAT_IMP &&
16332
 
           sfp->idx.subtype == FEATDEF_mat_peptide_aa)
16333
 
    FeatConvertPeptideToImp (sfp, mrfp->input_entityID);
16334
 
  else if (fromFeat == SEQFEAT_PROT &&
16335
 
           toFeat   == SEQFEAT_IMP &&
16336
 
           sfp->idx.subtype == FEATDEF_sig_peptide_aa)
16337
 
    FeatConvertPeptideToImp (sfp, mrfp->input_entityID);
16338
 
  else if (fromFeat == SEQFEAT_PROT &&
16339
 
           toFeat   == SEQFEAT_IMP &&
16340
 
           sfp->idx.subtype == FEATDEF_transit_peptide_aa)
16341
 
    FeatConvertPeptideToImp (sfp, mrfp->input_entityID);
16342
 
  else if (fromFeat == SEQFEAT_IMP &&
16343
 
           (mrfp->featdef_to == FEATDEF_misc_RNA ||
16344
 
            mrfp->featdef_to == FEATDEF_precursor_RNA))
16345
 
    FeatConvertImpToSpecialRNA (sfp, mrfp->featdef_to);
16346
 
  else if ((fromFeat == SEQFEAT_GENE ||
16347
 
            fromFeat == SEQFEAT_CDREGION) &&
16348
 
           toFeat == SEQFEAT_RNA)
16349
 
  {
16350
 
    AskForTranscriptionIdRemoval (&(mrfp->ask_for_transcript_id_removal),
16351
 
                                  &(mrfp->do_remove_transcript_ids));
16352
 
    ConvertGeneToRNA (sfp, mrfp->featdef_to, fromFeat, 
16353
 
                      mrfp->do_remove_transcript_ids, &(mrfp->productbsp_list));
16354
 
  }
16355
 
  else if (fromFeat == SEQFEAT_REGION &&
16356
 
           toFeat == SEQFEAT_IMP)
16357
 
    ConvertRegionToImp (sfp, mrfp->featname_to);
16358
 
  else if (fromFeat == SEQFEAT_REGION &&
16359
 
           (mrfp->featdef_to == FEATDEF_misc_RNA ||
16360
 
            mrfp->featdef_to == FEATDEF_precursor_RNA))
16361
 
    FeatConvertRegionToRNA (sfp, mrfp->featdef_to);
16362
 
  else if (fromFeat == SEQFEAT_IMP &&
16363
 
           toFeat == SEQFEAT_RNA)
16364
 
    FeatConvertImpToRNA (sfp, mrfp->featdef_to);
16365
 
  else if (fromFeat == SEQFEAT_COMMENT &&
16366
 
           mrfp->featdef_to == FEATDEF_misc_feature)
16367
 
    FeatConvertCommentToMiscFeature (sfp);
16368
 
  else if (fromFeat == SEQFEAT_GENE &&
16369
 
           mrfp->featdef_to == FEATDEF_misc_feature)
16370
 
    FeatConvertGeneToMiscFeature (sfp);
16371
 
  else if (fromFeat == SEQFEAT_RNA &&
16372
 
           mrfp->featdef_to == FEATDEF_misc_feature)
16373
 
    FeatConvertRNAToMiscFeature (sfp);
16374
 
  else if (fromFeat == SEQFEAT_SITE &&
16375
 
           mrfp->featdef_to == FEATDEF_misc_feature)
16376
 
    FeatConvertSiteToMiscFeature (sfp);
16377
 
  else if (fromFeat == SEQFEAT_PROT &&
16378
 
           (sfp->idx.subtype == FEATDEF_mat_peptide_aa ||
16379
 
            sfp->idx.subtype == FEATDEF_sig_peptide_aa ||
16380
 
            sfp->idx.subtype == FEATDEF_transit_peptide_aa) &&
16381
 
           toFeat == SEQFEAT_REGION)
16382
 
    FeatConvertPeptideToRegion (sfp);
16383
 
  else if (fromFeat == SEQFEAT_BIOSRC &&
16384
 
           toFeat == SEQFEAT_IMP &&
16385
 
           mrfp->featdef_to == FEATDEF_repeat_region)
16386
 
    FeatConvertBioSrcToRepeatRegion (sfp);
16387
 
  else if (fromFeat == SEQFEAT_REGION
16388
 
    && toFeat == SEQFEAT_PROT
16389
 
    && (mrfp->featdef_to == FEATDEF_mat_peptide_aa ||
16390
 
        mrfp->featdef_to == FEATDEF_sig_peptide_aa ||
16391
 
        mrfp->featdef_to == FEATDEF_transit_peptide_aa ||
16392
 
        mrfp->featdef_to == FEATDEF_preprotein))
16393
 
  {
16394
 
    FeatConvertRegionToProt (sfp, mrfp->featdef_to);
16395
 
  }
16396
 
  else if (toFeat == SEQFEAT_BOND || toFeat == SEQFEAT_REGION || toFeat == SEQFEAT_SITE)
16397
 
  {
16398
 
    GetSiteOrBondType (mrfp, toFeat);
16399
 
    ConvertToBondSiteOrRegion (sfp, mrfp->site_or_bond_type, toFeat);
16400
 
  }
16401
 
    
16402
 
  else if (fromFeat != toFeat)
16403
 
  {
16404
 
    ArrowCursor ();
16405
 
    Message (MSG_OK, "This conversion not supported - contact"
 
18702
  return ValNodeAddPointer (feat_list, 0, ofp);
 
18703
}
 
18704
 
 
18705
static Pointer SimpleOptsFree (Pointer data)
 
18706
{
 
18707
  return MemFree (data);
 
18708
}
 
18709
 
 
18710
static RnaRefPtr RnaRefFromLabel (Uint2 featdef_to, CharPtr label, BoolPtr add_label_to_comment)
 
18711
{
 
18712
  RnaRefPtr rrp;
 
18713
  tRNAPtr   trp = NULL;
 
18714
  Boolean   just_trna_text;
 
18715
  Int4      j;
 
18716
 
 
18717
  rrp = RnaRefNew ();
 
18718
  if (NULL == rrp)
 
18719
    return NULL;
 
18720
 
 
18721
  *add_label_to_comment = FALSE;
 
18722
 
 
18723
  switch (featdef_to) 
 
18724
  {
 
18725
    case FEATDEF_preRNA :
 
18726
      rrp->type = 1;
 
18727
      break;
 
18728
    case FEATDEF_mRNA :
 
18729
      rrp->type = 2;
 
18730
      break;
 
18731
    case FEATDEF_tRNA :
 
18732
      rrp->type = 3;
 
18733
      break;
 
18734
    case FEATDEF_rRNA :
 
18735
      rrp->type = 4;
 
18736
      break;
 
18737
    case FEATDEF_snRNA :
 
18738
      rrp->type = 5;
 
18739
      break;
 
18740
    case FEATDEF_scRNA :
 
18741
      rrp->type = 6;
 
18742
      break;
 
18743
    case FEATDEF_snoRNA :
 
18744
      rrp->type = 7;
 
18745
      break;
 
18746
    case FEATDEF_otherRNA :
 
18747
      rrp->type = 255;
 
18748
      break;
 
18749
    default :
 
18750
      break;
 
18751
  }
 
18752
 
 
18753
  if (featdef_to == FEATDEF_tRNA) 
 
18754
  {
 
18755
    trp = (tRNAPtr) MemNew (sizeof (tRNA));
 
18756
    rrp->ext.choice = 2;
 
18757
    rrp->ext.value.ptrvalue = (Pointer) trp;
 
18758
    trp->aa = ParseTRnaString (label, &just_trna_text, NULL, FALSE);
 
18759
    trp->aatype = 2;
 
18760
    for (j = 0; j < 6; j++) {
 
18761
            trp->codon [j] = 255;
 
18762
    }
 
18763
    if (!just_trna_text)
 
18764
    {
 
18765
      *add_label_to_comment = TRUE;
 
18766
    }
 
18767
  } 
 
18768
  else if (! StringHasNoText (label))
 
18769
  {
 
18770
    rrp->ext.choice = 1;
 
18771
    rrp->ext.value.ptrvalue = StringSave (label);
 
18772
  }
 
18773
  return rrp;
 
18774
}
 
18775
 
 
18776
static Boolean 
 
18777
ConvertCDSToRNA 
 
18778
(SeqFeatPtr  sfp,
 
18779
 Uint2        toFeatSubType,
 
18780
 Pointer     extradata)
 
18781
{
 
18782
  Char                   label [256];
 
18783
  BioseqPtr              product_bsp;
 
18784
  CharPtr                new_comment;
 
18785
  Int4                   comment_len = 0;
 
18786
  CDSConversionOptsPtr   opts;
 
18787
  Boolean                add_label_to_comment = FALSE;
 
18788
  SeqFeatPtr             mrna, gene;
 
18789
  SeqMgrFeatContext      fcontext;
 
18790
 
 
18791
  if (sfp == NULL || sfp->data.choice != SEQFEAT_CDREGION) return FALSE;
 
18792
 
 
18793
  opts = (CDSConversionOptsPtr) extradata;
 
18794
 
 
18795
  FeatDefLabel (sfp, label, sizeof (label), OM_LABEL_CONTENT);
 
18796
 
 
18797
  if (sfp->product != NULL) {
 
18798
    product_bsp = BioseqFindFromSeqLoc (sfp->product);
 
18799
    if (product_bsp != NULL)
 
18800
    {
 
18801
      product_bsp->idx.deleteme = TRUE;
 
18802
    }
 
18803
    if (!IsFeatInGPS (sfp) || (opts != NULL && opts->remove_transcript_id))
 
18804
    {
 
18805
      sfp->product = SeqLocFree (sfp->product);
 
18806
    }
 
18807
  }
 
18808
 
 
18809
  if (opts != NULL && opts->remove_gene)
 
18810
  {
 
18811
    gene = SeqMgrGetOverlappingGene (sfp->location, &fcontext);
 
18812
    if (gene != NULL)
 
18813
    {
 
18814
      gene->idx.deleteme = TRUE;
 
18815
    }
 
18816
  }
 
18817
  
 
18818
  if (opts != NULL && opts->remove_mrna)
 
18819
  {
 
18820
    mrna = SeqMgrGetOverlappingmRNA (sfp->location, &fcontext);
 
18821
    if (mrna != NULL)
 
18822
    {
 
18823
      mrna->idx.deleteme = TRUE;
 
18824
    }
 
18825
  }
 
18826
 
 
18827
  sfp->data.value.ptrvalue =
 
18828
      CdRegionFree ((CdRegionPtr) sfp->data.value.ptrvalue);
 
18829
 
 
18830
  sfp->data.choice = SEQFEAT_RNA;
 
18831
  sfp->data.value.ptrvalue = RnaRefFromLabel (toFeatSubType, label, &add_label_to_comment);
 
18832
  
 
18833
  if (add_label_to_comment && StringCmp (label, sfp->comment) != 0)
 
18834
  {
 
18835
    if (StringHasNoText (sfp->comment)) 
 
18836
    {
 
18837
      new_comment = StringSave (label);
 
18838
    }
 
18839
    else
 
18840
    {
 
18841
      comment_len = StringLen (sfp->comment) + StringLen (label) + 3;
 
18842
      new_comment = (CharPtr) MemNew (sizeof (Char) * comment_len);
 
18843
      sprintf (new_comment, "%s; %s", sfp->comment, label);
 
18844
    }
 
18845
    sfp->comment = MemFree (sfp->comment);
 
18846
    sfp->comment = new_comment;
 
18847
  }  
 
18848
  
 
18849
  return TRUE;
 
18850
}
 
18851
 
 
18852
 
 
18853
static Boolean ConvertGeneToRNA (SeqFeatPtr sfp, Uint2 featdef_to, Pointer extradata)
 
18854
{
 
18855
  Char                   label [256];
 
18856
  GeneRefPtr grp;
 
18857
  Boolean    add_label_to_comment = FALSE;
 
18858
  CharPtr    new_comment;
 
18859
  Int4       comment_len = 0;
 
18860
 
 
18861
  if (sfp == NULL || sfp->data.choice != SEQFEAT_GENE) return FALSE;
 
18862
 
 
18863
  FeatDefLabel (sfp, label, sizeof (label), OM_LABEL_CONTENT);
 
18864
 
 
18865
  grp = (GeneRefPtr) sfp->data.value.ptrvalue;
 
18866
 
 
18867
  sfp->data.choice = SEQFEAT_RNA;
 
18868
  sfp->data.value.ptrvalue = RnaRefFromLabel (featdef_to, label, &add_label_to_comment);
 
18869
  
 
18870
  if (add_label_to_comment)
 
18871
  {
 
18872
    comment_len += StringLen (label) + 2;
 
18873
  }
 
18874
  if (grp != NULL)
 
18875
  {
 
18876
    if (!StringHasNoText (grp->locus) && StringCmp (grp->locus, label) != 0)
 
18877
    {
 
18878
      comment_len += StringLen (grp->locus) + 2;
 
18879
    }
 
18880
    if (!StringHasNoText (grp->allele) && StringCmp (grp->allele, label) != 0)
 
18881
    {
 
18882
      comment_len += StringLen (grp->allele) + 2;
 
18883
    }
 
18884
    if (!StringHasNoText (grp->desc) && StringCmp (grp->desc, label) != 0)
 
18885
    {
 
18886
      comment_len += StringLen (grp->desc) + 2;
 
18887
    }
 
18888
    if (!StringHasNoText (grp->maploc) && StringCmp (grp->maploc, label) != 0)
 
18889
    {
 
18890
      comment_len += StringLen (grp->maploc) + 2;
 
18891
    }
 
18892
    if (!StringHasNoText (grp->locus_tag) && StringCmp (grp->locus_tag, label) != 0)
 
18893
    {
 
18894
      comment_len += StringLen (grp->locus_tag) + 2;
 
18895
    }
 
18896
  }
 
18897
  if (comment_len > 0)
 
18898
  {
 
18899
    comment_len += StringLen (sfp->comment) + 3;
 
18900
    new_comment = (CharPtr) MemNew (sizeof (Char) * comment_len);
 
18901
    if (!StringHasNoText (sfp->comment))
 
18902
    {
 
18903
      StringCat (new_comment, sfp->comment);
 
18904
      StringCat (new_comment, "; ");
 
18905
    }
 
18906
    if (add_label_to_comment)
 
18907
    {
 
18908
      StringCat (new_comment, label);
 
18909
      StringCat (new_comment, "; ");
 
18910
    }
 
18911
    /* append unused gene qualifiers */
 
18912
    if (grp != NULL)
 
18913
    {
 
18914
      if (!StringHasNoText (grp->locus) && StringCmp (grp->locus, label) != 0)
 
18915
      {
 
18916
        StringCat (new_comment, grp->locus);
 
18917
        StringCat (new_comment, "; ");
 
18918
      }
 
18919
      if (!StringHasNoText (grp->allele) && StringCmp (grp->allele, label) != 0)
 
18920
      {
 
18921
        StringCat (new_comment, grp->allele);
 
18922
        StringCat (new_comment, "; ");
 
18923
      }
 
18924
      if (!StringHasNoText (grp->desc) && StringCmp (grp->desc, label) != 0)
 
18925
      {
 
18926
        StringCat (new_comment, grp->desc);
 
18927
        StringCat (new_comment, "; ");
 
18928
      }
 
18929
      if (!StringHasNoText (grp->maploc) && StringCmp (grp->maploc, label) != 0)
 
18930
      {
 
18931
        StringCat (new_comment, grp->maploc);
 
18932
        StringCat (new_comment, "; ");
 
18933
      }
 
18934
      if (!StringHasNoText (grp->locus_tag) && StringCmp (grp->locus_tag, label) != 0)
 
18935
      {
 
18936
        StringCat (new_comment, grp->locus_tag);
 
18937
        StringCat (new_comment, "; ");
 
18938
      }
 
18939
    }
 
18940
    /* remove last semicolon */
 
18941
    new_comment[StringLen (new_comment) - 2] = 0;
 
18942
    sfp->comment = MemFree (sfp->comment);
 
18943
    sfp->comment = new_comment;
 
18944
 
 
18945
  }
 
18946
  
 
18947
  /* free generef */
 
18948
  grp = GeneRefFree (grp);      
 
18949
  
 
18950
  return TRUE;
 
18951
}
 
18952
 
 
18953
 
 
18954
static ValNodePtr CreateClickableListForSourceFeats (ValNodePtr feat_list)
 
18955
{
 
18956
  ValNodePtr transposon_only_list = NULL;
 
18957
  ValNodePtr insertion_seq_only_list = NULL;
 
18958
  ValNodePtr transposon_and_insertion_seq_list = NULL;
 
18959
  ValNodePtr note_only_list = NULL;
 
18960
  ValNodePtr no_data_list = NULL;
 
18961
  ValNodePtr vnp;
 
18962
  CharPtr transposon_txt, insertion_seq_txt, note_txt;
 
18963
  SeqFeatPtr sfp;
 
18964
  BioSourcePtr biop;
 
18965
  Boolean is_transposon;
 
18966
  Boolean is_insertion_seq;
 
18967
  ClickableItemPtr cip;
 
18968
  ValNodePtr clickable_list = NULL;
 
18969
  
 
18970
  for (vnp = feat_list; vnp != NULL; vnp = vnp->next) {   
 
18971
    sfp = (SeqFeatPtr) vnp->data.ptrvalue;
 
18972
    biop = (BioSourcePtr) sfp->data.value.ptrvalue;
 
18973
    is_transposon = FALSE;
 
18974
    is_insertion_seq = FALSE;
 
18975
    transposon_txt = SubSourceText (biop, SUBSRC_transposon_name, &is_transposon);
 
18976
    insertion_seq_txt = SubSourceText (biop, SUBSRC_insertion_seq_name, &is_insertion_seq);
 
18977
    note_txt = NoteText (biop, sfp->comment);
 
18978
    
 
18979
    if (is_transposon && is_insertion_seq) {
 
18980
      ValNodeAddPointer (&transposon_and_insertion_seq_list, OBJ_SEQFEAT, vnp->data.ptrvalue);
 
18981
    } else if (is_transposon) {
 
18982
      ValNodeAddPointer (&transposon_only_list, OBJ_SEQFEAT, vnp->data.ptrvalue);
 
18983
    } else if (is_insertion_seq) {
 
18984
      ValNodeAddPointer (&insertion_seq_only_list, OBJ_SEQFEAT, vnp->data.ptrvalue);
 
18985
    } else if (!StringHasNoText (note_txt)) {
 
18986
      ValNodeAddPointer (&note_only_list, OBJ_SEQFEAT, vnp->data.ptrvalue);
 
18987
    } else {
 
18988
      ValNodeAddPointer (&no_data_list, OBJ_SEQFEAT, vnp->data.ptrvalue);
 
18989
    }
 
18990
  }
 
18991
 
 
18992
  if (transposon_and_insertion_seq_list != NULL) {
 
18993
    cip = NewClickableItem (0, "%d source features have both transposon-name and insertion-seq-name.", transposon_and_insertion_seq_list);
 
18994
    ValNodeAddPointer (&clickable_list, 0, cip);
 
18995
  }
 
18996
  if (transposon_only_list != NULL) {
 
18997
    cip = NewClickableItem (0, "%d source features have transposon-name.", transposon_only_list);
 
18998
    cip->chosen = TRUE;
 
18999
    ValNodeAddPointer (&clickable_list, 0, cip);
 
19000
  }
 
19001
  if (insertion_seq_only_list != NULL) {
 
19002
    cip = NewClickableItem (0, "%d source features have insertion-seq-name.", insertion_seq_only_list);
 
19003
    cip->chosen = TRUE;
 
19004
    ValNodeAddPointer (&clickable_list, 0, cip);
 
19005
  }
 
19006
  if (note_only_list != NULL) {
 
19007
    cip = NewClickableItem (0, "%d source features have notes, but neither transposon-name nor insertion-seq-name.", note_only_list);
 
19008
    ValNodeAddPointer (&clickable_list, 0, cip);
 
19009
  }
 
19010
  if (no_data_list != NULL) {
 
19011
    cip = NewClickableItem (0, "%d source features have no notes, no transposon-name, and no insertion-seq-name.", no_data_list);
 
19012
    ValNodeAddPointer (&clickable_list, 0, cip);
 
19013
  }
 
19014
 
 
19015
  return clickable_list;
 
19016
}
 
19017
 
 
19018
 
 
19019
static ValNodePtr AdjustConvertFeaturesForBioSrcToRepeatRegion (ValNodePtr feat_list, Pointer extradata, BaseFormPtr bfp, BoolPtr cancel)
 
19020
{
 
19021
  ValNodePtr clickable_list;
 
19022
 
 
19023
  *cancel = FALSE;
 
19024
  clickable_list = CreateClickableListForSourceFeats (feat_list);
 
19025
  feat_list = ValNodeFree (feat_list);
 
19026
  feat_list = ChooseFeaturesForConversion (clickable_list, bfp, "Available Data", "Features");
 
19027
  /* NOTE - the clickable_list will be freed by the dialog  - do not free it again here */
 
19028
  if (feat_list == NULL)
 
19029
  {
 
19030
    *cancel = TRUE;
 
19031
  }
 
19032
  return feat_list;
 
19033
}
 
19034
 
 
19035
static Boolean AllFeaturesArePseudo (ValNodePtr feat_list)
 
19036
{
 
19037
  Boolean    all_pseudo = TRUE;
 
19038
  SeqFeatPtr sfp;
 
19039
 
 
19040
  while (feat_list != NULL && all_pseudo) {
 
19041
    sfp = (SeqFeatPtr) feat_list->data.ptrvalue;
 
19042
    if (sfp != NULL && !sfp->pseudo) {
 
19043
      all_pseudo = FALSE;
 
19044
    }
 
19045
    feat_list = feat_list->next;
 
19046
  }
 
19047
  return all_pseudo;
 
19048
}    
 
19049
 
 
19050
 
 
19051
static Boolean AnyFeaturesArePseudo (ValNodePtr feat_list)
 
19052
{
 
19053
  Boolean any_pseudo = FALSE;
 
19054
 
 
19055
  SeqFeatPtr sfp;
 
19056
 
 
19057
  while (feat_list != NULL && !any_pseudo) {
 
19058
    sfp = (SeqFeatPtr) feat_list->data.ptrvalue;
 
19059
    if (sfp != NULL && sfp->pseudo) {
 
19060
      any_pseudo = TRUE;
 
19061
    }
 
19062
    feat_list = feat_list->next;
 
19063
  }
 
19064
  return any_pseudo;
 
19065
}
 
19066
 
 
19067
 
 
19068
static void RemoveNonPseudoFeatures (ValNodePtr PNTR feat_list)
 
19069
{
 
19070
  ValNodePtr prev = NULL, next_vnp, vnp;
 
19071
  SeqFeatPtr sfp;
 
19072
 
 
19073
  vnp = *feat_list;
 
19074
  while (vnp != NULL) {
 
19075
    next_vnp = vnp->next;
 
19076
    sfp = (SeqFeatPtr) vnp->data.ptrvalue;
 
19077
    if (sfp != NULL && !sfp->pseudo) {
 
19078
      if (prev == NULL) {
 
19079
        *feat_list = vnp->next;
 
19080
      } else {
 
19081
        prev->next = vnp->next;
 
19082
      }
 
19083
      vnp->next = NULL;
 
19084
      vnp = ValNodeFree (vnp);
 
19085
    } else {
 
19086
      prev = vnp;
 
19087
    }
 
19088
    vnp = next_vnp;
 
19089
  }    
 
19090
}
 
19091
 
 
19092
 
 
19093
static Pointer GetCDSConversionOpts (ValNodePtr feat_list, BaseFormPtr bfp, BoolPtr cancel)
 
19094
{
 
19095
  Boolean all_are_pseudo = TRUE, any_are_pseudo = FALSE, any_gps = FALSE;
 
19096
  CDSConversionOptsPtr opts;
 
19097
  ValNodePtr vnp;
 
19098
  SeqFeatPtr sfp;
 
19099
  
 
19100
  for (vnp = feat_list; vnp != NULL; vnp = vnp->next)
 
19101
  {
 
19102
    sfp = (SeqFeatPtr) vnp->data.ptrvalue;
 
19103
    if (sfp != NULL)
 
19104
    {
 
19105
      if (sfp->pseudo)
 
19106
      {
 
19107
        any_are_pseudo = TRUE;
 
19108
      }
 
19109
      else
 
19110
      {
 
19111
        all_are_pseudo = FALSE;
 
19112
      }
 
19113
      if (!any_gps)
 
19114
      {
 
19115
        any_gps = IsFeatInGPS (sfp);
 
19116
      }
 
19117
    }
 
19118
  }
 
19119
 
 
19120
  opts = GetCDSConversionOptions (all_are_pseudo, any_are_pseudo, any_gps, cancel);
 
19121
 
 
19122
  return opts;
 
19123
}
 
19124
 
 
19125
 
 
19126
static ValNodePtr AdjustCDSToMiscFeatList (ValNodePtr feat_list, Pointer extradata, BaseFormPtr bfp, BoolPtr cancel)
 
19127
{
 
19128
  CDSConversionOptsPtr opts;
 
19129
 
 
19130
  if (feat_list == NULL || extradata == NULL || cancel == NULL) return feat_list;
 
19131
  opts = (CDSConversionOptsPtr) extradata;
 
19132
  *cancel = FALSE;
 
19133
  if (opts->only_pseudo) {
 
19134
    /* remove features that are not pseudo */
 
19135
    RemoveNonPseudoFeatures (&feat_list);
 
19136
  }
 
19137
  return feat_list;
 
19138
}
 
19139
 
 
19140
 
 
19141
static void CDSToMiscFeatConversionCleanup (Uint2 entityID, Pointer extradata)
 
19142
{
 
19143
  SeqEntryPtr sep;
 
19144
 
 
19145
  DeleteMarkedObjects (entityID, 0, NULL);
 
19146
  sep = GetTopSeqEntryForEntityID (entityID);
 
19147
  RenormalizeNucProtSets (sep, TRUE);  
 
19148
}
 
19149
 
 
19150
 
 
19151
static Boolean CDSToMiscFeatConvertFunc (SeqFeatPtr sfp, Uint2 featdef_to, Pointer extradata)
 
19152
{
 
19153
  CDSConversionOptsPtr opts;
 
19154
  Boolean              rval = FALSE;
 
19155
 
 
19156
  opts = (CDSConversionOptsPtr) extradata;
 
19157
  if (opts == NULL || sfp == NULL || sfp->data.choice != SEQFEAT_CDREGION)
 
19158
  {
 
19159
    return FALSE;
 
19160
  }
 
19161
  else if (sfp->pseudo) 
 
19162
  {
 
19163
    rval = ConvertOnePseudoCDSToMiscFeat (sfp);
 
19164
  }
 
19165
  else
 
19166
  {
 
19167
    /* do other here */
 
19168
  
 
19169
    rval = ConvertOneCDSToMiscFeat (sfp, FALSE, FALSE, opts);
 
19170
  }
 
19171
  return TRUE;
 
19172
}
 
19173
 
 
19174
 
 
19175
typedef struct siteorbond {
 
19176
  Int4 site_or_bond_type;
 
19177
} SiteOrBondData, PNTR SiteOrBondPtr;
 
19178
 
 
19179
static Pointer GetSiteOrBondOpts (ValNodePtr feat_list, BaseFormPtr bfp, BoolPtr cancel, Uint2 toFeat)
 
19180
{
 
19181
  EnumFieldAssocPtr  al;
 
19182
  CharPtr            mssg;
 
19183
  UIEnum             val;
 
19184
  SiteOrBondPtr      opts = NULL;
 
19185
 
 
19186
  *cancel = FALSE;
 
19187
  al = NULL;
 
19188
  mssg = NULL;
 
19189
  if (toFeat == FEATDEF_BOND) {
 
19190
    al = enum_bond_alist;
 
19191
    mssg = "Select type of bond";
 
19192
  } else if (toFeat == FEATDEF_SITE) {
 
19193
    al = enum_site_alist;
 
19194
    mssg = "Select type of site";
 
19195
  } else {
 
19196
    *cancel = TRUE;
 
19197
    return NULL;
 
19198
  }
 
19199
 
 
19200
  if (al == NULL || ! AlistMessage (al, &val, 1, mssg)) 
 
19201
  {
 
19202
    *cancel = TRUE;
 
19203
  }
 
19204
  else
 
19205
  {
 
19206
    opts = (SiteOrBondPtr) MemNew (sizeof (SiteOrBondData));
 
19207
    opts->site_or_bond_type = (Int4) val; 
 
19208
  }
 
19209
  return opts;
 
19210
}
 
19211
 
 
19212
 
 
19213
static Pointer GetSiteOpts (ValNodePtr feat_list, BaseFormPtr bfp, BoolPtr cancel)
 
19214
{
 
19215
  return GetSiteOrBondOpts (feat_list, bfp, cancel, FEATDEF_SITE);
 
19216
}
 
19217
 
 
19218
 
 
19219
static Pointer GetBondOpts (ValNodePtr feat_list, BaseFormPtr bfp, BoolPtr cancel)
 
19220
{
 
19221
  return GetSiteOrBondOpts (feat_list, bfp, cancel, FEATDEF_BOND);
 
19222
}
 
19223
 
 
19224
 
 
19225
static Boolean ConvertToSiteOrBond (SeqFeatPtr sfp, Uint2 featdef_to, Pointer extradata)
 
19226
{
 
19227
  SiteOrBondPtr      opts = NULL;
 
19228
 
 
19229
  opts = (SiteOrBondPtr) extradata;
 
19230
  if (sfp == NULL || opts == NULL) return FALSE;
 
19231
 
 
19232
  return ConvertToBondSiteOrRegion (sfp, opts->site_or_bond_type, featdef_to, TRUE);
 
19233
}
 
19234
 
 
19235
typedef struct regionopts {
 
19236
  Boolean create_prot_feats;
 
19237
} RegionOptsData, PNTR RegionOptsPtr;
 
19238
 
 
19239
 
 
19240
static ValNodePtr GetBadProteinConversionFeatures (ValNodePtr feat_list)
 
19241
{
 
19242
  ValNodePtr no_cds_list = NULL, bad_coordinates_list = NULL, err_list = NULL, vnp;
 
19243
  Boolean    no_cds;
 
19244
  SeqLocPtr  slp;
 
19245
  SeqFeatPtr sfp;
 
19246
  BioseqPtr  bsp;
 
19247
 
 
19248
  for (vnp = feat_list; vnp != NULL; vnp = vnp->next) {
 
19249
    sfp = (SeqFeatPtr) vnp->data.ptrvalue;
 
19250
    bsp = BioseqFindFromSeqLoc (sfp->location);
 
19251
    if (bsp != NULL && ISA_aa (bsp->mol))
 
19252
    {
 
19253
      slp = FindNucleotideLocationForProteinFeatureConversion (sfp->location, sfp->idx.entityID);
 
19254
      if (slp == NULL)
 
19255
      {
 
19256
        no_cds = TRUE;
 
19257
      }
 
19258
    }
 
19259
    else
 
19260
    {
 
19261
      slp = GetProteinLocationForNucleotideFeatureConversion (sfp->location, &no_cds);
 
19262
    }
 
19263
    if (slp == NULL) {
 
19264
      if (no_cds) {
 
19265
        ValNodeAddPointer (&no_cds_list, OBJ_SEQFEAT, sfp);
 
19266
      } else {
 
19267
        ValNodeAddPointer (&bad_coordinates_list, OBJ_SEQFEAT, sfp);
 
19268
      }
 
19269
    } else {
 
19270
      slp = SeqLocFree (slp);
 
19271
    }
 
19272
  }
 
19273
 
 
19274
  if (no_cds_list != NULL) {
 
19275
    ValNodeAddPointer (&err_list, 0, NewClickableItem (0, "%d features have no overlapping coding region", no_cds_list));
 
19276
  }
 
19277
  if (bad_coordinates_list != NULL) {
 
19278
    ValNodeAddPointer (&err_list, 0, NewClickableItem (0, "%d features do not stop or start on codon boundaries", bad_coordinates_list));
 
19279
  }
 
19280
  return err_list;
 
19281
}
 
19282
 
 
19283
 
 
19284
static Pointer GetRegionOpts (ValNodePtr feat_list, BaseFormPtr bfp, BoolPtr cancel)
 
19285
{
 
19286
  ValNodePtr            err_list;
 
19287
  WindoW                w;
 
19288
  GrouP                 h, nuc_prot_choice, c;
 
19289
  DialoG                bad_prot_feats = NULL;
 
19290
  ButtoN                b;
 
19291
  ModalAcceptCancelData acd;
 
19292
  Boolean               rval = FALSE;
 
19293
  RegionOptsPtr         opts = NULL;
 
19294
  
 
19295
  *cancel = FALSE;
 
19296
 
 
19297
  if (feat_list == NULL) return NULL;
 
19298
  
 
19299
  err_list = GetBadProteinConversionFeatures (feat_list);
 
19300
    
 
19301
  w = MovableModalWindow(-20, -13, -10, -10, "Create Nucleotide or Protein Features", NULL);
 
19302
  h = HiddenGroup (w, -1, 0, NULL);
 
19303
  SetGroupSpacing (h, 10, 10);
 
19304
 
 
19305
  if (err_list != NULL) {
 
19306
    bad_prot_feats = CreateClickableListDialog (h, "Reasons", "Original Features",
 
19307
                                                ScrollToDiscrepancyItem, EditDiscrepancyItem, NULL,
 
19308
                                                GetDiscrepancyItemText);
 
19309
    PointerToDialog (bad_prot_feats, err_list);
 
19310
  }
 
19311
 
 
19312
  nuc_prot_choice = HiddenGroup (h, 0, 2, NULL);
 
19313
  RadioButton (nuc_prot_choice, "Create Nucleotide Features");
 
19314
  RadioButton (nuc_prot_choice, err_list == NULL ? "Create Protein Features" : "Create Protein Features (features listed above will be skipped)");
 
19315
  SetValue (nuc_prot_choice, err_list == NULL ? 2 : 1);
 
19316
  
 
19317
  c = HiddenGroup (h, 2, 0, NULL);
 
19318
  SetGroupSpacing (c, 10, 10);
 
19319
  b = PushButton (c, "Accept", ModalAcceptButton);
 
19320
  SetObjectExtra (b, &acd, NULL);
 
19321
  b = PushButton (c, "Cancel", ModalCancelButton);
 
19322
  SetObjectExtra (b, &acd, NULL);
 
19323
  AlignObjects (ALIGN_CENTER, (HANDLE) nuc_prot_choice,
 
19324
                              (HANDLE) c, 
 
19325
                              (HANDLE) bad_prot_feats, 
 
19326
                              NULL);
 
19327
  Show (w);
 
19328
  Select (w);
 
19329
  acd.accepted = FALSE;
 
19330
  acd.cancelled = FALSE;
 
19331
  while (!acd.accepted && ! acd.cancelled)
 
19332
  {
 
19333
    ProcessExternalEvent ();
 
19334
    Update ();
 
19335
  }
 
19336
  ProcessAnEvent ();
 
19337
  if (acd.cancelled)
 
19338
  {
 
19339
    *cancel = TRUE;
 
19340
  }
 
19341
  else
 
19342
  {
 
19343
    opts = (RegionOptsPtr) MemNew (sizeof (RegionOptsData));
 
19344
    if (GetValue (nuc_prot_choice) == 2)
 
19345
    {
 
19346
      opts->create_prot_feats = TRUE;
 
19347
    }
 
19348
    else
 
19349
    {
 
19350
      opts->create_prot_feats = FALSE;
 
19351
    }
 
19352
  }
 
19353
  Remove (w);
 
19354
  
 
19355
  return opts;
 
19356
}
 
19357
 
 
19358
 
 
19359
static void RemoveClickableItemFeaturesFromFeatureList (ClickableItemPtr cip, ValNodePtr PNTR feat_list)
 
19360
{
 
19361
  ValNodePtr vnp_i, vnp_p, vnp_r;
 
19362
 
 
19363
  if (cip == NULL || feat_list == NULL || *feat_list == NULL) return;
 
19364
  for (vnp_i = cip->item_list; vnp_i != NULL; vnp_i = vnp_i->next) {
 
19365
    if (vnp_i->choice != OBJ_SEQFEAT || vnp_i->data.ptrvalue == NULL) continue;
 
19366
    vnp_p = NULL;
 
19367
    vnp_r = *feat_list;
 
19368
    while (vnp_r != NULL && vnp_r->data.ptrvalue != vnp_i->data.ptrvalue) {
 
19369
      vnp_p = vnp_r;
 
19370
      vnp_r = vnp_r->next;
 
19371
    }
 
19372
    if (vnp_r != NULL) {
 
19373
      if (vnp_p == NULL) {
 
19374
        *feat_list = vnp_r->next;
 
19375
      } else {
 
19376
        vnp_p->next = vnp_r->next;
 
19377
      }
 
19378
      vnp_r->next = NULL;
 
19379
      vnp_r = ValNodeFree (vnp_r);
 
19380
    }
 
19381
  }
 
19382
  for (vnp_i = cip->subcategories; vnp_i != NULL; vnp_i = vnp_i->next) {
 
19383
    RemoveClickableItemFeaturesFromFeatureList (vnp_i->data.ptrvalue, feat_list);
 
19384
  }
 
19385
}
 
19386
 
 
19387
 
 
19388
static ValNodePtr AdjustRegionConversionFeatures (ValNodePtr feat_list, Pointer extradata, BaseFormPtr bfp, BoolPtr cancel)
 
19389
{
 
19390
  RegionOptsPtr opts = (RegionOptsPtr) extradata;
 
19391
  ValNodePtr    err_list, vnp_c;
 
19392
 
 
19393
  *cancel = FALSE;
 
19394
  if (opts == NULL || !opts->create_prot_feats) return feat_list;
 
19395
  
 
19396
  err_list = GetBadProteinConversionFeatures (feat_list);
 
19397
  
 
19398
  for (vnp_c = err_list; vnp_c != NULL; vnp_c = vnp_c->next) {
 
19399
    RemoveClickableItemFeaturesFromFeatureList (vnp_c->data.ptrvalue, &feat_list);
 
19400
  }
 
19401
  return feat_list;  
 
19402
}
 
19403
 
 
19404
 
 
19405
static Boolean ConvertAnyToRegion (SeqFeatPtr sfp, Uint2 featdef_to, Pointer extradata)
 
19406
{
 
19407
  RegionOptsPtr opts = (RegionOptsPtr) extradata;
 
19408
 
 
19409
  if (opts == NULL || sfp == NULL) return FALSE;
 
19410
  return ConvertToBondSiteOrRegion (sfp, 0, FEATDEF_REGION, opts->create_prot_feats);
 
19411
}
 
19412
 
 
19413
 
 
19414
static Boolean ConvertImpToImp (SeqFeatPtr sfp, Uint2 featdef_to, Pointer extradata)
 
19415
{
 
19416
  ImpFeatPtr         ifp;
 
19417
  CharPtr            featname;
 
19418
 
 
19419
  if (sfp == NULL || sfp->data.choice != SEQFEAT_IMP) return FALSE;
 
19420
 
 
19421
  ifp = (ImpFeatPtr) sfp->data.value.ptrvalue;
 
19422
  if (NULL == ifp)
 
19423
    return FALSE;
 
19424
  
 
19425
  featname = GetImportFeatureName (featdef_to);
 
19426
  ifp->key = MemFree (ifp->key);
 
19427
  if (featname == NULL)
 
19428
  {
 
19429
    ifp->key = StringSave ("misc_feature");
 
19430
  }
 
19431
  else
 
19432
  {
 
19433
    ifp->key = StringSave (featname);
 
19434
  }
 
19435
 
 
19436
  return TRUE;
 
19437
}
 
19438
 
 
19439
 
 
19440
static void CollectFeaturesToBeConverted (SeqFeatPtr sfp, Pointer userdata, FilterSetPtr fsp)
 
19441
{
 
19442
  ValNodePtr PNTR feat_list = (ValNodePtr PNTR) userdata;
 
19443
  
 
19444
  ValNodeAddPointer (feat_list, OBJ_SEQFEAT, sfp);
 
19445
}
 
19446
 
 
19447
 
 
19448
static void MoveInferenceToOverlappingGene (SeqFeatPtr sfp)
 
19449
{
 
19450
  GBQualPtr qual, qual_prev= NULL, qual_next;
 
19451
  SeqFeatPtr gene;
 
19452
 
 
19453
  if (sfp == NULL) return;
 
19454
 
 
19455
  gene = GetGeneForFeature (sfp);
 
19456
  if (gene == NULL || gene->idx.deleteme || gene == sfp) return;
 
19457
 
 
19458
  qual = sfp->qual;
 
19459
  while (qual != NULL) {
 
19460
    qual_next = qual->next;
 
19461
    if (StringCmp (qual->qual, "inference") == 0) {
 
19462
      if (qual_prev == NULL) {
 
19463
        sfp->qual = qual->next;
 
19464
      } else {
 
19465
        qual_prev->next = qual->next;
 
19466
      }
 
19467
      qual->next = NULL;
 
19468
      qual->next = gene->qual;
 
19469
      gene->qual = qual;
 
19470
    } else {
 
19471
      qual_prev = qual;
 
19472
    }
 
19473
    qual = qual_next;
 
19474
  }
 
19475
}
 
19476
 
 
19477
 
 
19478
static Boolean NewConvertFeaturesByList (SeqEntryPtr sep, FilterSetPtr fsp, Uint1 featdef_from, FeatureSelRemConvFormPtr mrfp)
 
19479
{
 
19480
  ValNodePtr feat_list = NULL, sel_feat_list = NULL, vnp;
 
19481
  Boolean not_match = FALSE;
 
19482
  Boolean    only_pseudo = FALSE;
 
19483
  SelStructPtr sel;
 
19484
  SeqFeatPtr   sfp;
 
19485
  SeqMgrFeatContext fcontext;
 
19486
  Int4              table_line_num = -1;
 
19487
  Uint2             seqfeat_from, seqfeat_to;
 
19488
  Pointer           extradata = NULL;
 
19489
  Boolean           cancel = FALSE;
 
19490
  ValNodePtr        dup_feat_vnp = NULL;
 
19491
  OrigFeatPtr       ofp;
 
19492
  Boolean           removed_cds = FALSE;
 
19493
  BioseqPtr         protBsp;
 
19494
 
 
19495
  OperateOnSeqEntryConstrainedObjects (sep, fsp, 
 
19496
                                       CollectFeaturesToBeConverted,
 
19497
                                       NULL, 0, featdef_from, 0, &feat_list);
 
19498
  sel = ObjMgrGetSelected ();
 
19499
  while (sel != NULL) {
 
19500
    if (sel->entityID == mrfp->input_entityID && sel->itemtype == OBJ_SEQFEAT) {
 
19501
      sfp = SeqMgrGetDesiredFeature (sel->entityID, NULL, sel->itemID, 0, NULL, &fcontext);
 
19502
      if (sfp != NULL) {
 
19503
        vnp = feat_list; 
 
19504
        while (vnp != NULL && vnp->data.ptrvalue != sfp) {
 
19505
          vnp = vnp->next;
 
19506
        }
 
19507
        if (vnp == NULL) {
 
19508
          not_match = TRUE;
 
19509
        }
 
19510
        ValNodeAddPointer (&sel_feat_list, OBJ_SEQFEAT, sfp);
 
19511
      }
 
19512
    }
 
19513
    sel = sel->next;
 
19514
  }
 
19515
  if (sel_feat_list != NULL) {
 
19516
    feat_list = ValNodeFree (feat_list);
 
19517
    if (not_match 
 
19518
        && Message (MSG_YN, 
 
19519
                    "Selected feature%s do%s not match options - apply to selected feature anyway?",
 
19520
                    sel_feat_list->next == NULL ? "" : "s",
 
19521
                    sel_feat_list->next == NULL ? "es" : "") == ANS_NO) {
 
19522
      sel_feat_list = ValNodeFree (sel_feat_list);
 
19523
      return FALSE;
 
19524
    }
 
19525
    feat_list = sel_feat_list;
 
19526
  }
 
19527
 
 
19528
  if (feat_list == NULL) {
 
19529
    Message (MSG_ERROR, "No features of the specified type exist to be converted!");
 
19530
    return FALSE;
 
19531
  }
 
19532
 
 
19533
  /* find line in table that applies */
 
19534
  seqfeat_from = FindFeatFromFeatDefType (featdef_from);
 
19535
  seqfeat_to =   FindFeatFromFeatDefType (mrfp->featdef_to);
 
19536
 
 
19537
  table_line_num = GetConvertFeatureTableLine (seqfeat_from, featdef_from, seqfeat_to, mrfp->featdef_to);
 
19538
  if (table_line_num < 0 || ConvertFeaturesTable[table_line_num].convert_func == NULL)
 
19539
  {
 
19540
    Message (MSG_ERROR, "This conversion not supported - contact"
16406
19541
             " sequindev for instructions.");
16407
 
    mrfp->abort_convert = TRUE;
16408
 
    return;
16409
 
  }
16410
 
  else if (fromFeat == SEQFEAT_IMP)
16411
 
    ConvertImpToImp (sfp, mrfp->featname_to);
16412
 
  else if (fromFeat == SEQFEAT_RNA)
16413
 
    FeatConvertRNAToRNA (sfp, mrfp->featdef_to);
16414
 
  else if (fromFeat == SEQFEAT_PROT)
16415
 
    FeatConvertProtToProt (sfp, mrfp->featdef_to);
16416
 
   
16417
 
  /* set the subtype to zero so that it will be reindexed */
16418
 
  sfp->idx.subtype = 0;
 
19542
    return FALSE;
 
19543
  }
 
19544
 
 
19545
  /* collect extra data if necessary */
 
19546
  if (ConvertFeaturesTable[table_line_num].collect_options != NULL)
 
19547
  {
 
19548
    extradata = (ConvertFeaturesTable[table_line_num].collect_options) (feat_list, mrfp->bfp, &cancel);
 
19549
    if (cancel)
 
19550
    {
 
19551
      feat_list = ValNodeFree (feat_list);
 
19552
      /* free extradata */
 
19553
      if (ConvertFeaturesTable[table_line_num].free_options != NULL)
 
19554
      {
 
19555
        (ConvertFeaturesTable[table_line_num].free_options) (extradata);
 
19556
      }
 
19557
      return FALSE;
 
19558
    }
 
19559
  }
 
19560
 
 
19561
  /* adjust feature list if necessary */  
 
19562
  if (ConvertFeaturesTable[table_line_num].adjust_features != NULL) 
 
19563
  {
 
19564
    feat_list = (ConvertFeaturesTable[table_line_num].adjust_features) (feat_list, extradata, mrfp->bfp, &cancel);
 
19565
    if (cancel || feat_list == NULL)
 
19566
    {
 
19567
      feat_list = ValNodeFree (feat_list);
 
19568
      /* free extradata */
 
19569
      if (ConvertFeaturesTable[table_line_num].free_options != NULL)
 
19570
      {
 
19571
        (ConvertFeaturesTable[table_line_num].free_options) (extradata);
 
19572
      }
 
19573
      return FALSE;
 
19574
    }
 
19575
  }
 
19576
 
 
19577
  /* process list */
 
19578
  for (vnp = feat_list; vnp != NULL; vnp = vnp->next)
 
19579
  {
 
19580
    sfp = (SeqFeatPtr) vnp->data.ptrvalue;
 
19581
    if (sfp == NULL) continue;
 
19582
    protBsp = NULL;
 
19583
    if (sfp->data.choice == SEQFEAT_CDREGION && !mrfp->leave_original_feature)
 
19584
    {
 
19585
      protBsp = BioseqFindFromSeqLoc (sfp->product);
 
19586
      if (protBsp != NULL)
 
19587
      {
 
19588
        protBsp->idx.deleteme = TRUE;
 
19589
      }
 
19590
      removed_cds = TRUE;
 
19591
    }
 
19592
      
 
19593
    dup_feat_vnp = NULL;
 
19594
    if (mrfp->leave_original_feature)
 
19595
    {
 
19596
      /* need a list of duplicate features that we can add to the appropriate SeqEntrys
 
19597
       * when we are done with the conversions.
 
19598
       */
 
19599
      dup_feat_vnp = AddDuplicateFeature (sfp, &(mrfp->feat_list)); 
 
19600
    }
 
19601
 
 
19602
    if (ConvertFeaturesTable[table_line_num].convert_func (sfp, mrfp->featdef_to, extradata))
 
19603
    {
 
19604
      /* set the subtype to zero so that it will be reindexed */
 
19605
      sfp->idx.subtype = 0;
 
19606
      if (mrfp->featdef_to == FEATDEF_misc_feature)
 
19607
      {
 
19608
        MoveInferenceToOverlappingGene (sfp);
 
19609
      }
 
19610
    }
 
19611
    else if (dup_feat_vnp != NULL && dup_feat_vnp->data.ptrvalue != NULL)
 
19612
    {
 
19613
      /* feature wasn't removed, for whatever reason */
 
19614
      /* remove the duplicate feature from the list to be added later */
 
19615
      ofp = (OrigFeatPtr) dup_feat_vnp->data.ptrvalue;
 
19616
      ofp->sfp = SeqFeatFree (ofp->sfp);
 
19617
      ofp->sep = NULL;
 
19618
 
 
19619
      /* don't remove protein product if feature wasn't removed */
 
19620
      if (protBsp != NULL)
 
19621
      {
 
19622
        protBsp->idx.deleteme = FALSE;
 
19623
      }
 
19624
    }
 
19625
  }
 
19626
 
 
19627
  feat_list = ValNodeFree (feat_list);
 
19628
 
 
19629
  /* do cleanup tasks */
 
19630
  if (ConvertFeaturesTable[table_line_num].cleanup_func != NULL)
 
19631
  {
 
19632
    (ConvertFeaturesTable[table_line_num].cleanup_func) (mrfp->input_entityID, extradata);
 
19633
  }
 
19634
 
 
19635
  /* free extradata */
 
19636
  if (ConvertFeaturesTable[table_line_num].free_options != NULL)
 
19637
  {
 
19638
    (ConvertFeaturesTable[table_line_num].free_options) (extradata);
 
19639
  }
 
19640
 
 
19641
  if (removed_cds)
 
19642
  {
 
19643
    DeleteMarkedObjects (mrfp->input_entityID, 0, NULL);
 
19644
    RenormalizeNucProtSets (sep, TRUE);         
 
19645
  }
 
19646
 
 
19647
  return TRUE;
16419
19648
}
16420
19649
 
 
19650
 
16421
19651
static void RemoveProteinProducts (ValNodePtr bsplist, Uint2 entityID, SeqEntryPtr sep)
16422
19652
{
16423
19653
  MsgAnswer  ans;
16492
19722
  }
16493
19723
}
16494
19724
 
 
19725
static Boolean GetNucOrProtChoiceForConversion (ValNodePtr PNTR feat_list, BoolPtr use_prot)
 
19726
{
 
19727
  ValNodePtr            err_list, vnp_c;
 
19728
  WindoW                w;
 
19729
  GrouP                 h, nuc_prot_choice, c;
 
19730
  DialoG                bad_prot_feats = NULL;
 
19731
  ButtoN                b;
 
19732
  ModalAcceptCancelData acd;
 
19733
  Boolean               rval = FALSE;
 
19734
 
 
19735
  if (feat_list == NULL || *feat_list == NULL || use_prot == NULL) return FALSE;
 
19736
 
 
19737
  err_list = GetBadProteinConversionFeatures (*feat_list);
 
19738
   
 
19739
  w = MovableModalWindow(-20, -13, -10, -10, "Create Nucleotide or Protein Features", NULL);
 
19740
  h = HiddenGroup (w, -1, 0, NULL);
 
19741
  SetGroupSpacing (h, 10, 10);
 
19742
 
 
19743
  if (err_list != NULL) {
 
19744
    bad_prot_feats = CreateClickableListDialog (h, "Reasons", "Original Features",
 
19745
                                                ScrollToDiscrepancyItem, EditDiscrepancyItem, NULL,
 
19746
                                                GetDiscrepancyItemText);
 
19747
    PointerToDialog (bad_prot_feats, err_list);
 
19748
  }
 
19749
 
 
19750
  nuc_prot_choice = HiddenGroup (h, 0, 2, NULL);
 
19751
  RadioButton (nuc_prot_choice, "Create Nucleotide Features");
 
19752
  RadioButton (nuc_prot_choice, err_list == NULL ? "Create Protein Features" : "Create Protein Features (features listed above will be skipped)");
 
19753
  SetValue (nuc_prot_choice, err_list == NULL ? 2 : 1);
 
19754
 
 
19755
  c = HiddenGroup (h, 2, 0, NULL);
 
19756
  SetGroupSpacing (c, 10, 10);
 
19757
  b = PushButton (c, "Accept", ModalAcceptButton);
 
19758
  SetObjectExtra (b, &acd, NULL);
 
19759
  b = PushButton (c, "Cancel", ModalCancelButton);
 
19760
  SetObjectExtra (b, &acd, NULL);
 
19761
  AlignObjects (ALIGN_CENTER, (HANDLE) nuc_prot_choice,
 
19762
                              (HANDLE) c,
 
19763
                              (HANDLE) bad_prot_feats,
 
19764
                              NULL);
 
19765
  Show (w);
 
19766
  Select (w);
 
19767
  acd.accepted = FALSE;
 
19768
  acd.cancelled = FALSE;
 
19769
  while (!acd.accepted && ! acd.cancelled)
 
19770
  {
 
19771
    ProcessExternalEvent ();
 
19772
    Update ();
 
19773
  }
 
19774
  ProcessAnEvent ();
 
19775
  if (acd.cancelled)
 
19776
  {
 
19777
    rval = FALSE;
 
19778
  }
 
19779
  else if (GetValue (nuc_prot_choice) == 2)
 
19780
  {
 
19781
    *use_prot = TRUE;
 
19782
    if (err_list != NULL) {
 
19783
      for (vnp_c = err_list; vnp_c != NULL; vnp_c = vnp_c->next) {
 
19784
        RemoveClickableItemFeaturesFromFeatureList (vnp_c->data.ptrvalue, feat_list);
 
19785
      }
 
19786
    }
 
19787
    rval = TRUE;
 
19788
  } else {
 
19789
    *use_prot = FALSE;
 
19790
    rval = TRUE;
 
19791
  }
 
19792
  Remove (w);
 
19793
  return rval;
 
19794
}
 
19795
 
 
19796
 
 
19797
 
 
19798
 
16495
19799
static Boolean FeatureRemoveOrConvertAction (Pointer userdata)
16496
19800
{
16497
19801
  FeatureSelRemConvFormPtr   mrfp;
16503
19807
  RemoveFeatureData     rfd;
16504
19808
  OrigFeatPtr           ofp;
16505
19809
  SeqFeatPtr            sfp;
 
19810
  Boolean               rval = TRUE;
16506
19811
  
16507
19812
  if (userdata == NULL) return FALSE;
16508
19813
  
16509
19814
  mrfp = (FeatureSelRemConvFormPtr) userdata;
16510
 
  mrfp->abort_convert = FALSE;
16511
19815
  window_action = GetValue (mrfp->action_choice);
16512
19816
  
16513
19817
  fsp = (FilterSetPtr) DialogToPointer (mrfp->constraints);
16524
19828
      return FALSE;
16525
19829
    }
16526
19830
    mrfp->featdef_to = vnp->choice;
16527
 
    mrfp->featname_to = vnp->data.ptrvalue;
16528
19831
    /* NOTE - I do not need to use ValNodeFreeData because I'm using
16529
19832
     * the data.ptrvalue in mrfp->featname_to and will free it when I free
16530
19833
     * mrfp.
16553
19856
    switch (window_action)
16554
19857
    {
16555
19858
      case FEATURE_CONVERT:
16556
 
        if ((feat_def_choice == FEATDEF_CDS || feat_def_choice == FEATDEF_GENE)
16557
 
            && mrfp->featdef_to == SEQFEAT_RNA)
16558
 
        {
16559
 
          mrfp->ask_for_transcript_id_removal = TRUE;
16560
 
        }
16561
 
        OperateOnSeqEntryConstrainedObjects (sep, fsp, 
16562
 
                                             ConvertFeatureCallback,
16563
 
                                             NULL, 0, feat_def_choice, 0, mrfp);
 
19859
        rval = NewConvertFeaturesByList (sep, fsp, feat_def_choice, mrfp);
16564
19860
        break;
16565
19861
      case FEATURE_REMOVE:
16566
19862
        rfd.bsplist = NULL;
16607
19903
    }
16608
19904
  }
16609
19905
  mrfp->feat_list = ValNodeFreeData (mrfp->feat_list);
 
19906
 
 
19907
  if (mrfp->renormalize_nucprot) {
 
19908
    RenormalizeNucProtSets (sep, TRUE);         
 
19909
  }
16610
19910
  
16611
19911
  ObjMgrSetDirtyFlag (mrfp->input_entityID, TRUE);
16612
19912
  ObjMgrSendMsg (OM_MSG_UPDATE, mrfp->input_entityID, 0, 0);  
16613
19913
  Update ();
16614
 
  return TRUE;
 
19914
  return rval;
16615
19915
}
16616
19916
 
16617
19917
static void FeatureRemoveOrConvert (IteM i, Int4 first_action)
16619
19919
  BaseFormPtr         bfp;
16620
19920
  FeatureSelRemConvFormPtr mrfp;
16621
19921
  WindoW              w;
16622
 
  GrouP               h, k, n;
 
19922
  GrouP               h, k, g, n;
16623
19923
  SeqEntryPtr         sep;
16624
19924
 
16625
19925
#ifdef WIN_MAC
16632
19932
  mrfp = (FeatureSelRemConvFormPtr) MemNew (sizeof (FeatureSelRemConvFormData));
16633
19933
  if (mrfp == NULL) return;
16634
19934
  
 
19935
  mrfp->bfp = bfp;
 
19936
  
16635
19937
  w = FixedWindow (-50, -33, -10, -10, "Remove or Convert Features", StdCloseWindowProc);
16636
19938
  SetObjectExtra (w, mrfp, CleanupFeatureSelRemConvForm);
16637
19939
  mrfp->form = (ForM) w;
16661
19963
                                                  FeatureRemoveChangeNotify, 
16662
19964
                                                  mrfp);
16663
19965
  
16664
 
  mrfp->convert_grp = HiddenGroup (n, 2, 0, NULL);
 
19966
  mrfp->convert_grp = HiddenGroup (n, 3, 0, NULL);
16665
19967
  k = HiddenGroup (mrfp->convert_grp, 0, 2, NULL);
16666
19968
  mrfp->from_prompt = StaticPrompt (k, "From", 0, dialogTextHeight, systemFont, 'l');
16667
19969
  mrfp->feature_select_from =  FeatureSelectionDialogEx (k, FALSE, sep,
16675
19977
                                                  mrfp);
16676
19978
  AlignObjects (ALIGN_CENTER, (HANDLE) mrfp->to_prompt, (HANDLE) mrfp->feature_select_to, NULL);
16677
19979
  AlignObjects (ALIGN_CENTER, (HANDLE) mrfp->remove_grp, (HANDLE) mrfp->convert_grp, NULL);
16678
 
  mrfp->leave_original_feature_btn = CheckBox (mrfp->convert_grp, "Leave Original Feature", NULL);
 
19980
 
 
19981
  g = HiddenGroup (mrfp->convert_grp, 0, 2, NULL);
 
19982
  StaticPrompt (g, "Conversion Function", 0, dialogTextHeight, systemFont, 'c');
 
19983
  SelectFont (systemFont);
 
19984
  mrfp->help_text = DocumentPanel (g, stdCharWidth * 12, LineHeight () * (TALL_SELECTION_LIST + 1));
 
19985
 
 
19986
  mrfp->leave_original_feature_btn = CheckBox (mrfp->convert_grp, "Leave Original Feature", FeatureRemoveChangeButton);
 
19987
  SetObjectExtra (mrfp->leave_original_feature_btn, mrfp, NULL);
16679
19988
  SetStatus (mrfp->leave_original_feature_btn, FALSE);
16680
19989
  AlignObjects (ALIGN_CENTER, (HANDLE) k, (HANDLE) mrfp->leave_original_feature_btn, NULL);
16681
19990
  
16682
19991
  mrfp->feat_list = NULL;
16683
 
  mrfp->constraints = FilterGroup (h, TRUE, FALSE, TRUE, FALSE, "Where feature text");
 
19992
  mrfp->constraints = FilterGroup (h, TRUE, FALSE, TRUE, FALSE, TRUE, "Where feature text");
16684
19993
  mrfp->accept_cancel = AcceptCancelDialog (h, FeatureRemoveOrConvertAction, NULL, FeatureRemoveClear, FeatureRemoveClearText, (Pointer)mrfp, w);
16685
19994
  AlignObjects (ALIGN_CENTER, (HANDLE) mrfp->action_choice,
16686
19995
                              (HANDLE) mrfp->clear_constraints_on_action_change,
16778
20087
                                                  FeatureRemoveChangeNotify, 
16779
20088
                                                  mrfp);
16780
20089
    
16781
 
  mrfp->constraints = FilterGroup (h, TRUE, FALSE, TRUE, FALSE, "Where feature text");
 
20090
  mrfp->constraints = FilterGroup (h, TRUE, FALSE, TRUE, FALSE, FALSE, "Where feature text");
16782
20091
  mrfp->accept_cancel = AcceptCancelDialog (h, SelectFeatureAction, NULL, FeatureRemoveClear, FeatureRemoveClearText, (Pointer)mrfp, w);
16783
20092
  AlignObjects (ALIGN_CENTER, (HANDLE) mrfp->feature_select,
16784
20093
                              (HANDLE) mrfp->constraints,
16787
20096
  Show (w);
16788
20097
}
16789
20098
 
 
20099
 
 
20100
typedef struct reverseintervalsform
 
20101
{
 
20102
  FORM_MESSAGE_BLOCK
 
20103
  DialoG  feature_select;
 
20104
  DialoG  constraints;
 
20105
  DialoG  accept_cancel;
 
20106
 
 
20107
  ValNodePtr feat_list;
 
20108
  BaseFormPtr bfp;
 
20109
} ReverseIntervalsFormData, PNTR ReverseIntervalsFormPtr;
 
20110
 
 
20111
static void ReverseIntervalsChangeNotify (Pointer userdata)
 
20112
{
 
20113
  ReverseIntervalsFormPtr fp;
 
20114
  ValNodePtr          err_list;
 
20115
 
 
20116
  fp = (ReverseIntervalsFormPtr) userdata;
 
20117
  if (fp == NULL) return;
 
20118
 
 
20119
  err_list = TestDialog (fp->feature_select);
 
20120
  
 
20121
  if (err_list == NULL)
 
20122
  {
 
20123
    EnableAcceptCancelDialogAccept (fp->accept_cancel);
 
20124
  }
 
20125
  else
 
20126
  {
 
20127
    DisableAcceptCancelDialogAccept (fp->accept_cancel);
 
20128
  }
 
20129
  ValNodeFree (err_list);
 
20130
}
 
20131
 
 
20132
static void ReverseIntervalsClearText (Pointer data)
 
20133
{
 
20134
  ReverseIntervalsFormPtr   mrfp;
 
20135
  FilterSetPtr          fsp;
 
20136
 
 
20137
  mrfp = (ReverseIntervalsFormPtr) data;
 
20138
  if (mrfp == NULL) return;
 
20139
 
 
20140
  fsp = DialogToPointer (mrfp->constraints);
 
20141
  FilterSetClearText (fsp);
 
20142
  PointerToDialog (mrfp->constraints, fsp);
 
20143
  FilterSetFree (fsp);
 
20144
}
 
20145
 
 
20146
static void ReverseIntervalsClear (Pointer data)
 
20147
{
 
20148
  ReverseIntervalsFormPtr mrfp;
 
20149
 
 
20150
  mrfp = (ReverseIntervalsFormPtr) data;
 
20151
  if (mrfp == NULL) return;
 
20152
 
 
20153
  PointerToDialog (mrfp->feature_select, NULL);
 
20154
  PointerToDialog (mrfp->constraints, NULL);
 
20155
}
 
20156
 
 
20157
static void ReverseLocationIntervalOrder (SeqLocPtr slp)
 
20158
{
 
20159
  SeqLocPtr     subslp_list = NULL, subslp, subslp_next;
 
20160
  PackSeqPntPtr pspp;
 
20161
  Int4 pnt_num, swap;
 
20162
 
 
20163
  if (slp == NULL 
 
20164
      || slp->choice == SEQLOC_NULL
 
20165
      || slp->choice == SEQLOC_EMPTY
 
20166
      || slp->choice == SEQLOC_WHOLE
 
20167
      || slp->choice == SEQLOC_INT
 
20168
      || slp->choice == SEQLOC_PNT
 
20169
      || slp->choice == SEQLOC_BOND
 
20170
      || slp->choice == SEQLOC_FEAT) {
 
20171
    return;
 
20172
  }
 
20173
  if (slp->choice == SEQLOC_MIX
 
20174
      || slp->choice == SEQLOC_PACKED_INT
 
20175
      || slp->choice == SEQLOC_EQUIV) {
 
20176
    for (subslp = slp->data.ptrvalue;
 
20177
         subslp != NULL;
 
20178
         subslp = subslp_next) {
 
20179
      subslp_next = subslp->next;
 
20180
      subslp->next = subslp_list;
 
20181
      subslp_list = subslp;
 
20182
      ReverseLocationIntervalOrder (subslp);
 
20183
    }
 
20184
    slp->data.ptrvalue = subslp_list;
 
20185
  } else if (slp->choice == SEQLOC_PACKED_PNT) {
 
20186
    pspp = (PackSeqPntPtr) slp->data.ptrvalue;
 
20187
    if (pspp != NULL) {
 
20188
      for (pnt_num = 0; pnt_num < pspp->used / 2; pnt_num++) {
 
20189
        swap = pspp->pnts[pnt_num];
 
20190
        pspp->pnts[pnt_num] = pspp->pnts[pspp->used - 1 - pnt_num];
 
20191
        pspp->pnts[pspp->used - 1 - pnt_num] = swap;
 
20192
      }
 
20193
    }
 
20194
  }
 
20195
}
 
20196
 
 
20197
static void ReverseIntervalsCallback (SeqFeatPtr sfp, Pointer userdata, FilterSetPtr fsp)
 
20198
 
 
20199
{
 
20200
  if (sfp == NULL || sfp->location == NULL) return;
 
20201
 
 
20202
  ReverseLocationIntervalOrder (sfp->location);
 
20203
}
 
20204
 
 
20205
 
 
20206
static Boolean ReverseIntervalsAction (Pointer userdata)
 
20207
{
 
20208
  ReverseIntervalsFormPtr   mrfp;
 
20209
  FilterSetPtr          fsp;
 
20210
  SeqEntryPtr           sep;
 
20211
  ValNodePtr            feature_type_list, vnp;
 
20212
  Uint1                 feat_def_choice;
 
20213
  
 
20214
  if (userdata == NULL) return FALSE;
 
20215
  
 
20216
  mrfp = (ReverseIntervalsFormPtr) userdata;
 
20217
  fsp = (FilterSetPtr) DialogToPointer (mrfp->constraints);
 
20218
  
 
20219
  sep = GetTopSeqEntryForEntityID (mrfp->input_entityID);
 
20220
  if (sep == NULL) return FALSE;
 
20221
  
 
20222
  feature_type_list = (ValNodePtr) DialogToPointer (mrfp->feature_select);
 
20223
  if (feature_type_list == NULL)
 
20224
  {
 
20225
    FilterSetFree (fsp);
 
20226
    return FALSE;
 
20227
  }
 
20228
    
 
20229
  for (vnp = feature_type_list; vnp != NULL; vnp = vnp->next)
 
20230
  {
 
20231
    feat_def_choice = vnp->choice;
 
20232
    if (feat_def_choice == 255)
 
20233
    {
 
20234
      feat_def_choice = 0;
 
20235
    }
 
20236
    OperateOnSeqEntryConstrainedObjects (sep, fsp, 
 
20237
                                         ReverseIntervalsCallback,
 
20238
                                         NULL, 0, feat_def_choice, 0, NULL);
 
20239
  }
 
20240
  
 
20241
  ValNodeFree (feature_type_list);
 
20242
  FilterSetFree (fsp);
 
20243
  
 
20244
  ObjMgrSetDirtyFlag (mrfp->input_entityID, TRUE);
 
20245
  ObjMgrSendMsg (OM_MSG_UPDATE, mrfp->input_entityID, 0, 0);  
 
20246
  Update ();
 
20247
  return TRUE;
 
20248
}
 
20249
 
 
20250
extern void ReverseFeatureIntervals (IteM i)
 
20251
{
 
20252
  BaseFormPtr              bfp;
 
20253
  ReverseIntervalsFormPtr  fp;
 
20254
  WindoW                   w;
 
20255
  GrouP                    h;
 
20256
  SeqEntryPtr              sep;
 
20257
 
 
20258
#ifdef WIN_MAC
 
20259
  bfp = currentFormDataPtr;
 
20260
#else
 
20261
  bfp = GetObjectExtra (i);
 
20262
#endif
 
20263
  if (bfp == NULL) return;
 
20264
 
 
20265
  fp = (ReverseIntervalsFormPtr) MemNew (sizeof (ReverseIntervalsFormData));
 
20266
  if (fp == NULL) return;
 
20267
  
 
20268
  w = FixedWindow (-50, -33, -10, -10, "Reverse Feature Intervals", StdCloseWindowProc);
 
20269
  SetObjectExtra (w, fp, StdCleanupFormProc);
 
20270
  fp->form = (ForM) w;
 
20271
  fp->input_entityID = bfp->input_entityID;
 
20272
  sep = GetTopSeqEntryForEntityID(bfp->input_entityID);
 
20273
  
 
20274
  h = HiddenGroup (w, -1, 0, NULL);
 
20275
  SetGroupSpacing (h, 10, 10);
 
20276
 
 
20277
  fp->feature_select =  FeatureSelectionDialogEx (h, TRUE, sep,
 
20278
                                                  ReverseIntervalsChangeNotify, 
 
20279
                                                  fp);
 
20280
    
 
20281
  fp->constraints = FilterGroup (h, TRUE, FALSE, TRUE, FALSE, FALSE, "Where feature text");
 
20282
  fp->accept_cancel = AcceptCancelDialog (h, ReverseIntervalsAction, NULL, ReverseIntervalsClear, ReverseIntervalsClearText, (Pointer)fp, w);
 
20283
  AlignObjects (ALIGN_CENTER, (HANDLE) fp->feature_select,
 
20284
                              (HANDLE) fp->constraints,
 
20285
                              (HANDLE) fp->accept_cancel, NULL);
 
20286
                              
 
20287
  Show (w);
 
20288
}
 
20289
 
 
20290
 
 
20291
 
16790
20292
extern ParseFieldPtr ParseFieldFree (ParseFieldPtr pfp)
16791
20293
{
16792
20294
  if (pfp != NULL)
16793
20295
  {
16794
 
    pfp->feature_field = ValNodeFreeData (pfp->feature_field);
16795
 
    pfp->feature_subtype = ValNodeFreeData (pfp->feature_subtype);
 
20296
    switch (pfp->parse_field_type) {
 
20297
      case PARSE_FIELD_SOURCE_QUAL :
 
20298
      case PARSE_FIELD_FEATURE_NOTE:
 
20299
      case PARSE_FIELD_DBXREF:
 
20300
        pfp->feature_field = ValNodeFreeData (pfp->feature_field);
 
20301
        break;
 
20302
      case PARSE_FIELD_DEFLINE:
 
20303
      case PARSE_FIELD_BIOSRC_STRING:
 
20304
      case PARSE_FIELD_GENE_FIELD:
 
20305
      case PARSE_FIELD_RNA_FIELD:
 
20306
      case PARSE_FIELD_CDS_COMMENT:
 
20307
      case PARSE_FIELD_COMMENT_DESC:
 
20308
      case PARSE_FIELD_IMPORT_QUAL:
 
20309
      case PARSE_FIELD_PROTEIN_FIELD:
 
20310
        pfp->feature_field = ValNodeFree (pfp->feature_field);
 
20311
        break;
 
20312
      default:
 
20313
        pfp->feature_field = ValNodeFree (pfp->feature_field);
 
20314
    }
 
20315
 
 
20316
    if (pfp->parse_field_type == PARSE_FIELD_RNA_FIELD)
 
20317
    {
 
20318
      pfp->feature_subtype = ValNodeFree (pfp->feature_subtype);
 
20319
    }
 
20320
    else
 
20321
    {
 
20322
      pfp->feature_subtype = ValNodeFreeData (pfp->feature_subtype);
 
20323
    }
16796
20324
    pfp = MemFree (pfp);
16797
20325
  }
16798
20326
  return pfp;
16806
20334
  DialoG  destination_field;
16807
20335
  DialoG  accept_cancel;
16808
20336
  ButtoN  remove_from_parsed;
 
20337
  DialoG  change_case_dlg;
16809
20338
  
16810
20339
  ParseFieldPtr   dst_field_data;
16811
20340
  GetSamplePtr    gsp;
16812
20341
  ExistingTextPtr etp;
 
20342
  ChangeCasePtr   change_case;
16813
20343
} ParseFormData, PNTR ParseFormPtr;
16814
20344
 
16815
20345
static void CleanupParseForm (GraphiC g, VoidPtr data)
16821
20351
  {
16822
20352
    mp->gsp = GetSampleFree (mp->gsp);
16823
20353
    mp->etp = MemFree (mp->etp);
 
20354
    mp->change_case = MemFree (mp->change_case);
16824
20355
  }
16825
20356
  StdCleanupExtraProc (g, data);
16826
20357
}
16874
20405
                                            SEQFEAT_BIOSRC, 0,
16875
20406
                                            Seq_descr_source);
16876
20407
      break;
 
20408
    case PARSE_FIELD_DBXREF:
 
20409
      gsp = CheckForExistingTextInSeqEntry (sep, 
 
20410
                                            dst_field_data->feature_field, 
 
20411
                                            GetBioSourceFeatureDbxrefString,
 
20412
                                            GetBioSourceDescriptorDbxrefString,
 
20413
                                            ValNodeSimpleDataFree, ValNodeStringCopy,
 
20414
                                            fsp,
 
20415
                                            SEQFEAT_BIOSRC, 0,
 
20416
                                            Seq_descr_source);
 
20417
      break;
16877
20418
    case PARSE_FIELD_GENE_FIELD:
16878
20419
      gsp = CheckForExistingTextInSeqEntry (sep, 
16879
20420
                                            dst_field_data->feature_field, 
16883
20424
                                            fsp,
16884
20425
                                            SEQFEAT_GENE, 0, 0);
16885
20426
      break;
16886
 
    case PARSE_FIELD_MRNA_FIELD:
 
20427
    case PARSE_FIELD_RNA_FIELD:
16887
20428
      gsp = CheckForExistingTextInSeqEntry (sep, 
16888
20429
                                            dst_field_data->feature_field, 
16889
 
                                            GetmRNAFieldString,
 
20430
                                            GetRNAFieldString,
16890
20431
                                            NULL,
16891
20432
                                            NULL, IntValNodeCopy,
16892
20433
                                            fsp,
16893
 
                                            SEQFEAT_RNA, FEATDEF_mRNA, 0);
 
20434
                                            SEQFEAT_RNA, 
 
20435
                                            dst_field_data->feature_subtype == NULL ? 0 : dst_field_data->feature_subtype->data.intvalue, 0);
16894
20436
      break;
16895
20437
    case PARSE_FIELD_CDS_COMMENT:
16896
20438
      gsp = CheckForExistingTextInSeqEntry (sep, 
16992
20534
  return gsp;  
16993
20535
}
16994
20536
 
16995
 
static void GetParseToExistingTextCallback (ParseActionPtr pap, Pointer userdata, CharPtr found_text, Int4 found_len)
16996
 
{
16997
 
  ParseFormPtr mp;
16998
 
  GetSamplePtr gsp = NULL;
16999
 
  SeqEntryPtr  sep;
17000
 
  ValNodePtr   sum_vnp;
17001
 
 
17002
 
  mp = (ParseFormPtr) userdata;
17003
 
  if (mp == NULL || mp->dst_field_data == NULL)
17004
 
  {
17005
 
    return;
17006
 
  }
17007
 
  
17008
 
  if (mp->dst_field_data->parse_field_type == PARSE_FIELD_SOURCE_QUAL
17009
 
      || mp->dst_field_data->parse_field_type == PARSE_FIELD_BIOSRC_STRING)
17010
 
  {
17011
 
    sep = pap->biop_sep;
17012
 
  }
17013
 
  else if (mp->dst_field_data->parse_field_type == PARSE_FIELD_DEFLINE)
17014
 
  {
17015
 
    sep = pap->title_sep;
17016
 
  }
17017
 
  else
17018
 
  {
17019
 
    sep = pap->sep;
17020
 
  }
17021
 
  
17022
 
  gsp = GetSampleForSeqEntry (sep, mp->input_entityID, mp->dst_field_data, NULL);
17023
 
  
17024
 
  if (gsp == NULL)
17025
 
  {
17026
 
    return;
17027
 
  }
17028
 
  if (mp->gsp == NULL)
17029
 
  {
17030
 
    mp->gsp = gsp;
17031
 
  }
17032
 
  else
17033
 
  {
17034
 
    mp->gsp->num_found += gsp->num_found;
17035
 
    if (StringCmp (mp->gsp->sample_text, gsp->sample_text) != 0)
17036
 
    {
17037
 
      mp->gsp->all_same = FALSE;
17038
 
    }
17039
 
    
17040
 
    sum_vnp = AddValNodeLists (mp->gsp->feat_dest_list, gsp->feat_dest_list);
17041
 
    mp->gsp->feat_dest_list = ValNodeFree (mp->gsp->feat_dest_list);
17042
 
    mp->gsp->feat_dest_list = sum_vnp;
17043
 
    
17044
 
    sum_vnp = AddValNodeLists (mp->gsp->descr_dest_list, gsp->descr_dest_list);
17045
 
    mp->gsp->descr_dest_list = ValNodeFree (mp->gsp->descr_dest_list);
17046
 
    mp->gsp->descr_dest_list = sum_vnp;
17047
 
    
17048
 
    gsp = GetSampleFree (gsp);
17049
 
  } 
17050
 
}
17051
 
 
17052
20537
static void 
17053
20538
ParseToFeaturesOnBioseq 
17054
20539
(BioseqPtr             bsp, 
17079
20564
      prot_bsp = BioseqFindFromSeqLoc (sfp->product);
17080
20565
      if (prot_bsp == NULL)
17081
20566
      {
17082
 
            SeqEdTranslateOneCDS (sfp, bsp, sfp->idx.entityID);
 
20567
            SeqEdTranslateOneCDS (sfp, bsp, sfp->idx.entityID, Sequin_GlobalAlign2Seq);
17083
20568
            SeqMgrIndexFeatures (sfp->idx.entityID, NULL);
17084
20569
        prot_bsp = BioseqFindFromSeqLoc (sfp->product);
17085
20570
      }
17159
20644
    case PARSE_FIELD_GENE_FIELD :
17160
20645
      set_string_func = SetGeneFieldString;
17161
20646
      break;
17162
 
    case PARSE_FIELD_MRNA_FIELD :
17163
 
      set_string_func = SetmRNAFieldString;
 
20647
    case PARSE_FIELD_RNA_FIELD :
 
20648
      set_string_func = SetRNAFieldString;
17164
20649
      break;
17165
20650
    case PARSE_FIELD_CDS_COMMENT:
17166
20651
      set_string_func = SetCDSComment;
17256
20741
  avd.new_text [found_len] = 0;
17257
20742
  avd.etp = mp->etp;
17258
20743
  avd.text_to_replace = NULL;
 
20744
  avd.where_to_replace = EditApplyFindLocation_anywhere;
17259
20745
  
17260
20746
  switch (mp->dst_field_data->parse_field_type)
17261
20747
  {
17281
20767
                                           ApplySourceStringFeatureCallback,
17282
20768
                                           ApplySourceStringDescriptorCallback,
17283
20769
                                           0, 0, 0, &avd);
 
20770
    case PARSE_FIELD_DBXREF :
 
20771
      avd.field_list = mp->dst_field_data->feature_field;
 
20772
      OperateOnSeqEntryConstrainedObjects (pap->biop_sep, NULL, 
 
20773
                                           ApplyBioSourceDbxrefFeatureCallback,
 
20774
                                           ApplyBioSourceDbxrefDescriptorCallback,
 
20775
                                           0, 0, 0, &avd);
 
20776
      break;
17284
20777
    case PARSE_FIELD_GENE_FIELD :
17285
20778
      avd.field_list = mp->dst_field_data->feature_field;
17286
20779
      ParseToFeatures (pap->sep, &avd, mp->dst_field_data->parse_field_type,
17287
20780
                       FEATDEF_GENE);
17288
20781
      break;
17289
 
    case PARSE_FIELD_MRNA_FIELD :
 
20782
    case PARSE_FIELD_RNA_FIELD :
17290
20783
      avd.field_list = mp->dst_field_data->feature_field;
17291
20784
      ParseToFeatures (pap->sep, &avd, mp->dst_field_data->parse_field_type,
17292
 
                       FEATDEF_mRNA);
 
20785
                       mp->dst_field_data->feature_subtype == NULL ? 0 : mp->dst_field_data->feature_subtype->data.intvalue);
17293
20786
      break;
17294
20787
    case PARSE_FIELD_CDS_COMMENT:
17295
20788
      avd.field_list = NULL;
17374
20867
                                            NULL,
17375
20868
                                            SEQFEAT_BIOSRC, 0, Seq_descr_source);
17376
20869
      break;
 
20870
    case PARSE_FIELD_DBXREF:
 
20871
      gsp = CheckForExistingTextInSeqEntry (sep, dst_field_data->feature_field,
 
20872
                                            GetBioSourceFeatureDbxrefString,
 
20873
                                            GetBioSourceDescriptorDbxrefString,
 
20874
                                            ValNodeSimpleDataFree,
 
20875
                                            ValNodeStringCopy,
 
20876
                                            NULL,
 
20877
                                            SEQFEAT_BIOSRC, 0, Seq_descr_source);
 
20878
      break;
17377
20879
    case PARSE_FIELD_GENE_FIELD:
17378
20880
      gsp = CheckForExistingTextInSeqEntry (sep, dst_field_data->feature_field, 
17379
20881
                                            GetGeneFieldString,
17381
20883
                                            NULL, IntValNodeCopy,
17382
20884
                                            NULL, SEQFEAT_GENE, 0, 0);
17383
20885
      break;
17384
 
    case PARSE_FIELD_MRNA_FIELD:
 
20886
    case PARSE_FIELD_RNA_FIELD:
17385
20887
      gsp = CheckForExistingTextInSeqEntry (sep, dst_field_data->feature_field, 
17386
 
                                            GetmRNAFieldString,
 
20888
                                            GetRNAFieldString,
17387
20889
                                            NULL,
17388
20890
                                            NULL, IntValNodeCopy,
17389
 
                                            NULL, SEQFEAT_RNA, FEATDEF_mRNA, 0);
 
20891
                                            NULL, SEQFEAT_RNA, dst_field_data->feature_subtype == NULL ? 0 : dst_field_data->feature_subtype->data.intvalue, 0);
17390
20892
      break;
17391
20893
    case PARSE_FIELD_CDS_COMMENT:
17392
20894
      gsp = CheckForExistingTextInSeqEntry (sep, NULL, 
17450
20952
  return gsp;
17451
20953
}
17452
20954
 
17453
 
static Boolean ParseFileToDest (ParseFormPtr mp, FilterSetPtr fsp, TextPortionPtr tp, SeqEntryPtr sep)
 
20955
 
 
20956
static GetSamplePtr GetFlatFileParseProteinFieldSamples (Uint2 entityID, SeqEntryPtr sep, GetSamplePtr gsp, ParseFieldPtr dst_field_data)
17454
20957
{
17455
 
  ParseActionData     pad;
17456
 
  FILE                *fp;
17457
 
  Char                path [PATH_MAX];
17458
 
  ReadBufferData      rbd;
17459
 
  CharPtr             line;
17460
 
  CharPtr             found_loc = NULL;
17461
 
  Int4                found_len = 0;
17462
 
  GetSamplePtr        gsp;
17463
 
 
17464
 
  if (mp == NULL || tp == NULL || sep == NULL)
17465
 
  {
17466
 
    return FALSE;
17467
 
  }
17468
 
  ResetParseActionVisitData (&pad);
17469
 
  pad.fsp = fsp;
17470
 
  pad.tp = tp;
17471
 
 
17472
 
  gsp = GetDestSample (sep, mp->dst_field_data);
17473
 
  mp->etp = GetExistingTextHandlerInfo (gsp, FALSE);        
17474
 
  gsp = GetSampleFree (gsp);
17475
 
  if (mp->etp != NULL && mp->etp->existing_text_choice == EXISTING_TEXT_CHOICE_CANCEL)
17476
 
  {
17477
 
    mp->etp = MemFree (mp->etp);
17478
 
    return FALSE;
17479
 
  }
17480
 
  
17481
 
 
17482
 
  if (! GetInputFileName (path, sizeof (path), "", "TEXT")) 
17483
 
  {
17484
 
    mp->etp = MemFree (mp->etp);
17485
 
    return FALSE;
17486
 
  }
17487
 
  
17488
 
  fp = FileOpen (path, "r");
17489
 
  if (fp == NULL)
17490
 
  {
17491
 
    Message (MSG_ERROR, "Unable to open %s", path);
17492
 
    mp->etp = MemFree (mp->etp);
17493
 
    return FALSE;
17494
 
  }
17495
 
 
17496
 
  ResetParseActionVisitData (&pad);
17497
 
  pad.sep = sep;
17498
 
  pad.title_sep = sep;
17499
 
  pad.biop_sep = sep;
17500
 
 
17501
 
  rbd.fp = fp;
17502
 
  rbd.current_data = NULL;
17503
 
  line = AbstractReadFunction (&rbd);
17504
 
  while (line != NULL)
17505
 
  {
17506
 
    found_loc = NULL;
17507
 
    found_len = 0;
17508
 
    FindTextPortionInString (line, tp, &found_loc, &found_len);
17509
 
  
17510
 
    if (found_loc != NULL)
17511
 
    {
17512
 
      ParseToDest (&pad, mp, found_loc, found_len);
 
20958
  SeqEntryPtr  parent_sep, prot_sep;
 
20959
  BioseqSetPtr bssp;
 
20960
  GetSamplePtr new_gsp, sum_gsp;
 
20961
 
 
20962
  if (sep == NULL) return gsp;
 
20963
 
 
20964
  parent_sep = GetBestTopParentForData (entityID, sep->data.ptrvalue);
 
20965
 
 
20966
  if (parent_sep != NULL && IS_Bioseq_set (parent_sep)) {
 
20967
    bssp = (BioseqSetPtr) parent_sep->data.ptrvalue;
 
20968
    if (bssp != NULL && bssp->_class == BioseqseqSet_class_nuc_prot && bssp->seq_set != NULL) {
 
20969
      prot_sep = bssp->seq_set->next;
 
20970
      while (prot_sep != NULL) {
 
20971
        new_gsp = GetDestSample (prot_sep, dst_field_data);
 
20972
        sum_gsp = GetSampleAdd (gsp, new_gsp);
 
20973
        gsp = GetSampleFree (gsp);
 
20974
        new_gsp = GetSampleFree (new_gsp);
 
20975
        gsp = sum_gsp;
 
20976
        sum_gsp = NULL;
 
20977
        prot_sep = prot_sep->next;
 
20978
      }
17513
20979
    }
17514
 
    line = AbstractReadFunction (&rbd);
17515
20980
  }
17516
 
 
17517
 
  FileClose (fp);
17518
 
  mp->etp = MemFree (mp->etp);
17519
 
  
17520
 
  ObjMgrSetDirtyFlag (mp->input_entityID, TRUE);
17521
 
  ObjMgrSendMsg (OM_MSG_UPDATE, mp->input_entityID, 0, 0);
17522
 
  ArrowCursor ();
17523
 
  Update ();    
17524
 
  return TRUE;
 
20981
  return gsp;
17525
20982
}
17526
20983
 
17527
20984
static GetSamplePtr
17577
21034
        string = asn2gnbk_format (ajp, (Int4) index);
17578
21035
        if (string != NULL && *string != '\0') {
17579
21036
          CompressSpaces (string);
17580
 
          FindTextPortionInString (string, pap->tp, &found_loc, &found_len);
 
21037
          FindTextPortionXInString (string, pap->tp, &found_loc, &found_len);
17581
21038
  
17582
21039
          if (found_loc != NULL)
17583
21040
          {
17592
21049
            new_gsp = GetSampleFree (new_gsp);
17593
21050
            gsp = sum_gsp;
17594
21051
            sum_gsp = NULL;
 
21052
            if (mp->dst_field_data->parse_field_type == PARSE_FIELD_PROTEIN_FIELD) { 
 
21053
              /* also get samples from protein bioseqs in this nuc-prot set */
 
21054
              gsp = GetFlatFileParseProteinFieldSamples (mp->input_entityID, pap->sep, gsp, mp->dst_field_data);              
 
21055
            }
17595
21056
          }
17596
21057
        }
17597
21058
        MemFree (string);
17666
21127
        string = asn2gnbk_format (ajp, (Int4) index);
17667
21128
        if (string != NULL && *string != '\0') {
17668
21129
          CompressSpaces (string);
17669
 
          FindTextPortionInString (string, pap->tp, &found_loc, &found_len);
 
21130
          FindTextPortionXInString (string, pap->tp, &found_loc, &found_len);
17670
21131
  
17671
21132
          if (found_loc != NULL)
17672
21133
          {
17705
21166
{
17706
21167
  ParseFormPtr      mp;
17707
21168
  SeqEntryPtr         sep;
17708
 
  Char                path [PATH_MAX];
17709
 
  ParseActionLogData  pald;
17710
21169
  ParseActionData     pad;
17711
21170
  Boolean             rval = FALSE;
17712
 
  ParseFieldSrcPtr pfsp;
 
21171
  ParseFieldSrcPtr    pfsp;
 
21172
  SourceQualDescPtr   sqdp;
17713
21173
  Boolean             remove_from_parsed = FALSE;
17714
21174
 
17715
21175
  mp = (ParseFormPtr) data;
17726
21186
 
17727
21187
  pfsp = DialogToPointer (mp->source_field);
17728
21188
  if (pfsp == NULL 
17729
 
      || pfsp->parse_field < PARSE_FIELD_SRC_DEFLINE 
 
21189
      || pfsp->parse_field < eParseFieldSrcDefLine 
17730
21190
      || pfsp->parse_field > MAX_PARSE_FIELD
17731
 
      || (pfsp->parse_field == PARSE_FIELD_STRUCTURED_COMMENT && StringHasNoText (pfsp->comment_field)))
 
21191
      || (pfsp->parse_field == eParseFieldSrcStructuredComment && StringHasNoText (pfsp->comment_field))
 
21192
      || (pfsp->parse_field == eParseFieldSrcSourceQual && pfsp->sqdp == NULL))
17732
21193
  {
17733
21194
    pfsp = ParseFieldSrcFree (pfsp);
17734
21195
    return FALSE;
17736
21197
  pad.src_field = pfsp->parse_field;
17737
21198
  pad.comment_field = pfsp->comment_field;
17738
21199
  pfsp->comment_field = NULL;
 
21200
  sqdp = pfsp->sqdp;
 
21201
  pfsp->sqdp = NULL;
17739
21202
  pfsp = ParseFieldSrcFree (pfsp);
17740
21203
  
17741
21204
  pad.tp = DialogToPointer (mp->text_portion);
17743
21206
  pad.biop_sep = sep;
17744
21207
  pad.title_sep = sep;
17745
21208
  mp->dst_field_data = DialogToPointer (mp->destination_field);
 
21209
 
 
21210
  mp->change_case = DialogToPointer (mp->change_case_dlg);
17746
21211
  
17747
 
  if (pad.src_field == PARSE_FIELD_SRC_GENBANK_FLATFILE)
 
21212
  if (pad.src_field == eParseFieldSrcGenBankFlatFile)
17748
21213
  {
17749
21214
    WatchCursor ();
17750
21215
    ResetParseActionVisitData (&pad);
17751
21216
    
17752
21217
    mp->gsp = ParseFlatfileForSample (sep, &pad, mp, GENBANK_FMT, NULL);
17753
 
    mp->etp = GetExistingTextHandlerInfo (mp->gsp, FALSE);        
 
21218
    mp->etp = GetExistingTextHandlerInfo (mp->gsp == NULL ? 0 : mp->gsp->num_found, FALSE);        
17754
21219
    mp->gsp = GetSampleFree (mp->gsp);
17755
 
    if (mp->etp == NULL || mp->etp->existing_text_choice != EXISTING_TEXT_CHOICE_CANCEL)
 
21220
    if (mp->etp == NULL || mp->etp->existing_text_choice != eExistingTextChoiceCancel)
17756
21221
    {
17757
21222
      ResetParseActionVisitData (&pad);
17758
21223
      pad.biop_sep = sep;
17773
21238
      case PARSE_FIELD_DEFLINE:
17774
21239
      case PARSE_FIELD_BIOSRC_STRING:
17775
21240
      case PARSE_FIELD_GENE_FIELD:
17776
 
      case PARSE_FIELD_MRNA_FIELD:
 
21241
      case PARSE_FIELD_RNA_FIELD:
17777
21242
      case PARSE_FIELD_CDS_COMMENT:
17778
21243
      case PARSE_FIELD_PROTEIN_FIELD:
17779
21244
      case PARSE_FIELD_IMPORT_QUAL:
17780
21245
      case PARSE_FIELD_FEATURE_NOTE:
17781
21246
      case PARSE_FIELD_COMMENT_DESC:
 
21247
      case PARSE_FIELD_DBXREF:
17782
21248
        WatchCursor ();
17783
21249
        Update ();
17784
21250
        
17786
21252
            remove_from_parsed = GetStatus(mp->remove_from_parsed);
17787
21253
        }
17788
21254
        
17789
 
        rval = FindParseActionPairList (sep, pad.src_field, pad.comment_field, mp->dst_field_data, pad.fsp, pad.tp, remove_from_parsed);
 
21255
        rval = FindParseActionPairList (sep, pad.src_field, sqdp, pad.comment_field, mp->dst_field_data, pad.fsp, pad.tp, remove_from_parsed, mp->change_case);
17790
21256
        ObjMgrSetDirtyFlag (mp->input_entityID, TRUE);
17791
21257
        ObjMgrSendMsg (OM_MSG_UPDATE, mp->input_entityID, 0, 0);
17792
21258
        ArrowCursor ();
17793
21259
        Update ();    
17794
21260
        break;
17795
21261
      default:
17796
 
        pald.data_in_log = FALSE;
17797
 
        TmpNam (path);
17798
 
        pald.fp = FileOpen (path, "wb");
17799
 
        if (pald.fp != NULL)
17800
 
        {
17801
 
          VisitSeqEntriesForParseAction (sep, &pad, ParseActionSample, &pald, FALSE);
17802
 
          FileClose (pald.fp);
17803
 
          LaunchGeneralTextViewer (path, "Found Text");
17804
 
          FileRemove (path);
17805
 
          rval = TRUE;
17806
 
        }
 
21262
        Message (MSG_ERROR, "Unknown destination");
17807
21263
        break;
17808
21264
    }
17809
21265
  }
17810
21266
  
17811
 
  pad.tp = TextPortionFree (pad.tp);
 
21267
  pad.tp = TextPortionXFree (pad.tp);
17812
21268
  pad.comment_field = MemFree (pad.comment_field);
17813
21269
  FilterSetFree (pad.fsp);
17814
21270
  return rval;
17832
21288
static void ParseFormClearText (Pointer data)
17833
21289
{
17834
21290
  ParseFormPtr      mp;
17835
 
  TextPortionPtr      tp;
 
21291
  TextPortionXPtr      tp;
17836
21292
 
17837
21293
  mp = (ParseFormPtr) data;
17838
21294
  if (mp == NULL)
17880
21336
  /* only allow remove_from_parsed if not parsing from flatfile or local ID */
17881
21337
  pfsp = DialogToPointer (mp->source_field);
17882
21338
  if (pfsp != NULL 
17883
 
      && (pfsp->parse_field == PARSE_FIELD_SRC_GENBANK_FLATFILE
17884
 
          || pfsp->parse_field == PARSE_FIELD_SRC_LOCAL_ID)) {
 
21339
      && (pfsp->parse_field == eParseFieldSrcGenBankFlatFile
 
21340
          || pfsp->parse_field == eParseFieldSrcLocalID
 
21341
          || pfsp->parse_field == eParseFieldSrcFileID)) {
17885
21342
      Disable (mp->remove_from_parsed);
17886
21343
  } else {
17887
21344
      Enable (mp->remove_from_parsed);
17916
21373
  
17917
21374
  g1 = HiddenGroup (h, 2, 0, NULL);
17918
21375
  StaticPrompt (g1, "Select text", 0, dialogTextHeight, systemFont, 'l');
17919
 
  mp->text_portion = TextPortionDialog (g1);
 
21376
  mp->text_portion = TextPortionXDialog (g1);
17920
21377
  
17921
21378
  g2 = HiddenGroup (h, 2, 0, NULL);
17922
21379
  StaticPrompt (g2, "From", 0, dialogTextHeight, systemFont, 'l');
17924
21381
  
17925
21382
  g3 = HiddenGroup (h, 2, 0, NULL);
17926
21383
  StaticPrompt (g3, "And place in", 0, dialogTextHeight, systemFont, 'l');
17927
 
  mp->destination_field = ParseFieldDestDialog (g3, ParseChangeNotify, mp);
 
21384
  mp->destination_field =   ParseFieldDestDialogEx (g3, ParseChangeNotify, mp, FALSE, TRUE);
17928
21385
  
 
21386
  mp->change_case_dlg = ChangeCaseDialog (h);
 
21387
 
17929
21388
  mp->remove_from_parsed = CheckBox (h, "Remove from parsed field", NULL);  
17930
21389
  
17931
21390
  mp->accept_cancel = AcceptCancelDialog (h, ParseTextAction, NULL, ParseFormClear, ParseFormClearText, (Pointer)mp, w);  
17932
21391
  AlignObjects (ALIGN_CENTER, (HANDLE) g1,
17933
21392
                              (HANDLE) g2,
17934
21393
                              (HANDLE) g3,
 
21394
                              (HANDLE) mp->change_case_dlg,
17935
21395
                              (HANDLE) mp->remove_from_parsed,
17936
21396
                              (HANDLE) mp->accept_cancel,
17937
21397
                              NULL);
17941
21401
  {
17942
21402
    pfsd.parse_field = from_field;
17943
21403
    pfsd.comment_field = NULL;
 
21404
    pfsd.sqdp = NULL;
17944
21405
    PointerToDialog (mp->source_field, &pfsd);
17945
21406
  }
17946
21407
  if (to_field > 0)
17968
21429
 
17969
21430
extern void ParseDefLineToSourceQual (IteM i)
17970
21431
{
17971
 
  ParseTextItem (i, PARSE_FIELD_SRC_DEFLINE, PARSE_FIELD_SOURCE_QUAL);
 
21432
  ParseTextItem (i, eParseFieldSrcDefLine, PARSE_FIELD_SOURCE_QUAL);
 
21433
}
 
21434
 
 
21435
extern void ParseTaxnameToSourceQual (IteM i)
 
21436
{
 
21437
  ParseTextItem (i, eParseFieldSrcTaxNameAfterNomial, PARSE_FIELD_SOURCE_QUAL);
17972
21438
}
17973
21439
 
17974
21440
extern void ParseFlatfileToSourceQual (IteM i)
17975
21441
{
17976
 
  ParseTextItem (i, PARSE_FIELD_SRC_GENBANK_FLATFILE, PARSE_FIELD_SOURCE_QUAL);
 
21442
  ParseTextItem (i, eParseFieldSrcGenBankFlatFile, PARSE_FIELD_SOURCE_QUAL);
17977
21443
}
17978
21444
 
17979
21445
static void ParseTextToolBtn (ButtoN b, Int4 from_field, Int4 to_field)
17988
21454
 
17989
21455
extern void ParseLocalIDToSourceQual (ButtoN b)
17990
21456
{
17991
 
  ParseTextToolBtn (b, PARSE_FIELD_SRC_LOCAL_ID, PARSE_FIELD_SOURCE_QUAL);
 
21457
  ParseTextToolBtn (b, eParseFieldSrcLocalID, PARSE_FIELD_SOURCE_QUAL);
17992
21458
}
17993
21459
 
17994
21460
 
18066
21532
  GrouP      pseudo_action;
18067
21533
  Boolean    pseudo_val;
18068
21534
  
 
21535
  /* for inferences */
 
21536
  DialoG     inference_dlg;
18069
21537
} FeatEdData, PNTR FeatEdPtr;
18070
21538
 
18071
21539
static void FeatEdChangeNotify (Pointer userdata)
18101
21569
  }
18102
21570
  
18103
21571
  err_list = TestDialog (mp->feature_select);
 
21572
 
 
21573
  if (GetValue (mp->action_choice_grp) == FEAT_ED_INFERENCE)
 
21574
  {
 
21575
    ValNodeLink (&err_list, TestDialog (mp->inference_dlg));
 
21576
  }
18104
21577
  
18105
21578
  if (err_list == NULL)
18106
21579
  {
18399
21872
 
18400
21873
static GrouP FeatureEditorPartialGroup (GrouP h, FeatEdPtr mp)
18401
21874
{
18402
 
  GrouP g, k1, k2;
 
21875
  GrouP g, g1, g2,k1, k2;
 
21876
  PrompT p1, p2;
18403
21877
  
18404
21878
  if (mp == NULL)
18405
21879
  {
18406
21880
    return NULL;
18407
21881
  }
18408
21882
  
18409
 
  g = HiddenGroup (h, -1, 0, NULL);
 
21883
  g = HiddenGroup (h, 2, 0, NULL);
18410
21884
  SetGroupSpacing (g, 10, 10);
18411
 
  
18412
 
  mp->convert_choice = PopupList (g, TRUE, NULL);
18413
 
  PopupItem (mp->convert_choice, "Do not convert location");
18414
 
  PopupItem (mp->convert_choice, "Convert location to join");
18415
 
  PopupItem (mp->convert_choice, "Convert location to order");
18416
 
  PopupItem (mp->convert_choice, "Convert location to single interval");
18417
 
  SetValue (mp->convert_choice, 1);
18418
 
  
18419
 
  k1 = HiddenGroup (g, 2, 0, NULL);
 
21885
  StaticPrompt (g, "", 0, dialogTextHeight, systemFont, 'l');
 
21886
  StaticPrompt (g, "", 0, dialogTextHeight, systemFont, 'l');
 
21887
  
 
21888
  p1 = StaticPrompt (g, "Partials:", 0, dialogTextHeight, systemFont, 'l');
 
21889
  g1 = NormalGroup (g, 1, 0, "", programFont, NULL);
 
21890
  k1 = HiddenGroup (g1, 2, 0, NULL);
 
21891
 
18420
21892
  SetGroupSpacing (k1, 10, 10);
18421
21893
  StaticPrompt (k1, "5' partial:", 0, dialogTextHeight, systemFont, 'l');
18422
21894
  mp->partial5_choice = PopupList (k1, TRUE, NULL);
18430
21902
  PopupItem (mp->partial5_choice, "Do not change");
18431
21903
  SetValue (mp->partial5_choice, 8);
18432
21904
  
18433
 
  mp->extend5_btn = CheckBox (g, "Extend to 5' end of sequence if setting 5' partial", NULL);
18434
 
  
18435
 
  k2 = HiddenGroup (g, 2, 0, NULL);
 
21905
  mp->extend5_btn = CheckBox (g1, "Extend to 5' end of sequence if setting 5' partial", NULL);
 
21906
 
 
21907
  StaticPrompt (g1, "", 0, dialogTextHeight, systemFont, 'l');
 
21908
 
 
21909
  k2 = HiddenGroup (g1, 2, 0, NULL);
18436
21910
  SetGroupSpacing (k2, 10, 10);
18437
21911
  StaticPrompt (k2, "3' partial:", 0, dialogTextHeight, systemFont, 'l');
18438
21912
  mp->partial3_choice = PopupList (k2, TRUE, NULL);
18445
21919
  PopupItem (mp->partial3_choice, "Do not change");
18446
21920
  SetValue (mp->partial3_choice, 7);
18447
21921
  
18448
 
  mp->extend3_btn = CheckBox (g, "Extend to 3' end of sequence if setting 3' partial", NULL);
18449
 
  
18450
 
  AlignObjects (ALIGN_CENTER, (HANDLE) mp->convert_choice,
18451
 
                              (HANDLE) k1,
18452
 
                              (HANDLE) mp->extend5_btn,
18453
 
                              (HANDLE) k2,
18454
 
                              (HANDLE) mp->extend3_btn,
18455
 
                              NULL);
 
21922
  mp->extend3_btn = CheckBox (g1, "Extend to 3' end of sequence if setting 3' partial", NULL);
 
21923
 
 
21924
  p2 = StaticPrompt (g, "Join/Order/Merge:", 0, dialogTextHeight, systemFont, 'l');
 
21925
  g2 = NormalGroup (g, 1, 0, "", programFont, NULL);
 
21926
  mp->convert_choice = PopupList (g2, TRUE, NULL);
 
21927
  PopupItem (mp->convert_choice, "Do not convert location");
 
21928
  PopupItem (mp->convert_choice, "Convert location to join");
 
21929
  PopupItem (mp->convert_choice, "Convert location to order");
 
21930
  PopupItem (mp->convert_choice, "Convert location to single interval");
 
21931
  SetValue (mp->convert_choice, 1);
18456
21932
  
18457
21933
  return g;
18458
21934
}
18533
22009
 
18534
22010
  g = HiddenGroup (h, 1, 0, NULL);
18535
22011
  SetGroupSpacing (g, 10, 10);
18536
 
  StaticPrompt (g, "Hit Accept to remove all inferences", 0, dialogTextHeight, systemFont, 'l');
 
22012
 
 
22013
  mp->inference_dlg = CreateInferenceEditDialog (g, FeatEdChangeNotify, mp);
18537
22014
  return g;
18538
22015
}
18539
22016
 
18584
22061
  SetObjectExtra (mp->action_choice_grp, mp, NULL);
18585
22062
  RadioButton (mp->action_choice_grp, "Evidence");
18586
22063
  RadioButton (mp->action_choice_grp, "Exceptions");
18587
 
  RadioButton (mp->action_choice_grp, "Partials");
 
22064
  RadioButton (mp->action_choice_grp, "Location");
18588
22065
  RadioButton (mp->action_choice_grp, "Strands");
18589
22066
  RadioButton (mp->action_choice_grp, "Citations");
18590
22067
  RadioButton (mp->action_choice_grp, "Experiment");
18640
22117
  sfp->pseudo = mp->pseudo_val;  
18641
22118
}
18642
22119
 
 
22120
 
 
22121
static Boolean DoesInferenceMatchCategory (CharPtr inf_cat, CharPtr match_cat)
 
22122
{
 
22123
  if (StringHasNoText (inf_cat)) return FALSE;
 
22124
 
 
22125
  if (StringHasNoText (match_cat) 
 
22126
      || StringICmp (match_cat, "ANY") == 0
 
22127
      || StringICmp (inf_cat, match_cat) == 0)
 
22128
  {
 
22129
    return TRUE;
 
22130
  }
 
22131
  else
 
22132
  {
 
22133
    return FALSE;
 
22134
  }
 
22135
 
 
22136
}
 
22137
 
 
22138
#define AECR_APPLY   1
 
22139
#define AECR_EDIT    2
 
22140
#define AECR_CONVERT 3
 
22141
#define AECR_SWAP    4
 
22142
#define AECR_PARSE   5
 
22143
#define AECR_REMOVE  6
 
22144
#define NUM_AECR     6
 
22145
 
 
22146
static void 
 
22147
AddEditApplyDataToApplyValue 
 
22148
(Int4 action_choice,
 
22149
 EditApplyPtr edit_apply, 
 
22150
 ApplyValuePtr avp);
 
22151
 
 
22152
 
 
22153
static void DoInferenceFeatureProc (SeqFeatPtr sfp, Pointer userdata, FilterSetPtr fsp)
 
22154
{
 
22155
  InferenceEditPtr iep;
 
22156
  GBQualPtr        gbqual, gbqual_last = NULL, gbqual_next;
 
22157
  CharPtr          new_val;
 
22158
  InferenceParsePtr ipp;
 
22159
  Boolean           changed;
 
22160
  ApplyValueData    avd;
 
22161
 
 
22162
  iep = (InferenceEditPtr) userdata;
 
22163
 
 
22164
  if (iep == NULL || sfp == NULL) return;
 
22165
 
 
22166
  /* apply requested changes */
 
22167
  gbqual = sfp->qual;
 
22168
  while (gbqual != NULL)
 
22169
  {
 
22170
    gbqual_next = gbqual->next;
 
22171
    if (StringCmp (gbqual->qual, "inference") == 0)
 
22172
    {
 
22173
      if (iep->action == eInferenceRemove)
 
22174
      {
 
22175
        if (gbqual_last == NULL)
 
22176
        {
 
22177
          sfp->qual = gbqual->next;
 
22178
        }
 
22179
        else
 
22180
        {
 
22181
          gbqual_last->next = gbqual->next;
 
22182
        }
 
22183
        gbqual->next = NULL;
 
22184
        GBQualFree (gbqual);
 
22185
      }
 
22186
      else
 
22187
      {
 
22188
        /* perform editing here */
 
22189
        ipp = ParseInferenceText (gbqual->val);
 
22190
        changed = FALSE;
 
22191
        if (ipp != NULL)
 
22192
        {
 
22193
          switch (iep->action)
 
22194
          {
 
22195
            case eInferenceEditCategory:
 
22196
              if (DoesInferenceMatchCategory(ipp->category, iep->category_from))
 
22197
              {
 
22198
                ipp->category = MemFree (ipp->category);
 
22199
                ipp->category = StringSave (iep->category_to);
 
22200
                changed = TRUE;
 
22201
              }
 
22202
              break;
 
22203
            case eInferenceApplyCategoryFields:
 
22204
            case eInferenceEditCategoryFields:
 
22205
              if (iep->field_edit != NULL 
 
22206
                  && iep->field_edit->edit_apply != NULL
 
22207
                  && DoesInferenceMatchCategory (ipp->category, iep->field_edit->field_category))
 
22208
              {
 
22209
                avd.where_to_replace = EditApplyFindLocation_anywhere;
 
22210
                avd.field_list = NULL;
 
22211
                avd.etp = NULL;
 
22212
                AddEditApplyDataToApplyValue (iep->action == eInferenceApplyCategoryFields ? AECR_APPLY : AECR_EDIT,
 
22213
                                              iep->field_edit->edit_apply, &avd);
 
22214
                if (iep->field_edit->field_choice == 0)
 
22215
                {
 
22216
                  ipp->first_field = HandleApplyValue (ipp->first_field, &avd);
 
22217
                }
 
22218
                else
 
22219
                {
 
22220
                  ipp->second_field = HandleApplyValue (ipp->second_field, &avd);
 
22221
                }
 
22222
                avd.text_to_replace = MemFree (avd.text_to_replace);
 
22223
                avd.new_text = MemFree (avd.new_text);
 
22224
                changed = TRUE;
 
22225
              }
 
22226
              break;
 
22227
            default:
 
22228
              break;
 
22229
          }
 
22230
          if (changed)
 
22231
          {
 
22232
            new_val = InferenceTextFromStruct (ipp);
 
22233
            gbqual->val = MemFree (gbqual->val);
 
22234
            gbqual->val = new_val;
 
22235
          }
 
22236
        }
 
22237
        gbqual_last = gbqual;
 
22238
      }
 
22239
    }
 
22240
    else
 
22241
    {
 
22242
      gbqual_last = gbqual;
 
22243
    }
 
22244
    gbqual = gbqual_next;
 
22245
  }
 
22246
 
 
22247
 
 
22248
 
 
22249
}
 
22250
 
18643
22251
static void DoEvidenceFeatureProc (SeqFeatPtr sfp, Pointer userdata, FilterSetPtr fsp)
18644
22252
{
18645
22253
  FeatEdPtr mp;
18676
22284
    sfp->except_text = NULL;
18677
22285
    if (mp->do_move_to_comment)
18678
22286
    {
18679
 
      etd.existing_text_choice = EXISTING_TEXT_CHOICE_APPEND_SEMI;
 
22287
      etd.existing_text_choice = eExistingTextChoiceAppendSemi;
18680
22288
      sfp->comment = HandleExistingText (sfp->comment, old_explanation, &etd);
18681
22289
      old_explanation = NULL;
18682
22290
    }
19223
22831
  GetSamplePtr    gsp;
19224
22832
  MsgAnswer       ans;
19225
22833
  Boolean         also_remove_evidence = FALSE;
 
22834
  InferenceEditPtr iep;
19226
22835
 
19227
22836
  avd.etp = NULL;
19228
22837
  avd.field_list = NULL;
19229
22838
  avd.text_to_replace = NULL;
19230
22839
  avd.new_text = NULL;
 
22840
  avd.where_to_replace = EditApplyFindLocation_anywhere;
19231
22841
 
19232
22842
  if (action_choice == FEAT_ED_EXPERIMENT)
19233
22843
  {
19244
22854
      gsp = GetGBQualExistingText (sep, feature_type_list,
19245
22855
                                   avd.field_list,
19246
22856
                                   fsp);
19247
 
      avd.etp = GetExistingTextHandlerInfo (gsp, FALSE);
 
22857
      avd.etp = GetExistingTextHandlerInfo (gsp == NULL ? 0 : gsp->num_found, FALSE);
19248
22858
      gsp = GetSampleFree (gsp);
19249
22859
      if (avd.etp != NULL 
19250
 
          && avd.etp->existing_text_choice == EXISTING_TEXT_CHOICE_CANCEL)
 
22860
          && avd.etp->existing_text_choice == eExistingTextChoiceCancel)
19251
22861
      {
19252
22862
        avd.etp = MemFree (avd.etp);
19253
22863
        avd.field_list = ValNodeFree (avd.field_list);
19257
22867
  }
19258
22868
  else if (action_choice == FEAT_ED_INFERENCE)
19259
22869
  {
19260
 
    avd.field_list = ValNodeNew (NULL);
19261
 
    avd.field_list->data.intvalue = QUAL_EVIDENCE;
19262
 
    avd.new_text = NULL;
19263
 
    /* get handling for existing text */
19264
 
    gsp = GetGBQualExistingText (sep, feature_type_list,
19265
 
                                 avd.field_list,
19266
 
                                 fsp);
19267
 
    if (gsp->num_found > 0)
 
22870
    iep = DialogToPointer (mp->inference_dlg);
 
22871
    if (iep->action == eInferenceRemove)
19268
22872
    {
19269
 
      ans = Message (MSG_YNC, "There are evidence qualifiers on your features, which are displayed as inference qualifiers in the flat file.  Would you like to remove them as well?");
19270
 
      if (ans == ANS_CANCEL)
19271
 
      {
19272
 
        gsp = GetSampleFree (gsp);
19273
 
              avd.field_list = ValNodeFree (avd.field_list);
19274
 
        return;
19275
 
      }
19276
 
      else if (ans == ANS_YES)
19277
 
      {
19278
 
        also_remove_evidence = TRUE;
19279
 
      }
 
22873
      avd.field_list = ValNodeNew (NULL);
 
22874
      avd.field_list->data.intvalue = QUAL_EVIDENCE;
 
22875
      avd.new_text = NULL;
 
22876
      /* get handling for existing text */
 
22877
      gsp = GetGBQualExistingText (sep, feature_type_list,
 
22878
                                  avd.field_list,
 
22879
                                  fsp);
 
22880
      if (gsp->num_found > 0)
 
22881
      {
 
22882
        ans = Message (MSG_YNC, "There are evidence qualifiers on your features, which are displayed as inference qualifiers in the flat file.  Would you like to remove them as well?");
 
22883
        if (ans == ANS_CANCEL)
 
22884
        {
 
22885
          gsp = GetSampleFree (gsp);
 
22886
                avd.field_list = ValNodeFree (avd.field_list);
 
22887
          iep = InferenceEditFree (iep);
 
22888
          return;
 
22889
        }
 
22890
        else if (ans == ANS_YES)
 
22891
        {
 
22892
          also_remove_evidence = TRUE;
 
22893
        }
 
22894
      }
 
22895
      gsp = GetSampleFree (gsp);
19280
22896
    }
19281
 
    gsp = GetSampleFree (gsp);
 
22897
    iep = InferenceEditFree (iep);
19282
22898
  }
19283
22899
  
19284
22900
  for (vnp = feature_type_list; vnp != NULL; vnp = vnp->next)
19371
22987
 
19372
22988
        break;
19373
22989
      case FEAT_ED_INFERENCE:
19374
 
        OperateOnSeqEntryConstrainedObjects (sep, fsp, RemoveInference,
19375
 
                                               NULL, 0, feat_def_choice, 0, &avd);
 
22990
        iep = DialogToPointer (mp->inference_dlg);
 
22991
        OperateOnSeqEntryConstrainedObjects (sep, fsp, DoInferenceFeatureProc,
 
22992
                                               NULL, 0, feat_def_choice, 0, iep);
 
22993
        iep = InferenceEditFree (iep);
19376
22994
        if (also_remove_evidence)
19377
22995
        {
19378
22996
          mp->evidence_val = 0;
19458
23076
  
19459
23077
  g = FeatureEditorActionGroup (h, mp, first_action);
19460
23078
  
19461
 
  mp->constraints = FilterGroup (h, TRUE, FALSE, TRUE, FALSE, "Where feature text");
 
23079
  mp->constraints = FilterGroup (h, TRUE, FALSE, TRUE, FALSE, FALSE, "Where feature text");
19462
23080
                      
19463
23081
  mp->accept_cancel = AcceptCancelDialog (h, FeatureEditorAction, NULL, 
19464
23082
                                          FeatEdClear, 
19541
23159
  return NULL;
19542
23160
}
19543
23161
 
19544
 
static CharPtr GetCDSGeneProtFieldName (ValNodePtr vnp)
 
23162
extern CharPtr GetCDSGeneProtFieldName (ValNodePtr vnp)
19545
23163
{
19546
23164
  CharPtr PNTR      field_name_list = NULL;
19547
23165
  Int4              num_fields = 0;
19665
23283
  return NULL;
19666
23284
}
19667
23285
 
 
23286
typedef struct buildcdset2
 
23287
{
 
23288
  ValNodePtr cds_list;
 
23289
  ValNodePtr mrna_list;
 
23290
  ValNodePtr gene_list;
 
23291
} BuildCDSet2Data, PNTR BuildCDSet2Ptr;
 
23292
 
 
23293
static void BuildCDSet2Callback (SeqFeatPtr sfp, Pointer userdata)
 
23294
{
 
23295
  BuildCDSet2Ptr b;
 
23296
 
 
23297
  if (sfp == NULL || sfp->idx.deleteme || userdata == NULL) return;
 
23298
  b = (BuildCDSet2Ptr) userdata;
 
23299
  if (sfp->data.choice == SEQFEAT_CDREGION)
 
23300
  {
 
23301
    ValNodeAddPointer (&(b->cds_list), OBJ_SEQFEAT, sfp);
 
23302
  }
 
23303
  else if (sfp->data.choice == SEQFEAT_GENE)
 
23304
  {
 
23305
    ValNodeAddPointer (&(b->gene_list), OBJ_SEQFEAT, sfp);
 
23306
  }
 
23307
  else if (sfp->idx.subtype == FEATDEF_mRNA)
 
23308
  {
 
23309
    ValNodeAddPointer (&(b->mrna_list), OBJ_SEQFEAT, sfp);
 
23310
  }
 
23311
  else if (SeqMgrGetGeneXref (sfp) != NULL)
 
23312
  {
 
23313
    ValNodeAddPointer (&(b->gene_list), OBJ_SEQFEAT, sfp);
 
23314
  }
 
23315
}
 
23316
 
 
23317
 
 
23318
static void UnmarkFeatureList (ValNodePtr list)
 
23319
{
 
23320
  SeqFeatPtr sfp;
 
23321
 
 
23322
  while (list != NULL)
 
23323
  {
 
23324
    sfp = list->data.ptrvalue;
 
23325
    if (sfp != NULL)
 
23326
    {
 
23327
      sfp->idx.deleteme = FALSE;
 
23328
    }
 
23329
    list = list->next;
 
23330
  }
 
23331
}
 
23332
 
 
23333
 
 
23334
static SeqFeatPtr GetGeneForCDSetFeature (SeqFeatPtr sfp)
 
23335
{
 
23336
  GeneRefPtr        grp;
 
23337
  SeqFeatPtr        gene = NULL;
 
23338
  SeqMgrFeatContext fcontext;
 
23339
 
 
23340
  grp = SeqMgrGetGeneXref (sfp);
 
23341
  if (grp == NULL)
 
23342
  {
 
23343
    gene = SeqMgrGetOverlappingGene (sfp->location, &fcontext);
 
23344
  }
 
23345
  else if (!SeqMgrGeneIsSuppressed (grp))
 
23346
  {
 
23347
    if (!StringHasNoText (grp->locus_tag))
 
23348
    {
 
23349
      gene = SeqMgrGetGeneByLocusTag (BioseqFindFromSeqLoc (sfp->location), grp->locus_tag, &fcontext);
 
23350
    }
 
23351
  }
 
23352
  return gene;
 
23353
}
 
23354
 
 
23355
 
 
23356
static CDSetPtr BuildCDSetFromCodingRegion (SeqFeatPtr cds, BoolPtr indexing_needed)
 
23357
{
 
23358
  SeqMgrFeatContext fcontext;
 
23359
  SeqFeatPtr        gene = NULL, mrna, prot;
 
23360
  BioseqPtr         protbsp;
 
23361
  CDSetPtr          cdsp;
 
23362
  ProtRefPtr        prp;
 
23363
 
 
23364
  if (cds == NULL || cds->data.choice != SEQFEAT_CDREGION) return NULL;
 
23365
 
 
23366
  cdsp = (CDSetPtr) MemNew (sizeof (CDSetData));
 
23367
  ValNodeAddPointer (&(cdsp->cds_list), 0, cds);
 
23368
 
 
23369
  gene = GetGeneForCDSetFeature (cds);
 
23370
  if (gene != NULL)
 
23371
  {
 
23372
    ValNodeAddPointer (&(cdsp->gene_list), 0, gene);
 
23373
    /* mark gene, so that we'll know it isn't lonely */
 
23374
    gene->idx.deleteme = TRUE;
 
23375
  }
 
23376
 
 
23377
  mrna = SeqMgrGetOverlappingmRNA (cds->location, &fcontext);
 
23378
  if (mrna != NULL)
 
23379
  {
 
23380
    ValNodeAddPointer (&(cdsp->mrna_list), 0, mrna);
 
23381
    /* mark mrna, so that we'll know it's already in a set */
 
23382
    mrna->idx.deleteme = TRUE;
 
23383
  }
 
23384
 
 
23385
  if (cds->product != NULL)
 
23386
  {
 
23387
    protbsp = BioseqFindFromSeqLoc (cds->product);
 
23388
    if (protbsp != NULL)
 
23389
    {
 
23390
      prot = SeqMgrGetNextFeature (protbsp, NULL, SEQFEAT_PROT, FEATDEF_PROT, &fcontext);
 
23391
      /* if there is no full-length protein feature, make one */
 
23392
      if (prot == NULL)
 
23393
      {
 
23394
        prp = ProtRefNew ();
 
23395
        prot = CreateNewFeatureOnBioseq (protbsp, SEQFEAT_PROT, NULL);
 
23396
        if (prot != NULL)
 
23397
        {
 
23398
          prot->data.value.ptrvalue = prp;
 
23399
          if (indexing_needed != NULL)
 
23400
          {
 
23401
            *indexing_needed = TRUE;
 
23402
          }
 
23403
        }
 
23404
      }
 
23405
      if (prot != NULL)
 
23406
      {
 
23407
        ValNodeAddPointer (&(cdsp->prot_list), 0, prot);
 
23408
      }
 
23409
      
 
23410
      /* also add in mat_peptides from protein feature */
 
23411
      prot = SeqMgrGetNextFeature (protbsp, NULL, SEQFEAT_PROT, FEATDEF_mat_peptide_aa, &fcontext);
 
23412
      while (prot != NULL)
 
23413
      {
 
23414
        ValNodeAddPointer (&(cdsp->prot_list), 0, prot);
 
23415
        prot = SeqMgrGetNextFeature (protbsp, prot, SEQFEAT_PROT, FEATDEF_mat_peptide_aa, &fcontext);
 
23416
      }
 
23417
    }
 
23418
  }  
 
23419
  return cdsp;
 
23420
}
 
23421
 
 
23422
 
 
23423
static CDSetPtr BuildCDSetFrommRNA (SeqFeatPtr mrna)
 
23424
{
 
23425
  SeqFeatPtr        gene;
 
23426
  CDSetPtr          cdsp;
 
23427
 
 
23428
  if (mrna == NULL || mrna->idx.deleteme || mrna->idx.subtype != FEATDEF_mRNA) return NULL;
 
23429
 
 
23430
  cdsp = (CDSetPtr) MemNew (sizeof (CDSetData));
 
23431
  ValNodeAddPointer (&(cdsp->mrna_list), 0, mrna);
 
23432
 
 
23433
  gene = GetGeneForCDSetFeature (mrna);
 
23434
  if (gene != NULL)
 
23435
  {
 
23436
    ValNodeAddPointer (&(cdsp->gene_list), 0, gene);
 
23437
    /* mark gene, so that we'll know it isn't lonely */
 
23438
    gene->idx.deleteme = TRUE;
 
23439
  }
 
23440
 
 
23441
  return cdsp;
 
23442
}
 
23443
 
 
23444
 
 
23445
static Boolean DoesCDSetMatchConstraint (CDSetPtr cdsp, ChoiceConstraintPtr ccp);
 
23446
 
 
23447
static ValNodePtr BuildCDSet2List (Uint2 entityID, ChoiceConstraintPtr  ccp)
 
23448
{
 
23449
  SeqEntryPtr    sep;
 
23450
  BuildCDSet2Data b;
 
23451
  CDSetPtr       cdsp;
 
23452
  ValNodePtr     vnp, vnp_next, vnp_prev;
 
23453
  ValNodePtr     cdset_list = NULL;
 
23454
  SeqFeatPtr     cds, gene, mrna;
 
23455
  Boolean        need_indexing = FALSE;
 
23456
  
 
23457
  sep = GetTopSeqEntryForEntityID (entityID);
 
23458
 
 
23459
  b.cds_list = NULL;
 
23460
  b.gene_list = NULL;
 
23461
  b.mrna_list = NULL;
 
23462
  
 
23463
  VisitFeaturesInSep (sep, &b, BuildCDSet2Callback);
 
23464
 
 
23465
  /* build cdsets that have coding regions */
 
23466
  for (vnp = b.cds_list; vnp != NULL; vnp = vnp->next)
 
23467
  {
 
23468
    cds = (SeqFeatPtr) vnp->data.ptrvalue;
 
23469
    if (cds == NULL) continue;
 
23470
    cdsp = BuildCDSetFromCodingRegion (cds, &need_indexing);
 
23471
    if (cdsp != NULL)
 
23472
    {
 
23473
      ValNodeAddPointer (&cdset_list, 0, cdsp);
 
23474
    }
 
23475
  }
 
23476
  if (need_indexing)
 
23477
  {
 
23478
    /* indexing because we have created full-length protein features */
 
23479
    SeqMgrIndexFeatures (entityID, NULL);
 
23480
  }
 
23481
 
 
23482
  /* build cdsets for mrna features that don't have coding regions */
 
23483
  for (vnp = b.mrna_list; vnp != NULL; vnp = vnp->next)
 
23484
  {
 
23485
    mrna = (SeqFeatPtr) vnp->data.ptrvalue;
 
23486
    if (mrna == NULL || mrna->idx.deleteme) continue;
 
23487
    cdsp = BuildCDSetFrommRNA (mrna);
 
23488
    if (cdsp != NULL)
 
23489
    {
 
23490
      ValNodeAddPointer (&cdset_list, 0, cdsp);
 
23491
    }
 
23492
  }
 
23493
 
 
23494
  /* build cdsets for lonely genes / features with gene xrefs that are not coding regions or mrnas */
 
23495
  for (vnp = b.gene_list; vnp != NULL; vnp = vnp->next)
 
23496
  {
 
23497
    gene = (SeqFeatPtr) vnp->data.ptrvalue;
 
23498
    if (gene == NULL || gene->idx.deleteme) continue;
 
23499
    cdsp = (CDSetPtr) MemNew (sizeof (CDSetData));
 
23500
    ValNodeAddPointer (&(cdsp->gene_list), 0, gene);
 
23501
    ValNodeAddPointer (&cdset_list, 0, cdsp);
 
23502
  }
 
23503
 
 
23504
  /* now unmark features */
 
23505
  UnmarkFeatureList (b.cds_list);
 
23506
  UnmarkFeatureList (b.mrna_list);
 
23507
  UnmarkFeatureList (b.gene_list);
 
23508
 
 
23509
  b.cds_list = ValNodeFree (b.cds_list);
 
23510
  b.mrna_list = ValNodeFree (b.mrna_list);
 
23511
  b.gene_list = ValNodeFree (b.gene_list);
 
23512
 
 
23513
  /* now remove sets that don't match our choice constraint */
 
23514
  vnp_prev = NULL;
 
23515
  for (vnp = cdset_list; vnp != NULL; vnp = vnp_next)
 
23516
  {
 
23517
    vnp_next = vnp->next;
 
23518
    if (!DoesCDSetMatchConstraint (vnp->data.ptrvalue, ccp))
 
23519
    {
 
23520
      if (vnp_prev == NULL)
 
23521
      {
 
23522
        cdset_list = vnp->next;
 
23523
      }
 
23524
      else
 
23525
      {
 
23526
        vnp_prev->next = vnp->next;
 
23527
      }
 
23528
      vnp->next = NULL;
 
23529
      FreeCDSetList (vnp);     
 
23530
    }
 
23531
    else
 
23532
    {
 
23533
      vnp_prev = vnp;
 
23534
    }
 
23535
  }
 
23536
  
 
23537
  return cdset_list;
 
23538
}
 
23539
 
19668
23540
typedef struct buildcdset
19669
23541
{
19670
23542
  ValNodePtr cdset_list;
19671
 
  ValNodePtr lonely_gene_list;  
 
23543
  ValNodePtr lonely_gene_list;
19672
23544
} BuildCDSetData, PNTR BuildCDSetPtr;
19673
23545
 
19674
23546
static void BuildCDSSetCallback (SeqFeatPtr sfp, Pointer userdata)
19731
23603
    {
19732
23604
      cds = sfp;
19733
23605
      mrna = SeqMgrGetOverlappingmRNA (sfp->location, &fcontext);
19734
 
          if (mrna != NULL)
19735
 
          {
 
23606
      if (mrna != NULL)
 
23607
      {
19736
23608
        mrna_gene = SeqMgrGetOverlappingGene (mrna->location, &fcontext);
19737
 
                if (mrna_gene == gene)
19738
 
                {
 
23609
        if (mrna_gene == gene)
 
23610
        {
19739
23611
          vnp = AlreadyInCDSList (bp->cdset_list, mrna);
19740
23612
          if (vnp != NULL && vnp->data.ptrvalue != NULL)
19741
23613
          {
19744
23616
            if (AlreadyInList (cdsp->gene_list, gene))
19745
23617
            {
19746
23618
              gene = NULL;
19747
 
                        }
19748
 
                  }
 
23619
            }
 
23620
          }
19749
23621
        }
19750
23622
      }
19751
23623
    }
19790
23662
        if (prot != NULL)
19791
23663
        {
19792
23664
          prot->data.value.ptrvalue = prp;
19793
 
              SeqMgrIndexFeatures (protbsp->idx.entityID, NULL);
 
23665
          if (SeqMgrFeaturesAreIndexed (protbsp->idx.entityID) == 0) {
 
23666
                SeqMgrIndexFeatures (protbsp->idx.entityID, NULL);
 
23667
          }
19794
23668
        }
19795
23669
      }
19796
23670
      if (prot != NULL && ! AlreadyInList (cdsp->prot_list, prot))
19846
23720
  return str;
19847
23721
}
19848
23722
 
19849
 
static void SetCDSetField (CDSetPtr cdsp, ValNodePtr vnp, CharPtr new_text, ExistingTextPtr etp)
 
23723
static Boolean SetCDSetField (CDSetPtr cdsp, ValNodePtr vnp, ApplyValuePtr avp, FilterSetPtr fsp)
19850
23724
{
19851
23725
  ValNodePtr sfp_vnp;
19852
 
  CharPtr    str = NULL;
19853
 
  
19854
 
  if (cdsp == NULL || vnp == NULL)
19855
 
  {
19856
 
    return;
19857
 
  }
19858
 
  
19859
 
  for (sfp_vnp = cdsp->cds_list; sfp_vnp != NULL && str == NULL; sfp_vnp = sfp_vnp->next)
19860
 
  {
19861
 
    SetCDSGeneProtField (sfp_vnp->data.ptrvalue, vnp, new_text, etp);
19862
 
  }
19863
 
  for (sfp_vnp = cdsp->gene_list; sfp_vnp != NULL && str == NULL; sfp_vnp = sfp_vnp->next)
19864
 
  {
19865
 
    SetCDSGeneProtField (sfp_vnp->data.ptrvalue, vnp, new_text, etp);
19866
 
  }
19867
 
  for (sfp_vnp = cdsp->prot_list; sfp_vnp != NULL && str == NULL; sfp_vnp = sfp_vnp->next)
19868
 
  {
19869
 
    SetCDSGeneProtField (sfp_vnp->data.ptrvalue, vnp, new_text, etp);
19870
 
  }
19871
 
  for (sfp_vnp = cdsp->mrna_list; sfp_vnp != NULL && str == NULL; sfp_vnp = sfp_vnp->next)
19872
 
  {
19873
 
    SetCDSGeneProtField (sfp_vnp->data.ptrvalue, vnp, new_text, etp);
19874
 
  }
 
23726
  Boolean    rval = FALSE;
 
23727
  
 
23728
  if (cdsp == NULL || vnp == NULL || avp == NULL)
 
23729
  {
 
23730
    return FALSE;
 
23731
  }
 
23732
  
 
23733
  for (sfp_vnp = cdsp->cds_list; sfp_vnp != NULL ; sfp_vnp = sfp_vnp->next)
 
23734
  {
 
23735
    rval |= SetCDSGeneProtField (sfp_vnp->data.ptrvalue, vnp, avp, fsp);
 
23736
  }
 
23737
  for (sfp_vnp = cdsp->gene_list; sfp_vnp != NULL; sfp_vnp = sfp_vnp->next)
 
23738
  {
 
23739
    if (sfp_vnp->choice == 0) /* don't set again if already set */
 
23740
    {
 
23741
      rval |= SetCDSGeneProtField (sfp_vnp->data.ptrvalue, vnp, avp, fsp);
 
23742
    }
 
23743
  }
 
23744
  for (sfp_vnp = cdsp->prot_list; sfp_vnp != NULL; sfp_vnp = sfp_vnp->next)
 
23745
  {
 
23746
    rval |= SetCDSGeneProtField (sfp_vnp->data.ptrvalue, vnp, avp, fsp);
 
23747
  }
 
23748
  for (sfp_vnp = cdsp->mrna_list; sfp_vnp != NULL; sfp_vnp = sfp_vnp->next)
 
23749
  {
 
23750
    rval |= SetCDSGeneProtField (sfp_vnp->data.ptrvalue, vnp, avp, fsp);
 
23751
  }
 
23752
  return rval;
19875
23753
}
19876
23754
 
19877
 
static void RemoveCDSetField (CDSetPtr cdsp, ValNodePtr vnp)
 
23755
static void RemoveCDSetField (CDSetPtr cdsp, ValNodePtr vnp, FilterSetPtr fsp)
19878
23756
{
19879
23757
  ValNodePtr sfp_vnp;
19880
23758
  CharPtr    str = NULL;
19886
23764
  
19887
23765
  for (sfp_vnp = cdsp->cds_list; sfp_vnp != NULL && str == NULL; sfp_vnp = sfp_vnp->next)
19888
23766
  {
19889
 
    RemoveCDSGeneProtField (sfp_vnp->data.ptrvalue, vnp);
 
23767
    RemoveCDSGeneProtField (sfp_vnp->data.ptrvalue, vnp, fsp);
19890
23768
  }
19891
23769
  for (sfp_vnp = cdsp->gene_list; sfp_vnp != NULL && str == NULL; sfp_vnp = sfp_vnp->next)
19892
23770
  {
19893
 
    RemoveCDSGeneProtField (sfp_vnp->data.ptrvalue, vnp);
 
23771
    RemoveCDSGeneProtField (sfp_vnp->data.ptrvalue, vnp, fsp);
19894
23772
  }
19895
23773
  for (sfp_vnp = cdsp->prot_list; sfp_vnp != NULL && str == NULL; sfp_vnp = sfp_vnp->next)
19896
23774
  {
19897
 
    RemoveCDSGeneProtField (sfp_vnp->data.ptrvalue, vnp);
 
23775
    RemoveCDSGeneProtField (sfp_vnp->data.ptrvalue, vnp, fsp);
19898
23776
  }
19899
23777
  for (sfp_vnp = cdsp->mrna_list; sfp_vnp != NULL && str == NULL; sfp_vnp = sfp_vnp->next)
19900
23778
  {
19901
 
    RemoveCDSGeneProtField (sfp_vnp->data.ptrvalue, vnp);
 
23779
    RemoveCDSGeneProtField (sfp_vnp->data.ptrvalue, vnp, fsp);
19902
23780
  }
19903
23781
}
19904
23782
 
19967
23845
  return FALSE;
19968
23846
}
19969
23847
 
 
23848
static Boolean DoCDSFieldsMatch (CDSetPtr cdsp, ValNodePtr qual_choice, ValNodePtr qual_choice_match)
 
23849
{
 
23850
  CharPtr str1, str2;
 
23851
  Int4    field_choice, field_choice2;
 
23852
  ValNode field_vn, field_vn2;
 
23853
  Boolean does_match = FALSE;
 
23854
 
 
23855
  if (qual_choice == NULL && qual_choice_match == NULL) 
 
23856
  {
 
23857
    /* both are wildcards */
 
23858
    field_vn.next = NULL;
 
23859
    field_vn.choice = 0;
 
23860
    field_vn2.next = NULL;
 
23861
    field_vn2.choice = 0;
 
23862
 
 
23863
    for (field_choice = 1;
 
23864
         ! does_match && field_choice < num_gene_fields + num_mrna_fields + num_protein_fields;
 
23865
         field_choice++)
 
23866
    {
 
23867
      field_vn.data.intvalue = field_choice;
 
23868
      str1 = GetCDSetField (cdsp, &field_vn);
 
23869
      if (!StringHasNoText (str1)) {
 
23870
        for (field_choice2 = field_choice + 1;
 
23871
             ! does_match && field_choice2 < 1 + num_gene_fields + num_mrna_fields + num_protein_fields;
 
23872
             field_choice2++)
 
23873
        {
 
23874
          field_vn2.data.intvalue = field_choice2;
 
23875
          str2 = GetCDSetField (cdsp, &field_vn2);
 
23876
          if (StringCmp (str1, str2) == 0) 
 
23877
          {
 
23878
            does_match = TRUE;
 
23879
          }
 
23880
          str2 = MemFree (str2);
 
23881
        }
 
23882
      }
 
23883
      str1 = MemFree (str1);
 
23884
    }
 
23885
  }
 
23886
  else if (qual_choice == NULL || qual_choice_match == NULL) 
 
23887
  {
 
23888
    /* one is a wildcard */
 
23889
    /* make sure it is the first one */
 
23890
    if (qual_choice_match == NULL) 
 
23891
    {
 
23892
      qual_choice_match = qual_choice;
 
23893
      qual_choice = NULL;
 
23894
    }
 
23895
    field_vn.next = NULL;
 
23896
    field_vn.choice = 0;
 
23897
    str2 = GetCDSetField (cdsp, qual_choice_match);
 
23898
    if (!StringHasNoText (str2)) {
 
23899
      for (field_choice = 1;
 
23900
           ! does_match && field_choice < num_gene_fields + num_mrna_fields + num_protein_fields;
 
23901
           field_choice++)
 
23902
      {
 
23903
        if (field_choice != qual_choice_match->data.intvalue) {
 
23904
          /* don't compare something to itself */
 
23905
          field_vn.data.intvalue = field_choice;
 
23906
          str1 = GetCDSetField (cdsp, &field_vn);
 
23907
          if (StringCmp (str1, str2) == 0) 
 
23908
          {
 
23909
            does_match = TRUE;
 
23910
          }
 
23911
          str1 = MemFree (str1);
 
23912
        }
 
23913
      }
 
23914
    }
 
23915
    str2 = MemFree (str2);
 
23916
  } else {
 
23917
    str1 = GetCDSetField (cdsp, qual_choice);
 
23918
    str2 = GetCDSetField (cdsp, qual_choice_match);
 
23919
    if (!StringHasNoText (str1) && StringCmp (str1, str2) == 0)
 
23920
    {
 
23921
      does_match = TRUE;
 
23922
    }
 
23923
    str1 = MemFree (str1);
 
23924
    str2 = MemFree (str2);
 
23925
  }
 
23926
  return does_match;
 
23927
}
 
23928
 
 
23929
 
19970
23930
static Boolean DoesCDSetMatchConstraint (CDSetPtr cdsp, ChoiceConstraintPtr ccp)
19971
23931
{
19972
23932
  Boolean                does_match = FALSE;
19973
23933
  CharPtr                str;
19974
23934
  Int4                   field_choice;
19975
23935
  ValNode                field_vn;
 
23936
  ValNodePtr             sfp_vnp;
19976
23937
  
19977
23938
  if (cdsp == NULL)
19978
23939
  {
20010
23971
      {
20011
23972
        field_vn.data.intvalue = field_choice;
20012
23973
        str = GetCDSetField (cdsp, &field_vn);
20013
 
        does_match = DoesStringMatchConstraint (str, ccp->string_constraint);
 
23974
        does_match = DoesStringMatchConstraintX (str, ccp->string_constraint);
20014
23975
        MemFree (str);
20015
23976
      }
 
23977
      if (ccp->string_constraint != NULL && ccp->string_constraint->not_present)
 
23978
      {
 
23979
        does_match = ! does_match;
 
23980
      }
20016
23981
    }
 
23982
    else if (IsCDSetMatPeptideQualChoice(ccp->qual_choice))
 
23983
    {
 
23984
      /* if we're matching protein fields, we need to look at all of them */
 
23985
      for (sfp_vnp = cdsp->prot_list; sfp_vnp != NULL && !does_match; sfp_vnp = sfp_vnp->next)
 
23986
      {
 
23987
        str = GetCDSGeneProtField (sfp_vnp->data.ptrvalue, ccp->qual_choice, NULL);
 
23988
        does_match = DoesStringMatchConstraintX (str, ccp->string_constraint);
 
23989
        if (ccp->string_constraint != NULL && ccp->string_constraint->not_present)
 
23990
        {
 
23991
          does_match = ! does_match;
 
23992
        }
 
23993
        MemFree (str);
 
23994
      }
 
23995
    } 
20017
23996
    else
20018
23997
    {
20019
23998
      str = GetCDSetField (cdsp, ccp->qual_choice);
20020
 
      does_match = DoesStringMatchConstraint (str, ccp->string_constraint);
 
23999
      does_match = DoesStringMatchConstraintX (str, ccp->string_constraint);
20021
24000
      MemFree (str);
20022
 
    }
20023
 
    if (ccp->string_constraint != NULL && ccp->string_constraint->not_present)
20024
 
    {
20025
 
      does_match = ! does_match;
20026
 
    }
 
24001
      if (ccp->string_constraint != NULL && ccp->string_constraint->not_present)
 
24002
      {
 
24003
        does_match = ! does_match;
 
24004
      }
 
24005
    }
 
24006
  }
 
24007
  else if (ccp->constraint_type == CHOICE_CONSTRAINT_MATCH)
 
24008
  {
 
24009
    does_match = DoCDSFieldsMatch (cdsp, ccp->qual_choice, ccp->qual_choice_match);
20027
24010
  }
20028
24011
  else if (ccp->constraint_type == CHOICE_CONSTRAINT_PSEUDO)
20029
24012
  {
20053
24036
  bd.lonely_gene_list = NULL;
20054
24037
  
20055
24038
  VisitFeaturesInSep (sep, &bd, BuildCDSSetCallback);
20056
 
  
 
24039
 
20057
24040
  for (vnp = bd.lonely_gene_list; vnp != NULL; vnp = vnp->next)
20058
24041
  {
20059
24042
    /* only create sets for lonely genes if they have not been added to other sets */
20097
24080
  return bd.cdset_list;
20098
24081
}
20099
24082
 
20100
 
static SeqFeatPtr BuildOneNewCDSGeneProtFeature (CDSetPtr cdsp, Uint1 choice)
 
24083
 
 
24084
static SeqLocPtr GetNewFeatureLocation(ValNodePtr feat_list, Uint2 choice, Uint2 choice_from)
 
24085
{
 
24086
  ValNodePtr vnp;
 
24087
  SeqFeatPtr sfp;
 
24088
  BioseqPtr  bsp = NULL;
 
24089
  SeqLocPtr  slp = NULL;
 
24090
  
 
24091
  for (vnp = feat_list; vnp != NULL && slp == NULL; vnp = vnp->next)
 
24092
  {
 
24093
    sfp = vnp->data.ptrvalue;
 
24094
    if (sfp != NULL)
 
24095
    {
 
24096
      if (choice == FEATDEF_PROT || choice == FEATDEF_mat_peptide_aa)
 
24097
      {
 
24098
        bsp = BioseqFindFromSeqLoc (sfp->product);
 
24099
        slp = SeqLocWholeNew (bsp);
 
24100
      }
 
24101
      else
 
24102
      {
 
24103
        if (choice_from == sfp->idx.subtype || (sfp->idx.subtype == FEATDEF_CDS && (choice_from == FEATDEF_PROT || choice_from == FEATDEF_mat_peptide_aa)))
 
24104
        {
 
24105
          slp = (SeqLocPtr) AsnIoMemCopy (sfp->location, (AsnReadFunc) SeqLocAsnRead, (AsnWriteFunc) SeqLocAsnWrite);
 
24106
        }
 
24107
        else
 
24108
        { 
 
24109
          bsp = BioseqFindFromSeqLoc (sfp->location);
 
24110
          slp = SeqLocWholeNew (bsp);
 
24111
        }
 
24112
      }
 
24113
    }
 
24114
  }  
 
24115
  return slp;  
 
24116
}
 
24117
 
 
24118
 
 
24119
static SeqFeatPtr BuildOneNewCDSGeneProtFeature (CDSetPtr cdsp, Uint2 choice, Uint2 choice_from)
20101
24120
{
20102
24121
  BioseqPtr bsp = NULL;
20103
 
  SeqLocPtr slp = NULL, slp_tmp;
20104
 
  ValNodePtr vnp;
 
24122
  SeqLocPtr slp = NULL, slp_tmp, slp_sum;
20105
24123
  SeqFeatPtr sfp = NULL;
20106
24124
  RnaRefPtr  rrp;
 
24125
  ProtRefPtr prp;
20107
24126
  
20108
24127
  if (cdsp == NULL)
20109
24128
  {
20110
24129
    return NULL;
20111
24130
  }
20112
24131
 
20113
 
  /* get location from CDS features */
20114
 
  for (vnp = cdsp->cds_list; vnp != NULL; vnp = vnp->next)
20115
 
  {
20116
 
    sfp = vnp->data.ptrvalue;
20117
 
    if (sfp != NULL)
20118
 
    {
20119
 
      if (choice == SEQFEAT_PROT)
20120
 
      {
20121
 
        if (bsp == NULL)
20122
 
        {
20123
 
          bsp = BioseqFindFromSeqLoc (sfp->product);
20124
 
        }
20125
 
      }
20126
 
      else
20127
 
      {
20128
 
        if (bsp == NULL)
20129
 
        {
20130
 
          bsp = BioseqFindFromSeqLoc (sfp->location);
20131
 
        }
20132
 
        if (bsp != NULL)
20133
 
        {
20134
 
          slp_tmp = SeqLocMerge (bsp, sfp->location, slp, TRUE, FALSE, FALSE);
20135
 
          slp = SeqLocFree (slp);
20136
 
          slp = slp_tmp;
20137
 
          slp_tmp = NULL;
20138
 
        }
20139
 
      }
20140
 
    }
20141
 
  }  
20142
 
  
20143
 
  /* get location from mRNA features */
20144
 
  for (vnp = cdsp->mrna_list; vnp != NULL; vnp = vnp->next)
20145
 
  {
20146
 
    sfp = vnp->data.ptrvalue;
20147
 
    if (sfp != NULL)
20148
 
    {
20149
 
      if (choice == SEQFEAT_PROT)
20150
 
      {
20151
 
        if (bsp == NULL)
20152
 
        {
20153
 
          bsp = BioseqFindFromSeqLoc (sfp->product);
20154
 
        }
20155
 
      }
20156
 
      else
20157
 
      {
20158
 
        if (bsp == NULL)
20159
 
        {
20160
 
          bsp = BioseqFindFromSeqLoc (sfp->location);
20161
 
        }
20162
 
        if (bsp != NULL)
20163
 
        {
20164
 
          slp_tmp = SeqLocMerge (bsp, sfp->location, slp, TRUE, FALSE, FALSE);
20165
 
          slp = SeqLocFree (slp);
20166
 
          slp = slp_tmp;
20167
 
          slp_tmp = NULL;
20168
 
        }
20169
 
      }
20170
 
    }
20171
 
  }
20172
 
 
20173
 
  if (choice == SEQFEAT_PROT)
20174
 
  {
20175
 
    if (bsp != NULL)
20176
 
    {
20177
 
      slp = SeqLocWholeNew (bsp);
20178
 
    }
 
24132
  if (choice == FEATDEF_PROT || choice == FEATDEF_mat_peptide_aa)
 
24133
  {
 
24134
    slp = GetNewFeatureLocation(cdsp->cds_list, choice, choice_from);
20179
24135
  }
20180
24136
  else
20181
24137
  {
 
24138
    /* get location from CDS features */
 
24139
    if (choice_from == 0 || choice_from == FEATDEF_CDS || choice_from == FEATDEF_PROT || choice_from == FEATDEF_mat_peptide_aa)
 
24140
    {
 
24141
      slp = GetNewFeatureLocation(cdsp->cds_list, choice, choice_from);
 
24142
    }
 
24143
 
 
24144
    /* get location from mRNA features */
 
24145
    if ((choice_from == 0 && slp == NULL) || choice_from == FEATDEF_mRNA)
 
24146
    {    
 
24147
      slp_tmp = GetNewFeatureLocation(cdsp->mrna_list, choice, choice_from);
 
24148
      if (slp == NULL) 
 
24149
      {
 
24150
        slp = slp_tmp;
 
24151
      }
 
24152
      else
 
24153
      {
 
24154
        bsp = BioseqFindFromSeqLoc (sfp->location);
 
24155
        if (bsp != NULL)
 
24156
        {
 
24157
          slp_sum = SeqLocMerge (bsp, slp_tmp, slp, TRUE, FALSE, FALSE);
 
24158
          slp = SeqLocFree (slp);
 
24159
          slp_tmp = SeqLocFree (slp_tmp);
 
24160
          slp = slp_sum;
 
24161
          slp_sum = NULL;
 
24162
        }
 
24163
      }
 
24164
    }
 
24165
 
20182
24166
    /* get location from gene features */
20183
 
    for (vnp = cdsp->gene_list; vnp != NULL; vnp = vnp->next)
20184
 
    {
20185
 
      sfp = vnp->data.ptrvalue;
20186
 
      if (sfp != NULL)
20187
 
      {
20188
 
        if (bsp == NULL)
20189
 
        {
20190
 
          bsp = BioseqFindFromSeqLoc (sfp->location);
20191
 
        }
 
24167
    if ((choice_from == 0 && slp == NULL) || choice_from == FEATDEF_GENE)
 
24168
    {    
 
24169
      slp_tmp = GetNewFeatureLocation(cdsp->gene_list, choice, choice_from);
 
24170
      if (slp == NULL) 
 
24171
      {
 
24172
        slp = slp_tmp;
 
24173
      }
 
24174
      else
 
24175
      {
 
24176
        bsp = BioseqFindFromSeqLoc (sfp->location);
20192
24177
        if (bsp != NULL)
20193
24178
        {
20194
 
          slp_tmp = SeqLocMerge (bsp, sfp->location, slp, TRUE, FALSE, FALSE);
 
24179
          slp_sum = SeqLocMerge (bsp, slp_tmp, slp, TRUE, FALSE, FALSE);
20195
24180
          slp = SeqLocFree (slp);
20196
 
          slp = slp_tmp;
20197
 
          slp_tmp = NULL;
 
24181
          slp_tmp = SeqLocFree (slp_tmp);
 
24182
          slp = slp_sum;
 
24183
          slp_sum = NULL;
20198
24184
        }
20199
24185
      }
20200
24186
    }
20201
 
  }
20202
 
  
20203
 
  /* for now, cover the entire sequence */
20204
 
  slp = SeqLocFree (slp);
20205
 
  slp = SeqLocWholeNew (bsp);
20206
 
  
 
24187
  }  
 
24188
  
 
24189
  bsp = BioseqFindFromSeqLoc (slp);
20207
24190
  if (bsp != NULL && slp != NULL)
20208
24191
  {
20209
 
    sfp = CreateNewFeatureOnBioseq (bsp, choice, slp);
20210
 
    if (choice == SEQFEAT_RNA)
 
24192
    sfp = CreateNewFeatureOnBioseq (bsp, FindFeatFromFeatDefType(choice), slp);
 
24193
    switch (choice)
20211
24194
    {
20212
 
      rrp = RnaRefNew ();
20213
 
      rrp->type = 2;
20214
 
      sfp->data.value.ptrvalue = rrp;
 
24195
      case FEATDEF_mRNA:
 
24196
        rrp = RnaRefNew ();
 
24197
        rrp->type = 2;
 
24198
        sfp->data.value.ptrvalue = rrp;
 
24199
        break;
 
24200
      case FEATDEF_GENE:
 
24201
        sfp->data.value.ptrvalue = GeneRefNew();
 
24202
        break;
 
24203
      case FEATDEF_CDS:
 
24204
        sfp->data.value.ptrvalue = CdRegionNew();
 
24205
        break;
 
24206
      case FEATDEF_PROT:
 
24207
      case FEATDEF_mat_peptide_aa:
 
24208
        prp = ProtRefNew();        
 
24209
        if (choice == FEATDEF_mat_peptide_aa)
 
24210
        {
 
24211
          prp->processed = 2;
 
24212
        }
 
24213
        sfp->data.value.ptrvalue = prp;
 
24214
        break;
20215
24215
    }
20216
24216
  }
20217
24217
  return sfp;
20218
24218
}
20219
24219
 
20220
 
static void BuildNewCDSGeneProtFeature (CDSetPtr cdsp, ValNodePtr vnp)
 
24220
static SeqFeatPtr BuildNewCDSGeneProtFeature (CDSetPtr cdsp, ValNodePtr vnp, ValNodePtr field_from)
20221
24221
{
20222
 
  SeqFeatPtr new_sfp;
 
24222
  SeqFeatPtr new_sfp = NULL, sfp;
 
24223
  Uint2      choice_to, choice_from;
 
24224
  ValNodePtr v;
 
24225
  Boolean    found;
20223
24226
  
20224
24227
  if (cdsp == NULL || vnp == NULL)
20225
24228
  {
20226
 
    return;
20227
 
  }
20228
 
  if (vnp->data.intvalue == 1)
20229
 
  {
20230
 
    /* for now, don't build anything but genes */
20231
 
#if 0
20232
 
    if (cdsp->cds_list == NULL)
20233
 
    {
20234
 
      /* add new CDS */
20235
 
      new_sfp = BuildOneNewCDSGeneProtFeature (cdsp, SEQFEAT_CDREGION);
20236
 
      if (new_sfp != NULL)
20237
 
      {
20238
 
        ValNodeAddPointer (&(cdsp->cds_list), 0, new_sfp);
20239
 
      }
20240
 
    }
20241
 
#endif
20242
 
  }
20243
 
  else if (vnp->data.intvalue <= 1 + num_gene_fields)
20244
 
  {
20245
 
    if (cdsp->gene_list == NULL)
20246
 
    {
20247
 
      /* add new gene */
20248
 
      new_sfp = BuildOneNewCDSGeneProtFeature (cdsp, SEQFEAT_GENE);
20249
 
      if (new_sfp != NULL)
20250
 
      {
20251
 
        ValNodeAddPointer (&(cdsp->gene_list), 0, new_sfp);
20252
 
      }
20253
 
    }
20254
 
  }
20255
 
  else if (vnp->data.intvalue <= 1 + num_gene_fields + num_mrna_fields)
20256
 
  {
20257
 
    /* for now, don't build anything but genes */
20258
 
#if 0
20259
 
    if (cdsp->mrna_list == NULL)
20260
 
    {
20261
 
      /* add new mrna */
20262
 
      new_sfp = BuildOneNewCDSGeneProtFeature (cdsp, SEQFEAT_RNA);
20263
 
      if (new_sfp != NULL)
20264
 
      {
20265
 
        ValNodeAddPointer (&(cdsp->mrna_list), 0, new_sfp);
20266
 
      }
20267
 
    }
20268
 
#endif
20269
 
  }
20270
 
  else if (vnp->data.intvalue <= 1 + num_gene_fields + num_mrna_fields + num_protein_fields)
20271
 
  {
20272
 
    /* for now, don't build anything but genes */
20273
 
#if 0
20274
 
    if (cdsp->prot_list == NULL)
20275
 
    {
20276
 
      /* add new prot */
20277
 
      new_sfp = BuildOneNewCDSGeneProtFeature (cdsp, SEQFEAT_PROT);
20278
 
      if (new_sfp != NULL)
20279
 
      {
20280
 
        ValNodeAddPointer (&(cdsp->prot_list), 0, new_sfp);
20281
 
      }
20282
 
    }
20283
 
#endif
20284
 
  }  
20285
 
}
20286
 
 
20287
 
static void BuildGeneForSegSet (BioseqSetPtr segset)
 
24229
    return NULL;
 
24230
  }
 
24231
 
 
24232
  choice_to = FeatDefTypeFromFieldList (vnp);
 
24233
  choice_from = FeatDefTypeFromFieldList (field_from);
 
24234
 
 
24235
  switch (choice_to)
 
24236
  {
 
24237
    case FEATDEF_CDS:
 
24238
      if (choice_from != 0 && cdsp->cds_list == NULL)
 
24239
      {
 
24240
        /* add new CDS */
 
24241
        new_sfp = BuildOneNewCDSGeneProtFeature (cdsp, choice_to, choice_from);
 
24242
        if (new_sfp != NULL)
 
24243
        {
 
24244
          ValNodeAddPointer (&(cdsp->cds_list), 0, new_sfp);
 
24245
        }
 
24246
      }
 
24247
      break;
 
24248
    case FEATDEF_GENE:
 
24249
      if ((choice_from != 0 || vnp->data.intvalue - 1 == GENEFIELD_LOCUS) && cdsp->gene_list == NULL)
 
24250
      {
 
24251
        /* add new gene */
 
24252
        new_sfp = BuildOneNewCDSGeneProtFeature (cdsp, choice_to, choice_from);
 
24253
        if (new_sfp != NULL)
 
24254
        {
 
24255
          ValNodeAddPointer (&(cdsp->gene_list), 0, new_sfp);
 
24256
        }
 
24257
      }
 
24258
      break;
 
24259
    case FEATDEF_mRNA:
 
24260
      if (choice_from != 0 && cdsp->mrna_list == NULL)
 
24261
      {
 
24262
        /* add new mrna */
 
24263
        new_sfp = BuildOneNewCDSGeneProtFeature (cdsp, choice_to, choice_from);
 
24264
        if (new_sfp != NULL)
 
24265
        {
 
24266
          ValNodeAddPointer (&(cdsp->mrna_list), 0, new_sfp);
 
24267
        }
 
24268
      }
 
24269
      break;
 
24270
    case FEATDEF_PROT:
 
24271
    case FEATDEF_mat_peptide_aa:
 
24272
      if (choice_from != 0 && cdsp->cds_list != NULL)
 
24273
      {
 
24274
        found = FALSE;
 
24275
        for (v = cdsp->prot_list; v != NULL && !found; v = v->next)
 
24276
        {
 
24277
          sfp = (SeqFeatPtr) v->data.ptrvalue;
 
24278
          if (sfp != NULL && sfp->idx.subtype == choice_to)
 
24279
          {
 
24280
            found = FALSE;
 
24281
          }
 
24282
        }
 
24283
        if (!found)
 
24284
        {
 
24285
          new_sfp = BuildOneNewCDSGeneProtFeature (cdsp, choice_to, choice_from);
 
24286
          if (new_sfp != NULL)
 
24287
          {
 
24288
            /* set subtype so other functions will work */
 
24289
            new_sfp->idx.subtype = choice_to;
 
24290
            ValNodeAddPointer (&(cdsp->mrna_list), 0, new_sfp);
 
24291
          }
 
24292
        }
 
24293
      }
 
24294
      break;
 
24295
  }
 
24296
  return new_sfp;        
 
24297
}
 
24298
 
 
24299
static Boolean CDSetOnBioseq (CDSetPtr cdsp, BioseqPtr bsp)
 
24300
{
 
24301
  SeqFeatPtr sfp;
 
24302
  Boolean    is_on_bioseq = FALSE;
 
24303
  ValNodePtr sfp_vnp;
 
24304
 
 
24305
  if (cdsp == NULL || bsp == NULL) return FALSE;
 
24306
 
 
24307
  for (sfp_vnp = cdsp->cds_list; sfp_vnp != NULL && !is_on_bioseq; sfp_vnp = sfp_vnp->next)
 
24308
  {
 
24309
    sfp = sfp_vnp->data.ptrvalue;
 
24310
    if (sfp != NULL && BioseqFindFromSeqLoc (sfp->location) == bsp) {
 
24311
      is_on_bioseq = TRUE;
 
24312
    }
 
24313
  }
 
24314
  for (sfp_vnp = cdsp->gene_list; sfp_vnp != NULL && !is_on_bioseq; sfp_vnp = sfp_vnp->next)
 
24315
  {
 
24316
    sfp = sfp_vnp->data.ptrvalue;
 
24317
    if (sfp != NULL && BioseqFindFromSeqLoc (sfp->location) == bsp) {
 
24318
      is_on_bioseq = TRUE;
 
24319
    }
 
24320
  }
 
24321
  for (sfp_vnp = cdsp->mrna_list; sfp_vnp != NULL && !is_on_bioseq; sfp_vnp = sfp_vnp->next)
 
24322
  {
 
24323
    sfp = sfp_vnp->data.ptrvalue;
 
24324
    if (sfp != NULL && BioseqFindFromSeqLoc (sfp->location) == bsp) {
 
24325
      is_on_bioseq = TRUE;
 
24326
    }
 
24327
  }
 
24328
  return is_on_bioseq;
 
24329
}
 
24330
 
 
24331
static Boolean ValNodeDataAlreadyInValNodeList (ValNodePtr list, ValNodePtr findme)
 
24332
{
 
24333
  if (findme == NULL) return FALSE;
 
24334
  while (list != NULL) 
 
24335
  {
 
24336
    if (list->data.ptrvalue == findme->data.ptrvalue)
 
24337
    {
 
24338
      return TRUE;
 
24339
    }
 
24340
    list = list->next;
 
24341
  }
 
24342
  return FALSE;
 
24343
}
 
24344
 
 
24345
static void BuildGeneForSegSet (BioseqSetPtr segset, ValNodePtr PNTR cdset_list, Boolean lonely_ok)
20288
24346
{
20289
24347
  SeqEntryPtr       this_sep, master_sep = NULL;
20290
24348
  BioseqSetPtr      part_set = NULL;
20291
24349
  SeqLocPtr         slp = NULL, slp_new, slp_last = NULL;
20292
24350
  SeqFeatPtr        sfp;
20293
24351
  SeqMgrFeatContext context;
 
24352
  ValNodePtr        vnp, add_gene_to = NULL;
 
24353
  Boolean           on_part;
 
24354
  CDSetPtr          cdsp;
20294
24355
  
20295
24356
  if (segset == NULL || segset->seq_set == NULL)
20296
24357
  {
20333
24394
    {
20334
24395
      return;
20335
24396
    }
20336
 
  
20337
 
    this_sep = part_set->seq_set;
20338
 
    while (this_sep != NULL)
 
24397
 
 
24398
    /* no other genes anywhere in segmented set.  Any cdsets? */
 
24399
    for (vnp = *cdset_list; vnp != NULL; vnp = vnp->next)
20339
24400
    {
20340
 
      if (IS_Bioseq (this_sep))
20341
 
      {
20342
 
        slp_new = SeqLocWholeNew (this_sep->data.ptrvalue);
20343
 
        if (slp_new != NULL)
20344
 
        {
20345
 
          if (slp_last == NULL)
20346
 
          {
20347
 
            slp = slp_new;
20348
 
          }
20349
 
          else
20350
 
          {
20351
 
            slp_last = ValNodeNew (slp);
20352
 
            slp_last->choice = SEQLOC_NULL;
20353
 
            slp_last->next = slp_new;
20354
 
          }
20355
 
          slp_last = slp_new;
20356
 
        }
20357
 
      }
20358
 
      this_sep = this_sep->next;
20359
 
    }
20360
 
    slp_new = ValNodeNew (NULL);
20361
 
    slp_new->choice = SEQLOC_MIX;
20362
 
    slp_new->data.ptrvalue = slp;
20363
 
    sfp = CreateNewFeature (master_sep, NULL, SEQFEAT_GENE, NULL);
20364
 
    sfp->location = SeqLocFree (sfp->location);
20365
 
    sfp->location = slp_new;
20366
 
    sfp->data.value.ptrvalue = GeneRefNew ();
20367
 
  }
20368
 
}
20369
 
 
20370
 
static void BuildNewGenes (SeqEntryPtr sep)
 
24401
      cdsp = (CDSetPtr) vnp->data.ptrvalue;
 
24402
      if (CDSetOnBioseq(cdsp, master_sep->data.ptrvalue)
 
24403
          && !ValNodeDataAlreadyInValNodeList(add_gene_to, vnp)) 
 
24404
      {
 
24405
        ValNodeAddPointer (&add_gene_to, 0, cdsp);
 
24406
      }
 
24407
      else
 
24408
      {
 
24409
        on_part = FALSE;
 
24410
        for (this_sep = part_set->seq_set; this_sep != NULL && !on_part; this_sep = this_sep->next) 
 
24411
        {
 
24412
          if (CDSetOnBioseq(cdsp, this_sep->data.ptrvalue)
 
24413
              && !ValNodeDataAlreadyInValNodeList(add_gene_to, vnp)) 
 
24414
          {
 
24415
            ValNodeAddPointer (&add_gene_to, 0, cdsp);
 
24416
            on_part = TRUE;
 
24417
          }
 
24418
        }
 
24419
      }
 
24420
    }
 
24421
 
 
24422
    if (add_gene_to != NULL || lonely_ok) {    
 
24423
      /* create gene */
 
24424
      this_sep = part_set->seq_set;
 
24425
      while (this_sep != NULL)
 
24426
      {
 
24427
        if (IS_Bioseq (this_sep))
 
24428
        {
 
24429
          slp_new = SeqLocWholeNew (this_sep->data.ptrvalue);
 
24430
          if (slp_new != NULL)
 
24431
          {
 
24432
            if (slp_last == NULL)
 
24433
            {
 
24434
              slp = slp_new;
 
24435
            }
 
24436
            else
 
24437
            {
 
24438
              slp_last = ValNodeNew (slp);
 
24439
              slp_last->choice = SEQLOC_NULL;
 
24440
              slp_last->next = slp_new;
 
24441
            }
 
24442
            slp_last = slp_new;
 
24443
          }
 
24444
        }
 
24445
        this_sep = this_sep->next;
 
24446
      }
 
24447
      slp_new = ValNodeNew (NULL);
 
24448
      slp_new->choice = SEQLOC_MIX;
 
24449
      slp_new->data.ptrvalue = slp;
 
24450
      sfp = CreateNewFeature (master_sep, NULL, SEQFEAT_GENE, NULL);
 
24451
      sfp->location = SeqLocFree (sfp->location);
 
24452
      sfp->location = slp_new;
 
24453
      sfp->data.value.ptrvalue = GeneRefNew ();
 
24454
 
 
24455
      /* add to sets */
 
24456
      if (add_gene_to == NULL)
 
24457
      {
 
24458
        cdsp = (CDSetPtr) MemNew (sizeof (CDSetData));
 
24459
        MemSet (cdsp, 0, sizeof (CDSetData));
 
24460
        ValNodeAddPointer (&(cdsp->gene_list), 0, sfp);
 
24461
        ValNodeAddPointer (cdset_list, 0, cdsp);
 
24462
      }
 
24463
      else
 
24464
      {
 
24465
        for (vnp = add_gene_to; vnp != NULL; vnp = vnp->next)
 
24466
        {
 
24467
          cdsp = (CDSetPtr) vnp->data.ptrvalue;
 
24468
          ValNodeAddPointer (&(cdsp->gene_list), 0, sfp);
 
24469
        }
 
24470
      }
 
24471
    }
 
24472
    add_gene_to = ValNodeFree (add_gene_to);
 
24473
  }
 
24474
}
 
24475
 
 
24476
static Boolean LoneGeneOkWithFilter (FilterSetPtr fsp)
 
24477
{
 
24478
  if (fsp == NULL || fsp->cgp == NULL
 
24479
      || fsp->cgp->constraint_type == CHOICE_CONSTRAINT_ANY
 
24480
      || (fsp->cgp->constraint_type == CHOICE_CONSTRAINT_QUAL_PRESENT
 
24481
          && fsp->cgp->qual_choice == NULL))
 
24482
  {
 
24483
    return TRUE;
 
24484
  }
 
24485
  else
 
24486
  {
 
24487
    return FALSE;
 
24488
  }
 
24489
}
 
24490
 
 
24491
static void BuildNewGenes (SeqEntryPtr sep, ValNodePtr PNTR cdset_list, Boolean lonely_ok)
20371
24492
{
20372
24493
  BioseqSetPtr      bssp = NULL;
20373
24494
  BioseqPtr         bsp = NULL;
20374
24495
  SeqFeatPtr        sfp;
20375
24496
  SeqMgrFeatContext context;
20376
24497
  SeqLocPtr         slp = NULL;
 
24498
  ValNodePtr        vnp;
 
24499
  CDSetPtr          cdsp;
 
24500
  ValNodePtr        add_gene_to;
20377
24501
  
20378
24502
  if (sep == NULL) 
20379
24503
  {
20388
24512
      sfp = SeqMgrGetNextFeature (bsp, NULL, SEQFEAT_GENE, FEATDEF_GENE, &context);
20389
24513
      if (sfp == NULL)
20390
24514
      {
20391
 
        slp = SeqLocWholeNew (bsp);
20392
 
        sfp = CreateNewFeatureOnBioseq (bsp, SEQFEAT_GENE, slp);    
20393
 
        sfp->data.value.ptrvalue = GeneRefNew();  
 
24515
        /* are there any sets already on this Bioseq? */
 
24516
        add_gene_to = NULL;
 
24517
        for (vnp = *cdset_list; vnp != NULL; vnp = vnp->next) 
 
24518
        {
 
24519
          cdsp = (CDSetPtr) vnp->data.ptrvalue;
 
24520
          if (CDSetOnBioseq(cdsp, bsp))
 
24521
          {
 
24522
            if (cdsp->gene_list == NULL)
 
24523
            {
 
24524
              ValNodeAddPointer (&add_gene_to, 0, cdsp);
 
24525
            }
 
24526
          }
 
24527
        }
 
24528
        if (add_gene_to != NULL || lonely_ok) 
 
24529
        {
 
24530
          slp = SeqLocWholeNew (bsp);
 
24531
          sfp = CreateNewFeatureOnBioseq (bsp, SEQFEAT_GENE, slp);    
 
24532
          sfp->data.value.ptrvalue = GeneRefNew();  
 
24533
          if (add_gene_to == NULL)
 
24534
          {
 
24535
            cdsp = (CDSetPtr) MemNew (sizeof (CDSetData));
 
24536
            MemSet (cdsp, 0, sizeof (CDSetData));
 
24537
            ValNodeAddPointer (&(cdsp->gene_list), 0, sfp);
 
24538
            ValNodeAddPointer (cdset_list, 0, cdsp);
 
24539
          }
 
24540
          else
 
24541
          {
 
24542
            for (vnp = add_gene_to; vnp != NULL; vnp = vnp->next)
 
24543
            {
 
24544
              cdsp = (CDSetPtr) vnp->data.ptrvalue;
 
24545
              ValNodeAddPointer (&(cdsp->gene_list), 0, sfp);
 
24546
            }
 
24547
          }
 
24548
        }
 
24549
        add_gene_to = ValNodeFree (add_gene_to);
20394
24550
      }
20395
24551
    }
20396
24552
  }
20399
24555
    bssp = (BioseqSetPtr) sep->data.ptrvalue;
20400
24556
    if (bssp->_class == BioseqseqSet_class_segset)
20401
24557
    {
20402
 
      BuildGeneForSegSet (bssp);
 
24558
      BuildGeneForSegSet (bssp, cdset_list, lonely_ok);
20403
24559
    }
20404
24560
    else
20405
24561
    {
20406
 
      BuildNewGenes (bssp->seq_set);
 
24562
      BuildNewGenes (bssp->seq_set, cdset_list, lonely_ok);
20407
24563
    }
20408
24564
  }
20409
 
  BuildNewGenes (sep->next);
 
24565
  BuildNewGenes (sep->next, cdset_list, lonely_ok);
20410
24566
}
20411
24567
 
20412
24568
typedef Boolean (*Nlm_TestAECRChoiceProc) PROTO((Pointer));
20415
24571
typedef DialoG  (*Nlm_FieldListDlgProc) PROTO ((GrouP, Boolean, Nlm_ChangeNotifyProc, Pointer));
20416
24572
typedef DialoG  (*Nlm_SubtypeListDlgProc) PROTO ((GrouP, Boolean, SeqEntryPtr, Nlm_ChangeNotifyProc, Pointer));
20417
24573
 
20418
 
#define AECR_APPLY   1
20419
 
#define AECR_EDIT    2
20420
 
#define AECR_CONVERT 3
20421
 
#define AECR_SWAP    4
20422
 
#define AECR_PARSE   5
20423
 
#define AECR_REMOVE  6
20424
 
#define NUM_AECR     6
20425
 
 
20426
24574
#define AECR_VIB_MSG_SET_DEFAULT (NUM_VIB_MSG + 1)
20427
24575
#define AECR_VIB_MSG_CLEAR_TEXT  (NUM_VIB_MSG + 2)
20428
24576
#define AECR_VIB_MSG_AUTOPOPULATE (NUM_VIB_MSG + 3)
20636
24784
 Boolean                  source_constraint,
20637
24785
 Boolean                  location_constraint,
20638
24786
 Boolean                  cds_gene_prot_constraint,
 
24787
 Boolean                  id_list_constraint,
20639
24788
 CharPtr                  string_constraint_label,
20640
24789
 Nlm_AcceptActnProc       accept_actn,
20641
24790
 Nlm_CancelActnProc       cancel_actn,
20673
24822
  SetObjectExtra (w, mp, NULL);
20674
24823
  mp->form = (ForM) w;
20675
24824
  mp->input_entityID = bfp->input_entityID;
 
24825
 
 
24826
#ifndef WIN_MAC
 
24827
  CreateStandardEditMenu (w);
 
24828
#endif
20676
24829
  
20677
24830
  n = HiddenGroup (w, -1, 0, NULL);
20678
24831
  SetGroupSpacing (n, 10, 10);
20741
24894
                                (HANDLE) NULL);
20742
24895
    mp->constraints = FilterGroup (n, string_constraint, source_constraint, 
20743
24896
                                   location_constraint, cds_gene_prot_constraint,
 
24897
                                   id_list_constraint,
20744
24898
                                   string_constraint_label);
20745
24899
  
20746
24900
  }
20806
24960
}
20807
24961
 
20808
24962
 
20809
 
typedef struct editapply
20810
 
{
20811
 
  CharPtr    find_txt;
20812
 
  CharPtr    repl_txt;
20813
 
  CharPtr    apply_txt;  
20814
 
} EditApplyData, PNTR EditApplyPtr;
20815
 
 
20816
 
static EditApplyPtr EditApplyFree (EditApplyPtr eap)
20817
 
{
20818
 
  if (eap != NULL)
20819
 
  {
20820
 
    eap->find_txt = MemFree (eap->find_txt);
20821
 
    eap->repl_txt = MemFree (eap->repl_txt);
20822
 
    eap->apply_txt = MemFree (eap->apply_txt);
20823
 
    eap = MemFree (eap);
20824
 
  }
20825
 
  return eap;
20826
 
}
20827
 
 
20828
 
typedef struct EditApplydlg
20829
 
{
20830
 
  DIALOG_MESSAGE_BLOCK
20831
 
  TexT           find_txt;
20832
 
  TexT           repl_txt;
20833
 
  TexT           apply_txt;
20834
 
  Int4           action_choice;
20835
 
} EditApplyDlgData, PNTR EditApplyDlgPtr;
20836
 
 
20837
 
static void ResetEditApplyDlg (EditApplyDlgPtr dlg)
20838
 
{
20839
 
  if (dlg != NULL)
20840
 
  {
20841
 
    if (dlg->find_txt != NULL)
20842
 
    {
20843
 
      SetTitle (dlg->find_txt, "");
20844
 
    }
20845
 
    if (dlg->repl_txt != NULL)
20846
 
    {
20847
 
      SetTitle (dlg->repl_txt, "");
20848
 
    }
20849
 
    if (dlg->apply_txt != NULL)
20850
 
    {
20851
 
      SetTitle (dlg->apply_txt, "");
20852
 
    }
20853
 
  }
20854
 
}
20855
 
 
20856
 
static void EditApplyToDialog (DialoG d, Pointer userdata)
20857
 
{
20858
 
  EditApplyDlgPtr dlg;
20859
 
  EditApplyPtr    data;
20860
 
  
20861
 
  dlg = (EditApplyDlgPtr) GetObjectExtra (d);
20862
 
  if (dlg == NULL)
20863
 
  {
20864
 
    return;
20865
 
  }
20866
 
  
20867
 
  ResetEditApplyDlg (dlg);
20868
 
  data = (EditApplyPtr) userdata;
20869
 
  if (data != NULL)
20870
 
  {
20871
 
    if (dlg->find_txt != NULL && !StringHasNoText (data->find_txt))
20872
 
    {
20873
 
      SetTitle (dlg->find_txt, data->find_txt);
20874
 
    }
20875
 
    if (dlg->repl_txt != NULL && !StringHasNoText (data->repl_txt))
20876
 
    {
20877
 
      SetTitle (dlg->repl_txt, data->repl_txt);
20878
 
    }
20879
 
    if (dlg->apply_txt != NULL && !StringHasNoText (data->apply_txt))
20880
 
    {
20881
 
      SetTitle (dlg->apply_txt, data->apply_txt);
20882
 
    }
20883
 
  }
20884
 
}
20885
 
 
20886
 
static Pointer DialogToEditApply (DialoG d)
20887
 
{
20888
 
  EditApplyDlgPtr dlg;
20889
 
  EditApplyPtr    data;
20890
 
  
20891
 
  dlg = (EditApplyDlgPtr) GetObjectExtra (d);
20892
 
  if (dlg == NULL)
20893
 
  {
20894
 
    return NULL;
20895
 
  }
20896
 
  
20897
 
  data = (EditApplyPtr) MemNew (sizeof (EditApplyData));
20898
 
  if (data != NULL)
20899
 
  {
20900
 
    if (dlg->find_txt != NULL)
20901
 
    {
20902
 
      data->find_txt = JustSaveStringFromText (dlg->find_txt);
20903
 
    }
20904
 
    if (dlg->repl_txt != NULL)
20905
 
    {
20906
 
      data->repl_txt = JustSaveStringFromText (dlg->repl_txt);
20907
 
    }
20908
 
    if (dlg->apply_txt != NULL)
20909
 
    {
20910
 
      data->apply_txt = JustSaveStringFromText (dlg->apply_txt);
20911
 
    }
20912
 
  }
20913
 
  return data;
20914
 
}
20915
 
 
20916
 
static void EditApplyMessage (DialoG d, Int2 mssg)
20917
 
 
20918
 
{
20919
 
  EditApplyDlgPtr  dlg;
20920
 
 
20921
 
  dlg = (EditApplyDlgPtr) GetObjectExtra (d);
20922
 
  if (dlg != NULL) {
20923
 
    switch (mssg) 
20924
 
    {
20925
 
      case VIB_MSG_INIT :
20926
 
        /* reset list */
20927
 
        ResetEditApplyDlg (dlg);
20928
 
        break;
20929
 
      case VIB_MSG_ENTER :
20930
 
        if (dlg->find_txt != NULL)
20931
 
        {
20932
 
          Select (dlg->find_txt);
20933
 
        }
20934
 
        else if (dlg->apply_txt != NULL)
20935
 
        {
20936
 
          Select (dlg->apply_txt);
20937
 
        }
20938
 
        break;
20939
 
      case AECR_VIB_MSG_SET_DEFAULT :
20940
 
        ResetEditApplyDlg (dlg);
20941
 
        break;
20942
 
      case AECR_VIB_MSG_CLEAR_TEXT :
20943
 
        ResetEditApplyDlg (dlg);
20944
 
        break;
20945
 
      default :
20946
 
        break;
20947
 
    }
20948
 
  }
20949
 
}
20950
 
 
20951
 
static ValNodePtr TestEditApply (DialoG d)
20952
 
{
20953
 
  EditApplyDlgPtr dlg;
20954
 
  ValNodePtr      total_err_list = NULL;
20955
 
  
20956
 
  dlg = (EditApplyDlgPtr) GetObjectExtra (d);
20957
 
  if (dlg == NULL)
20958
 
  {
20959
 
    return FALSE;
20960
 
  }
20961
 
 
20962
 
  if (dlg->action_choice == AECR_APPLY)
20963
 
  {
20964
 
    if (TextHasNoText (dlg->apply_txt))
20965
 
    {
20966
 
      ValNodeAddPointer (&total_err_list, 0, "apply text");
20967
 
    }
20968
 
  }
20969
 
  else if (dlg->action_choice == AECR_EDIT)
20970
 
  {
20971
 
    if (TextHasNoText (dlg->find_txt))
20972
 
    {
20973
 
      ValNodeAddPointer (&total_err_list, 0, "find text");
20974
 
    }
20975
 
  }
20976
 
  return total_err_list;
20977
 
}
20978
 
 
20979
 
static void EditApplyDialogCopy (ButtoN b)
20980
 
{
20981
 
  EditApplyDlgPtr dlg;
20982
 
  CharPtr         str = NULL;
20983
 
 
20984
 
  dlg = (EditApplyDlgPtr) GetObjectExtra (b);
20985
 
  if (dlg == NULL)
20986
 
  {
20987
 
    return;
20988
 
  }
20989
 
  str = JustSaveStringFromText (dlg->find_txt);
20990
 
  SetTitle (dlg->repl_txt, str);
20991
 
  str = MemFree (str);
20992
 
}
20993
 
 
20994
 
static DialoG EditApplyDialog 
20995
 
(GrouP                    h,
20996
 
 Int4                     action_choice, 
20997
 
 CharPtr                  apply_label,
20998
 
 Nlm_ChangeNotifyProc     change_notify,
20999
 
 Pointer                  change_userdata)
21000
 
{
21001
 
  EditApplyDlgPtr dlg;
21002
 
  GrouP           p;
21003
 
  ButtoN          b;
21004
 
  
21005
 
  dlg = (EditApplyDlgPtr) MemNew (sizeof (EditApplyDlgData));
21006
 
  if (dlg == NULL)
21007
 
  {
21008
 
    return NULL;
21009
 
  }
21010
 
 
21011
 
  p = HiddenGroup (h, 3, 0, NULL);
21012
 
  SetGroupSpacing (p, 10, 10);
21013
 
  SetObjectExtra (p, dlg, StdCleanupExtraProc);
21014
 
  
21015
 
  dlg->dialog = (DialoG) p;
21016
 
  dlg->todialog = EditApplyToDialog;
21017
 
  dlg->fromdialog = DialogToEditApply;
21018
 
  dlg->dialogmessage = EditApplyMessage;
21019
 
  dlg->testdialog = TestEditApply;
21020
 
  dlg->action_choice = action_choice;
21021
 
  
21022
 
  if (action_choice == AECR_APPLY)
21023
 
  {
21024
 
    StaticPrompt (p, apply_label, 0, dialogTextHeight, systemFont, 'r');
21025
 
    dlg->apply_txt = DialogText (p, "", 20, ApplyEditConvertRemoveTextChange);
21026
 
    SetObjectExtra (dlg->apply_txt, change_userdata, NULL);
21027
 
  }
21028
 
  else if (action_choice == AECR_EDIT)
21029
 
  {
21030
 
    StaticPrompt (p, "Find", 0, dialogTextHeight, systemFont, 'r');
21031
 
    dlg->find_txt = DialogText (p, "", 18, ApplyEditConvertRemoveTextChange);
21032
 
    SetObjectExtra (dlg->find_txt, change_userdata, NULL);
21033
 
    b = PushButton (p, "Copy", EditApplyDialogCopy);
21034
 
    SetObjectExtra (b, dlg, NULL);
21035
 
    Hide (b);
21036
 
    StaticPrompt (p, "Replace", 0, dialogTextHeight, systemFont, 'r');
21037
 
    dlg->repl_txt = DialogText (p, "", 18, ApplyEditConvertRemoveTextChange);
21038
 
    SetObjectExtra (dlg->repl_txt, change_userdata, NULL);
21039
 
    b = PushButton (p, "Copy", EditApplyDialogCopy);
21040
 
    SetObjectExtra (b, dlg, NULL);
21041
 
  }
21042
 
  return (DialoG) p;
21043
 
}
21044
 
 
21045
24963
typedef struct conversionconflict 
21046
24964
{
21047
24965
  ConvertFieldPtr cfp;
21206
25124
  {
21207
25125
    avp->text_to_replace = NULL;
21208
25126
    avp->new_text = NULL;
 
25127
    avp->where_to_replace = EditApplyFindLocation_anywhere;
 
25128
 
21209
25129
    return;
21210
25130
  }
21211
25131
 
21213
25133
  {
21214
25134
    avp->text_to_replace = StringSave (edit_apply->find_txt);
21215
25135
    avp->new_text = StringSave (edit_apply->repl_txt);
 
25136
    avp->where_to_replace = edit_apply->find_location;
21216
25137
  }
21217
25138
  else if (action_choice == AECR_APPLY)
21218
25139
  {
21219
25140
    avp->new_text = StringSave (edit_apply->apply_txt);
21220
25141
    avp->text_to_replace = NULL; 
 
25142
    avp->where_to_replace = EditApplyFindLocation_anywhere;
21221
25143
  }
21222
25144
  else
21223
25145
  {
21224
25146
    avp->text_to_replace = NULL;
21225
25147
    avp->new_text = NULL;
 
25148
    avp->where_to_replace = EditApplyFindLocation_anywhere;
21226
25149
  } 
21227
25150
}
21228
25151
 
 
25152
#define AECR_DATA_BLOCK \
 
25153
  ValNodePtr      field_list;           \
 
25154
  ValNodePtr      field_list_to;        \
 
25155
  ValNodePtr      subtype_list;         \
 
25156
  Boolean         leave_on_original;    \
 
25157
  Boolean         strip_name_from_text; \
 
25158
  EditApplyPtr    edit_apply;           \
 
25159
  TextPortionXPtr  text_portion;         \
 
25160
  Boolean         remove_parsed;        \
 
25161
  FreeValNodeProc free_field_vn_proc;   \
 
25162
  FreeValNodeProc free_subtype_vn_proc;
 
25163
 
21229
25164
typedef struct simpleaecr
21230
25165
{
21231
 
  ValNodePtr      field_list;
21232
 
  ValNodePtr      field_list_to;
21233
 
  ValNodePtr      subtype_list;
21234
 
  Boolean         leave_on_original;
21235
 
  Boolean         strip_name_from_text;
21236
 
  EditApplyPtr    edit_apply;
21237
 
  TextPortionPtr  text_portion;
21238
 
  Boolean         remove_parsed;
21239
 
  FreeValNodeProc free_field_vn_proc;
21240
 
  FreeValNodeProc free_subtype_vn_proc;
 
25166
  AECR_DATA_BLOCK
21241
25167
} SimpleAECRData, PNTR SimpleAECRPtr;
21242
25168
 
21243
 
static SimpleAECRPtr SimpleAECRFree (SimpleAECRPtr sp)
 
25169
static void AECRDataBlockFreeContents (SimpleAECRPtr sp)
21244
25170
{
21245
25171
  if (sp != NULL)
21246
25172
  {
21248
25174
    sp->field_list_to = ValNodeFuncFree (sp->field_list_to, sp->free_field_vn_proc);
21249
25175
    sp->subtype_list = ValNodeFuncFree (sp->subtype_list, sp->free_subtype_vn_proc);
21250
25176
    sp->edit_apply = EditApplyFree (sp->edit_apply);
21251
 
    sp->text_portion = TextPortionFree(sp->text_portion);
 
25177
    sp->text_portion = TextPortionXFree(sp->text_portion);
 
25178
  }
 
25179
}
 
25180
 
 
25181
static SimpleAECRPtr SimpleAECRFree (SimpleAECRPtr sp)
 
25182
{
 
25183
  if (sp != NULL)
 
25184
  {
 
25185
    AECRDataBlockFreeContents (sp);
21252
25186
    sp = MemFree (sp);
21253
25187
  }
21254
25188
  return sp;
21257
25191
/* This function is used to autopopulate the new_text and find fields */
21258
25192
typedef CharPtr (*GetAutoPopulateTextFunc) PROTO ((ValNodePtr, ValNodePtr, Uint2));
21259
25193
 
21260
 
typedef struct simpleecrdlg
 
25194
#define AECR_BLOCK \
 
25195
  DIALOG_MESSAGE_BLOCK                                \
 
25196
  DialoG          field_list;                         \
 
25197
  DialoG          field_list_to;                      \
 
25198
  DialoG          subtype_list;                       \
 
25199
  ButtoN          leave_on_original;                  \
 
25200
  ButtoN          strip_name_from_text;               \
 
25201
  DialoG          edit_apply;                         \
 
25202
  DialoG          text_portion;                       \
 
25203
  ButtoN          remove_parsed;                      \
 
25204
  Int4            action_choice;                      \
 
25205
  /* These are necessary to produce the SimpleAECR structure for output */ \
 
25206
  FreeValNodeProc free_field_vn_proc;                 \
 
25207
  FreeValNodeProc free_subtype_vn_proc;               \
 
25208
  /* These are used for autopopulating text fields */ \
 
25209
  GetAutoPopulateTextFunc  get_autopopulate_text;     \
 
25210
  Nlm_ChangeNotifyProc     change_notify;             \
 
25211
  Pointer                  change_userdata;           \
 
25212
  Uint2                    entityID;
 
25213
 
 
25214
typedef struct simpleaecrdlg
21261
25215
{
21262
 
  DIALOG_MESSAGE_BLOCK
21263
 
  DialoG          field_list;
21264
 
  DialoG          field_list_to;
21265
 
  DialoG          subtype_list;
21266
 
  ButtoN          leave_on_original;  
21267
 
  ButtoN          strip_name_from_text;
21268
 
  DialoG          edit_apply; 
21269
 
  DialoG          text_portion;
21270
 
  ButtoN          remove_parsed;
21271
 
  Int4            action_choice;
21272
 
  /* These are necessary to produce the SimpleAECR structure for output */
21273
 
  FreeValNodeProc free_field_vn_proc;
21274
 
  FreeValNodeProc free_subtype_vn_proc;
21275
 
  
21276
 
  /* These are used for autopopulating text fields */
21277
 
  GetAutoPopulateTextFunc  get_autopopulate_text;
21278
 
  Nlm_ChangeNotifyProc     change_notify;
21279
 
  Pointer                  change_userdata;
21280
 
  Uint2                    entityID;
 
25216
  AECR_BLOCK
21281
25217
} SimpleAECRDlgData, PNTR SimpleAECRDlgPtr;
21282
25218
 
21283
25219
static void ClearTextSimpleAECRDlg (SimpleAECRDlgPtr dlg)
21508
25444
  return total_err_list;
21509
25445
}
21510
25446
 
 
25447
static void SimpleAECRButtonChange (ButtoN b)
 
25448
{
 
25449
  SimpleAECRDlgPtr dlg;
 
25450
 
 
25451
  dlg = (SimpleAECRDlgPtr) GetObjectExtra (b);
 
25452
  if (dlg == NULL) return;
 
25453
 
 
25454
  if (dlg->change_notify != NULL) 
 
25455
  {
 
25456
    (dlg->change_notify) (dlg->change_userdata);
 
25457
  }
 
25458
}
 
25459
 
21511
25460
static DialoG SimpleAECRDialogEx
21512
25461
(GrouP                    h,
21513
25462
 Int4                     action_choice, 
21582
25531
                                             change_userdata);
21583
25532
    if (action_choice == AECR_CONVERT && is_text)
21584
25533
    {
21585
 
      dlg->leave_on_original = CheckBox (p, "Leave on original", NULL);
 
25534
      dlg->leave_on_original = CheckBox (p, "Leave on original", SimpleAECRButtonChange);
 
25535
      SetObjectExtra (dlg->leave_on_original, dlg, NULL);
21586
25536
    }
21587
25537
    if (strip_name)
21588
25538
    {
21589
 
      dlg->strip_name_from_text = CheckBox (p, "Strip name from text", NULL);
 
25539
      dlg->strip_name_from_text = CheckBox (p, "Strip name from text", SimpleAECRButtonChange);
 
25540
      SetObjectExtra (dlg->strip_name_from_text, dlg, NULL);
21590
25541
    }
21591
25542
  }
21592
25543
  else
21628
25579
  
21629
25580
  if (is_text && (action_choice == AECR_APPLY || action_choice == AECR_EDIT))
21630
25581
  {
21631
 
    dlg->edit_apply = EditApplyDialog (p, action_choice, "New Text",
 
25582
    dlg->edit_apply = EditApplyDialog (p, 
 
25583
                                       action_choice == AECR_APPLY ? eEditApplyChoice_Apply : eEditApplyChoice_Edit,
 
25584
                                       "New Text", NULL,
21632
25585
                                       change_notify, change_userdata);
21633
25586
    dlg->text_portion = NULL;
21634
25587
    dlg->remove_parsed = NULL;
21637
25590
  {
21638
25591
    dlg->edit_apply = NULL;
21639
25592
    if (is_text) {
21640
 
        dlg->text_portion = TextPortionDialog(p);
 
25593
        dlg->text_portion = TextPortionXDialog(p);
21641
25594
    }
21642
 
    dlg->remove_parsed = CheckBox (p, "Remove from parsed field", NULL);
 
25595
    dlg->remove_parsed = CheckBox (p, "Remove from parsed field", SimpleAECRButtonChange);
 
25596
    SetObjectExtra (dlg->remove_parsed, dlg, NULL);
21643
25597
  }
21644
25598
  else
21645
25599
  {
21719
25673
  return rval;
21720
25674
}
21721
25675
 
 
25676
typedef struct cdsgeneprotaecrdlg
 
25677
{
 
25678
  AECR_BLOCK
 
25679
  ButtoN also_mrna;
 
25680
} CDSGeneProtAECRDlgData, PNTR CDSGeneProtAECRDlgPtr;
 
25681
 
 
25682
typedef struct cdsgeneprotaecr 
 
25683
{
 
25684
  AECR_DATA_BLOCK
 
25685
  Boolean also_mrna;
 
25686
} CDSGeneProtAECRData, PNTR CDSGeneProtAECRPtr;
 
25687
 
 
25688
 
 
25689
static CDSGeneProtAECRPtr CDSGeneProtAECRFree (CDSGeneProtAECRPtr sp)
 
25690
{
 
25691
  if (sp != NULL)
 
25692
  {
 
25693
    AECRDataBlockFreeContents ((SimpleAECRPtr) sp);
 
25694
    sp = MemFree (sp);
 
25695
  }
 
25696
  return sp;
 
25697
}
 
25698
 
 
25699
 
 
25700
static void PointerToCDSGeneProtAECRDialog (DialoG d, Pointer userdata)
 
25701
{
 
25702
  CDSGeneProtAECRDlgPtr dlg;
 
25703
  CDSGeneProtAECRPtr    data;
 
25704
 
 
25705
  dlg = (CDSGeneProtAECRDlgPtr) GetObjectExtra (d);
 
25706
  if (dlg == NULL) return;
 
25707
  data = (CDSGeneProtAECRPtr) userdata;
 
25708
  SimpleAECRToDialog (d, userdata);
 
25709
  if (data != NULL)
 
25710
  {
 
25711
    SetStatus (dlg->also_mrna, data->also_mrna);
 
25712
  }
 
25713
  
 
25714
}
 
25715
 
 
25716
 
 
25717
static Boolean ShowingProteinName (CDSGeneProtAECRDlgPtr dlg)
 
25718
{
 
25719
  ValNodePtr vnp_from, vnp_to;
 
25720
  Int4       protein_name_field_num = 2 + num_gene_fields + num_mrna_fields;
 
25721
  Boolean    rval = FALSE;
 
25722
 
 
25723
  if (dlg == NULL) return FALSE;
 
25724
 
 
25725
  vnp_from = DialogToPointer (dlg->field_list);
 
25726
  vnp_to = DialogToPointer (dlg->field_list_to);
 
25727
 
 
25728
  if ((vnp_from != NULL && vnp_from->data.intvalue == protein_name_field_num)
 
25729
      || (vnp_to != NULL && vnp_to->data.intvalue == protein_name_field_num))
 
25730
  {
 
25731
    rval = TRUE;
 
25732
  }
 
25733
  vnp_from = ValNodeFree (vnp_from);
 
25734
  vnp_to = ValNodeFree (vnp_to);
 
25735
 
 
25736
  return rval;
 
25737
}
 
25738
 
 
25739
 
 
25740
static Pointer CDSGeneProtAECRDialogToPointer (DialoG d)
 
25741
{
 
25742
  CDSGeneProtAECRDlgPtr dlg;
 
25743
  SimpleAECRPtr         subset;
 
25744
  CDSGeneProtAECRPtr    data = NULL;
 
25745
 
 
25746
  dlg = (CDSGeneProtAECRDlgPtr) GetObjectExtra (d);
 
25747
  if (dlg == NULL) return NULL;
 
25748
 
 
25749
  subset = DialogToSimpleAECR (d);
 
25750
  if (subset != NULL)
 
25751
  {
 
25752
    data = (CDSGeneProtAECRPtr) MemNew (sizeof (CDSGeneProtAECRData));
 
25753
    MemCpy (data, subset, sizeof (SimpleAECRData));
 
25754
    MemSet (subset, 0, sizeof (SimpleAECRData));
 
25755
    subset = MemFree (subset);
 
25756
    if (ShowingProteinName (dlg))
 
25757
    {
 
25758
      data->also_mrna = GetStatus (dlg->also_mrna);
 
25759
    }
 
25760
    else
 
25761
    {
 
25762
      data->also_mrna = FALSE;
 
25763
    }
 
25764
  }
 
25765
  return data;
 
25766
}
 
25767
 
 
25768
 
 
25769
static void CDSGeneProtAECRDialogChange (Pointer data)
 
25770
{
 
25771
  CDSGeneProtAECRDlgPtr dlg;
 
25772
 
 
25773
  dlg = (CDSGeneProtAECRDlgPtr) data;
 
25774
  if (dlg == NULL) return;
 
25775
  
 
25776
  if (ShowingProteinName (dlg))
 
25777
  {
 
25778
    Show (dlg->also_mrna);
 
25779
  }
 
25780
  else
 
25781
  {
 
25782
    Hide (dlg->also_mrna);
 
25783
  }
 
25784
 
 
25785
  SimpleAECRDialogChangeNotify (dlg);
 
25786
}
 
25787
 
 
25788
 
21722
25789
static DialoG CDSGeneProtAECRDialog
21723
25790
(GrouP                    h,
21724
25791
 Int4                     action_choice, 
21726
25793
 Pointer                  change_userdata,
21727
25794
 Uint2                    entityID)
21728
25795
{
21729
 
  return SimpleAECRDialog (h, action_choice, change_notify, change_userdata,
21730
 
                           NULL, NULL, 
21731
 
                           CDSGeneProtFieldSelectionDialog, NULL,
21732
 
                           CDSGeneProtAutopopulate,
21733
 
                           "Field", NULL, TRUE, entityID);
 
25796
  CDSGeneProtAECRDlgPtr dlg;
 
25797
  GrouP                 p, g1;
 
25798
  SeqEntryPtr           sep;
 
25799
  
 
25800
  dlg = (CDSGeneProtAECRDlgPtr) MemNew (sizeof (CDSGeneProtAECRDlgData));
 
25801
  if (dlg == NULL)
 
25802
  {
 
25803
    return NULL;
 
25804
  }
 
25805
 
 
25806
  p = HiddenGroup (h, -1, 0, NULL);
 
25807
  SetObjectExtra (p, dlg, StdCleanupExtraProc);
 
25808
  SetGroupSpacing (p, 10, 10);
 
25809
  
 
25810
  dlg->dialog = (DialoG) p;
 
25811
  dlg->todialog = PointerToCDSGeneProtAECRDialog;
 
25812
  dlg->fromdialog = CDSGeneProtAECRDialogToPointer;
 
25813
  dlg->dialogmessage = SimpleAECRMessage;
 
25814
  dlg->testdialog = TestSimpleAECR;
 
25815
  dlg->action_choice = action_choice;
 
25816
  dlg->free_field_vn_proc = NULL;
 
25817
  dlg->free_subtype_vn_proc = NULL;
 
25818
  dlg->change_notify = change_notify;
 
25819
  dlg->change_userdata = change_userdata;
 
25820
  dlg->get_autopopulate_text = CDSGeneProtAutopopulate;
 
25821
  dlg->entityID = entityID;
 
25822
  dlg->strip_name_from_text = NULL;
 
25823
  
 
25824
  dlg->subtype_list = NULL;
 
25825
  
 
25826
  sep = GetTopSeqEntryForEntityID(entityID);
 
25827
  
 
25828
  if (action_choice == AECR_CONVERT || action_choice == AECR_SWAP || action_choice == AECR_PARSE)
 
25829
  {
 
25830
    g1 = HiddenGroup (p, 2, 0, NULL);
 
25831
    StaticPrompt (g1, "From", 0, dialogTextHeight, systemFont, 'l');
 
25832
    StaticPrompt (g1, "To", 0, dialogTextHeight, systemFont, 'l');
 
25833
    
 
25834
    dlg->field_list = CDSGeneProtFieldSelectionDialog (g1, FALSE, 
 
25835
                                          CDSGeneProtAECRDialogChange, 
 
25836
                                          dlg);
 
25837
    dlg->field_list_to = CDSGeneProtFieldSelectionDialog (g1, FALSE, 
 
25838
                                             CDSGeneProtAECRDialogChange, 
 
25839
                                             dlg);
 
25840
    if (action_choice == AECR_CONVERT)
 
25841
    {
 
25842
      dlg->leave_on_original = CheckBox (p, "Leave on original", NULL);
 
25843
    }
 
25844
  }
 
25845
  else
 
25846
  {
 
25847
    g1 = HiddenGroup (p, 1, 0, NULL);
 
25848
    StaticPrompt (g1, "Field", 0, dialogTextHeight, systemFont, 'l');
 
25849
    if (action_choice == AECR_REMOVE)
 
25850
    {
 
25851
      dlg->field_list = CDSGeneProtFieldSelectionDialog (g1, TRUE, 
 
25852
                                            CDSGeneProtAECRDialogChange, 
 
25853
                                            dlg);
 
25854
    }
 
25855
    else
 
25856
    {
 
25857
      dlg->field_list = CDSGeneProtFieldSelectionDialog (g1, FALSE, 
 
25858
                                            CDSGeneProtAECRDialogChange, 
 
25859
                                            dlg);
 
25860
    }
 
25861
  }
 
25862
  
 
25863
  if (action_choice == AECR_APPLY || action_choice == AECR_EDIT)
 
25864
  {
 
25865
    dlg->edit_apply = EditApplyDialog (p, 
 
25866
                                       action_choice == AECR_APPLY ? eEditApplyChoice_Apply : eEditApplyChoice_Edit,
 
25867
                                       "New Text", NULL,
 
25868
                                       change_notify, change_userdata);
 
25869
    dlg->text_portion = NULL;
 
25870
    dlg->remove_parsed = NULL;
 
25871
  }
 
25872
  else if (action_choice == AECR_PARSE)
 
25873
  {
 
25874
    dlg->edit_apply = NULL;
 
25875
    dlg->text_portion = TextPortionXDialog(p);
 
25876
    dlg->remove_parsed = CheckBox (p, "Remove from parsed field", NULL);
 
25877
  }
 
25878
  else
 
25879
  {
 
25880
    dlg->edit_apply = NULL;
 
25881
    dlg->text_portion = NULL;
 
25882
    dlg->remove_parsed = NULL;
 
25883
  }
 
25884
 
 
25885
  dlg->also_mrna = CheckBox (p, "Make mRNA product match CDS protein name", NULL);
 
25886
 
 
25887
  if (action_choice == AECR_CONVERT)
 
25888
  {
 
25889
    AlignObjects (ALIGN_CENTER, (HANDLE) g1, (HANDLE) dlg->leave_on_original, (HANDLE) dlg->also_mrna, NULL);
 
25890
  }
 
25891
  else if (action_choice == AECR_SWAP)
 
25892
  {
 
25893
    AlignObjects (ALIGN_CENTER, (HANDLE) g1, (HANDLE) dlg->strip_name_from_text, (HANDLE) dlg->also_mrna, NULL);
 
25894
  }
 
25895
  else if (action_choice == AECR_PARSE)
 
25896
  {
 
25897
    AlignObjects (ALIGN_CENTER, (HANDLE) g1, (HANDLE) dlg->text_portion, (HANDLE) dlg->remove_parsed, (HANDLE) dlg->also_mrna, NULL);
 
25898
  }
 
25899
  else
 
25900
  {
 
25901
    AlignObjects (ALIGN_CENTER, (HANDLE) g1, (HANDLE) dlg->edit_apply, (HANDLE) dlg->also_mrna, NULL);
 
25902
  }
 
25903
  return (DialoG) p;
 
25904
}
 
25905
 
 
25906
static Boolean AreFilterAndFieldBothForMatPeptide (FilterSetPtr fsp, ValNodePtr field_list)
 
25907
{
 
25908
  if (fsp != NULL && fsp->cgp == NULL 
 
25909
      && IsCDSetMatPeptideQualChoice(fsp->cgp->qual_choice) 
 
25910
      && IsCDSetMatPeptideQualChoice(field_list))
 
25911
  {
 
25912
    return TRUE;
 
25913
  }
 
25914
  else 
 
25915
  {
 
25916
    return FALSE;
 
25917
  }
 
25918
}
 
25919
 
 
25920
static void AddStringToSample (CharPtr str, GetSamplePtr gsp)
 
25921
{
 
25922
  if (gsp == NULL) return;
 
25923
 
 
25924
  if (str != NULL)
 
25925
  {
 
25926
    gsp->num_found ++;
 
25927
  }
 
25928
  if (gsp->sample_text == NULL)
 
25929
  {
 
25930
    gsp->sample_text = StringSave (str);
 
25931
  }
 
25932
  else
 
25933
  {
 
25934
    if (StringCmp (str, gsp->sample_text) != 0)
 
25935
    {
 
25936
      gsp->all_same = FALSE;
 
25937
    }
 
25938
  }
21734
25939
}
21735
25940
 
21736
25941
static GetSamplePtr 
21737
25942
GetCDSGeneProtAECRSample 
21738
25943
(ValNodePtr cdset_list,
21739
25944
 ValNodePtr field_list, 
21740
 
 ValNodePtr field_list_to)
 
25945
 ValNodePtr field_list_to,
 
25946
 FilterSetPtr fsp)
21741
25947
{
21742
25948
  GetSamplePtr gsp;
21743
 
  ValNodePtr   cdset_vnp;
 
25949
  ValNodePtr   cdset_vnp, sfp_vnp;
21744
25950
  CharPtr      str;
21745
 
  
 
25951
  CDSetPtr       cdsp;
 
25952
 
21746
25953
  gsp = (GetSamplePtr) MemNew (sizeof (GetSampleData));
21747
25954
  if (gsp == NULL)
21748
25955
  {
21752
25959
  gsp->copy_vn_proc = IntValNodeCopy;
21753
25960
  for (cdset_vnp = cdset_list; cdset_vnp != NULL; cdset_vnp = cdset_vnp->next)
21754
25961
  {
21755
 
    str = GetCDSetField (cdset_vnp->data.ptrvalue, field_list);
21756
 
    if (str != NULL && field_list_to != NULL)
21757
 
    {
21758
 
      str = MemFree (str);
21759
 
      str = GetCDSetField (cdset_vnp->data.ptrvalue, field_list_to);
21760
 
    }
21761
 
    if (str != NULL)
21762
 
    {
21763
 
      gsp->num_found ++;
21764
 
    }
21765
 
    if (gsp->sample_text == NULL)
21766
 
    {
21767
 
      gsp->sample_text = str;
21768
 
    }
21769
 
    else
21770
 
    {
21771
 
      if (StringCmp (str, gsp->sample_text) != 0)
21772
 
      {
21773
 
        gsp->all_same = FALSE;
21774
 
      }
 
25962
    cdsp = (CDSetPtr) cdset_vnp->data.ptrvalue;
 
25963
    if (IsCDSetMatPeptideQualChoice(field_list) || IsCDSetMatPeptideQualChoice(field_list_to))
 
25964
    {
 
25965
      /* need to look at all mat_peptide features */
 
25966
      for (sfp_vnp = cdsp->prot_list; sfp_vnp != NULL; sfp_vnp = sfp_vnp->next)
 
25967
      {
 
25968
        if (fsp != NULL && fsp->cgp != NULL && DoesConstraintDisqualifyFeature (sfp_vnp->data.ptrvalue, fsp->cgp))
 
25969
        {
 
25970
          /* this feature will be skipped in the action, so it should not be included in the sample */
 
25971
        }
 
25972
        else
 
25973
        {
 
25974
          str = GetCDSGeneProtField (sfp_vnp->data.ptrvalue, field_list, fsp);
 
25975
          if (str != NULL && field_list_to != NULL)
 
25976
          {
 
25977
            str = GetCDSGeneProtField (sfp_vnp->data.ptrvalue, field_list_to, fsp);
 
25978
          }
 
25979
          AddStringToSample (str, gsp);     
 
25980
          str = MemFree (str);
 
25981
        }
 
25982
      }
 
25983
    } else {
 
25984
      str = GetCDSetField (cdsp, field_list);
 
25985
      if (str != NULL && field_list_to != NULL)
 
25986
      {
 
25987
        str = MemFree (str);
 
25988
        str = GetCDSetField (cdset_vnp->data.ptrvalue, field_list_to);
 
25989
      }
 
25990
      AddStringToSample (str, gsp);     
21775
25991
      str = MemFree (str);
21776
25992
    }
21777
25993
  }
21778
25994
  return gsp;
21779
25995
}
21780
25996
 
 
25997
static Boolean FeatureTypeMissingFromCDSet (CDSetPtr cdsp, Uint2 choice)
 
25998
{
 
25999
  ValNodePtr vnp;
 
26000
  SeqFeatPtr sfp;
 
26001
  Boolean    is_missing = TRUE;
 
26002
 
 
26003
  if (cdsp == NULL) return TRUE;
 
26004
  switch (choice)
 
26005
  {
 
26006
    case FEATDEF_CDS:
 
26007
      if (cdsp->cds_list != NULL)
 
26008
      {
 
26009
        is_missing = FALSE;
 
26010
      }
 
26011
      break;
 
26012
    case FEATDEF_GENE:
 
26013
      if (cdsp->gene_list != NULL)
 
26014
      {
 
26015
        is_missing = FALSE;
 
26016
      }
 
26017
      break;
 
26018
    case FEATDEF_mRNA:
 
26019
      if (cdsp->mrna_list != NULL)
 
26020
      {
 
26021
        is_missing = FALSE;
 
26022
      }
 
26023
      break;
 
26024
    case FEATDEF_PROT:
 
26025
    case FEATDEF_mat_peptide_aa:
 
26026
      for (vnp = cdsp->prot_list; vnp != NULL; vnp = vnp->next)
 
26027
      {
 
26028
        sfp = (SeqFeatPtr) vnp->data.ptrvalue;
 
26029
        if (sfp != NULL && sfp->idx.subtype == choice)
 
26030
        {
 
26031
          is_missing = FALSE;
 
26032
        }
 
26033
      }
 
26034
      break;
 
26035
  }
 
26036
  return is_missing;
 
26037
}
 
26038
 
 
26039
static Int4 
 
26040
CountMissingFeatures 
 
26041
(ValNodePtr cdset_list,
 
26042
 ValNodePtr field_list, 
 
26043
 ValNodePtr field_list_to,
 
26044
 FilterSetPtr fsp)
 
26045
{
 
26046
  ValNodePtr   cdset_vnp, sfp_vnp;
 
26047
  CharPtr      str;
 
26048
  CDSetPtr     cdsp;
 
26049
  Uint2        choice_from, choice_to;
 
26050
  Int4         num_missing = 0;
 
26051
 
 
26052
  choice_from = FeatDefTypeFromFieldList (field_list);
 
26053
  choice_to = FeatDefTypeFromFieldList (field_list_to);
 
26054
 
 
26055
  if (choice_from == 0 || choice_to == 0 || choice_from == choice_to)
 
26056
  {
 
26057
    return 0;
 
26058
  }
 
26059
 
 
26060
  for (cdset_vnp = cdset_list; cdset_vnp != NULL; cdset_vnp = cdset_vnp->next)
 
26061
  {
 
26062
    cdsp = (CDSetPtr) cdset_vnp->data.ptrvalue;
 
26063
 
 
26064
    if (choice_from == FEATDEF_mat_peptide_aa)
 
26065
    {
 
26066
      /* need to look at all mat_peptide features */
 
26067
      for (sfp_vnp = cdsp->prot_list; sfp_vnp != NULL; sfp_vnp = sfp_vnp->next)
 
26068
      {
 
26069
        if (fsp != NULL && fsp->cgp != NULL && DoesConstraintDisqualifyFeature (sfp_vnp->data.ptrvalue, fsp->cgp))
 
26070
        {
 
26071
          /* this feature will be skipped in the action, so it doesn't count towards missing sets */
 
26072
        }
 
26073
        else
 
26074
        {
 
26075
          str = GetCDSGeneProtField (sfp_vnp->data.ptrvalue, field_list, fsp);
 
26076
          if (str != NULL)
 
26077
          {
 
26078
            if (FeatureTypeMissingFromCDSet (cdsp, choice_to)) 
 
26079
            {
 
26080
              num_missing++;
 
26081
            }
 
26082
          }
 
26083
          str = MemFree (str);
 
26084
        }
 
26085
      }
 
26086
    } else {
 
26087
      str = GetCDSetField (cdsp, field_list);
 
26088
      if (str != NULL)
 
26089
      {
 
26090
        if (FeatureTypeMissingFromCDSet (cdsp, choice_to)) 
 
26091
        {
 
26092
          num_missing++;
 
26093
        }
 
26094
      }
 
26095
      str = MemFree (str);
 
26096
    }
 
26097
  }
 
26098
  return num_missing;
 
26099
}
 
26100
 
 
26101
 
 
26102
/* things get tricksy when we're dealing with mat_peptides, because there
 
26103
 * can be more than one of them in the CDS-mRNA-Gene-Prot group.
 
26104
 */
 
26105
 
 
26106
static Boolean CDSGeneProtApplyToAllThatMatchFilter 
 
26107
(CharPtr         str_src,
 
26108
 CDSetPtr        cdsp,
 
26109
 ValNodePtr      field_list_to,
 
26110
 FilterSetPtr    fsp,
 
26111
 ExistingTextPtr etp)
 
26112
{
 
26113
  ApplyValueData avd;
 
26114
 
 
26115
  avd.where_to_replace = EditApplyFindLocation_anywhere;
 
26116
 
 
26117
  /* build gene if we're applying to gene but gene doesn't already exist */
 
26118
  BuildNewCDSGeneProtFeature (cdsp, field_list_to, NULL);
 
26119
  avd.field_list = NULL;
 
26120
  avd.new_text = str_src;
 
26121
  avd.text_to_replace = NULL;
 
26122
  avd.etp = etp;
 
26123
          
 
26124
  return SetCDSetField (cdsp, field_list_to, &avd, fsp);
 
26125
}
 
26126
 
 
26127
static Boolean CDSGeneProtApplyToOneFeature
 
26128
(CharPtr         str_src,
 
26129
 SeqFeatPtr      sfp,
 
26130
 ValNodePtr      field_list_to,
 
26131
 FilterSetPtr    fsp,
 
26132
 ExistingTextPtr etp)
 
26133
{
 
26134
  ApplyValueData avd;
 
26135
 
 
26136
  avd.where_to_replace = EditApplyFindLocation_anywhere;
 
26137
 
 
26138
  avd.field_list = NULL;
 
26139
  avd.new_text = str_src;
 
26140
  avd.text_to_replace = NULL;
 
26141
  avd.etp = etp;
 
26142
          
 
26143
  return SetCDSGeneProtField (sfp, field_list_to, &avd, fsp);
 
26144
}
 
26145
 
 
26146
 
 
26147
static void CopyProteinNameTomRNAName (CDSetPtr cdsp)
 
26148
{
 
26149
  Int4    protein_name_field_num = 2 + num_gene_fields + num_mrna_fields;
 
26150
  Int4    mrna_product_field_num = 2 + num_gene_fields;
 
26151
  ValNode vn_src, vn_dst;
 
26152
  ApplyValueData avd;
 
26153
 
 
26154
  vn_src.data.intvalue = protein_name_field_num;
 
26155
  vn_src.next = NULL;
 
26156
  vn_src.choice = 0;
 
26157
 
 
26158
  vn_dst.data.intvalue = mrna_product_field_num;
 
26159
  vn_dst.next = NULL;
 
26160
  vn_dst.choice = 0;
 
26161
 
 
26162
  avd.new_text = GetCDSetField (cdsp, &vn_src);
 
26163
  avd.etp = NULL;
 
26164
  avd.field_list = NULL;
 
26165
  avd.text_to_replace = NULL;
 
26166
  avd.where_to_replace = EditApplyFindLocation_anywhere;
 
26167
  SetCDSetField (cdsp, &vn_dst, &avd, NULL);
 
26168
}
 
26169
 
 
26170
static void CDSGeneProtConvert 
 
26171
(CDSetPtr        cdsp,
 
26172
 CDSGeneProtAECRPtr   sp,
 
26173
 FilterSetPtr    fsp,
 
26174
 ExistingTextPtr etp,
 
26175
 Boolean         build_missing)
 
26176
{
 
26177
  CharPtr        str_src = NULL;
 
26178
  CharPtr        str_dst = NULL;
 
26179
  ValNodePtr     sfp_vnp;
 
26180
  SeqFeatPtr     sfp;
 
26181
  Boolean        able_to_apply = FALSE;
 
26182
  Boolean        change_made = FALSE;
 
26183
 
 
26184
  if (IsCDSetMatPeptideQualChoice(sp->field_list)) 
 
26185
  {
 
26186
    for (sfp_vnp = cdsp->prot_list; sfp_vnp != NULL; sfp_vnp = sfp_vnp->next)
 
26187
    {
 
26188
      sfp = sfp_vnp->data.ptrvalue;
 
26189
      able_to_apply = FALSE;
 
26190
      if (fsp == NULL || !DoesConstraintDisqualifyFeature(sfp, fsp->cgp)) {
 
26191
        str_src = GetCDSGeneProtField (sfp_vnp->data.ptrvalue, sp->field_list, NULL);
 
26192
        if (str_src != NULL)
 
26193
        {
 
26194
          if (IsCDSetMatPeptideQualChoice (sp->field_list_to)) 
 
26195
          {
 
26196
            CDSGeneProtApplyToOneFeature (str_src, sfp, sp->field_list_to, fsp, etp);
 
26197
            change_made = TRUE;
 
26198
          } 
 
26199
          else 
 
26200
          {
 
26201
            if (build_missing)
 
26202
            {
 
26203
              BuildNewCDSGeneProtFeature (cdsp, sp->field_list_to, sp->field_list);
 
26204
            }
 
26205
            able_to_apply = CDSGeneProtApplyToAllThatMatchFilter (str_src, cdsp, sp->field_list_to, fsp, etp);
 
26206
            if (able_to_apply)
 
26207
            {
 
26208
              change_made = TRUE;
 
26209
            }
 
26210
          }
 
26211
          if (!sp->leave_on_original && able_to_apply)
 
26212
          {
 
26213
            sp->field_list->choice = 1;
 
26214
            RemoveCDSGeneProtField (sfp, sp->field_list, fsp);
 
26215
            change_made = TRUE;
 
26216
          }
 
26217
        }
 
26218
      }
 
26219
    }    
 
26220
  }
 
26221
  else 
 
26222
  {
 
26223
    str_src = GetCDSetField (cdsp, sp->field_list);
 
26224
    if (str_src != NULL)
 
26225
    {
 
26226
      if (build_missing)
 
26227
      {
 
26228
        BuildNewCDSGeneProtFeature (cdsp, sp->field_list_to, sp->field_list);
 
26229
      }
 
26230
      able_to_apply = CDSGeneProtApplyToAllThatMatchFilter (str_src, cdsp, sp->field_list_to, fsp, etp);
 
26231
      if (!sp->leave_on_original && able_to_apply)
 
26232
      {
 
26233
        sp->field_list->choice = 1;
 
26234
        RemoveCDSetField (cdsp, sp->field_list, fsp);
 
26235
      }
 
26236
      if (able_to_apply)
 
26237
      {
 
26238
        change_made = TRUE;
 
26239
      }
 
26240
    }   
 
26241
  }
 
26242
  if (sp->also_mrna && change_made)
 
26243
  {
 
26244
    CopyProteinNameTomRNAName (cdsp);
 
26245
  }
 
26246
 
 
26247
}
 
26248
 
 
26249
static void CDSGeneProtSwap
 
26250
(CDSetPtr        cdsp,
 
26251
 CDSGeneProtAECRPtr   sp,
 
26252
 FilterSetPtr    fsp,
 
26253
 ExistingTextPtr etp,
 
26254
 Boolean         build_missing)
 
26255
{
 
26256
  CharPtr        str_src = NULL;
 
26257
  CharPtr        str_dst = NULL;
 
26258
  ValNodePtr     sfp_vnp_src, sfp_vnp_dst, vnp_swap;
 
26259
  SeqFeatPtr     sfp_src, sfp_dst;
 
26260
  ApplyValueData avd;
 
26261
  Uint2          choice_to, choice_from;
 
26262
  Boolean        change_made = FALSE;
 
26263
 
 
26264
  avd.where_to_replace = EditApplyFindLocation_anywhere;
 
26265
 
 
26266
  choice_from = FeatDefTypeFromFieldList (sp->field_list);
 
26267
  choice_to = FeatDefTypeFromFieldList (sp->field_list_to);
 
26268
 
 
26269
  if (choice_from == FEATDEF_mat_peptide_aa || choice_to == FEATDEF_mat_peptide_aa)
 
26270
  {
 
26271
    /* make sure mat_peptide qual if in field_list */
 
26272
    if (!IsCDSetMatPeptideQualChoice(sp->field_list)) 
 
26273
    {
 
26274
      vnp_swap = sp->field_list;
 
26275
      sp->field_list = sp->field_list_to;
 
26276
      sp->field_list_to = vnp_swap;
 
26277
    }
 
26278
    for (sfp_vnp_src = cdsp->prot_list; sfp_vnp_src != NULL; sfp_vnp_src = sfp_vnp_src->next)
 
26279
    {
 
26280
      sfp_src = sfp_vnp_src->data.ptrvalue;
 
26281
      if (fsp == NULL || !DoesConstraintDisqualifyFeature(sfp_src, fsp->cgp)) 
 
26282
      {
 
26283
        str_src = GetCDSGeneProtField (sfp_src, sp->field_list, NULL);
 
26284
        if (IsCDSetMatPeptideQualChoice(sp->field_list_to)) 
 
26285
        {
 
26286
          for (sfp_vnp_dst = cdsp->prot_list; sfp_vnp_dst != NULL; sfp_vnp_dst = sfp_vnp_dst->next)
 
26287
          {
 
26288
            sfp_dst = sfp_vnp_dst->data.ptrvalue;
 
26289
            if (fsp == NULL || !DoesConstraintDisqualifyFeature(sfp_dst, fsp->cgp))
 
26290
            {
 
26291
              str_dst = GetCDSGeneProtField (sfp_dst, sp->field_list_to, NULL);
 
26292
              if (!StringHasNoText (str_src) || !StringHasNoText (str_dst))
 
26293
              {
 
26294
                if (build_missing)
 
26295
                {
 
26296
                  BuildNewCDSGeneProtFeature (cdsp, sp->field_list, sp->field_list_to);
 
26297
                  BuildNewCDSGeneProtFeature (cdsp, sp->field_list_to, sp->field_list);
 
26298
                }
 
26299
                if (!FeatureTypeMissingFromCDSet(cdsp, choice_from) 
 
26300
                    && !FeatureTypeMissingFromCDSet(cdsp, choice_to))
 
26301
                {
 
26302
                  avd.etp = NULL;
 
26303
                  avd.text_to_replace = NULL;
 
26304
                  avd.new_text = StringSave (str_src);
 
26305
                  avd.field_list = NULL;
 
26306
                  SetCDSGeneProtField (sfp_dst, sp->field_list_to, &avd, fsp);
 
26307
                  avd.new_text = StringSave (str_dst);
 
26308
                  SetCDSGeneProtField (sfp_src, sp->field_list, &avd, fsp);
 
26309
                  change_made = TRUE;
 
26310
                }
 
26311
              }
 
26312
              str_dst = MemFree (str_dst);
 
26313
            }
 
26314
          }
 
26315
        } 
 
26316
        else
 
26317
        {
 
26318
          str_dst = GetCDSetField (cdsp, sp->field_list_to);
 
26319
          if (!StringHasNoText (str_src) || !StringHasNoText (str_dst))
 
26320
          {
 
26321
            if (build_missing) 
 
26322
            {
 
26323
              BuildNewCDSGeneProtFeature (cdsp, sp->field_list, sp->field_list_to);
 
26324
              BuildNewCDSGeneProtFeature (cdsp, sp->field_list_to, sp->field_list);
 
26325
            }
 
26326
            if (!FeatureTypeMissingFromCDSet(cdsp, choice_from)
 
26327
                && !FeatureTypeMissingFromCDSet(cdsp, choice_to))
 
26328
            {
 
26329
              avd.etp = NULL;
 
26330
              avd.text_to_replace = NULL;
 
26331
              avd.new_text = StringSave (str_src);
 
26332
              avd.field_list = NULL;
 
26333
              SetCDSetField (cdsp, sp->field_list_to, &avd, fsp);
 
26334
              avd.new_text = StringSave (str_dst);
 
26335
              SetCDSGeneProtField (sfp_src, sp->field_list, &avd, fsp);
 
26336
              change_made = TRUE;
 
26337
            }
 
26338
          }
 
26339
          str_dst = MemFree (str_dst);
 
26340
        }
 
26341
        str_src = MemFree (str_src);
 
26342
      }
 
26343
    } 
 
26344
  }
 
26345
  else
 
26346
  {
 
26347
    str_src = GetCDSetField (cdsp, sp->field_list);
 
26348
    str_dst = GetCDSetField (cdsp, sp->field_list_to);
 
26349
    if (!StringHasNoText (str_src) || !StringHasNoText (str_dst))
 
26350
    {
 
26351
      if (build_missing)
 
26352
      {
 
26353
        BuildNewCDSGeneProtFeature (cdsp, sp->field_list, sp->field_list_to);
 
26354
        BuildNewCDSGeneProtFeature (cdsp, sp->field_list_to, sp->field_list);
 
26355
      }
 
26356
      if (!FeatureTypeMissingFromCDSet(cdsp, choice_from)
 
26357
          && !FeatureTypeMissingFromCDSet(cdsp, choice_to))
 
26358
      {
 
26359
        avd.etp = NULL;
 
26360
        avd.text_to_replace = NULL;
 
26361
        avd.new_text = str_src;
 
26362
        avd.field_list = NULL;
 
26363
        SetCDSetField (cdsp, sp->field_list_to, &avd, fsp);
 
26364
        avd.new_text = str_dst;
 
26365
        SetCDSetField (cdsp, sp->field_list, &avd, fsp);
 
26366
        change_made = TRUE;
 
26367
      }
 
26368
    }
 
26369
  }
 
26370
  if (change_made && sp->also_mrna)
 
26371
  {
 
26372
    CopyProteinNameTomRNAName (cdsp);
 
26373
  }
 
26374
}
 
26375
 
 
26376
 
 
26377
static void CDSGeneProtParse
 
26378
(CDSetPtr        cdsp,
 
26379
 CDSGeneProtAECRPtr   sp,
 
26380
 FilterSetPtr    fsp,
 
26381
 ExistingTextPtr etp,
 
26382
 Boolean         build_missing)
 
26383
{
 
26384
  CharPtr        str_src = NULL;
 
26385
  CharPtr        str_dst = NULL;
 
26386
  ValNodePtr     sfp_vnp;
 
26387
  SeqFeatPtr     sfp;
 
26388
  ApplyValueData avd;
 
26389
  Boolean        able_to_apply;
 
26390
  Boolean        change_made = FALSE;
 
26391
 
 
26392
  avd.where_to_replace = EditApplyFindLocation_anywhere;
 
26393
 
 
26394
  if (IsCDSetMatPeptideQualChoice(sp->field_list)) 
 
26395
  {
 
26396
    for (sfp_vnp = cdsp->prot_list; sfp_vnp != NULL; sfp_vnp = sfp_vnp->next)
 
26397
    {
 
26398
      sfp = sfp_vnp->data.ptrvalue;
 
26399
      if (fsp == NULL || !DoesConstraintDisqualifyFeature(sfp, fsp->cgp)) 
 
26400
      {
 
26401
        str_src = GetCDSGeneProtField (sfp, sp->field_list, NULL);
 
26402
        str_dst = str_src;
 
26403
        str_src = ReplaceStringForParse(str_src, sp->text_portion);
 
26404
        if (!sp->remove_parsed) {
 
26405
          str_dst = MemFree (str_dst);
 
26406
        }
 
26407
 
 
26408
        if (str_src != NULL) {
 
26409
          if (build_missing) 
 
26410
          {
 
26411
            BuildNewCDSGeneProtFeature (cdsp, sp->field_list_to, sp->field_list);
 
26412
          }
 
26413
          able_to_apply = FALSE;
 
26414
          if (IsCDSetMatPeptideQualChoice (sp->field_list_to)) 
 
26415
          {
 
26416
            able_to_apply = CDSGeneProtApplyToOneFeature (str_src, sfp, sp->field_list_to, fsp, etp);
 
26417
          } 
 
26418
          else 
 
26419
          {
 
26420
            able_to_apply = CDSGeneProtApplyToAllThatMatchFilter (str_src, cdsp, sp->field_list_to, fsp, etp);
 
26421
          }
 
26422
          if (sp->remove_parsed && able_to_apply) {
 
26423
            CDSGeneProtApplyToOneFeature (str_dst, sfp, sp->field_list, fsp, NULL);
 
26424
          }
 
26425
          if (able_to_apply)
 
26426
          {
 
26427
            change_made = TRUE;
 
26428
          }
 
26429
          str_src = MemFree (str_src);
 
26430
        }
 
26431
        str_dst = MemFree (str_dst);
 
26432
      }
 
26433
    }
 
26434
  }
 
26435
  else
 
26436
  {
 
26437
    str_src = GetCDSetField (cdsp, sp->field_list);
 
26438
    str_dst = str_src;
 
26439
    str_src = ReplaceStringForParse(str_src, sp->text_portion);
 
26440
    if (!sp->remove_parsed) {
 
26441
      str_dst = MemFree (str_dst);
 
26442
    }
 
26443
    if (str_src != NULL) {
 
26444
      if (build_missing) 
 
26445
      {
 
26446
        BuildNewCDSGeneProtFeature (cdsp, sp->field_list_to, sp->field_list);
 
26447
      }
 
26448
      able_to_apply = CDSGeneProtApplyToAllThatMatchFilter (str_src, cdsp, sp->field_list_to, fsp, etp);
 
26449
      if (sp->remove_parsed && able_to_apply) {
 
26450
        CDSGeneProtApplyToAllThatMatchFilter (str_dst, cdsp, sp->field_list, fsp, NULL);
 
26451
      }
 
26452
      if (able_to_apply)
 
26453
      {
 
26454
        change_made = TRUE;
 
26455
      }
 
26456
      str_src = MemFree (str_src);
 
26457
    }   
 
26458
    str_dst = MemFree (str_dst);
 
26459
  }
 
26460
 
 
26461
  if (sp->also_mrna && change_made)
 
26462
  {
 
26463
    CopyProteinNameTomRNAName (cdsp);
 
26464
  }
 
26465
}     
 
26466
 
 
26467
static void CDSGeneProtEdit
 
26468
(CDSetPtr        cdsp,
 
26469
 CDSGeneProtAECRPtr   sp,
 
26470
 FilterSetPtr    fsp,
 
26471
 ExistingTextPtr etp)
 
26472
{
 
26473
  ApplyValueData avd;
 
26474
 
 
26475
  avd.where_to_replace = EditApplyFindLocation_anywhere;
 
26476
 
 
26477
  avd.field_list = sp->field_list;
 
26478
  avd.etp = NULL;
 
26479
  AddEditApplyDataToApplyValue (AECR_EDIT, sp->edit_apply, &avd);
 
26480
  SetCDSetField (cdsp, sp->field_list, &avd, fsp);
 
26481
  avd.text_to_replace = MemFree (avd.text_to_replace);
 
26482
  avd.new_text = MemFree (avd.new_text);
 
26483
  if (sp->also_mrna)
 
26484
  {
 
26485
    CopyProteinNameTomRNAName (cdsp);
 
26486
  }
 
26487
}
 
26488
 
 
26489
static ValNodePtr CollectCDSetList (Uint2 entityID, FilterSetPtr fsp)
 
26490
{
 
26491
  ValNodePtr cdset_list;
 
26492
 
 
26493
  /* need to create a list of sets */
 
26494
#if 1
 
26495
  cdset_list = BuildCDSet2List (entityID, fsp == NULL || fsp->cgp == NULL ? NULL : fsp->cgp);
 
26496
 
 
26497
#else
 
26498
  if (fsp == NULL || fsp->cgp == NULL)
 
26499
  {
 
26500
    /* if we are applying to mat_peptides AND the constraint involved mat_peptides,
 
26501
     * create all sets and we'll filter out later.
 
26502
     */
 
26503
    cdset_list = BuildCDSetList (entityID, NULL);
 
26504
  }
 
26505
  else
 
26506
  {
 
26507
    cdset_list = BuildCDSetList (entityID, fsp->cgp);
 
26508
  }
 
26509
#endif
 
26510
  return cdset_list;
 
26511
}
 
26512
 
 
26513
 
 
26514
static void MarkAlreadyEditedGenes (CDSetPtr cdsp, ValNodePtr cdset_list)
 
26515
{
 
26516
  ValNodePtr gene_vnp, list_vnp, genecheck_vnp;
 
26517
  CDSetPtr   check_cdsp;
 
26518
 
 
26519
  if (cdsp == NULL || cdset_list == NULL || cdsp->gene_list == NULL) return;
 
26520
 
 
26521
  for (gene_vnp = cdsp->gene_list; gene_vnp != NULL; gene_vnp = gene_vnp->next)
 
26522
  {
 
26523
    if (gene_vnp->choice > 0) continue;
 
26524
    for (list_vnp = cdset_list; list_vnp != NULL; list_vnp = list_vnp->next)
 
26525
    {
 
26526
      check_cdsp = (CDSetPtr) list_vnp->data.ptrvalue;
 
26527
      if (check_cdsp != NULL) 
 
26528
      {
 
26529
        for (genecheck_vnp = check_cdsp->gene_list; genecheck_vnp != NULL; genecheck_vnp = genecheck_vnp->next)
 
26530
        {
 
26531
          if (genecheck_vnp->data.ptrvalue == gene_vnp->data.ptrvalue)
 
26532
          {
 
26533
            genecheck_vnp->choice = 1;
 
26534
          }
 
26535
        }
 
26536
      }
 
26537
    }
 
26538
  }  
 
26539
}
 
26540
 
 
26541
 
21781
26542
static Boolean CDSGeneProtAECRAction (Pointer userdata)
21782
26543
{
21783
26544
  ApplyEditConvertRemovePtr ap;
21784
 
  SimpleAECRPtr             sp;
 
26545
  CDSGeneProtAECRPtr        sp;
21785
26546
  Int4                      action_choice;
21786
26547
  SeqEntryPtr               sep;
21787
 
  ApplyValueData            avd;
21788
26548
  FilterSetPtr              fsp;
21789
26549
  GetSamplePtr              gsp = NULL;
21790
26550
  Boolean                   rval = TRUE;
21791
26551
  ValNodePtr                cdset_list, cdset_vnp;
21792
26552
  ExistingTextPtr           etp = NULL;
21793
 
  CharPtr                   str_src, str_dst;
 
26553
  Int4                      num_missing;
 
26554
  Boolean                   build_missing = FALSE;
 
26555
  MsgAnswer                 ans;
21794
26556
 
21795
26557
  ap = (ApplyEditConvertRemovePtr) userdata;
21796
26558
  if (ap == NULL)
21813
26575
  {
21814
26576
    return FALSE;
21815
26577
  }
21816
 
  sp = (SimpleAECRPtr) DialogToPointer (ap->aecr_pages[action_choice - 1]);
 
26578
  sp = (CDSGeneProtAECRPtr) DialogToPointer (ap->aecr_pages[action_choice - 1]);
21817
26579
 
21818
26580
  sep = GetTopSeqEntryForEntityID (ap->input_entityID);
21819
26581
  if (sp->field_list == NULL
21820
26582
      || ((action_choice == AECR_CONVERT || action_choice == AECR_SWAP) 
21821
26583
           && sp->field_list == NULL))
21822
26584
  {
21823
 
    sp = SimpleAECRFree (sp);
 
26585
    sp = CDSGeneProtAECRFree (sp);
21824
26586
    ArrowCursor ();
21825
26587
    Update ();
21826
26588
    return FALSE;
21829
26591
  fsp = (FilterSetPtr) DialogToPointer (ap->constraints);
21830
26592
  
21831
26593
  /* need to create a list of sets */
21832
 
  if (fsp == NULL)
21833
 
  {
21834
 
    cdset_list = BuildCDSetList (ap->input_entityID, NULL);
21835
 
  }
21836
 
  else
21837
 
  {
21838
 
    cdset_list = BuildCDSetList (ap->input_entityID, fsp->cgp);
21839
 
  }
 
26594
  cdset_list = CollectCDSetList (ap->input_entityID, fsp);
21840
26595
  
21841
26596
  /* find existing text and how to handle it */
21842
26597
  if (action_choice == AECR_CONVERT || action_choice == AECR_APPLY || action_choice == AECR_PARSE)
21843
26598
  {
21844
 
    gsp = GetCDSGeneProtAECRSample (cdset_list, sp->field_list, sp->field_list_to);
21845
 
    etp = GetExistingTextHandlerInfo (gsp, FALSE);
 
26599
    gsp = GetCDSGeneProtAECRSample (cdset_list, sp->field_list, sp->field_list_to, fsp);
 
26600
    etp = GetExistingTextHandlerInfo (gsp == NULL ? 0 : gsp->num_found, FALSE);
21846
26601
    gsp = GetSampleFree (gsp);
21847
 
    if (etp != NULL && etp->existing_text_choice == EXISTING_TEXT_CHOICE_CANCEL)
 
26602
    if (etp != NULL && etp->existing_text_choice == eExistingTextChoiceCancel)
21848
26603
    {
21849
26604
      rval = FALSE;
21850
26605
    }
21851
26606
  }
21852
26607
  
 
26608
  num_missing = CountMissingFeatures (cdset_list, sp->field_list, sp->field_list_to, fsp);
 
26609
  if (action_choice == AECR_SWAP) 
 
26610
  {
 
26611
    num_missing += CountMissingFeatures (cdset_list, sp->field_list_to, sp->field_list, fsp);
 
26612
  }
 
26613
  if (num_missing > 0) 
 
26614
  {
 
26615
    ans = Message (MSG_YNC, "There are %d fields where the feature to which the field should be applied does not exist.  Do you want to create these features?", num_missing);
 
26616
    if (ans == ANS_CANCEL)
 
26617
    {
 
26618
      rval = FALSE;
 
26619
    } else if (ans == ANS_YES) {
 
26620
      build_missing = TRUE;
 
26621
    }
 
26622
  }
21853
26623
  
21854
26624
  if (rval)
21855
26625
  {
21856
 
    /* if we are applying gene fields, we need to make sure every sequence has a gene
 
26626
    /* if we are applying gene locus, we need to make sure every sequence has a gene
21857
26627
     * and we need to recollect the cdset_list
21858
26628
     */
21859
26629
    if ((action_choice == AECR_APPLY || action_choice == AECR_PARSE)
21860
26630
        && sp->field_list != NULL
21861
 
        && sp->field_list->data.intvalue > 1 
21862
 
        && sp->field_list->data.intvalue <= 1 + num_gene_fields)
 
26631
        && sp->field_list->data.intvalue == 1 + GENEFIELD_LOCUS)
21863
26632
    {
21864
 
      BuildNewGenes (sep);
21865
 
      FreeCDSetList (cdset_list);
21866
 
      if (fsp == NULL)
21867
 
      {
21868
 
        cdset_list = BuildCDSetList (ap->input_entityID, NULL); 
21869
 
      }
21870
 
      else
21871
 
      {
21872
 
        cdset_list = BuildCDSetList (ap->input_entityID, fsp->cgp); 
21873
 
      }
 
26633
      BuildNewGenes (sep, &cdset_list, LoneGeneOkWithFilter(fsp));
21874
26634
    }
21875
26635
    
21876
26636
    for (cdset_vnp = cdset_list; cdset_vnp != NULL; cdset_vnp = cdset_vnp->next)
21877
26637
    {
21878
26638
      if (action_choice == AECR_CONVERT)
21879
26639
      {
21880
 
        str_src = GetCDSetField (cdset_vnp->data.ptrvalue, sp->field_list);
21881
 
        if (str_src != NULL)
21882
 
        {
21883
 
          BuildNewCDSGeneProtFeature (cdset_vnp->data.ptrvalue, sp->field_list_to);
21884
 
          SetCDSetField (cdset_vnp->data.ptrvalue, sp->field_list_to, str_src, etp);
21885
 
          if (!sp->leave_on_original)
21886
 
          {
21887
 
            sp->field_list->choice = 1;
21888
 
            RemoveCDSetField (cdset_vnp->data.ptrvalue, sp->field_list);
21889
 
          }
21890
 
        }   
 
26640
        CDSGeneProtConvert (cdset_vnp->data.ptrvalue, sp, fsp, etp, build_missing);
21891
26641
      }
21892
26642
      else if (action_choice == AECR_SWAP)
21893
26643
      {
21894
 
        str_src = GetCDSetField (cdset_vnp->data.ptrvalue, sp->field_list);
21895
 
        str_dst = GetCDSetField (cdset_vnp->data.ptrvalue, sp->field_list_to);
21896
 
        if (!StringHasNoText (str_src) || !StringHasNoText (str_dst))
21897
 
        {
21898
 
          BuildNewCDSGeneProtFeature (cdset_vnp->data.ptrvalue, sp->field_list);
21899
 
          BuildNewCDSGeneProtFeature (cdset_vnp->data.ptrvalue, sp->field_list_to);
21900
 
          SetCDSetField (cdset_vnp->data.ptrvalue, sp->field_list_to, str_src, NULL);
21901
 
          SetCDSetField (cdset_vnp->data.ptrvalue, sp->field_list, str_dst, NULL);
21902
 
        }
 
26644
        CDSGeneProtSwap (cdset_vnp->data.ptrvalue, sp, fsp, etp, build_missing);
21903
26645
      }
21904
26646
      else if (action_choice == AECR_PARSE)
21905
26647
      {
21906
 
        str_src = GetCDSetField (cdset_vnp->data.ptrvalue, sp->field_list);
21907
 
        str_dst = str_src;
21908
 
        str_src = ReplaceStringForParse(str_src, sp->text_portion);
21909
 
        if (!sp->remove_parsed) {
21910
 
          str_dst = MemFree (str_dst);
21911
 
        }
21912
 
        if (str_src != NULL) {
21913
 
          BuildNewCDSGeneProtFeature (cdset_vnp->data.ptrvalue, sp->field_list_to);
21914
 
          if (sp->remove_parsed) {
21915
 
            BuildNewCDSGeneProtFeature (cdset_vnp->data.ptrvalue, sp->field_list);
21916
 
          }
21917
 
          SetCDSetField (cdset_vnp->data.ptrvalue, sp->field_list_to, str_src, etp);
21918
 
          if (sp->remove_parsed) {
21919
 
            SetCDSetField (cdset_vnp->data.ptrvalue, sp->field_list, str_dst, NULL);
21920
 
          }
21921
 
          str_src = MemFree (str_src);
21922
 
        }   
21923
 
        str_dst = MemFree (str_dst);
 
26648
        CDSGeneProtParse (cdset_vnp->data.ptrvalue, sp, fsp, etp, build_missing);
21924
26649
      }      
21925
26650
      else if (action_choice == AECR_APPLY)
21926
26651
      {
21927
 
        /* for now, this is taken care of by BuildNewGenes */
21928
 
        /* BuildNewCDSGeneProtFeature (cdset_vnp->data.ptrvalue, sp->field_list); */
21929
 
        SetCDSetField (cdset_vnp->data.ptrvalue, sp->field_list, sp->edit_apply->apply_txt, etp);
 
26652
        CDSGeneProtApplyToAllThatMatchFilter (sp->edit_apply->apply_txt, cdset_vnp->data.ptrvalue, sp->field_list, fsp, etp);
21930
26653
      }
21931
26654
      else if (action_choice == AECR_REMOVE)
21932
26655
      {
21933
26656
        sp->field_list->choice = 1;
21934
 
        RemoveCDSetField (cdset_vnp->data.ptrvalue, sp->field_list);
 
26657
        RemoveCDSetField (cdset_vnp->data.ptrvalue, sp->field_list, fsp);
 
26658
        if (sp->also_mrna)
 
26659
        {
 
26660
          CopyProteinNameTomRNAName (cdset_vnp->data.ptrvalue);
 
26661
        }
21935
26662
      }
21936
26663
      else if (action_choice == AECR_EDIT)
21937
26664
      {
21938
 
        str_src = GetCDSetField (cdset_vnp->data.ptrvalue, sp->field_list);
21939
 
        avd.field_list = sp->field_list;
21940
 
        avd.etp = NULL;
21941
 
        AddEditApplyDataToApplyValue (AECR_EDIT, sp->edit_apply, &avd);
21942
 
        str_src = HandleApplyValue (str_src, &avd);
21943
 
        SetCDSetField (cdset_vnp->data.ptrvalue, sp->field_list, str_src, NULL);
21944
 
        avd.text_to_replace = MemFree (avd.text_to_replace);
21945
 
        avd.new_text = MemFree (avd.new_text);
 
26665
        CDSGeneProtEdit (cdset_vnp->data.ptrvalue, sp, fsp, etp);
 
26666
      }
 
26667
      if (((action_choice == AECR_APPLY || action_choice == AECR_EDIT) && IsCDSetGeneQualChoice (sp->field_list))
 
26668
          || ((action_choice == AECR_PARSE || action_choice == AECR_CONVERT) && IsCDSetGeneQualChoice (sp->field_list_to))
 
26669
          || (action_choice == AECR_SWAP && (IsCDSetGeneQualChoice (sp->field_list) || IsCDSetGeneQualChoice (sp->field_list_to))))
 
26670
      {
 
26671
        MarkAlreadyEditedGenes (cdset_vnp->data.ptrvalue, cdset_vnp->next);
21946
26672
      }
21947
26673
    }
21948
26674
  }
21949
26675
  FilterSetFree (fsp);
21950
 
  sp = SimpleAECRFree (sp);
 
26676
  sp = CDSGeneProtAECRFree (sp);
21951
26677
  FreeCDSetList (cdset_list);
21952
26678
  
21953
26679
  if (rval)
21972
26698
                               "CDS-Gene-Prot-mRNA",
21973
26699
                               CDSGeneProtAECRDialog, 
21974
26700
                               TRUE, GetCDSGeneProtSample,
21975
 
                               FALSE, FALSE, FALSE, TRUE, NULL,
 
26701
                               FALSE, FALSE, FALSE, TRUE, FALSE, NULL,
21976
26702
                               CDSGeneProtAECRAction, NULL, NULL,
21977
26703
                               CheckFeaturesForPresample);
21978
26704
}
22025
26751
  SimpleAECRPtr origin;
22026
26752
  SimpleAECRPtr strings;
22027
26753
  
 
26754
  TaxnameOptionsPtr taxname_options;
22028
26755
} SourceQualAECRData, PNTR SourceQualAECRPtr;
22029
26756
 
22030
26757
static SourceQualAECRPtr SourceQualAECRFree (SourceQualAECRPtr sp)
22032
26759
  if (sp != NULL)
22033
26760
  {
22034
26761
    sp->source_qual = SimpleAECRFree (sp->source_qual);
 
26762
    sp->taxname_options = MemFree (sp->taxname_options);
22035
26763
    sp = MemFree (sp);
22036
26764
  }
22037
26765
  return sp;
22046
26774
  DialoG location;
22047
26775
  DialoG origin;
22048
26776
  DialoG strings;
 
26777
 
 
26778
  DialoG taxname_options;
22049
26779
  
22050
26780
  Int4   action_choice;
22051
26781
  Nlm_ChangeNotifyProc     change_notify;
22053
26783
  
22054
26784
} SourceQualAECRDlgData, PNTR SourceQualAECRDlgPtr;
22055
26785
 
 
26786
 
 
26787
static Boolean AreTaxNameOptionsRelevant (Int4 action_choice, SimpleAECRPtr sp)
 
26788
{
 
26789
  Boolean relevant = FALSE;
 
26790
  if (sp == NULL) return FALSE;
 
26791
 
 
26792
  switch (action_choice)
 
26793
  {
 
26794
    case AECR_APPLY:
 
26795
    case AECR_EDIT:
 
26796
    case AECR_REMOVE:
 
26797
      if (sp->field_list != NULL && sp->field_list->choice == 1)
 
26798
      {
 
26799
        relevant = TRUE;
 
26800
      }
 
26801
      break;
 
26802
    case AECR_SWAP:
 
26803
      if ((sp->field_list != NULL && sp->field_list->choice == 1) 
 
26804
          || (sp->field_list_to != NULL && sp->field_list_to->choice == 1))
 
26805
      {
 
26806
        relevant = TRUE;
 
26807
      }
 
26808
      break;
 
26809
    case AECR_CONVERT:
 
26810
      if ((sp->field_list != NULL && sp->field_list->choice == 1 && !sp->leave_on_original) 
 
26811
          || (sp->field_list_to != NULL && sp->field_list_to->choice == 1))
 
26812
      {
 
26813
        relevant = TRUE;
 
26814
      }
 
26815
      break;
 
26816
    case AECR_PARSE:
 
26817
      if ((sp->field_list != NULL && sp->field_list->choice == 1 && sp->remove_parsed)
 
26818
          || (sp->field_list_to != NULL && sp->field_list_to->choice == 1))
 
26819
      {
 
26820
        relevant = TRUE;
 
26821
      }
 
26822
      break;
 
26823
    default:
 
26824
      relevant = FALSE;
 
26825
      break;
 
26826
  }
 
26827
  return relevant;
 
26828
}
 
26829
 
22056
26830
static void ChangeQualKind (GrouP g)
22057
26831
{
22058
26832
  SourceQualAECRDlgPtr dlg;
22059
26833
  Int4                 qual_kind;
 
26834
  SimpleAECRPtr        sp;
22060
26835
 
22061
26836
  dlg = (SourceQualAECRDlgPtr) GetObjectExtra (g);
22062
26837
  if (dlg == NULL)
22068
26843
  Hide (dlg->location);
22069
26844
  Hide (dlg->origin);
22070
26845
  Hide (dlg->strings);
 
26846
  Hide (dlg->taxname_options);
22071
26847
  qual_kind = GetValue (dlg->qual_kind);
22072
26848
  switch (qual_kind)
22073
26849
  {
22082
26858
      break;
22083
26859
    case QUALKIND_STRINGS :
22084
26860
      Show (dlg->strings);
 
26861
      Show (dlg->taxname_options);
 
26862
      sp = DialogToPointer (dlg->strings);
 
26863
      if (AreTaxNameOptionsRelevant (dlg->action_choice, sp))
 
26864
      {
 
26865
        Enable (dlg->taxname_options);
 
26866
      }
 
26867
      else
 
26868
      {
 
26869
        Disable (dlg->taxname_options);
 
26870
      }
 
26871
      sp = SimpleAECRFree (sp);
22085
26872
      break;
22086
26873
  }
22087
26874
  if (dlg->change_notify != NULL)
22102
26889
  PointerToDialog (dlg->origin, NULL);
22103
26890
  PointerToDialog (dlg->strings, NULL);
22104
26891
  ChangeQualKind (dlg->qual_kind);
 
26892
  PointerToDialog (dlg->taxname_options, NULL);
22105
26893
}
22106
26894
 
22107
26895
static void ClearTextSourceQualAECRDlg (SourceQualAECRDlgPtr dlg)
22147
26935
           && (dlg->action_choice == AECR_EDIT || dlg->action_choice == AECR_SWAP))
22148
26936
  {
22149
26937
    SetValue (dlg->qual_kind, QUALKIND_STRINGS);
 
26938
    PointerToDialog (dlg->taxname_options, data->taxname_options);
22150
26939
  }
22151
26940
  else if (data->qual_kind > QUALKIND_ORIGIN)
22152
26941
  {
22173
26962
  data = (SourceQualAECRPtr) MemNew (sizeof (SourceQualAECRData));
22174
26963
  if (data != NULL)
22175
26964
  {
 
26965
    data->taxname_options = NULL;
22176
26966
    data->qual_kind = GetValue (dlg->qual_kind);
22177
26967
    switch (data->qual_kind)
22178
26968
    {
22187
26977
        break;
22188
26978
      case QUALKIND_STRINGS :
22189
26979
        data->strings = DialogToPointer (dlg->strings);
 
26980
        if (AreTaxNameOptionsRelevant (dlg->action_choice, data->strings))
 
26981
        {
 
26982
          data->taxname_options = DialogToPointer (dlg->taxname_options);
 
26983
        }
22190
26984
        break;
22191
26985
    }
22192
26986
    
22216
27010
        SendMessageToDialog (dlg->location, AECR_VIB_MSG_SET_DEFAULT);
22217
27011
        SendMessageToDialog (dlg->origin, AECR_VIB_MSG_SET_DEFAULT);
22218
27012
        SendMessageToDialog (dlg->strings, AECR_VIB_MSG_SET_DEFAULT);
 
27013
        PointerToDialog (dlg->taxname_options, NULL);
22219
27014
        ChangeQualKind (dlg->qual_kind);
22220
27015
        break;
22221
27016
      case AECR_VIB_MSG_CLEAR_TEXT :
22230
27025
static ValNodePtr TestSourceQualAECR (DialoG d)
22231
27026
{
22232
27027
  SourceQualAECRDlgPtr dlg;
22233
 
  ValNodePtr           err_list = NULL;
22234
27028
  ValNodePtr           total_err_list = NULL;
22235
27029
  Int4                 qual_kind;
22236
27030
  
22517
27311
                                                dlg);
22518
27312
  
22519
27313
  g2 = HiddenGroup (p, 0, 0, NULL);
22520
 
  dlg->edit_apply = EditApplyDialog (g2, AECR_APPLY, "New Text",
 
27314
  dlg->edit_apply = EditApplyDialog (g2, eEditApplyChoice_Apply, "New Text", NULL,
22521
27315
                                     change_notify, change_userdata);
22522
27316
  
22523
27317
  dlg->true_false = PopupList (g2, TRUE, NULL);
22643
27437
  return (DialoG) p;
22644
27438
}
22645
27439
 
 
27440
 
 
27441
static void ChangeTaxonomyStrings (Pointer data)
 
27442
{
 
27443
  SourceQualAECRDlgPtr dlg;
 
27444
  SimpleAECRPtr        sp;
 
27445
 
 
27446
  dlg = (SourceQualAECRDlgPtr) data;
 
27447
  if (dlg == NULL) return;
 
27448
 
 
27449
  if (GetValue (dlg->qual_kind) == QUALKIND_STRINGS)
 
27450
  {
 
27451
    sp = DialogToPointer (dlg->strings);
 
27452
    if (AreTaxNameOptionsRelevant (dlg->action_choice, sp))
 
27453
    {
 
27454
      Enable (dlg->taxname_options);
 
27455
    }
 
27456
    else
 
27457
    {
 
27458
      Disable (dlg->taxname_options);
 
27459
    }
 
27460
    sp = SimpleAECRFree (sp);
 
27461
  }
 
27462
  if (dlg->change_notify != NULL)
 
27463
  {
 
27464
    (dlg->change_notify)(dlg->change_userdata);
 
27465
  }
 
27466
 
 
27467
}
 
27468
 
22646
27469
static DialoG SourceQualAECRDialog 
22647
27470
(GrouP                    h,
22648
27471
 Int4                     action_choice, 
22726
27549
  }
22727
27550
  
22728
27551
  /* Taxonomy Strings dialog */
22729
 
  dlg->strings = SimpleAECRDialog (g1, action_choice, change_notify, change_userdata,
 
27552
  dlg->strings = SimpleAECRDialog (g1, action_choice, ChangeTaxonomyStrings, dlg,
22730
27553
                           ValNodeSimpleDataFree, NULL,
22731
27554
                           SourceStringSelectionDialog, NULL, NULL,
22732
27555
                           "Taxonomy", NULL, TRUE, entityID);
22765
27588
                           SourceOriginSelectionDialog, NULL, NULL,
22766
27589
                           "Origin", NULL, FALSE, entityID);
22767
27590
  }
 
27591
 
 
27592
  dlg->taxname_options = TaxnameOptionsDialog (p, change_notify, change_userdata);
 
27593
 
 
27594
  Disable (dlg->taxname_options);
22768
27595
  
22769
27596
  AlignObjects (ALIGN_CENTER, (HANDLE) dlg->source_qual,
22770
27597
                              (HANDLE) dlg->location,
22774
27601
                              
22775
27602
  AlignObjects (ALIGN_CENTER, (HANDLE) dlg->qual_kind,
22776
27603
                              (HANDLE) g1,
 
27604
                              (HANDLE) dlg->taxname_options,
22777
27605
                              NULL);
22778
27606
                           
22779
27607
  ChangeQualKind (dlg->qual_kind);                         
22780
27608
  return (DialoG) p;
22781
27609
}
22782
27610
 
22783
 
typedef struct multiqual
22784
 
{
22785
 
  Boolean           multi_found;
22786
 
  SourceQualDescPtr sqdp;
22787
 
  FilterSetPtr      fsp;
22788
 
} MultiQualData, PNTR MultiQualPtr;
22789
27611
 
22790
 
static void CheckForMultipleQuals (BioSourcePtr biop, Pointer userdata)
 
27612
static Boolean BioSourceHasMultipleQuals (BioSourcePtr biop, SourceQualDescPtr sqdp, FilterSetPtr fsp)
22791
27613
{
22792
 
  MultiQualPtr mqp;
 
27614
  OrgModPtr    mod;
 
27615
  SubSourcePtr ssp;
22793
27616
  Boolean      found_one = FALSE;
22794
 
  OrgModPtr    mod;
22795
 
  SubSourcePtr       ssp;
22796
 
  
22797
 
  if (biop == NULL || userdata == NULL)
22798
 
  {
22799
 
    return;
22800
 
  }
22801
 
  
22802
 
  mqp = (MultiQualPtr) userdata;
22803
 
  if (mqp->sqdp == NULL || mqp->multi_found) return;
22804
 
 
22805
 
  if (mqp->sqdp->isOrgMod)
 
27617
 
 
27618
  if (biop == NULL || sqdp == NULL) return FALSE;
 
27619
 
 
27620
  if (sqdp->isOrgMod)
22806
27621
  {
22807
27622
    if (biop->org != NULL && biop->org->orgname != NULL)
22808
27623
    {
22809
27624
      mod = biop->org->orgname->mod;
22810
 
      while (mod != NULL && !mqp->multi_found)
 
27625
      while (mod != NULL)
22811
27626
      {
22812
 
        if (mod->subtype == mqp->sqdp->subtype
 
27627
        if (mod->subtype == sqdp->subtype
22813
27628
            && !StringHasNoText (mod->subname)
22814
 
            && OrgModSpecialMatch (mod, mqp->fsp))
 
27629
            && OrgModSpecialMatch (mod, fsp))
22815
27630
        {
22816
27631
          if (found_one) {
22817
 
            mqp->multi_found = TRUE;
 
27632
            return TRUE;
22818
27633
          } else {
22819
27634
            found_one = TRUE;
22820
27635
          }
22826
27641
  else
22827
27642
  {
22828
27643
    ssp = biop->subtype;
22829
 
    while (ssp != NULL && !mqp->multi_found)
 
27644
    while (ssp != NULL)
22830
27645
    {
22831
 
      if (ssp->subtype == mqp->sqdp->subtype
 
27646
      if (ssp->subtype == sqdp->subtype
22832
27647
          && !StringHasNoText (ssp->name)
22833
 
          && SubSrcSpecialMatch (ssp, mqp->fsp))
 
27648
          && SubSrcSpecialMatch (ssp, fsp))
22834
27649
      {
22835
27650
        if (found_one) {
22836
 
          mqp->multi_found = TRUE;
 
27651
          return TRUE;
22837
27652
        } else {
22838
27653
          found_one = TRUE;
22839
27654
        }
22841
27656
      ssp = ssp->next;
22842
27657
    }
22843
27658
  }
 
27659
  return FALSE;
 
27660
}
 
27661
 
 
27662
static Boolean CheckBioSrcListForMultipleQuals (ValNodePtr biosrc_list, SourceQualDescPtr sqdp, FilterSetPtr fsp)
 
27663
{
 
27664
  ValNodePtr   vnp;
 
27665
  SeqFeatPtr   sfp;
 
27666
  SeqDescrPtr  sdp;
 
27667
  Boolean      has_multiple = FALSE;
 
27668
 
 
27669
  if (sqdp == NULL) return FALSE;
 
27670
 
 
27671
  for (vnp = biosrc_list; vnp != NULL && !has_multiple; vnp = vnp->next)
 
27672
  {
 
27673
    if (vnp->data.ptrvalue == NULL) continue;
 
27674
    if (vnp->choice == OBJ_SEQFEAT)
 
27675
    {
 
27676
      sfp = (SeqFeatPtr) vnp->data.ptrvalue;
 
27677
      if (sfp->data.choice == SEQFEAT_BIOSRC)
 
27678
      {
 
27679
        has_multiple = BioSourceHasMultipleQuals ((BioSourcePtr)sfp->data.value.ptrvalue, sqdp, fsp);
 
27680
      }
 
27681
    }
 
27682
    else if (vnp->choice == OBJ_SEQDESC)
 
27683
    {
 
27684
      sdp = (SeqDescrPtr) vnp->data.ptrvalue;
 
27685
      if (sdp->choice == Seq_descr_source)
 
27686
      {
 
27687
        has_multiple = BioSourceHasMultipleQuals ((BioSourcePtr)sdp->data.ptrvalue, sqdp, fsp);
 
27688
      }
 
27689
    }
 
27690
  }
 
27691
  return has_multiple;
 
27692
}
 
27693
 
 
27694
 
 
27695
typedef struct taxnameoptionsdlg
 
27696
{
 
27697
  DIALOG_MESSAGE_BLOCK
 
27698
  ButtoN               remove_taxref;
 
27699
  ButtoN               remove_common;
 
27700
  ButtoN               remove_old_name;
 
27701
  Nlm_ChangeNotifyProc change_notify;
 
27702
  Pointer              change_userdata;
 
27703
} TaxnameOptionsDlgData, PNTR TaxnameOptionsDlgPtr;
 
27704
 
 
27705
static void TaxnameOptionsToDialog (DialoG d, Pointer data)
 
27706
{
 
27707
  TaxnameOptionsDlgPtr dlg;
 
27708
  TaxnameOptionsPtr    top;
 
27709
 
 
27710
  dlg = (TaxnameOptionsDlgPtr) GetObjectExtra (d);
 
27711
  if (dlg == NULL) return;
 
27712
 
 
27713
  top = (TaxnameOptionsPtr) data;
 
27714
  if (top == NULL)
 
27715
  {
 
27716
    SetStatus (dlg->remove_taxref, TRUE);
 
27717
    SetStatus (dlg->remove_common, TRUE);
 
27718
    SetStatus (dlg->remove_old_name, TRUE);
 
27719
  }
 
27720
  else
 
27721
  {
 
27722
    SetStatus (dlg->remove_taxref, top->remove_taxref);
 
27723
    SetStatus (dlg->remove_common, top->remove_common);
 
27724
    SetStatus (dlg->remove_old_name, top->remove_old_name);
 
27725
  }
 
27726
  if (dlg->change_notify != NULL)
 
27727
  {
 
27728
    (dlg->change_notify) (dlg->change_userdata);
 
27729
  }
 
27730
}
 
27731
 
 
27732
static Pointer TaxnameOptionsFromDialog (DialoG d)
 
27733
{
 
27734
  TaxnameOptionsDlgPtr dlg;
 
27735
  TaxnameOptionsPtr    top;
 
27736
 
 
27737
  dlg = (TaxnameOptionsDlgPtr) GetObjectExtra (d);
 
27738
  if (dlg == NULL) return NULL;
 
27739
 
 
27740
  top = (TaxnameOptionsPtr) MemNew (sizeof (TaxnameOptionsData));
 
27741
  top->remove_taxref = GetStatus (dlg->remove_taxref);
 
27742
  top->remove_common = GetStatus (dlg->remove_common);
 
27743
  top->remove_old_name = GetStatus (dlg->remove_old_name);
 
27744
  return top;
 
27745
}
 
27746
 
 
27747
 
 
27748
static void ChangeTaxnameOptions (ButtoN b)
 
27749
{
 
27750
  TaxnameOptionsDlgPtr dlg;
 
27751
 
 
27752
  dlg = (TaxnameOptionsDlgPtr) GetObjectExtra (b);
 
27753
  if (dlg != NULL && dlg->change_notify != NULL)
 
27754
  {
 
27755
    (dlg->change_notify) (dlg->change_userdata);
 
27756
  }
 
27757
}
 
27758
 
 
27759
 
 
27760
extern DialoG TaxnameOptionsDialog (GrouP h, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
 
27761
{
 
27762
  TaxnameOptionsDlgPtr dlg;
 
27763
  GrouP                p;
 
27764
  
 
27765
  dlg = (TaxnameOptionsDlgPtr) MemNew (sizeof (TaxnameOptionsDlgData));
 
27766
  if (dlg == NULL)
 
27767
  {
 
27768
    return NULL;
 
27769
  }
 
27770
 
 
27771
  p = HiddenGroup (h, 3, 0, NULL);
 
27772
  SetObjectExtra (p, dlg, StdCleanupExtraProc);
 
27773
  SetGroupSpacing (p, 10, 10);
 
27774
  
 
27775
  dlg->dialog = (DialoG) p;
 
27776
  dlg->todialog = TaxnameOptionsToDialog;
 
27777
  dlg->fromdialog = TaxnameOptionsFromDialog;
 
27778
  dlg->change_notify = change_notify;
 
27779
  dlg->change_userdata = change_userdata;
 
27780
 
 
27781
  dlg->remove_taxref = CheckBox (p, "Remove taxonomy xref", ChangeTaxnameOptions);
 
27782
  SetObjectExtra (dlg->remove_taxref, dlg, NULL);
 
27783
  SetStatus (dlg->remove_taxref, TRUE);
 
27784
  dlg->remove_common = CheckBox (p, "Remove GenBank common name", ChangeTaxnameOptions);
 
27785
  SetObjectExtra (dlg->remove_common, dlg, NULL);
 
27786
  SetStatus (dlg->remove_common, TRUE);
 
27787
  dlg->remove_old_name = CheckBox (p, "Remove old_name qualifier", ChangeTaxnameOptions);
 
27788
  SetObjectExtra (dlg->remove_old_name, dlg, NULL);
 
27789
  SetStatus (dlg->remove_old_name, TRUE);
 
27790
  return (DialoG) p;
 
27791
}
 
27792
 
 
27793
extern void ApplyTaxnameOptionsToBioSource (BioSourcePtr biop, TaxnameOptionsPtr top)
 
27794
{
 
27795
  if (biop == NULL || top == NULL) return;
 
27796
 
 
27797
  if (top->remove_taxref)
 
27798
  {
 
27799
    RemoveTaxRef (biop->org);
 
27800
  }
 
27801
  if (top->remove_old_name)
 
27802
  {
 
27803
    RemoveOldName (biop->org);
 
27804
  }
 
27805
  if (top->remove_common) 
 
27806
  {
 
27807
    if (biop->org != NULL)
 
27808
    {
 
27809
      biop->org->common = MemFree (biop->org->common);
 
27810
    }
 
27811
  }
 
27812
}
 
27813
 
 
27814
static void HandleTaxnameOptionsFeature (SeqFeatPtr sfp, TaxnameOptionsPtr top)
 
27815
{
 
27816
  if (sfp == NULL || sfp->data.choice != SEQFEAT_BIOSRC || top == NULL)
 
27817
  {
 
27818
    return;
 
27819
  }
 
27820
  ApplyTaxnameOptionsToBioSource (sfp->data.value.ptrvalue, top);
 
27821
}
 
27822
 
 
27823
static void HandleTaxnameOptionsDescriptorCallback (SeqDescrPtr sdp, TaxnameOptionsPtr top)
 
27824
{
 
27825
  if (sdp == NULL || sdp->choice != Seq_descr_source || top == NULL)
 
27826
  {
 
27827
    return;
 
27828
  }
 
27829
  ApplyTaxnameOptionsToBioSource (sdp->data.ptrvalue, top);
 
27830
}
 
27831
 
 
27832
 
 
27833
static void HandleTaxnameOptionsForBioSourceList (ValNodePtr biosrc_list, TaxnameOptionsPtr top)
 
27834
{
 
27835
  ValNodePtr vnp;
 
27836
 
 
27837
  if (top == NULL) return;
 
27838
  for (vnp = biosrc_list; vnp != NULL; vnp = vnp->next)
 
27839
  {
 
27840
    if (vnp->choice == OBJ_SEQFEAT) 
 
27841
    {
 
27842
      HandleTaxnameOptionsFeature (vnp->data.ptrvalue, top);
 
27843
    }
 
27844
    else if (vnp->choice == OBJ_SEQDESC)
 
27845
    {
 
27846
      HandleTaxnameOptionsDescriptorCallback (vnp->data.ptrvalue, top);
 
27847
    }
 
27848
  }  
 
27849
}
 
27850
 
 
27851
static void CollectBioSourceFeatureFieldCallback (SeqFeatPtr sfp, Pointer userdata, FilterSetPtr fsp)
 
27852
{
 
27853
  if (sfp == NULL || userdata == NULL)
 
27854
  {
 
27855
    return;
 
27856
  }
 
27857
  ValNodeAddPointer ((ValNodePtr PNTR) userdata, OBJ_SEQFEAT, sfp);  
 
27858
}
 
27859
 
 
27860
static void CollectBioSourceDescriptorFieldCallback (SeqDescrPtr sdp, Pointer userdata, FilterSetPtr fsp)
 
27861
{  
 
27862
  if (sdp == NULL || userdata == NULL)
 
27863
  {
 
27864
    return;
 
27865
  }
 
27866
  
 
27867
  ValNodeAddPointer ((ValNodePtr PNTR) userdata, OBJ_SEQDESC, sdp);  
 
27868
}
 
27869
 
 
27870
 
 
27871
static void RemoveSourceQualEditNonMatches (ValNodePtr PNTR biosrc_list, ApplyValuePtr avp)
 
27872
{
 
27873
  ValNodePtr vnp_prev = NULL, vnp_next, vnp_this;
 
27874
  CharPtr    val1, val2;
 
27875
  Boolean    do_remove;
 
27876
 
 
27877
  if (biosrc_list == NULL || avp == NULL || StringHasNoText (avp->text_to_replace))
 
27878
  {
 
27879
    return;
 
27880
  }
 
27881
 
 
27882
  vnp_this = *biosrc_list;
 
27883
  while (vnp_this != NULL)
 
27884
  {
 
27885
    vnp_next = vnp_this->next;
 
27886
    do_remove = FALSE;
 
27887
    if (vnp_this->choice == OBJ_SEQFEAT)
 
27888
    {
 
27889
      val1 = GetSourceQualFeatureString (vnp_this->data.ptrvalue, avp->field_list, NULL);
 
27890
    }
 
27891
    else if (vnp_this->choice == OBJ_SEQDESC)
 
27892
    {
 
27893
      val1 = GetSourceQualDescrString (vnp_this->data.ptrvalue, avp->field_list, NULL);
 
27894
    } 
 
27895
    else
 
27896
    {
 
27897
      val1 = NULL;
 
27898
    }
 
27899
    if (val1 == NULL)
 
27900
    {
 
27901
      do_remove = TRUE;
 
27902
    }
 
27903
    else
 
27904
    {
 
27905
      val2 = HandleApplyValue (StringSave (val1), avp);
 
27906
      if (StringCmp (val1, val2) == 0)
 
27907
      {
 
27908
        do_remove = TRUE;
 
27909
      }
 
27910
      val1 = MemFree (val1);
 
27911
      val2 = MemFree (val2);
 
27912
    }
 
27913
    if (do_remove)
 
27914
    {
 
27915
      if (vnp_prev == NULL)
 
27916
      {
 
27917
        *biosrc_list = vnp_this->next;
 
27918
      }
 
27919
      else
 
27920
      {
 
27921
        vnp_prev->next = vnp_this->next;
 
27922
      }
 
27923
      vnp_this->next = NULL;
 
27924
      vnp_this = ValNodeFree (vnp_this);
 
27925
    }
 
27926
    else
 
27927
    {
 
27928
      vnp_prev = vnp_this;
 
27929
    }
 
27930
    vnp_this = vnp_next;
 
27931
  }
22844
27932
}
22845
27933
 
22846
27934
 
22857
27945
 GetFeatureFieldString       fieldstring_func,
22858
27946
 GetDescriptorFieldString    descrstring_func,
22859
27947
 Boolean                     non_text,
22860
 
 NameFromValNodeProc         name_field_func)
 
27948
 NameFromValNodeProc         name_field_func,
 
27949
 TaxnameOptionsPtr           top)
22861
27950
 
22862
27951
{
22863
27952
  SeqEntryPtr               sep;
22867
27956
  GetSamplePtr              gsp;
22868
27957
  Boolean                   rval = TRUE;
22869
27958
  ValNodePtr                vnp;
22870
 
  MultiQualData             mqd;
22871
27959
  CharPtr                   field_name = NULL;
22872
27960
  MsgAnswer                 ans;
 
27961
  ValNodePtr                biosrc_list = NULL;
 
27962
  SourceQualDescPtr         multi_sqdp = NULL;
22873
27963
  
22874
27964
  sep = GetTopSeqEntryForEntityID (ap->input_entityID);
22875
27965
  if (sp == NULL
22887
27977
  WatchCursor ();
22888
27978
  Update ();
22889
27979
  
 
27980
  avd.where_to_replace = EditApplyFindLocation_anywhere;
 
27981
 
22890
27982
  fsp = (FilterSetPtr) DialogToPointer (ap->constraints);
 
27983
 
 
27984
  /* collect list of BioSources that will be acted upon */
 
27985
  OperateOnSeqEntryConstrainedObjects (sep, fsp, 
 
27986
                                       CollectBioSourceFeatureFieldCallback,
 
27987
                                       CollectBioSourceDescriptorFieldCallback,
 
27988
                                       SEQFEAT_BIOSRC, 0, Seq_descr_source,
 
27989
                                       &biosrc_list);    
22891
27990
  
22892
27991
  if (action_choice == AECR_CONVERT || action_choice == AECR_SWAP || action_choice == AECR_PARSE)
22893
27992
  {
22894
27993
    /* check for multiple sources */
22895
 
    mqd.fsp = fsp;
22896
 
    mqd.multi_found = FALSE;
22897
 
    mqd.sqdp = sp->field_list->data.ptrvalue;
22898
 
    VisitBioSourcesInSep (sep, &mqd, CheckForMultipleQuals);
22899
 
    if (!mqd.multi_found && action_choice == AECR_SWAP) {
22900
 
      mqd.sqdp = sp->field_list_to->data.ptrvalue;
22901
 
      VisitBioSourcesInSep (sep, &mqd, CheckForMultipleQuals);
22902
 
    }
22903
 
    if (mqd.multi_found) {
 
27994
    if ((sp->field_list->choice == 0
 
27995
         && (multi_sqdp = sp->field_list->data.ptrvalue) != NULL
 
27996
         && CheckBioSrcListForMultipleQuals(biosrc_list, multi_sqdp, fsp))
 
27997
        || (action_choice == AECR_SWAP && sp->field_list_to->choice == 0
 
27998
            && (multi_sqdp = sp->field_list_to->data.ptrvalue) != NULL
 
27999
            && CheckBioSrcListForMultipleQuals(biosrc_list, multi_sqdp, fsp))) {
22904
28000
      if (name_field_func != NULL) {  
22905
 
        if (action_choice == AECR_SWAP && mqd.sqdp == sp->field_list_to->data.ptrvalue) {
 
28001
        if (action_choice == AECR_SWAP && multi_sqdp == sp->field_list_to->data.ptrvalue) {
22906
28002
          field_name = name_field_func(sp->field_list_to);
22907
28003
        } else {
22908
28004
          field_name = name_field_func(sp->field_list);
22932
28028
    cfd.remove_d_str_func = descriptor_remove_action;
22933
28029
    cfd.fsp = fsp;
22934
28030
    cfd.strip_name_from_text = sp->strip_name_from_text;
 
28031
    cfd.remove_parsed = sp->remove_parsed;
22935
28032
    cfd.name_field_func = name_field_func;
22936
28033
    cfd.text_portion = sp->text_portion;
22937
28034
    if (action_choice == AECR_CONVERT)
22959
28056
      gsp = CheckForConversionExistingTextInSeqEntry (sep, &cfd, fsp, 
22960
28057
                                                      SEQFEAT_BIOSRC, 0,
22961
28058
                                                      Seq_descr_source);
22962
 
      cfd.etp = GetExistingTextHandlerInfo (gsp, non_text);
 
28059
      cfd.etp = GetExistingTextHandlerInfo (gsp == NULL ? 0 : gsp->num_found, non_text);
22963
28060
      gsp = GetSampleFree (gsp);
22964
 
      if (cfd.etp != NULL && cfd.etp->existing_text_choice == EXISTING_TEXT_CHOICE_CANCEL)
 
28061
      if (cfd.etp != NULL && cfd.etp->existing_text_choice == eExistingTextChoiceCancel)
22965
28062
      {
22966
28063
        rval = FALSE;
22967
28064
      }
23007
28104
                                  ValNodeSimpleDataFree,
23008
28105
                                  copy_vn_proc,
23009
28106
                                  fsp, SEQFEAT_BIOSRC, 0, Seq_descr_source);
23010
 
      avd.etp = GetExistingTextHandlerInfo (gsp, non_text);
 
28107
      avd.etp = GetExistingTextHandlerInfo (gsp == NULL ? 0 : gsp->num_found, non_text);
23011
28108
      gsp = GetSampleFree (gsp);
23012
28109
    
23013
28110
      if (avd.etp != NULL 
23014
 
          && avd.etp->existing_text_choice == EXISTING_TEXT_CHOICE_CANCEL)
 
28111
          && avd.etp->existing_text_choice == eExistingTextChoiceCancel)
23015
28112
      {
23016
28113
        rval = FALSE;
23017
28114
      }
23024
28121
    if (rval)
23025
28122
    {
23026
28123
      AddEditApplyDataToApplyValue (action_choice, sp->edit_apply, &avd);
 
28124
 
 
28125
      if (action_choice == AECR_EDIT)
 
28126
      {
 
28127
        /* remove items that don't contain text that will be replaced */
 
28128
        RemoveSourceQualEditNonMatches (&biosrc_list, &avd);
 
28129
      }
 
28130
 
23027
28131
   
23028
28132
      if (action_choice == AECR_EDIT || action_choice == AECR_APPLY)
23029
28133
      {
23049
28153
    }
23050
28154
    avd.etp = MemFree (avd.etp);
23051
28155
  }
 
28156
 
23052
28157
  FilterSetFree (fsp);
23053
28158
  
23054
28159
  if (rval)
23055
28160
  {
 
28161
    /* Handle taxname options */
 
28162
    HandleTaxnameOptionsForBioSourceList (biosrc_list, top);
 
28163
 
23056
28164
    ObjMgrSetDirtyFlag (ap->input_entityID, TRUE);
23057
28165
    ObjMgrSendMsg (OM_MSG_UPDATE, ap->input_entityID, 0, 0);
23058
28166
  }
 
28167
  biosrc_list = ValNodeFree (biosrc_list);
23059
28168
  ArrowCursor ();
23060
28169
  Update (); 
23061
28170
  
23102
28211
                                       GetSourceQualFeatureString,
23103
28212
                                       GetSourceQualDescrString,
23104
28213
                                       FALSE,
23105
 
                                       SourceQualValNodeName);
 
28214
                                       SourceQualValNodeName,
 
28215
                                       NULL);
23106
28216
      break;
23107
28217
    case QUALKIND_STRINGS :
23108
28218
      rval = SourceQualQualApplyEditConvertRemoveAction (ap, sp->strings, 
23115
28225
                                       GetStringFromSourceFeature,
23116
28226
                                       GetStringFromSourceDescriptor,
23117
28227
                                       FALSE,
23118
 
                                       NULL);
 
28228
                                       NULL,
 
28229
                                       sp->taxname_options);
23119
28230
      break;
23120
28231
    case QUALKIND_LOCATION :
23121
28232
      rval = SourceQualQualApplyEditConvertRemoveAction (ap, sp->location, 
23128
28239
                                       GetLocationFromSourceFeature,
23129
28240
                                       GetLocationFromSourceDescriptor,
23130
28241
                                       TRUE,
23131
 
                                       ValNodeStringName);
 
28242
                                       ValNodeStringName,
 
28243
                                       NULL);
23132
28244
      break;      
23133
28245
    case QUALKIND_ORIGIN :
23134
28246
      rval = SourceQualQualApplyEditConvertRemoveAction (ap, sp->origin, 
23141
28253
                                       GetOriginFromSourceFeature,
23142
28254
                                       GetOriginFromSourceDescriptor,
23143
28255
                                       TRUE,
23144
 
                                       ValNodeStringName);
 
28256
                                       ValNodeStringName,
 
28257
                                       NULL);
23145
28258
      break;      
23146
28259
  }
23147
28260
  sp = SourceQualAECRFree (sp);
23177
28290
  ssd.fieldstring_func = GetSourceQualFeatureString;
23178
28291
  ssd.descrstring_func = GetSourceQualDescrString;
23179
28292
  ssd.entityID = entityID;
23180
 
  ssd.field_list = GetSourceQualDescList (TRUE, TRUE, TRUE);
 
28293
  ssd.field_list = GetSourceQualDescList (TRUE, TRUE, TRUE, FALSE);
23181
28294
  ValNodeAddPointer (&(ssd.field_list), 1, StringSave ("Scientific Name"));
23182
28295
  ValNodeAddPointer (&(ssd.field_list), 1, StringSave ("Location"));
23183
28296
  
23200
28313
                               "Source Qual",
23201
28314
                               SourceQualAECRDialog, 
23202
28315
                               FALSE, GetSourceQualSample,
23203
 
                               FALSE, TRUE, FALSE, FALSE, NULL,
 
28316
                               FALSE, TRUE, FALSE, FALSE, FALSE, NULL,
23204
28317
                               SourceQualApplyEditConvertRemoveAction, NULL,
23205
28318
                               ChangeSourceQualAction, NULL);
23206
28319
}
23240
28353
  SourceQualApplyEditConvertRemove (i, AECR_REMOVE, FALSE);
23241
28354
}
23242
28355
 
23243
 
static CharPtr rna_sample_field_list [] = { "Name", 
23244
 
                                            "Comment", 
23245
 
                                            "Product GBQual" };
 
28356
static CharPtr rna_sample_field_list [] = { "Product", 
 
28357
                                            "Comment" };
23246
28358
static Int2    num_rna_sample_fields = sizeof (rna_sample_field_list) / sizeof (CharPtr);
23247
28359
 
23248
28360
 
23249
 
 
23250
28361
static CharPtr GetRNASampleFieldString (SeqFeatPtr sfp, ValNodePtr vnp, FilterSetPtr fsp)
23251
28362
{
23252
28363
  RnaRefPtr  rrp;
23253
28364
  CharPtr    str = NULL;
23254
 
  GBQualPtr  gbqual;
23255
28365
  Int2       rna_subtype, rna_field_type;
23256
28366
  GeneRefPtr grp;
23257
28367
  SeqFeatPtr gene;
23269
28379
  {
23270
28380
    rna_subtype = (vnp->data.intvalue - 1) / (num_rna_sample_fields + num_gene_fields);
23271
28381
    rna_field_type = (vnp->data.intvalue - 1) % (num_rna_sample_fields + num_gene_fields);
23272
 
    if (rna_subtype == 0)
23273
 
    {
23274
 
      rna_subtype = 255;
23275
 
    }
23276
 
    if (rna_subtype != rrp->type)
23277
 
    {
23278
 
      vnp = vnp->next;
23279
 
      continue;
23280
 
    }
 
28382
    switch (rna_subtype)
 
28383
    {
 
28384
      case 0:
 
28385
        if (rrp->type != 255 
 
28386
            || (rrp->ext.choice == 1
 
28387
                && (StringCmp (rrp->ext.value.ptrvalue, "ncRNA") == 0
 
28388
                    || StringCmp (rrp->ext.value.ptrvalue, "tmRNA") == 0)))
 
28389
        {
 
28390
          vnp = vnp->next;
 
28391
          continue;
 
28392
        }
 
28393
        break;
 
28394
      case 1:
 
28395
      case 2:
 
28396
      case 3:
 
28397
      case 4:
 
28398
        if (rna_subtype != rrp->type)
 
28399
        {
 
28400
          vnp = vnp->next;
 
28401
          continue;
 
28402
        }
 
28403
        break;
 
28404
      case 5:
 
28405
        if (rrp->type != 255 
 
28406
            || rrp->ext.choice != 1
 
28407
            || StringCmp (rrp->ext.value.ptrvalue, "ncRNA") != 0)
 
28408
        {
 
28409
          vnp = vnp->next;
 
28410
          continue;
 
28411
        }
 
28412
        break;
 
28413
      case 6:
 
28414
        if (rrp->type != 255 
 
28415
            || rrp->ext.choice != 1
 
28416
            || StringCmp (rrp->ext.value.ptrvalue, "tmRNA") != 0)
 
28417
        {
 
28418
          vnp = vnp->next;
 
28419
          continue;
 
28420
        }
 
28421
        break;
 
28422
    }
 
28423
 
23281
28424
    switch (rna_field_type)
23282
28425
    {
23283
28426
      case 0 :
23284
 
        str = GetRNANameString (sfp);
 
28427
        str = GetRNAProductString (sfp);
23285
28428
        break;
23286
28429
      case 1 :
23287
28430
        if (!StringHasNoText (sfp->comment))
23289
28432
          str = StringSave (sfp->comment);
23290
28433
        }
23291
28434
        break;
23292
 
      case 2 :
23293
 
        gbqual = sfp->qual;
23294
 
        while (gbqual != NULL && str == NULL) {
23295
 
          if (StringICmp (gbqual->qual, "product") == 0
23296
 
              && !StringHasNoText (gbqual->val)) 
23297
 
          {
23298
 
            str = StringSave (gbqual->val);
23299
 
          }
23300
 
          gbqual = gbqual->next;
23301
 
        }
23302
 
        break;
23303
28435
      default :
23304
28436
        vn.next = NULL;
23305
28437
        vn.choice = 0;
23400
28532
  return d;
23401
28533
}
23402
28534
 
23403
 
typedef struct applyrnaqual
 
28535
typedef struct aecrrnaqual
23404
28536
{
23405
28537
  ValNodePtr   field_list;
23406
 
  ValNodePtr   subtype_list;
 
28538
  ValNodePtr   field_list_to;
 
28539
  RnaTypePtr   rna_type;
23407
28540
  EditApplyPtr edit_apply;
23408
28541
  ValNodePtr   codons;
23409
28542
  SeqLocPtr    anticodon;
23410
 
} ApplyRNAQualData, PNTR ApplyRNAQualPtr;
 
28543
  TextPortionXPtr text_portion;
 
28544
  Boolean        leave_on_original;
 
28545
  Boolean        remove_parsed;
 
28546
} AECRRNAQualData, PNTR AECRRNAQualPtr;
23411
28547
 
23412
 
static ApplyRNAQualPtr ApplyRNAQualFree (ApplyRNAQualPtr ap)
 
28548
static AECRRNAQualPtr AECRRNAQualFree (AECRRNAQualPtr ap)
23413
28549
{
23414
28550
  if (ap != NULL)
23415
28551
  {
23416
28552
    ap->field_list = ValNodeFree (ap->field_list);
23417
 
    ap->subtype_list = ValNodeFree (ap->subtype_list);
 
28553
    ap->field_list_to = ValNodeFree (ap->field_list_to);
 
28554
    ap->rna_type = RnaTypeFree (ap->rna_type);
23418
28555
    ap->edit_apply = EditApplyFree (ap->edit_apply);
23419
28556
    ap->codons = ValNodeFreeData (ap->codons);
23420
28557
    ap = MemFree (ap);
23422
28559
  return ap;
23423
28560
}
23424
28561
 
23425
 
typedef struct applyrnaqualdlg
 
28562
typedef struct aecrrnaqualdlg
23426
28563
{
23427
28564
  DIALOG_MESSAGE_BLOCK
23428
28565
  DialoG               field_list;
23429
 
  DialoG               subtype_list;
 
28566
  DialoG               field_list_to;
 
28567
  DialoG               rna_type;
23430
28568
  DialoG               edit_apply;
23431
28569
  DialoG               codons;
 
28570
  DialoG               ncrna_class;
 
28571
  DialoG               text_portion;
 
28572
  ButtoN               leave_on_original;
 
28573
  ButtoN               remove_parsed;
 
28574
 
23432
28575
  Nlm_ChangeNotifyProc change_notify;
23433
28576
  Pointer              change_userdata;
23434
28577
  Uint2                entityID;
23436
28579
  /* The following is used to create the anticodon location dialog */
23437
28580
  FeatureForm          ff;
23438
28581
  DialoG               anticodon;
23439
 
} ApplyRNAQualDlgData, PNTR ApplyRNAQualDlgPtr;
 
28582
} AECRRNAQualDlgData, PNTR AECRRNAQualDlgPtr;
23440
28583
 
23441
 
static void ClearTextApplyRNAQualDlg (ApplyRNAQualDlgPtr dlg)
 
28584
static void ClearTextAECRRNAQualDlg (AECRRNAQualDlgPtr dlg)
23442
28585
{
23443
28586
  if (dlg != NULL)
23444
28587
  {
23445
28588
    PointerToDialog (dlg->edit_apply, NULL);
23446
28589
    PointerToDialog (dlg->codons, NULL);
 
28590
    PointerToDialog (dlg->ncrna_class, NULL);
23447
28591
  }
23448
28592
}
23449
28593
 
23450
 
static void ResetApplyRNAQualDlg (ApplyRNAQualDlgPtr dlg)
 
28594
static void ResetAECRRNAQualDlg (AECRRNAQualDlgPtr dlg)
23451
28595
{
23452
28596
  if (dlg != NULL)
23453
28597
  {
23454
28598
    PointerToDialog (dlg->field_list, NULL);
 
28599
    PointerToDialog (dlg->field_list_to, NULL);
23455
28600
    SendMessageToDialog (dlg->field_list, NUM_VIB_MSG + 1);
23456
 
    PointerToDialog (dlg->subtype_list, NULL);
23457
 
    ClearTextApplyRNAQualDlg (dlg);
 
28601
    PointerToDialog (dlg->rna_type, NULL);
 
28602
    PointerToDialog (dlg->text_portion, NULL);
 
28603
    SafeSetStatus (dlg->leave_on_original, FALSE);
 
28604
    SafeSetStatus (dlg->remove_parsed, FALSE);
 
28605
    ClearTextAECRRNAQualDlg (dlg);
23458
28606
  }
23459
28607
}
23460
28608
 
23461
 
static void ApplyRNAQualToDialog (DialoG d, Pointer userdata)
 
28609
static void AECRRNAQualToDialog (DialoG d, Pointer userdata)
23462
28610
{
23463
 
  ApplyRNAQualDlgPtr dlg;
23464
 
  ApplyRNAQualPtr    data;
 
28611
  AECRRNAQualDlgPtr dlg;
 
28612
  AECRRNAQualPtr    data;
23465
28613
  
23466
 
  dlg = (ApplyRNAQualDlgPtr) GetObjectExtra (d);
 
28614
  dlg = (AECRRNAQualDlgPtr) GetObjectExtra (d);
23467
28615
  if (dlg == NULL)
23468
28616
  {
23469
28617
    return;
23470
28618
  }
23471
28619
  
23472
 
  ResetApplyRNAQualDlg (dlg);
23473
 
  data = (ApplyRNAQualPtr) userdata;
 
28620
  ResetAECRRNAQualDlg (dlg);
 
28621
  data = (AECRRNAQualPtr) userdata;
23474
28622
  if (data != NULL)
23475
28623
  {
23476
28624
    PointerToDialog (dlg->field_list, data->field_list);
23477
 
    PointerToDialog (dlg->subtype_list, data->subtype_list);
 
28625
    PointerToDialog (dlg->field_list_to, data->field_list_to);
 
28626
    PointerToDialog (dlg->rna_type, data->rna_type);
23478
28627
    PointerToDialog (dlg->edit_apply, data->edit_apply);
23479
28628
    PointerToDialog (dlg->codons, data->codons);
 
28629
    if (data->field_list != NULL && data->field_list->data.intvalue == RNAFIELD_NCRNA_CLASS) {
 
28630
      if (data->edit_apply == NULL) {
 
28631
        PointerToDialog (dlg->ncrna_class, NULL);
 
28632
      } else {
 
28633
        PointerToDialog (dlg->ncrna_class, data->edit_apply->apply_txt);
 
28634
      }
 
28635
    }
23480
28636
    PointerToDialog (dlg->anticodon, data->anticodon);
 
28637
    PointerToDialog (dlg->text_portion, data->text_portion);
 
28638
    SafeSetStatus (dlg->leave_on_original, data->leave_on_original);
 
28639
    SafeSetStatus (dlg->remove_parsed, data->remove_parsed);
23481
28640
  }
23482
28641
}
23483
28642
 
23484
 
static Pointer DialogToApplyRNAQual (DialoG d)
 
28643
static Pointer DialogToAECRRNAQual (DialoG d)
23485
28644
{
23486
 
  ApplyRNAQualDlgPtr dlg;
23487
 
  ApplyRNAQualPtr    data;
 
28645
  AECRRNAQualDlgPtr dlg;
 
28646
  AECRRNAQualPtr    data;
23488
28647
  
23489
 
  dlg = (ApplyRNAQualDlgPtr) GetObjectExtra (d);
 
28648
  dlg = (AECRRNAQualDlgPtr) GetObjectExtra (d);
23490
28649
  if (dlg == NULL)
23491
28650
  {
23492
28651
    return NULL;
23493
28652
  }
23494
28653
  
23495
 
  data = (ApplyRNAQualPtr) MemNew (sizeof (ApplyRNAQualData));
 
28654
  data = (AECRRNAQualPtr) MemNew (sizeof (AECRRNAQualData));
23496
28655
  if (data != NULL)
23497
28656
  {
23498
28657
    data->field_list = DialogToPointer (dlg->field_list);
23499
 
    data->subtype_list = DialogToPointer (dlg->subtype_list);
23500
 
    data->edit_apply = DialogToPointer (dlg->edit_apply);
 
28658
    data->field_list_to = DialogToPointer (dlg->field_list_to);
 
28659
    data->rna_type = DialogToPointer (dlg->rna_type);
 
28660
    if (data->field_list != NULL && data->field_list->data.intvalue == RNAFIELD_NCRNA_CLASS
 
28661
        && dlg->ncrna_class != NULL) {
 
28662
      data->edit_apply = EditApplyNew ();
 
28663
      data->edit_apply->apply_txt = DialogToPointer (dlg->ncrna_class);
 
28664
    } else {
 
28665
      data->edit_apply = DialogToPointer (dlg->edit_apply);
 
28666
    }
23501
28667
    data->codons = DialogToPointer (dlg->codons);
23502
28668
    data->anticodon = DialogToPointer (dlg->anticodon);
 
28669
    data->text_portion = DialogToPointer (dlg->text_portion);
 
28670
    data->leave_on_original = (dlg->leave_on_original == NULL) ? FALSE : GetStatus (dlg->leave_on_original);
 
28671
    data->remove_parsed = (dlg->remove_parsed == NULL) ? FALSE : GetStatus (dlg->remove_parsed);
23503
28672
  }
23504
28673
  return data;
23505
28674
}
23506
28675
 
 
28676
static ValNodePtr GetRNAFeatureList (SeqEntryPtr sep, FilterSetPtr fsp, RnaTypePtr rtp);
 
28677
static GetSamplePtr GetRnaExistingTextForList (ValNodePtr rna_list, ValNodePtr requested_field);
 
28678
 
23507
28679
static CharPtr 
23508
28680
RNAQualAutopopulate 
23509
 
(ValNodePtr subtype_list,
 
28681
(RnaTypePtr rna_type,
23510
28682
 ValNodePtr field_list,
23511
28683
 Uint2      entityID)
23512
28684
{
 
28685
  SeqEntryPtr  sep;
23513
28686
  GetSamplePtr gsp;
 
28687
  ValNodePtr   rna_list;
23514
28688
  CharPtr      rval = NULL;
23515
 
  ValNodePtr   vnp;
23516
28689
 
23517
 
  for (vnp = subtype_list; vnp != NULL && rval == NULL; vnp = vnp->next)
 
28690
  sep = GetTopSeqEntryForEntityID (entityID);
 
28691
  rna_list = GetRNAFeatureList (sep, NULL, rna_type);
 
28692
  gsp = GetRnaExistingTextForList (rna_list, field_list);
 
28693
  if (gsp != NULL && !StringHasNoText (gsp->sample_text))
23518
28694
  {
23519
 
    gsp = CheckForExistingText (entityID,
23520
 
                                field_list,
23521
 
                                GetRNAFieldString,
23522
 
                                NULL, NULL, IntValNodeCopy,
23523
 
                                NULL, SEQFEAT_RNA, vnp->data.intvalue, 0);
23524
 
    if (gsp != NULL && !StringHasNoText (gsp->sample_text))
23525
 
    {
23526
 
      rval = gsp->sample_text;
23527
 
      gsp->sample_text = NULL;
23528
 
    }
23529
 
    GetSampleFree (gsp);
 
28695
    rval = gsp->sample_text;
 
28696
    gsp->sample_text = NULL;
23530
28697
  }
 
28698
  GetSampleFree (gsp);
 
28699
  rna_list = ValNodeFree (rna_list);
23531
28700
  return rval;
23532
28701
}
23533
28702
 
23534
28703
static void RNAQualChangeNotify (Pointer userdata)
23535
28704
{
23536
 
  ApplyRNAQualDlgPtr dlg;
23537
 
  ValNodePtr         field_list = NULL, subtype_list = NULL;
 
28705
  AECRRNAQualDlgPtr  dlg;
 
28706
  ValNodePtr         field_list = NULL;
 
28707
  RnaTypePtr         rna_type;
23538
28708
  EditApplyPtr       eap;
 
28709
  CharPtr            ncrna_class;
23539
28710
 
23540
 
  dlg = (ApplyRNAQualDlgPtr) userdata;
 
28711
  dlg = (AECRRNAQualDlgPtr) userdata;
23541
28712
  if (dlg == NULL)
23542
28713
  {
23543
28714
    return;
23549
28720
    Hide (dlg->edit_apply);
23550
28721
    Hide (dlg->anticodon);
23551
28722
    Hide (dlg->codons);
 
28723
    Hide (dlg->ncrna_class);
23552
28724
  }  
23553
28725
  else if (field_list->data.intvalue == RNAFIELD_CODONS_RECOGNIZED)
23554
28726
  {
23555
28727
    Show (dlg->codons);
23556
28728
    Hide (dlg->edit_apply);
23557
28729
    Hide (dlg->anticodon);
 
28730
    Hide (dlg->ncrna_class);
23558
28731
  }
23559
28732
  else if (field_list->data.intvalue == RNAFIELD_ANTICODON)
23560
28733
  {
23561
28734
    Show (dlg->anticodon);
23562
28735
    Hide (dlg->edit_apply);
23563
28736
    Hide (dlg->codons);
 
28737
    Hide (dlg->ncrna_class);
 
28738
  }
 
28739
  else if (field_list->data.intvalue == RNAFIELD_NCRNA_CLASS && dlg->ncrna_class != NULL)
 
28740
  {
 
28741
    Show (dlg->ncrna_class);
 
28742
    Hide (dlg->codons);
 
28743
    Hide (dlg->edit_apply);
 
28744
    Hide (dlg->anticodon);
 
28745
    /* autopopulate */
 
28746
    rna_type = DialogToPointer (dlg->rna_type);
 
28747
    ncrna_class = RNAQualAutopopulate (rna_type, field_list, dlg->entityID);
 
28748
    PointerToDialog (dlg->ncrna_class, ncrna_class);
 
28749
    ncrna_class = MemFree (ncrna_class);
23564
28750
  }
23565
28751
  else
23566
28752
  {
23567
28753
    Show (dlg->edit_apply);
23568
28754
    Hide (dlg->codons);
23569
28755
    Hide (dlg->anticodon);
 
28756
    Hide (dlg->ncrna_class);
23570
28757
 
23571
28758
    /* autopopulate text fields */
23572
 
    subtype_list = DialogToPointer (dlg->subtype_list);
23573
 
    eap = DialogToPointer (dlg->edit_apply);
23574
 
    eap->apply_txt = MemFree (eap->apply_txt);
23575
 
    eap->apply_txt = RNAQualAutopopulate (subtype_list, field_list, dlg->entityID);
23576
 
    PointerToDialog (dlg->edit_apply, eap);
23577
 
    EditApplyFree (eap);    
23578
 
    subtype_list = ValNodeFree (subtype_list);
 
28759
    if (dlg->edit_apply != NULL)
 
28760
    {    
 
28761
      rna_type = DialogToPointer (dlg->rna_type);
 
28762
      eap = DialogToPointer (dlg->edit_apply);
 
28763
      eap->apply_txt = MemFree (eap->apply_txt);
 
28764
      eap->apply_txt = RNAQualAutopopulate (rna_type, field_list, dlg->entityID);
 
28765
      PointerToDialog (dlg->edit_apply, eap);
 
28766
      EditApplyFree (eap);    
 
28767
      rna_type = RnaTypeFree (rna_type);
 
28768
    }
23579
28769
  }
23580
28770
  
23581
28771
  field_list = ValNodeFree (field_list);
23586
28776
  }  
23587
28777
}
23588
28778
 
23589
 
static void ApplyRNAQualMessage (DialoG d, Int2 mssg)
 
28779
static void AECRRNAQualMessage (DialoG d, Int2 mssg)
23590
28780
 
23591
28781
{
23592
 
  ApplyRNAQualDlgPtr  dlg;
 
28782
  AECRRNAQualDlgPtr  dlg;
23593
28783
 
23594
 
  dlg = (ApplyRNAQualDlgPtr) GetObjectExtra (d);
 
28784
  dlg = (AECRRNAQualDlgPtr) GetObjectExtra (d);
23595
28785
  if (dlg != NULL) {
23596
28786
    switch (mssg) 
23597
28787
    {
23598
28788
      case VIB_MSG_INIT :
23599
28789
        /* reset list */
23600
 
        ResetApplyRNAQualDlg (dlg);
 
28790
        ResetAECRRNAQualDlg (dlg);
23601
28791
        break;
23602
28792
      case VIB_MSG_ENTER :
23603
 
        if (dlg->subtype_list != NULL)
23604
 
        {
23605
 
          Select (dlg->subtype_list);
23606
 
        }
23607
 
        else
23608
 
        {
23609
 
          Select (dlg->field_list);
23610
 
        }
 
28793
        Select (dlg->rna_type);
23611
28794
        break;
23612
28795
      case AECR_VIB_MSG_SET_DEFAULT :
23613
28796
        SendMessageToDialog (dlg->field_list, AECR_VIB_MSG_SET_DEFAULT);
23614
 
        SendMessageToDialog (dlg->subtype_list, AECR_VIB_MSG_SET_DEFAULT);
23615
 
        ClearTextApplyRNAQualDlg (dlg);
 
28797
        SendMessageToDialog (dlg->rna_type, AECR_VIB_MSG_SET_DEFAULT);
 
28798
        ClearTextAECRRNAQualDlg (dlg);
23616
28799
        break;
23617
28800
      case AECR_VIB_MSG_CLEAR_TEXT :
23618
 
        ClearTextApplyRNAQualDlg (dlg);
 
28801
        ClearTextAECRRNAQualDlg (dlg);
23619
28802
        break;
23620
28803
      case AECR_VIB_MSG_AUTOPOPULATE:
23621
28804
        RNAQualChangeNotify (dlg);
23626
28809
  }
23627
28810
}
23628
28811
 
23629
 
static ValNodePtr TestApplyRNAQual (DialoG d)
 
28812
static ValNodePtr TestAECRRNAQual (DialoG d)
23630
28813
{
23631
 
  ApplyRNAQualDlgPtr dlg;
23632
 
  ValNodePtr         err_list = NULL;
 
28814
  AECRRNAQualDlgPtr dlg;
23633
28815
  ValNodePtr         total_err_list = NULL;
23634
28816
  ValNodePtr         field_list;
23635
28817
  
23636
 
  dlg = (ApplyRNAQualDlgPtr) GetObjectExtra (d);
 
28818
  dlg = (AECRRNAQualDlgPtr) GetObjectExtra (d);
23637
28819
  if (dlg == NULL)
23638
28820
  {
23639
28821
    return NULL;
23640
28822
  }
23641
28823
 
23642
 
  total_err_list = TestDialog (dlg->subtype_list);
 
28824
  total_err_list = TestDialog (dlg->rna_type);
23643
28825
  
23644
 
  err_list = TestDialog (dlg->field_list);
23645
 
  total_err_list = ValNodeAppend (total_err_list, err_list);
 
28826
  ValNodeLink (&total_err_list, TestDialog (dlg->field_list));
23646
28827
      
23647
28828
  field_list = DialogToPointer (dlg->field_list);
23648
 
  if (field_list != NULL && field_list->data.intvalue != RNAFIELD_CODONS_RECOGNIZED)
23649
 
  {
23650
 
    err_list = TestDialog (dlg->edit_apply);
23651
 
    total_err_list = ValNodeAppend (total_err_list, err_list);
 
28829
  if (field_list != NULL) {
 
28830
    if (field_list->data.intvalue == RNAFIELD_NCRNA_CLASS && dlg->ncrna_class != NULL) {
 
28831
      ValNodeLink (&total_err_list, TestDialog (dlg->ncrna_class));
 
28832
    } else if (field_list->data.intvalue != RNAFIELD_CODONS_RECOGNIZED) {
 
28833
      ValNodeLink (&total_err_list, TestDialog (dlg->edit_apply));
 
28834
    }
23652
28835
  }
23653
28836
      
23654
28837
  return total_err_list;
23655
28838
}
23656
28839
 
23657
 
static DialoG ApplyRNAQualDialog
 
28840
 
 
28841
static void AECRRNAQualButtonChange (ButtoN b)
 
28842
{
 
28843
  AECRRNAQualDlgPtr dlg;
 
28844
 
 
28845
  dlg = (AECRRNAQualDlgPtr) GetObjectExtra (b);
 
28846
  if (dlg == NULL) return;
 
28847
 
 
28848
  if (dlg->change_notify != NULL) 
 
28849
  {
 
28850
    (dlg->change_notify) (dlg->change_userdata);
 
28851
  }
 
28852
}
 
28853
 
 
28854
 
 
28855
static DialoG RNAQualListDialog
23658
28856
(GrouP                    h,
 
28857
 Int4                     action_choice, 
23659
28858
 Nlm_ChangeNotifyProc     change_notify,
23660
28859
 Pointer                  change_userdata,
23661
28860
 Uint2                    entityID)
23662
28861
{
23663
 
  ApplyRNAQualDlgPtr dlg;
23664
 
  GrouP              p, g1, g2;
 
28862
  AECRRNAQualDlgPtr dlg;
 
28863
  GrouP              p, g1, g2 = NULL;
23665
28864
  SeqEntryPtr        sep;
23666
28865
  
23667
 
  dlg = (ApplyRNAQualDlgPtr) MemNew (sizeof (ApplyRNAQualDlgData));
 
28866
  dlg = (AECRRNAQualDlgPtr) MemNew (sizeof (AECRRNAQualDlgData));
23668
28867
  if (dlg == NULL)
23669
28868
  {
23670
28869
    return NULL;
23675
28874
  SetGroupSpacing (p, 10, 10);
23676
28875
  
23677
28876
  dlg->dialog = (DialoG) p;
23678
 
  dlg->todialog = ApplyRNAQualToDialog;
23679
 
  dlg->fromdialog = DialogToApplyRNAQual;
23680
 
  dlg->dialogmessage = ApplyRNAQualMessage;
23681
 
  dlg->testdialog = TestApplyRNAQual;
 
28877
  dlg->todialog = AECRRNAQualToDialog;
 
28878
  dlg->fromdialog = DialogToAECRRNAQual;
 
28879
  dlg->dialogmessage = AECRRNAQualMessage;
 
28880
  dlg->testdialog = TestAECRRNAQual;
23682
28881
  dlg->change_notify = change_notify;
23683
28882
  dlg->change_userdata = change_userdata;
23684
28883
  dlg->entityID = entityID;
23685
 
  
23686
 
  g1 = HiddenGroup (p, 2, 0, NULL);
23687
 
  StaticPrompt (g1, "RNA Type", 0, dialogTextHeight, systemFont, 'l');
23688
 
  StaticPrompt (g1, "RNA Field", 0, dialogTextHeight, systemFont, 'l');
23689
 
  dlg->subtype_list = RNASubtypeSelectionDialog (g1, TRUE, NULL,
23690
 
                                                 RNAQualChangeNotify,
23691
 
                                                 dlg);
23692
 
  dlg->field_list = RNAAddFieldSelectionDialog (g1, FALSE, 
23693
 
                                                RNAQualChangeNotify,
23694
 
                                                dlg);
23695
 
  
23696
 
  g2 = HiddenGroup (p, 0, 0, NULL);
23697
 
  dlg->edit_apply = EditApplyDialog (g2, AECR_APPLY, "New Text",
23698
 
                                     change_notify, change_userdata);
23699
 
  
23700
 
  dlg->codons = CreateVisibleStringDialog (g2, 3, -1, 4);
23701
 
  
23702
 
  sep = GetTopSeqEntryForEntityID (entityID);
23703
 
  
23704
 
  dlg->anticodon = NULL;
23705
 
/*
23706
 
  dlg->anticodon = CreateIntervalEditorDialogEx (g2, NULL, 2, 2, sep, TRUE, FALSE,
23707
 
                                                  TRUE, TRUE, FALSE,
23708
 
                                                  &(dlg->ff),
23709
 
                                                  NULL); */
23710
 
 
23711
 
  AlignObjects (ALIGN_CENTER, (HANDLE) dlg->edit_apply,
23712
 
                              (HANDLE) dlg->codons,
23713
 
                              (HANDLE) dlg->anticodon,
23714
 
                              NULL);
 
28884
 
 
28885
 
 
28886
  if (action_choice == AECR_CONVERT || action_choice == AECR_SWAP || action_choice == AECR_PARSE)
 
28887
  {
 
28888
    g1 = HiddenGroup (p, 3, 0, NULL);
 
28889
    StaticPrompt (g1, "", 0, dialogTextHeight, systemFont, 'l');
 
28890
    StaticPrompt (g1, "From", 0, dialogTextHeight, systemFont, 'l');
 
28891
    StaticPrompt (g1, "To", 0, dialogTextHeight, systemFont, 'l');
 
28892
    dlg->rna_type = RnaTypeDialog (g1, TRUE, RNAQualChangeNotify, dlg);
 
28893
 
 
28894
    dlg->field_list = RNAFieldSelectionDialog (g1, FALSE, 
 
28895
                                          change_notify, 
 
28896
                                          change_userdata);
 
28897
    dlg->field_list_to = RNAFieldSelectionDialog (g1, FALSE, 
 
28898
                                             change_notify, 
 
28899
                                             change_userdata);
 
28900
    if (action_choice == AECR_CONVERT)
 
28901
    {
 
28902
      dlg->leave_on_original = CheckBox (p, "Leave on original", AECRRNAQualButtonChange);
 
28903
      SetObjectExtra (dlg->leave_on_original, dlg, NULL);
 
28904
    }
 
28905
  }
 
28906
  else
 
28907
  {
 
28908
    g1 = HiddenGroup (p, 2, 0, NULL);
 
28909
    StaticPrompt (g1, "", 0, dialogTextHeight, systemFont, 'l');
 
28910
    StaticPrompt (g1, "RNA Field", 0, dialogTextHeight, systemFont, 'l');
 
28911
    dlg->rna_type = RnaTypeDialog (g1, TRUE, RNAQualChangeNotify, dlg);
 
28912
    if (action_choice == AECR_REMOVE)
 
28913
    {
 
28914
      dlg->field_list = RNARemoveFieldSelectionDialog (g1, TRUE, 
 
28915
                                            RNAQualChangeNotify, dlg);
 
28916
    }
 
28917
    else
 
28918
    {
 
28919
      dlg->field_list = RNAFieldSelectionDialog (g1, FALSE, 
 
28920
                                            RNAQualChangeNotify, 
 
28921
                                            dlg);
 
28922
    }
 
28923
  }
 
28924
 
 
28925
  if (action_choice == AECR_APPLY)
 
28926
  {
 
28927
    g2 = HiddenGroup (p, 0, 0, NULL);
 
28928
    dlg->edit_apply = EditApplyDialog (g2, eEditApplyChoice_Apply, "New Text", NULL,
 
28929
                                       change_notify, change_userdata);
 
28930
  
 
28931
    dlg->codons = CreateVisibleStringDialog (g2, 3, -1, 4);
 
28932
 
 
28933
    dlg->ncrna_class = CreatencRNAClassDialog (g2, FALSE, change_notify, change_userdata);
 
28934
  
 
28935
    sep = GetTopSeqEntryForEntityID (entityID);
 
28936
  
 
28937
    dlg->anticodon = NULL;
 
28938
  /*
 
28939
    dlg->anticodon = CreateIntervalEditorDialogEx (g2, NULL, 2, 2, sep, TRUE, FALSE,
 
28940
                                                    TRUE, TRUE, FALSE,
 
28941
                                                    &(dlg->ff),
 
28942
                                                    NULL); */
 
28943
 
 
28944
    AlignObjects (ALIGN_CENTER, (HANDLE) dlg->edit_apply,
 
28945
                                (HANDLE) dlg->codons,
 
28946
                                (HANDLE) dlg->ncrna_class,
 
28947
                                (HANDLE) dlg->anticodon,
 
28948
                                NULL);
 
28949
  }
 
28950
  else if (action_choice == AECR_EDIT)
 
28951
  {
 
28952
    g2 = HiddenGroup (p, 1, 0, NULL);
 
28953
    dlg->edit_apply = EditApplyDialog (g2, eEditApplyChoice_Edit,
 
28954
                                       "New Text", NULL,
 
28955
                                       change_notify, change_userdata);
 
28956
    dlg->text_portion = NULL;
 
28957
    dlg->remove_parsed = NULL;
 
28958
  }
 
28959
  else if (action_choice == AECR_PARSE)
 
28960
  {
 
28961
    g2 = HiddenGroup (p, -1, 0, NULL);
 
28962
    dlg->edit_apply = NULL;
 
28963
    dlg->text_portion = TextPortionXDialog(p);
 
28964
    dlg->remove_parsed = CheckBox (p, "Remove from parsed field", SimpleAECRButtonChange);
 
28965
    SetObjectExtra (dlg->remove_parsed, dlg, NULL);
 
28966
    AlignObjects (ALIGN_CENTER, (HANDLE) dlg->edit_apply, (HANDLE) dlg->remove_parsed, NULL);
 
28967
  }
 
28968
  else
 
28969
  {
 
28970
    dlg->edit_apply = NULL;
 
28971
    dlg->text_portion = NULL;
 
28972
    dlg->remove_parsed = NULL;
 
28973
  }
 
28974
  
23715
28975
 
23716
28976
  AlignObjects (ALIGN_CENTER, (HANDLE) g1, (HANDLE) g2, NULL);
23717
28977
  
23720
28980
  return (DialoG) p;
23721
28981
}
23722
28982
 
23723
 
static DialoG RNAQualListDialog 
23724
 
(GrouP                    h,
23725
 
 Int4                     action_choice,
23726
 
 Nlm_ChangeNotifyProc     change_notify,
23727
 
 Pointer                  change_userdata,
23728
 
 Uint2                    entityID)
23729
 
{
23730
 
  DialoG d = NULL;
23731
 
  
23732
 
  switch (action_choice)
23733
 
  {
23734
 
    case AECR_REMOVE:
23735
 
      d = SimpleAECRDialog (h, action_choice, change_notify, change_userdata,
23736
 
                            NULL, NULL,
23737
 
                            RNARemoveFieldSelectionDialog,
23738
 
                            RNASubtypeSelectionDialog,
23739
 
                            NULL,
23740
 
                            "RNA Field", "RNA type", FALSE, entityID);
23741
 
      break;
23742
 
    case AECR_CONVERT:
23743
 
    case AECR_SWAP:
23744
 
    case AECR_PARSE:
23745
 
      d = SimpleAECRDialog (h, action_choice, change_notify, change_userdata,
23746
 
                            NULL, NULL,
23747
 
                            RNAFieldSelectionDialog,
23748
 
                            RNASubtypeSelectionDialog,
23749
 
                            NULL,
23750
 
                            "RNA Field", "RNA type", TRUE, entityID);
23751
 
      break;
23752
 
      break;
23753
 
    case AECR_EDIT:
23754
 
      d = SimpleAECRDialog (h, action_choice, change_notify, change_userdata,
23755
 
                            NULL, NULL,
23756
 
                            RNAFieldSelectionDialog,
23757
 
                            RNASubtypeSelectionDialog,
23758
 
                            RNAQualAutopopulate,
23759
 
                            "RNA Field", "RNA type", TRUE, entityID);
23760
 
      break;
23761
 
    case AECR_APPLY:
23762
 
      d = ApplyRNAQualDialog (h, change_notify, change_userdata, entityID);
23763
 
      break;
23764
 
  }
23765
 
  return d;
23766
 
}
23767
28983
 
23768
28984
static void ApplyRNACodonsCallback (SeqFeatPtr sfp, Pointer userdata, FilterSetPtr fsp)
23769
28985
{
23818
29034
  }
23819
29035
}
23820
29036
 
23821
 
static Boolean AcceptRNAApply (ApplyEditConvertRemovePtr ap)
23822
 
{
23823
 
  ApplyRNAQualPtr rp;
23824
 
  FilterSetPtr    fsp;
 
29037
 
 
29038
static void CollectRNAFeaturesCallback (SeqFeatPtr sfp, Pointer userdata, FilterSetPtr fsp)
 
29039
{  
 
29040
  if (sfp != NULL && sfp->data.choice == SEQFEAT_RNA && userdata != NULL)
 
29041
  {
 
29042
    ValNodeAddPointer ((ValNodePtr PNTR) userdata, OBJ_SEQFEAT, sfp);
 
29043
  }
 
29044
  
 
29045
}
 
29046
 
 
29047
 
 
29048
static ValNodePtr GetRNAFeatureList (SeqEntryPtr sep, FilterSetPtr fsp, RnaTypePtr rtp)
 
29049
{
 
29050
  ValNodePtr rna_list = NULL, vnp_rna;
 
29051
  ValNodePtr not_match;
 
29052
  SeqFeatPtr sfp;
 
29053
  Boolean    matches;
 
29054
 
 
29055
  if (sep == NULL) return NULL;
 
29056
 
 
29057
  OperateOnSeqEntryConstrainedObjects (sep, fsp, CollectRNAFeaturesCallback,
 
29058
                                       NULL, SEQFEAT_RNA, 0, 0, &rna_list);  
 
29059
 
 
29060
  if (rtp != NULL)
 
29061
  {
 
29062
    for (vnp_rna = rna_list; vnp_rna != NULL; vnp_rna = vnp_rna->next)
 
29063
    {  
 
29064
      matches = FALSE;
 
29065
      sfp = vnp_rna->data.ptrvalue;
 
29066
      if (!MatchesRnaType (sfp, rtp))
 
29067
      {
 
29068
        vnp_rna->choice = 0;
 
29069
      }
 
29070
    }
 
29071
 
 
29072
    not_match = ValNodeExtractList (&rna_list, 0);
 
29073
    not_match = ValNodeFree (not_match);
 
29074
  }
 
29075
  return rna_list;
 
29076
}
 
29077
 
 
29078
 
 
29079
static GetSamplePtr GetRnaExistingTextForList (ValNodePtr rna_list, ValNodePtr requested_field)
 
29080
{
 
29081
  GetSamplePtr gsp;
 
29082
  ValNodePtr   vnp;
 
29083
  SeqFeatPtr   sfp;
 
29084
 
 
29085
  if (rna_list == NULL || requested_field == NULL) return NULL;
 
29086
 
 
29087
  gsp = GetSampleNew ();
 
29088
  gsp->sample_text = NULL;
 
29089
  gsp->fieldstring_func = GetRNAFieldString;
 
29090
  gsp->descrstring_func = NULL;
 
29091
  gsp->free_vn_proc = NULL;
 
29092
  gsp->copy_vn_proc = IntValNodeCopy;
 
29093
  gsp->requested_field = (gsp->copy_vn_proc) (requested_field);
 
29094
  gsp->num_found = 0;
 
29095
  gsp->all_same = TRUE;
 
29096
 
 
29097
  for (vnp = rna_list; vnp != NULL; vnp = vnp->next)
 
29098
  {  
 
29099
    sfp = vnp->data.ptrvalue;
 
29100
    GetSampleFeatureCallback (sfp, gsp, NULL);
 
29101
  }
 
29102
  return gsp;
 
29103
}
 
29104
 
 
29105
 
 
29106
static Boolean ApplyToRNAList (ValNodePtr rna_list, AECRRNAQualPtr rp, FilterSetPtr fsp)
 
29107
{
 
29108
  ValNodePtr      vnp_rna;
 
29109
  SeqFeatPtr      sfp;
23825
29110
  ApplyValueData  avd;
23826
29111
  Boolean         rval = TRUE;
23827
 
  SeqEntryPtr     sep;
23828
 
  ValNodePtr      vnp;
23829
 
  GetSamplePtr    gsp, gsp_new, gsp_sum;
23830
 
  
23831
 
  if (ap == NULL)
23832
 
  {
23833
 
    return FALSE;
23834
 
  }
23835
 
  
23836
 
  rp = DialogToPointer (ap->aecr_pages[AECR_APPLY - 1]);
23837
 
  
23838
 
  sep = GetTopSeqEntryForEntityID (ap->input_entityID);
23839
 
  if (rp->subtype_list == NULL || rp->field_list == NULL)
23840
 
  {
23841
 
    rp = ApplyRNAQualFree (rp);
23842
 
    return FALSE;
23843
 
  }
23844
 
  
23845
 
  fsp = (FilterSetPtr) DialogToPointer (ap->constraints);
23846
 
  
 
29112
  GetSamplePtr    gsp;
 
29113
 
 
29114
  if (rna_list == NULL || rp == NULL || rp->field_list == NULL)
 
29115
  {
 
29116
    return FALSE;
 
29117
  }
 
29118
 
23847
29119
  if (rp->field_list->data.intvalue == RNAFIELD_CODONS_RECOGNIZED)
23848
29120
  {
23849
 
    for (vnp = rp->subtype_list; vnp != NULL; vnp = vnp->next)
 
29121
    for (vnp_rna = rna_list; vnp_rna != NULL; vnp_rna = vnp_rna->next)
23850
29122
    {
23851
 
      OperateOnSeqEntryConstrainedObjects (sep, fsp, ApplyRNACodonsCallback,
23852
 
                                           NULL, SEQFEAT_RNA, FEATDEF_tRNA, 0, rp->codons);  
 
29123
      sfp = vnp_rna->data.ptrvalue;
 
29124
      if (sfp->idx.subtype == FEATDEF_tRNA)
 
29125
      {
 
29126
        ApplyRNACodonsCallback (sfp, rp->codons, fsp);
 
29127
      }
23853
29128
    }
23854
29129
  }
23855
29130
  else if (rp->field_list->data.intvalue == RNAFIELD_ANTICODON)
23856
29131
  {
23857
 
    for (vnp = rp->subtype_list; vnp != NULL; vnp = vnp->next)
 
29132
    for (vnp_rna = rna_list; vnp_rna != NULL; vnp_rna = vnp_rna->next)
23858
29133
    {
23859
 
      OperateOnSeqEntryConstrainedObjects (sep, fsp, ApplyRNAAnticodonCallback,
23860
 
                                           NULL, SEQFEAT_RNA, FEATDEF_tRNA, 0, rp->anticodon);  
 
29134
      sfp = vnp_rna->data.ptrvalue;
 
29135
      if (sfp->idx.subtype == FEATDEF_tRNA)
 
29136
      {
 
29137
        ApplyRNAAnticodonCallback (sfp, rp->anticodon, fsp);
 
29138
      }
23861
29139
    }
23862
29140
  }
23863
29141
  else
23864
29142
  {
23865
29143
    avd.field_list = rp->field_list;
 
29144
    avd.where_to_replace = EditApplyFindLocation_anywhere;
23866
29145
    
23867
29146
    /* get handling for existing text */
23868
 
    gsp_sum = NULL;
23869
 
    for (vnp = rp->subtype_list; vnp != NULL; vnp = vnp->next)
23870
 
    {
23871
 
      gsp = CheckForExistingText (ap->input_entityID,
23872
 
                                  avd.field_list,
23873
 
                                  GetRNAFieldString,
23874
 
                                  NULL, NULL, IntValNodeCopy,
23875
 
                                  fsp, SEQFEAT_RNA, vnp->data.intvalue, 0);
23876
 
      gsp_new = GetSampleAdd (gsp_sum, gsp);
23877
 
      gsp = GetSampleFree (gsp);
23878
 
      gsp_sum = GetSampleFree (gsp_sum);
23879
 
      gsp_sum = gsp_new;
23880
 
    }
23881
 
    avd.etp = GetExistingTextHandlerInfo (gsp_sum, FALSE);
23882
 
    gsp_sum = GetSampleFree (gsp_sum);
 
29147
    gsp = GetRnaExistingTextForList (rna_list, rp->field_list);
 
29148
    avd.etp = GetExistingTextHandlerInfo (gsp == NULL ? 0 : gsp->num_found, FALSE);
 
29149
    gsp = GetSampleFree (gsp);
23883
29150
  
23884
29151
    if (avd.etp != NULL 
23885
 
        && avd.etp->existing_text_choice == EXISTING_TEXT_CHOICE_CANCEL)
 
29152
        && avd.etp->existing_text_choice == eExistingTextChoiceCancel)
23886
29153
    {
23887
29154
      rval = FALSE;
23888
29155
    }
23891
29158
    {
23892
29159
      AddEditApplyDataToApplyValue (AECR_APPLY, rp->edit_apply, &avd);
23893
29160
     
23894
 
      for (vnp = rp->subtype_list; vnp != NULL; vnp = vnp->next)
 
29161
      for (vnp_rna = rna_list; vnp_rna != NULL; vnp_rna = vnp_rna->next)
23895
29162
      {
23896
 
        OperateOnSeqEntryConstrainedObjects (sep, fsp, SetRNAFieldString,
23897
 
                                             NULL, SEQFEAT_RNA, vnp->data.intvalue, 0, &avd);  
 
29163
        sfp = vnp_rna->data.ptrvalue;
 
29164
        SetRNAFieldString (sfp, &avd, fsp);
23898
29165
      }
23899
29166
      avd.text_to_replace = MemFree (avd.text_to_replace);
23900
29167
      avd.new_text = MemFree (avd.new_text);
23901
29168
    }
23902
29169
    avd.etp = MemFree (avd.etp);
23903
29170
  }
23904
 
  
23905
 
  FilterSetFree (fsp);
23906
 
  
23907
29171
  return rval;
23908
29172
}
23909
29173
 
 
29174
 
23910
29175
static Boolean 
23911
 
AcceptRNAQualEditRemoveConvert 
23912
 
(ApplyEditConvertRemovePtr ap,
23913
 
 Int4                      action_choice,
23914
 
 SimpleAECRPtr             rp)
 
29176
RNAQualConvertSwapParseList
 
29177
(ValNodePtr      rna_list,
 
29178
 AECRRNAQualPtr  rp,
 
29179
 Int4            action_choice,
 
29180
 FilterSetPtr    fsp)
23915
29181
{
23916
 
  SeqEntryPtr      sep;
23917
 
  FilterSetPtr     fsp;
23918
 
  ConvertFieldData cfd;
23919
 
  GetSamplePtr     gsp, gsp_new, gsp_sum;
23920
 
  ValNodePtr       vnp;
23921
 
  ApplyValueData   avd;
23922
 
  Boolean          rval = TRUE;
 
29182
  ConvertFieldData       cfd;
 
29183
  ConversionConflictData ccd;
 
29184
  ValNodePtr             vnp_rna;
 
29185
  ApplyValueData         avd;
 
29186
  Boolean                rval = TRUE;
 
29187
  SeqFeatPtr             sfp;
23923
29188
  
23924
 
  if (ap == NULL
 
29189
  if (rna_list == NULL
 
29190
      || rp == NULL
23925
29191
      || action_choice < AECR_EDIT 
23926
29192
      || action_choice > NUM_AECR
23927
 
      || rp == NULL
23928
 
      || rp->subtype_list == NULL || rp->field_list == NULL
23929
 
      || ((action_choice == AECR_CONVERT || action_choice == AECR_SWAP || action_choice == AECR_PARSE) 
23930
 
           && rp->field_list_to == NULL))
 
29193
      || rp->field_list == NULL
 
29194
      || rp->field_list_to == NULL)
23931
29195
  {
23932
29196
    return FALSE;
23933
29197
  }
23934
29198
 
23935
 
  sep = GetTopSeqEntryForEntityID (ap->input_entityID);
23936
 
 
23937
 
  fsp = (FilterSetPtr) DialogToPointer (ap->constraints);
 
29199
  avd.where_to_replace = EditApplyFindLocation_anywhere;
23938
29200
  
23939
 
  if (action_choice == AECR_CONVERT || action_choice == AECR_SWAP || action_choice == AECR_PARSE)
 
29201
  cfd.src_field_list = rp->field_list;
 
29202
  cfd.dst_field_list = rp->field_list_to;
 
29203
  cfd.etp = NULL;
 
29204
  cfd.get_str_func = GetRNAFieldString;
 
29205
  cfd.set_str_func = SetRNAFieldString;
 
29206
  cfd.remove_str_func = RemoveRNAField;
 
29207
  cfd.get_d_str_func = NULL;
 
29208
  cfd.set_d_str_func = NULL;
 
29209
  cfd.remove_d_str_func = NULL;
 
29210
  cfd.fsp = fsp;
 
29211
  cfd.strip_name_from_text = FALSE;
 
29212
  cfd.name_field_func = NULL;
 
29213
  cfd.text_portion = rp->text_portion;
 
29214
  cfd.remove_parsed = rp->remove_parsed;
 
29215
 
 
29216
  if (action_choice == AECR_CONVERT)
23940
29217
  {
23941
 
    cfd.src_field_list = rp->field_list;
23942
 
    cfd.dst_field_list = rp->field_list_to;
23943
 
    cfd.etp = NULL;
23944
 
    cfd.get_str_func = GetRNAFieldString;
23945
 
    cfd.set_str_func = SetRNAFieldString;
23946
 
    cfd.remove_str_func = RemoveRNAField;
23947
 
    cfd.get_d_str_func = NULL;
23948
 
    cfd.set_d_str_func = NULL;
23949
 
    cfd.remove_d_str_func = NULL;
23950
 
    cfd.fsp = fsp;
23951
 
    cfd.strip_name_from_text = rp->strip_name_from_text;
23952
 
    cfd.name_field_func = NULL;
23953
 
    cfd.text_portion = rp->text_portion;
23954
 
 
23955
 
    if (action_choice == AECR_CONVERT)
23956
 
    {
23957
 
      if (rp->leave_on_original)
23958
 
      {
23959
 
        cfd.convert_type = CONVERT_TYPE_COPY;
23960
 
      }
23961
 
      else
23962
 
      {
23963
 
        cfd.convert_type = CONVERT_TYPE_MOVE;
23964
 
      }
23965
 
    }
23966
 
    else if (action_choice == AECR_SWAP)
23967
 
    {
23968
 
      cfd.convert_type = CONVERT_TYPE_SWAP;
23969
 
    }
23970
 
    else if (action_choice == AECR_PARSE)
23971
 
    {
23972
 
      cfd.convert_type = CONVERT_TYPE_PARSE;
23973
 
    }
23974
 
    
23975
 
    if (cfd.convert_type == CONVERT_TYPE_MOVE || cfd.convert_type == CONVERT_TYPE_COPY || cfd.convert_type == CONVERT_TYPE_PARSE)
23976
 
    {
23977
 
      /* get existing text sample */
23978
 
      gsp_sum = NULL;
23979
 
      for (vnp = rp->subtype_list; vnp != NULL; vnp = vnp->next)
23980
 
      {
23981
 
        gsp = CheckForConversionExistingTextInSeqEntry (sep, &cfd, fsp,
23982
 
                                                        SEQFEAT_RNA,
23983
 
                                                        vnp->data.intvalue,
23984
 
                                                        0);
23985
 
        gsp_new = GetSampleAdd (gsp_sum, gsp);
23986
 
        gsp = GetSampleFree (gsp);
23987
 
        gsp_sum = GetSampleFree (gsp_sum);
23988
 
        gsp_sum = gsp_new;
23989
 
      }
23990
 
      cfd.etp = GetExistingTextHandlerInfo (gsp_sum, FALSE);
23991
 
      gsp_sum = GetSampleFree (gsp_sum);
23992
 
      if (cfd.etp != NULL && cfd.etp->existing_text_choice == EXISTING_TEXT_CHOICE_CANCEL)
23993
 
      {
23994
 
        rval = FALSE;
23995
 
      }
 
29218
    if (rp->leave_on_original)
 
29219
    {
 
29220
      cfd.convert_type = CONVERT_TYPE_COPY;
23996
29221
    }
23997
29222
    else
23998
29223
    {
23999
 
      cfd.etp = NULL;
24000
 
    }  
 
29224
      cfd.convert_type = CONVERT_TYPE_MOVE;
 
29225
    }
 
29226
  }
 
29227
  else if (action_choice == AECR_SWAP)
 
29228
  {
 
29229
    cfd.convert_type = CONVERT_TYPE_SWAP;
 
29230
  }
 
29231
  else if (action_choice == AECR_PARSE)
 
29232
  {
 
29233
    cfd.convert_type = CONVERT_TYPE_PARSE;
 
29234
  }
 
29235
  
 
29236
  if (cfd.convert_type == CONVERT_TYPE_MOVE || cfd.convert_type == CONVERT_TYPE_COPY || cfd.convert_type == CONVERT_TYPE_PARSE)
 
29237
  {
 
29238
    /* get existing text sample */
 
29239
    ccd.cfp = &cfd;
 
29240
    ccd.gsp = GetSampleNew();
24001
29241
 
24002
 
    if (rval)
24003
 
    {
24004
 
      for (vnp = rp->subtype_list; vnp != NULL; vnp = vnp->next)
24005
 
      {
24006
 
        OperateOnSeqEntryConstrainedObjects (sep, fsp, 
24007
 
                                             ConvertFeatureFieldCallback, NULL,
24008
 
                                             SEQFEAT_RNA, vnp->data.intvalue, 
24009
 
                                             0, &cfd);
24010
 
      }
 
29242
    for (vnp_rna = rna_list; vnp_rna != NULL; vnp_rna = vnp_rna->next)
 
29243
    {
 
29244
      sfp = vnp_rna->data.ptrvalue;
 
29245
      GetConversionConflictsFeatureCallback (sfp, &ccd, fsp);
 
29246
    }
 
29247
    cfd.etp = GetExistingTextHandlerInfo (ccd.gsp == NULL ? 0 : ccd.gsp->num_found, FALSE);
 
29248
    ccd.gsp = GetSampleFree (ccd.gsp);
 
29249
    if (cfd.etp != NULL && cfd.etp->existing_text_choice == eExistingTextChoiceCancel)
 
29250
    {
 
29251
      rval = FALSE;
24011
29252
    }
24012
29253
  }
24013
29254
  else
24014
29255
  {
24015
 
    avd.field_list = rp->field_list;
24016
 
    avd.etp = NULL;
24017
 
    AddEditApplyDataToApplyValue (action_choice, rp->edit_apply, &avd);
24018
 
     
24019
 
    for (vnp = rp->subtype_list; vnp != NULL; vnp = vnp->next)
 
29256
    cfd.etp = NULL;
 
29257
  }  
 
29258
 
 
29259
  if (rval)
 
29260
  {
 
29261
    for (vnp_rna = rna_list; vnp_rna != NULL; vnp_rna = vnp_rna->next)
24020
29262
    {
24021
 
      if (action_choice == AECR_EDIT)
24022
 
      {
24023
 
        OperateOnSeqEntryConstrainedObjects (sep, fsp, SetRNAFieldString,
24024
 
                                             NULL, SEQFEAT_RNA, vnp->data.intvalue, 0, &avd);  
24025
 
      }
24026
 
      else if (action_choice == AECR_REMOVE)
24027
 
      {
24028
 
        OperateOnSeqEntryConstrainedObjects (sep, fsp, RemoveRNAField,
24029
 
                                             NULL, SEQFEAT_RNA, vnp->data.intvalue, 0, &avd);  
24030
 
      }
 
29263
      sfp = vnp_rna->data.ptrvalue;
 
29264
      ConvertFeatureFieldCallback (sfp, &cfd, fsp);
24031
29265
    }
24032
 
    avd.text_to_replace = MemFree (avd.text_to_replace);
24033
 
    avd.new_text = MemFree (avd.new_text);
24034
29266
  }
24035
29267
 
24036
 
  FilterSetFree (fsp);
24037
29268
  return rval;
24038
 
 
24039
 
}
 
29269
}
 
29270
 
 
29271
 
 
29272
static Boolean RNAQualEditRemoveList 
 
29273
(ValNodePtr    rna_list,
 
29274
 AECRRNAQualPtr  rp,
 
29275
 Int4          action_choice,
 
29276
 FilterSetPtr  fsp)
 
29277
{
 
29278
  SeqFeatPtr       sfp;
 
29279
  ValNodePtr       vnp_rna;
 
29280
  ApplyValueData   avd;
 
29281
  Boolean          rval = TRUE;
 
29282
  
 
29283
  if (rna_list == NULL
 
29284
      || rp == NULL
 
29285
      || (action_choice != AECR_EDIT && action_choice != AECR_REMOVE)
 
29286
      || rp->field_list == NULL)
 
29287
  {
 
29288
    return FALSE;
 
29289
  }
 
29290
 
 
29291
  avd.where_to_replace = EditApplyFindLocation_anywhere;
 
29292
  avd.field_list = rp->field_list;
 
29293
  avd.etp = NULL;
 
29294
  AddEditApplyDataToApplyValue (action_choice, rp->edit_apply, &avd);
 
29295
 
 
29296
  for (vnp_rna = rna_list; vnp_rna != NULL; vnp_rna = vnp_rna->next)
 
29297
  {
 
29298
    sfp = vnp_rna->data.ptrvalue;
 
29299
    if (action_choice == AECR_EDIT)
 
29300
    {
 
29301
      SetRNAFieldString (sfp, &avd, fsp);
 
29302
    }
 
29303
    else if (action_choice == AECR_REMOVE)
 
29304
    {
 
29305
      RemoveRNAField (sfp, &avd, fsp);
 
29306
    }
 
29307
  }
 
29308
    
 
29309
  avd.text_to_replace = MemFree (avd.text_to_replace);
 
29310
  avd.new_text = MemFree (avd.new_text);
 
29311
  return TRUE;
 
29312
}
 
29313
 
 
29314
 
 
29315
 
24040
29316
 
24041
29317
static Boolean AcceptRNAQualApplyEditRemoveConvert (Pointer userdata)
24042
29318
{
24043
29319
  ApplyEditConvertRemovePtr ap;
24044
 
  SimpleAECRPtr             rp = NULL;
 
29320
  AECRRNAQualPtr            rp;
24045
29321
  Int4                      action_choice;
24046
29322
  Boolean                   rval = TRUE;
 
29323
  FilterSetPtr              fsp;
 
29324
  ValNodePtr                rna_list;
 
29325
  SeqEntryPtr               sep;
24047
29326
 
24048
29327
  ap = (ApplyEditConvertRemovePtr) userdata;
24049
29328
  if (ap == NULL)
24062
29341
  {
24063
29342
    action_choice = GetValue (ap->action_popup);
24064
29343
  }
 
29344
 
 
29345
  rp = (AECRRNAQualPtr) DialogToPointer (ap->aecr_pages[action_choice - 1]);
 
29346
  if (rp == NULL) return FALSE;
 
29347
 
 
29348
  fsp = (FilterSetPtr) DialogToPointer (ap->constraints);
 
29349
  sep = GetTopSeqEntryForEntityID (ap->input_entityID);
 
29350
  rna_list = GetRNAFeatureList (sep, fsp, rp->rna_type);
24065
29351
  
24066
29352
  if (action_choice == AECR_APPLY)
24067
29353
  {
24068
 
    rval = AcceptRNAApply (ap);
 
29354
    rval = ApplyToRNAList (rna_list, rp, fsp);
 
29355
  }
 
29356
  else if (action_choice == AECR_CONVERT || action_choice == AECR_SWAP
 
29357
           || action_choice == AECR_PARSE)
 
29358
  {
 
29359
    rval = RNAQualConvertSwapParseList (rna_list, rp, action_choice, fsp);
24069
29360
  }
24070
29361
  else if (action_choice > AECR_APPLY && action_choice <= NUM_AECR)
24071
29362
  {
24072
 
    rp = (SimpleAECRPtr) DialogToPointer (ap->aecr_pages[action_choice - 1]);
24073
 
    rval = AcceptRNAQualEditRemoveConvert (ap, action_choice, rp);
24074
 
    rp = SimpleAECRFree (rp);
 
29363
    rval = RNAQualEditRemoveList (rna_list, rp, action_choice, fsp);
24075
29364
  }
24076
29365
    
24077
29366
  if (rval)
24094
29383
  ApplyEditConvertRemoveCombo (i, first_action_choice, crippled,
24095
29384
                               "RNA Qualifiers",
24096
29385
                               RNAQualListDialog, TRUE, GetRNAQualSample,
24097
 
                               TRUE, FALSE, TRUE, FALSE, "Where feature text",
 
29386
                               TRUE, FALSE, TRUE, FALSE, FALSE, "Where feature text",
24098
29387
                               AcceptRNAQualApplyEditRemoveConvert, NULL, NULL,
24099
29388
                               CheckFeaturesForPresample);
24100
29389
}
24158
29447
{
24159
29448
  ValNodePtr          field_list;
24160
29449
  ValNodePtr          subtype_list;
24161
 
  StringConstraintPtr scp;
 
29450
  StringConstraintXPtr scp;
24162
29451
  Boolean             use_field_list;
24163
29452
} RemoveGBQualData, PNTR RemoveGBQualPtr;
24164
29453
 
24168
29457
  {
24169
29458
    ap->field_list = ValNodeFree (ap->field_list);
24170
29459
    ap->subtype_list = ValNodeFree (ap->subtype_list);
24171
 
    ap->scp = StringConstraintFree (ap->scp);
 
29460
    ap->scp = StringConstraintXFree (ap->scp);
24172
29461
    ap = MemFree (ap);
24173
29462
  }
24174
29463
  return ap;
24336
29625
static void GBQualChangeNotify (GrouP b)
24337
29626
{
24338
29627
  RemoveGBQualDlgPtr dlg;
24339
 
  ValNodePtr         field_list = NULL, subtype_list = NULL;
24340
29628
 
24341
29629
  dlg = (RemoveGBQualDlgPtr) GetObjectExtra (b);
24342
29630
  if (dlg == NULL)
24405
29693
  dlg->field_list = GBQualSelectionDialog (dlg->list_or_txt_grp, FALSE, 
24406
29694
                                                change_notify,
24407
29695
                                                change_userdata);
24408
 
  dlg->qual_name_constraint = StringConstraintDialog (dlg->list_or_txt_grp, "Where qualifier name contains", FALSE);
 
29696
  dlg->qual_name_constraint = StringConstraintDialogX (dlg->list_or_txt_grp, "Where qualifier name contains", FALSE);
24409
29697
  SetValue (dlg->list_or_txt_grp, 1);
24410
29698
  Disable (dlg->qual_name_constraint);
24411
29699
    
24488
29776
  Boolean                   rval = TRUE;
24489
29777
 
24490
29778
  ValNodePtr                field_list = NULL;
24491
 
  ValNodePtr                field_list_to = NULL;
24492
29779
  ValNodePtr                subtype_list = NULL;
24493
 
  Boolean                   leave_on_original = FALSE;
24494
 
  EditApplyPtr              edit_apply = NULL;
24495
 
  FreeValNodeProc           free_field_vn_proc = NULL;
24496
 
  FreeValNodeProc           free_subtype_vn_proc = NULL;
24497
29780
  EditApplyPtr              eap = NULL;
24498
29781
 
24499
29782
 
24515
29798
  {
24516
29799
    return FALSE;
24517
29800
  }
 
29801
 
 
29802
  avd.where_to_replace = EditApplyFindLocation_anywhere;
24518
29803
  
24519
29804
  if (action_choice == AECR_REMOVE)
24520
29805
  {
24569
29854
    cfd.remove_d_str_func = NULL;
24570
29855
    cfd.fsp = fsp;
24571
29856
    cfd.strip_name_from_text = gp->strip_name_from_text;
 
29857
    cfd.remove_parsed = gp->remove_parsed;
24572
29858
    cfd.name_field_func = NULL;
24573
29859
    cfd.text_portion = gp->text_portion;
24574
29860
    
24607
29893
        gsp_sum = GetSampleFree (gsp_sum);
24608
29894
        gsp_sum = gsp_new;
24609
29895
      }
24610
 
      cfd.etp = GetExistingTextHandlerInfo (gsp_sum, FALSE);
 
29896
      cfd.etp = GetExistingTextHandlerInfo (gsp_sum == NULL ? 0 : gsp_sum->num_found, FALSE);
24611
29897
      gsp_sum = GetSampleFree (gsp_sum);
24612
 
      if (cfd.etp != NULL && cfd.etp->existing_text_choice == EXISTING_TEXT_CHOICE_CANCEL)
 
29898
      if (cfd.etp != NULL && cfd.etp->existing_text_choice == eExistingTextChoiceCancel)
24613
29899
      {
24614
29900
        rval = FALSE;
24615
29901
      }
24647
29933
      gsp = GetGBQualExistingText (sep, subtype_list,
24648
29934
                                   avd.field_list,
24649
29935
                                   fsp);
24650
 
      avd.etp = GetExistingTextHandlerInfo (gsp, FALSE);
 
29936
      avd.etp = GetExistingTextHandlerInfo (gsp == NULL ? 0 : gsp->num_found, FALSE);
24651
29937
      gsp = GetSampleFree (gsp);
24652
29938
    
24653
29939
      if (avd.etp != NULL 
24654
 
        && avd.etp->existing_text_choice == EXISTING_TEXT_CHOICE_CANCEL)
 
29940
        && avd.etp->existing_text_choice == eExistingTextChoiceCancel)
24655
29941
      {
24656
29942
        rval = FALSE;
24657
29943
      }
24831
30117
  ApplyEditConvertRemoveCombo (i, first_action_choice, crippled,
24832
30118
                               "Import Qualifiers",
24833
30119
                               GBQualListDialog, FALSE, GetGBQualSample,
24834
 
                               TRUE, FALSE, TRUE, FALSE, "Where feature text",
 
30120
                               TRUE, FALSE, TRUE, FALSE, FALSE, "Where feature text",
24835
30121
                               AcceptGBQualApplyEditRemoveConvert, NULL, NULL,
24836
30122
                               CheckFeaturesForPresample);
24837
30123
}
24872
30158
}
24873
30159
 
24874
30160
 
 
30161
static CharPtr  alltargetsTabs [] = {
 
30162
  "BioSource", "GenBank Qualifiers", "RNA Qualifiers", "CDS-Gene-Prot-mRNA", NULL
 
30163
};
 
30164
 
 
30165
typedef enum 
 
30166
{
 
30167
  eAllTargetsAllActions_BioSource = 0,
 
30168
  eAllTargetsAllActions_GBQual,
 
30169
  eAllTargetsAllActions_RNAQual,
 
30170
  eAllTargetsAllActions_CDSGeneProtmRNA,
 
30171
  eNumAllTargetsAllActions
 
30172
} EAllTargetsAllActions;
 
30173
 
 
30174
typedef struct allactionsalltargetsdlg
 
30175
{
 
30176
  DIALOG_MESSAGE_BLOCK
 
30177
  DialoG                   tbs; /* folder tab for switching between target types */
 
30178
  Int2                     currentPage;
 
30179
  GrouP                    target_pages [eNumAllTargetsAllActions];
 
30180
  DialoG                   aecr_pages [NUM_AECR * eNumAllTargetsAllActions];
 
30181
  PopuP                    action_popup;
 
30182
 
 
30183
  DialoG                   accept_cancel;
 
30184
  DialoG                   constraints;
 
30185
  ButtoN                   clear_constraints_on_action_change;
 
30186
  Nlm_ChangeAECRActionProc change_action;
 
30187
  Int4                     prev_page;
 
30188
  Boolean                  crippled;
 
30189
  Int4                     crippled_action;
 
30190
  Uint2                    entityID;
 
30191
  Nlm_ChangeNotifyProc     change_notify;
 
30192
  Pointer                  change_userdata;
 
30193
} AllActionsAllTargetsDlgData, PNTR AllActionsAllTargetsDlgPtr;
 
30194
 
 
30195
 
 
30196
static void ChangeAllActionsAllTargetsTarget (VoidPtr data, Int2 newval, Int2 oldval)
 
30197
{
 
30198
  AllActionsAllTargetsDlgPtr  dlg;
 
30199
 
 
30200
  dlg = (AllActionsAllTargetsDlgPtr) data;
 
30201
  if (dlg != NULL) {
 
30202
    dlg->currentPage = newval;
 
30203
    SafeHide (dlg->target_pages [oldval]);
 
30204
    SafeShow (dlg->target_pages [newval]);
 
30205
    Update ();
 
30206
    if (dlg->change_notify != NULL) {
 
30207
      (dlg->change_notify) (dlg->change_userdata);
 
30208
    }
 
30209
  }
 
30210
}
 
30211
 
 
30212
static void ChangeAllActionsAllTargetsAction (PopuP p)
 
30213
{
 
30214
  AllActionsAllTargetsDlgPtr  dlg;
 
30215
  Int4                        i;
 
30216
  
 
30217
  dlg = (AllActionsAllTargetsDlgPtr) GetObjectExtra (p);
 
30218
  if (dlg == NULL) return;
 
30219
 
 
30220
  for (i = 0; i < NUM_AECR; i++)
 
30221
  {
 
30222
    Hide (dlg->aecr_pages[(dlg->currentPage * NUM_AECR) + i]);
 
30223
  }
 
30224
  i = GetValue (dlg->action_popup);
 
30225
  if (i > 0 && i <= NUM_AECR)
 
30226
  {
 
30227
    Show (dlg->aecr_pages[(dlg->currentPage * NUM_AECR) + i - 1]);
 
30228
    SendMessageToDialog (dlg->aecr_pages[(dlg->currentPage * NUM_AECR) + i - 1], VIB_MSG_ENTER);
 
30229
  }
 
30230
  
 
30231
}
 
30232
 
 
30233
static DialoG AllActionsAllTargetsDialog (GrouP h, Uint2 entityID, Nlm_ChangeNotifyProc change_notify, Pointer change_userdata)
 
30234
{
 
30235
  AllActionsAllTargetsDlgPtr dlg;
 
30236
  GrouP                      p, g;
 
30237
  Int4                       i;
 
30238
 
 
30239
  dlg = (AllActionsAllTargetsDlgPtr) MemNew (sizeof (AllActionsAllTargetsDlgData));
 
30240
 
 
30241
  p = HiddenGroup (h, -1, 0, NULL);
 
30242
  SetObjectExtra (p, dlg, StdCleanupExtraProc);
 
30243
  SetGroupSpacing (p, 10, 10);
 
30244
  
 
30245
  dlg->dialog = (DialoG) p;
 
30246
  dlg->todialog = NULL;
 
30247
  dlg->fromdialog = NULL;
 
30248
  dlg->dialogmessage = NULL;
 
30249
  dlg->testdialog = NULL;
 
30250
  dlg->change_notify = change_notify;
 
30251
  dlg->change_userdata = change_userdata;
 
30252
  dlg->entityID = entityID;
 
30253
 
 
30254
  dlg->action_popup = PopupList (p, TRUE, ChangeAllActionsAllTargetsAction);
 
30255
  SetObjectExtra (dlg->action_popup, dlg, NULL);
 
30256
  PopupItem (dlg->action_popup, "Apply");
 
30257
  PopupItem (dlg->action_popup, "Edit");
 
30258
  PopupItem (dlg->action_popup, "Convert");
 
30259
  PopupItem (dlg->action_popup, "Swap");
 
30260
  PopupItem (dlg->action_popup, "Parse");
 
30261
  PopupItem (dlg->action_popup, "Remove");
 
30262
  SetValue (dlg->action_popup, 1);
 
30263
 
 
30264
 
 
30265
  dlg->tbs = CreateFolderTabs (p, alltargetsTabs, eAllTargetsAllActions_BioSource,
 
30266
                               0, 0, SYSTEM_FOLDER_TAB,
 
30267
                               ChangeAllActionsAllTargetsTarget, (Pointer) dlg);
 
30268
 
 
30269
  g = HiddenGroup (p, 0, 0, NULL);
 
30270
  dlg->target_pages[eAllTargetsAllActions_BioSource] = HiddenGroup (g, 0, 0, NULL);
 
30271
  for (i = 0; i < NUM_AECR; i++)
 
30272
  {
 
30273
    dlg->aecr_pages[(eAllTargetsAllActions_BioSource * NUM_AECR) + i] 
 
30274
               = SourceQualAECRDialog (dlg->target_pages[eAllTargetsAllActions_BioSource],
 
30275
                                       i + 1, change_notify, change_userdata, entityID);
 
30276
    Hide (dlg->aecr_pages[(eAllTargetsAllActions_BioSource * NUM_AECR) + i]);
 
30277
  }
 
30278
  
 
30279
  dlg->target_pages[eAllTargetsAllActions_GBQual] = HiddenGroup (g, 0, 0, NULL);
 
30280
  for (i = 0; i < NUM_AECR; i++)
 
30281
  {
 
30282
    dlg->aecr_pages[(eAllTargetsAllActions_GBQual * NUM_AECR) + i] 
 
30283
               = GBQualListDialog (dlg->target_pages[eAllTargetsAllActions_GBQual],
 
30284
                                       i + 1, change_notify, change_userdata, entityID);
 
30285
    Hide (dlg->aecr_pages[(eAllTargetsAllActions_GBQual * NUM_AECR) + i]);
 
30286
  }
 
30287
 
 
30288
  dlg->target_pages[eAllTargetsAllActions_RNAQual] = HiddenGroup (g, 0, 0, NULL);
 
30289
  for (i = 0; i < NUM_AECR; i++)
 
30290
  {
 
30291
    dlg->aecr_pages[(eAllTargetsAllActions_RNAQual * NUM_AECR) + i] 
 
30292
               = RNAQualListDialog (dlg->target_pages[eAllTargetsAllActions_RNAQual],
 
30293
                                       i + 1, change_notify, change_userdata, entityID);
 
30294
    Hide (dlg->aecr_pages[(eAllTargetsAllActions_RNAQual * NUM_AECR) + i]);
 
30295
  }
 
30296
 
 
30297
  dlg->target_pages[eAllTargetsAllActions_CDSGeneProtmRNA] = HiddenGroup (g, 0, 0, NULL);
 
30298
  for (i = 0; i < NUM_AECR; i++)
 
30299
  {
 
30300
    dlg->aecr_pages[(eAllTargetsAllActions_CDSGeneProtmRNA * NUM_AECR) + i] 
 
30301
               = CDSGeneProtAECRDialog (dlg->target_pages[eAllTargetsAllActions_CDSGeneProtmRNA],
 
30302
                                       i + 1, change_notify, change_userdata, entityID);
 
30303
    Hide (dlg->aecr_pages[(eAllTargetsAllActions_CDSGeneProtmRNA * NUM_AECR) + i]);
 
30304
  }
 
30305
 
 
30306
  AlignObjects (ALIGN_CENTER, (HANDLE) dlg->tbs, (HANDLE) g, NULL);
 
30307
 
 
30308
  return (DialoG) p;
 
30309
}
 
30310
 
 
30311
 
 
30312
extern void AllActionsAllTargets (IteM i)
 
30313
{
 
30314
 
 
30315
}
 
30316
 
24875
30317
typedef struct locustagtooldlocustag 
24876
30318
{
24877
30319
  FORM_MESSAGE_BLOCK
25003
30445
  h = HiddenGroup (w, -1, 0, NULL);
25004
30446
  SetGroupSpacing (h, 10, 10);
25005
30447
  
25006
 
  mp->constraints = FilterGroup (h, TRUE, FALSE, TRUE, FALSE, "Where feature text"); 
 
30448
  mp->constraints = FilterGroup (h, TRUE, FALSE, TRUE, FALSE, FALSE, "Where feature text"); 
25007
30449
  mp->accept_cancel = AcceptCancelDialog (h, LocusTagToOldLocusTagAction, NULL, 
25008
30450
                                          LocusTagToOldLocusTagActionClear,
25009
30451
                                          LocusTagToOldLocusTagActionClearText,
25212
30654
  
25213
30655
  Int2                action_choice;
25214
30656
  Boolean             cover_sequence;
25215
 
  StringConstraintPtr string_constraint;
 
30657
  StringConstraintXPtr string_constraint;
25216
30658
  LogInfoPtr          lip;
25217
30659
  
25218
30660
  /* for string constraint */
25256
30698
      && !DoesObjectMatchStringConstraint (ccp->omtp, ccp->aip, sfp, &(ccp->ohsd)))
25257
30699
  {
25258
30700
    sfp = SeqMgrGetDesiredFeature (ccp->input_entityID, NULL, 0, 0, sfp, &fcontext);
25259
 
    if (sfp == NULL || !DoesStringMatchConstraint (fcontext.label, ccp->ohsd.scp))
 
30701
    if (sfp == NULL || !DoesStringMatchConstraintX (fcontext.label, ccp->ohsd.scp))
25260
30702
    {
25261
30703
      return;
25262
30704
    }
25499
30941
  
25500
30942
  CloseLog (ccp->lip);
25501
30943
  FreeLog (ccp->lip);  
25502
 
  ccp->string_constraint = StringConstraintFree (ccp->string_constraint);
 
30944
  ccp->string_constraint = StringConstraintXFree (ccp->string_constraint);
25503
30945
  Remove (ccp->form);
25504
30946
  DeleteMarkedObjects (ccp->input_entityID, 0, NULL);
25505
30947
  ObjMgrSetDirtyFlag (ccp->input_entityID, TRUE);
25587
31029
  SetValue (ccp->prod_name_choice_grp, 1);
25588
31030
  Disable (ccp->prod_name_txt);
25589
31031
  
25590
 
  ccp->string_constraint_dlg = StringConstraintDialog (ccp->new_cds_grp, "Where CDS field", TRUE);
 
31032
  ccp->string_constraint_dlg = StringConstraintDialogX (ccp->new_cds_grp, "Where CDS field", TRUE);
25591
31033
  Disable (ccp->new_cds_grp);
25592
31034
  
25593
31035
  AlignObjects (ALIGN_CENTER, (HANDLE) ccp->cover_sequence_btn,
25780
31222
  p = StaticPrompt (g, "Move features to protein of type", 0, dialogTextHeight, systemFont, 'l');
25781
31223
 
25782
31224
  mtpp->feature_selection = FeatureSelectionDialogEx (g, TRUE, sep, NULL, NULL);
25783
 
  mtpp->constraints = FilterGroup (g, TRUE, FALSE, FALSE, FALSE, "Where feature text");
 
31225
  mtpp->constraints = FilterGroup (g, TRUE, FALSE, FALSE, FALSE, FALSE, "Where feature text");
25784
31226
  AlignObjects (ALIGN_CENTER, (HANDLE) p, (HANDLE) mtpp->feature_selection, (HANDLE) mtpp->constraints, NULL);
25785
31227
 
25786
31228
  c = HiddenGroup (w, 2, 0, NULL);
25793
31235
  Select (w);
25794
31236
  Update ();
25795
31237
}
 
31238
 
 
31239
 
 
31240
typedef struct uniquevaluecollection {
 
31241
  ValNodePtr               requested_field;
 
31242
  GetFeatureFieldString    fieldstring_func;
 
31243
  GetDescriptorFieldString descrstring_func;
 
31244
  FreeValNodeProc          free_vn_proc;
 
31245
  CopyValNodeDataProc      copy_vn_proc;
 
31246
  ValNodePtr               value_lists;
 
31247
} UniqueValueCollectionData, PNTR UniqueValueCollectionPtr;
 
31248
 
 
31249
 
 
31250
static ClickableItemPtr FindExistingCategory (CharPtr description, ValNodePtr category_list)
 
31251
{
 
31252
  ClickableItemPtr cip;
 
31253
 
 
31254
  while (category_list != NULL) {
 
31255
    cip = (ClickableItemPtr) category_list->data.ptrvalue;
 
31256
    if (cip != NULL && 
 
31257
        (StringCmp (description, cip->description) == 0
 
31258
         || (StringHasNoText (description) && StringHasNoText (cip->description)))) {
 
31259
      return cip;
 
31260
    }
 
31261
    category_list = category_list->next;
 
31262
  }
 
31263
  return NULL;
 
31264
}
 
31265
 
 
31266
 
 
31267
static ValNodePtr DataInValNodeList (ValNodePtr list, Uint1 choice, Pointer ptrvalue)
 
31268
{
 
31269
  while (list != NULL) {
 
31270
    if (choice == list->choice && ptrvalue == list->data.ptrvalue) {
 
31271
      return list;
 
31272
    }
 
31273
    list = list->next;
 
31274
  }
 
31275
  return NULL;
 
31276
}
 
31277
 
 
31278
 
 
31279
static void CombineClickableItemLists (ValNodePtr PNTR list1, ValNodePtr list2)
 
31280
{
 
31281
  ValNodePtr add_vnp, prev_vnp = NULL, next_vnp;
 
31282
 
 
31283
  if (*list1 == NULL) {
 
31284
    *list1 = list2;
 
31285
    return;
 
31286
  } else if (list2 == NULL) {
 
31287
    return;
 
31288
  }
 
31289
 
 
31290
  add_vnp = list2;
 
31291
  while (add_vnp != NULL) {
 
31292
    next_vnp = add_vnp->next;
 
31293
    if (DataInValNodeList (*list1, add_vnp->choice, add_vnp->data.ptrvalue)) {
 
31294
      if (prev_vnp == NULL) {
 
31295
        list2 = next_vnp;
 
31296
      } else {
 
31297
        prev_vnp->next = next_vnp;
 
31298
      }
 
31299
      add_vnp->next = NULL;
 
31300
      ValNodeFree (add_vnp);
 
31301
    } else {
 
31302
      prev_vnp = add_vnp;
 
31303
    }
 
31304
    add_vnp = next_vnp;
 
31305
  }
 
31306
  ValNodeLink (list1, list2); 
 
31307
}
 
31308
 
 
31309
 
 
31310
static void CombineClickableLists (ValNodePtr PNTR list1, ValNodePtr list2)
 
31311
{
 
31312
  ClickableItemPtr cip1, cip2;
 
31313
  ValNodePtr vnp;
 
31314
  for (vnp = list2; vnp != NULL; vnp = vnp->next) {
 
31315
    cip2 = vnp->data.ptrvalue;
 
31316
    if (cip2 != NULL) {
 
31317
      cip1 = FindExistingCategory (cip2->description, *list1);
 
31318
      if (cip1 == NULL) {
 
31319
        ValNodeAddPointer (list1, 0, cip2);
 
31320
        vnp->data.ptrvalue = NULL;
 
31321
      } else {
 
31322
        CombineClickableItemLists (&(cip1->item_list), cip2->item_list);
 
31323
        cip2->item_list = NULL;
 
31324
      }
 
31325
    }
 
31326
  }
 
31327
  list2 = FreeClickableList (list2);
 
31328
}
 
31329
 
 
31330
 
 
31331
static void GetUniqueValuesFeatureCallback (SeqFeatPtr sfp, Pointer userdata, FilterSetPtr fsp)
 
31332
{
 
31333
  UniqueValueCollectionPtr uvcp;
 
31334
  CharPtr      str;
 
31335
  ValNodePtr   check_vnp;
 
31336
  ClickableItemPtr cip;
 
31337
  
 
31338
  if (sfp == NULL || userdata == NULL)
 
31339
  {
 
31340
    return;
 
31341
  }
 
31342
  
 
31343
  uvcp = (UniqueValueCollectionPtr) userdata;
 
31344
  if (uvcp->fieldstring_func == NULL)
 
31345
  {
 
31346
    return;
 
31347
  }
 
31348
  
 
31349
  str = uvcp->fieldstring_func (sfp, uvcp->requested_field, NULL);
 
31350
  cip = FindExistingCategory (str, uvcp->value_lists);
 
31351
  if (cip == NULL) {
 
31352
    cip = (ClickableItemPtr) MemNew (sizeof (ClickableItemData));
 
31353
    MemSet (cip, 0, sizeof (ClickableItemData));
 
31354
    cip->description = str;
 
31355
    ValNodeAddPointer (&cip->item_list, OBJ_SEQFEAT, sfp);
 
31356
    ValNodeAddPointer (&(uvcp->value_lists), 0, cip);
 
31357
  } else {
 
31358
    str = MemFree (str);
 
31359
    /* make sure feature isn't already in the list */
 
31360
    for (check_vnp = cip->item_list; check_vnp != NULL; check_vnp = check_vnp->next) {
 
31361
      if (check_vnp->choice == OBJ_SEQFEAT && sfp == check_vnp->data.ptrvalue) break;
 
31362
    }
 
31363
    if (check_vnp == NULL) {
 
31364
      ValNodeAddPointer (&cip->item_list, OBJ_SEQFEAT, sfp);
 
31365
    }
 
31366
  }
 
31367
}
 
31368
 
 
31369
static void GetUniqueValuesDescriptorCallback (SeqDescrPtr sdp, Pointer userdata, FilterSetPtr fsp)
 
31370
{
 
31371
  UniqueValueCollectionPtr uvcp;
 
31372
  ClickableItemPtr         cip;
 
31373
  CharPtr      str;
 
31374
  ValNodePtr   check_vnp;
 
31375
  
 
31376
  if (sdp == NULL || userdata == NULL)
 
31377
  {
 
31378
    return;
 
31379
  }
 
31380
  
 
31381
  uvcp = (UniqueValueCollectionPtr) userdata;
 
31382
  if (uvcp->descrstring_func == NULL)
 
31383
  {
 
31384
    return;
 
31385
  }
 
31386
 
 
31387
  str = uvcp->descrstring_func (sdp, uvcp->requested_field, NULL);
 
31388
 
 
31389
  cip = FindExistingCategory (str, uvcp->value_lists);
 
31390
 
 
31391
  if (cip == NULL) {
 
31392
    cip = (ClickableItemPtr) MemNew (sizeof (ClickableItemData));
 
31393
    MemSet (cip, 0, sizeof (ClickableItemData));
 
31394
    cip->description = str;
 
31395
    ValNodeAddPointer (&cip->item_list, OBJ_SEQDESC, sdp);
 
31396
    ValNodeAddPointer (&(uvcp->value_lists), 0, cip);
 
31397
  } else {
 
31398
    str = MemFree (str);
 
31399
    /* make sure feature isn't already in the list */
 
31400
    for (check_vnp = cip->item_list; check_vnp != NULL; check_vnp = check_vnp->next) {
 
31401
      if (check_vnp->choice == OBJ_SEQDESC && sdp == check_vnp->data.ptrvalue) break;
 
31402
    }
 
31403
    if (check_vnp == NULL) {
 
31404
      ValNodeAddPointer (&cip->item_list, OBJ_SEQDESC, sdp);
 
31405
    }
 
31406
  }
 
31407
}
 
31408
 
 
31409
 
 
31410
static ValNodePtr CheckForUniqueValuesInSeqEntry
 
31411
(SeqEntryPtr              sep,
 
31412
 ValNodePtr               requested_field,
 
31413
 GetFeatureFieldString    fieldstring_func,
 
31414
 GetDescriptorFieldString descrstring_func,
 
31415
 FreeValNodeProc          free_vn_proc,
 
31416
 CopyValNodeDataProc      copy_vn_proc,
 
31417
 FilterSetPtr             fsp,
 
31418
 Uint1                    seqfeat_choice,
 
31419
 Uint1                    featdef_choice,
 
31420
 Uint1                    descr_choice)
 
31421
{
 
31422
  UniqueValueCollectionData uvcd;
 
31423
  
 
31424
  uvcd.fieldstring_func = fieldstring_func;
 
31425
  uvcd.descrstring_func = descrstring_func;
 
31426
  uvcd.free_vn_proc = free_vn_proc;
 
31427
  uvcd.copy_vn_proc = copy_vn_proc;
 
31428
  uvcd.requested_field = (copy_vn_proc) (requested_field);
 
31429
  uvcd.value_lists = NULL;
 
31430
  OperateOnSeqEntryConstrainedObjects (sep, fsp, GetUniqueValuesFeatureCallback, 
 
31431
                                         GetUniqueValuesDescriptorCallback,
 
31432
                                         seqfeat_choice, featdef_choice,
 
31433
                                         descr_choice, &uvcd);
 
31434
  return uvcd.value_lists;  
 
31435
}
 
31436
 
 
31437
 
 
31438
static ValNodePtr
 
31439
GetUniqueValueListForSeqEntry
 
31440
(SeqEntryPtr   sep,
 
31441
 Uint2         entityID, 
 
31442
 ParseFieldPtr dst_field_data,
 
31443
 FilterSetPtr  fsp)
 
31444
{
 
31445
  ValNodePtr   unique_values = NULL;
 
31446
  ValNodePtr   requested_field = NULL, vnp;
 
31447
  SeqEntryPtr  orig_sep;
 
31448
 
 
31449
  if (sep == NULL || dst_field_data == NULL)
 
31450
  {
 
31451
    return NULL;
 
31452
  }
 
31453
  
 
31454
  switch (dst_field_data->parse_field_type)
 
31455
  {
 
31456
    case PARSE_FIELD_SOURCE_QUAL :
 
31457
      unique_values = CheckForUniqueValuesInSeqEntry (sep, 
 
31458
                                            dst_field_data->feature_field, 
 
31459
                                            GetSourceQualFeatureString,
 
31460
                                            GetSourceQualDescrString,
 
31461
                                            ValNodeSimpleDataFree,
 
31462
                                            SourceQualValNodeDataCopy,
 
31463
                                            fsp,
 
31464
                                            SEQFEAT_BIOSRC, 0,
 
31465
                                            Seq_descr_source);
 
31466
      break;
 
31467
    case PARSE_FIELD_DEFLINE:
 
31468
      requested_field = ValNodeNew (NULL);
 
31469
      requested_field->data.intvalue = Seq_descr_title;
 
31470
      unique_values = CheckForUniqueValuesInSeqEntry (sep, requested_field, 
 
31471
                                            NULL,
 
31472
                                            GetStringFromStringDescriptor,
 
31473
                                            NULL, IntValNodeCopy,
 
31474
                                            fsp, 0, 0, Seq_descr_title);
 
31475
      requested_field = ValNodeFree (requested_field);
 
31476
      break;
 
31477
    case PARSE_FIELD_BIOSRC_STRING:
 
31478
      unique_values = CheckForUniqueValuesInSeqEntry (sep, 
 
31479
                                            dst_field_data->feature_field, 
 
31480
                                            GetSourceFeatureString,
 
31481
                                            GetSourceDescriptorString,
 
31482
                                            NULL, IntValNodeCopy,
 
31483
                                            fsp,
 
31484
                                            SEQFEAT_BIOSRC, 0,
 
31485
                                            Seq_descr_source);
 
31486
      break;
 
31487
    case PARSE_FIELD_DBXREF:
 
31488
      unique_values = CheckForUniqueValuesInSeqEntry (sep, dst_field_data->feature_field,
 
31489
                                            GetBioSourceFeatureDbxrefString,
 
31490
                                            GetBioSourceDescriptorDbxrefString,
 
31491
                                            ValNodeSimpleDataFree,
 
31492
                                            ValNodeStringCopy,
 
31493
                                            fsp,
 
31494
                                            SEQFEAT_BIOSRC, 0, Seq_descr_source);
 
31495
      break;
 
31496
    case PARSE_FIELD_GENE_FIELD:
 
31497
      unique_values = CheckForUniqueValuesInSeqEntry (sep, 
 
31498
                                            dst_field_data->feature_field, 
 
31499
                                            GetGeneFieldString,
 
31500
                                            NULL,
 
31501
                                            NULL, IntValNodeCopy,
 
31502
                                            fsp,
 
31503
                                            SEQFEAT_GENE, 0, 0);
 
31504
      break;
 
31505
    case PARSE_FIELD_RNA_FIELD:
 
31506
      unique_values = CheckForUniqueValuesInSeqEntry (sep, 
 
31507
                                            dst_field_data->feature_field, 
 
31508
                                            GetRNAFieldString,
 
31509
                                            NULL,
 
31510
                                            NULL, IntValNodeCopy,
 
31511
                                            fsp,
 
31512
                                            SEQFEAT_RNA, 
 
31513
                                            dst_field_data->feature_subtype == NULL ? 0 : dst_field_data->feature_subtype->data.intvalue,
 
31514
                                            0);
 
31515
      break;
 
31516
    case PARSE_FIELD_CDS_COMMENT:
 
31517
      unique_values = CheckForUniqueValuesInSeqEntry (sep, 
 
31518
                                            NULL, 
 
31519
                                            GetCDSComment,
 
31520
                                            NULL,
 
31521
                                            NULL, IntValNodeCopy,
 
31522
                                            fsp,
 
31523
                                            SEQFEAT_CDREGION, FEATDEF_CDS, 0);
 
31524
      break;
 
31525
    case PARSE_FIELD_COMMENT_DESC:
 
31526
      requested_field = ValNodeNew (NULL);
 
31527
      requested_field->data.intvalue = Seq_descr_comment;
 
31528
 
 
31529
      unique_values = CheckForUniqueValuesInSeqEntry (sep, requested_field, 
 
31530
                                            NULL,
 
31531
                                            GetStringFromStringDescriptor,
 
31532
                                            NULL, IntValNodeCopy,
 
31533
                                            fsp, 0, 0, Seq_descr_comment);
 
31534
      requested_field = ValNodeFree (requested_field);
 
31535
      break;
 
31536
    case PARSE_FIELD_PROTEIN_FIELD:
 
31537
      unique_values = CheckForUniqueValuesInSeqEntry (sep, 
 
31538
                                            dst_field_data->feature_field, 
 
31539
                                            GetProteinFieldString,
 
31540
                                            NULL,
 
31541
                                            NULL, IntValNodeCopy,
 
31542
                                            fsp,
 
31543
                                            SEQFEAT_PROT, 0, 0);
 
31544
      break;
 
31545
    case PARSE_FIELD_IMPORT_QUAL:
 
31546
      orig_sep = sep;
 
31547
      for (vnp = dst_field_data->feature_subtype; vnp != NULL; vnp = vnp->next)
 
31548
      {
 
31549
        CombineClickableLists (&unique_values, 
 
31550
                               CheckForUniqueValuesInSeqEntry (sep, 
 
31551
                                                               dst_field_data->feature_field, 
 
31552
                                                               GetGBQualString,
 
31553
                                                               NULL,
 
31554
                                                               NULL, IntValNodeCopy,
 
31555
                                                               fsp, 0, vnp->choice, 0));
 
31556
        /* if we are also looking at features other than mat_peptides, use
 
31557
         * original SeqEntry */
 
31558
        sep = orig_sep;
 
31559
      }
 
31560
      break;
 
31561
    case PARSE_FIELD_FEATURE_NOTE:
 
31562
      orig_sep = sep;      
 
31563
      for (vnp = dst_field_data->feature_field; vnp != NULL; vnp = vnp->next)
 
31564
      {
 
31565
        CombineClickableLists (&unique_values, 
 
31566
                               CheckForUniqueValuesInSeqEntry (sep, vnp, 
 
31567
                                                               GetFeatureNote,
 
31568
                                                               NULL,
 
31569
                                                               ValNodeSimpleDataFree,
 
31570
                                                               ValNodeStringCopy,
 
31571
                                                               fsp, 0, vnp->choice, 0));
 
31572
        /* if we are also looking at features other than mat_peptides, use
 
31573
         * original SeqEntry */
 
31574
        sep = orig_sep;
 
31575
      }
 
31576
      break;
 
31577
  }
 
31578
  return unique_values;  
 
31579
}
 
31580
 
 
31581
 
 
31582
static SeqEntryPtr GetBestSeqEntryForItem (ValNodePtr vnp)
 
31583
{
 
31584
  SeqFeatPtr       sfp;
 
31585
  SeqDescrPtr      sdp;
 
31586
  ObjValNodePtr    ovp;
 
31587
  SeqEntryPtr      sep = NULL;
 
31588
  BioseqPtr        bsp;
 
31589
 
 
31590
  if (vnp == NULL || vnp->data.ptrvalue == NULL) return NULL;
 
31591
 
 
31592
  if (vnp->choice == OBJ_SEQFEAT) {
 
31593
    sfp = vnp->data.ptrvalue;
 
31594
    sep = GetBestTopParentForData (sfp->idx.entityID, BioseqFindFromSeqLoc (sfp->location));
 
31595
  } else if (vnp->choice == OBJ_SEQDESC) {
 
31596
    sdp = vnp->data.ptrvalue;
 
31597
    if (sdp->extended != 0) {
 
31598
      ovp = (ObjValNodePtr) sdp;
 
31599
      if (ovp->idx.parenttype == OBJ_BIOSEQSET) {
 
31600
        sep = SeqMgrGetSeqEntryForData (ovp->idx.parentptr);
 
31601
      } else if (ovp->idx.parenttype == OBJ_BIOSEQ) {
 
31602
        sep = GetBestTopParentForData (ovp->idx.entityID, ovp->idx.parentptr);
 
31603
      }
 
31604
    }
 
31605
  } else if (vnp->choice == OBJ_BIOSEQ) {
 
31606
    bsp = (BioseqPtr) vnp->data.ptrvalue;
 
31607
    sep = GetBestTopParentForData (bsp->idx.entityID, bsp);
 
31608
  } else if (vnp->choice == OBJ_SEQENTRY) {
 
31609
    sep = vnp->data.ptrvalue;
 
31610
  }
 
31611
  return sep;
 
31612
}
 
31613
 
 
31614
static ValNodePtr GetSeqEntryListForItem (ValNodePtr vnp)
 
31615
{
 
31616
  SeqFeatPtr       sfp;
 
31617
  SeqDescrPtr      sdp;
 
31618
  ObjValNodePtr    ovp;
 
31619
  SeqEntryPtr      sep = NULL;
 
31620
  BioseqPtr        bsp;
 
31621
  BioseqSetPtr     bssp;
 
31622
  ValNodePtr       sep_list = NULL;
 
31623
 
 
31624
  if (vnp == NULL || vnp->data.ptrvalue == NULL) return NULL;
 
31625
 
 
31626
  if (vnp->choice == OBJ_SEQFEAT) {
 
31627
    sfp = vnp->data.ptrvalue;
 
31628
    sep = GetBestTopParentForData (sfp->idx.entityID, BioseqFindFromSeqLoc (sfp->location));
 
31629
    ValNodeAddPointer (&sep_list, OBJ_SEQENTRY, sep);
 
31630
  } else if (vnp->choice == OBJ_SEQDESC) {
 
31631
    sdp = vnp->data.ptrvalue;
 
31632
    if (sdp->extended != 0) {
 
31633
      ovp = (ObjValNodePtr) sdp;
 
31634
      if (ovp->idx.parenttype == OBJ_BIOSEQSET) {
 
31635
        bssp = (BioseqSetPtr) ovp->idx.parentptr;
 
31636
        if (bssp != NULL) {
 
31637
          /* nuc_prot sets, segsets, and members of parts should travel together */
 
31638
          if (bssp->_class == BioseqseqSet_class_nuc_prot) {
 
31639
            sep = SeqMgrGetSeqEntryForData (bssp);
 
31640
            if (sep != NULL) {
 
31641
              ValNodeAddPointer (&sep_list, OBJ_SEQENTRY, sep);
 
31642
            }
 
31643
          } else if (bssp->_class == BioseqseqSet_class_segset
 
31644
                     || bssp->_class == BioseqseqSet_class_parts) {
 
31645
            sep = bssp->seq_set;
 
31646
            if (sep != NULL && IS_Bioseq (sep)) {
 
31647
              bsp = sep->data.ptrvalue;
 
31648
              sep = GetBestTopParentForData (bsp->idx.entityID, bsp);
 
31649
              if (sep != NULL) {
 
31650
                ValNodeAddPointer (&sep_list, OBJ_SEQENTRY, sep);
 
31651
              }
 
31652
            }
 
31653
          } else {            
 
31654
            sep = bssp->seq_set;
 
31655
            while (sep != NULL) {
 
31656
              ValNodeAddPointer (&sep_list, OBJ_SEQENTRY, sep);
 
31657
              sep = sep->next;
 
31658
            }
 
31659
          }
 
31660
        }
 
31661
      } else if (ovp->idx.parenttype == OBJ_BIOSEQ) {
 
31662
        sep = GetBestTopParentForData (ovp->idx.entityID, ovp->idx.parentptr);
 
31663
        if (sep != NULL) {
 
31664
          ValNodeAddPointer (&sep_list, OBJ_SEQENTRY, sep);
 
31665
        }
 
31666
      }
 
31667
    }
 
31668
  } else if (vnp->choice == OBJ_BIOSEQ) {
 
31669
    bsp = (BioseqPtr) vnp->data.ptrvalue;
 
31670
    sep = GetBestTopParentForData (bsp->idx.entityID, bsp);
 
31671
  } else if (vnp->choice == OBJ_SEQENTRY) {
 
31672
    sep = vnp->data.ptrvalue;
 
31673
  }
 
31674
  return sep_list;  
 
31675
}
 
31676
 
 
31677
 
 
31678
static Boolean RemoveItemAndCategory (ClickableItemPtr cip, Uint1 choice, Pointer ptrvalue)
 
31679
{
 
31680
  ValNodePtr vnp, prev = NULL;
 
31681
  Boolean    found = FALSE;
 
31682
  CharPtr    description = NULL;
 
31683
  ClickableItemPtr subcat;
 
31684
 
 
31685
  vnp = cip->item_list;
 
31686
  while (vnp != NULL) {
 
31687
    if (vnp->choice == choice && vnp->data.ptrvalue == ptrvalue) {
 
31688
      found = TRUE;
 
31689
      if (prev == NULL) {
 
31690
        cip->item_list = vnp->next;
 
31691
      } else {
 
31692
        prev->next = vnp->next;
 
31693
      }
 
31694
      vnp->next = NULL;
 
31695
      description = GetDiscrepancyItemText (vnp);
 
31696
      vnp = ValNodeFree (vnp);
 
31697
    } else {
 
31698
      prev = vnp;
 
31699
      vnp = vnp->next;
 
31700
    }
 
31701
  }
 
31702
  if (found) {
 
31703
    /* also remove subcategory */
 
31704
    prev = NULL;
 
31705
    vnp = cip->subcategories;
 
31706
    while (vnp != NULL) {
 
31707
      subcat = (ClickableItemPtr) vnp->data.ptrvalue;
 
31708
      if (subcat != NULL && StringCmp (subcat->description, description) == 0) {
 
31709
        if (prev == NULL) {
 
31710
          cip->subcategories = vnp->next;
 
31711
        } else {
 
31712
          prev->next = vnp->next;
 
31713
        }
 
31714
        vnp->next = NULL;
 
31715
        vnp = FreeClickableList (vnp);
 
31716
      } else {
 
31717
        prev = vnp;
 
31718
        vnp = vnp->next;
 
31719
      }
 
31720
    }
 
31721
  }
 
31722
  return found;
 
31723
}
 
31724
 
 
31725
static ValNodePtr RearrangeForSeqEntriesInMultipleCategories (ValNodePtr value_lists)
 
31726
{
 
31727
  ClickableItemPtr cip1, cip2, existing_cat;
 
31728
  ValNodePtr       vnp, check_vnp, last_vnp, vnp_item1, prev, vnp_next;
 
31729
  Boolean          found;
 
31730
  CharPtr          new_description;
 
31731
 
 
31732
  /* now check for SeqEntries that appear in multiple lists */
 
31733
  for (vnp = value_lists; vnp != NULL && vnp->next != NULL; vnp = vnp->next) {
 
31734
    if (vnp->data.ptrvalue == NULL) continue;
 
31735
    last_vnp = vnp->next;
 
31736
    while (last_vnp->next != NULL) {
 
31737
      last_vnp = last_vnp->next;
 
31738
    }
 
31739
    cip1 = (ClickableItemPtr) vnp->data.ptrvalue;
 
31740
    for (vnp_item1 = cip1->item_list; 
 
31741
         vnp_item1 != NULL;
 
31742
         vnp_item1 = vnp_next) {
 
31743
      vnp_next = vnp_item1->next;
 
31744
      found = FALSE;
 
31745
      if (vnp_item1->data.ptrvalue != NULL && vnp_item1->choice == OBJ_SEQENTRY) {
 
31746
        check_vnp = vnp->next;
 
31747
        while (check_vnp != NULL && !found) {
 
31748
          if (check_vnp->data.ptrvalue != NULL) {
 
31749
            cip2 = check_vnp->data.ptrvalue;
 
31750
            found = RemoveItemAndCategory (cip2, vnp_item1->choice, vnp_item1->data.ptrvalue);
 
31751
          } 
 
31752
          if (!found) {
 
31753
            if (check_vnp == last_vnp) {
 
31754
              check_vnp = NULL;
 
31755
            } else {
 
31756
              check_vnp = check_vnp->next;
 
31757
            }
 
31758
          }
 
31759
        }
 
31760
      }
 
31761
      if (found) {
 
31762
        /* need to take this SeqEntry out of both lists, put in new category */
 
31763
        new_description = (CharPtr) MemNew (sizeof (Char) * (StringLen (cip1->description)
 
31764
                                                             + StringLen (cip2->description) + 6));
 
31765
        if (StringCmp (cip1->description, cip2->description) < 0) {
 
31766
          sprintf (new_description, "%s AND %s", cip1->description, cip2->description);
 
31767
        } else {
 
31768
          sprintf (new_description, "%s AND %s", cip2->description, cip1->description);
 
31769
        }
 
31770
        existing_cat = FindExistingCategory (new_description, check_vnp->next);
 
31771
        if (existing_cat == NULL) {
 
31772
          /* make new category, add to end of list */
 
31773
          existing_cat = (ClickableItemPtr) MemNew (sizeof (ClickableItemData));
 
31774
          MemSet (existing_cat, 0, sizeof (ClickableItemData));
 
31775
          existing_cat->description = new_description;
 
31776
          ValNodeAddPointer (&value_lists, 0, existing_cat);
 
31777
        } else {
 
31778
          new_description = MemFree (new_description);
 
31779
        }
 
31780
        /* don't add item twice */
 
31781
        if (!DataInValNodeList (existing_cat->item_list, vnp_item1->choice, vnp_item1->data.ptrvalue)) {
 
31782
          ValNodeAddPointer (&(existing_cat->item_list), vnp_item1->choice, vnp_item1->data.ptrvalue);
 
31783
        }
 
31784
        /* remove from cip1 */
 
31785
        RemoveItemAndCategory (cip1, vnp_item1->choice, vnp_item1->data.ptrvalue);
 
31786
      }  
 
31787
    }   
 
31788
  }
 
31789
 
 
31790
  /* remove empty categories */
 
31791
  for (vnp = value_lists, prev = NULL; vnp != NULL; vnp = vnp_next) {
 
31792
    vnp_next = vnp->next;
 
31793
    cip1 = (ClickableItemPtr) vnp->data.ptrvalue;
 
31794
    if (cip1 == NULL || cip1->item_list == NULL) {
 
31795
      if (prev == NULL) {
 
31796
        value_lists = vnp->next;
 
31797
      } else {
 
31798
        prev->next = vnp->next;
 
31799
      }
 
31800
      vnp->next = NULL;
 
31801
      vnp = FreeClickableList (vnp);
 
31802
    } else {
 
31803
      prev = vnp;
 
31804
    }
 
31805
  }
 
31806
  return value_lists;
 
31807
}
 
31808
 
 
31809
 
 
31810
static ValNodePtr ChangeUniqueValueListsToSeqEntryLists (ValNodePtr value_lists)
 
31811
{
 
31812
  ValNodePtr vnp, vnp_item, new_item_list, new_vnp, sep_list, sep_vnp;
 
31813
  ClickableItemPtr cip, subcat;
 
31814
  SeqEntryPtr      sep;
 
31815
  CharPtr          description;
 
31816
 
 
31817
  /* First, add SeqEntry for each feature or descriptor to the item list */
 
31818
  for (vnp = value_lists; vnp != NULL; vnp = vnp->next) {
 
31819
    cip = (ClickableItemPtr) vnp->data.ptrvalue;
 
31820
    new_item_list = NULL;
 
31821
    if (cip != NULL) {
 
31822
      for (vnp_item = cip->item_list; vnp_item != NULL; vnp_item = vnp_item->next) {
 
31823
        if (vnp_item->data.ptrvalue == NULL) continue;
 
31824
        sep_list = GetSeqEntryListForItem (vnp_item);
 
31825
        for (sep_vnp = sep_list; sep_vnp != NULL; sep_vnp = sep_vnp->next) {
 
31826
          sep = sep_vnp->data.ptrvalue;
 
31827
          new_vnp = DataInValNodeList (new_item_list, OBJ_SEQENTRY, sep);
 
31828
          /* add to list for this category */
 
31829
          if (new_vnp == NULL) {
 
31830
            new_vnp = ValNodeAddPointer (&new_item_list, OBJ_SEQENTRY, sep);
 
31831
          }
 
31832
          description = GetDiscrepancyItemText(new_vnp);
 
31833
          subcat = FindExistingCategory (description, cip->subcategories);
 
31834
          if (subcat == NULL) {
 
31835
            subcat = (ClickableItemPtr) MemNew (sizeof (ClickableItemData));
 
31836
            MemSet (subcat, 0, sizeof (ClickableItemData));
 
31837
            subcat->description = description;
 
31838
            ValNodeAddPointer (&(cip->subcategories), 0, subcat);
 
31839
          } else {
 
31840
            description = MemFree (description);
 
31841
          }
 
31842
          /* don't add item twice */
 
31843
          if (!DataInValNodeList (subcat->item_list, vnp_item->choice, vnp_item->data.ptrvalue)) {
 
31844
            ValNodeAddPointer (&(subcat->item_list), vnp_item->choice, vnp_item->data.ptrvalue);
 
31845
          }
 
31846
        }
 
31847
        sep_list = ValNodeFree (sep_list);
 
31848
      }
 
31849
      
 
31850
      cip->item_list = ValNodeFree (cip->item_list);
 
31851
      cip->item_list = new_item_list;
 
31852
    }
 
31853
  }
 
31854
  value_lists = RearrangeForSeqEntriesInMultipleCategories (value_lists);
 
31855
  return value_lists;
 
31856
}
 
31857
 
 
31858
 
 
31859
static void GetMolTypes (SeqDescrPtr sdp, Pointer userdata)
 
31860
{
 
31861
  ValNodePtr PNTR   type_list;
 
31862
  ClickableItemPtr  cip;
 
31863
  CharPtr           str;
 
31864
  MolInfoPtr        mip;
 
31865
  
 
31866
  if (sdp == NULL || sdp->choice != Seq_descr_molinfo || sdp->data.ptrvalue == NULL || userdata == NULL)
 
31867
  {
 
31868
    return;
 
31869
  }
 
31870
  
 
31871
  type_list = (ValNodePtr PNTR) userdata;
 
31872
 
 
31873
  mip = (MolInfoPtr) sdp->data.ptrvalue;
 
31874
  /* don't look for peptides */
 
31875
  if (mip->biomol == 8) return;
 
31876
 
 
31877
  str = GetMoleculeTypeName (mip->biomol);
 
31878
 
 
31879
  cip = FindExistingCategory (str, *type_list);
 
31880
 
 
31881
  if (cip == NULL) {
 
31882
    cip = (ClickableItemPtr) MemNew (sizeof (ClickableItemData));
 
31883
    MemSet (cip, 0, sizeof (ClickableItemData));
 
31884
    cip->description = StringSave (str);
 
31885
    ValNodeAddPointer (&cip->item_list, OBJ_SEQDESC, sdp);
 
31886
    ValNodeAddPointer (type_list, 0, cip);
 
31887
  } else {
 
31888
    /* make sure feature isn't already in the list */
 
31889
    if (DataInValNodeList (cip->item_list, OBJ_SEQDESC, sdp) == NULL) {
 
31890
      ValNodeAddPointer (&cip->item_list, OBJ_SEQDESC, sdp);
 
31891
    }
 
31892
  }
 
31893
}
 
31894
 
 
31895
static void GetMolClasses (BioseqPtr bsp, Pointer userdata)
 
31896
{
 
31897
  ValNodePtr PNTR   type_list;
 
31898
  ClickableItemPtr  cip;
 
31899
  CharPtr           str;
 
31900
  
 
31901
  if (bsp == NULL || ISA_aa(bsp->mol) || userdata == NULL)
 
31902
  {
 
31903
    return;
 
31904
  }
 
31905
  
 
31906
  type_list = (ValNodePtr PNTR) userdata;
 
31907
 
 
31908
  str = GetMoleculeClassName (bsp->mol);
 
31909
 
 
31910
  cip = FindExistingCategory (str, *type_list);
 
31911
 
 
31912
  if (cip == NULL) {
 
31913
    cip = (ClickableItemPtr) MemNew (sizeof (ClickableItemData));
 
31914
    MemSet (cip, 0, sizeof (ClickableItemData));
 
31915
    cip->description = StringSave (str);
 
31916
    ValNodeAddPointer (&cip->item_list, OBJ_BIOSEQ, bsp);
 
31917
    ValNodeAddPointer (type_list, 0, cip);
 
31918
  } else {
 
31919
    /* make sure feature isn't already in the list */
 
31920
    if (DataInValNodeList (cip->item_list, OBJ_BIOSEQ, bsp) == NULL) {
 
31921
      ValNodeAddPointer (&cip->item_list, OBJ_BIOSEQ, bsp);
 
31922
    }
 
31923
  }
 
31924
}
 
31925
 
 
31926
 
 
31927
typedef struct segfeatures {
 
31928
  Uint2      featdef;
 
31929
  ValNodePtr feature_list;
 
31930
} SegFeaturesData, PNTR SegFeaturesPtr;
 
31931
 
 
31932
static void FindFeaturesForSeg (SeqFeatPtr sfp, Pointer userdata)
 
31933
{
 
31934
  SegFeaturesPtr fp;
 
31935
 
 
31936
  if (sfp == NULL || userdata == NULL) return;
 
31937
 
 
31938
  fp = (SegFeaturesPtr) userdata;
 
31939
 
 
31940
  if (sfp->idx.subtype == fp->featdef) {
 
31941
    ValNodeAddPointer (&(fp->feature_list), OBJ_SEQFEAT, sfp);
 
31942
  }
 
31943
}
 
31944
 
 
31945
typedef struct segdescriptors {
 
31946
  Uint2      desc_type;
 
31947
  ValNodePtr descriptor_list;
 
31948
} SegDescriptorsData, PNTR SegDescriptorsPtr;
 
31949
 
 
31950
static void FindDescriptorsForSeg (SeqDescrPtr sdp, Pointer userdata)
 
31951
{
 
31952
  SegDescriptorsPtr fp;
 
31953
 
 
31954
  if (sdp == NULL || userdata == NULL) return;
 
31955
 
 
31956
  fp = (SegDescriptorsPtr) userdata;
 
31957
 
 
31958
  if (sdp->choice == fp->desc_type) {
 
31959
    ValNodeAddPointer (&(fp->descriptor_list), OBJ_SEQDESC, sdp);
 
31960
  }
 
31961
}
 
31962
 
 
31963
 
 
31964
extern ValNodePtr 
 
31965
CreateSeqEntryListsForUniqueValues
 
31966
(SeqEntryPtr   sep,
 
31967
 Uint2         entityID, 
 
31968
 ParseFieldPtr dst_field_data,
 
31969
 FilterSetPtr  fsp)
 
31970
{
 
31971
  ValNodePtr value_lists;
 
31972
 
 
31973
  value_lists = GetUniqueValueListForSeqEntry (sep, entityID, dst_field_data, fsp);
 
31974
 
 
31975
  value_lists = ChangeUniqueValueListsToSeqEntryLists (value_lists);
 
31976
  return value_lists;
 
31977
}
 
31978
 
 
31979
static void AddPubFeatureWithText (SeqFeatPtr sfp, Pointer userdata)
 
31980
{
 
31981
  ValNodePtr PNTR pub_list;
 
31982
 
 
31983
  if (sfp == NULL || userdata == NULL) return;
 
31984
  pub_list = (ValNodePtr PNTR) userdata;
 
31985
 
 
31986
  ValNodeAddPointer (pub_list, OBJ_SEQFEAT, sfp);
 
31987
}
 
31988
 
 
31989
static void AddPubDescriptorWithText (SeqDescrPtr sdp, Pointer userdata)
 
31990
{
 
31991
  ValNodePtr PNTR pub_list;
 
31992
 
 
31993
  if (sdp == NULL || userdata == NULL || sdp->choice != Seq_descr_pub) return;
 
31994
  pub_list = (ValNodePtr PNTR) userdata;
 
31995
 
 
31996
  ValNodeAddPointer (pub_list, OBJ_SEQDESC, sdp);
 
31997
}
 
31998
 
 
31999
static ValNodePtr GetTextPubListsForSeqEntry (SeqEntryPtr sep, CharPtr search_text)
 
32000
{
 
32001
  FeaturesWithTextData    ftd;
 
32002
  DescriptorsWithTextData dtd;
 
32003
  ValNodePtr              obj_list = NULL;
 
32004
 
 
32005
  ftd.seqFeatChoice = SEQFEAT_PUB;
 
32006
  ftd.featDefChoice = FEATDEF_PUB;
 
32007
  ftd.search_text = search_text;
 
32008
  ftd.act_when_string_not_present = FALSE;
 
32009
  ftd.case_insensitive = TRUE;
 
32010
  ftd.whole_word = FALSE;
 
32011
  ftd.no_text = FALSE;
 
32012
  ftd.callback = AddPubFeatureWithText;
 
32013
  ftd.userdata = &obj_list;
 
32014
 
 
32015
  dtd.search_text = search_text;
 
32016
  dtd.act_when_string_not_present = FALSE;
 
32017
  dtd.case_insensitive = TRUE;
 
32018
  dtd.whole_word = FALSE;
 
32019
  dtd.no_text = FALSE;
 
32020
  dtd.callback = AddPubDescriptorWithText;
 
32021
  dtd.userdata = &obj_list;
 
32022
 
 
32023
  OperateOnSeqEntryFeaturesWithText (sep, &ftd);
 
32024
  OperateOnSeqEntryDescriptorsWithText (sep, &dtd);
 
32025
 
 
32026
  return obj_list;
 
32027
}
 
32028
 
 
32029
static ValNodePtr GetTextSeqEntryListForSeqEntry (SeqEntryPtr sep, Uint2 entityID, CharPtr search_text, ParseFieldPtr dst_field_data)
 
32030
{
 
32031
  ValNodePtr value_lists = NULL;
 
32032
  ValNodePtr obj_list = NULL, tmp_list, vnp;
 
32033
  ClickableItemPtr cip;
 
32034
  CharPtr          desc_fmt = "%d sequences contain %s";
 
32035
  StringConstraintData scd;
 
32036
  ChoiceConstraintData ccd;
 
32037
  FilterSetData        fsd;
 
32038
 
 
32039
  if (dst_field_data == NULL) {
 
32040
    /* do nothing */
 
32041
  } else if (dst_field_data->parse_field_type == SEARCH_FIELD_PUBLICATION) {
 
32042
    obj_list = GetTextPubListsForSeqEntry(sep, search_text);
 
32043
  } else {
 
32044
    scd.match_text = search_text;
 
32045
    scd.match_location = 1;
 
32046
    scd.insensitive = TRUE;
 
32047
    scd.whole_word = FALSE;
 
32048
    scd.not_present = FALSE;
 
32049
 
 
32050
    ccd.constraint_type = CHOICE_CONSTRAINT_STRING;
 
32051
    ccd.qual_choice = 
 
32052
    ccd.qual_choice_match = NULL;
 
32053
    ccd.string_constraint = &scd;
 
32054
    ccd.pseudo_constraint = NULL;
 
32055
    ccd.free_vn_proc = NULL;
 
32056
    ccd.copy_vn_proc = NULL;
 
32057
 
 
32058
    MemSet (&fsd, 0, sizeof (FilterSetData));
 
32059
    fsd.ccp = &ccd;
 
32060
 
 
32061
    tmp_list = GetUniqueValueListForSeqEntry (sep, entityID, dst_field_data, NULL);
 
32062
 
 
32063
    for (vnp = tmp_list; vnp != NULL; vnp = vnp->next) {
 
32064
      cip = (ClickableItemPtr) vnp->data.ptrvalue;
 
32065
      if (cip != NULL && StringISearch (cip->description, search_text) != NULL) {
 
32066
        ValNodeLink (&obj_list, cip->item_list);
 
32067
        cip->item_list = NULL;
 
32068
      }
 
32069
    }
 
32070
    tmp_list = FreeClickableList (tmp_list);
 
32071
  }
 
32072
  if (obj_list != NULL) {
 
32073
    cip = (ClickableItemPtr) MemNew (sizeof (ClickableItemData));
 
32074
    MemSet (cip, 0, sizeof (ClickableItemData));
 
32075
    cip->description = StringSave (search_text);
 
32076
    cip->item_list = obj_list;
 
32077
    cip->chosen = TRUE;
 
32078
    ValNodeAddPointer (&value_lists, 0, cip);
 
32079
    value_lists = ChangeUniqueValueListsToSeqEntryLists (value_lists);
 
32080
    /* rename description */
 
32081
    if (value_lists != NULL) {
 
32082
      cip = value_lists->data.ptrvalue;
 
32083
      if (cip != NULL) {
 
32084
        cip->description = MemFree (cip->description);
 
32085
        cip->description = (CharPtr) MemNew (sizeof(Char) * (StringLen (desc_fmt) + StringLen (search_text) + 15));
 
32086
        sprintf (cip->description, desc_fmt, ValNodeLen (cip->item_list), search_text);
 
32087
      }
 
32088
    }
 
32089
  }
 
32090
 
 
32091
  return value_lists;
 
32092
}
 
32093
 
 
32094
static void AddNewUniqueDescriptors (SeqDescrPtr PNTR new_set, SeqDescrPtr parent_set)
 
32095
{
 
32096
  SeqDescrPtr sdp, sdp_next, sdp_tmp, sdp_tmp_next;
 
32097
  Boolean     found_match;
 
32098
 
 
32099
  if (new_set == NULL || parent_set == NULL) return;
 
32100
 
 
32101
  if (*new_set == NULL) {
 
32102
    ValNodeLink (new_set,
 
32103
                 AsnIoMemCopy ((Pointer) parent_set,
 
32104
                               (AsnReadFunc) SeqDescrAsnRead,
 
32105
                               (AsnWriteFunc) SeqDescrAsnWrite));
 
32106
  } else {
 
32107
    sdp = parent_set;
 
32108
    while (sdp != NULL) {
 
32109
      sdp_next = sdp->next;
 
32110
      sdp->next = NULL;
 
32111
      for (sdp_tmp = *new_set, found_match = FALSE;
 
32112
           sdp_tmp != NULL && !found_match; 
 
32113
           sdp_tmp = sdp_tmp->next) {
 
32114
        sdp_tmp_next = sdp_tmp->next;
 
32115
        sdp_tmp->next = NULL;
 
32116
        if (AsnIoMemComp (sdp, sdp_tmp, (AsnWriteFunc) SeqDescrAsnWrite)) {
 
32117
          found_match = TRUE;
 
32118
        }
 
32119
        sdp_tmp->next = sdp_tmp_next;
 
32120
      }
 
32121
      if (!found_match) {
 
32122
        ValNodeLink (new_set,
 
32123
                     AsnIoMemCopy ((Pointer) sdp,
 
32124
                                   (AsnReadFunc) SeqDescrAsnRead,
 
32125
                                   (AsnWriteFunc) SeqDescrAsnWrite));
 
32126
      }
 
32127
      sdp->next = sdp_next;
 
32128
      sdp = sdp->next;
 
32129
    }
 
32130
  }
 
32131
}
 
32132
 
 
32133
static void AddNewUniqueDescriptorsToSeqEntry (SeqEntryPtr sep, SeqDescrPtr parent_set)
 
32134
{
 
32135
  BioseqPtr    bsp;
 
32136
  BioseqSetPtr bssp;
 
32137
 
 
32138
  if (IS_Bioseq(sep)) {
 
32139
    bsp = (BioseqPtr) sep->data.ptrvalue;
 
32140
    if (bsp != NULL) {
 
32141
      AddNewUniqueDescriptors (&(bsp->descr), parent_set);
 
32142
    }
 
32143
  } else if (IS_Bioseq_set (sep)) {
 
32144
    bssp = (BioseqSetPtr) sep->data.ptrvalue;
 
32145
    if (bssp != NULL) {
 
32146
      AddNewUniqueDescriptors (&(bssp->descr), parent_set);
 
32147
    }
 
32148
  }
 
32149
}
 
32150
 
 
32151
static void AddNewUniqueAnnotations (SeqAnnotPtr PNTR new_set, SeqAnnotPtr parent_set)
 
32152
{
 
32153
  SeqAnnotPtr sap, sap_next, sap_tmp, sap_tmp_next, sap_copy, last_sap;
 
32154
  Boolean     found_match;
 
32155
 
 
32156
  if (new_set == NULL || parent_set == NULL) return;
 
32157
 
 
32158
  sap = parent_set;
 
32159
  while (sap != NULL) {
 
32160
    sap_next = sap->next;
 
32161
    sap->next = NULL;
 
32162
    last_sap = NULL;
 
32163
    for (sap_tmp = *new_set, found_match = FALSE;
 
32164
         sap_tmp != NULL && !found_match;
 
32165
         sap_tmp = sap_tmp->next) {
 
32166
      sap_tmp_next = sap_tmp->next;
 
32167
      sap_tmp->next = NULL;
 
32168
      if (AsnIoMemComp (sap, sap_tmp, (AsnWriteFunc) SeqAnnotAsnWrite)) {
 
32169
        found_match = TRUE;
 
32170
      }
 
32171
      sap_tmp->next = sap_tmp->next;
 
32172
      last_sap = sap_tmp;
 
32173
    }
 
32174
    if (!found_match) {        
 
32175
      sap_copy = (SeqAnnotPtr) AsnIoMemCopy ((Pointer) sap, (AsnReadFunc) SeqAnnotAsnRead, (AsnWriteFunc) SeqAnnotAsnWrite); 
 
32176
      if (last_sap == NULL) {
 
32177
        *new_set = sap_copy;
 
32178
      } else {
 
32179
        last_sap->next = sap_copy;
 
32180
      }
 
32181
    }
 
32182
    sap->next = sap_next;
 
32183
    sap = sap->next;
 
32184
  }
 
32185
}
 
32186
 
 
32187
 
 
32188
static void AddNewUniqueAnnotationsToSeqEntry (SeqEntryPtr sep, SeqAnnotPtr parent_set)
 
32189
{
 
32190
  BioseqPtr    bsp;
 
32191
  BioseqSetPtr bssp;
 
32192
 
 
32193
  if (IS_Bioseq(sep)) {
 
32194
    bsp = (BioseqPtr) sep->data.ptrvalue;
 
32195
    if (bsp != NULL) {
 
32196
      AddNewUniqueAnnotations (&(bsp->annot), parent_set);
 
32197
    }
 
32198
  } else if (IS_Bioseq_set (sep)) {
 
32199
    bssp = (BioseqSetPtr) sep->data.ptrvalue;
 
32200
    if (bssp != NULL) {
 
32201
      AddNewUniqueAnnotations (&(bssp->annot), parent_set);
 
32202
    }
 
32203
  }
 
32204
}
 
32205
 
 
32206
 
 
32207
static void AddCategorySeqEntriesToSet (BioseqSetPtr newset, ClickableItemPtr category)
 
32208
{
 
32209
  ValNodePtr vnp_item;
 
32210
  SeqEntryPtr sep, last_sep, prev_sep, remove_sep;
 
32211
  BioseqSetPtr bssp, orig_parent;
 
32212
  BioseqPtr bsp;
 
32213
 
 
32214
  if (newset == NULL || category == NULL || category->item_list == NULL) return;
 
32215
 
 
32216
  if (category->chosen) {
 
32217
    last_sep = newset->seq_set;
 
32218
    while (last_sep != NULL && last_sep->next != NULL) {
 
32219
      last_sep = last_sep->next;
 
32220
    }
 
32221
 
 
32222
    for (vnp_item = category->item_list; vnp_item != NULL; vnp_item = vnp_item->next) {
 
32223
      sep = GetBestSeqEntryForItem (vnp_item);
 
32224
      if (sep == NULL || sep->data.ptrvalue == NULL) continue;
 
32225
      orig_parent = NULL;
 
32226
      if (IS_Bioseq (sep)) {
 
32227
        bsp = sep->data.ptrvalue;
 
32228
        if (bsp->idx.parenttype == OBJ_BIOSEQSET) {
 
32229
          orig_parent = bsp->idx.parentptr;
 
32230
          bsp->idx.parentptr = NULL;
 
32231
        }
 
32232
      } else if (IS_Bioseq_set (sep)) {
 
32233
        bssp = sep->data.ptrvalue;
 
32234
        if (bssp->idx.parenttype == OBJ_BIOSEQSET) {
 
32235
          orig_parent = bssp->idx.parentptr;
 
32236
          bssp->idx.parentptr = NULL;
 
32237
        }
 
32238
      } else {
 
32239
        continue;
 
32240
      }
 
32241
         
 
32242
      if (orig_parent != NULL) {
 
32243
        /* remove this seq-entry from the original parent */
 
32244
        prev_sep = NULL;
 
32245
        for (remove_sep = orig_parent->seq_set;
 
32246
             remove_sep != NULL && remove_sep != sep;
 
32247
             remove_sep = remove_sep->next) {
 
32248
          prev_sep = remove_sep;
 
32249
        }
 
32250
        if (remove_sep == sep) {
 
32251
          if (prev_sep == NULL) {
 
32252
            orig_parent->seq_set = orig_parent->seq_set->next;
 
32253
            if (orig_parent->seq_set == NULL) {
 
32254
              orig_parent->idx.deleteme = TRUE; 
 
32255
            }
 
32256
          } else {
 
32257
            prev_sep->next = sep->next;
 
32258
          }
 
32259
        }
 
32260
        /* set class type if not already set */
 
32261
        if (newset->_class == BioseqseqSet_class_genbank) {
 
32262
          newset->_class = orig_parent->_class;
 
32263
        }
 
32264
      }
 
32265
      /* add descriptors from the orig_parent to the new parent */
 
32266
      AddNewUniqueDescriptors (&(newset->descr), orig_parent->descr);
 
32267
 
 
32268
      /* add annotations from the orig_parent to the new parent */
 
32269
      AddNewUniqueAnnotations (&(newset->annot), orig_parent->annot);
 
32270
 
 
32271
      /* add to new parent */
 
32272
      sep->next = NULL;
 
32273
      if (last_sep == NULL) {
 
32274
        newset->seq_set = sep;
 
32275
      } else {
 
32276
        last_sep->next = sep;
 
32277
      }
 
32278
      last_sep = sep;
 
32279
      SeqMgrLinkSeqEntry (sep, OBJ_BIOSEQSET, newset);
 
32280
    }
 
32281
  } else {
 
32282
    for (vnp_item = category->subcategories; vnp_item != NULL; vnp_item = vnp_item->next) {
 
32283
      AddCategorySeqEntriesToSet (newset, vnp_item->data.ptrvalue);
 
32284
    }
 
32285
  }
 
32286
}
 
32287
 
 
32288
static Boolean AnyDiscrepanciesChosen (ValNodePtr cip_list)
 
32289
{
 
32290
  ClickableItemPtr cip;
 
32291
  Boolean          any_chosen = FALSE;
 
32292
 
 
32293
  while (cip_list != NULL && !any_chosen) {
 
32294
    cip = (ClickableItemPtr) cip_list->data.ptrvalue;
 
32295
    if (cip != NULL
 
32296
        && (cip->chosen 
 
32297
            || (cip->expanded && AnyDiscrepanciesChosen (cip->subcategories)))) {
 
32298
      any_chosen = TRUE;
 
32299
    }
 
32300
    cip_list = cip_list->next;
 
32301
  }
 
32302
  return any_chosen;
 
32303
}
 
32304
 
 
32305
static Boolean NeedsNewSet (SeqEntryPtr sep)
 
32306
{
 
32307
  BioseqSetPtr bssp;
 
32308
  while (sep != NULL) {
 
32309
    if (IS_Bioseq (sep)) {
 
32310
      return TRUE;
 
32311
    } else if (IS_Bioseq_set (sep)) {
 
32312
      bssp = (BioseqSetPtr) sep->data.ptrvalue;
 
32313
      if (bssp != NULL 
 
32314
          && (bssp->_class == BioseqseqSet_class_nuc_prot
 
32315
          || bssp->_class == BioseqseqSet_class_segset)) {
 
32316
        return TRUE;
 
32317
      }
 
32318
    }
 
32319
    sep = sep->next;
 
32320
  }
 
32321
  return FALSE;
 
32322
}
 
32323
 
 
32324
static BioseqSetPtr MakeGroupsForUniqueValues
 
32325
(BioseqSetPtr bssp, 
 
32326
 ValNodePtr   value_lists)
 
32327
{
 
32328
  ObjMgrDataPtr     omdptop;
 
32329
  ObjMgrData        omdata;
 
32330
  Uint2             parenttype;
 
32331
  Pointer           parentptr;
 
32332
  BioseqSetPtr parent_set;
 
32333
  SeqEntryPtr  sep, first_new_sep = NULL;
 
32334
  SeqEntryPtr  tmp;
 
32335
  BioseqSetPtr newset;
 
32336
  ValNodePtr   vnp;
 
32337
  ClickableItemPtr cip;
 
32338
  Uint1        child_class;
 
32339
  Uint2        entityID;
 
32340
  Boolean      child_became_parent = FALSE;
 
32341
 
 
32342
  if (bssp == NULL) return NULL;
 
32343
  entityID = bssp->idx.entityID;
 
32344
  
 
32345
  sep = SeqMgrGetSeqEntryForData (bssp);
 
32346
 
 
32347
  WatchCursor ();
 
32348
  Update ();
 
32349
  SaveSeqEntryObjMgrData (sep, &omdptop, &omdata);
 
32350
  GetSeqEntryParent (sep, &parentptr, &parenttype);
 
32351
 
 
32352
  parent_set = (BioseqSetPtr)(bssp->idx.parentptr);
 
32353
 
 
32354
  if (parent_set == NULL || parent_set->seq_set == NULL) {
 
32355
    /* this set has no parent, so make it the parent set, class GenBank,
 
32356
     * and create two new sets using the original set class as members of this set
 
32357
     */
 
32358
    parent_set = bssp;
 
32359
    child_class = parent_set->_class;
 
32360
    child_became_parent = TRUE;
 
32361
  } else {
 
32362
    /* we already have a parent set. */
 
32363
    child_class = bssp->_class;
 
32364
  }
 
32365
 
 
32366
  for (vnp = value_lists; vnp != NULL; vnp = vnp->next) {      
 
32367
    cip = (ClickableItemPtr) vnp->data.ptrvalue;
 
32368
    if (cip == NULL || (!cip->chosen && ! AnyDiscrepanciesChosen (cip->subcategories))) {
 
32369
      continue;
 
32370
    }
 
32371
 
 
32372
    newset = BioseqSetNew ();
 
32373
    newset->_class = child_class;
 
32374
    /* add SeqEntries for this category here */
 
32375
    AddCategorySeqEntriesToSet (newset, cip);
 
32376
 
 
32377
    /* check - is any member of the newset also a set? */
 
32378
    tmp = newset->seq_set;
 
32379
    while (tmp != NULL && IS_Bioseq (tmp)) {
 
32380
      tmp = tmp->next;
 
32381
    }
 
32382
 
 
32383
    /* add to members for parent_set */
 
32384
    tmp = SeqEntryNew ();
 
32385
    tmp->choice = 2;
 
32386
    tmp->data.ptrvalue = (Pointer) newset;
 
32387
 
 
32388
    tmp->next = parent_set->seq_set;
 
32389
    parent_set->seq_set = tmp;
 
32390
 
 
32391
    if (parent_set->idx.deleteme) {
 
32392
      parent_set->idx.deleteme = FALSE;
 
32393
    }
 
32394
    if (first_new_sep == NULL) {
 
32395
      first_new_sep = tmp;
 
32396
    }
 
32397
 
 
32398
    SeqMgrLinkSeqEntry (tmp, OBJ_BIOSEQSET, parent_set);
 
32399
  }
 
32400
 
 
32401
  RestoreSeqEntryObjMgrData (sep, omdptop, &omdata); 
 
32402
  DeleteMarkedObjects (entityID, 0, NULL);
 
32403
 
 
32404
  if (child_became_parent) {
 
32405
    if (NeedsNewSet (first_new_sep->next)) {
 
32406
      /* make new set to hold what wasn't moved */
 
32407
      newset = BioseqSetNew ();
 
32408
      /* contents of set are unmoved sequences */
 
32409
      newset->seq_set = first_new_sep->next;
 
32410
      /* set class type */
 
32411
      newset->_class = parent_set->_class;
 
32412
      /* add descriptors from the parent */
 
32413
      ValNodeLink (&(newset->descr),
 
32414
                   AsnIoMemCopy ((Pointer) parent_set->descr,
 
32415
                                 (AsnReadFunc) SeqDescrAsnRead,
 
32416
                                 (AsnWriteFunc) SeqDescrAsnWrite));
 
32417
 
 
32418
 
 
32419
      tmp = SeqEntryNew();
 
32420
      tmp->choice = 2;
 
32421
      tmp->data.ptrvalue = (Pointer) newset;
 
32422
      tmp->next = NULL;
 
32423
      first_new_sep->next = tmp;
 
32424
      SeqMgrLinkSeqEntry (tmp, OBJ_BIOSEQSET, parent_set);
 
32425
    } else {
 
32426
      sep = first_new_sep->next;
 
32427
      while (sep != NULL) {
 
32428
        AddNewUniqueDescriptorsToSeqEntry (sep, parent_set->descr);
 
32429
        sep = sep->next;
 
32430
      }
 
32431
    }
 
32432
    /* set parent class to GenBank set */
 
32433
    parent_set->_class = BioseqseqSet_class_genbank;
 
32434
    /* remove descriptors on parent, they will all have been copied down */
 
32435
    parent_set->descr = SeqDescrFree (parent_set->descr);
 
32436
  }
 
32437
 
 
32438
  ObjMgrSetDirtyFlag (entityID, TRUE);
 
32439
  ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
 
32440
 
 
32441
  ArrowCursor ();
 
32442
  Update ();
 
32443
  return parent_set;
 
32444
}
 
32445
 
 
32446
typedef enum {
 
32447
  eSegPageId = 1,
 
32448
  eSegPageText,
 
32449
  eSegPageField,
 
32450
  eSegPageMolInfo,
 
32451
  eSegPageFeatureType,
 
32452
  eSegPageDescriptorType,
 
32453
  eNumSegPages
 
32454
} ESegPage;
 
32455
 
 
32456
typedef struct segbyfield {
 
32457
  FORM_MESSAGE_BLOCK
 
32458
  GrouP        seg_choice_grp;
 
32459
 
 
32460
  GrouP        pages[eNumSegPages];
 
32461
  /* for segregating by field */
 
32462
  DialoG       field_dlg;
 
32463
  DialoG       group_list_dlg;
 
32464
 
 
32465
  /* for segregating by molinfo */
 
32466
  ButtoN       mol_type_btn;
 
32467
  ButtoN       mol_class_btn;
 
32468
 
 
32469
  /* for segregating by feature */
 
32470
  DialoG       feature_select;
 
32471
 
 
32472
  /* for segregating by descriptor */
 
32473
  DialoG       descriptor_select;
 
32474
 
 
32475
  /* for segregating by text */
 
32476
  DialoG       search_field;
 
32477
  TexT         search_text;
 
32478
 
 
32479
  /* for segregating by ID */
 
32480
  DialoG       id_constraint;
 
32481
 
 
32482
  ButtoN       accept;
 
32483
  ButtoN       leave_dlg_up;
 
32484
  BioseqSetPtr target_set;
 
32485
  ValNodePtr   value_lists;
 
32486
} SegByFieldData, PNTR SegByFieldPtr;
 
32487
 
 
32488
static void ChooseAllDiscrepancies (ValNodePtr cip_list)
 
32489
{
 
32490
  ClickableItemPtr cip;
 
32491
 
 
32492
  while (cip_list != NULL) {
 
32493
    cip = cip_list->data.ptrvalue;
 
32494
    if (cip != NULL) {
 
32495
      cip->chosen = TRUE;
 
32496
    }
 
32497
    cip_list = cip_list->next;
 
32498
  }
 
32499
}
 
32500
 
 
32501
static void ChangeSegChoice (GrouP g);
 
32502
 
 
32503
 
 
32504
static void PullChosenIntoOneGroup (ValNodePtr PNTR value_list, ClickableItemPtr chosen)
 
32505
{
 
32506
  ValNodePtr vnp_prev = NULL, vnp_next, vnp_this;
 
32507
  ClickableItemPtr cip;
 
32508
 
 
32509
  if (value_list == NULL || chosen == NULL) return;
 
32510
 
 
32511
  vnp_this = *value_list;
 
32512
  while (vnp_this != NULL)
 
32513
  {
 
32514
    vnp_next = vnp_this->next;
 
32515
    cip = (ClickableItemPtr) vnp_this->data.ptrvalue;
 
32516
    if (cip == NULL)
 
32517
    {
 
32518
      vnp_this->next = NULL;
 
32519
      if (vnp_prev == NULL) 
 
32520
      {
 
32521
        *value_list = vnp_next;
 
32522
      }
 
32523
      else
 
32524
      {
 
32525
        vnp_prev->next = vnp_next;
 
32526
      }
 
32527
      vnp_this = ValNodeFree (vnp_this);
 
32528
    }
 
32529
    else if (cip->chosen)
 
32530
    {
 
32531
      vnp_this->next = NULL;
 
32532
      if (vnp_prev == NULL) 
 
32533
      {
 
32534
        *value_list = vnp_next;
 
32535
      }
 
32536
      else
 
32537
      {
 
32538
        vnp_prev->next = vnp_next;
 
32539
      }
 
32540
      ValNodeLink (&(chosen->item_list), cip->item_list);
 
32541
      cip->item_list = NULL;
 
32542
      vnp_this = FreeClickableList (vnp_this);
 
32543
    }
 
32544
    else
 
32545
    {
 
32546
      PullChosenIntoOneGroup (&(cip->subcategories), chosen);
 
32547
      vnp_prev = vnp_this;
 
32548
    }
 
32549
    vnp_this = vnp_next;
 
32550
  }
 
32551
}
 
32552
 
 
32553
 
 
32554
static void SegregateByField_Callback (ButtoN b)
 
32555
{
 
32556
  SegByFieldPtr sfp;
 
32557
  Int4          num_chosen = 0;
 
32558
  ClickableItemPtr cip;
 
32559
  
 
32560
  sfp = (SegByFieldPtr) GetObjectExtra (b);
 
32561
  if (sfp == NULL) return;
 
32562
 
 
32563
  num_chosen = CountChosenDiscrepancies (sfp->value_lists, FALSE);
 
32564
  if (num_chosen < 1) {
 
32565
    if (ANS_OK == Message (MSG_OKC, "You have not chosen any groups.  Create all?")) {
 
32566
      ChooseAllDiscrepancies (sfp->value_lists);
 
32567
    } else {
 
32568
      return;
 
32569
    }
 
32570
  }
 
32571
 
 
32572
  if (GetValue (sfp->seg_choice_grp) == eSegPageId) {
 
32573
    /* put all selected sequences into one group */
 
32574
    cip = (ClickableItemPtr) MemNew (sizeof (ClickableItemData));
 
32575
    cip->chosen = TRUE;
 
32576
    PullChosenIntoOneGroup (&(sfp->value_lists), cip);
 
32577
    ValNodeAddPointer (&(sfp->value_lists), 0, cip);
 
32578
  }
 
32579
 
 
32580
  sfp->target_set = MakeGroupsForUniqueValues (sfp->target_set, sfp->value_lists);
 
32581
 
 
32582
  if (GetStatus (sfp->leave_dlg_up)) {
 
32583
    ChangeSegChoice (sfp->seg_choice_grp);
 
32584
  } else {
 
32585
    Remove (sfp->form);
 
32586
  }
 
32587
}
 
32588
 
 
32589
static void ChangeSegField (Pointer userdata)
 
32590
{
 
32591
  SegByFieldPtr sfp = (SegByFieldPtr) userdata;
 
32592
  SeqEntryPtr   sep;
 
32593
  ParseFieldPtr dst_field_data;
 
32594
 
 
32595
  if (sfp == NULL || sfp->target_set == NULL) return;
 
32596
 
 
32597
  WatchCursor();
 
32598
  Update();
 
32599
  sep = SeqMgrGetSeqEntryForData (sfp->target_set);
 
32600
 
 
32601
  PointerToDialog (sfp->group_list_dlg, NULL);
 
32602
  sfp->value_lists = FreeClickableList (sfp->value_lists);
 
32603
 
 
32604
  dst_field_data = DialogToPointer (sfp->field_dlg);
 
32605
  if (dst_field_data == NULL) {
 
32606
    Disable (sfp->accept);
 
32607
    return;
 
32608
  }
 
32609
 
 
32610
  sfp->value_lists = CreateSeqEntryListsForUniqueValues (sep, sfp->target_set->idx.entityID, dst_field_data, NULL);
 
32611
  dst_field_data = ParseFieldFree (dst_field_data);
 
32612
  PointerToDialog (sfp->group_list_dlg, sfp->value_lists);
 
32613
  if (ValNodeLen (sfp->value_lists) < 2) {
 
32614
    Disable(sfp->accept);
 
32615
  } else {
 
32616
    Enable (sfp->accept);
 
32617
  }
 
32618
  ArrowCursor();
 
32619
  Update();
 
32620
}
 
32621
 
 
32622
static void SegTextChangeNotify (Pointer userdata)
 
32623
{
 
32624
  SegByFieldPtr sfp = (SegByFieldPtr) userdata;
 
32625
  SeqEntryPtr   sep;
 
32626
  ParseFieldPtr dst_field_data;
 
32627
  CharPtr       search_text;
 
32628
 
 
32629
  if (sfp == NULL || sfp->target_set == NULL) return;
 
32630
 
 
32631
  WatchCursor();
 
32632
  Update();
 
32633
  sep = SeqMgrGetSeqEntryForData (sfp->target_set);
 
32634
 
 
32635
  PointerToDialog (sfp->group_list_dlg, NULL);
 
32636
  sfp->value_lists = FreeClickableList (sfp->value_lists);
 
32637
 
 
32638
  if (TextHasNoText (sfp->search_text)) {
 
32639
    Disable (sfp->accept);
 
32640
    ArrowCursor();
 
32641
    Update();
 
32642
    return;
 
32643
  }
 
32644
  dst_field_data = DialogToPointer (sfp->search_field);
 
32645
  if (dst_field_data == NULL) {
 
32646
    Disable (sfp->accept);
 
32647
    ArrowCursor();
 
32648
    Update();
 
32649
    return;
 
32650
  }
 
32651
  search_text = SaveStringFromText (sfp->search_text);
 
32652
 
 
32653
  sfp->value_lists = GetTextSeqEntryListForSeqEntry (sep, sfp->target_set->idx.entityID, search_text, dst_field_data);
 
32654
 
 
32655
  search_text = MemFree (search_text);
 
32656
 
 
32657
  dst_field_data = ParseFieldFree (dst_field_data);
 
32658
  PointerToDialog (sfp->group_list_dlg, sfp->value_lists);
 
32659
  if (sfp->value_lists == NULL) {
 
32660
    Disable(sfp->accept);
 
32661
  } else {
 
32662
    Enable (sfp->accept);
 
32663
  }
 
32664
  ArrowCursor();
 
32665
  Update();
 
32666
}
 
32667
 
 
32668
static void SegTextChange (TexT t)
 
32669
{
 
32670
  SegByFieldPtr sfp;
 
32671
 
 
32672
  sfp = (SegByFieldPtr) GetObjectExtra (t);
 
32673
 
 
32674
  SegTextChangeNotify (sfp);
 
32675
 
 
32676
}
 
32677
 
 
32678
 
 
32679
extern void ListAllSequences (BioseqPtr bsp, Pointer userdata)
 
32680
{
 
32681
  ClickableItemPtr cip;
 
32682
  Char             id_str[100];
 
32683
 
 
32684
  if (bsp != NULL && userdata != NULL && ! ISA_aa (bsp->mol))
 
32685
  {
 
32686
    cip = (ClickableItemPtr) MemNew (sizeof (ClickableItemData));
 
32687
    SeqIdWrite (SeqIdFindBest (bsp->id, SEQID_GENBANK), id_str, PRINTID_REPORT, sizeof (id_str) - 1);
 
32688
    cip->description = StringSave (id_str);
 
32689
 
 
32690
    ValNodeAddPointer (&(cip->item_list), OBJ_BIOSEQ, bsp);
 
32691
    ValNodeAddPointer ((ValNodePtr PNTR) userdata, 0, cip);
 
32692
  }
 
32693
}
 
32694
 
 
32695
 
 
32696
static void ChooseSegId (Pointer userdata)
 
32697
{
 
32698
  SegByFieldPtr sfp = (SegByFieldPtr) userdata;
 
32699
  SeqEntryPtr   sep;
 
32700
 
 
32701
  if (sfp == NULL || sfp->target_set == NULL) return;
 
32702
 
 
32703
  WatchCursor();
 
32704
  Update();
 
32705
  sep = SeqMgrGetSeqEntryForData (sfp->target_set);
 
32706
 
 
32707
  PointerToDialog (sfp->group_list_dlg, NULL);
 
32708
  sfp->value_lists = FreeClickableList (sfp->value_lists);
 
32709
 
 
32710
  VisitBioseqsInSep (sep, &sfp->value_lists, ListAllSequences);
 
32711
 
 
32712
  PointerToDialog (sfp->group_list_dlg, sfp->value_lists);
 
32713
  if (sfp->value_lists == NULL) {
 
32714
    Disable(sfp->accept);
 
32715
  } else {
 
32716
    Enable (sfp->accept);
 
32717
  }
 
32718
  ArrowCursor();
 
32719
  Update();
 
32720
}
 
32721
 
 
32722
 
 
32723
static void ChangeMol (ButtoN b)
 
32724
{
 
32725
  SegByFieldPtr sfp;
 
32726
  SeqEntryPtr   sep;
 
32727
 
 
32728
  sfp = (SegByFieldPtr) GetObjectExtra (b);
 
32729
 
 
32730
  if (sfp == NULL) return;
 
32731
 
 
32732
  WatchCursor ();
 
32733
  Update();
 
32734
  sep = SeqMgrGetSeqEntryForData (sfp->target_set);
 
32735
 
 
32736
  PointerToDialog (sfp->group_list_dlg, NULL);
 
32737
  sfp->value_lists = FreeClickableList (sfp->value_lists);
 
32738
 
 
32739
  if (GetStatus (sfp->mol_class_btn)) {
 
32740
    VisitBioseqsInSep (sep, &(sfp->value_lists), GetMolClasses);
 
32741
  }
 
32742
  if (GetStatus (sfp->mol_type_btn)) {
 
32743
    VisitDescriptorsInSep (sep, &(sfp->value_lists), GetMolTypes);
 
32744
  }
 
32745
 
 
32746
  sfp->value_lists = ChangeUniqueValueListsToSeqEntryLists (sfp->value_lists);
 
32747
 
 
32748
  PointerToDialog (sfp->group_list_dlg, sfp->value_lists);
 
32749
  if (ValNodeLen (sfp->value_lists) < 2) {
 
32750
    Disable(sfp->accept);
 
32751
  } else {
 
32752
    Enable (sfp->accept);
 
32753
  }
 
32754
  ArrowCursor();
 
32755
  Update();
 
32756
}
 
32757
 
 
32758
 
 
32759
static void SegFeatureChangeNotify (Pointer userdata)
 
32760
{
 
32761
  SegByFieldPtr sfp = (SegByFieldPtr) userdata;
 
32762
  SeqEntryPtr   sep;
 
32763
  SegFeaturesData sfd;
 
32764
  ClickableItemPtr cip;
 
32765
  ValNodePtr       vnp;
 
32766
  CharPtr          desc_fmt = "%d %ss";
 
32767
 
 
32768
  if (sfp == NULL) return;
 
32769
 
 
32770
  vnp = DialogToPointer (sfp->feature_select);
 
32771
  if (vnp == NULL) {
 
32772
    PointerToDialog (sfp->group_list_dlg, NULL);
 
32773
    sfp->value_lists = FreeClickableList (sfp->value_lists);
 
32774
    Disable (sfp->accept);
 
32775
    return;
 
32776
  }
 
32777
 
 
32778
  WatchCursor ();
 
32779
  Update();
 
32780
  sep = SeqMgrGetSeqEntryForData (sfp->target_set);
 
32781
 
 
32782
  PointerToDialog (sfp->group_list_dlg, NULL);
 
32783
  sfp->value_lists = FreeClickableList (sfp->value_lists);
 
32784
 
 
32785
  sfd.featdef = vnp->choice;
 
32786
  sfd.feature_list = NULL;
 
32787
  VisitFeaturesInSep (sep, &sfd, FindFeaturesForSeg);
 
32788
 
 
32789
  if (sfd.feature_list != NULL) {
 
32790
    cip = (ClickableItemPtr) MemNew (sizeof (ClickableItemData));
 
32791
    MemSet (cip, 0, sizeof (ClickableItemData));
 
32792
    cip->description = (CharPtr) MemNew (sizeof(Char) * (StringLen (desc_fmt) + StringLen (vnp->data.ptrvalue) + 15));
 
32793
    sprintf (cip->description, desc_fmt, ValNodeLen (sfd.feature_list), vnp->data.ptrvalue);
 
32794
    cip->item_list = sfd.feature_list;
 
32795
    cip->chosen = TRUE;
 
32796
    ValNodeAddPointer (&(sfp->value_lists), 0, cip);
 
32797
    sfp->value_lists = ChangeUniqueValueListsToSeqEntryLists (sfp->value_lists);
 
32798
  }
 
32799
  vnp = ValNodeFree (vnp);
 
32800
 
 
32801
  PointerToDialog (sfp->group_list_dlg, sfp->value_lists);
 
32802
 
 
32803
  if (sfp->value_lists == NULL) {
 
32804
    Disable (sfp->accept);
 
32805
  } else {
 
32806
    Enable (sfp->accept);
 
32807
  }
 
32808
  ArrowCursor();
 
32809
  Update();
 
32810
}
 
32811
 
 
32812
static void SegDescriptorChangeNotify (Pointer data)
 
32813
{
 
32814
  SegByFieldPtr      sfp;
 
32815
  ValNodePtr         vnp;
 
32816
  SegDescriptorsData sdd;
 
32817
  ClickableItemPtr   cip;
 
32818
  CharPtr            desc_fmt = "%d %ss";
 
32819
  SeqEntryPtr        sep;
 
32820
 
 
32821
  sfp = (SegByFieldPtr) data;
 
32822
  if (sfp == NULL) return;
 
32823
 
 
32824
  vnp = DialogToPointer (sfp->descriptor_select);
 
32825
  if (vnp == NULL) {
 
32826
    PointerToDialog (sfp->group_list_dlg, NULL);
 
32827
    sfp->value_lists = FreeClickableList (sfp->value_lists);
 
32828
    Disable (sfp->accept);
 
32829
    return;
 
32830
  }
 
32831
 
 
32832
  WatchCursor ();
 
32833
  Update();
 
32834
  sep = SeqMgrGetSeqEntryForData (sfp->target_set);
 
32835
 
 
32836
  PointerToDialog (sfp->group_list_dlg, NULL);
 
32837
  sfp->value_lists = FreeClickableList (sfp->value_lists);
 
32838
 
 
32839
  sdd.desc_type = vnp->choice;
 
32840
  sdd.descriptor_list = NULL;
 
32841
  VisitDescriptorsInSep (sep, &sdd, FindDescriptorsForSeg);
 
32842
 
 
32843
  if (sdd.descriptor_list != NULL) {
 
32844
    cip = (ClickableItemPtr) MemNew (sizeof (ClickableItemData));
 
32845
    MemSet (cip, 0, sizeof (ClickableItemData));
 
32846
    cip->description = (CharPtr) MemNew (sizeof(Char) * (StringLen (desc_fmt) + StringLen (vnp->data.ptrvalue) + 15));
 
32847
    sprintf (cip->description, desc_fmt, ValNodeLen (sdd.descriptor_list), vnp->data.ptrvalue);
 
32848
    cip->item_list = sdd.descriptor_list;
 
32849
    cip->chosen = TRUE;
 
32850
    ValNodeAddPointer (&(sfp->value_lists), 0, cip);
 
32851
    sfp->value_lists = ChangeUniqueValueListsToSeqEntryLists (sfp->value_lists);
 
32852
  }
 
32853
  vnp = ValNodeFree (vnp);
 
32854
 
 
32855
  PointerToDialog (sfp->group_list_dlg, sfp->value_lists);
 
32856
 
 
32857
  if (sfp->value_lists == NULL) {
 
32858
    Disable (sfp->accept);
 
32859
  } else {
 
32860
    Enable (sfp->accept);
 
32861
  }
 
32862
  ArrowCursor();
 
32863
  Update();
 
32864
 
 
32865
}
 
32866
 
 
32867
static void ChangeSegChoice (GrouP g)
 
32868
{
 
32869
  SegByFieldPtr sfp;
 
32870
  Int4          seg_choice, i;
 
32871
 
 
32872
  sfp = (SegByFieldPtr) GetObjectExtra (g);
 
32873
  if (sfp == NULL) return;
 
32874
 
 
32875
  seg_choice = GetValue (sfp->seg_choice_grp);
 
32876
 
 
32877
        for (i = 0; i < eNumSegPages; i++) {
 
32878
    if (i == seg_choice - 1) {
 
32879
        Show (sfp->pages[i]);
 
32880
          } else {
 
32881
            Hide (sfp->pages[i]);
 
32882
          }
 
32883
        }
 
32884
        switch (seg_choice) {
 
32885
          case eSegPageField:
 
32886
        ChangeSegField (sfp);
 
32887
              break;
 
32888
          case eSegPageMolInfo:
 
32889
        ChangeMol(sfp->mol_class_btn);
 
32890
        break;
 
32891
          case eSegPageFeatureType:
 
32892
        SegFeatureChangeNotify (sfp);
 
32893
        break;
 
32894
    case eSegPageDescriptorType:
 
32895
        SegDescriptorChangeNotify (sfp);
 
32896
        break;
 
32897
    case eSegPageText:
 
32898
        SegTextChangeNotify (sfp);
 
32899
        break;
 
32900
    case eSegPageId:
 
32901
        ChooseSegId (sfp);
 
32902
        break;
 
32903
  }
 
32904
  if (seg_choice == eSegPageId) {
 
32905
    SetClickableListDialogTitles (sfp->group_list_dlg, "Sequences for New Set", "",
 
32906
                                                       "Use checkbox to mark sequences for new set",
 
32907
                                                       "Single click to navigate to sequence in record");
 
32908
  } else {
 
32909
    SetClickableListDialogTitles (sfp->group_list_dlg, "New Sets", "Sequences in Highlighted Set",
 
32910
                                                       "Use checkbox to mark sets to create",
 
32911
                                                       "");
 
32912
  }
 
32913
}
 
32914
 
 
32915
 
 
32916
extern void ChooseCategories (ValNodePtr value_list, Boolean do_choose)
 
32917
{
 
32918
  ClickableItemPtr cip;
 
32919
 
 
32920
  while (value_list != NULL) {
 
32921
    cip = (ClickableItemPtr) value_list->data.ptrvalue;
 
32922
          if (cip != NULL) {
 
32923
            cip->chosen = do_choose;
 
32924
            ChooseCategories (cip->subcategories, FALSE);
 
32925
          }
 
32926
          value_list = value_list->next;
 
32927
  }
 
32928
}
 
32929
 
 
32930
 
 
32931
extern void ChooseCategoriesByStringConstraint (ValNodePtr value_list, StringConstraintXPtr scp, Boolean do_choose)
 
32932
{
 
32933
  ClickableItemPtr cip;
 
32934
 
 
32935
  while (value_list != NULL) {
 
32936
    cip = (ClickableItemPtr) value_list->data.ptrvalue;
 
32937
          if (cip != NULL) {
 
32938
      if (cip->item_list != NULL 
 
32939
          && cip->item_list->choice == OBJ_BIOSEQ 
 
32940
          && cip->item_list->data.ptrvalue != NULL
 
32941
          && DoesIDListMeetStringConstraint (((BioseqPtr) cip->item_list->data.ptrvalue)->id, scp)) {
 
32942
        cip->chosen = do_choose;
 
32943
      } else {
 
32944
              ChooseCategoriesByStringConstraint (cip->subcategories, scp, do_choose);
 
32945
      }
 
32946
          }
 
32947
          value_list = value_list->next;
 
32948
  }
 
32949
}
 
32950
 
 
32951
 
 
32952
static void SelectSegCategories (ButtoN b)
 
32953
{
 
32954
  SegByFieldPtr sfp;
 
32955
 
 
32956
  sfp = (SegByFieldPtr) GetObjectExtra (b);
 
32957
  if (sfp != NULL) {
 
32958
    ChooseCategories (sfp->value_lists, TRUE);
 
32959
    PointerToDialog (sfp->group_list_dlg, sfp->value_lists);
 
32960
  }
 
32961
}
 
32962
 
 
32963
 
 
32964
static void UnselectSegCategories (ButtoN b)
 
32965
{
 
32966
  SegByFieldPtr sfp;
 
32967
 
 
32968
  sfp = (SegByFieldPtr) GetObjectExtra (b);
 
32969
  if (sfp != NULL) {
 
32970
    ChooseCategories (sfp->value_lists, FALSE);
 
32971
    PointerToDialog (sfp->group_list_dlg, sfp->value_lists);
 
32972
  }
 
32973
}
 
32974
 
 
32975
 
 
32976
static void SelectSequenceIDsForSegregate (ButtoN b)
 
32977
{
 
32978
  SegByFieldPtr       sfp;
 
32979
  StringConstraintXPtr scp;
 
32980
 
 
32981
  sfp = (SegByFieldPtr) GetObjectExtra (b);
 
32982
  if (sfp == NULL) return;
 
32983
 
 
32984
  scp = DialogToPointer (sfp->id_constraint);
 
32985
  ChooseCategoriesByStringConstraint (sfp->value_lists, scp, TRUE);
 
32986
  PointerToDialog (sfp->group_list_dlg, sfp->value_lists);
 
32987
  scp = StringConstraintXFree (scp);
 
32988
}
 
32989
 
 
32990
 
 
32991
static void CleanupSegregateByFieldForm (GraphiC g, VoidPtr data)
 
32992
 
 
32993
{
 
32994
  SegByFieldPtr      sfp;
 
32995
 
 
32996
  sfp = (SegByFieldPtr) data;
 
32997
  if (sfp != NULL) {
 
32998
    sfp->value_lists = FreeClickableList (sfp->value_lists);
 
32999
  }
 
33000
  StdCleanupFormProc (g, data);
 
33001
}
 
33002
 
 
33003
 
 
33004
 
 
33005
extern Int2 LIBCALLBACK SegregateSetsByField (Pointer data)
 
33006
{
 
33007
  GrouP              c;
 
33008
  SegByFieldPtr      cfp;
 
33009
  GrouP              h, k, page_grp, g1, g2, g3;
 
33010
  OMProcControlPtr   ompcp;
 
33011
  PrompT             p, p2;
 
33012
  StdEditorProcsPtr  sepp;
 
33013
  WindoW             w;
 
33014
  ButtoN             b;
 
33015
  StringConstraintData scd;
 
33016
 
 
33017
  /* Check parameters and get a pointer to the current data */
 
33018
 
 
33019
  ompcp = (OMProcControlPtr) data;
 
33020
  if (ompcp == NULL
 
33021
      || ompcp->input_itemtype != OBJ_BIOSEQSET 
 
33022
      || ompcp->input_data == NULL) {
 
33023
    Message (MSG_ERROR, "You must select a set to segregate!");
 
33024
    return OM_MSG_RET_ERROR;
 
33025
  } 
 
33026
 
 
33027
  /* Create a new window, and a struct */
 
33028
  /* to pass around the data in.       */
 
33029
 
 
33030
  cfp = (SegByFieldPtr) MemNew (sizeof (SegByFieldData));
 
33031
  if (cfp == NULL)
 
33032
    return OM_MSG_RET_ERROR;
 
33033
  cfp->target_set = (BioseqSetPtr)ompcp->input_data;
 
33034
 
 
33035
  w = FixedWindow (-50, -33, -10, -10, "Segregate By Field",
 
33036
                   StdCloseWindowProc);
 
33037
  SetObjectExtra (w, cfp, CleanupSegregateByFieldForm);
 
33038
  cfp->form = (ForM) w;
 
33039
 
 
33040
  sepp = (StdEditorProcsPtr) GetAppProperty ("StdEditorForm");
 
33041
  if (sepp != NULL) {
 
33042
    SetActivate (w, sepp->activateForm);
 
33043
    cfp->appmessage = sepp->handleMessages;
 
33044
  }
 
33045
 
 
33046
  cfp->input_entityID = ompcp->input_entityID;
 
33047
  cfp->input_itemID = ompcp->input_itemID;
 
33048
  cfp->input_itemtype = ompcp->input_itemtype;
 
33049
 
 
33050
  sepp = (StdEditorProcsPtr) GetAppProperty ("StdEditorForm");
 
33051
  if (sepp != NULL) {
 
33052
    SetActivate (w, sepp->activateForm);
 
33053
    cfp->appmessage = sepp->handleMessages;
 
33054
  }
 
33055
 
 
33056
  h = HiddenGroup (w, -1, 0, NULL);
 
33057
  SetGroupSpacing (h, 10, 10);
 
33058
 
 
33059
  cfp->group_list_dlg = CreateClickableListDialogEx (h, "New Sets", "Sequences for New Set",
 
33060
                                                      "Use checkbox to mark sets to create",
 
33061
                                                      "",
 
33062
                                                      ScrollToDiscrepancyItem, EditDiscrepancyItem, NULL,
 
33063
                                                      GetDiscrepancyItemText,
 
33064
                                                      stdCharWidth * 30,
 
33065
                                                      stdCharWidth * 30 + 5,
 
33066
                                                      TRUE, FALSE);
 
33067
 
 
33068
  g3 = NormalGroup (h, 2, 0, "", programFont, NULL);
 
33069
  SetGroupSpacing (g3, 10, 10);
 
33070
  StaticPrompt (g3, "Segregate Based on", 0, dialogTextHeight, programFont, 'c');
 
33071
  cfp->seg_choice_grp = HiddenGroup (g3, eNumSegPages, 0, ChangeSegChoice);
 
33072
  SetObjectExtra (cfp->seg_choice_grp, cfp, NULL);
 
33073
  SetGroupSpacing (cfp->seg_choice_grp, 10, 10);
 
33074
 
 
33075
  RadioButton (cfp->seg_choice_grp, "ID");
 
33076
  RadioButton (cfp->seg_choice_grp, "Text");
 
33077
  RadioButton (cfp->seg_choice_grp, "Field");
 
33078
  RadioButton (cfp->seg_choice_grp, "MolInfo");
 
33079
  RadioButton (cfp->seg_choice_grp, "Feature Type");
 
33080
  RadioButton (cfp->seg_choice_grp, "Descriptor Type");
 
33081
 
 
33082
  page_grp = HiddenGroup (h, 0, 0, NULL);
 
33083
  /* identical fields */
 
33084
  cfp->pages[eSegPageField - 1] = HiddenGroup (page_grp, 2, 0, NULL);
 
33085
  SetGroupSpacing (cfp->pages[eSegPageField - 1], 10, 10);
 
33086
  p = StaticPrompt (cfp->pages[eSegPageField - 1], "Segregate sequences with identical", 0, dialogTextHeight,
 
33087
                            programFont, 'c');  
 
33088
  cfp->field_dlg = ParseFieldDestDialog (cfp->pages[eSegPageField - 1], ChangeSegField, cfp);
 
33089
 
 
33090
  /* molinfo */
 
33091
  cfp->pages[eSegPageMolInfo - 1] = HiddenGroup (page_grp, 0, 2, NULL);
 
33092
  SetGroupSpacing (cfp->pages[eSegPageMolInfo - 1], 10, 10);
 
33093
  cfp->mol_class_btn = CheckBox (cfp->pages[eSegPageMolInfo - 1], "Molecule Class", ChangeMol);
 
33094
  SetObjectExtra (cfp->mol_class_btn, cfp, NULL);
 
33095
  SetStatus (cfp->mol_class_btn, TRUE);
 
33096
  cfp->mol_type_btn = CheckBox (cfp->pages[eSegPageMolInfo - 1], "Molecule Type", ChangeMol);
 
33097
  SetObjectExtra (cfp->mol_type_btn, cfp, NULL);
 
33098
  SetStatus (cfp->mol_type_btn, TRUE);
 
33099
 
 
33100
  /* features */
 
33101
  cfp->pages[eSegPageFeatureType - 1] = HiddenGroup (page_grp, 2, 0, NULL);
 
33102
  SetGroupSpacing (cfp->pages[eSegPageFeatureType - 1], 10, 10);
 
33103
  StaticPrompt (cfp->pages[eSegPageFeatureType - 1], "Segregate by Feature", 0, dialogTextHeight,
 
33104
                    programFont, 'c');
 
33105
  cfp->feature_select =  FeatureSelectionDialogEx (cfp->pages[eSegPageFeatureType - 1], FALSE, NULL,
 
33106
                                                   SegFeatureChangeNotify, 
 
33107
                                                   cfp);
 
33108
 
 
33109
  /* descriptors */
 
33110
  cfp->pages[eSegPageDescriptorType - 1] = HiddenGroup (page_grp, 2, 0, NULL);
 
33111
  SetGroupSpacing (cfp->pages[eSegPageDescriptorType - 1], 10, 10);
 
33112
  StaticPrompt (cfp->pages[eSegPageDescriptorType - 1], "Segregate by Descriptor", 0, dialogTextHeight,
 
33113
                programFont, 'c');
 
33114
  cfp->descriptor_select = DescriptorSelectionDialog (cfp->pages[eSegPageDescriptorType - 1], FALSE, 
 
33115
                                                      SegDescriptorChangeNotify, cfp);
 
33116
 
 
33117
  /* text */
 
33118
  cfp->pages[eSegPageText - 1] = HiddenGroup (page_grp, 4, 0, NULL);
 
33119
  SetGroupSpacing (cfp->pages[eSegPageText - 1], 10, 10);
 
33120
  StaticPrompt (cfp->pages[eSegPageText - 1], "Create set with sequences where", 0, dialogTextHeight, programFont, 'l');
 
33121
  cfp->search_text = DialogText (cfp->pages[eSegPageText - 1], "", 10, SegTextChange);
 
33122
  SetObjectExtra (cfp->search_text, cfp, NULL);
 
33123
  StaticPrompt (cfp->pages[eSegPageText - 1], "appears in", 0, dialogTextHeight, programFont, 'l');
 
33124
  cfp->search_field = SearchFieldDialog (cfp->pages[eSegPageText - 1], SegTextChangeNotify, cfp);
 
33125
 
 
33126
  /* id */
 
33127
  cfp->pages[eSegPageId - 1] = HiddenGroup (page_grp, -1, 0, NULL);
 
33128
  SetGroupSpacing (cfp->pages[eSegPageId - 1], 10, 10);
 
33129
  p2 = StaticPrompt (cfp->pages[eSegPageId - 1], "Create set with marked sequences", 0, dialogTextHeight, programFont, 'l');
 
33130
  g1 = HiddenGroup (cfp->pages[eSegPageId - 1], 3, 0, NULL);
 
33131
  g2 = HiddenGroup (cfp->pages[eSegPageId - 1], 2, 0, NULL);
 
33132
  cfp->id_constraint = StringConstraintDialogX (g2, "Mark sequences where sequence ID", TRUE);
 
33133
  scd.insensitive = TRUE;
 
33134
  scd.match_location = eStringConstraintInList;
 
33135
  scd.match_text = NULL;
 
33136
  scd.not_present = FALSE;
 
33137
  scd.whole_word = FALSE;
 
33138
  PointerToDialog (cfp->id_constraint, &scd);
 
33139
  b = PushButton (g2, "Mark", SelectSequenceIDsForSegregate);
 
33140
  SetObjectExtra (b, cfp, NULL);
 
33141
  AlignObjects (ALIGN_CENTER, (HANDLE) p2, (HANDLE) g1, (HANDLE) g2, NULL);
 
33142
 
 
33143
  AlignObjects (ALIGN_CENTER, (HANDLE) cfp->pages[0],
 
33144
                                    (HANDLE) cfp->pages[1], 
 
33145
                                                                        (HANDLE) cfp->pages[2], 
 
33146
                              (HANDLE) cfp->pages[3],
 
33147
                              (HANDLE) cfp->pages[4],
 
33148
                              (HANDLE) cfp->pages[5],
 
33149
                              NULL);
 
33150
 
 
33151
  SetValue (cfp->seg_choice_grp, 1);
 
33152
 
 
33153
  /* add select all/unselect all buttons */
 
33154
  k = HiddenGroup (h, 2, 0, NULL);
 
33155
  b = PushButton (k, "Mark All", SelectSegCategories);
 
33156
  SetObjectExtra (b, cfp, NULL);
 
33157
  b = PushButton (k, "Unmark All", UnselectSegCategories);
 
33158
  SetObjectExtra (b, cfp, NULL);  
 
33159
 
 
33160
 
 
33161
  /* Add Accept and Cancel buttons */
 
33162
 
 
33163
  c = HiddenGroup (h, 3, 0, NULL);
 
33164
  cfp->accept = DefaultButton (c, "Accept", SegregateByField_Callback);
 
33165
  SetObjectExtra (cfp->accept, cfp, NULL);
 
33166
  Disable (cfp->accept);
 
33167
  PushButton (c, "Cancel", StdCancelButtonProc);
 
33168
  cfp->leave_dlg_up = CheckBox (c, "Leave Dialog Up", NULL);
 
33169
 
 
33170
  /* Line things up nicely */
 
33171
 
 
33172
  AlignObjects (ALIGN_CENTER, (HANDLE) g3,
 
33173
                              (HANDLE) cfp->group_list_dlg,
 
33174
                              (HANDLE) page_grp,
 
33175
                                                          (HANDLE) k,
 
33176
                              (HANDLE) c, NULL);
 
33177
 
 
33178
  /* initialize the display */
 
33179
  ChangeSegChoice (cfp->seg_choice_grp);
 
33180
 
 
33181
  /* Display the window now */
 
33182
 
 
33183
  RealizeWindow (w);
 
33184
  Show (w);
 
33185
  Select (w);
 
33186
  Select (cfp->accept);
 
33187
  Update ();
 
33188
  return OM_MSG_RET_OK;
 
33189
}
 
33190
 
 
33191
typedef struct fixcase {
 
33192
  FORM_MESSAGE_BLOCK
 
33193
  DialoG       field_dlg;
 
33194
  DialoG       case_dlg;  
 
33195
  ButtoN       accept;
 
33196
  ButtoN       leave_dlg_up;
 
33197
 
 
33198
  ValNodePtr               requested_field;
 
33199
  GetFeatureFieldString    fieldstring_func;
 
33200
  GetDescriptorFieldString descrstring_func;
 
33201
  SetFeatureFieldString    feature_apply_action;
 
33202
  SetDescriptorFieldString descriptor_apply_action;
 
33203
  FreeValNodeProc          free_vn_proc;
 
33204
  CopyValNodeDataProc      copy_vn_proc;
 
33205
  ChangeCasePtr            ccp;
 
33206
  ValNodePtr               orgnames;
 
33207
} FixCaseData, PNTR FixCasePtr;
 
33208
 
 
33209
 
 
33210
static void FixCaseFeatureCallback (SeqFeatPtr sfp, Pointer userdata, FilterSetPtr fsp)
 
33211
{
 
33212
  FixCasePtr     fcp;
 
33213
  CharPtr        str;
 
33214
  ApplyValueData avd;
 
33215
 
 
33216
  if (sfp == NULL || userdata == NULL) return;
 
33217
  fcp = (FixCasePtr) userdata;
 
33218
  if (fcp->fieldstring_func == NULL || fcp->feature_apply_action == NULL
 
33219
      || fcp->ccp == NULL || fcp->ccp->change == eChangeCaseNone) 
 
33220
  {
 
33221
    return;
 
33222
  }
 
33223
  
 
33224
  str = fcp->fieldstring_func (sfp, fcp->requested_field, fsp);
 
33225
  if (StringHasNoText (str)) {
 
33226
    str = MemFree (str);
 
33227
    return;
 
33228
  } else {
 
33229
    avd.text_to_replace = NULL;
 
33230
    avd.where_to_replace = EditApplyFindLocation_anywhere;
 
33231
    avd.etp = NULL;
 
33232
    avd.field_list = fcp->requested_field;
 
33233
    ChangeCase (&str, fcp->ccp, fcp->orgnames);
 
33234
    avd.new_text = str;
 
33235
    (fcp->feature_apply_action) (sfp, &avd, fsp);
 
33236
  }
 
33237
}
 
33238
 
 
33239
static void FixCaseDescriptorCallback (SeqDescrPtr sdp, Pointer userdata, FilterSetPtr fsp)
 
33240
{
 
33241
  FixCasePtr     fcp;
 
33242
  CharPtr        str;
 
33243
  ApplyValueData avd;
 
33244
 
 
33245
  if (sdp == NULL || userdata == NULL) return;
 
33246
  fcp = (FixCasePtr) userdata;
 
33247
  if (fcp->descrstring_func == NULL || fcp->descriptor_apply_action == NULL
 
33248
      || fcp->ccp == NULL || fcp->ccp->change == eChangeCaseNone) 
 
33249
  {
 
33250
    return;
 
33251
  }
 
33252
  
 
33253
  str = fcp->descrstring_func (sdp, fcp->requested_field, fsp);
 
33254
  if (StringHasNoText (str)) {
 
33255
    str = MemFree (str);
 
33256
    return;
 
33257
  } else {
 
33258
    avd.text_to_replace = NULL;
 
33259
    avd.where_to_replace = EditApplyFindLocation_anywhere;
 
33260
    avd.etp = NULL;
 
33261
    avd.field_list = fcp->requested_field;
 
33262
    ChangeCase (&str, fcp->ccp, fcp->orgnames);
 
33263
    avd.new_text = str;
 
33264
    (fcp->descriptor_apply_action) (sdp, &avd, fsp);
 
33265
  }
 
33266
}
 
33267
 
 
33268
 
 
33269
static void FixCaseByFieldCallback (ButtoN b)
 
33270
{
 
33271
  FixCasePtr  fcp;
 
33272
  SeqEntryPtr sep;
 
33273
  ParseFieldPtr dst_field_data;
 
33274
  FilterSetPtr fsp = NULL;
 
33275
  ValNodePtr   vnp;
 
33276
 
 
33277
  fcp = (FixCasePtr) GetObjectExtra (b);
 
33278
  if (fcp == NULL) return;
 
33279
 
 
33280
  sep = GetTopSeqEntryForEntityID (fcp->input_entityID);
 
33281
 
 
33282
  if (sep == NULL) return;
 
33283
  
 
33284
  dst_field_data = DialogToPointer (fcp->field_dlg);
 
33285
  if (dst_field_data == NULL) return;
 
33286
  fcp->ccp = DialogToPointer (fcp->case_dlg);
 
33287
  if (fcp->ccp == NULL || fcp->ccp->change == eChangeCaseNone) {
 
33288
    dst_field_data = ParseFieldFree (dst_field_data);
 
33289
    fcp->ccp = MemFree (fcp->ccp);
 
33290
    return;
 
33291
  }
 
33292
 
 
33293
  WatchCursor();
 
33294
  Update();
 
33295
 
 
33296
  /* if we will be fixing capitalization, get org names to use in fixes */
 
33297
  if (dst_field_data->parse_field_type != PARSE_FIELD_BIOSRC_STRING
 
33298
      || dst_field_data->feature_field == NULL
 
33299
      || dst_field_data->feature_field->data.intvalue != PARSE_FIELD_BIOSRC_TAXNAME) {
 
33300
    VisitBioSourcesInSep (sep, &(fcp->orgnames), GetOrgNamesInRecordCallback);
 
33301
  }
 
33302
 
 
33303
  switch (dst_field_data->parse_field_type)
 
33304
  {
 
33305
    case PARSE_FIELD_SOURCE_QUAL :
 
33306
      fcp->fieldstring_func = GetSourceQualFeatureString;
 
33307
      fcp->descrstring_func = GetSourceQualDescrString;
 
33308
      fcp->feature_apply_action = ApplySourceQualFeatureCallback;
 
33309
      fcp->descriptor_apply_action = ApplySourceQualDescriptorCallback,
 
33310
      fcp->free_vn_proc = ValNodeSimpleDataFree;
 
33311
      fcp->copy_vn_proc = SourceQualValNodeDataCopy;
 
33312
      fcp->requested_field = dst_field_data->feature_field;
 
33313
      OperateOnSeqEntryConstrainedObjects (sep, fsp, FixCaseFeatureCallback, 
 
33314
                                           FixCaseDescriptorCallback,
 
33315
                                           SEQFEAT_BIOSRC, 0,
 
33316
                                           Seq_descr_source, fcp);
 
33317
 
 
33318
      break;
 
33319
    case PARSE_FIELD_DEFLINE:
 
33320
      fcp->fieldstring_func = NULL;
 
33321
      fcp->descrstring_func = GetStringFromStringDescriptor;
 
33322
      fcp->feature_apply_action = NULL;
 
33323
      fcp->descriptor_apply_action = ApplyTitleDescriptorCallback;
 
33324
      fcp->free_vn_proc = NULL;
 
33325
      fcp->copy_vn_proc = IntValNodeCopy;
 
33326
      fcp->requested_field = ValNodeNew (NULL);
 
33327
      fcp->requested_field->data.intvalue = Seq_descr_title;
 
33328
      OperateOnSeqEntryConstrainedObjects (sep, fsp, NULL, 
 
33329
                                           FixCaseDescriptorCallback,
 
33330
                                           0, 0,
 
33331
                                           Seq_descr_title, fcp);
 
33332
      fcp->requested_field = ValNodeFree (fcp->requested_field);
 
33333
 
 
33334
      break;
 
33335
    case PARSE_FIELD_BIOSRC_STRING:
 
33336
      fcp->fieldstring_func = GetSourceFeatureString;
 
33337
      fcp->descrstring_func = GetSourceDescriptorString;
 
33338
      fcp->feature_apply_action = ApplySourceStringFeatureCallback;
 
33339
      fcp->descriptor_apply_action = ApplySourceStringDescriptorCallback;
 
33340
      fcp->free_vn_proc = NULL;
 
33341
      fcp->copy_vn_proc = IntValNodeCopy;
 
33342
      fcp->requested_field = dst_field_data->feature_field;
 
33343
      OperateOnSeqEntryConstrainedObjects (sep, fsp, FixCaseFeatureCallback, 
 
33344
                                           FixCaseDescriptorCallback,
 
33345
                                           SEQFEAT_BIOSRC, 0,
 
33346
                                           Seq_descr_source, fcp);
 
33347
      break;
 
33348
    case PARSE_FIELD_DBXREF:
 
33349
      fcp->fieldstring_func = GetBioSourceFeatureDbxrefString;
 
33350
      fcp->descrstring_func = GetBioSourceDescriptorDbxrefString;
 
33351
      fcp->feature_apply_action = ApplyBioSourceDbxrefFeatureCallback;
 
33352
      fcp->descriptor_apply_action = ApplyBioSourceDbxrefDescriptorCallback;
 
33353
      fcp->free_vn_proc = ValNodeSimpleDataFree;
 
33354
      fcp->copy_vn_proc = ValNodeStringCopy;
 
33355
      fcp->requested_field = dst_field_data->feature_field;
 
33356
      OperateOnSeqEntryConstrainedObjects (sep, fsp, FixCaseFeatureCallback, 
 
33357
                                           FixCaseDescriptorCallback,
 
33358
                                           SEQFEAT_BIOSRC, 0,
 
33359
                                           Seq_descr_source, fcp);
 
33360
      break;
 
33361
    case PARSE_FIELD_GENE_FIELD:
 
33362
      fcp->fieldstring_func = GetGeneFieldString;
 
33363
      fcp->descrstring_func = NULL;
 
33364
      fcp->feature_apply_action = SetGeneFieldString;
 
33365
      fcp->descriptor_apply_action = NULL;
 
33366
      fcp->free_vn_proc = NULL;
 
33367
      fcp->copy_vn_proc = IntValNodeCopy;
 
33368
      fcp->requested_field = dst_field_data->feature_field;
 
33369
      OperateOnSeqEntryConstrainedObjects (sep, fsp, FixCaseFeatureCallback, 
 
33370
                                           NULL,
 
33371
                                           SEQFEAT_GENE, 0,
 
33372
                                           0, fcp);
 
33373
      break;
 
33374
    case PARSE_FIELD_RNA_FIELD:
 
33375
      fcp->fieldstring_func = GetRNAFieldString;
 
33376
      fcp->descrstring_func = NULL;
 
33377
      fcp->feature_apply_action = SetRNAFieldString;
 
33378
      fcp->descriptor_apply_action = NULL;
 
33379
      fcp->free_vn_proc = NULL;
 
33380
      fcp->copy_vn_proc = IntValNodeCopy;
 
33381
      fcp->requested_field = dst_field_data->feature_field;
 
33382
      OperateOnSeqEntryConstrainedObjects (sep, fsp, FixCaseFeatureCallback, 
 
33383
                                           NULL,
 
33384
                                           SEQFEAT_RNA,
 
33385
                                           dst_field_data->feature_subtype == NULL ? 0 : dst_field_data->feature_subtype->data.intvalue,
 
33386
                                           0, fcp);
 
33387
      break;
 
33388
    case PARSE_FIELD_CDS_COMMENT:
 
33389
      fcp->fieldstring_func = GetCDSComment;
 
33390
      fcp->descrstring_func = NULL;
 
33391
      fcp->feature_apply_action = SetCDSComment;
 
33392
      fcp->descriptor_apply_action = NULL;
 
33393
      fcp->free_vn_proc = NULL;
 
33394
      fcp->copy_vn_proc = IntValNodeCopy;
 
33395
      fcp->requested_field = dst_field_data->feature_field;
 
33396
      OperateOnSeqEntryConstrainedObjects (sep, fsp, FixCaseFeatureCallback, 
 
33397
                                           NULL,
 
33398
                                           SEQFEAT_CDREGION, FEATDEF_CDS,
 
33399
                                           0, fcp);
 
33400
      break;
 
33401
    case PARSE_FIELD_COMMENT_DESC:
 
33402
      fcp->requested_field = ValNodeNew (NULL);
 
33403
      fcp->requested_field->data.intvalue = Seq_descr_comment;
 
33404
      fcp->fieldstring_func = NULL;
 
33405
      fcp->descrstring_func = GetStringFromStringDescriptor;
 
33406
      fcp->feature_apply_action = NULL;
 
33407
      fcp->descriptor_apply_action = ApplyTitleDescriptorCallback;
 
33408
      fcp->free_vn_proc = NULL;
 
33409
      fcp->copy_vn_proc = IntValNodeCopy;
 
33410
      OperateOnSeqEntryConstrainedObjects (sep, fsp, NULL, 
 
33411
                                           FixCaseDescriptorCallback,
 
33412
                                           0, 0,
 
33413
                                           Seq_descr_comment, fcp);
 
33414
      fcp->requested_field = ValNodeFree (fcp->requested_field);
 
33415
      break;
 
33416
    case PARSE_FIELD_PROTEIN_FIELD:
 
33417
      fcp->fieldstring_func = GetProteinFieldString;
 
33418
      fcp->descrstring_func = NULL;
 
33419
      fcp->feature_apply_action = SetProteinFieldString;
 
33420
      fcp->descriptor_apply_action = NULL;
 
33421
      fcp->free_vn_proc = NULL;
 
33422
      fcp->copy_vn_proc = IntValNodeCopy;
 
33423
      fcp->requested_field = dst_field_data->feature_field;
 
33424
      OperateOnSeqEntryConstrainedObjects (sep, fsp, FixCaseFeatureCallback, 
 
33425
                                           NULL,
 
33426
                                           SEQFEAT_PROT, 0,
 
33427
                                           0, fcp);
 
33428
      break;
 
33429
    case PARSE_FIELD_IMPORT_QUAL:
 
33430
      fcp->requested_field = dst_field_data->feature_field;
 
33431
      fcp->fieldstring_func = GetGBQualString;
 
33432
      fcp->descrstring_func = NULL;
 
33433
      fcp->feature_apply_action = SetGBQualString;
 
33434
      fcp->descriptor_apply_action = NULL;
 
33435
      fcp->free_vn_proc = NULL;
 
33436
      fcp->copy_vn_proc = IntValNodeCopy;
 
33437
 
 
33438
      for (vnp = dst_field_data->feature_subtype; vnp != NULL; vnp = vnp->next)
 
33439
      {
 
33440
        OperateOnSeqEntryConstrainedObjects (sep, fsp, FixCaseFeatureCallback, 
 
33441
                                             NULL,
 
33442
                                             0, vnp->choice,
 
33443
                                             0, fcp);
 
33444
      }
 
33445
      break;
 
33446
    case PARSE_FIELD_FEATURE_NOTE:
 
33447
      fcp->fieldstring_func = GetFeatureNote;
 
33448
      fcp->descrstring_func = NULL;
 
33449
      fcp->feature_apply_action = SetFeatureNote;
 
33450
      fcp->descriptor_apply_action = NULL;
 
33451
      fcp->free_vn_proc = ValNodeSimpleDataFree;
 
33452
      fcp->copy_vn_proc = ValNodeStringCopy;
 
33453
 
 
33454
      for (vnp = dst_field_data->feature_field; vnp != NULL; vnp = vnp->next)
 
33455
      {
 
33456
        fcp->requested_field = vnp;
 
33457
        OperateOnSeqEntryConstrainedObjects (sep, fsp, FixCaseFeatureCallback, 
 
33458
                                             NULL,
 
33459
                                             0, vnp->choice,
 
33460
                                             0, fcp);
 
33461
      }
 
33462
      break;
 
33463
  }
 
33464
  fcp->orgnames = ValNodeFree (fcp->orgnames);
 
33465
  dst_field_data = ParseFieldFree (dst_field_data);
 
33466
  fcp->ccp = MemFree (fcp->ccp);
 
33467
 
 
33468
  ObjMgrSetDirtyFlag (fcp->input_entityID, TRUE);
 
33469
  ObjMgrSendMsg (OM_MSG_UPDATE, fcp->input_entityID, 0, 0);
 
33470
  ArrowCursor ();
 
33471
  Update ();
 
33472
 
 
33473
  if (!GetStatus (fcp->leave_dlg_up)) {
 
33474
    Remove (fcp->form);
 
33475
  }
 
33476
}
 
33477
 
 
33478
extern void FixCaseByField (IteM i)
 
33479
{
 
33480
  GrouP              c;
 
33481
  FixCasePtr         cfp;
 
33482
  ChangeCaseData     ccd;
 
33483
  GrouP              h;
 
33484
  WindoW             w;
 
33485
  BaseFormPtr  bfp;
 
33486
 
 
33487
#ifdef WIN_MAC
 
33488
  bfp = currentFormDataPtr;
 
33489
#else
 
33490
  bfp = GetObjectExtra (i);
 
33491
#endif
 
33492
  if (bfp == NULL) return;
 
33493
 
 
33494
  /* Create a new window, and a struct */
 
33495
  /* to pass around the data in.       */
 
33496
 
 
33497
  cfp = (FixCasePtr) MemNew (sizeof (FixCaseData));
 
33498
  if (cfp == NULL)
 
33499
    return;
 
33500
 
 
33501
  w = FixedWindow (-50, -33, -10, -10, "Fix Case By Field",
 
33502
                   StdCloseWindowProc);
 
33503
  SetObjectExtra (w, cfp, StdCleanupFormProc);
 
33504
  cfp->form = (ForM) w;
 
33505
  cfp->input_entityID = bfp->input_entityID;
 
33506
 
 
33507
  h = HiddenGroup (w, -1, 0, NULL);
 
33508
  SetGroupSpacing (h, 10, 10);
 
33509
 
 
33510
  cfp->field_dlg = ParseFieldDestDialogEx (h, NULL, NULL, FALSE, TRUE);
 
33511
 
 
33512
  cfp->case_dlg = ChangeCaseDialog (h);
 
33513
  ccd.change = eChangeCaseAllLower;
 
33514
  PointerToDialog (cfp->case_dlg, &ccd);
 
33515
 
 
33516
  /* Add Accept and Cancel buttons */
 
33517
 
 
33518
  c = HiddenGroup (h, 3, 0, NULL);
 
33519
  cfp->accept = DefaultButton (c, "Accept", FixCaseByFieldCallback);
 
33520
  SetObjectExtra (cfp->accept, cfp, NULL);
 
33521
  PushButton (c, "Cancel", StdCancelButtonProc);
 
33522
  cfp->leave_dlg_up = CheckBox (c, "Leave Dialog Up", NULL);
 
33523
 
 
33524
  /* Line things up nicely */
 
33525
 
 
33526
  AlignObjects (ALIGN_CENTER, (HANDLE) cfp->field_dlg,
 
33527
                              (HANDLE) cfp->case_dlg,
 
33528
                              (HANDLE) c, NULL);
 
33529
 
 
33530
 
 
33531
  /* Display the window now */
 
33532
 
 
33533
  RealizeWindow (w);
 
33534
  Show (w);
 
33535
  Select (w);
 
33536
  Select (cfp->accept);
 
33537
  Update ();
 
33538
}
 
33539
 
 
33540
static void FormatBoxColumn (ColPtr col)
 
33541
{
 
33542
  if (col == NULL) return;
 
33543
  col->pixWidth = stdCharWidth;
 
33544
  col->pixInset = 0;
 
33545
  col->charWidth = 0;
 
33546
  col->charInset = 0;
 
33547
  col->font = NULL;
 
33548
  col->just = 'l';
 
33549
  col->wrap = 1;
 
33550
  col->bar = 0;
 
33551
  col->underline = 0;
 
33552
  col->left = 0;
 
33553
  col->last = FALSE;
 
33554
}
 
33555
 
 
33556
static ColPtr AllocateDocColumnsForFieldList (BulkEdFieldPtr field_list, Int4Ptr p_len, Int4 last_sorted_col)
 
33557
{
 
33558
  Int4   i, num_columns = 3, len = 0, col;
 
33559
  ColPtr col_list;
 
33560
 
 
33561
  if (field_list == NULL) {
 
33562
    return NULL;
 
33563
  }
 
33564
 
 
33565
  /* set the font so that the pixwidth will be correct */
 
33566
  SelectFont (programFont);
 
33567
 
 
33568
  /* start with 3 columns, one for expand/collapse and one for checkbox for row selection and one for final blank */
 
33569
  for (i = 0; field_list[i].name != NULL; i++) {
 
33570
    num_columns ++;
 
33571
  }
 
33572
  col_list = (ColPtr) MemNew (num_columns * sizeof (ColData));
 
33573
  col = 0;
 
33574
  FormatBoxColumn (col_list + col);
 
33575
  len += col_list[col].pixWidth;
 
33576
  col++;
 
33577
 
 
33578
  for (i = 0; field_list[i].name != NULL; i++) {
 
33579
    if (i == last_sorted_col) {
 
33580
      FormatBoxColumn (col_list + col);
 
33581
      len += col_list[col].pixWidth;
 
33582
      col++;
 
33583
    }
 
33584
    len += (field_list[i].format_col_func) (col_list + col, field_list[i].name);
 
33585
    col_list[col].last = FALSE;
 
33586
    col++;
 
33587
  }
 
33588
  
 
33589
  /* final blank column */
 
33590
  col_list[col].pixWidth = 0;
 
33591
  col_list[col].pixInset = 0;
 
33592
  col_list[col].charWidth = 0;
 
33593
  col_list[col].charInset = 0;
 
33594
  col_list[col].font = NULL;
 
33595
  col_list[col].just = 'l';
 
33596
  col_list[col].wrap = 1;
 
33597
  col_list[col].bar = 0;
 
33598
  col_list[col].underline = 0;
 
33599
  col_list[col].left = 0;
 
33600
  col_list[col].last = TRUE;
 
33601
  if (p_len != NULL) {
 
33602
    *p_len = len;
 
33603
  }
 
33604
  return col_list;
 
33605
}
 
33606
 
 
33607
typedef struct bulkeditorrow {
 
33608
  ValNodePtr values_list;
 
33609
  ValNodePtr object_list;
 
33610
  struct bulkeditorrow PNTR subrows;
 
33611
  Int4       copied_to_meta;
 
33612
  Int4       copied_to_sub;
 
33613
  Boolean    expanded;
 
33614
  Boolean    selected;
 
33615
} BulkEditorRowData, PNTR BulkEditorRowPtr;
 
33616
 
 
33617
static ValNodePtr FreeBulkEditorValues (ValNodePtr values, BulkEdFieldPtr field_list)
 
33618
{
 
33619
  ValNodePtr       vnp;
 
33620
  Int4             col;
 
33621
 
 
33622
  for (col = 0, vnp = values;
 
33623
       vnp != NULL;
 
33624
       col++, vnp = vnp->next) {
 
33625
    if (field_list[col].free_func == NULL) {
 
33626
      vnp->data.ptrvalue = MemFree (vnp->data.ptrvalue);
 
33627
    } else {
 
33628
      (field_list[col].free_func) (vnp->data.ptrvalue);
 
33629
      vnp->data.ptrvalue = NULL;
 
33630
    }
 
33631
  }
 
33632
  values = ValNodeFree (values);
 
33633
  return values;
 
33634
}
 
33635
 
 
33636
static void FreeBulkEditorValuesList (ValNodePtr PNTR values_list, Int4 num_rows, BulkEdFieldPtr field_list)
 
33637
{
 
33638
  Int4             i;
 
33639
 
 
33640
  if (values_list == NULL || field_list == NULL) return;
 
33641
  for (i = 0; i < num_rows; i++) {
 
33642
    values_list[i] = FreeBulkEditorValues (values_list[i], field_list);
 
33643
  }
 
33644
  values_list = MemFree (values_list);
 
33645
}
 
33646
 
 
33647
static BulkEditorRowPtr FreeBulkEditorRows (BulkEditorRowPtr rows, BulkEdFieldPtr field_list)
 
33648
{
 
33649
  Int4 row_num;
 
33650
 
 
33651
  if (rows == NULL) return NULL;
 
33652
  for (row_num = 0; rows[row_num].object_list != NULL; row_num++) {
 
33653
    rows[row_num].values_list = FreeBulkEditorValues (rows[row_num].values_list, field_list);
 
33654
    rows[row_num].object_list = ValNodeFree (rows[row_num].object_list);
 
33655
    FreeBulkEditorRows (rows[row_num].subrows, field_list);
 
33656
    rows[row_num].subrows = NULL;
 
33657
  }
 
33658
  rows = MemFree (rows);
 
33659
  return rows;
 
33660
}
 
33661
 
 
33662
static void CopyToSingleBulkEditRow (BulkEditorRowPtr dst, BulkEditorRowPtr src, BulkEdFieldPtr field_list)
 
33663
{
 
33664
  ValNodePtr vnp;
 
33665
  Int4       col;
 
33666
 
 
33667
  if (dst == NULL || src == NULL) return;
 
33668
  
 
33669
  /* copy values */
 
33670
  dst->values_list = NULL;
 
33671
  for (vnp = src->values_list, col = 0; vnp != NULL; vnp = vnp->next, col++) {
 
33672
    ValNodeAddPointer (&(dst->values_list), vnp->choice, field_list[col].copy_func(vnp->data.ptrvalue));
 
33673
  }
 
33674
 
 
33675
  /* copy object */
 
33676
  dst->object_list = NULL;
 
33677
  ValNodeAddPointer (&(dst->object_list), src->object_list->choice, src->object_list->data.ptrvalue);
 
33678
 
 
33679
  /* copy selection */
 
33680
  dst->selected = src->selected;
 
33681
}
 
33682
 
 
33683
static void ExpandAllBulkEditRows (BulkEditorRowPtr row_list) 
 
33684
{
 
33685
  Int4 row_num;
 
33686
 
 
33687
  if (row_list == NULL) return;
 
33688
  for (row_num = 0; row_list[row_num].object_list != NULL; row_num++) {
 
33689
    if (row_list[row_num].subrows != NULL) {
 
33690
      row_list[row_num].expanded = TRUE;
 
33691
    }
 
33692
  }
 
33693
}
 
33694
 
 
33695
static void CollapseAllBulkEditRows (BulkEditorRowPtr row_list) 
 
33696
{
 
33697
  Int4 row_num;
 
33698
 
 
33699
  if (row_list == NULL) return;
 
33700
  for (row_num = 0; row_list[row_num].object_list != NULL; row_num++) {
 
33701
    if (row_list[row_num].subrows != NULL) {
 
33702
      row_list[row_num].expanded = FALSE;
 
33703
    }
 
33704
  }
 
33705
}
 
33706
 
 
33707
 
 
33708
/* sort_col is zero-based data column, already corrected for selection and expansion columns */
 
33709
static CharPtr GetTextForBulkEditorRow (BulkEditorRowPtr berp, BulkEdFieldPtr field_list, Int4 sort_col)
 
33710
{
 
33711
  ValNodePtr column_values = NULL, vnp;
 
33712
  Int4 text_len = 6, col;
 
33713
  CharPtr str, line_text = NULL, tmp_str;
 
33714
 
 
33715
  if (berp == NULL) return NULL;
 
33716
  for (vnp = berp->values_list, col = 0; vnp != NULL; vnp = vnp->next, col++) {
 
33717
    if (field_list[col].display_func == NULL) {
 
33718
      str = NULL;
 
33719
    } else {
 
33720
      str = (field_list[col].display_func)(vnp->data.ptrvalue);
 
33721
    }
 
33722
    if (str == NULL) {
 
33723
      str = StringSave ("");
 
33724
    }
 
33725
    if (berp->subrows != NULL && col == sort_col) {
 
33726
      tmp_str = (CharPtr) MemNew (sizeof (Char) * (18 + StringLen (str)));
 
33727
      sprintf (tmp_str, "%s%s(%d)", field_list[col].draw_col_func == NULL ? "" : " ",               
 
33728
                                    str, ValNodeLen (berp->object_list));
 
33729
      str = MemFree (str);
 
33730
      str = tmp_str;
 
33731
    }
 
33732
    ValNodeAddPointer (&column_values, 0, str);
 
33733
    text_len += StringLen (str) + 1;
 
33734
  }
 
33735
  line_text = (CharPtr) MemNew (text_len * sizeof (Char));
 
33736
  line_text[0] = 0;
 
33737
  /* add blank column for row selector */
 
33738
  StringCat (line_text, "\t");
 
33739
  for (vnp = column_values, col = 0; vnp != NULL; vnp = vnp->next, col++) {
 
33740
    if (col == sort_col) {
 
33741
      /* add blank column for expand/collapse */
 
33742
      StringCat (line_text, "\t");
 
33743
    }
 
33744
    StringCat (line_text, vnp->data.ptrvalue);
 
33745
    StringCat (line_text, "\t");
 
33746
  }
 
33747
  column_values = ValNodeFreeData (column_values);
 
33748
  /* add blank column at end, to allow last real column to be highlighted when blank */
 
33749
  StringCat (line_text, "\t\n");
 
33750
  return line_text;
 
33751
}
 
33752
 
 
33753
 
 
33754
static Boolean DataPosFromBulkEdDlgRow (Int2 row, BulkEditorRowPtr row_list, Int4Ptr pRowNum, Int4Ptr pSubNum)
 
33755
{
 
33756
  Int4 row_num = 0, sub_num;
 
33757
  Int2 display_row = 1;
 
33758
 
 
33759
  if (row < 1 || row_list == NULL || pRowNum == NULL || pSubNum == NULL) return FALSE;
 
33760
 
 
33761
  while (row_list[row_num].object_list != NULL) {
 
33762
    if (display_row == row) {
 
33763
      *pRowNum = row_num;
 
33764
      *pSubNum = -1;
 
33765
      return TRUE;
 
33766
    }
 
33767
    display_row++;
 
33768
    if (row_list[row_num].subrows != NULL && row_list[row_num].expanded) {
 
33769
      sub_num = 0;
 
33770
      while (display_row != row && row_list[row_num].subrows[sub_num].object_list != NULL) {
 
33771
        display_row++;
 
33772
        sub_num++;
 
33773
      }
 
33774
      if (row_list[row_num].subrows[sub_num].object_list == NULL) {
 
33775
        sub_num = -1;
 
33776
      } else {
 
33777
        if (display_row == row) {
 
33778
          *pRowNum = row_num;
 
33779
          *pSubNum = sub_num;
 
33780
          return TRUE;
 
33781
        }
 
33782
      }
 
33783
    }
 
33784
    row_num++;
 
33785
  }
 
33786
  *pRowNum = -1;
 
33787
  *pSubNum = -1;
 
33788
  return FALSE;
 
33789
}
 
33790
 
 
33791
 
 
33792
static Int4 BulkEdDlgRowFromDataPos (Int4 row_num, Int4 sub_num, BulkEditorRowPtr row_list)
 
33793
{
 
33794
  Int4 i, j, display_row = 1;
 
33795
  
 
33796
  if (row_list == NULL) return 0;
 
33797
  /* count subrows also passed */
 
33798
  for (i = 0; row_list[i].object_list != NULL && i < row_num; i++) {
 
33799
    display_row++;
 
33800
    if (row_list[i].subrows != NULL && row_list[i].expanded) {
 
33801
      for (j = 0; row_list[i].subrows[j].object_list != NULL; j++) {
 
33802
        display_row++;
 
33803
      }
 
33804
    }
 
33805
  }
 
33806
  if (sub_num > -1) {
 
33807
    display_row += sub_num + 1;
 
33808
  }
 
33809
  return display_row; 
 
33810
}
 
33811
 
 
33812
 
 
33813
static Int4 BulkEdDataColumnFromDocColumn (Int4 doc_col, Int4 sort_col)
 
33814
{
 
33815
  /* subtract offset (document maps first column to 1) */
 
33816
  doc_col--;
 
33817
  /* subtract selection column */
 
33818
  doc_col--;
 
33819
 
 
33820
  /* subtract expand/collapse column */
 
33821
  if (doc_col > sort_col && sort_col > -1) {
 
33822
    doc_col--;
 
33823
  }
 
33824
  return doc_col;
 
33825
}
 
33826
 
 
33827
 
 
33828
static ValNodePtr GetBulkEditorRowValueByColumn (BulkEditorRowPtr berp, Int4 col)
 
33829
{
 
33830
  Int4       i;
 
33831
  ValNodePtr vnp;
 
33832
 
 
33833
  if (col < 0) return NULL;
 
33834
 
 
33835
  for (i = 0, vnp = berp->values_list;
 
33836
       i < col && vnp != NULL;
 
33837
       i++, vnp = vnp->next) {}
 
33838
  return vnp;
 
33839
}
 
33840
 
 
33841
 
 
33842
static void SelectBulkEditorRows (BulkEditorRowPtr berp, Boolean val)
 
33843
{
 
33844
  if (berp == NULL) return;
 
33845
 
 
33846
  while (berp->object_list != NULL) {
 
33847
    berp->selected = val;
 
33848
    SelectBulkEditorRows (berp->subrows, val);
 
33849
    berp++;
 
33850
  }
 
33851
}
 
33852
 
 
33853
 
 
33854
static Int4 CountBulkEditorRowsSelected (BulkEditorRowPtr berp)
 
33855
{
 
33856
  Int4 num = 0;
 
33857
  if (berp == NULL) return 0;
 
33858
 
 
33859
  while (berp->object_list != NULL) {
 
33860
    if (berp->subrows == NULL) {
 
33861
      if (berp->selected) {
 
33862
        num++;
 
33863
      }
 
33864
    } else {
 
33865
      num+= CountBulkEditorRowsSelected (berp->subrows);
 
33866
    }
 
33867
    berp++;
 
33868
  }
 
33869
  return num;
 
33870
}
 
33871
 
 
33872
 
 
33873
static void GetBulkEditorSelectedObjects (BulkEditorRowPtr berp, ValNodePtr PNTR object_list)
 
33874
{
 
33875
  ValNodePtr vnp;
 
33876
  if (berp == NULL || object_list == NULL) return;
 
33877
 
 
33878
  while (berp->object_list != NULL) {
 
33879
    if (berp->subrows == NULL) {
 
33880
      if (berp->selected) {
 
33881
        for (vnp = berp->object_list; vnp != NULL; vnp = vnp->next) {
 
33882
          ValNodeAddPointer (object_list, vnp->choice, vnp->data.ptrvalue);
 
33883
        }
 
33884
      }
 
33885
    } else {
 
33886
      GetBulkEditorSelectedObjects (berp->subrows, object_list);
 
33887
    }
 
33888
    berp++;
 
33889
  }
 
33890
}
 
33891
 
 
33892
 
 
33893
static Boolean AllBulkEditorRowsSelected (BulkEditorRowPtr berp)
 
33894
{
 
33895
  if (berp == NULL) return FALSE;
 
33896
 
 
33897
  while (berp->object_list != NULL) {
 
33898
    /* note - don't need to check subrows, because metarow would
 
33899
     * have been unselected if any subrows were unselected */
 
33900
    if (!berp->selected) {
 
33901
      return FALSE;
 
33902
    }
 
33903
    berp++;
 
33904
  }
 
33905
  return TRUE;
 
33906
}
 
33907
 
 
33908
 
 
33909
static void SelectBulkEditorRowsByStringConstraint (BulkEditorRowPtr berp, BulkEdFieldPtr field_list, Int4 col, StringConstraintXPtr scp, Boolean val)
 
33910
{
 
33911
  ValNodePtr vnp;
 
33912
  CharPtr    str = NULL;
 
33913
  Boolean    match;
 
33914
 
 
33915
  if (berp == NULL || field_list == NULL || col < 0 || field_list[col].display_func == NULL) return;
 
33916
 
 
33917
  while (berp->object_list != NULL) {
 
33918
    if (berp->subrows == NULL) {
 
33919
      vnp = GetBulkEditorRowValueByColumn (berp, col);
 
33920
      if (vnp != NULL) {
 
33921
        str = field_list[col].display_func(vnp->data.ptrvalue);
 
33922
      }
 
33923
      match = DoesStringMatchConstraintX (str, scp);
 
33924
      str = MemFree (str);
 
33925
      if (scp != NULL && scp->not_present) {
 
33926
        match = !match;
 
33927
      }
 
33928
      if (match) {
 
33929
        berp->selected = val;
 
33930
      }
 
33931
    } else {
 
33932
      SelectBulkEditorRowsByStringConstraint (berp->subrows, field_list, col, scp, val);
 
33933
      berp->selected = AllBulkEditorRowsSelected (berp->subrows);
 
33934
    }
 
33935
    berp++;
 
33936
  }
 
33937
}
 
33938
 
 
33939
 
 
33940
/* call nulls and null values bigger */
 
33941
/* return 0 if a and b are equal, -1 if a is smaller, and 1 if b is smaller */
 
33942
static Int4 CompareBulkRowValues (Pointer val_a, Pointer val_b, BulkDisplayFieldFunc display_func)
 
33943
{
 
33944
  CharPtr str_a, str_b;
 
33945
  Int4    rval = 0;
 
33946
 
 
33947
  if (val_a == NULL && val_b == NULL) {
 
33948
    rval = 0;
 
33949
  } else if (val_a == NULL) {
 
33950
    rval = 1;
 
33951
  } else if (val_b == NULL) {
 
33952
    rval = -1;
 
33953
  } else if (display_func == NULL) {
 
33954
    rval = 0;
 
33955
  } else {
 
33956
    str_a = display_func(val_a);
 
33957
    str_b = display_func(val_b);
 
33958
    rval = StringCmp (str_a, str_b);
 
33959
  }
 
33960
  return rval;
 
33961
}
 
33962
 
 
33963
/* call nulls and null values bigger */
 
33964
/* return 0 if a and b are equal, -1 if a is smaller, and 1 if b is smaller */
 
33965
static Int4 CompareBulkRows (BulkEditorRowPtr row_a, BulkEditorRowPtr row_b, Int4 sort_column, BulkEdFieldPtr field_list)
 
33966
{
 
33967
  Int4 col;
 
33968
  ValNodePtr vnp_a, vnp_b;
 
33969
  Int4 rval = 0;
 
33970
 
 
33971
  if (row_a == NULL && row_b == NULL) {
 
33972
    rval = 0;
 
33973
  } else if (row_a == NULL) {
 
33974
    rval = 1;
 
33975
  } else if (row_b == NULL) {
 
33976
    rval = -1;
 
33977
  } else if (row_a->values_list == NULL && row_b->values_list == NULL) {
 
33978
    rval = 0;
 
33979
  } else if (row_a->values_list == NULL) {
 
33980
    rval = 1;
 
33981
  } else if (row_b->values_list == NULL) {
 
33982
    rval = -1;
 
33983
  } else {
 
33984
    col = 0;
 
33985
    vnp_a = GetBulkEditorRowValueByColumn (row_a, sort_column);
 
33986
    vnp_b = GetBulkEditorRowValueByColumn (row_b, sort_column);
 
33987
 
 
33988
    if (vnp_a == NULL && vnp_b == NULL) {
 
33989
      rval = 0;
 
33990
    } else if (vnp_a == NULL) {
 
33991
      rval = 1;
 
33992
    } else if (vnp_b == NULL) {
 
33993
      rval = -1;
 
33994
    } else {
 
33995
      rval = CompareBulkRowValues (vnp_a->data.ptrvalue, vnp_b->data.ptrvalue, field_list[sort_column].display_func);
 
33996
    }
 
33997
  }
 
33998
  return rval;
 
33999
}
 
34000
 
 
34001
static Int4 CountIndividualRows (BulkEditorRowPtr row_list)
 
34002
{
 
34003
  Int4 num_rows = 0, row_num;
 
34004
 
 
34005
  if (row_list == NULL) return 0;
 
34006
 
 
34007
  for (row_num = 0; row_list[row_num].object_list != NULL; row_num++) {
 
34008
    if (row_list[row_num].subrows == NULL) {
 
34009
      num_rows++;
 
34010
    } else {
 
34011
      num_rows += CountIndividualRows(row_list[row_num].subrows);
 
34012
    }
 
34013
  }
 
34014
  return num_rows;
 
34015
}
 
34016
 
 
34017
 
 
34018
static void SetDefaultCopiedToValues (BulkEditorRowPtr row_list)
 
34019
{
 
34020
  Int4 row_num;
 
34021
 
 
34022
  if (row_list == NULL) return;
 
34023
 
 
34024
  for (row_num = 0; row_list[row_num].object_list != NULL; row_num++) {
 
34025
    row_list[row_num].copied_to_meta = -1;
 
34026
    row_list[row_num].copied_to_sub = -1;
 
34027
    if (row_list[row_num].subrows != NULL) {
 
34028
      SetDefaultCopiedToValues(row_list[row_num].subrows);
 
34029
    }
 
34030
  }
 
34031
}
 
34032
 
 
34033
 
 
34034
static BulkEditorRowPtr ResortBulkEditorRows (BulkEditorRowPtr orig_rows, BulkEdFieldPtr field_list, Int4 new_sort_column)
 
34035
{
 
34036
  Int4 num_individual_rows = 0;
 
34037
  Int4 row_num, sub_num, last_inserted = 0, comp, col;
 
34038
  BulkEditorRowPtr new_rows = NULL, smallest, berp;
 
34039
  ValNodePtr       matches, vnp;
 
34040
  Boolean          any_left, all_selected;
 
34041
 
 
34042
  /* count individual rows (will need this many or fewer) */
 
34043
  num_individual_rows = CountIndividualRows(orig_rows);
 
34044
 
 
34045
  /* set default copied_to values */
 
34046
  SetDefaultCopiedToValues (orig_rows);
 
34047
  
 
34048
  new_rows = (BulkEditorRowPtr) MemNew (sizeof (BulkEditorRowData) * (num_individual_rows + 1));
 
34049
  MemSet (new_rows, 0, sizeof (BulkEditorRowData) * (num_individual_rows + 1));
 
34050
  any_left = TRUE;
 
34051
  while (any_left) {
 
34052
    smallest = NULL;
 
34053
    matches = NULL;
 
34054
    for (row_num = 0; orig_rows[row_num].object_list != NULL; row_num++) {
 
34055
      if (orig_rows[row_num].subrows != NULL) {
 
34056
        /* look in subrows */
 
34057
        for (sub_num = 0; orig_rows[row_num].subrows[sub_num].object_list != NULL; sub_num++) {
 
34058
          if (orig_rows[row_num].subrows[sub_num].copied_to_meta > -1) continue; /* already copied to other list */
 
34059
          if (smallest == NULL) {
 
34060
            smallest = orig_rows[row_num].subrows + sub_num;
 
34061
            ValNodeAddPointer (&matches, 0, orig_rows[row_num].subrows + sub_num);
 
34062
          } else {
 
34063
            comp = CompareBulkRows (orig_rows[row_num].subrows + sub_num, smallest, new_sort_column, field_list);
 
34064
            if (comp == 0) {
 
34065
              /* equal - add to list of matches */
 
34066
              ValNodeAddPointer (&matches, 0, orig_rows[row_num].subrows + sub_num);
 
34067
            } else if (comp < 0) {
 
34068
              /* smaller - make new smallest and list of matches */
 
34069
              smallest = orig_rows[row_num].subrows + sub_num;
 
34070
              matches = ValNodeFree (matches);
 
34071
              ValNodeAddPointer (&matches, 0, orig_rows[row_num].subrows + sub_num);
 
34072
            }
 
34073
            /* if it's bigger, leave it alone for now */
 
34074
          }
 
34075
        }
 
34076
      } else {
 
34077
        /* look at just this row */
 
34078
        if (orig_rows[row_num].copied_to_meta > -1) continue; /* already copied to other list */
 
34079
        if (smallest == NULL) {
 
34080
          smallest = orig_rows + row_num;
 
34081
          ValNodeAddPointer (&matches, 0, orig_rows + row_num);
 
34082
        } else {
 
34083
          comp = CompareBulkRows (orig_rows + row_num, smallest, new_sort_column, field_list);
 
34084
          if (comp == 0) {
 
34085
            /* equal - add to list of matches */
 
34086
            ValNodeAddPointer (&matches, 0, orig_rows + row_num);
 
34087
          } else if (comp < 0) {
 
34088
            /* smaller - make new smallest and list of matches */
 
34089
            smallest = orig_rows + row_num;
 
34090
            matches = ValNodeFree (matches);
 
34091
            ValNodeAddPointer (&matches, 0, orig_rows + row_num);
 
34092
          }
 
34093
          /* if it's bigger, leave it alone for now */
 
34094
        }
 
34095
      }
 
34096
    }
 
34097
    if (smallest == NULL) {
 
34098
      any_left = FALSE;
 
34099
    } else {
 
34100
      if (ValNodeLen (matches) > 1) {
 
34101
        /* make metarow */
 
34102
        /* add value for only sort column */
 
34103
        for (col = 0, vnp = smallest->values_list; vnp != NULL; col++, vnp = vnp->next) {
 
34104
          if (col == new_sort_column) {
 
34105
            ValNodeAddPointer (&(new_rows[last_inserted].values_list), vnp->choice, field_list[col].copy_func(vnp->data.ptrvalue));
 
34106
          } else {
 
34107
            ValNodeAddPointer (&(new_rows[last_inserted].values_list), 0, NULL);
 
34108
          }
 
34109
        }
 
34110
        /* add features and subrows */
 
34111
        new_rows[last_inserted].subrows = (BulkEditorRowPtr) MemNew (sizeof(BulkEditorRowData) * (ValNodeLen(matches) + 1));
 
34112
        MemSet (new_rows[last_inserted].subrows, 0, sizeof(BulkEditorRowData) * (ValNodeLen(matches) + 1));
 
34113
        all_selected = TRUE;
 
34114
        for (vnp = matches, sub_num = 0; vnp != NULL; vnp = vnp->next, sub_num++) {
 
34115
          berp = (vnp->data.ptrvalue);
 
34116
          ValNodeAddPointer (&(new_rows[last_inserted].object_list), berp->object_list->choice, berp->object_list->data.ptrvalue);
 
34117
          CopyToSingleBulkEditRow (new_rows[last_inserted].subrows + sub_num, berp, field_list);
 
34118
          berp->copied_to_meta = last_inserted;
 
34119
          berp->copied_to_sub = sub_num;
 
34120
          if (!berp->selected) {
 
34121
            all_selected = FALSE;
 
34122
          }
 
34123
        }
 
34124
        new_rows[last_inserted].selected = all_selected;
 
34125
      } else {
 
34126
        CopyToSingleBulkEditRow (new_rows + last_inserted, smallest, field_list);
 
34127
        smallest->copied_to_meta = last_inserted;
 
34128
        smallest->copied_to_sub = 0;
 
34129
      }
 
34130
      last_inserted++;
 
34131
      matches = ValNodeFree (matches);
 
34132
    }
 
34133
  }
 
34134
  return new_rows;     
 
34135
}
 
34136
 
 
34137
 
 
34138
/* sort_column is zero-based data column, already corrected for selection and expansion columns */
 
34139
static Boolean AllSubrowsSameValue (BulkEditorRowPtr berp, BulkEdFieldPtr field_list, Int4 sort_column)
 
34140
{
 
34141
  Int4 i;
 
34142
  Boolean all_same = TRUE;
 
34143
 
 
34144
  if (berp == NULL || berp->subrows == NULL || berp->subrows[0].object_list == NULL) {
 
34145
    return TRUE;
 
34146
  }
 
34147
  
 
34148
  for (i = 1; berp->subrows[i].object_list != NULL && all_same; i++) {
 
34149
    if (CompareBulkRows (berp->subrows + i - 1, berp->subrows + i, sort_column, field_list) != 0) {
 
34150
      all_same = FALSE;
 
34151
    }
 
34152
  }
 
34153
 
 
34154
  return all_same;
 
34155
}
 
34156
 
 
34157
 
 
34158
/* sort_column is zero-based data column, already corrected for selection and expansion columns */
 
34159
/* look to see if data in columns is different from data in editor */
 
34160
static Boolean AnyChangeInBulkFields (BulkEditorRowPtr berp, BulkEdFieldPtr field_list, DialoG editor, Int4 sort_column)
 
34161
{
 
34162
  Pointer    m_data;
 
34163
  ValNodePtr vnp;
 
34164
  Int4       comp;
 
34165
 
 
34166
  if (berp == NULL || berp->subrows == NULL || berp->subrows[0].object_list == NULL) return FALSE;
 
34167
  if (field_list == NULL || editor == NULL) return FALSE;
 
34168
 
 
34169
  if (!AllSubrowsSameValue (berp, field_list, sort_column)) {
 
34170
    return TRUE;
 
34171
  }
 
34172
 
 
34173
  /* find value for sort_column from first subrow */
 
34174
  vnp = GetBulkEditorRowValueByColumn (berp, sort_column);
 
34175
  
 
34176
  if (vnp == NULL) return TRUE;
 
34177
  
 
34178
  /* compare with data from editor */
 
34179
  m_data = DialogToPointer (editor);
 
34180
 
 
34181
  comp = CompareBulkRowValues (m_data, vnp->data.ptrvalue, field_list[sort_column].display_func);
 
34182
  
 
34183
  /* free data from editor */
 
34184
  if (field_list[sort_column].free_func) {
 
34185
    (field_list[sort_column].free_func)(m_data);
 
34186
  }
 
34187
  
 
34188
  if (comp == 0) {
 
34189
    return FALSE;
 
34190
  } else {
 
34191
    return TRUE;
 
34192
  }
 
34193
}
 
34194
 
 
34195
 
 
34196
/* col is zero-based data column, already corrected for selection and expansion columns */
 
34197
static void ApplyValueToOneBulkEditorRow (BulkEditorRowPtr berp, Int2 col, BulkEdFieldPtr field_list, DialoG editor)
 
34198
{
 
34199
  ValNodePtr vnp;
 
34200
 
 
34201
  if (berp == NULL || field_list == NULL ||  editor == NULL) return;
 
34202
 
 
34203
  vnp = GetBulkEditorRowValueByColumn (berp, col);
 
34204
 
 
34205
  if (vnp != NULL) {
 
34206
    if (field_list[col].free_func == NULL) {
 
34207
      vnp->data.ptrvalue = MemFree (vnp->data.ptrvalue);
 
34208
    } else {
 
34209
      (field_list[col].free_func) (vnp->data.ptrvalue);
 
34210
      vnp->data.ptrvalue = NULL;
 
34211
    }
 
34212
    vnp->data.ptrvalue = DialogToPointer (editor);
 
34213
  }
 
34214
}
 
34215
 
 
34216
 
 
34217
static void PopulateSingleBulkEditRowFromData (BulkEditorRowPtr berp, Uint1 data_choice, Pointer data, BulkEdFieldPtr field_list, Pointer metadata)
 
34218
{
 
34219
  Int4 col;
 
34220
 
 
34221
  /* add values for all columns */
 
34222
  for (col = 0; field_list[col].name != NULL; col++) {
 
34223
    ValNodeAddPointer (&(berp->values_list), 0, (field_list[col].get_func (data_choice, data, metadata)));
 
34224
  }
 
34225
  /* add feature */
 
34226
  ValNodeAddPointer (&(berp->object_list), data_choice, data);
 
34227
}
 
34228
 
 
34229
static BulkEditorRowPtr MakeBulkEditorRowsFromObjectList (ValNodePtr object_list, BulkEdFieldPtr field_list, Int4 sort_column, Pointer metadata)
 
34230
{
 
34231
  ValNodePtr       vnp;
 
34232
  BulkEditorRowPtr bulk_ed_rows = NULL, sorted_rows = NULL;
 
34233
  Int4             num_rows, row_num;
 
34234
 
 
34235
  if (object_list == NULL || field_list == NULL) return NULL;
 
34236
 
 
34237
  /* first, create list with one row per object */
 
34238
  num_rows = ValNodeLen (object_list);
 
34239
  
 
34240
  bulk_ed_rows = (BulkEditorRowPtr) MemNew (sizeof (BulkEditorRowData) * (num_rows + 1));
 
34241
  MemSet (bulk_ed_rows, 0, sizeof (BulkEditorRowData) * (num_rows + 1));
 
34242
 
 
34243
  for (vnp = object_list, row_num = 0; vnp != NULL; vnp = vnp->next, row_num++)
 
34244
  {
 
34245
    PopulateSingleBulkEditRowFromData (bulk_ed_rows + row_num, vnp->choice, vnp->data.ptrvalue, field_list, metadata); 
 
34246
  }
 
34247
 
 
34248
  if (sort_column >= 0)
 
34249
  {
 
34250
    /* Now resort rows for column */
 
34251
    sorted_rows = ResortBulkEditorRows (bulk_ed_rows, field_list, sort_column);
 
34252
    bulk_ed_rows = FreeBulkEditorRows (bulk_ed_rows, field_list);
 
34253
    bulk_ed_rows = sorted_rows;
 
34254
  }
 
34255
  return bulk_ed_rows;
 
34256
}
 
34257
 
 
34258
 
 
34259
static Int4 
 
34260
AddRowsToListBySelection 
 
34261
(BulkEditorRowPtr dest,
 
34262
 BulkEditorRowPtr src,
 
34263
 BulkEdFieldPtr   field_list,
 
34264
 Int4             last_inserted,
 
34265
 Boolean          selected)
 
34266
{
 
34267
  Int4 row_num;
 
34268
 
 
34269
  if (dest == NULL || src == NULL) return last_inserted;
 
34270
 
 
34271
  for (row_num = 0; src[row_num].object_list != NULL; row_num++) {
 
34272
    if (src[row_num].subrows == NULL) {
 
34273
      if ((src[row_num].selected && selected)
 
34274
          || (!src[row_num].selected && !selected)) {
 
34275
        CopyToSingleBulkEditRow (dest + last_inserted, src + row_num, field_list);
 
34276
        src[row_num].copied_to_meta = last_inserted;
 
34277
        src[row_num].copied_to_sub = 0;
 
34278
        last_inserted++;
 
34279
      }
 
34280
    } else {
 
34281
      last_inserted = AddRowsToListBySelection(dest, src[row_num].subrows, field_list, last_inserted, selected);
 
34282
    }
 
34283
  }
 
34284
  return last_inserted;
 
34285
}
 
34286
 
 
34287
static BulkEditorRowPtr ResortBulkEditorRowsBySelected (BulkEditorRowPtr orig_rows, BulkEdFieldPtr field_list)
 
34288
{
 
34289
  Int4 num_individual_rows;
 
34290
  Int4 last_inserted = 0;
 
34291
  BulkEditorRowPtr new_rows = NULL;
 
34292
 
 
34293
  /* count individual rows (will need this many or fewer) */
 
34294
  num_individual_rows = CountIndividualRows(orig_rows);
 
34295
 
 
34296
  /* set default copied_to values */
 
34297
  SetDefaultCopiedToValues (orig_rows);
 
34298
  
 
34299
  new_rows = (BulkEditorRowPtr) MemNew (sizeof (BulkEditorRowData) * (num_individual_rows + 1));
 
34300
  MemSet (new_rows, 0, sizeof (BulkEditorRowData) * (num_individual_rows + 1));
 
34301
 
 
34302
  /* add selected rows first */
 
34303
  last_inserted = AddRowsToListBySelection(new_rows, orig_rows, field_list, last_inserted, TRUE);
 
34304
 
 
34305
  /* add unselected rows */
 
34306
  last_inserted = AddRowsToListBySelection(new_rows, orig_rows, field_list, last_inserted, FALSE);
 
34307
 
 
34308
  return new_rows;     
 
34309
}
 
34310
 
 
34311
 
 
34312
 
 
34313
 
 
34314
 
 
34315
typedef enum {
 
34316
  eBulkApplyField = 1,
 
34317
  eBulkEditField,
 
34318
  eBulkConvertField,
 
34319
  eBulkParseField,
 
34320
  eBulkSwapField,
 
34321
  eBulkRemoveField,
 
34322
  eBulkCapitalizeField
 
34323
} EBulkAction;
 
34324
 
 
34325
static Int4 GetFieldNumFromPopupValue (Int4 popup_val, BulkEdFieldPtr field_list, Boolean edit_only)
 
34326
{
 
34327
  Int4 i, pval = 1;
 
34328
 
 
34329
  for (i = 0; field_list[i].name != NULL; i++) {
 
34330
    if (field_list[i].create_dlg_func != NULL || (!edit_only && field_list[i].display_func != NULL)) {
 
34331
      if (pval == popup_val) {
 
34332
        return i;
 
34333
      } else {
 
34334
        pval++;
 
34335
      }
 
34336
    }
 
34337
  }
 
34338
  return -1;
 
34339
}
 
34340
 
 
34341
static Int4 GetPopupValueFromFieldNum (Int4 field_num, BulkEdFieldPtr field_list, Boolean edit_only)
 
34342
{
 
34343
  Int4 i, pval = 1;
 
34344
 
 
34345
  for (i = 0; field_list[i].name != NULL; i++) {
 
34346
    if (field_list[i].create_dlg_func != NULL || (!edit_only && field_list[i].display_func != NULL)) {
 
34347
      if (i == field_num) {
 
34348
        return pval;
 
34349
      } else {
 
34350
        pval++;
 
34351
      }
 
34352
    }
 
34353
  }
 
34354
  return 0;
 
34355
}
 
34356
 
 
34357
 
 
34358
static PopuP MakeBulkEditorFieldListPopup (GrouP g, BulkEdFieldPtr field_list, Boolean edit_only)
 
34359
{
 
34360
  PopuP p;
 
34361
  Int4  i;
 
34362
 
 
34363
  if (field_list == NULL) return NULL;
 
34364
 
 
34365
  p = PopupList (g, TRUE, NULL);
 
34366
  for (i = 0; field_list[i].name != NULL; i++) {
 
34367
    if (field_list[i].create_dlg_func != NULL || (!edit_only && field_list[i].display_func != NULL)) {
 
34368
      PopupItem (p, field_list[i].name);
 
34369
    }
 
34370
  }
 
34371
  return p;
 
34372
}
 
34373
 
 
34374
 
 
34375
typedef struct onefieldbulkedit
 
34376
{
 
34377
  Int4          field;
 
34378
  EditApplyPtr  edit_apply;
 
34379
  ChangeCasePtr capitalization;
 
34380
} OneFieldBulkEditData, PNTR OneFieldBulkEditPtr;
 
34381
 
 
34382
static OneFieldBulkEditPtr OneFieldBulkEditFree (OneFieldBulkEditPtr ofp)
 
34383
{
 
34384
  if (ofp != NULL) {
 
34385
    ofp->edit_apply = EditApplyFree (ofp->edit_apply);
 
34386
    ofp->capitalization = MemFree (ofp->capitalization);
 
34387
    ofp = MemFree (ofp);
 
34388
  }
 
34389
  return ofp;
 
34390
}
 
34391
 
 
34392
typedef struct onefieldbulkeditdlg
 
34393
{
 
34394
  DIALOG_MESSAGE_BLOCK
 
34395
  Nlm_ChangeNotifyProc     change_notify;
 
34396
  Pointer                  change_userdata;
 
34397
  BulkEdFieldPtr           field_list;
 
34398
  DialoG                   edit_apply;
 
34399
  DialoG                   capitalization;
 
34400
  PopuP                    field;
 
34401
 
 
34402
} OneFieldBulkEditDialogData, PNTR OneFieldBulkEditDialogPtr;
 
34403
 
 
34404
 
 
34405
static void OneFieldBulkEditToDialog (DialoG d, Pointer data)
 
34406
{
 
34407
  OneFieldBulkEditDialogPtr dlg;
 
34408
  OneFieldBulkEditPtr       dlg_data;
 
34409
 
 
34410
  dlg = (OneFieldBulkEditDialogPtr) GetObjectExtra (d);
 
34411
  if (dlg == NULL) return;
 
34412
 
 
34413
  dlg_data = (OneFieldBulkEditPtr) data;
 
34414
  if (dlg_data == NULL) {
 
34415
    SetValue (dlg->field, 1);
 
34416
    PointerToDialog (dlg->edit_apply, NULL);
 
34417
    PointerToDialog (dlg->capitalization, NULL);
 
34418
  } else {
 
34419
    SetValue (dlg->field, GetPopupValueFromFieldNum(dlg_data->field, dlg->field_list, TRUE));
 
34420
    PointerToDialog (dlg->edit_apply, dlg_data->edit_apply);
 
34421
    PointerToDialog (dlg->capitalization, dlg_data->capitalization);
 
34422
  }
 
34423
  if (dlg->change_notify != NULL) {
 
34424
    (dlg->change_notify) (dlg->change_userdata);
 
34425
  }
 
34426
}
 
34427
 
 
34428
 
 
34429
static Pointer OneFieldBulkEditDialogToPointer (DialoG d)
 
34430
{
 
34431
  OneFieldBulkEditDialogPtr dlg;
 
34432
  OneFieldBulkEditPtr       dlg_data;
 
34433
 
 
34434
  dlg = (OneFieldBulkEditDialogPtr) GetObjectExtra (d);
 
34435
  if (dlg == NULL) return NULL;
 
34436
 
 
34437
  dlg_data = (OneFieldBulkEditPtr) MemNew (sizeof (OneFieldBulkEditData));
 
34438
  dlg_data->field = GetFieldNumFromPopupValue(GetValue (dlg->field), dlg->field_list, TRUE);
 
34439
  dlg_data->edit_apply = DialogToPointer (dlg->edit_apply);
 
34440
  dlg_data->capitalization = DialogToPointer (dlg->capitalization);
 
34441
 
 
34442
  return dlg_data;
 
34443
}
 
34444
 
 
34445
static DialoG OneFieldBulkEditDialog
 
34446
(GrouP                    h,
 
34447
 EBulkAction              action_choice,
 
34448
 Nlm_ChangeNotifyProc     change_notify,
 
34449
 Pointer                  change_userdata,
 
34450
 BulkEdFieldPtr           field_list)
 
34451
 
 
34452
{
 
34453
  OneFieldBulkEditDialogPtr dlg;
 
34454
  GrouP                     p;
 
34455
  
 
34456
  dlg = (OneFieldBulkEditDialogPtr) MemNew (sizeof (OneFieldBulkEditDialogData));
 
34457
  if (dlg == NULL)
 
34458
  {
 
34459
    return NULL;
 
34460
  }
 
34461
 
 
34462
  p = HiddenGroup (h, 2, 0, NULL);
 
34463
  SetObjectExtra (p, dlg, StdCleanupExtraProc);
 
34464
  SetGroupSpacing (p, 10, 10);
 
34465
  
 
34466
  dlg->dialog = (DialoG) p;
 
34467
  dlg->todialog = OneFieldBulkEditToDialog;
 
34468
  dlg->fromdialog = OneFieldBulkEditDialogToPointer;
 
34469
  dlg->dialogmessage = NULL;
 
34470
  dlg->testdialog = NULL;
 
34471
 
 
34472
  dlg->field_list = field_list;
 
34473
  
 
34474
  dlg->field = MakeBulkEditorFieldListPopup (p, field_list, TRUE);
 
34475
  SetValue (dlg->field, 1);
 
34476
 
 
34477
  if (action_choice == eBulkApplyField) 
 
34478
  {
 
34479
    dlg->edit_apply = EditApplyDialog (p, eEditApplyChoice_Apply, NULL, NULL, NULL, NULL);
 
34480
  } 
 
34481
  else if (action_choice == eBulkEditField)
 
34482
  {
 
34483
    dlg->edit_apply = EditApplyDialog (p, eEditApplyChoice_Edit, NULL, NULL, NULL, NULL);
 
34484
  }
 
34485
  else if (action_choice == eBulkCapitalizeField)
 
34486
  {
 
34487
    dlg->capitalization = ChangeCaseDialog (p);
 
34488
  }
 
34489
 
 
34490
  return (DialoG) p;
 
34491
}
 
34492
 
 
34493
 
 
34494
typedef struct twofieldbulkedit
 
34495
{
 
34496
  Int4 field_from;
 
34497
  Int4 field_to;
 
34498
  Boolean strip_name;
 
34499
  Boolean leave_on_original;
 
34500
  Boolean remove_parsed;
 
34501
  TextPortionXPtr text_portion;
 
34502
} TwoFieldBulkEditData, PNTR TwoFieldBulkEditPtr;
 
34503
 
 
34504
 
 
34505
static TwoFieldBulkEditPtr TwoFieldBulkEditFree (TwoFieldBulkEditPtr tfp)
 
34506
{
 
34507
  if (tfp != NULL) {
 
34508
    tfp->text_portion = TextPortionXFree (tfp->text_portion);
 
34509
    tfp = MemFree (tfp);
 
34510
  }
 
34511
  return tfp;
 
34512
}
 
34513
 
 
34514
 
 
34515
typedef struct twofieldbulkeditdlg
 
34516
{
 
34517
  DIALOG_MESSAGE_BLOCK
 
34518
  Nlm_ChangeNotifyProc     change_notify;
 
34519
  Pointer                  change_userdata;
 
34520
  BulkEdFieldPtr           field_list;
 
34521
  ButtoN                   strip_name;
 
34522
  ButtoN                   leave_on_original;
 
34523
  ButtoN                   remove_parsed;
 
34524
  DialoG                   text_portion;
 
34525
  PopuP                    field_from;
 
34526
  PopuP                    field_to;
 
34527
 
 
34528
} TwoFieldBulkEditDialogData, PNTR TwoFieldBulkEditDialogPtr;
 
34529
 
 
34530
 
 
34531
static void TwoFieldBulkEditToDialog (DialoG d, Pointer data)
 
34532
{
 
34533
  TwoFieldBulkEditDialogPtr dlg;
 
34534
  TwoFieldBulkEditPtr       dlg_data;
 
34535
 
 
34536
  dlg = (TwoFieldBulkEditDialogPtr) GetObjectExtra (d);
 
34537
  if (dlg == NULL) return;
 
34538
 
 
34539
  dlg_data = (TwoFieldBulkEditPtr) data;
 
34540
  if (dlg_data == NULL) {
 
34541
    SetValue (dlg->field_from, 1);
 
34542
    SetValue (dlg->field_to, 1);
 
34543
    if (dlg->leave_on_original != NULL) {
 
34544
      SetStatus (dlg->leave_on_original, FALSE);
 
34545
    }
 
34546
    if (dlg->strip_name != NULL) {
 
34547
      SetStatus (dlg->strip_name, FALSE);
 
34548
    }
 
34549
    if (dlg->remove_parsed != NULL) {
 
34550
      SetStatus (dlg->remove_parsed, FALSE);
 
34551
    }
 
34552
    PointerToDialog (dlg->text_portion, NULL);
 
34553
  } else {
 
34554
    SetValue (dlg->field_from, GetPopupValueFromFieldNum(dlg_data->field_from, dlg->field_list, TRUE));
 
34555
    SetValue (dlg->field_to, GetPopupValueFromFieldNum(dlg_data->field_to, dlg->field_list, TRUE));
 
34556
    if (dlg->leave_on_original != NULL) {
 
34557
      SetStatus (dlg->leave_on_original, dlg_data->leave_on_original);
 
34558
    }
 
34559
    if (dlg->strip_name != NULL) {
 
34560
      SetStatus (dlg->strip_name, dlg_data->strip_name);
 
34561
    }
 
34562
    if (dlg->remove_parsed != NULL) {
 
34563
      SetStatus (dlg->remove_parsed, dlg_data->remove_parsed);
 
34564
    }
 
34565
    PointerToDialog (dlg->text_portion, dlg_data->text_portion);
 
34566
  }
 
34567
  if (dlg->change_notify != NULL) {
 
34568
    (dlg->change_notify) (dlg->change_userdata);
 
34569
  }
 
34570
}
 
34571
 
 
34572
 
 
34573
static Pointer TwoFieldBulkEditDialogToPointer (DialoG d)
 
34574
{
 
34575
  TwoFieldBulkEditDialogPtr dlg;
 
34576
  TwoFieldBulkEditPtr       dlg_data;
 
34577
 
 
34578
  dlg = (TwoFieldBulkEditDialogPtr) GetObjectExtra (d);
 
34579
  if (dlg == NULL) return NULL;
 
34580
 
 
34581
  dlg_data = (TwoFieldBulkEditPtr) MemNew (sizeof (TwoFieldBulkEditData));
 
34582
  dlg_data->field_from = GetFieldNumFromPopupValue(GetValue (dlg->field_from), dlg->field_list, TRUE);
 
34583
  dlg_data->field_to = GetFieldNumFromPopupValue(GetValue (dlg->field_to), dlg->field_list, TRUE);
 
34584
  dlg_data->leave_on_original = dlg->leave_on_original == NULL ? FALSE : GetStatus (dlg->leave_on_original);
 
34585
  dlg_data->strip_name = dlg->strip_name == NULL ? FALSE : GetStatus (dlg->strip_name);
 
34586
  dlg_data->remove_parsed = dlg->remove_parsed == NULL ? FALSE : GetStatus (dlg->remove_parsed);
 
34587
  dlg_data->text_portion = DialogToPointer (dlg->text_portion);
 
34588
 
 
34589
  return dlg_data;
 
34590
}
 
34591
 
 
34592
static DialoG TwoFieldBulkEditDialog
 
34593
(GrouP                    h,
 
34594
 EBulkAction              action_choice,
 
34595
 Nlm_ChangeNotifyProc     change_notify,
 
34596
 Pointer                  change_userdata,
 
34597
 BulkEdFieldPtr           field_list,
 
34598
 Boolean                  strip_name)
 
34599
 
 
34600
{
 
34601
  TwoFieldBulkEditDialogPtr dlg;
 
34602
  GrouP            p, g1, g2;
 
34603
  
 
34604
  dlg = (TwoFieldBulkEditDialogPtr) MemNew (sizeof (TwoFieldBulkEditDialogData));
 
34605
  if (dlg == NULL)
 
34606
  {
 
34607
    return NULL;
 
34608
  }
 
34609
 
 
34610
  p = HiddenGroup (h, -1, 0, NULL);
 
34611
  SetObjectExtra (p, dlg, StdCleanupExtraProc);
 
34612
  SetGroupSpacing (p, 10, 10);
 
34613
  
 
34614
  dlg->dialog = (DialoG) p;
 
34615
  dlg->todialog = TwoFieldBulkEditToDialog;
 
34616
  dlg->fromdialog = TwoFieldBulkEditDialogToPointer;
 
34617
  dlg->dialogmessage = NULL;
 
34618
  dlg->testdialog = NULL;
 
34619
 
 
34620
  dlg->field_list = field_list;
 
34621
  
 
34622
  g1 = HiddenGroup (p, 2, 0, NULL);
 
34623
  StaticPrompt (g1, "From", 0, dialogTextHeight, systemFont, 'l');
 
34624
  StaticPrompt (g1, "To", 0, dialogTextHeight, systemFont, 'l');
 
34625
  
 
34626
  dlg->field_from = MakeBulkEditorFieldListPopup (g1, field_list, TRUE);
 
34627
  SetValue (dlg->field_from, 1);
 
34628
  dlg->field_to = MakeBulkEditorFieldListPopup (g1, field_list, TRUE);
 
34629
  SetValue (dlg->field_to, 1);
 
34630
 
 
34631
  if (action_choice == eBulkParseField) 
 
34632
  {
 
34633
    dlg->text_portion = TextPortionXDialog(p);
 
34634
  }
 
34635
 
 
34636
  g2 = HiddenGroup (p, 3, 0, NULL);
 
34637
 
 
34638
  if (action_choice == eBulkParseField)
 
34639
  {
 
34640
    dlg->remove_parsed = CheckBox (g2, "Remove from parsed field", NULL);
 
34641
  }
 
34642
 
 
34643
  if (action_choice == eBulkConvertField)
 
34644
  {
 
34645
    dlg->leave_on_original = CheckBox (g2, "Leave on original", NULL);
 
34646
  }
 
34647
  if (strip_name)
 
34648
  {
 
34649
    dlg->strip_name = CheckBox (g2, "Strip name from text", NULL);
 
34650
  }
 
34651
 
 
34652
  AlignObjects (ALIGN_CENTER, (HANDLE) g1, (HANDLE)g2, (HANDLE) dlg->text_portion, NULL);
 
34653
  return (DialoG) p;
 
34654
}
 
34655
 
 
34656
 
 
34657
static void BulkDrawCollapseExpand (Boolean val, RectPtr r)
 
34658
{
 
34659
  RecT rct;
 
34660
 
 
34661
  if (r == NULL) return;
 
34662
 
 
34663
  rct = *r;
 
34664
  rct.bottom = rct.top + stdLineHeight - 4;
 
34665
  rct.right = rct.left + stdLineHeight - 4;
 
34666
  InsetRect (&rct, 2, 2);
 
34667
  FrameRect (&rct);
 
34668
  
 
34669
  if (val) {
 
34670
    /* draw minus */
 
34671
    MoveTo (rct.left, (rct.top + rct.bottom) / 2);
 
34672
    LineTo (rct.right - 1, (rct.top + rct.bottom) / 2);
 
34673
  } else {
 
34674
    /* draw plus */
 
34675
    MoveTo (rct.left, (rct.top + rct.bottom) / 2);
 
34676
    LineTo (rct.right - 1, (rct.top + rct.bottom) / 2);
 
34677
    MoveTo ((rct.left + rct.right) / 2, rct.top);
 
34678
    LineTo ((rct.left + rct.right) / 2, rct.bottom);
 
34679
  }
 
34680
}
 
34681
 
 
34682
 
 
34683
static void BulkDrawSelect (Boolean val, RectPtr r)
 
34684
{
 
34685
  RecT rct;
 
34686
 
 
34687
  if (r == NULL) return;
 
34688
 
 
34689
  rct = *r;
 
34690
  rct.bottom = rct.top + stdLineHeight - 4;
 
34691
  rct.right = rct.left + stdLineHeight - 4;
 
34692
  InsetRect (&rct, 2, 2);
 
34693
  FrameRect (&rct);
 
34694
  
 
34695
  if (val) {
 
34696
    /* draw X */
 
34697
    MoveTo (rct.left, rct.top);
 
34698
    LineTo (rct.right - 1, rct.bottom - 1);
 
34699
    MoveTo (rct.right, rct.top);
 
34700
    LineTo (rct.left, rct.bottom - 1);
 
34701
  }
 
34702
}
 
34703
 
 
34704
 
 
34705
typedef struct bulkeditordlg {
 
34706
  DIALOG_MESSAGE_BLOCK
 
34707
  DoC               title_doc;
 
34708
  DoC               doc;
 
34709
  BulkEdFieldPtr    field_list;
 
34710
  ColPtr            col_list;
 
34711
  ParData           par_fmt;
 
34712
  BulkEditorRowPtr  row_list;
 
34713
  DialoG PNTR       editor_list;
 
34714
  Int4              num_columns;
 
34715
  Int2              last_viewed_row;
 
34716
  Int2              last_viewed_col;  /* this will always refer to the data column */
 
34717
  Int2              last_sorted_col;  /* this will always refer to the data column */
 
34718
 
 
34719
  /* These are for the bulk edit actions */
 
34720
  PopuP             bulk_action;
 
34721
  GrouP             action_pages[8];
 
34722
 
 
34723
  DialoG            bulk_apply;
 
34724
  DialoG            bulk_edit;
 
34725
  DialoG            bulk_convert;
 
34726
  DialoG            bulk_parse;
 
34727
  DialoG            bulk_swap;
 
34728
  DialoG            bulk_remove;
 
34729
  DialoG            bulk_capitalize;
 
34730
 
 
34731
  GrouP             sel_unsel_grp;
 
34732
  PopuP             check_constraint_field;
 
34733
  DialoG            check_constraint;
 
34734
  PrompT            check_status;
 
34735
 
 
34736
  Boolean           any_editing;
 
34737
  Boolean           collapse_by_default;
 
34738
  ClickableCallback single_click_func;
 
34739
  ClickableCallback double_click_func;
 
34740
  Pointer           metadata;
 
34741
} BulkEditorDlgData, PNTR BulkEditorDlgPtr;
 
34742
 
 
34743
 
 
34744
static void InitBulkEdTitleDoc (BulkEditorDlgPtr dlg, DoC doc)
 
34745
{
 
34746
  Int4       i, text_len = 5;
 
34747
  CharPtr    line_text;
 
34748
 
 
34749
  if (dlg == NULL || doc == NULL) {
 
34750
    return;
 
34751
  }
 
34752
 
 
34753
  Reset (doc);
 
34754
  for (i = 0; i < dlg->num_columns; i++) {
 
34755
    text_len += StringLen (dlg->field_list[i].name) + 1;
 
34756
  }
 
34757
 
 
34758
  line_text = (CharPtr) MemNew (text_len * sizeof (Char));
 
34759
  line_text[0] = 0;
 
34760
  /* add blank column for row selection */
 
34761
  StringCat (line_text, "\t");
 
34762
 
 
34763
  for (i = 0; i < dlg->num_columns - 1; i++) {
 
34764
    if (i == dlg->last_sorted_col) {
 
34765
      /* add blank column for expand/collapse */
 
34766
      StringCat (line_text, "\t");
 
34767
    }
 
34768
    StringCat (line_text, dlg->field_list[i].name);
 
34769
    StringCat (line_text, "\t");
 
34770
  }
 
34771
  if (i == dlg->last_sorted_col) {
 
34772
    /* add blank column for expand/collapse */
 
34773
    StringCat (line_text, "\t");
 
34774
  }
 
34775
  StringCat (line_text, dlg->field_list[i].name);
 
34776
  /* add blank column at end */
 
34777
  StringCat (line_text, "\t\n");
 
34778
 
 
34779
  AppendText (doc, line_text, &(dlg->par_fmt), dlg->col_list, programFont);
 
34780
  line_text = MemFree (line_text);
 
34781
}
 
34782
 
 
34783
 
 
34784
/* redraw, set scroll position */
 
34785
static void UpdateBulkEdDisplay (BulkEditorDlgPtr dlg)
 
34786
{
 
34787
  Int4       i, text_len = 0, sub_num;
 
34788
  CharPtr    line_text;
 
34789
  BaR        sb;
 
34790
  Int4       offset = 0;
 
34791
  Int2       first_shown = 0;
 
34792
 
 
34793
  if (dlg == NULL) {
 
34794
    return;
 
34795
  }
 
34796
 
 
34797
  /* Get original scroll position */
 
34798
  sb = GetSlateVScrollBar ((SlatE)dlg->doc);
 
34799
  offset = 0;
 
34800
  GetScrlParams4 (dlg->doc, &offset, &first_shown, NULL);
 
34801
 
 
34802
  Reset (dlg->doc);
 
34803
 
 
34804
  if (dlg->row_list == NULL) {
 
34805
    return;
 
34806
  }
 
34807
 
 
34808
  for (i = 0; dlg->row_list[i].object_list != NULL; i++) {
 
34809
    line_text = GetTextForBulkEditorRow(dlg->row_list + i, dlg->field_list, dlg->last_sorted_col);
 
34810
          AppendText (dlg->doc, line_text, &(dlg->par_fmt), dlg->col_list, programFont);
 
34811
    line_text = MemFree (line_text);
 
34812
    if (dlg->row_list[i].subrows != NULL && dlg->row_list[i].expanded) {
 
34813
      for (sub_num = 0; dlg->row_list[i].subrows[sub_num].object_list != NULL; sub_num++) {
 
34814
        line_text = GetTextForBulkEditorRow(dlg->row_list[i].subrows + sub_num, dlg->field_list, dlg->last_sorted_col);
 
34815
              AppendText (dlg->doc, line_text, &(dlg->par_fmt), dlg->col_list, programFont);
 
34816
        line_text = MemFree (line_text);
 
34817
      }
 
34818
    }
 
34819
  }
 
34820
  
 
34821
  /* restore original scroll position */
 
34822
  GetItemParams4 (dlg->doc, first_shown, &offset, NULL, NULL, NULL, NULL);
 
34823
  offset = MIN (offset, GetBarMax (sb));
 
34824
  SetScrlParams4 (dlg->doc, offset);
 
34825
}
 
34826
 
 
34827
/* col is zero-based data column, already corrected for selection and expansion columns */
 
34828
static void BulkEdDlgToField (Int2 row, Int2 col, BulkEditorDlgPtr dlg)
 
34829
{
 
34830
  Int4       i;
 
34831
  Int4       bulk_row, sub_num;
 
34832
 
 
34833
  if (row < 1 || col < 0 || dlg == NULL) return;
 
34834
  if (dlg->editor_list[col] == NULL) return;
 
34835
 
 
34836
  if (!DataPosFromBulkEdDlgRow (row, dlg->row_list, &bulk_row, &sub_num)) return;
 
34837
 
 
34838
  /* don't apply values if editing master row and column other than sort */
 
34839
  if (sub_num < 0 && col != dlg->last_sorted_col && dlg->row_list[bulk_row].subrows != NULL) return;
 
34840
 
 
34841
  if (sub_num < 0) {
 
34842
    /* if applying to all, get confirmation */
 
34843
    if (dlg->row_list[bulk_row].subrows != NULL) {
 
34844
      /* if nothing changed, no need to ask, nothing to do */
 
34845
      if (!AnyChangeInBulkFields(dlg->row_list + bulk_row, dlg->field_list, dlg->editor_list[dlg->last_sorted_col], dlg->last_sorted_col)) {
 
34846
        return;
 
34847
      } else if (ANS_CANCEL == Message (MSG_OKC, "Apply value to all features in collapsible group?")) {
 
34848
        return;
 
34849
      }
 
34850
    }
 
34851
    ApplyValueToOneBulkEditorRow (dlg->row_list + bulk_row, col, dlg->field_list, dlg->editor_list[col]);
 
34852
    if (dlg->row_list[bulk_row].subrows != NULL) {
 
34853
      for (i = 0; dlg->row_list[bulk_row].subrows[i].object_list != NULL; i++) {
 
34854
        ApplyValueToOneBulkEditorRow (dlg->row_list[bulk_row].subrows + i, col, dlg->field_list, dlg->editor_list[col]);
 
34855
      }
 
34856
    }
 
34857
  } else {
 
34858
    ApplyValueToOneBulkEditorRow (dlg->row_list[bulk_row].subrows + sub_num, col, dlg->field_list, dlg->editor_list[col]);
 
34859
  }
 
34860
  UpdateBulkEdDisplay (dlg);
 
34861
}
 
34862
 
 
34863
 
 
34864
/* col is zero-based data column, already corrected for selection and expansion columns */
 
34865
/* if col is -1, hide everything (sorted by selection) */
 
34866
static void ShowBulkFieldEditor (BulkEditorDlgPtr dlg, Int4 bulk_row, Int4 sub_num, Int2 col)
 
34867
{
 
34868
  BulkEditorRowPtr berp;
 
34869
  ValNodePtr       vnp;
 
34870
  Int2             i;
 
34871
 
 
34872
  for (i = 0; i < dlg->num_columns; i++) {
 
34873
    SafeHide (dlg->editor_list[i]);
 
34874
  }
 
34875
 
 
34876
  if (col < 0) return;
 
34877
 
 
34878
  if (sub_num < 0) {
 
34879
    berp = dlg->row_list + bulk_row;
 
34880
  } else {
 
34881
    berp = dlg->row_list[bulk_row].subrows + sub_num;
 
34882
  }
 
34883
 
 
34884
  /* only show editor dialog if sorted column or not master row */
 
34885
  if (col == dlg->last_sorted_col || berp->subrows == NULL) {
 
34886
    vnp = GetBulkEditorRowValueByColumn (berp, col);
 
34887
 
 
34888
    if (vnp == NULL) {
 
34889
      PointerToDialog (dlg->editor_list[col], NULL);
 
34890
    } else {
 
34891
      PointerToDialog (dlg->editor_list[col], vnp->data.ptrvalue);
 
34892
    }
 
34893
  
 
34894
    SafeShow (dlg->editor_list[col]);
 
34895
  }
 
34896
}
 
34897
 
 
34898
 
 
34899
/* clicking on a column in the title indicates that we should sort by this column. */
 
34900
static void ClickBulkTitle (DoC d, PoinT pt)
 
34901
{
 
34902
  BulkEditorDlgPtr dlg;
 
34903
  Int2            item;
 
34904
  Int2            row;
 
34905
  Int2            col;
 
34906
  Int4            bulk_row_num = -1, bulk_sub_num = -1;
 
34907
  RecT            r;
 
34908
  Int4            offset = 0, i;
 
34909
  BulkEditorRowPtr sorted_rows;
 
34910
 
 
34911
  dlg = (BulkEditorDlgPtr) GetObjectExtra (d);
 
34912
  if (dlg == NULL) return;
 
34913
 
 
34914
  MapDocPoint (d, pt, &item, &row, &col, NULL);
 
34915
 
 
34916
  if (col - 2 == dlg->last_sorted_col) {
 
34917
    /* clicked on checkbox column */
 
34918
    col = -1;
 
34919
  } else {
 
34920
    col = BulkEdDataColumnFromDocColumn(col, dlg->last_sorted_col);
 
34921
  }
 
34922
 
 
34923
  if (item < 1 || col < -1 || col >= dlg->num_columns) return;
 
34924
  BulkEdDlgToField (dlg->last_viewed_row, dlg->last_viewed_col, dlg);
 
34925
  ResetClip();
 
34926
 
 
34927
  /* save value of column listed */
 
34928
  dlg->last_sorted_col = col;
 
34929
 
 
34930
  if (col < 0) {
 
34931
    sorted_rows = ResortBulkEditorRowsBySelected (dlg->row_list, dlg->field_list);
 
34932
  } else {
 
34933
    sorted_rows = ResortBulkEditorRows (dlg->row_list, dlg->field_list, dlg->last_sorted_col);
 
34934
    if (dlg->collapse_by_default) {
 
34935
      CollapseAllBulkEditRows (sorted_rows);
 
34936
    } else {
 
34937
      ExpandAllBulkEditRows (sorted_rows);
 
34938
    }
 
34939
  }
 
34940
  /* get new position from old row */
 
34941
  if (DataPosFromBulkEdDlgRow (dlg->last_viewed_row, dlg->row_list, &bulk_row_num, &bulk_sub_num)) {
 
34942
    if (bulk_sub_num > -1) {
 
34943
      dlg->last_viewed_row = BulkEdDlgRowFromDataPos (dlg->row_list[bulk_row_num].subrows[bulk_sub_num].copied_to_meta,
 
34944
                                                      dlg->row_list[bulk_row_num].subrows[bulk_sub_num].copied_to_sub,
 
34945
                                                      sorted_rows);
 
34946
    } else {
 
34947
      dlg->last_viewed_row = BulkEdDlgRowFromDataPos (dlg->row_list[bulk_row_num].copied_to_meta,
 
34948
                                                      dlg->row_list[bulk_row_num].copied_to_sub,
 
34949
                                                      sorted_rows);
 
34950
    }
 
34951
    dlg->last_viewed_col = dlg->last_sorted_col;
 
34952
  }
 
34953
 
 
34954
  dlg->row_list = FreeBulkEditorRows (dlg->row_list, dlg->field_list);
 
34955
  dlg->row_list = sorted_rows;
 
34956
 
 
34957
 
 
34958
  /* reformat the columns */
 
34959
  dlg->col_list = AllocateDocColumnsForFieldList (dlg->field_list, NULL, dlg->last_sorted_col);
 
34960
  ResetClip();
 
34961
  InitBulkEdTitleDoc (dlg, dlg->title_doc);
 
34962
  ObjectRect (dlg->title_doc, &r);
 
34963
  InvalRect (&r);  
 
34964
 
 
34965
  UpdateBulkEdDisplay (dlg);
 
34966
 
 
34967
  if (dlg->last_viewed_row > 0) {
 
34968
    /* show appropriate editor for highlighted item */
 
34969
    if (DataPosFromBulkEdDlgRow (dlg->last_viewed_row, dlg->row_list, &bulk_row_num, &bulk_sub_num)) {
 
34970
      ShowBulkFieldEditor (dlg, bulk_row_num, bulk_sub_num, dlg->last_sorted_col);
 
34971
    } else {
 
34972
      dlg->last_viewed_row = 0;
 
34973
      dlg->last_viewed_col = 0;
 
34974
      for (i = 0; i < dlg->num_columns; i++) {
 
34975
        SafeHide (dlg->editor_list[i]);
 
34976
      }
 
34977
    }
 
34978
 
 
34979
    /* scroll to new position of last_viewed */
 
34980
    GetItemParams4 (dlg->doc, dlg->last_viewed_row, &offset, NULL, NULL, NULL, NULL);
 
34981
    SetScrlParams4 (dlg->doc, offset);
 
34982
  }
 
34983
 
 
34984
  /* redraw highlight etc. */
 
34985
  ObjectRect (dlg->title_doc, &r);
 
34986
  InvalRect (&r);  
 
34987
  ObjectRect (dlg->doc, &r);
 
34988
  InvalRect (&r);  
 
34989
  Update ();
 
34990
}
 
34991
 
 
34992
static void UpdateCheckStatus (BulkEditorDlgPtr dlg)
 
34993
{
 
34994
  Int4 num_selected;
 
34995
  CharPtr status_fmt = "%d feature%s currently checked";
 
34996
  Char status_str[50];
 
34997
 
 
34998
  if (dlg == NULL) return;
 
34999
 
 
35000
  num_selected = CountBulkEditorRowsSelected (dlg->row_list);
 
35001
  sprintf (status_str, status_fmt, num_selected, num_selected == 1 ? "" : "s");
 
35002
  SetTitle (dlg->check_status, status_str);
 
35003
}
 
35004
 
 
35005
 
 
35006
/* when clicking on field, show editor (if available), change selection, collapse/expand,
 
35007
 * set last viewed row, populate data from previously displayed editor 
 
35008
 */
 
35009
static void ClickBulkEdField (DoC d, PoinT pt)
 
35010
{
 
35011
  BulkEditorDlgPtr dlg;
 
35012
  BulkEditorRowPtr berp;
 
35013
  Int2            item;
 
35014
  Int2            row;
 
35015
  Int2            col;
 
35016
  RecT            r;
 
35017
  ValNodePtr      vnp;
 
35018
  Int4            bulk_row = -1, sub_num = -1;
 
35019
  Boolean         dblclick = dblClick;
 
35020
 
 
35021
  dlg = (BulkEditorDlgPtr) GetObjectExtra (d);
 
35022
  if (dlg == NULL) return;
 
35023
 
 
35024
  MapDocPoint (d, pt, &item, &row, &col, NULL);
 
35025
 
 
35026
  if (!DataPosFromBulkEdDlgRow (item, dlg->row_list, &bulk_row, &sub_num)) {
 
35027
    return;
 
35028
  }
 
35029
 
 
35030
  if (sub_num < 0) {
 
35031
    berp = dlg->row_list + bulk_row;
 
35032
  } else {
 
35033
    berp = dlg->row_list[bulk_row].subrows + sub_num;
 
35034
  }
 
35035
 
 
35036
  if (col == 1) {
 
35037
    /* do selection */
 
35038
    berp->selected = !berp->selected;
 
35039
    if (berp->subrows != NULL) {
 
35040
      SelectBulkEditorRows (berp->subrows, berp->selected);
 
35041
    } else if (sub_num > -1) {
 
35042
      /* this is a subrow - metarow can no longer be selected
 
35043
       * if this is not selected.
 
35044
       */
 
35045
      if (dlg->row_list[bulk_row].selected && !berp->selected) {
 
35046
        dlg->row_list[bulk_row].selected = FALSE;
 
35047
      } else if (AllBulkEditorRowsSelected(dlg->row_list[bulk_row].subrows)) {
 
35048
        /* all child rows are now selected, so select metarow */
 
35049
        dlg->row_list[bulk_row].selected = TRUE;
 
35050
      }
 
35051
    }
 
35052
    UpdateCheckStatus (dlg);
 
35053
    ObjectRect (dlg->doc, &r);
 
35054
    InvalRect (&r);  
 
35055
    Update ();
 
35056
    return;
 
35057
  } else if (col == dlg->last_sorted_col + 2) {
 
35058
    /* do expand/collapse */
 
35059
    if (berp->subrows != NULL) {
 
35060
      berp->expanded = !berp->expanded;
 
35061
      UpdateBulkEdDisplay (dlg);
 
35062
      ObjectRect (dlg->doc, &r);
 
35063
      InvalRect (&r);  
 
35064
      Update ();
 
35065
    }
 
35066
    return;
 
35067
  } else  {
 
35068
    /* adjust to account for checkbox column */
 
35069
    col = BulkEdDataColumnFromDocColumn(col, dlg->last_sorted_col);
 
35070
  }
 
35071
  if (item < 1 || col < 0 || col >= dlg->num_columns) return;
 
35072
  BulkEdDlgToField (dlg->last_viewed_row, dlg->last_viewed_col, dlg);
 
35073
  ResetClip();
 
35074
 
 
35075
  ShowBulkFieldEditor (dlg, bulk_row, sub_num, col);
 
35076
 
 
35077
  if (dlg->field_list[col].release_cell_func != NULL) {
 
35078
    vnp = GetBulkEditorRowValueByColumn (berp, col);
 
35079
    if (vnp != NULL) {
 
35080
      vnp->data.ptrvalue = (dlg->field_list[col].release_cell_func) (vnp->data.ptrvalue);
 
35081
    }
 
35082
  }
 
35083
  dlg->last_viewed_row = item;
 
35084
  dlg->last_viewed_col = col;
 
35085
 
 
35086
  /* redraw highlight etc. */
 
35087
  ObjectRect (dlg->doc, &r);
 
35088
  InvalRect (&r);  
 
35089
  Update ();
 
35090
 
 
35091
 
 
35092
  if (dblclick) {
 
35093
    if (dlg->double_click_func != NULL) {
 
35094
      (dlg->double_click_func) (berp->object_list, NULL);
 
35095
    }
 
35096
  } else {
 
35097
    if (dlg->single_click_func != NULL) {
 
35098
      (dlg->single_click_func) (berp->object_list, NULL);
 
35099
    } 
 
35100
  }
 
35101
}
 
35102
 
 
35103
static Boolean HighlightBulkEdField (DoC d, Int2 item, Int2 row, Int2 col)
 
35104
 
 
35105
{
 
35106
  BulkEditorDlgPtr dlg;
 
35107
 
 
35108
  dlg = (BulkEditorDlgPtr) GetObjectExtra (d);
 
35109
  if (dlg == NULL) return FALSE;
 
35110
 
 
35111
  if (col == 1 || col == dlg->last_sorted_col + 1) {
 
35112
    /* don't highlight selection column or expansion column */
 
35113
    return FALSE;
 
35114
  } 
 
35115
 
 
35116
  col = BulkEdDataColumnFromDocColumn (col, dlg->last_sorted_col);
 
35117
  
 
35118
  if (item == dlg->last_viewed_row && col == dlg->last_viewed_col) {
 
35119
    return TRUE;
 
35120
  } else {
 
35121
    return FALSE;
 
35122
  }
 
35123
}
 
35124
 
 
35125
static void DrawBulkEdCell (DoC d, RectPtr r, Int2 item, Int2 firstLine)
 
35126
 
 
35127
{
 
35128
  Int2  lineHeight;
 
35129
  RecT  rct;
 
35130
  Int2  format_col, data_col;
 
35131
  BulkEditorDlgPtr dlg;
 
35132
  BulkEditorRowPtr berp;
 
35133
  ValNodePtr       vnp;
 
35134
  Int4             bulk_row_num = -1, bulk_sub_num = -1;
 
35135
 
 
35136
  dlg = (BulkEditorDlgPtr) GetObjectExtra (d);
 
35137
  if (dlg == NULL || r == NULL || item <= 0 || firstLine != 0) {
 
35138
    return;
 
35139
  }
 
35140
 
 
35141
  GetItemParams (d, item, NULL, NULL, NULL, &lineHeight, NULL);
 
35142
  rct = *r;
 
35143
 
 
35144
  if (!DataPosFromBulkEdDlgRow (item, dlg->row_list, &bulk_row_num, &bulk_sub_num)) {
 
35145
    return;
 
35146
  }
 
35147
 
 
35148
  /* draw lines at top of each row after the first that does not have subrows */
 
35149
  if (bulk_row_num > 0 && bulk_sub_num < 0) {
 
35150
    MoveTo (rct.left, rct.top);
 
35151
    LineTo (rct.right, rct.top);
 
35152
  }
 
35153
  
 
35154
  if (bulk_sub_num < 0) {
 
35155
    berp = dlg->row_list + bulk_row_num;
 
35156
  } else {
 
35157
    berp = dlg->row_list[bulk_row_num].subrows + bulk_sub_num;
 
35158
  }
 
35159
  
 
35160
  /* for column 0, draw selection box */
 
35161
  format_col = 0;
 
35162
  rct.right = rct.left + dlg->col_list[format_col].pixWidth - 1;
 
35163
  BulkDrawSelect (berp->selected, &rct);
 
35164
  rct.left = rct.right + 1;
 
35165
  format_col++; 
 
35166
 
 
35167
  for (data_col = 0, vnp = berp->values_list;
 
35168
       data_col < dlg->num_columns && vnp != NULL; 
 
35169
       data_col++, vnp = vnp->next) {
 
35170
    rct.right = rct.left + dlg->col_list[format_col].pixWidth - 1;
 
35171
    if (data_col == dlg->last_sorted_col) {
 
35172
      /* draw box if expandable */
 
35173
      if (bulk_sub_num == -1
 
35174
          && dlg->row_list[bulk_row_num].subrows != NULL) {
 
35175
        BulkDrawCollapseExpand (dlg->row_list[bulk_row_num].expanded, &rct);
 
35176
      }
 
35177
      rct.left = rct.right + 1;
 
35178
      format_col++;
 
35179
      rct.right = rct.left + dlg->col_list[format_col].pixWidth - 1;
 
35180
    }  
 
35181
    if (dlg->field_list[data_col].draw_col_func != NULL) {
 
35182
      (dlg->field_list[data_col].draw_col_func)(vnp->data.ptrvalue, &rct);
 
35183
    }
 
35184
    rct.left = rct.right + 1;
 
35185
    format_col++;
 
35186
  }
 
35187
}
 
35188
 
 
35189
static void CleanupBulkEditorDialog (GraphiC g, VoidPtr data)
 
35190
{
 
35191
  BulkEditorDlgPtr dlg;
 
35192
 
 
35193
  dlg = (BulkEditorDlgPtr) data;
 
35194
  if (dlg != NULL) {
 
35195
    dlg->row_list = FreeBulkEditorRows(dlg->row_list, dlg->field_list);
 
35196
  }
 
35197
  StdCleanupExtraProc (g, data);
 
35198
}
 
35199
 
 
35200
static void ApplyBulkEditorRowToObject (BulkEditorRowPtr berp, Pointer target, BulkEdFieldPtr field_list)
 
35201
{
 
35202
  ValNodePtr vnp_val;
 
35203
  Int4       i;
 
35204
 
 
35205
  if (berp == NULL || target == NULL || field_list == NULL) return;
 
35206
 
 
35207
  for (i = 0, vnp_val = berp->values_list;
 
35208
       vnp_val != NULL;
 
35209
       i++, vnp_val = vnp_val->next) {
 
35210
    if (field_list[i].set_func != NULL) {
 
35211
      (field_list[i].set_func) (target, vnp_val->data.ptrvalue);
 
35212
    }
 
35213
  }
 
35214
}
 
35215
 
 
35216
static void ApplyBulkEditorToObjectList (DialoG d)
 
35217
{
 
35218
  BulkEditorDlgPtr dlg;
 
35219
  Int4             row, i;
 
35220
 
 
35221
  dlg = (BulkEditorDlgPtr) GetObjectExtra (d);
 
35222
  if (dlg == NULL) return;
 
35223
 
 
35224
  BulkEdDlgToField (dlg->last_viewed_row, dlg->last_viewed_col, dlg);
 
35225
 
 
35226
  for (row = 0; dlg->row_list[row].object_list != NULL; row++) {
 
35227
    if (dlg->row_list[row].subrows == NULL) {
 
35228
      ApplyBulkEditorRowToObject (dlg->row_list + row, 
 
35229
                                  dlg->row_list[row].object_list->data.ptrvalue, 
 
35230
                                  dlg->field_list);
 
35231
    } else {
 
35232
      for (i = 0; dlg->row_list[row].subrows[i].object_list != NULL; i++) {
 
35233
        ApplyBulkEditorRowToObject (dlg->row_list[row].subrows + i,
 
35234
                                    dlg->row_list[row].subrows[i].object_list->data.ptrvalue,
 
35235
                                    dlg->field_list);
 
35236
      }
 
35237
    }
 
35238
  }
 
35239
}
 
35240
 
 
35241
static void ChangeBulkEditorAction (PopuP p)
 
35242
{
 
35243
  BulkEditorDlgPtr dlg;
 
35244
  Int4             page_num;
 
35245
  Int4             num_pages;
 
35246
 
 
35247
  dlg = (BulkEditorDlgPtr) GetObjectExtra (p);
 
35248
  if (dlg == NULL || !dlg->any_editing) return;
 
35249
 
 
35250
  num_pages = sizeof (dlg->action_pages) / sizeof (GrouP);
 
35251
  for (page_num = 0; page_num < num_pages; page_num++) {
 
35252
    Hide (dlg->action_pages[page_num]);
 
35253
  }
 
35254
  page_num = GetValue (dlg->bulk_action) - 1;
 
35255
  if (page_num > -1 && page_num < num_pages) {
 
35256
    Show (dlg->action_pages[page_num]);
 
35257
  }
 
35258
}
 
35259
 
 
35260
static void RemoveColumnFromSelectedBulkEditRows (BulkEditorRowPtr row_list, Int4 col, BulkEdFieldPtr field_list)
 
35261
{
 
35262
  ValNodePtr vnp;
 
35263
 
 
35264
  if (row_list == NULL || col < 0 || field_list == NULL) return;
 
35265
  while (row_list->object_list != NULL) {
 
35266
    if (row_list->selected) {
 
35267
      if (row_list->subrows == NULL || AllBulkEditorRowsSelected(row_list->subrows)) {
 
35268
        vnp = GetBulkEditorRowValueByColumn (row_list, col);
 
35269
        if (vnp != NULL) {
 
35270
          field_list[col].free_func(vnp->data.ptrvalue);
 
35271
          vnp->data.ptrvalue = NULL;
 
35272
        }
 
35273
      }
 
35274
    }
 
35275
    RemoveColumnFromSelectedBulkEditRows (row_list->subrows, col, field_list);
 
35276
    row_list++;
 
35277
  }
 
35278
}
 
35279
 
 
35280
static void 
 
35281
ApplyEditColumnFromSelectedBulkEditRows 
 
35282
(BulkEditorRowPtr berp, 
 
35283
 BulkEdFieldPtr   field_list,
 
35284
 Int4             col,
 
35285
 ApplyValuePtr    avp)
 
35286
{
 
35287
  ValNodePtr     vnp;
 
35288
 
 
35289
  if (berp == NULL) return;
 
35290
 
 
35291
  while (berp->object_list != NULL) {
 
35292
    if (berp->selected) {
 
35293
      if (berp->subrows == NULL || AllBulkEditorRowsSelected(berp->subrows)) {
 
35294
        vnp = GetBulkEditorRowValueByColumn (berp, col);
 
35295
        if (vnp != NULL) {
 
35296
          vnp->data.ptrvalue = (field_list[col].set_str_func) (vnp->data.ptrvalue, avp);
 
35297
        }
 
35298
      }
 
35299
    }
 
35300
    ApplyEditColumnFromSelectedBulkEditRows (berp->subrows, field_list, col, avp);
 
35301
    berp++;
 
35302
  }
 
35303
}
 
35304
 
 
35305
 
 
35306
static void 
 
35307
CapitalizeColumnsForSelectedBulkEditRows
 
35308
(BulkEditorRowPtr berp, 
 
35309
 BulkEdFieldPtr   field_list,
 
35310
 Int4             col,
 
35311
 ChangeCasePtr    capitalization)
 
35312
{
 
35313
  ValNodePtr     vnp;
 
35314
  CharPtr        val_str;
 
35315
  ApplyValueData avd;
 
35316
  SeqFeatPtr     sfp;
 
35317
  SeqEntryPtr    sep, last_sep = NULL;
 
35318
  ValNodePtr     orgname_list = NULL;
 
35319
 
 
35320
  if (berp == NULL) return;
 
35321
 
 
35322
  avd.field_list = NULL;
 
35323
  avd.text_to_replace = NULL;
 
35324
  avd.where_to_replace = EditApplyFindLocation_anywhere;
 
35325
  avd.etp = NULL;
 
35326
 
 
35327
  while (berp->object_list != NULL) {
 
35328
    if (berp->selected) {
 
35329
      if (berp->subrows == NULL || AllBulkEditorRowsSelected(berp->subrows)) {
 
35330
        vnp = GetBulkEditorRowValueByColumn (berp, col);
 
35331
        if (vnp != NULL) {
 
35332
          val_str = (field_list[col].display_func)(vnp->data.ptrvalue);
 
35333
          if (!StringHasNoText (val_str)) {
 
35334
            if (berp->object_list->choice == OBJ_SEQFEAT && berp->object_list->data.ptrvalue != NULL) {
 
35335
              sfp = (SeqFeatPtr) berp->object_list->data.ptrvalue;
 
35336
              sep = GetTopSeqEntryForEntityID (sfp->idx.entityID);
 
35337
              if (sep != last_sep) {
 
35338
                orgname_list = ValNodeFree (orgname_list);
 
35339
                /* get org names to use in fixes */
 
35340
                VisitBioSourcesInSep (sep, &orgname_list, GetOrgNamesInRecordCallback);
 
35341
                last_sep = sep;
 
35342
              }
 
35343
            }
 
35344
            ChangeCase (&val_str, capitalization, orgname_list);
 
35345
            avd.new_text = val_str;
 
35346
            vnp->data.ptrvalue = (field_list[col].set_str_func) (vnp->data.ptrvalue, &avd);
 
35347
          }
 
35348
          val_str = MemFree (val_str);
 
35349
        }
 
35350
      }
 
35351
    }
 
35352
    CapitalizeColumnsForSelectedBulkEditRows (berp->subrows, field_list, col, capitalization);
 
35353
    berp++;
 
35354
  }
 
35355
  orgname_list = ValNodeFree (orgname_list);
 
35356
}
 
35357
 
 
35358
static void RemoveNameFromText (CharPtr orig, CharPtr remove)
 
35359
{
 
35360
  CharPtr cp, cp_dst;
 
35361
  Int4    len;
 
35362
 
 
35363
  if (StringHasNoText (orig) || StringHasNoText (remove)) {
 
35364
    return;
 
35365
  }
 
35366
  cp = StringISearch (orig, remove);
 
35367
  if (cp != NULL) {
 
35368
    len = StringLen (remove);
 
35369
    cp_dst = cp;
 
35370
    cp = cp + len;
 
35371
    while (*cp != 0 && len > 0) {
 
35372
      *cp_dst = *cp;
 
35373
      cp_dst++;
 
35374
      cp++;
 
35375
      len--;
 
35376
    }
 
35377
    *cp_dst = 0;
 
35378
  }
 
35379
}
 
35380
 
 
35381
static void ConvertColumnsForSelectedBulkEditRows 
 
35382
(BulkEditorRowPtr    berp,
 
35383
 BulkEdFieldPtr      field_list,
 
35384
 TwoFieldBulkEditPtr tfp,
 
35385
 ExistingTextPtr     etp)
 
35386
{
 
35387
  ValNodePtr vnp_from, vnp_to;
 
35388
  CharPtr    val_from;
 
35389
  ApplyValueData avd;
 
35390
  if (berp == NULL || tfp == NULL) return;
 
35391
 
 
35392
  avd.field_list = NULL;
 
35393
  avd.text_to_replace = NULL;
 
35394
  avd.where_to_replace = EditApplyFindLocation_anywhere;
 
35395
  avd.etp = etp;
 
35396
 
 
35397
  while (berp->object_list != NULL) {
 
35398
    if (berp->selected && berp->subrows == NULL) {
 
35399
      vnp_from = GetBulkEditorRowValueByColumn (berp, tfp->field_from);
 
35400
      vnp_to   = GetBulkEditorRowValueByColumn (berp, tfp->field_to);
 
35401
      if (vnp_from != NULL && vnp_to != NULL) {
 
35402
        val_from = (field_list[tfp->field_from].display_func)(vnp_from->data.ptrvalue);
 
35403
        if (StringDoesHaveText (val_from)) {
 
35404
          if (tfp->strip_name) {
 
35405
            RemoveNameFromText (val_from, field_list[tfp->field_to].name);
 
35406
          }
 
35407
 
 
35408
          avd.new_text = val_from;
 
35409
          vnp_to->data.ptrvalue = (field_list[tfp->field_to].set_str_func) (vnp_to->data.ptrvalue, &avd);
 
35410
          
 
35411
          if (!tfp->leave_on_original) {
 
35412
            (field_list[tfp->field_from].free_func)(vnp_from->data.ptrvalue);
 
35413
            vnp_from->data.ptrvalue = NULL;
 
35414
          }
 
35415
      
 
35416
        }
 
35417
        val_from = MemFree (val_from);
 
35418
      }
 
35419
    }
 
35420
    ConvertColumnsForSelectedBulkEditRows (berp->subrows, field_list, tfp, etp);
 
35421
    berp++;
 
35422
  }
 
35423
}
 
35424
 
 
35425
 
 
35426
static void ParseColumnsForSelectedBulkEditRows 
 
35427
(BulkEditorRowPtr    berp,
 
35428
 BulkEdFieldPtr      field_list,
 
35429
 TwoFieldBulkEditPtr tfp,
 
35430
 ExistingTextPtr     etp)
 
35431
{
 
35432
  ValNodePtr vnp_from, vnp_to;
 
35433
  CharPtr    val_from, val_to;
 
35434
  ApplyValueData avd;
 
35435
  if (berp == NULL || tfp == NULL) return;
 
35436
 
 
35437
  avd.field_list = NULL;
 
35438
  avd.text_to_replace = NULL;
 
35439
  avd.where_to_replace = EditApplyFindLocation_anywhere;
 
35440
  avd.etp = etp;
 
35441
 
 
35442
  while (berp->object_list != NULL) {
 
35443
    if (berp->selected && berp->subrows == NULL) {
 
35444
      vnp_from = GetBulkEditorRowValueByColumn (berp, tfp->field_from);
 
35445
      vnp_to   = GetBulkEditorRowValueByColumn (berp, tfp->field_to);
 
35446
      if (vnp_from != NULL && vnp_to != NULL) {
 
35447
        val_from = (field_list[tfp->field_from].display_func)(vnp_from->data.ptrvalue);
 
35448
        val_to = NULL;
 
35449
        if (StringDoesHaveText (val_from)) {
 
35450
          val_to = ReplaceStringForParse(val_from, tfp->text_portion);
 
35451
          if (StringDoesHaveText (val_to)) {
 
35452
            avd.new_text = val_to;
 
35453
            vnp_to->data.ptrvalue = (field_list[tfp->field_to].set_str_func) (vnp_to->data.ptrvalue, &avd);
 
35454
          }
 
35455
          if (tfp->remove_parsed) {
 
35456
            avd.new_text = val_from;
 
35457
            avd.etp = NULL;
 
35458
            vnp_from->data.ptrvalue = (field_list[tfp->field_from].set_str_func) (vnp_from->data.ptrvalue, &avd);
 
35459
            avd.etp = etp;
 
35460
          }      
 
35461
        }
 
35462
        val_from = MemFree (val_from);
 
35463
        val_to = MemFree (val_to);
 
35464
      }
 
35465
    }
 
35466
    ParseColumnsForSelectedBulkEditRows (berp->subrows, field_list, tfp, etp);
 
35467
    berp++;
 
35468
  }
 
35469
}
 
35470
 
 
35471
 
 
35472
static void SwapColumnsForSelectedBulkEditRows
 
35473
(BulkEditorRowPtr berp,
 
35474
 BulkEdFieldPtr   field_list,
 
35475
 Int4             col_from,
 
35476
 Int4             col_to)
 
35477
{
 
35478
  ValNodePtr vnp_from, vnp_to;
 
35479
  CharPtr    val_from, val_to;
 
35480
  ApplyValueData avd;
 
35481
  if (berp == NULL) return;
 
35482
 
 
35483
  avd.etp = NULL;
 
35484
  avd.field_list = NULL;
 
35485
  avd.text_to_replace = NULL;
 
35486
  avd.where_to_replace = EditApplyFindLocation_anywhere;
 
35487
 
 
35488
  while (berp->object_list != NULL) {
 
35489
    if (berp->selected && berp->subrows == NULL) {
 
35490
      vnp_from = GetBulkEditorRowValueByColumn (berp, col_from);
 
35491
      vnp_to   = GetBulkEditorRowValueByColumn (berp, col_to);
 
35492
      if (vnp_from != NULL && vnp_to != NULL) {
 
35493
        val_from = (field_list[col_from].display_func)(vnp_from->data.ptrvalue);
 
35494
        val_to = (field_list[col_to].display_func)(vnp_to->data.ptrvalue);
 
35495
        if (StringDoesHaveText (val_from) || StringDoesHaveText (val_to)) {
 
35496
          avd.new_text = val_to;
 
35497
          vnp_from->data.ptrvalue = (field_list[col_from].set_str_func) (vnp_from->data.ptrvalue, &avd);
 
35498
      
 
35499
          avd.new_text = val_from;
 
35500
          vnp_to->data.ptrvalue = (field_list[col_to].set_str_func) (vnp_to->data.ptrvalue, &avd);
 
35501
        }
 
35502
        val_from = MemFree (val_from);
 
35503
        val_to = MemFree (val_to);
 
35504
      }
 
35505
    }
 
35506
    SwapColumnsForSelectedBulkEditRows (berp->subrows, field_list, col_from, col_to);
 
35507
    berp++;
 
35508
  }
 
35509
}
 
35510
 
 
35511
 
 
35512
 
 
35513
static void 
 
35514
AddSampleDataForBulkEditorSelectedFeatures 
 
35515
(BulkEditorRowPtr berp,
 
35516
 BulkEdFieldPtr   field_list,
 
35517
 Int4             col,
 
35518
 Int4             col_src,
 
35519
 GetSamplePtr     gsp,
 
35520
 TextPortionXPtr   text_portion)
 
35521
{
 
35522
  CharPtr    str, str_src, str_parse;
 
35523
  ValNodePtr vnp, vnp_src;
 
35524
  Boolean    skip;
 
35525
 
 
35526
  if (berp == NULL || field_list == NULL || col < 0 || field_list[col].display_func == NULL || gsp == NULL) return;
 
35527
  
 
35528
  while (berp->object_list != NULL) {
 
35529
    if (berp->subrows == NULL && berp->selected) {
 
35530
      vnp = GetBulkEditorRowValueByColumn (berp, col);
 
35531
      if (vnp != NULL) {
 
35532
        str = (field_list[col]).display_func (vnp->data.ptrvalue);
 
35533
        if (!StringHasNoText (str)) {
 
35534
          skip = FALSE;
 
35535
          /* only add values if col_src < 0 or data in col_src is not blank */
 
35536
          if (col_src >= 0) {
 
35537
            skip = TRUE;
 
35538
            vnp_src = GetBulkEditorRowValueByColumn (berp, col_src);
 
35539
            if (vnp_src != NULL) {
 
35540
              str_src = (field_list[col_src]).display_func(vnp_src->data.ptrvalue);
 
35541
              if (StringDoesHaveText (str_src)) {
 
35542
                if (text_portion == NULL) {
 
35543
                  skip = FALSE;
 
35544
                } else {
 
35545
                  str_parse = ReplaceStringForParse(str_src, text_portion);
 
35546
                  if (StringDoesHaveText (str_parse)) {
 
35547
                    skip = FALSE;
 
35548
                  }
 
35549
                  str_parse = MemFree (str_parse);
 
35550
                }
 
35551
              }
 
35552
              str_src = MemFree (str_src);
 
35553
            }
 
35554
          }
 
35555
          if (!skip) {
 
35556
            gsp->num_found++;
 
35557
            if (gsp->sample_text == NULL) {
 
35558
              gsp->sample_text = str;
 
35559
              str = NULL;
 
35560
            } else if (StringCmp (str, gsp->sample_text) != 0) {
 
35561
              gsp->all_same = FALSE;
 
35562
            }
 
35563
          }
 
35564
        }
 
35565
        str = MemFree (str);
 
35566
      }
 
35567
    }
 
35568
    AddSampleDataForBulkEditorSelectedFeatures (berp->subrows, field_list, col, col_src, gsp, text_portion);
 
35569
    berp++;
 
35570
  }
 
35571
}
 
35572
 
 
35573
 
 
35574
static GetSamplePtr 
 
35575
GetSampleDataForBulkEditorSelectedFeatures 
 
35576
(BulkEditorRowPtr berp,
 
35577
 BulkEdFieldPtr   field_list,
 
35578
 Int4             col,
 
35579
 Int4             col_src,
 
35580
 TextPortionXPtr   text_portion)
 
35581
{
 
35582
  GetSamplePtr gsp;
 
35583
 
 
35584
  if (berp == NULL || field_list == NULL || col < 0) return NULL;
 
35585
 
 
35586
  gsp = GetSampleNew ();
 
35587
 
 
35588
  AddSampleDataForBulkEditorSelectedFeatures(berp, field_list, col, col_src, gsp, text_portion);
 
35589
 
 
35590
  return gsp;
 
35591
}
 
35592
 
 
35593
 
 
35594
static void ApplyBulkEdit (ButtoN b)
 
35595
{
 
35596
  BulkEditorDlgPtr dlg;
 
35597
  RecT             r;
 
35598
  GetSamplePtr     gsp = NULL;
 
35599
  ExistingTextPtr  etp = NULL;
 
35600
  ApplyValueData   avd;
 
35601
  OneFieldBulkEditPtr ofp = NULL;
 
35602
  TwoFieldBulkEditPtr tfp = NULL;
 
35603
 
 
35604
  dlg = (BulkEditorDlgPtr) GetObjectExtra (b);
 
35605
  if (dlg == NULL) return;
 
35606
 
 
35607
  switch (GetValue (dlg->bulk_action)) {
 
35608
    case eBulkRemoveField:
 
35609
      ofp = (OneFieldBulkEditPtr) DialogToPointer (dlg->bulk_remove);
 
35610
      if (ofp != NULL) {
 
35611
        RemoveColumnFromSelectedBulkEditRows (dlg->row_list, ofp->field, dlg->field_list);
 
35612
      }
 
35613
      break;
 
35614
    case eBulkApplyField:
 
35615
      ofp = (OneFieldBulkEditPtr) DialogToPointer (dlg->bulk_apply);
 
35616
      if (ofp != NULL) {
 
35617
        gsp = GetSampleDataForBulkEditorSelectedFeatures (dlg->row_list, dlg->field_list, ofp->field, -1, NULL);
 
35618
        etp = GetExistingTextHandlerInfo (gsp == NULL ? 0 : gsp->num_found, FALSE);
 
35619
        if (etp == NULL || etp->existing_text_choice != eExistingTextChoiceCancel) {
 
35620
          avd.etp = etp;
 
35621
          avd.field_list = NULL;
 
35622
          AddEditApplyDataToApplyValue (AECR_APPLY, ofp->edit_apply, &avd);
 
35623
          ApplyEditColumnFromSelectedBulkEditRows (dlg->row_list, dlg->field_list, ofp->field, &avd);
 
35624
        }
 
35625
      }
 
35626
      break;
 
35627
    case eBulkEditField:
 
35628
      ofp = (OneFieldBulkEditPtr) DialogToPointer (dlg->bulk_edit);
 
35629
      if (ofp != NULL) {
 
35630
        avd.etp = NULL;
 
35631
        avd.field_list = NULL;
 
35632
        AddEditApplyDataToApplyValue (AECR_EDIT, ofp->edit_apply, &avd);
 
35633
        ApplyEditColumnFromSelectedBulkEditRows (dlg->row_list, dlg->field_list, ofp->field, &avd);
 
35634
      }
 
35635
      break;     
 
35636
    case eBulkConvertField:
 
35637
      tfp = (TwoFieldBulkEditPtr) DialogToPointer (dlg->bulk_convert);
 
35638
      if (tfp != NULL) {
 
35639
        gsp = GetSampleDataForBulkEditorSelectedFeatures (dlg->row_list, dlg->field_list, tfp->field_to, tfp->field_from, NULL);
 
35640
        etp = GetExistingTextHandlerInfo (gsp == NULL ? 0 : gsp->num_found, FALSE);
 
35641
        if (etp == NULL || etp->existing_text_choice != eExistingTextChoiceCancel) {
 
35642
          ConvertColumnsForSelectedBulkEditRows (dlg->row_list, dlg->field_list, tfp, etp);
 
35643
        }
 
35644
      }
 
35645
      break;
 
35646
    case eBulkParseField:
 
35647
      tfp = (TwoFieldBulkEditPtr) DialogToPointer (dlg->bulk_parse);
 
35648
      if (tfp != NULL) {
 
35649
        gsp = GetSampleDataForBulkEditorSelectedFeatures (dlg->row_list, dlg->field_list, tfp->field_to, tfp->field_from, tfp->text_portion);
 
35650
        etp = GetExistingTextHandlerInfo (gsp == NULL ? 0 : gsp->num_found, FALSE);        
 
35651
        if (etp == NULL || etp->existing_text_choice != eExistingTextChoiceCancel) {
 
35652
          ParseColumnsForSelectedBulkEditRows (dlg->row_list, dlg->field_list, tfp, etp);
 
35653
        }        
 
35654
      }
 
35655
      break;
 
35656
    case eBulkSwapField:
 
35657
      tfp = (TwoFieldBulkEditPtr) DialogToPointer (dlg->bulk_swap);
 
35658
      if (tfp != NULL) {
 
35659
        SwapColumnsForSelectedBulkEditRows (dlg->row_list, dlg->field_list, tfp->field_from, tfp->field_to);
 
35660
      }
 
35661
      break;
 
35662
    case eBulkCapitalizeField:
 
35663
      ofp = (OneFieldBulkEditPtr) DialogToPointer (dlg->bulk_capitalize);
 
35664
      if (ofp != NULL && ofp->capitalization != NULL && ofp->capitalization->change != eChangeCaseNone) {
 
35665
        CapitalizeColumnsForSelectedBulkEditRows (dlg->row_list, dlg->field_list, ofp->field, ofp->capitalization);
 
35666
      }
 
35667
      break;
 
35668
  }
 
35669
 
 
35670
  ofp = OneFieldBulkEditFree (ofp);
 
35671
  tfp = TwoFieldBulkEditFree (tfp);
 
35672
  gsp = GetSampleFree (gsp);
 
35673
  etp = MemFree (etp);
 
35674
 
 
35675
  UpdateBulkEdDisplay (dlg);
 
35676
  ObjectRect (dlg->doc, &r);
 
35677
  InvalRect (&r);  
 
35678
  Update ();
 
35679
}
 
35680
 
 
35681
 
 
35682
static void BulkEditorCheckAll (ButtoN b)
 
35683
{
 
35684
  BulkEditorDlgPtr dlg;
 
35685
  RecT             r;
 
35686
 
 
35687
  dlg = (BulkEditorDlgPtr) GetObjectExtra (b);
 
35688
  if (dlg == NULL) return;
 
35689
 
 
35690
  SelectBulkEditorRows (dlg->row_list, TRUE);
 
35691
  UpdateCheckStatus (dlg);
 
35692
  ObjectRect (dlg->doc, &r);
 
35693
  InvalRect (&r);  
 
35694
  Update ();
 
35695
}
 
35696
 
 
35697
 
 
35698
static void BulkEditorUncheckAll (ButtoN b)
 
35699
{
 
35700
  BulkEditorDlgPtr dlg;
 
35701
  RecT             r;
 
35702
 
 
35703
  dlg = (BulkEditorDlgPtr) GetObjectExtra (b);
 
35704
  if (dlg == NULL) return;
 
35705
 
 
35706
  SelectBulkEditorRows (dlg->row_list, FALSE);
 
35707
  UpdateCheckStatus (dlg);
 
35708
  ObjectRect (dlg->doc, &r);
 
35709
  InvalRect (&r);  
 
35710
  Update ();
 
35711
}
 
35712
 
 
35713
static void BulkEditorStringConstraintCheck (ButtoN b)
 
35714
{
 
35715
  BulkEditorDlgPtr    dlg;
 
35716
  RecT                r;
 
35717
  Int4                field_num;
 
35718
  StringConstraintXPtr scp;
 
35719
  Boolean             val;
 
35720
 
 
35721
  dlg = (BulkEditorDlgPtr) GetObjectExtra (b);
 
35722
  if (dlg == NULL) return;
 
35723
 
 
35724
  field_num = GetFieldNumFromPopupValue(GetValue (dlg->check_constraint_field), dlg->field_list, FALSE);
 
35725
  scp = DialogToPointer (dlg->check_constraint);
 
35726
 
 
35727
  if (GetValue (dlg->sel_unsel_grp) == 1) {
 
35728
    val = TRUE;
 
35729
  } else {
 
35730
    val = FALSE;
 
35731
  }
 
35732
 
 
35733
  SelectBulkEditorRowsByStringConstraint (dlg->row_list, dlg->field_list, field_num, scp, val);
 
35734
  
 
35735
  scp = StringConstraintXFree (scp);
 
35736
  UpdateCheckStatus (dlg);
 
35737
 
 
35738
  ObjectRect (dlg->doc, &r);
 
35739
  InvalRect (&r);  
 
35740
  Update ();
 
35741
}
 
35742
 
 
35743
 
 
35744
static void ObjectListToBulkEditorDialog (DialoG d, Pointer data)
 
35745
{
 
35746
  BulkEditorDlgPtr dlg;
 
35747
  ValNodePtr       object_list;
 
35748
 
 
35749
  dlg = (BulkEditorDlgPtr) GetObjectExtra (d);
 
35750
  if (dlg == NULL) return;
 
35751
  object_list = (ValNodePtr) data;
 
35752
    
 
35753
  dlg->row_list = FreeBulkEditorRows(dlg->row_list, dlg->field_list);
 
35754
  dlg->row_list = MakeBulkEditorRowsFromObjectList (object_list, dlg->field_list, dlg->last_sorted_col, dlg->metadata);
 
35755
  if (dlg->collapse_by_default) {
 
35756
    CollapseAllBulkEditRows (dlg->row_list);
 
35757
  } else {
 
35758
    ExpandAllBulkEditRows (dlg->row_list);
 
35759
  }
 
35760
  ResetClip();
 
35761
  UpdateBulkEdDisplay (dlg);
 
35762
  UpdateCheckStatus (dlg);
 
35763
}
 
35764
 
 
35765
 
 
35766
static Pointer GetSelectedObjectsFromBulkEditorDialog (DialoG d)
 
35767
{
 
35768
  BulkEditorDlgPtr dlg;
 
35769
  ValNodePtr       object_list = NULL;
 
35770
 
 
35771
  dlg = (BulkEditorDlgPtr) GetObjectExtra (d);
 
35772
  if (dlg == NULL) return NULL;
 
35773
 
 
35774
  GetBulkEditorSelectedObjects (dlg->row_list, &object_list);
 
35775
  return (Pointer) object_list;
 
35776
}
 
35777
 
 
35778
 
 
35779
static DialoG 
 
35780
CreateBulkEditorDialogEx 
 
35781
(GrouP               h,
 
35782
 BulkEdFieldPtr      field_list,
 
35783
 ValNodePtr          feat_list,
 
35784
 SeqEntryPtr         sep, 
 
35785
 Boolean             collapse_by_default,
 
35786
 ClickableCallback   single_click_func,
 
35787
 ClickableCallback   double_click_func,
 
35788
 Pointer             metadata)
 
35789
{
 
35790
  GrouP            p;
 
35791
  BulkEditorDlgPtr dlg;
 
35792
  Int4             width, num_columns = 0;
 
35793
  Int4             i, page_num;
 
35794
  GrouP            ed_grp, check_grp, action_grp, page_grp, box_grp;
 
35795
  GrouP            g1, g2, a;
 
35796
  ButtoN           b; 
 
35797
 
 
35798
  p = HiddenGroup (h, -1, 0, NULL);
 
35799
  dlg = (BulkEditorDlgPtr) MemNew (sizeof (BulkEditorDlgData));
 
35800
 
 
35801
  SetObjectExtra (p, dlg, CleanupBulkEditorDialog); /* need to cleanup values_list */
 
35802
  dlg->dialog = (DialoG) p;
 
35803
  dlg->todialog = ObjectListToBulkEditorDialog; 
 
35804
  dlg->fromdialog = GetSelectedObjectsFromBulkEditorDialog;
 
35805
  dlg->testdialog = NULL;
 
35806
 
 
35807
  dlg->collapse_by_default = collapse_by_default;
 
35808
  dlg->single_click_func = single_click_func;
 
35809
  dlg->double_click_func = double_click_func;
 
35810
  dlg->field_list = field_list;
 
35811
  dlg->metadata = metadata;
 
35812
 
 
35813
  dlg->last_viewed_row = 0;
 
35814
  dlg->last_viewed_col = 0;
 
35815
  dlg->last_sorted_col = 0;
 
35816
  dlg->row_list = MakeBulkEditorRowsFromObjectList(feat_list, dlg->field_list, dlg->last_sorted_col, dlg->metadata);
 
35817
  if (dlg->collapse_by_default) {
 
35818
    CollapseAllBulkEditRows (dlg->row_list);
 
35819
  } else {
 
35820
    ExpandAllBulkEditRows (dlg->row_list);
 
35821
  }
 
35822
 
 
35823
  /* count columns, look for editing functions */
 
35824
  dlg->any_editing = FALSE;
 
35825
  for (i = 0; field_list[i].name != NULL; i++) {
 
35826
    if (field_list[i].create_dlg_func != NULL) {
 
35827
      dlg->any_editing = TRUE;
 
35828
    }
 
35829
    num_columns++;
 
35830
  }
 
35831
  dlg->num_columns = num_columns;
 
35832
  /* populate values list */
 
35833
 
 
35834
  SelectFont (systemFont);
 
35835
  dlg->col_list = AllocateDocColumnsForFieldList (field_list, &width, dlg->last_sorted_col);
 
35836
  dlg->par_fmt.minLines = 1;
 
35837
  dlg->par_fmt.minHeight = 1;
 
35838
 
 
35839
  dlg->title_doc = DocumentPanel (p, width, stdLineHeight);
 
35840
  InitBulkEdTitleDoc (dlg, dlg->title_doc);
 
35841
  SetObjectExtra (dlg->title_doc, dlg, NULL);
 
35842
  SetDocProcs (dlg->title_doc, ClickBulkTitle, NULL, NULL, NULL);
 
35843
 
 
35844
  dlg->doc = DocumentPanel (p, width, 10 * stdLineHeight);
 
35845
  SetObjectExtra (dlg->doc, dlg, NULL);
 
35846
  SetDocProcs (dlg->doc, ClickBulkEdField, NULL, NULL, NULL);
 
35847
  SetDocShade (dlg->doc, DrawBulkEdCell, NULL, HighlightBulkEdField, NULL);
 
35848
 
 
35849
  ed_grp = HiddenGroup (p, 0, 0, NULL);
 
35850
  dlg->editor_list = (DialoG PNTR) MemNew (sizeof(DialoG) * dlg->num_columns);
 
35851
  for (i = 0; field_list[i].name != NULL; i++) {
 
35852
    if (dlg->field_list[i].create_dlg_func == NULL) {
 
35853
      dlg->editor_list[i] = NULL;
 
35854
    } else {
 
35855
      dlg->editor_list[i] = (dlg->field_list[i].create_dlg_func) (ed_grp, field_list[i].name, sep);
 
35856
      Hide (dlg->editor_list[i]);
 
35857
    }
 
35858
  }
 
35859
 
 
35860
  box_grp = HiddenGroup (p, 0, 2, NULL);
 
35861
 
 
35862
  /* group that contains controls for checking and unchecking features */
 
35863
  check_grp = NormalGroup (box_grp, -1, 0, "Check Features", programFont, NULL);
 
35864
  SetGroupSpacing (check_grp, 10, 10);
 
35865
  g1 = HiddenGroup (check_grp, 3, 0, NULL);
 
35866
  SetGroupSpacing (g1, 10, 10);
 
35867
  b = PushButton (g1, "Check All Features", BulkEditorCheckAll);
 
35868
  SetObjectExtra (b, dlg, NULL);
 
35869
  b = PushButton (g1, "Uncheck All Features", BulkEditorUncheckAll);
 
35870
  SetObjectExtra (b, dlg, NULL);
 
35871
  dlg->check_status = StaticPrompt (g1, "0 features are checked", 20 * stdCharWidth, dialogTextHeight, programFont, 'l');
 
35872
 
 
35873
  g2 = HiddenGroup (check_grp, 4, 0, NULL);
 
35874
  dlg->sel_unsel_grp = HiddenGroup (g2, 0, 2, NULL);
 
35875
  RadioButton (dlg->sel_unsel_grp, "Check features where");
 
35876
  RadioButton (dlg->sel_unsel_grp, "Uncheck features where");
 
35877
  SetValue (dlg->sel_unsel_grp, 1);
 
35878
  dlg->check_constraint_field = MakeBulkEditorFieldListPopup (g2, dlg->field_list, FALSE);
 
35879
  dlg->check_constraint = StringConstraintDialogX (g2, NULL, FALSE);
 
35880
  b = PushButton (g2, "Apply", BulkEditorStringConstraintCheck);
 
35881
  SetObjectExtra (b, dlg, NULL);
 
35882
 
 
35883
  if (dlg->any_editing) {
 
35884
    /* group that contains controls for applying actions to check features */
 
35885
    action_grp = NormalGroup (box_grp, -1, 0, "Action for Checked Features", programFont, NULL);
 
35886
    a = HiddenGroup (action_grp, 2, 0, NULL);
 
35887
    SetGroupSpacing (a, 10, 10);
 
35888
    dlg->bulk_action = PopupList (a, TRUE, ChangeBulkEditorAction);
 
35889
    SetObjectExtra (dlg->bulk_action, dlg, NULL);
 
35890
    PopupItem (dlg->bulk_action, "Apply");
 
35891
    PopupItem (dlg->bulk_action, "Edit");
 
35892
    PopupItem (dlg->bulk_action, "Convert");
 
35893
    PopupItem (dlg->bulk_action, "Parse");
 
35894
    PopupItem (dlg->bulk_action, "Swap");
 
35895
    PopupItem (dlg->bulk_action, "Remove");
 
35896
    PopupItem (dlg->bulk_action, "Change Case");
 
35897
    SetValue (dlg->bulk_action, 2);
 
35898
    page_grp = HiddenGroup (a, 0, 0, NULL);
 
35899
    page_num = 0;
 
35900
    dlg->action_pages[page_num] = HiddenGroup (page_grp, 2, 0, NULL);
 
35901
    dlg->bulk_apply = OneFieldBulkEditDialog (dlg->action_pages[page_num], eBulkApplyField, NULL, NULL, dlg->field_list);
 
35902
 
 
35903
    page_num++;
 
35904
    dlg->action_pages[page_num] = HiddenGroup (page_grp, 2, 0, NULL);
 
35905
    dlg->bulk_edit = OneFieldBulkEditDialog (dlg->action_pages[page_num], eBulkEditField, NULL, NULL, dlg->field_list);
 
35906
 
 
35907
    page_num++;
 
35908
    dlg->action_pages[page_num] = HiddenGroup (page_grp, 2, 0, NULL);
 
35909
    dlg->bulk_convert = TwoFieldBulkEditDialog (dlg->action_pages[page_num], eBulkConvertField, NULL, NULL, dlg->field_list, FALSE);
 
35910
 
 
35911
    page_num++;
 
35912
    dlg->action_pages[page_num] = HiddenGroup (page_grp, 2, 0, NULL);
 
35913
    dlg->bulk_parse = TwoFieldBulkEditDialog (dlg->action_pages[page_num], eBulkParseField, NULL, NULL, dlg->field_list, FALSE);
 
35914
 
 
35915
    page_num++;
 
35916
    dlg->action_pages[page_num] = HiddenGroup (page_grp, 2, 0, NULL);
 
35917
    dlg->bulk_swap = TwoFieldBulkEditDialog (dlg->action_pages[page_num], eBulkSwapField, NULL, NULL, dlg->field_list, FALSE);
 
35918
 
 
35919
    page_num++;
 
35920
    dlg->action_pages[page_num] = HiddenGroup (page_grp, 2, 0, NULL);  
 
35921
    dlg->bulk_remove = OneFieldBulkEditDialog (dlg->action_pages[page_num], eBulkRemoveField, NULL, NULL, dlg->field_list);
 
35922
 
 
35923
    page_num++;
 
35924
    dlg->action_pages[page_num] = HiddenGroup (page_grp, 2, 0, NULL);  
 
35925
    dlg->bulk_capitalize = OneFieldBulkEditDialog (dlg->action_pages[page_num], eBulkCapitalizeField, NULL, NULL, dlg->field_list);
 
35926
 
 
35927
    AlignObjects (ALIGN_CENTER, (HANDLE) dlg->action_pages[0], 
 
35928
                                (HANDLE) dlg->action_pages[1], 
 
35929
                                (HANDLE) dlg->action_pages[2], 
 
35930
                                (HANDLE) dlg->action_pages[3], 
 
35931
                                (HANDLE) dlg->action_pages[4], 
 
35932
                                (HANDLE) dlg->action_pages[5], 
 
35933
                                (HANDLE) dlg->action_pages[6], 
 
35934
                                NULL);
 
35935
 
 
35936
    b = PushButton (action_grp, "Apply to Checked Features", ApplyBulkEdit);
 
35937
    SetObjectExtra (b, dlg, NULL);
 
35938
    AlignObjects (ALIGN_CENTER, (HANDLE) a, (HANDLE) b, NULL);
 
35939
  }
 
35940
 
 
35941
 
 
35942
  AlignObjects (ALIGN_CENTER, (HANDLE) dlg->title_doc, (HANDLE) dlg->doc, (HANDLE) ed_grp, (HANDLE) box_grp, NULL);
 
35943
 
 
35944
  UpdateBulkEdDisplay (dlg);
 
35945
  UpdateCheckStatus (dlg);
 
35946
  ChangeBulkEditorAction (dlg->bulk_action);
 
35947
 
 
35948
  return (DialoG) p;
 
35949
}
 
35950
 
 
35951
 
 
35952
NLM_EXTERN DialoG 
 
35953
CreateBulkEditorDialog 
 
35954
(GrouP               h,
 
35955
 BulkEdFieldPtr      field_list,
 
35956
 ValNodePtr          feat_list,
 
35957
 SeqEntryPtr         sep, 
 
35958
 Boolean             collapse_by_default,
 
35959
 ClickableCallback   single_click_func,
 
35960
 ClickableCallback   double_click_func)
 
35961
{
 
35962
  return CreateBulkEditorDialogEx (h, field_list, feat_list, sep, collapse_by_default,
 
35963
                                   single_click_func, double_click_func, NULL);
 
35964
}
 
35965
 
 
35966
 
 
35967
static Pointer BulkGetLocation (Uint1 data_choice, Pointer data, Pointer metadata)
 
35968
{
 
35969
  SeqLocPtr slp;
 
35970
  SeqFeatPtr sfp = (SeqFeatPtr) data;
 
35971
 
 
35972
  if (sfp == NULL) return NULL;
 
35973
  slp = (SeqLocPtr) AsnIoMemCopy (sfp->location, (AsnReadFunc) SeqLocAsnRead, (AsnWriteFunc) SeqLocAsnWrite);
 
35974
  return slp;
 
35975
}
 
35976
 
 
35977
static void BulkSetLocation (Pointer target, Pointer data)
 
35978
{
 
35979
  SeqFeatPtr sfp = (SeqFeatPtr) target;
 
35980
  SeqLocPtr slp = (SeqLocPtr) data;
 
35981
  if (sfp == NULL) return;
 
35982
  sfp->location = SeqLocFree (sfp->location);
 
35983
  sfp->location = (SeqLocPtr) AsnIoMemCopy (slp, (AsnReadFunc) SeqLocAsnRead, (AsnWriteFunc) SeqLocAsnWrite);
 
35984
}
 
35985
 
 
35986
static Int4 BulkFormatLocation (ColPtr col, CharPtr name)
 
35987
{
 
35988
  if (col == NULL) return 0;
 
35989
 
 
35990
  col->pixWidth = MAX (15, StringLen (name)) * stdCharWidth;
 
35991
  col->pixInset = 1;
 
35992
  col->charWidth = 0;
 
35993
  col->charInset = 0;
 
35994
  col->font = NULL;
 
35995
  col->just = 'l';
 
35996
  col->wrap = 1;
 
35997
  col->bar = 0;
 
35998
  col->underline = 0;
 
35999
  col->left = 0;
 
36000
  return col->pixWidth;
 
36001
}
 
36002
 
 
36003
static void BulkFreeLocation (Pointer data)
 
36004
{
 
36005
  SeqLocPtr slp = (SeqLocPtr) data;
 
36006
 
 
36007
  slp = SeqLocFree (slp);
 
36008
}
 
36009
 
 
36010
static CharPtr BulkDisplayLocation (Pointer data)
 
36011
{
 
36012
  SeqLocPtr slp = (SeqLocPtr) data;
 
36013
 
 
36014
  return SeqLocPrint (slp);
 
36015
}
 
36016
 
 
36017
static DialoG BulkNucLocationDialog (GrouP g, CharPtr name, SeqEntryPtr sep)
 
36018
{
 
36019
  return CreateIntervalEditorDialog (g, NULL, 4, 2, sep, TRUE, FALSE);
 
36020
}
 
36021
 
 
36022
static Pointer BulkCopyLocation (Pointer data)
 
36023
{
 
36024
  SeqLocPtr orig = (SeqLocPtr) data;
 
36025
  SeqLocPtr new_loc;
 
36026
 
 
36027
  if (orig == NULL) return NULL;
 
36028
  new_loc = (SeqLocPtr) AsnIoMemCopy ((Pointer) orig,
 
36029
                          (AsnReadFunc) SeqLocAsnRead,
 
36030
                          (AsnWriteFunc) SeqLocAsnWrite);
 
36031
 
 
36032
  return new_loc;
 
36033
}
 
36034
 
 
36035
NLM_EXTERN Int4 BulkFormatSimpleText (ColPtr col, CharPtr name)
 
36036
{
 
36037
  if (col == NULL) return 0;
 
36038
 
 
36039
  col->pixWidth = (MAX (15, StringLen (name)) + 3) * MaxCharWidth();
 
36040
  col->pixInset = 0;
 
36041
  col->charWidth = 0;
 
36042
  col->charInset = 0;
 
36043
  col->font = NULL;
 
36044
  col->just = 'l';
 
36045
  col->wrap = 1;
 
36046
  col->bar = 0;
 
36047
  col->underline = 0;
 
36048
  col->left = 0;
 
36049
  return col->pixWidth;
 
36050
}
 
36051
 
 
36052
NLM_EXTERN void BulkFreeSimpleText (Pointer data)
 
36053
{
 
36054
  CharPtr str = (CharPtr) data;
 
36055
 
 
36056
  str = MemFree (str);
 
36057
}
 
36058
 
 
36059
NLM_EXTERN CharPtr BulkDisplaySimpleText (Pointer data)
 
36060
{
 
36061
  CharPtr str = (CharPtr) data;
 
36062
  if (StringHasNoText (str)) {
 
36063
    return NULL;
 
36064
  } else {
 
36065
    return StringSave ((CharPtr) data);
 
36066
  }
 
36067
}
 
36068
 
 
36069
typedef struct bulksimpletext {
 
36070
  DIALOG_MESSAGE_BLOCK
 
36071
  TexT txt;
 
36072
} BulkSimpleTextData, PNTR BulkSimpleTextPtr;
 
36073
 
 
36074
static void StringToBulkSimpleTextDialog (DialoG d, Pointer data)
 
36075
{
 
36076
  BulkSimpleTextPtr dlg;
 
36077
  CharPtr           str;
 
36078
 
 
36079
  dlg = (BulkSimpleTextPtr) GetObjectExtra (d);
 
36080
  if (dlg == NULL) return;
 
36081
 
 
36082
  str = (CharPtr) data;
 
36083
  if (str == NULL) {
 
36084
    SetTitle (dlg->txt, "");
 
36085
  } else {
 
36086
    SetTitle (dlg->txt, str);
 
36087
  }
 
36088
}
 
36089
 
 
36090
static Pointer BulkSimpleTextDialogToString (DialoG d)
 
36091
{
 
36092
  BulkSimpleTextPtr dlg;
 
36093
 
 
36094
  dlg = (BulkSimpleTextPtr) GetObjectExtra (d);
 
36095
  if (dlg == NULL) return NULL;
 
36096
 
 
36097
  return (Pointer) SaveStringFromText (dlg->txt);
 
36098
}
 
36099
 
 
36100
 
 
36101
 
 
36102
static DialoG BulkSimpleTextDialogEx (GrouP g, CharPtr name, SeqEntryPtr sep, Boolean use_scroll)
 
36103
{
 
36104
  BulkSimpleTextPtr dlg;
 
36105
  GrouP           p;
 
36106
 
 
36107
  p = HiddenGroup (g, 2, 0, NULL);
 
36108
  SetGroupSpacing (p, 10, 10);
 
36109
  dlg = (BulkSimpleTextPtr) MemNew (sizeof(BulkSimpleTextData));
 
36110
 
 
36111
  SetObjectExtra (p, dlg, StdCleanupExtraProc);
 
36112
  dlg->dialog = (DialoG) p;
 
36113
  dlg->todialog = StringToBulkSimpleTextDialog;
 
36114
  dlg->fromdialog = BulkSimpleTextDialogToString;
 
36115
  dlg->testdialog = NULL;
 
36116
 
 
36117
  StaticPrompt (p, name, 0, dialogTextHeight, programFont, 'l');
 
36118
  if (use_scroll) {
 
36119
    dlg->txt = ScrollText (p, 30, 4, programFont, TRUE, NULL);
 
36120
  } else {
 
36121
    dlg->txt = DialogText (p, "", 20, NULL);
 
36122
  }
 
36123
 
 
36124
  return (DialoG) p;
 
36125
}
 
36126
 
 
36127
NLM_EXTERN DialoG BulkSimpleTextDialog (GrouP g, CharPtr name, SeqEntryPtr sep)
 
36128
{
 
36129
  return BulkSimpleTextDialogEx (g, name, sep, FALSE);
 
36130
}
 
36131
 
 
36132
static DialoG BulkSimpleTextScrollDialog (GrouP g, CharPtr name, SeqEntryPtr sep)
 
36133
{
 
36134
  return BulkSimpleTextDialogEx (g, name, sep, TRUE);
 
36135
}
 
36136
 
 
36137
NLM_EXTERN Pointer BulkSimpleTextCopy (Pointer data)
 
36138
{
 
36139
  CharPtr orig = (CharPtr) data;
 
36140
  CharPtr new_str = StringSave (orig);
 
36141
  return new_str;
 
36142
}
 
36143
 
 
36144
static Int4 BulkFormatTrueFalse (ColPtr col, CharPtr name)
 
36145
{
 
36146
  size_t box_width = stdLineHeight - 3;
 
36147
  if (col == NULL) return 0;
 
36148
 
 
36149
  col->pixWidth = MAX (box_width, (StringLen (name) + 2) * MaxCharWidth());
 
36150
  col->pixInset = 0;
 
36151
  col->charWidth = 0;
 
36152
  col->charInset = 0;
 
36153
  col->font = NULL;
 
36154
  col->just = 'l';
 
36155
  col->wrap = 0;
 
36156
  col->bar = 0;
 
36157
  col->underline = 0;
 
36158
  col->left = 0;
 
36159
  return col->pixWidth;
 
36160
}
 
36161
 
 
36162
static void BulkDrawTrueFalse (Pointer p, RectPtr r)
 
36163
{
 
36164
  RecT rct;
 
36165
 
 
36166
  if (r == NULL) return;
 
36167
 
 
36168
  rct = *r;
 
36169
  rct.bottom = rct.top + stdLineHeight - 4;
 
36170
  rct.right = rct.left + stdLineHeight - 4;
 
36171
  InsetRect (&rct, 2, 2);
 
36172
  FrameRect (&rct);
 
36173
  
 
36174
  if (p != NULL) {
 
36175
    MoveTo (rct.left, rct.top);
 
36176
    LineTo (rct.right - 1, rct.bottom - 1);
 
36177
    MoveTo (rct.left, rct.bottom - 1);
 
36178
    LineTo (rct.right - 1, rct.top);
 
36179
  }
 
36180
}
 
36181
 
 
36182
static Pointer BulkReleaseTrueFalse (Pointer p)
 
36183
{
 
36184
  if (p == NULL) {
 
36185
    p = (Pointer) StringSave ("TRUE");
 
36186
  } else {
 
36187
    p = MemFree (p);
 
36188
  }
 
36189
  return p;
 
36190
}
 
36191
 
 
36192
 
 
36193
static void BulkSetPseudo (Pointer target, Pointer val)
 
36194
{
 
36195
  SeqFeatPtr sfp = (SeqFeatPtr) target;
 
36196
  if (sfp == NULL) return;
 
36197
  if (StringHasNoText ((CharPtr)val)) {
 
36198
    sfp->pseudo = FALSE;
 
36199
  } else {
 
36200
    sfp->pseudo = TRUE;
 
36201
  }
 
36202
}
 
36203
 
 
36204
static Pointer BulkGetPseudo (Pointer data)
 
36205
{
 
36206
  SeqFeatPtr sfp = (SeqFeatPtr) data;
 
36207
  if (sfp == NULL || ! sfp->pseudo) {
 
36208
    return NULL;
 
36209
  } else {
 
36210
    return StringSave ("TRUE");
 
36211
  }
 
36212
}
 
36213
 
 
36214
static void BulkSetComment (Pointer target, Pointer data)
 
36215
{
 
36216
  CharPtr str = (CharPtr) data;
 
36217
  SeqFeatPtr sfp = (SeqFeatPtr) target;
 
36218
  if (sfp == NULL) return;
 
36219
 
 
36220
  sfp->comment = MemFree (sfp->comment);
 
36221
  if (str != NULL) {
 
36222
    sfp->comment = StringSave (str);
 
36223
  }
 
36224
}
 
36225
 
 
36226
static Pointer BulkGetComment (Uint1 data_choice, Pointer data, Pointer metadata)
 
36227
{
 
36228
  SeqFeatPtr sfp = (SeqFeatPtr) data;
 
36229
  if (sfp == NULL || StringHasNoText (sfp->comment)) {
 
36230
    return NULL;
 
36231
  } else {
 
36232
    return (Pointer) StringSave (sfp->comment);
 
36233
  }
 
36234
}
 
36235
 
 
36236
static void BulkCDSSetProtein (Pointer target, Pointer data)
 
36237
{
 
36238
  SeqFeatXrefPtr xref;
 
36239
  ProtRefPtr     prp = NULL;
 
36240
  BioseqPtr      prot_bsp;
 
36241
  SeqFeatPtr     prot_feat;
 
36242
  SeqMgrFeatContext fcontext;
 
36243
  ValNodePtr        prot_name_list = NULL, vnp;
 
36244
  SeqFeatPtr sfp = (SeqFeatPtr) target;
 
36245
  if (sfp == NULL) return;
 
36246
 
 
36247
  prot_name_list = (ValNodePtr) data;
 
36248
 
 
36249
  xref = sfp->xref;
 
36250
  while (xref != NULL && xref->data.choice != SEQFEAT_PROT) {
 
36251
    xref = xref->next;
 
36252
  }
 
36253
  if (xref != NULL) {
 
36254
    prp = xref->data.value.ptrvalue;
 
36255
  }
 
36256
 
 
36257
  if (prp == NULL) {
 
36258
    if (sfp->data.choice == SEQFEAT_PROT) {
 
36259
      prp = (ProtRefPtr) sfp->data.value.ptrvalue;
 
36260
    } else if (sfp->data.choice == SEQFEAT_CDREGION) {
 
36261
      prot_bsp = BioseqFindFromSeqLoc (sfp->product);
 
36262
      prot_feat = SeqMgrGetNextFeature (prot_bsp, NULL, SEQFEAT_PROT, FEATDEF_PROT, &fcontext);
 
36263
      if (prot_feat == NULL && prot_name_list != NULL) {
 
36264
        prot_feat = CreateNewFeatureOnBioseq (prot_bsp, SEQFEAT_PROT, NULL);
 
36265
        prp = ProtRefNew ();
 
36266
        prot_feat->data.value.ptrvalue = prp;
 
36267
            SeqMgrIndexFeatures (prot_bsp->idx.entityID, NULL);
 
36268
      }
 
36269
      if (prot_feat != NULL) {
 
36270
        prp = (ProtRefPtr) prot_feat->data.value.ptrvalue;
 
36271
      }
 
36272
    }
 
36273
  }
 
36274
 
 
36275
  if (prp == NULL && prot_name_list != NULL) {
 
36276
    xref = SeqFeatXrefNew ();
 
36277
    prp = ProtRefNew ();
 
36278
    xref->data.choice = SEQFEAT_PROT;
 
36279
    xref->data.value.ptrvalue = prp;
 
36280
    xref->next = sfp->xref;
 
36281
    sfp->xref = xref;
 
36282
  }
 
36283
  if (prp != NULL) {
 
36284
    prp->name = ValNodeFreeData (prp->name);
 
36285
    for (vnp = prot_name_list; vnp != NULL; vnp = vnp->next) {
 
36286
      ValNodeAddPointer (&prp->name, vnp->choice, StringSave (vnp->data.ptrvalue));
 
36287
    }
 
36288
  }
 
36289
 
 
36290
}
 
36291
 
 
36292
static Pointer BulkCDSGetProtein (Uint1 data_choice, Pointer data, Pointer metadata)
 
36293
{
 
36294
  SeqFeatXrefPtr xref;
 
36295
  ProtRefPtr     prp = NULL;
 
36296
  BioseqPtr      prot_bsp;
 
36297
  SeqFeatPtr     prot_feat;
 
36298
  SeqMgrFeatContext fcontext;
 
36299
  ValNodePtr        prot_name_list = NULL, vnp;
 
36300
  SeqFeatPtr        sfp = (SeqFeatPtr) data;
 
36301
 
 
36302
  if (sfp == NULL) return NULL;
 
36303
 
 
36304
  xref = sfp->xref;
 
36305
  while (xref != NULL && xref->data.choice != SEQFEAT_PROT) {
 
36306
    xref = xref->next;
 
36307
  }
 
36308
  if (xref != NULL) {
 
36309
    prp = xref->data.value.ptrvalue;
 
36310
  }
 
36311
 
 
36312
  if (prp == NULL) {
 
36313
    if (sfp->data.choice == SEQFEAT_PROT) {
 
36314
      prp = (ProtRefPtr) sfp->data.value.ptrvalue;
 
36315
    } else if (sfp->data.choice == SEQFEAT_CDREGION) {
 
36316
      prot_bsp = BioseqFindFromSeqLoc (sfp->product);
 
36317
      prot_feat = SeqMgrGetNextFeature (prot_bsp, NULL, SEQFEAT_PROT, FEATDEF_PROT, &fcontext);
 
36318
      if (prot_feat != NULL) {
 
36319
        prp = (ProtRefPtr) prot_feat->data.value.ptrvalue;
 
36320
      }
 
36321
    }
 
36322
  }
 
36323
 
 
36324
  if (prp != NULL) {
 
36325
    for (vnp = prp->name; vnp != NULL; vnp = vnp->next) {
 
36326
      ValNodeAddPointer (&prot_name_list, vnp->choice, StringSave (vnp->data.ptrvalue));
 
36327
    }
 
36328
  }
 
36329
    
 
36330
  return prot_name_list;
 
36331
}
 
36332
 
 
36333
static Pointer BulkCDSCopyProtein (Pointer data)
 
36334
{
 
36335
  ValNodePtr        new_prot_name_list = NULL, prot_name_list, vnp;
 
36336
 
 
36337
  prot_name_list = (ValNodePtr) data;
 
36338
  
 
36339
  for (vnp = prot_name_list; vnp != NULL; vnp = vnp->next) {
 
36340
    ValNodeAddPointer (&new_prot_name_list, vnp->choice, StringSave (vnp->data.ptrvalue));
 
36341
  }
 
36342
  return new_prot_name_list;
 
36343
}  
 
36344
 
 
36345
static Int4 BulkCDSFormatProtein (ColPtr col, CharPtr name)
 
36346
{
 
36347
  if (col == NULL) return 0;
 
36348
 
 
36349
  col->pixWidth = MAX (15, StringLen (name)) * MaxCharWidth();
 
36350
  col->pixInset = 0;
 
36351
  col->charWidth = 0;
 
36352
  col->charInset = 0;
 
36353
  col->font = NULL;
 
36354
  col->just = 'l';
 
36355
  col->wrap = 1;
 
36356
  col->bar = 0;
 
36357
  col->underline = 0;
 
36358
  col->left = 0;
 
36359
  return col->pixWidth;
 
36360
}
 
36361
 
 
36362
static CharPtr BulkCDSDisplayProtein (Pointer data)
 
36363
{
 
36364
  ValNodePtr prot_name_list, vnp;
 
36365
  CharPtr    prot_text;
 
36366
  Int4       text_len = 1;
 
36367
 
 
36368
  if (data == NULL) return NULL;
 
36369
  prot_name_list = (ValNodePtr) data;
 
36370
  for (vnp = prot_name_list; vnp != NULL; vnp = vnp->next) {
 
36371
    text_len += StringLen (vnp->data.ptrvalue) + 1;
 
36372
  }
 
36373
  prot_text = (CharPtr) MemNew (sizeof (Char) * text_len);
 
36374
  prot_text[0] = 0;
 
36375
  for (vnp = prot_name_list; vnp != NULL; vnp = vnp->next) {
 
36376
    StringCat (prot_text, vnp->data.ptrvalue);
 
36377
    if (vnp->next != NULL) {
 
36378
      StringCat (prot_text, ";");
 
36379
    }
 
36380
  }
 
36381
  return prot_text;
 
36382
}
 
36383
 
 
36384
 
 
36385
static Pointer BulkCDSSetProteinString (Pointer curr_val, ApplyValuePtr avp)
 
36386
{
 
36387
  CharPtr        curr_val_str;
 
36388
  CharPtr        new_str, name_str, cp;
 
36389
  ValNodePtr     name_list;
 
36390
 
 
36391
  name_list = (ValNodePtr) curr_val;
 
36392
  curr_val_str = BulkCDSDisplayProtein (name_list);
 
36393
  name_list = ValNodeFreeData (name_list);
 
36394
 
 
36395
  new_str = HandleApplyValue (curr_val_str, avp);
 
36396
 
 
36397
  name_str = new_str;
 
36398
  cp = StringChr (name_str, ';');
 
36399
  while (cp != NULL) {
 
36400
    *cp = 0;
 
36401
    ValNodeAddPointer (&name_list, 0, StringSave (name_str));
 
36402
    *cp = ';';
 
36403
    name_str = cp + 1;
 
36404
    cp = StringChr (name_str, ';');
 
36405
  }
 
36406
  ValNodeAddPointer (&name_list, 0, StringSave (name_str));
 
36407
  new_str = MemFree (new_str);
 
36408
 
 
36409
  return name_list;
 
36410
}
 
36411
 
 
36412
 
 
36413
static void BulkCDSFreeProtein (Pointer data)
 
36414
{
 
36415
  ValNodePtr prot_name_list = (ValNodePtr) data;
 
36416
 
 
36417
  ValNodeFreeData (prot_name_list);
 
36418
}
 
36419
 
 
36420
static DialoG BulkCDSProteinDialog (GrouP g, CharPtr name, SeqEntryPtr sep)
 
36421
{
 
36422
  return CreateVisibleStringDialog (g, 3, -1, 25);
 
36423
}
 
36424
 
 
36425
static void BulkCDSSetProteinDesc (Pointer target, Pointer data)
 
36426
{
 
36427
  SeqFeatXrefPtr xref;
 
36428
  ProtRefPtr     prp = NULL;
 
36429
  BioseqPtr      prot_bsp;
 
36430
  SeqFeatPtr     prot_feat;
 
36431
  SeqMgrFeatContext fcontext;
 
36432
  CharPtr           prot_desc;
 
36433
  SeqFeatPtr sfp = (SeqFeatPtr) target;
 
36434
  if (sfp == NULL) return;
 
36435
 
 
36436
  prot_desc = (CharPtr) data;
 
36437
 
 
36438
  xref = sfp->xref;
 
36439
  while (xref != NULL && xref->data.choice != SEQFEAT_PROT) {
 
36440
    xref = xref->next;
 
36441
  }
 
36442
  if (xref != NULL) {
 
36443
    prp = xref->data.value.ptrvalue;
 
36444
  }
 
36445
 
 
36446
  if (prp == NULL) {
 
36447
    if (sfp->data.choice == SEQFEAT_PROT) {
 
36448
      prp = (ProtRefPtr) sfp->data.value.ptrvalue;
 
36449
    } else if (sfp->data.choice == SEQFEAT_CDREGION) {
 
36450
      prot_bsp = BioseqFindFromSeqLoc (sfp->product);
 
36451
      prot_feat = SeqMgrGetNextFeature (prot_bsp, NULL, SEQFEAT_PROT, FEATDEF_PROT, &fcontext);
 
36452
      if (prot_feat == NULL && !StringHasNoText (prot_desc)) {
 
36453
        prot_feat = CreateNewFeatureOnBioseq (prot_bsp, SEQFEAT_PROT, NULL);
 
36454
        prp = ProtRefNew ();
 
36455
        prot_feat->data.value.ptrvalue = prp;
 
36456
            SeqMgrIndexFeatures (prot_bsp->idx.entityID, NULL);
 
36457
      }
 
36458
      if (prot_feat != NULL) {
 
36459
        prp = (ProtRefPtr) prot_feat->data.value.ptrvalue;
 
36460
      }
 
36461
    }
 
36462
  }
 
36463
 
 
36464
  if (prp == NULL && !StringHasNoText (prot_desc)) {
 
36465
    xref = SeqFeatXrefNew ();
 
36466
    prp = ProtRefNew ();
 
36467
    xref->data.choice = SEQFEAT_PROT;
 
36468
    xref->data.value.ptrvalue = prp;
 
36469
    xref->next = sfp->xref;
 
36470
    sfp->xref = xref;
 
36471
  }
 
36472
  if (prp != NULL) {
 
36473
    prp->desc = StringSave (prot_desc);
 
36474
  }
 
36475
 
 
36476
}
 
36477
 
 
36478
 
 
36479
static Pointer BulkCDSGetProteinDesc (Uint1 data_choice, Pointer data, Pointer metadata)
 
36480
{
 
36481
  SeqFeatXrefPtr xref;
 
36482
  ProtRefPtr     prp = NULL;
 
36483
  BioseqPtr      prot_bsp;
 
36484
  SeqFeatPtr     prot_feat;
 
36485
  SeqMgrFeatContext fcontext;
 
36486
  CharPtr           prot_desc = NULL;
 
36487
  SeqFeatPtr sfp = (SeqFeatPtr) data;
 
36488
 
 
36489
  if (sfp == NULL) return NULL;
 
36490
 
 
36491
  xref = sfp->xref;
 
36492
  while (xref != NULL && xref->data.choice != SEQFEAT_PROT) {
 
36493
    xref = xref->next;
 
36494
  }
 
36495
  if (xref != NULL) {
 
36496
    prp = xref->data.value.ptrvalue;
 
36497
  }
 
36498
 
 
36499
  if (prp == NULL) {
 
36500
    if (sfp->data.choice == SEQFEAT_PROT) {
 
36501
      prp = (ProtRefPtr) sfp->data.value.ptrvalue;
 
36502
    } else if (sfp->data.choice == SEQFEAT_CDREGION) {
 
36503
      prot_bsp = BioseqFindFromSeqLoc (sfp->product);
 
36504
      prot_feat = SeqMgrGetNextFeature (prot_bsp, NULL, SEQFEAT_PROT, FEATDEF_PROT, &fcontext);
 
36505
      if (prot_feat != NULL) {
 
36506
        prp = (ProtRefPtr) prot_feat->data.value.ptrvalue;
 
36507
      }
 
36508
    }
 
36509
  }
 
36510
 
 
36511
  if (prp != NULL) {
 
36512
    prot_desc = StringSave (prp->desc);
 
36513
  }
 
36514
    
 
36515
  return prot_desc;
 
36516
}
 
36517
 
 
36518
 
 
36519
static void BulkGeneSetLocus (Pointer target, Pointer data)
 
36520
{
 
36521
  CharPtr    str = (CharPtr) data;
 
36522
  GeneRefPtr grp;
 
36523
  SeqFeatPtr sfp = (SeqFeatPtr) target;
 
36524
 
 
36525
  if (sfp == NULL || sfp->idx.subtype != FEATDEF_GENE) return;
 
36526
 
 
36527
  grp = (GeneRefPtr) sfp->data.value.ptrvalue;
 
36528
  if (grp == NULL) {
 
36529
    grp = GeneRefNew();
 
36530
    sfp->data.value.ptrvalue = grp;
 
36531
  }
 
36532
  grp->locus = MemFree (grp->locus);
 
36533
  if (str != NULL) {
 
36534
    grp->locus = StringSave (str);
 
36535
  }
 
36536
}
 
36537
 
 
36538
static Pointer BulkGeneGetLocus (Uint1 data_choice, Pointer data, Pointer metadata)
 
36539
{
 
36540
  GeneRefPtr grp; 
 
36541
  SeqFeatPtr sfp = (SeqFeatPtr) data;
 
36542
 
 
36543
  if (sfp == NULL || sfp->idx.subtype != FEATDEF_GENE || sfp->data.value.ptrvalue == NULL) {
 
36544
    return NULL;
 
36545
  }
 
36546
  grp = (GeneRefPtr) sfp->data.value.ptrvalue;
 
36547
  if (StringHasNoText (grp->locus)) {
 
36548
    return NULL;
 
36549
  } else {
 
36550
    return (Pointer) StringSave (grp->locus);
 
36551
  }
 
36552
}
 
36553
 
 
36554
static void BulkGeneSetLocusTag (Pointer target, Pointer data)
 
36555
{
 
36556
  CharPtr    str = (CharPtr) data;
 
36557
  GeneRefPtr grp;
 
36558
  SeqFeatPtr sfp = (SeqFeatPtr) target;
 
36559
 
 
36560
  if (sfp == NULL || sfp->idx.subtype != FEATDEF_GENE) return;
 
36561
 
 
36562
  grp = (GeneRefPtr) sfp->data.value.ptrvalue;
 
36563
  if (grp == NULL) {
 
36564
    grp = GeneRefNew();
 
36565
    sfp->data.value.ptrvalue = grp;
 
36566
  }
 
36567
  grp->locus_tag = MemFree (grp->locus_tag);
 
36568
  if (str != NULL) {
 
36569
    grp->locus_tag = StringSave (str);
 
36570
  }
 
36571
}
 
36572
 
 
36573
static Pointer BulkGeneGetLocusTag (Uint1 data_choice, Pointer data, Pointer metadata)
 
36574
{
 
36575
  GeneRefPtr grp;
 
36576
  SeqFeatPtr sfp = (SeqFeatPtr) data;
 
36577
 
 
36578
  if (sfp == NULL || sfp->idx.subtype != FEATDEF_GENE || sfp->data.value.ptrvalue == NULL) {
 
36579
    return NULL;
 
36580
  }
 
36581
  grp = (GeneRefPtr) sfp->data.value.ptrvalue;
 
36582
  if (StringHasNoText (grp->locus_tag)) {
 
36583
    return NULL;
 
36584
  } else {
 
36585
    return (Pointer) StringSave (grp->locus_tag);
 
36586
  }
 
36587
}
 
36588
 
 
36589
static void BulkGeneSetDescription (Pointer target, Pointer data)
 
36590
{
 
36591
  CharPtr    str = (CharPtr) data;
 
36592
  GeneRefPtr grp;
 
36593
  SeqFeatPtr sfp = (SeqFeatPtr) target;
 
36594
 
 
36595
  if (sfp == NULL || sfp->idx.subtype != FEATDEF_GENE) return;
 
36596
 
 
36597
  grp = (GeneRefPtr) sfp->data.value.ptrvalue;
 
36598
  if (grp == NULL) {
 
36599
    grp = GeneRefNew();
 
36600
    sfp->data.value.ptrvalue = grp;
 
36601
  }
 
36602
  grp->desc = MemFree (grp->desc);
 
36603
  if (str != NULL) {
 
36604
    grp->desc = StringSave (str);
 
36605
  }
 
36606
}
 
36607
 
 
36608
static Pointer BulkGeneGetDescription (Uint1 data_choice, Pointer data, Pointer metadata)
 
36609
{
 
36610
  GeneRefPtr grp;
 
36611
  SeqFeatPtr sfp = (SeqFeatPtr) data;
 
36612
 
 
36613
  if (sfp == NULL || sfp->idx.subtype != FEATDEF_GENE || sfp->data.value.ptrvalue == NULL) {
 
36614
    return NULL;
 
36615
  }
 
36616
  grp = (GeneRefPtr) sfp->data.value.ptrvalue;
 
36617
  if (StringHasNoText (grp->desc)) {
 
36618
    return NULL;
 
36619
  } else {
 
36620
    return (Pointer) StringSave (grp->desc);
 
36621
  }
 
36622
}
 
36623
 
 
36624
 
 
36625
static void BulkRNASetProduct (Pointer target, Pointer data)
 
36626
{
 
36627
  RnaRefPtr  rrp;
 
36628
  CharPtr    rna_product;
 
36629
  SeqFeatPtr sfp = (SeqFeatPtr) target;
 
36630
 
 
36631
  if (sfp == NULL || sfp->data.choice != SEQFEAT_RNA) return;
 
36632
 
 
36633
  rna_product = (CharPtr) data;
 
36634
 
 
36635
  rrp = (RnaRefPtr) sfp->data.value.ptrvalue;
 
36636
  if (rrp == NULL && !StringHasNoText (rna_product)) {
 
36637
    rrp = RnaRefNew ();
 
36638
    rrp->ext.choice = 1;
 
36639
    sfp->data.value.ptrvalue = rrp;
 
36640
  }
 
36641
  if (rrp->ext.choice == 0 && !StringHasNoText (rna_product)) {
 
36642
    rrp->ext.choice = 1;
 
36643
  } else if (rrp->ext.choice == 1 && StringHasNoText (rna_product)) {
 
36644
    rrp->ext.choice = 0;
 
36645
    rrp->ext.value.ptrvalue = MemFree (rrp->ext.value.ptrvalue);
 
36646
  }
 
36647
 
 
36648
  if (rrp != NULL && rrp->ext.choice == 1) {    
 
36649
    rrp->ext.value.ptrvalue = MemFree (rrp->ext.value.ptrvalue);
 
36650
    rrp->ext.value.ptrvalue = StringSave (rna_product);
 
36651
  }
 
36652
}
 
36653
 
 
36654
static Pointer BulkRNAGetProduct (Uint1 data_choice, Pointer data, Pointer metadata)
 
36655
{
 
36656
  RnaRefPtr  rrp;
 
36657
  CharPtr    rna_product = NULL;
 
36658
  SeqFeatPtr sfp = (SeqFeatPtr) data;
 
36659
 
 
36660
  if (sfp == NULL || sfp->data.choice != SEQFEAT_RNA) return NULL;
 
36661
 
 
36662
  rrp = (RnaRefPtr) sfp->data.value.ptrvalue;
 
36663
  if (rrp != NULL) {
 
36664
    if (rrp->ext.choice == 1) {
 
36665
      rna_product = StringSave( rrp->ext.value.ptrvalue);
 
36666
    }
 
36667
  }
 
36668
 
 
36669
    
 
36670
  return rna_product;
 
36671
}
 
36672
 
 
36673
static Boolean IsBulkEditableRNA (SeqFeatPtr sfp)
 
36674
{
 
36675
  RnaRefPtr rrp;
 
36676
 
 
36677
  if (sfp == NULL || sfp->data.choice != SEQFEAT_RNA) {
 
36678
    return FALSE;
 
36679
  }
 
36680
  rrp = (RnaRefPtr) sfp->data.value.ptrvalue;
 
36681
  if (rrp != NULL && rrp->ext.choice != 1 && rrp->ext.choice != 0) {
 
36682
    return FALSE;
 
36683
  } else {
 
36684
    return TRUE;
 
36685
  }
 
36686
}
 
36687
 
 
36688
 
 
36689
/* template for setting simple text strings */
 
36690
NLM_EXTERN Pointer BulkSetSimpleTextString (Pointer curr_val, ApplyValuePtr avp)
 
36691
{
 
36692
  CharPtr        curr_val_str;
 
36693
 
 
36694
  curr_val_str = (CharPtr)curr_val;
 
36695
  return HandleApplyValue (curr_val_str, avp);
 
36696
}
 
36697
 
 
36698
/* for now, disallow pseudo editing and display.  To add back, put in this line:
 
36699
  { "pseudo", BulkSetPseudo, BulkGetPseudo, NULL, NULL, NULL, BulkFormatTrueFalse, BulkDrawTrueFalse, BulkReleaseTrueFalse },
 
36700
*/
 
36701
/* for now, disallow location editing (but continue display).  To add back, use BulkNucLocationDialog in dialog. */
 
36702
static BulkEdFieldData bulk_cds_fields[] = {
 
36703
  { "protein name", BulkCDSSetProtein, BulkCDSSetProteinString, BulkCDSGetProtein, BulkCDSDisplayProtein, BulkCDSFreeProtein, BulkCDSProteinDialog, BulkCDSFormatProtein, NULL, NULL, BulkCDSCopyProtein },
 
36704
  { "protein description", BulkCDSSetProteinDesc, BulkSetSimpleTextString, BulkCDSGetProteinDesc, BulkDisplaySimpleText, BulkFreeSimpleText, BulkSimpleTextDialog, BulkFormatSimpleText, NULL, NULL, BulkSimpleTextCopy },
 
36705
  { "location", BulkSetLocation, NULL, BulkGetLocation, BulkDisplayLocation, BulkFreeLocation, NULL, BulkFormatLocation, NULL, NULL, BulkCopyLocation },
 
36706
  { "comment", BulkSetComment, BulkSetSimpleTextString, BulkGetComment, BulkDisplaySimpleText, BulkFreeSimpleText, BulkSimpleTextScrollDialog, BulkFormatSimpleText, NULL, NULL, BulkSimpleTextCopy },
 
36707
  { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}};
 
36708
 
 
36709
static BulkEdFieldData bulk_gene_fields[] = {
 
36710
  { "locus", BulkGeneSetLocus, BulkSetSimpleTextString, BulkGeneGetLocus, BulkDisplaySimpleText, BulkFreeSimpleText, BulkSimpleTextDialog, BulkFormatSimpleText, NULL, NULL, BulkSimpleTextCopy },
 
36711
  { "locus_tag", BulkGeneSetLocusTag, BulkSetSimpleTextString, BulkGeneGetLocusTag, BulkDisplaySimpleText, BulkFreeSimpleText, BulkSimpleTextDialog, BulkFormatSimpleText, NULL, NULL, BulkSimpleTextCopy },
 
36712
  { "description", BulkGeneSetDescription, BulkSetSimpleTextString, BulkGeneGetDescription, BulkDisplaySimpleText, BulkFreeSimpleText, BulkSimpleTextDialog, BulkFormatSimpleText, NULL, NULL, BulkSimpleTextCopy },
 
36713
  { "location", BulkSetLocation, NULL, BulkGetLocation, BulkDisplayLocation, BulkFreeLocation, NULL, BulkFormatLocation, NULL, NULL, BulkCopyLocation },
 
36714
  { "comment", BulkSetComment, BulkSetSimpleTextString, BulkGetComment, BulkDisplaySimpleText, BulkFreeSimpleText, BulkSimpleTextScrollDialog, BulkFormatSimpleText, NULL, NULL, BulkSimpleTextCopy },
 
36715
  { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}};
 
36716
 
 
36717
static BulkEdFieldData bulk_rna_fields[] = {
 
36718
  { "product", BulkRNASetProduct, BulkSetSimpleTextString, BulkRNAGetProduct, BulkDisplaySimpleText, BulkFreeSimpleText, BulkSimpleTextDialog, BulkFormatSimpleText, NULL, NULL, BulkSimpleTextCopy },
 
36719
  { "location", BulkSetLocation, NULL, BulkGetLocation, BulkDisplayLocation, BulkFreeLocation, NULL, BulkFormatLocation, NULL, NULL, BulkCopyLocation },
 
36720
  { "comment", BulkSetComment, BulkSetSimpleTextString, BulkGetComment, BulkDisplaySimpleText, BulkFreeSimpleText, BulkSimpleTextScrollDialog, BulkFormatSimpleText, NULL, NULL, BulkSimpleTextCopy },
 
36721
  { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}};
 
36722
 
 
36723
 
 
36724
static BulkEdFieldPtr GetBulkEditorFieldListForFeature (SeqFeatPtr sfp)
 
36725
{
 
36726
  if (sfp == NULL) {
 
36727
    return NULL;
 
36728
  } else if (sfp->data.choice == SEQFEAT_CDREGION) {
 
36729
    return bulk_cds_fields;
 
36730
  } else if (sfp->data.choice == SEQFEAT_GENE) {
 
36731
    return bulk_gene_fields;
 
36732
  } else if (sfp->data.choice == SEQFEAT_RNA && IsBulkEditableRNA(sfp)) {
 
36733
    /* Note - using FEATDEF_rRNA to represent all editable rRNA features */
 
36734
    return bulk_rna_fields;
 
36735
  } else {
 
36736
    return NULL;
 
36737
  }
 
36738
}
 
36739
 
 
36740
 
 
36741
static void BulkSrcSetTaxNameDesc (Pointer target, Pointer data)
 
36742
{
 
36743
  CharPtr      taxname;
 
36744
  SeqDescrPtr  sdp = (SeqDescrPtr) target;
 
36745
  BioSourcePtr biop;
 
36746
 
 
36747
  if (sdp == NULL || sdp->choice != Seq_descr_source || sdp->data.ptrvalue == NULL) return;
 
36748
 
 
36749
  biop = (BioSourcePtr) sdp->data.ptrvalue;
 
36750
 
 
36751
  taxname = (CharPtr) data;
 
36752
 
 
36753
  if (biop->org == NULL) {
 
36754
    biop->org = OrgRefNew();
 
36755
  }
 
36756
  SetTaxNameAndRemoveTaxRef (biop->org, StringSave (taxname)); 
 
36757
}
 
36758
 
 
36759
 
 
36760
NLM_EXTERN BioSourcePtr GetBioSourceFromObject (Uint1 choice, Pointer data);
 
36761
 
 
36762
static Pointer BulkSrcGetTaxNameDesc (Uint1 data_choice, Pointer data, Pointer metadata)
 
36763
{
 
36764
  CharPtr      taxname = NULL;
 
36765
  BioSourcePtr biop = NULL;
 
36766
 
 
36767
  biop = GetBioSourceFromObject (data_choice, data);
 
36768
  if (biop == NULL) return NULL;
 
36769
 
 
36770
  if (biop->org != NULL) {
 
36771
    taxname = StringSave (biop->org->taxname);
 
36772
  }
 
36773
 
 
36774
  return taxname;
 
36775
}
 
36776
 
 
36777
 
 
36778
static void BulkSrcSetTaxNameFeat (Pointer target, Pointer data)
 
36779
{
 
36780
  CharPtr      taxname;
 
36781
  SeqFeatPtr   sfp = (SeqFeatPtr) target;
 
36782
  BioSourcePtr biop;
 
36783
 
 
36784
  if (sfp == NULL || sfp->data.choice != SEQFEAT_BIOSRC || sfp->data.value.ptrvalue == NULL) return;
 
36785
 
 
36786
  biop = (BioSourcePtr) sfp->data.value.ptrvalue;
 
36787
 
 
36788
  taxname = (CharPtr) data;
 
36789
 
 
36790
  if (biop->org == NULL) {
 
36791
    biop->org = OrgRefNew();
 
36792
  }
 
36793
  SetTaxNameAndRemoveTaxRef (biop->org, StringSave (taxname)); 
 
36794
}
 
36795
 
 
36796
 
 
36797
static Pointer BulkSrcGetTaxNameFeat (Uint1 data_choice, Pointer data, Pointer metadata)
 
36798
{
 
36799
  CharPtr      taxname = NULL;
 
36800
  SeqFeatPtr   sfp = (SeqFeatPtr) data;
 
36801
  BioSourcePtr biop;
 
36802
 
 
36803
  if (sfp == NULL || sfp->data.choice != SEQFEAT_BIOSRC || sfp->data.value.ptrvalue == NULL) return NULL;
 
36804
 
 
36805
  biop = (BioSourcePtr) sfp->data.value.ptrvalue;
 
36806
 
 
36807
  if (biop->org != NULL) {
 
36808
    taxname = StringSave (biop->org->taxname);
 
36809
  }
 
36810
 
 
36811
  return taxname;
 
36812
}
 
36813
 
 
36814
 
 
36815
static BulkEdFieldData bulk_src_desc_fields[] = {
 
36816
  { "tax name", BulkSrcSetTaxNameDesc, BulkSetSimpleTextString, BulkSrcGetTaxNameDesc, BulkDisplaySimpleText, BulkFreeSimpleText, BulkSimpleTextDialog, BulkFormatSimpleText, NULL, NULL, BulkSimpleTextCopy },
 
36817
  { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}};
 
36818
 
 
36819
static BulkEdFieldData bulk_src_feat_fields[] = {
 
36820
  { "tax name", BulkSrcSetTaxNameFeat, BulkSetSimpleTextString, BulkSrcGetTaxNameFeat, BulkDisplaySimpleText, BulkFreeSimpleText, BulkSimpleTextDialog, BulkFormatSimpleText, NULL, NULL, BulkSimpleTextCopy },
 
36821
  { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}};
 
36822
 
 
36823
typedef struct bulkeditor {
 
36824
  FORM_MESSAGE_BLOCK
 
36825
  DialoG         bulk_ed;
 
36826
  BulkEdFieldPtr field_list;
 
36827
} BulkEditorData, PNTR BulkEditorPtr;
 
36828
 
 
36829
typedef struct collectfeat {
 
36830
  Uint1 featdef;
 
36831
  Uint1 featchoice;
 
36832
  ValNodePtr feat_list;
 
36833
} CollectFeatData, PNTR CollectFeatPtr;
 
36834
 
 
36835
static void CollectFeaturesForBulkEditor (BioseqPtr bsp, Pointer data)
 
36836
{
 
36837
  CollectFeatPtr cfp;
 
36838
  SeqFeatPtr     sfp;
 
36839
  SeqMgrFeatContext fcontext;
 
36840
 
 
36841
  if (bsp == NULL || data == NULL) return;
 
36842
  cfp = (CollectFeatPtr) data;
 
36843
 
 
36844
  for (sfp = SeqMgrGetNextFeature (bsp, NULL, cfp->featchoice, cfp->featdef, &fcontext);
 
36845
       sfp != NULL;
 
36846
       sfp = SeqMgrGetNextFeature (bsp, sfp, cfp->featchoice, cfp->featdef, &fcontext)) {
 
36847
    ValNodeAddPointer (&(cfp->feat_list), OBJ_SEQFEAT, sfp);
 
36848
  }
 
36849
}
 
36850
 
 
36851
static void AcceptBulkEditor (ButtoN b)
 
36852
{
 
36853
  BulkEditorPtr      bep;
 
36854
 
 
36855
  bep = (BulkEditorPtr) GetObjectExtra (b);
 
36856
  if (bep == NULL) return;
 
36857
 
 
36858
  WatchCursor();
 
36859
  Update();
 
36860
 
 
36861
  ApplyBulkEditorToObjectList (bep->bulk_ed);
 
36862
 
 
36863
  ObjMgrSetDirtyFlag (bep->input_entityID, TRUE);
 
36864
  ObjMgrSendMsg (OM_MSG_UPDATE, bep->input_entityID, 0, 0);
 
36865
  ArrowCursor ();
 
36866
  Update ();
 
36867
  Remove (bep->form);
 
36868
}
 
36869
 
 
36870
extern Uint1 GetSubtypeForBulkEdit (ValNodePtr feat_list)
 
36871
{
 
36872
  ValNodePtr vnp_check;
 
36873
  SeqFeatPtr sfp;
 
36874
  Uint1      subtype = FEATDEF_BAD;
 
36875
 
 
36876
  for (vnp_check = feat_list; vnp_check != NULL; vnp_check = vnp_check->next) {
 
36877
    if (vnp_check->choice != OBJ_SEQFEAT) continue;
 
36878
    sfp = vnp_check->data.ptrvalue;
 
36879
    if (sfp->data.choice == SEQFEAT_RNA) {
 
36880
      /* note - using FEATDEF_rRNA to represent all editable RNA features */
 
36881
      if (!IsBulkEditableRNA(sfp)) {
 
36882
        return FEATDEF_BAD;
 
36883
      } else if (subtype == FEATDEF_BAD) {
 
36884
        subtype = FEATDEF_rRNA;
 
36885
      } else if (subtype != FEATDEF_rRNA) {
 
36886
        return FEATDEF_BAD;
 
36887
      }
 
36888
    } else if (subtype == FEATDEF_BAD) {
 
36889
      subtype = sfp->idx.subtype;
 
36890
    } else if (subtype != sfp->idx.subtype) {
 
36891
      return FEATDEF_BAD;
 
36892
    }
 
36893
  }
 
36894
  return subtype;
 
36895
}
 
36896
 
 
36897
extern void BulkEditorFeatList (Uint2 entityID, ValNodePtr feat_list)
 
36898
{
 
36899
  GrouP              c;
 
36900
  ButtoN             b;
 
36901
  BulkEditorPtr      bep;
 
36902
  GrouP              h;
 
36903
  WindoW             w;
 
36904
  SeqEntryPtr        sep;
 
36905
  BulkEdFieldPtr     field_list = NULL;
 
36906
  Uint1              subtype = 0;
 
36907
 
 
36908
  if (feat_list == NULL) {
 
36909
    Message (MSG_ERROR, "No features found!");
 
36910
    return;
 
36911
  }
 
36912
  /* Create a new window, and a struct */
 
36913
  /* to pass around the data in.       */
 
36914
 
 
36915
  sep = GetTopSeqEntryForEntityID (entityID);
 
36916
 
 
36917
  subtype = GetSubtypeForBulkEdit (feat_list);
 
36918
  if (subtype == FEATDEF_BAD) {
 
36919
    Message (MSG_ERROR, "Can't bulk edit a list of mixed feature types!");
 
36920
    return;
 
36921
  }
 
36922
  if (subtype == FEATDEF_CDS) {
 
36923
    field_list = bulk_cds_fields;
 
36924
  } else if (subtype == FEATDEF_GENE) {
 
36925
    field_list = bulk_gene_fields;
 
36926
  } else if (subtype == FEATDEF_rRNA) {
 
36927
    /* Note - using FEATDEF_rRNA to represent all editable rRNA features */
 
36928
    field_list = bulk_rna_fields;
 
36929
  } else if (subtype == FEATDEF_BIOSRC) {
 
36930
    field_list = bulk_src_feat_fields;
 
36931
  } else {
 
36932
    Message (MSG_ERROR, "No bulk editor for this feature type!");
 
36933
    return;
 
36934
  }
 
36935
 
 
36936
  bep = (BulkEditorPtr) MemNew (sizeof (BulkEditorData));
 
36937
  if (bep == NULL)
 
36938
    return;
 
36939
 
 
36940
  bep->field_list = field_list;
 
36941
 
 
36942
  w = FixedWindow (-50, -33, -10, -10, "Bulk Editor",
 
36943
                   StdCloseWindowProc);
 
36944
  SetObjectExtra (w, bep, StdCleanupFormProc); 
 
36945
  bep->form = (ForM) w;
 
36946
  bep->input_entityID = entityID;
 
36947
 
 
36948
  h = HiddenGroup (w, -1, 0, NULL);
 
36949
  SetGroupSpacing (h, 10, 10);
 
36950
 
 
36951
  /* want: Document with columns for pseudo (when appropriate), location, fields */
 
36952
  /* when user clicks on field, should be able to edit contents */
 
36953
  
 
36954
  bep->bulk_ed = CreateBulkEditorDialog (h, bep->field_list, feat_list, sep, TRUE, NULL, NULL);
 
36955
 
 
36956
  /* Add Accept and Cancel buttons */
 
36957
 
 
36958
  c = HiddenGroup (h, 3, 0, NULL);
 
36959
  b = PushButton (c, "Accept", AcceptBulkEditor);
 
36960
  SetObjectExtra (b, bep, NULL);
 
36961
  PushButton (c, "Cancel", StdCancelButtonProc);
 
36962
 
 
36963
  /* Line things up nicely */
 
36964
 
 
36965
  AlignObjects (ALIGN_CENTER, (HANDLE) bep->bulk_ed,
 
36966
                              (HANDLE) c, NULL);
 
36967
 
 
36968
 
 
36969
  /* Display the window now */
 
36970
 
 
36971
  RealizeWindow (w);
 
36972
  Show (w);
 
36973
  Select (w);
 
36974
  Update ();
 
36975
}
 
36976
 
 
36977
 
 
36978
extern Uint1 GetSubtypeForBulkDescrEdit (ValNodePtr descr_list)
 
36979
{
 
36980
  ValNodePtr vnp_check;
 
36981
  SeqDescrPtr sdp;
 
36982
  Uint1      subtype = 0;
 
36983
 
 
36984
  for (vnp_check = descr_list; vnp_check != NULL; vnp_check = vnp_check->next) {
 
36985
    if (vnp_check->choice != OBJ_SEQDESC) continue;
 
36986
    sdp = vnp_check->data.ptrvalue;
 
36987
    if (subtype == 0) {
 
36988
      subtype = sdp->choice;
 
36989
    } else if (sdp->choice != subtype) {
 
36990
      return 0;
 
36991
    }
 
36992
  }
 
36993
  return subtype;
 
36994
}
 
36995
 
 
36996
 
 
36997
extern void BulkEditorDescrList (Uint2 entityID, ValNodePtr descr_list)
 
36998
{
 
36999
  GrouP              c;
 
37000
  ButtoN             b;
 
37001
  BulkEditorPtr      bep;
 
37002
  GrouP              h;
 
37003
  WindoW             w;
 
37004
  SeqEntryPtr        sep;
 
37005
  BulkEdFieldPtr     field_list = NULL;
 
37006
  Uint1              subtype = 0;
 
37007
 
 
37008
  if (descr_list == NULL) {
 
37009
    Message (MSG_ERROR, "No descriptors found!");
 
37010
    return;
 
37011
  }
 
37012
  /* Create a new window, and a struct */
 
37013
  /* to pass around the data in.       */
 
37014
 
 
37015
  sep = GetTopSeqEntryForEntityID (entityID);
 
37016
 
 
37017
  subtype = GetSubtypeForBulkDescrEdit (descr_list);
 
37018
  if (subtype == 0) {
 
37019
    Message (MSG_ERROR, "Can't bulk edit a list of mixed descriptor types!");
 
37020
    return;
 
37021
  }
 
37022
  if (subtype == Seq_descr_source) {
 
37023
    field_list = bulk_src_desc_fields;
 
37024
  } else {
 
37025
    Message (MSG_ERROR, "No bulk editor for this descriptor type!");
 
37026
    return;
 
37027
  }
 
37028
 
 
37029
  bep = (BulkEditorPtr) MemNew (sizeof (BulkEditorData));
 
37030
  if (bep == NULL)
 
37031
    return;
 
37032
 
 
37033
  bep->field_list = field_list;
 
37034
 
 
37035
  w = FixedWindow (-50, -33, -10, -10, "Bulk Editor",
 
37036
                   StdCloseWindowProc);
 
37037
  SetObjectExtra (w, bep, StdCleanupFormProc); 
 
37038
  bep->form = (ForM) w;
 
37039
  bep->input_entityID = entityID;
 
37040
 
 
37041
  h = HiddenGroup (w, -1, 0, NULL);
 
37042
  SetGroupSpacing (h, 10, 10);
 
37043
 
 
37044
  /* want: Document with columns for pseudo (when appropriate), location, fields */
 
37045
  /* when user clicks on field, should be able to edit contents */
 
37046
  
 
37047
  bep->bulk_ed = CreateBulkEditorDialog (h, bep->field_list, descr_list, sep, TRUE, NULL, NULL);
 
37048
 
 
37049
  /* Add Accept and Cancel buttons */
 
37050
 
 
37051
  c = HiddenGroup (h, 3, 0, NULL);
 
37052
  b = PushButton (c, "Accept", AcceptBulkEditor);
 
37053
  SetObjectExtra (b, bep, NULL);
 
37054
  PushButton (c, "Cancel", StdCancelButtonProc);
 
37055
 
 
37056
  /* Line things up nicely */
 
37057
 
 
37058
  AlignObjects (ALIGN_CENTER, (HANDLE) bep->bulk_ed,
 
37059
                              (HANDLE) c, NULL);
 
37060
 
 
37061
 
 
37062
  /* Display the window now */
 
37063
 
 
37064
  RealizeWindow (w);
 
37065
  Show (w);
 
37066
  Select (w);
 
37067
  Update ();
 
37068
}
 
37069
 
 
37070
 
 
37071
NLM_EXTERN void BulkEditorObjectList (Uint2 entityID, CharPtr title, ValNodePtr feat_list, BulkEdFieldPtr field_list)
 
37072
{
 
37073
  GrouP              c;
 
37074
  ButtoN             b;
 
37075
  BulkEditorPtr      bep;
 
37076
  GrouP              h;
 
37077
  WindoW             w;
 
37078
  SeqEntryPtr        sep;
 
37079
  Uint1              subtype = 0;
 
37080
 
 
37081
  if (feat_list == NULL) {
 
37082
    Message (MSG_ERROR, "No features found!");
 
37083
    return;
 
37084
  }
 
37085
  /* Create a new window, and a struct */
 
37086
  /* to pass around the data in.       */
 
37087
 
 
37088
  sep = GetTopSeqEntryForEntityID (entityID);
 
37089
 
 
37090
  bep = (BulkEditorPtr) MemNew (sizeof (BulkEditorData));
 
37091
  if (bep == NULL)
 
37092
    return;
 
37093
 
 
37094
  bep->field_list = field_list;
 
37095
 
 
37096
  w = FixedWindow (-50, -33, -10, -10, title,
 
37097
                   StdCloseWindowProc);
 
37098
  SetObjectExtra (w, bep, StdCleanupFormProc); 
 
37099
  bep->form = (ForM) w;
 
37100
  bep->input_entityID = entityID;
 
37101
 
 
37102
  h = HiddenGroup (w, -1, 0, NULL);
 
37103
  SetGroupSpacing (h, 10, 10);
 
37104
 
 
37105
  /* want: Document with columns for pseudo (when appropriate), location, fields */
 
37106
  /* when user clicks on field, should be able to edit contents */
 
37107
  
 
37108
  bep->bulk_ed = CreateBulkEditorDialog (h, bep->field_list, feat_list, sep, TRUE, NULL, NULL);
 
37109
 
 
37110
  /* Add Accept and Cancel buttons */
 
37111
 
 
37112
  c = HiddenGroup (h, 3, 0, NULL);
 
37113
  b = PushButton (c, "Accept", AcceptBulkEditor);
 
37114
  SetObjectExtra (b, bep, NULL);
 
37115
  PushButton (c, "Cancel", StdCancelButtonProc);
 
37116
 
 
37117
  /* Line things up nicely */
 
37118
 
 
37119
  AlignObjects (ALIGN_CENTER, (HANDLE) bep->bulk_ed,
 
37120
                              (HANDLE) c, NULL);
 
37121
 
 
37122
 
 
37123
  /* Display the window now */
 
37124
 
 
37125
  RealizeWindow (w);
 
37126
  Show (w);
 
37127
  Select (w);
 
37128
  Update ();
 
37129
}
 
37130
 
 
37131
 
 
37132
static void BulkEditor (IteM i, Uint1 featchoice, Uint1 featdef)
 
37133
{
 
37134
  BaseFormPtr        bfp;
 
37135
  SeqEntryPtr        sep;
 
37136
  CollectFeatData    cfd;
 
37137
  BulkEdFieldPtr     field_list = NULL;
 
37138
 
 
37139
#ifdef WIN_MAC
 
37140
  bfp = currentFormDataPtr;
 
37141
#else
 
37142
  bfp = GetObjectExtra (i);
 
37143
#endif
 
37144
  if (bfp == NULL) return;
 
37145
 
 
37146
  /* Create a new window, and a struct */
 
37147
  /* to pass around the data in.       */
 
37148
 
 
37149
  sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
 
37150
 
 
37151
  if (featchoice == SEQFEAT_CDREGION || featdef == FEATDEF_CDS) {
 
37152
    field_list = bulk_cds_fields;
 
37153
  } else if (featchoice == SEQFEAT_GENE || featdef == FEATDEF_GENE) {
 
37154
    field_list = bulk_gene_fields;
 
37155
  } else if (featchoice == SEQFEAT_RNA) {
 
37156
    field_list = bulk_rna_fields;
 
37157
  } else {
 
37158
    Message (MSG_ERROR, "No bulk editor for this feature type!");
 
37159
    return;
 
37160
  }
 
37161
 
 
37162
  cfd.featchoice = featchoice;
 
37163
  cfd.featdef = featdef;
 
37164
  cfd.feat_list = NULL;
 
37165
  VisitBioseqsInSep (sep, &cfd, CollectFeaturesForBulkEditor);
 
37166
 
 
37167
  if (cfd.feat_list == NULL) {
 
37168
    Message (MSG_ERROR, "No features found!");
 
37169
    return;
 
37170
  }
 
37171
 
 
37172
  BulkEditorFeatList (bfp->input_entityID, cfd.feat_list);
 
37173
}
 
37174
 
 
37175
extern void BulkEditCDS (IteM i)
 
37176
{
 
37177
  BulkEditor (i, SEQFEAT_CDREGION, FEATDEF_CDS);
 
37178
}
 
37179
 
 
37180
extern void BulkEditGene (IteM i)
 
37181
{
 
37182
  BulkEditor (i, SEQFEAT_GENE, FEATDEF_GENE);
 
37183
}
 
37184
 
 
37185
extern void BulkEditRNA (IteM i)
 
37186
{
 
37187
  BulkEditor (i, SEQFEAT_RNA, 0);
 
37188
}
 
37189
 
 
37190
 
 
37191
static Pointer GetBarcodeTestBarcodeID (Uint1 data_choice, Pointer data, Pointer metadata)
 
37192
{
 
37193
  BarcodeTestResultsPtr res = (BarcodeTestResultsPtr) data;
 
37194
  if (res == NULL || res->bsp == NULL) {
 
37195
    return NULL;
 
37196
  } else {
 
37197
    return BarcodeTestBarcodeIdString (res->bsp);
 
37198
  }
 
37199
}
 
37200
 
 
37201
  
 
37202
static Pointer GetBarcodeTestGenbankID (Uint1 data_choice, Pointer data, Pointer metadata)
 
37203
{
 
37204
  BarcodeTestResultsPtr res = (BarcodeTestResultsPtr) data;
 
37205
  if (res == NULL || res->bsp == NULL) {
 
37206
    return NULL;
 
37207
  } else {
 
37208
    return BarcodeTestGenbankIdString (res->bsp);
 
37209
  }
 
37210
}
 
37211
 
 
37212
 
 
37213
static Pointer GetBarcodeTestLengthResult (Uint1 data_choice, Pointer data, Pointer metadata)
 
37214
{
 
37215
  BarcodeTestResultsPtr res = (BarcodeTestResultsPtr) data;
 
37216
  if (res == NULL || !res->failed_tests[eBarcodeTest_Length]) {
 
37217
    return NULL;
 
37218
  } else {
 
37219
    return StringSave ("TRUE");
 
37220
  }
 
37221
}
 
37222
 
 
37223
 
 
37224
static Pointer GetBarcodeTestPrimersResult (Uint1 data_choice, Pointer data, Pointer metadata)
 
37225
{
 
37226
  BarcodeTestResultsPtr res = (BarcodeTestResultsPtr) data;
 
37227
  if (res == NULL || !res->failed_tests[eBarcodeTest_Primers]) {
 
37228
    return NULL;
 
37229
  } else {
 
37230
    return StringSave ("TRUE");
 
37231
  }
 
37232
}
 
37233
 
 
37234
 
 
37235
static Pointer GetBarcodeTestCountryResult (Uint1 data_choice, Pointer data, Pointer metadata)
 
37236
{
 
37237
  BarcodeTestResultsPtr res = (BarcodeTestResultsPtr) data;
 
37238
  if (res == NULL || !res->failed_tests[eBarcodeTest_Country]) {
 
37239
    return NULL;
 
37240
  } else {
 
37241
    return StringSave ("TRUE");
 
37242
  }
 
37243
}
 
37244
 
 
37245
 
 
37246
static Pointer GetBarcodeTestSpecimenVoucherResult (Uint1 data_choice, Pointer data, Pointer metadata)
 
37247
{
 
37248
  BarcodeTestResultsPtr res = (BarcodeTestResultsPtr) data;
 
37249
  if (res == NULL || !res->failed_tests[eBarcodeTest_SpecimenVoucher]) {
 
37250
    return NULL;
 
37251
  } else {
 
37252
    return StringSave ("TRUE");
 
37253
  }
 
37254
}
 
37255
 
 
37256
 
 
37257
static Pointer GetBarcodeTestPercentNsResult (Uint1 data_choice, Pointer data, Pointer metadata)
 
37258
{
 
37259
  BarcodeTestResultsPtr res = (BarcodeTestResultsPtr) data;
 
37260
  Char txt[5];
 
37261
  if (res == NULL || !res->failed_tests[eBarcodeTest_PercentN]) {
 
37262
    return NULL;
 
37263
  } else {
 
37264
    sprintf (txt, "%.1f", res->n_percent);
 
37265
    return StringSave (txt);
 
37266
  }
 
37267
}
 
37268
 
 
37269
 
 
37270
static Int4 BarcodeFormatBarcodeID (ColPtr col, CharPtr name)
 
37271
{
 
37272
  if (col == NULL) return 0;
 
37273
 
 
37274
  col->pixWidth = MAX (21, StringLen (name)) * MaxCharWidth();
 
37275
  col->pixInset = 0;
 
37276
  col->charWidth = 0;
 
37277
  col->charInset = 0;
 
37278
  col->font = NULL;
 
37279
  col->just = 'l';
 
37280
  col->wrap = 1;
 
37281
  col->bar = 0;
 
37282
  col->underline = 0;
 
37283
  col->left = 0;
 
37284
  return col->pixWidth;
 
37285
}
 
37286
 
 
37287
 
 
37288
static Int4 BarcodeFormatGenbankID (ColPtr col, CharPtr name)
 
37289
{
 
37290
  if (col == NULL) return 0;
 
37291
 
 
37292
  col->pixWidth = MAX (10, StringLen (name)) * MaxCharWidth();
 
37293
  col->pixInset = 0;
 
37294
  col->charWidth = 0;
 
37295
  col->charInset = 0;
 
37296
  col->font = NULL;
 
37297
  col->just = 'l';
 
37298
  col->wrap = 1;
 
37299
  col->bar = 0;
 
37300
  col->underline = 0;
 
37301
  col->left = 0;
 
37302
  return col->pixWidth;
 
37303
}
 
37304
 
 
37305
 
 
37306
static Int4 BarcodeFormatPercentN (ColPtr col, CharPtr name)
 
37307
{
 
37308
  if (col == NULL) return 0;
 
37309
 
 
37310
  col->pixWidth = MAX (5, StringLen (name)) * MaxCharWidth();
 
37311
  col->pixInset = 0;
 
37312
  col->charWidth = 0;
 
37313
  col->charInset = 0;
 
37314
  col->font = NULL;
 
37315
  col->just = 'l';
 
37316
  col->wrap = 1;
 
37317
  col->bar = 0;
 
37318
  col->underline = 0;
 
37319
  col->left = 0;
 
37320
  return col->pixWidth;
 
37321
}
 
37322
 
 
37323
 
 
37324
static BulkEdFieldData barcode_test_fields[] = {
 
37325
  { "Barcode ID", NULL, NULL, GetBarcodeTestBarcodeID, BulkDisplaySimpleText, BulkFreeSimpleText, NULL, BarcodeFormatBarcodeID, NULL, NULL, BulkSimpleTextCopy },
 
37326
  { "Genbank Accession", NULL, NULL, GetBarcodeTestGenbankID, BulkDisplaySimpleText, BulkFreeSimpleText, NULL, BarcodeFormatGenbankID, NULL, NULL, BulkSimpleTextCopy },
 
37327
  { "Length", NULL, NULL, GetBarcodeTestLengthResult, NULL, BulkFreeSimpleText, NULL, BulkFormatTrueFalse, BulkDrawTrueFalse, NULL, BulkSimpleTextCopy }, 
 
37328
  { "Primers", NULL, NULL, GetBarcodeTestPrimersResult, NULL, BulkFreeSimpleText, NULL, BulkFormatTrueFalse, BulkDrawTrueFalse, NULL, BulkSimpleTextCopy }, 
 
37329
  { "Country", NULL, NULL, GetBarcodeTestCountryResult, NULL, BulkFreeSimpleText, NULL, BulkFormatTrueFalse, BulkDrawTrueFalse, NULL, BulkSimpleTextCopy }, 
 
37330
  { "Specimen Voucher", NULL, NULL, GetBarcodeTestSpecimenVoucherResult, NULL, BulkFreeSimpleText, NULL, BulkFormatTrueFalse, BulkDrawTrueFalse, NULL, BulkSimpleTextCopy }, 
 
37331
  { "Percent Ns", NULL, NULL, GetBarcodeTestPercentNsResult, BulkDisplaySimpleText, BulkFreeSimpleText, NULL, BarcodeFormatPercentN, NULL, NULL, BulkSimpleTextCopy }, 
 
37332
  { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}};
 
37333
 
 
37334
static void NavigateToBarcodeTestResultBioseq (ValNodePtr object, Pointer userdata)
 
37335
{
 
37336
  BaseFormPtr           bfp;
 
37337
  BarcodeTestResultsPtr res;
 
37338
 
 
37339
  if (object == NULL) return;
 
37340
 
 
37341
  res = (BarcodeTestResultsPtr) object->data.ptrvalue;
 
37342
 
 
37343
  if (res == NULL || res->bsp == NULL) return;
 
37344
  bfp = GetBaseFormForEntityID (res->bsp->idx.entityID);
 
37345
  if (bfp != NULL) {
 
37346
    Select (bfp->form);
 
37347
    SetBioseqViewTargetByBioseq (bfp, res->bsp);
 
37348
  }
 
37349
}
 
37350
 
 
37351
 
 
37352
extern DialoG BarcodeTestResultsDisplay (GrouP h, BarcodeTestConfigPtr cfg)
 
37353
{
 
37354
  return CreateBulkEditorDialog (h, barcode_test_fields, NULL, NULL, FALSE, NavigateToBarcodeTestResultBioseq, NULL);
 
37355
}
 
37356
 
 
37357
extern SubSourcePtr FindBadLatLon (BioSourcePtr biop)
 
37358
{
 
37359
  SubSourcePtr ssp, ssp_bad = NULL;
 
37360
  Boolean      format_ok, lat_in_range, lon_in_range;
 
37361
 
 
37362
  if (biop == NULL)
 
37363
  {
 
37364
    return NULL;
 
37365
  }
 
37366
 
 
37367
  for (ssp = biop->subtype; ssp != NULL && ssp_bad == NULL; ssp = ssp->next)
 
37368
  {
 
37369
    if (ssp->subtype == SUBSRC_lat_lon)
 
37370
    {
 
37371
      IsCorrectLatLonFormat (ssp->name, &format_ok, &lat_in_range, &lon_in_range);
 
37372
      if (!format_ok || !lat_in_range || !lon_in_range)
 
37373
      {
 
37374
        ssp_bad = ssp;
 
37375
      }
 
37376
    }
 
37377
  }
 
37378
  return ssp_bad;
 
37379
}
 
37380
 
 
37381
 
 
37382
static Pointer GetCurrentLatLon (Uint1 data_choice, Pointer data, Pointer metadata)
 
37383
{
 
37384
  SubSourcePtr bad_ssp;
 
37385
  BioSourcePtr biop;
 
37386
 
 
37387
  biop = GetBioSourceFromObject (data_choice, data);
 
37388
  if (biop == NULL) return NULL;
 
37389
 
 
37390
  bad_ssp = FindBadLatLon (biop);
 
37391
  if (bad_ssp == NULL) 
 
37392
  {
 
37393
    return NULL;
 
37394
  }
 
37395
  else
 
37396
  {
 
37397
    return StringSave (bad_ssp->name);
 
37398
  }
 
37399
}
 
37400
 
 
37401
 
 
37402
static Pointer GetCorrectedLatLon (Uint1 data_choice, Pointer data, Pointer metadata)
 
37403
{
 
37404
  SubSourcePtr bad_ssp;
 
37405
  CharPtr      fix;
 
37406
  BioSourcePtr biop;
 
37407
 
 
37408
  biop = GetBioSourceFromObject (data_choice, data);
 
37409
  if (biop == NULL) return NULL;
 
37410
 
 
37411
  bad_ssp = FindBadLatLon (biop);
 
37412
  if (bad_ssp == NULL) 
 
37413
  {
 
37414
    return NULL;
 
37415
  }
 
37416
  else
 
37417
  {
 
37418
    fix = FixLatLonFormat (bad_ssp->name);
 
37419
    if (fix == NULL)
 
37420
    {
 
37421
      return StringSave ("Unable to autocorrect");
 
37422
    }
 
37423
    else
 
37424
    {
 
37425
      return fix;
 
37426
    }
 
37427
  }
 
37428
}
 
37429
 
 
37430
 
 
37431
static BulkEdFieldData latlon_fields[] = {
 
37432
  { "Current Lat-lon", NULL, NULL, GetCurrentLatLon, BulkDisplaySimpleText, BulkFreeSimpleText, NULL, BulkFormatSimpleText, NULL, NULL, BulkSimpleTextCopy },
 
37433
  { "Suggested Correction", NULL, NULL, GetCorrectedLatLon, BulkDisplaySimpleText, BulkFreeSimpleText, NULL, BulkFormatSimpleText, NULL, NULL, BulkSimpleTextCopy },
 
37434
  { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}};
 
37435
 
 
37436
extern DialoG LatLonTestResultsDisplay (GrouP h)
 
37437
{
 
37438
  return CreateBulkEditorDialog (h, latlon_fields, NULL, NULL, FALSE, ScrollToDiscrepancyItem, EditDiscrepancyItem);
 
37439
}
 
37440
 
 
37441
 
 
37442
static CharPtr GetSubSource (Uint1 data_choice, Pointer data, Uint1 subtype)
 
37443
{
 
37444
  SubSourcePtr ssp;
 
37445
  BioSourcePtr biop;
 
37446
 
 
37447
  biop = GetBioSourceFromObject (data_choice, data);
 
37448
  if (biop == NULL) return NULL;
 
37449
 
 
37450
  for (ssp = biop->subtype; ssp != NULL && ssp->subtype != subtype; ssp = ssp->next)
 
37451
  {}
 
37452
 
 
37453
  if (ssp == NULL) 
 
37454
  {
 
37455
    return NULL;
 
37456
  }
 
37457
  else
 
37458
  {
 
37459
    return StringSave (ssp->name);
 
37460
  }
 
37461
}
 
37462
 
 
37463
 
 
37464
static Pointer GetCountry (Uint1 data_choice, Pointer data, Pointer metadata)
 
37465
{
 
37466
  return GetSubSource (data_choice, data, SUBSRC_country);
 
37467
}
 
37468
 
 
37469
static Pointer GetLatLon (Uint1 data_choice, Pointer data, Pointer metadata)
 
37470
{
 
37471
  return GetSubSource (data_choice, data, SUBSRC_lat_lon);
 
37472
}
 
37473
 
 
37474
 
 
37475
extern Pointer GetLatLonCountryCorrection (Uint1 data_choice, Pointer data, Pointer metadata)
 
37476
{
 
37477
  SubSourcePtr ssp;
 
37478
  BioSourcePtr biop;
 
37479
  CharPtr      country = NULL, cp;
 
37480
  FloatHi      lat, lon;
 
37481
  Boolean      found_lat_lon = FALSE;
 
37482
  CharPtr      msg = NULL;
 
37483
  CharPtr      guess_fmt = "Lat_lon does not map to '%s', but may be in '%s'";
 
37484
  CharPtr      guess;
 
37485
 
 
37486
  biop = GetBioSourceFromObject (data_choice, data);
 
37487
  if (biop == NULL) return NULL;
 
37488
 
 
37489
  for (ssp = biop->subtype; ssp != NULL && (country == NULL || !found_lat_lon); ssp = ssp->next)
 
37490
  {
 
37491
    if (ssp->subtype == SUBSRC_country && !StringHasNoText (ssp->name))
 
37492
    {
 
37493
      country = StringSave (ssp->name);
 
37494
    }
 
37495
    else if (ssp->subtype == SUBSRC_lat_lon)
 
37496
    {
 
37497
      if (ParseLatLon (ssp->name, &lat, &lon))
 
37498
      {
 
37499
        found_lat_lon = TRUE;
 
37500
      }
 
37501
    }
 
37502
  }
 
37503
 
 
37504
  cp = StringChr (country, ':');
 
37505
  if (cp != NULL) 
 
37506
  {
 
37507
    *cp = 0;
 
37508
  }
 
37509
 
 
37510
  if (country == NULL && !found_lat_lon)
 
37511
  {
 
37512
    msg = StringSave ("Country and lat-lon not specified");
 
37513
  }
 
37514
  else if (country == NULL) 
 
37515
  {
 
37516
    msg = StringSave ("Country not specified");
 
37517
  }
 
37518
  else if (!found_lat_lon)
 
37519
  {
 
37520
    msg = StringSave ("Lat-lon not specified.");
 
37521
  }
 
37522
  else if (!IsCountryInLatLonList (country)) 
 
37523
  {
 
37524
    msg = StringSave ("Country not in lat-lon list");
 
37525
  }
 
37526
  else if (TestLatLonForCountry (country, lat, lon))
 
37527
  {
 
37528
    msg = StringSave ("No conflict");
 
37529
  }
 
37530
  else if (TestLatLonForCountry (country, -lat, lon)) 
 
37531
  {
 
37532
    if (lat < 0.0) {
 
37533
      msg = StringSave ("Latitude should be set to N (northern hemisphere)");
 
37534
    } else {
 
37535
      msg = StringSave ("Latitude should be set to S (southern hemisphere)");
 
37536
    }
 
37537
  } else if (TestLatLonForCountry (country, lat, -lon)) {
 
37538
    if (lon < 0.0) {
 
37539
      msg = StringSave ("Longitude should be set to E (eastern hemisphere)");
 
37540
    } else {
 
37541
      msg = StringSave ("Longitude should be set to W (western hemisphere)");
 
37542
    }
 
37543
  } else if (TestLatLonForCountry (country, lon, lat)) {
 
37544
    msg = StringSave ("Latitude and longitude values appear to be exchanged");
 
37545
  } else {
 
37546
    guess = GuessCountryForLatLon (lat, lon);
 
37547
    if (guess == NULL)
 
37548
    {
 
37549
      msg = StringSave ("Lat-lon does not map to country");
 
37550
    }
 
37551
    else
 
37552
    {
 
37553
      msg = (CharPtr) MemNew (sizeof (Char) * (StringLen (guess_fmt) + StringLen (country) + StringLen (guess)));
 
37554
      sprintf (msg, guess_fmt, country, guess);
 
37555
    }
 
37556
  }
 
37557
  return msg;
 
37558
}
 
37559
 
 
37560
static BulkEdFieldData latloncountry_fields[] = {
 
37561
  { "Lat-lon", NULL, NULL, GetLatLon, BulkDisplaySimpleText, BulkFreeSimpleText, NULL, BulkFormatSimpleText, NULL, NULL, BulkSimpleTextCopy },
 
37562
  { "Country", NULL, NULL, GetCountry, BulkDisplaySimpleText, BulkFreeSimpleText, NULL, BulkFormatSimpleText, NULL, NULL, BulkSimpleTextCopy },
 
37563
  { "Suggested Correction", NULL, NULL, GetLatLonCountryCorrection, BulkDisplaySimpleText, BulkFreeSimpleText, NULL, BulkFormatSimpleText, NULL, NULL, BulkSimpleTextCopy },
 
37564
  { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}};
 
37565
 
 
37566
extern DialoG LatLonCountryResultsDisplay (GrouP h)
 
37567
{
 
37568
  return CreateBulkEditorDialog (h, latloncountry_fields, NULL, NULL, FALSE, ScrollToDiscrepancyItem, EditDiscrepancyItem);
 
37569
}
 
37570
 
 
37571
 
 
37572
static Pointer GetCurrentSpecificHost (Uint1 data_choice, Pointer data, Pointer metadata)
 
37573
{
 
37574
  SpecificHostFixPtr s = (SpecificHostFixPtr) data;
 
37575
 
 
37576
  if (s == NULL || StringHasNoText (s->bad_specific_host))
 
37577
  {
 
37578
    return NULL;
 
37579
  } 
 
37580
  else
 
37581
  {
 
37582
    return StringSave (s->bad_specific_host);
 
37583
  }
 
37584
}
 
37585
 
 
37586
 
 
37587
static Pointer GetCorrectedSpecificHost (Uint1 data_choice, Pointer data, Pointer metadata)
 
37588
{
 
37589
  SpecificHostFixPtr s = (SpecificHostFixPtr) data;
 
37590
  CharPtr            new_spec_host;
 
37591
 
 
37592
  if (s == NULL || StringHasNoText (s->bad_specific_host) || StringHasNoText (s->old_taxname))
 
37593
  {
 
37594
    return NULL;
 
37595
  } 
 
37596
  else if (StringHasNoText (s->new_taxname))
 
37597
  {
 
37598
    return StringSave ("Unable to suggest correction");
 
37599
  }
 
37600
  else
 
37601
  {
 
37602
    new_spec_host = StringSave (s->bad_specific_host);
 
37603
    FindReplaceString (&new_spec_host, s->old_taxname, s->new_taxname, TRUE, TRUE);
 
37604
    return new_spec_host;
 
37605
  }
 
37606
}
 
37607
 
 
37608
 
 
37609
static void ScrollToSpecificHostFix (ValNodePtr vnp, Pointer userdata)
 
37610
{
 
37611
  SpecificHostFixPtr s;
 
37612
  
 
37613
  if (vnp == NULL || vnp->data.ptrvalue == NULL) return;
 
37614
 
 
37615
  s = (SpecificHostFixPtr) vnp->data.ptrvalue;
 
37616
  ScrollToDiscrepancyItem (s->feat_or_desc, NULL);
 
37617
}
 
37618
 
 
37619
 
 
37620
static void EditSpecificHostFix (ValNodePtr vnp, Pointer userdata)
 
37621
{
 
37622
  SpecificHostFixPtr s;
 
37623
  
 
37624
  if (vnp == NULL || vnp->data.ptrvalue == NULL) return;
 
37625
 
 
37626
  s = (SpecificHostFixPtr) vnp->data.ptrvalue;
 
37627
  EditDiscrepancyItem (s->feat_or_desc, NULL);
 
37628
}
 
37629
 
 
37630
 
 
37631
static BulkEdFieldData specifichost_fields[] = {
 
37632
  { "Current Specific-host", NULL, NULL, GetCurrentSpecificHost, BulkDisplaySimpleText, BulkFreeSimpleText, NULL, BulkFormatSimpleText, NULL, NULL, BulkSimpleTextCopy },
 
37633
  { "Suggested Correction", NULL, NULL, GetCorrectedSpecificHost, BulkDisplaySimpleText, BulkFreeSimpleText, NULL, BulkFormatSimpleText, NULL, NULL, BulkSimpleTextCopy },
 
37634
  { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}};
 
37635
 
 
37636
extern DialoG SpecificHostResultsDisplay (GrouP h)
 
37637
{
 
37638
  return CreateBulkEditorDialog (h, specifichost_fields, NULL, NULL, FALSE, ScrollToSpecificHostFix, EditSpecificHostFix);
 
37639
}
 
37640
 
 
37641