~ubuntu-branches/ubuntu/saucy/ncbi-tools6/saucy-proposed

« back to all changes in this revision

Viewing changes to sequin/sequin8.c

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2009-08-11 22:03:47 UTC
  • mfrom: (1.4.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: james.westby@ubuntu.com-20090811220347-g4b6lzdvphvvbpiu
* New upstream release.
* debian/libncbi6.symbols: update accordingly.
* debian/control: clean up obsolete or redundant relationship declarations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
*
30
30
* Version Creation Date:   2/3/98
31
31
*
32
 
* $Revision: 6.524 $
 
32
* $Revision: 6.540 $
33
33
*
34
34
* File Description: 
35
35
*
68
68
#include <macrodlg.h>
69
69
#include <macroapi.h>
70
70
#include <alignval.h>
 
71
#include <pubdesc.h>
71
72
 
72
73
#define DEFLINE_MAX_LEN          380
73
74
#define TEXT_MAX_LEN             64
402
403
  }
403
404
}
404
405
 
405
 
static void ExtendOnePartialFeatureEx (SeqFeatPtr sfp, Boolean extend5, Boolean extend3)
 
406
 
 
407
static void ExtendOnePartialFeatureExEx (SeqFeatPtr sfp, Boolean extend5, Boolean extend3, Boolean stop_at_gap)
406
408
{
407
409
  BioseqPtr   bsp;
408
410
  Boolean     partial3, partial5;
415
417
  CheckSeqLocForPartial (sfp->location, &partial5, &partial3);
416
418
  if (partial5 && extend5)
417
419
  {
418
 
    start_diff = ExtendSeqLocToEnd (sfp->location, bsp, TRUE);
 
420
    if (stop_at_gap) {
 
421
      start_diff = ExtendSeqLocToEndOrGap (sfp->location, bsp, TRUE);
 
422
    } else {
 
423
      start_diff = ExtendSeqLocToEnd (sfp->location, bsp, TRUE);
 
424
    }
419
425
    if (start_diff > 0 && sfp->data.choice == SEQFEAT_CDREGION) {
420
426
      crp = (CdRegionPtr) sfp->data.value.ptrvalue;
421
427
      if (crp != NULL) {
428
434
  }
429
435
  if (partial3 && extend3)
430
436
  {
431
 
    ExtendSeqLocToEnd (sfp->location, bsp, FALSE);
 
437
    if (stop_at_gap) {
 
438
      ExtendSeqLocToEndOrGap (sfp->location, bsp, FALSE);
 
439
    } else {
 
440
      ExtendSeqLocToEnd (sfp->location, bsp, FALSE);
 
441
    }
432
442
  }
433
443
}
434
444
 
 
445
 
 
446
static void ExtendOnePartialFeatureEx (SeqFeatPtr sfp, Boolean extend5, Boolean extend3)
 
447
{
 
448
  ExtendOnePartialFeatureExEx (sfp, extend5, extend3, FALSE);
 
449
}
 
450
 
 
451
 
 
452
static void ExtendOnePartialFeatureToEndOrGap (SeqFeatPtr sfp, Pointer userdata)
 
453
{
 
454
  ExtendOnePartialFeatureExEx (sfp, TRUE, TRUE, TRUE);
 
455
}
 
456
 
 
457
 
435
458
static void ExtendOnePartialFeature (SeqFeatPtr sfp, Pointer userdata)
436
459
{
437
460
  ExtendOnePartialFeatureEx (sfp, TRUE, TRUE);
490
513
  DialoG feature_type;
491
514
  ButtoN extend5;
492
515
  ButtoN extend3;
 
516
  ButtoN stop_at_gaps;
493
517
  DialoG string_constraint;
494
518
  ButtoN leave_dlg_up;
495
519
} ExtendPartialFeaturesFormData, PNTR ExtendPartialFeaturesFormPtr;
504
528
  ValNodePtr vnp;
505
529
  StringConstraintPtr scp;
506
530
  ValNodePtr object_list;
507
 
  Boolean    extend5, extend3;
 
531
  Boolean    extend5, extend3, stop_at_gaps;
508
532
 
509
533
  f = (ExtendPartialFeaturesFormPtr) GetObjectExtra (b);
510
534
  if (f == NULL) return;
537
561
 
538
562
  extend5 = GetStatus (f->extend5);
539
563
  extend3 = GetStatus (f->extend3);
 
564
  stop_at_gaps = GetStatus (f->stop_at_gaps);
540
565
  for (vnp = object_list; vnp != NULL; vnp = vnp->next) {
541
566
    if (vnp->choice == OBJ_SEQFEAT && vnp->data.ptrvalue != NULL) {
542
 
      ExtendOnePartialFeatureEx (vnp->data.ptrvalue, extend5, extend3);
 
567
      ExtendOnePartialFeatureExEx (vnp->data.ptrvalue, extend5, extend3, stop_at_gaps);
543
568
    }
544
569
  }
545
570
  object_list = ValNodeFree (object_list);
600
625
  SetStatus (f->extend5, TRUE);
601
626
  f->extend3 = CheckBox (g, "Extend partial 3'", NULL);
602
627
  SetStatus (f->extend3, TRUE);
 
628
 
 
629
  f->stop_at_gaps = CheckBox (h, "Stop at gaps", NULL);
 
630
  SetStatus (f->stop_at_gaps, TRUE);
603
631
  
604
632
  p2 = StaticPrompt (h, "Optional Constraint", 0, dialogTextHeight, programFont, 'c');
605
633
  f->string_constraint = StringConstraintDialog (h, "Where feature text", FALSE, NULL, NULL);
613
641
  AlignObjects (ALIGN_CENTER, (HANDLE) p1,
614
642
                              (HANDLE) f->feature_type,
615
643
                              (HANDLE) g,
 
644
                              (HANDLE) f->stop_at_gaps,
616
645
                              (HANDLE) p2,
617
646
                              (HANDLE) f->string_constraint,
618
647
                              (HANDLE) c,
4415
4444
  DIALOG_MESSAGE_BLOCK
4416
4445
  DialoG  traceassm;
4417
4446
  DialoG  biosample;
 
4447
  DialoG  probedb;
4418
4448
} DblinkDialog, PNTR DblinkDialogPtr;
4419
4449
 
4420
4450
typedef struct dblinkform {
4447
4477
  if (uop == NULL || uop->type == NULL || StringICmp (uop->type->str, "DBLink") != 0) {
4448
4478
    PointerToDialog (ddp->traceassm, NULL);
4449
4479
    PointerToDialog (ddp->biosample, NULL);
 
4480
    PointerToDialog (ddp->probedb, NULL);
4450
4481
    return;
4451
4482
  }
4452
4483
 
4469
4500
          if (head != NULL) {
4470
4501
            PointerToDialog (ddp->traceassm, (Pointer) head);
4471
4502
          }
4472
 
          ValNodeFreeData (head);
 
4503
          head = ValNodeFreeData (head);
4473
4504
        }
4474
4505
      }
4475
4506
    } else if (StringICmp (oip->str, "Bio Sample") == 0) {
4487
4518
          if (head != NULL) {
4488
4519
            PointerToDialog (ddp->biosample, (Pointer) head);
4489
4520
          }
4490
 
          ValNodeFreeData (head);
 
4521
          head = ValNodeFreeData (head);
 
4522
        }
 
4523
      }
 
4524
    } else if (StringICmp (oip->str, "ProbeDB") == 0) {
 
4525
      if (curr->choice == 7) {
 
4526
        num = curr->num;
 
4527
        cpp = (CharPtr PNTR) curr->data.ptrvalue;
 
4528
        if (num > 0 && cpp != NULL) {
 
4529
          head = NULL;
 
4530
          for (i = 0; i < num; i++) {
 
4531
            str = cpp [i];
 
4532
            if (StringDoesHaveText (str)) {
 
4533
              ValNodeCopyStr (&head, 0, str);
 
4534
            }
 
4535
          }
 
4536
          if (head != NULL) {
 
4537
            PointerToDialog (ddp->probedb, (Pointer) head);
 
4538
          }
 
4539
          head = ValNodeFreeData (head);
4491
4540
        }
4492
4541
      }
4493
4542
    }
4571
4620
  }
4572
4621
  ValNodeFreeData (head);
4573
4622
 
 
4623
  head = (ValNodePtr) DialogToPointer (ddp->probedb);
 
4624
  if (head != NULL) {
 
4625
    num = 0;
 
4626
    for (vnp = head; vnp != NULL; vnp = vnp->next) {
 
4627
      str = (CharPtr) vnp->data.ptrvalue;
 
4628
      if (StringHasNoText (str)) continue;
 
4629
      num++;
 
4630
    }
 
4631
    if (num > 0) {
 
4632
      cpp = (CharPtr PNTR) MemNew (sizeof (CharPtr) * num);
 
4633
      if (cpp != NULL) {
 
4634
        i = 0;
 
4635
        for (vnp = head; vnp != NULL; vnp = vnp->next) {
 
4636
          str = (CharPtr) vnp->data.ptrvalue;
 
4637
          if (StringHasNoText (str)) continue;
 
4638
          cpp [i] = str;
 
4639
          i++;
 
4640
        }
 
4641
        if (i > 0) {
 
4642
          AddProbeDBIDsToDBLinkUserObject (uop, i, cpp);
 
4643
          okay = TRUE;
 
4644
        }
 
4645
      }
 
4646
    }
 
4647
  }
 
4648
  ValNodeFreeData (head);
 
4649
 
4574
4650
  if (! okay) {
4575
4651
    uop = UserObjectFree (uop);
4576
4652
  }
4605
4681
  StaticPrompt (x, "Bio Sample", 10 * stdCharWidth, 0, programFont, 'c');
4606
4682
  ddp->biosample = CreateVisibleStringDialog (x, 3, -1, 15);
4607
4683
 
 
4684
  StaticPrompt (x, "ProbeDB", 10 * stdCharWidth, 0, programFont, 'c');
 
4685
  ddp->probedb = CreateVisibleStringDialog (x, 3, -1, 15);
 
4686
 
4608
4687
  return (DialoG) p;
4609
4688
}
4610
4689
 
4791
4870
#define REFGENE_SPLICEVAR  3
4792
4871
#define REFGENE_RELDREK    4
4793
4872
#define REFGENE_REJECT     5
4794
 
#define REFGENE_UNKNOWN    6
 
4873
#define REFGENE_IDENTICAL  6
 
4874
#define REFGENE_UNKNOWN    7
4795
4875
 
4796
4876
typedef struct refgeneuserdialog {
4797
4877
  DIALOG_MESSAGE_BLOCK
4817
4897
  {"SpliceVar",   REFGENE_SPLICEVAR},
4818
4898
  {"RelatedDrek", REFGENE_RELDREK},
4819
4899
  {"Reject",      REFGENE_REJECT},
 
4900
  {"Identical",   REFGENE_IDENTICAL},
4820
4901
  {"Unknown",     REFGENE_UNKNOWN},
4821
4902
END_ENUM_ALIST
4822
4903
 
4833
4914
};
4834
4915
 
4835
4916
static CharPtr refgene_labels [] = {
4836
 
  "", "Assembly", "Related", "SpliceVar", "RelatedDrek", "Reject", "Unknown", NULL
 
4917
  "", "Assembly", "Related", "SpliceVar", "RelatedDrek", "Reject", "IdenticalTo", "Unknown", NULL
4837
4918
};
4838
4919
 
4839
4920
static CharPtr refgene_fields [] = {
5704
5785
  return (DialoG) p;
5705
5786
}
5706
5787
 
 
5788
 
 
5789
static Boolean ExportStructuredCommentForm (ForM f, CharPtr filename)
 
5790
{
 
5791
  StruCommUserFormPtr  sfp;
 
5792
  Char            path [PATH_MAX];
 
5793
  UserObjectPtr   uop;
 
5794
  AsnIoPtr        aip;
 
5795
  Boolean         rval = FALSE;
 
5796
#ifdef WIN_MAC
 
5797
  FILE            *fp;
 
5798
#endif
 
5799
 
 
5800
  sfp = (StruCommUserFormPtr) GetObjectExtra (f);
 
5801
  if (sfp == NULL) {
 
5802
    return FALSE;
 
5803
  }
 
5804
 
 
5805
  uop = DialogToPointer (sfp->data);
 
5806
  if (uop == NULL) {
 
5807
    Message (MSG_ERROR, "Don't have a valid structured comment yet!");
 
5808
    return FALSE;
 
5809
  }
 
5810
 
 
5811
  path [0] = '\0';
 
5812
  StringNCpy_0 (path, filename, sizeof (path));
 
5813
  if (path [0] != '\0' || GetOutputFileName (path, sizeof (path), NULL)) {
 
5814
#ifdef WIN_MAC
 
5815
    fp = FileOpen (path, "r");
 
5816
    if (fp != NULL) {
 
5817
      FileClose (fp);
 
5818
    } else {
 
5819
      FileCreate (path, "TEXT", "ttxt");
 
5820
    }
 
5821
#endif
 
5822
  }
 
5823
  aip = AsnIoOpen (path, "w");
 
5824
  if (aip == NULL) {
 
5825
    Message (MSG_ERROR, "Unable to create file %s", path);
 
5826
  } else {
 
5827
    UserObjectAsnWrite (uop, aip, NULL);
 
5828
    AsnIoClose (aip);
 
5829
    rval = TRUE;
 
5830
  }
 
5831
  uop = UserObjectFree (uop);
 
5832
  return rval;
 
5833
}
 
5834
 
 
5835
 
 
5836
static Boolean ImportStructuredCommentForm  (ForM f, CharPtr filename)
 
5837
{
 
5838
  StruCommUserFormPtr  sfp;
 
5839
  Char            path [PATH_MAX];
 
5840
  UserObjectPtr   uop;
 
5841
  AsnIoPtr        aip;
 
5842
  Boolean         rval = FALSE;
 
5843
 
 
5844
  sfp = (StruCommUserFormPtr) GetObjectExtra (f);
 
5845
  if (sfp == NULL) {
 
5846
    return FALSE;
 
5847
  }
 
5848
 
 
5849
  path [0] = '\0';
 
5850
  StringNCpy_0 (path, filename, sizeof (path));
 
5851
  if (path [0] == '\0') {
 
5852
    if (!GetInputFileName (path, sizeof (path), "", "TEXT")) {
 
5853
      return FALSE;
 
5854
    }
 
5855
  }
 
5856
 
 
5857
  aip = AsnIoOpen (path, "r");
 
5858
  if (aip == NULL) {
 
5859
    Message (MSG_ERROR, "Unable to read file %s", path);
 
5860
  } else {
 
5861
    uop = UserObjectAsnRead (aip, NULL);
 
5862
    if (uop == NULL) {
 
5863
      Message (MSG_ERROR, "Unable to read structured comment ASN.1 from file");
 
5864
    } else {
 
5865
      PointerToDialog (sfp->data, uop);
 
5866
      uop = UserObjectFree (uop);
 
5867
      rval = TRUE;
 
5868
    }
 
5869
    AsnIoClose (aip);
 
5870
  }
 
5871
  return rval;
 
5872
}
 
5873
 
 
5874
 
5707
5875
static void StruCommUserFormMessage (ForM f, Int2 mssg)
5708
5876
 
5709
5877
{
5727
5895
      case VIB_MSG_DELETE :
5728
5896
        StdDeleteTextProc (NULL);
5729
5897
        break;
 
5898
      case VIB_MSG_EXPORT :
 
5899
        ExportStructuredCommentForm (f, NULL);
 
5900
        break;
 
5901
      case VIB_MSG_IMPORT :
 
5902
        ImportStructuredCommentForm (f, NULL);
 
5903
        break;
5730
5904
      default :
5731
5905
        if (sfp->appmessage != NULL) {
5732
5906
          sfp->appmessage (f, mssg);
5736
5910
  }
5737
5911
}
5738
5912
 
 
5913
 
 
5914
typedef struct replacestruccmt {
 
5915
  UserObjectPtr   deleteThis;
 
5916
  UserObjectPtr   replaceWith;
 
5917
} ReplaceStrucCmtData, PNTR ReplaceStrucCmtPtr;
 
5918
 
 
5919
 
 
5920
static void ReplaceAllStructuredCommentsCallback (SeqDescrPtr sdp, Pointer data)
 
5921
 
 
5922
{
 
5923
  ReplaceStrucCmtPtr   rp;
 
5924
 
 
5925
  if ((rp = (ReplaceStrucCmtPtr) data) == NULL || sdp == NULL || sdp->choice != Seq_descr_user) {
 
5926
    return;
 
5927
  }
 
5928
 
 
5929
  if (AsnIoMemComp (sdp->data.ptrvalue, rp->deleteThis, (AsnWriteFunc) UserObjectAsnWrite)) {
 
5930
    sdp->data.ptrvalue = UserObjectFree (sdp->data.ptrvalue);
 
5931
    sdp->data.ptrvalue = AsnIoMemCopy (rp->replaceWith, (AsnReadFunc) UserObjectAsnRead, (AsnWriteFunc) UserObjectAsnWrite);
 
5932
  }
 
5933
}
 
5934
 
 
5935
 
 
5936
static void ReplaceAllStructuredCommentsButtonProc (ButtoN b)
 
5937
{
 
5938
  StruCommUserFormPtr sfp;
 
5939
  SeqEntryPtr   sep;
 
5940
  ReplaceStrucCmtData rd; 
 
5941
  SeqDescrPtr       sdp_orig;
 
5942
  SeqMgrDescContext context;
 
5943
 
 
5944
  sfp = (StruCommUserFormPtr) GetObjectExtra (b);
 
5945
  if (sfp == NULL) {
 
5946
    return;
 
5947
  }
 
5948
 
 
5949
  rd.replaceWith = DialogToPointer (sfp->data);
 
5950
  if (rd.replaceWith == NULL) {
 
5951
    Message (MSG_ERROR, "Must supply text!");
 
5952
    rd.replaceWith = UserObjectFree (rd.replaceWith);
 
5953
    return;
 
5954
  }
 
5955
 
 
5956
  sdp_orig = SeqMgrGetDesiredDescriptor (sfp->input_entityID, NULL, sfp->input_itemID, 0, NULL, &context);
 
5957
  if (sdp_orig == NULL || sdp_orig->choice != Seq_descr_user) {
 
5958
    Message (MSG_ERROR, "Unable to find original descriptor!");
 
5959
    Remove (sfp->form);
 
5960
    rd.replaceWith = UserObjectFree (rd.replaceWith);
 
5961
    return;
 
5962
  }
 
5963
  rd.deleteThis = AsnIoMemCopy (sdp_orig->data.ptrvalue, (AsnReadFunc)UserObjectAsnRead, (AsnWriteFunc) UserObjectAsnWrite);
 
5964
 
 
5965
  sep = GetTopSeqEntryForEntityID (sfp->input_entityID);
 
5966
  VisitDescriptorsInSep (sep, &rd, ReplaceAllStructuredCommentsCallback);
 
5967
 
 
5968
  rd.deleteThis = UserObjectFree (rd.deleteThis);
 
5969
  rd.replaceWith = UserObjectFree (rd.replaceWith);
 
5970
  
 
5971
  ObjMgrSetDirtyFlag (sfp->input_entityID, TRUE);
 
5972
  ObjMgrSendMsg (OM_MSG_UPDATE, sfp->input_entityID,
 
5973
                  sfp->input_itemID, sfp->input_itemtype);
 
5974
  Remove (sfp->form);
 
5975
}
 
5976
 
 
5977
 
5739
5978
static ForM CreateStruCommDescForm (Int2 left, Int2 top, Int2 width,
5740
5979
                                     Int2 height, CharPtr title, ValNodePtr sdp,
5741
5980
                                     SeqEntryPtr sep, FormActnFunc actproc)
5756
5995
    sfp->form = (ForM) w;
5757
5996
    sfp->actproc = actproc;
5758
5997
    sfp->formmessage = StruCommUserFormMessage;
5759
 
 
 
5998
    sfp->exportform = ExportStructuredCommentForm;
 
5999
    sfp->importform = ImportStructuredCommentForm;
5760
6000
    sfp->sep = sep;
5761
6001
 
5762
6002
#ifndef WIN_MAC
5771
6011
    g = HiddenGroup (w, -1, 0, NULL);
5772
6012
    sfp->data = CreateStruCommDialog (g);
5773
6013
 
5774
 
    c = HiddenGroup (w, 2, 0, NULL);
5775
 
    b = DefaultButton (c, "Accept", StdAcceptFormButtonProc);
5776
 
    SetObjectExtra (b, sfp, NULL);
 
6014
    c = HiddenGroup (w, 3, 0, NULL);
 
6015
    if (sdp == NULL) {
 
6016
      b = DefaultButton (c, "Accept", StdAcceptFormButtonProc);
 
6017
      SetObjectExtra (b, sfp, NULL);
 
6018
    } else {
 
6019
      b = DefaultButton (c, "Replace This", StdAcceptFormButtonProc);
 
6020
      SetObjectExtra (b, sfp, NULL);
 
6021
      b = PushButton (c, "Replace All", ReplaceAllStructuredCommentsButtonProc);
 
6022
      SetObjectExtra (b, sfp, NULL);
 
6023
    }
 
6024
 
5777
6025
    PushButton (c, "Cancel", StdCancelButtonProc);
 
6026
 
5778
6027
    AlignObjects (ALIGN_CENTER, (HANDLE) g, (HANDLE) c, NULL);
5779
6028
    RealizeWindow (w);
5780
6029
  }
6628
6877
}
6629
6878
 
6630
6879
 
 
6880
static Boolean SeqAlignRowConflict (SeqAlignRowPtr r1, SeqAlignRowPtr r2)
 
6881
{
 
6882
  if (r1 == NULL || r2 == NULL) {
 
6883
    return FALSE;
 
6884
  }
 
6885
  if (r1->start <= r2->start && r1->stop >= r2->start) {
 
6886
    return TRUE;
 
6887
  } else if (r1->start <= r2->stop && r1->stop >= r2->stop) {
 
6888
    return TRUE;
 
6889
  } else if (r2->start <= r1->start && r2->start >= r2->start) {
 
6890
    return TRUE;
 
6891
  } else if (r2->start <= r1->stop && r2->stop >= r2->stop) {
 
6892
    return TRUE;
 
6893
  } else {
 
6894
    return FALSE;
 
6895
  }
 
6896
}
 
6897
 
 
6898
 
6631
6899
static Int4 SeqAlignRowLen (SeqAlignRowPtr r) 
6632
6900
{
6633
6901
  Int4 len = 0;
6655
6923
  }
6656
6924
 
6657
6925
  s = (SeqAlignSortPtr) MemNew (sizeof (SeqAlignSortData));
6658
 
  s->salp = salp;
6659
 
 
6660
 
  AlnMgr2IndexSingleChildSeqAlign(salp);
6661
 
 
6662
 
  s->row1 = SeqAlignRowNew (SeqAlignStart (salp, 0), SeqAlignStop (salp, 0), SeqAlignStrand (salp, 0));
6663
 
  s->row2 = SeqAlignRowNew (SeqAlignStart (salp, 1), SeqAlignStop (salp, 1), SeqAlignStrand (salp, 1));
 
6926
  s->salp = SeqAlignDup (salp);
 
6927
 
 
6928
  AlnMgr2IndexSingleChildSeqAlign(s->salp);
 
6929
 
 
6930
  s->row1 = SeqAlignRowNew (SeqAlignStart (s->salp, 0), SeqAlignStop (s->salp, 0), SeqAlignStrand (s->salp, 0));
 
6931
  s->row2 = SeqAlignRowNew (SeqAlignStart (s->salp, 1), SeqAlignStop (s->salp, 1), SeqAlignStrand (s->salp, 1));
6664
6932
 
6665
6933
  return s;
6666
6934
}
6671
6939
  if (s != NULL) {
6672
6940
    s->row1 = SeqAlignRowFree (s->row1);
6673
6941
    s->row2 = SeqAlignRowFree (s->row2);
 
6942
    s->salp = SeqAlignFree (s->salp);
6674
6943
    s = MemFree (s);
6675
6944
  }
6676
6945
  return s;
6677
6946
}
6678
6947
 
6679
6948
 
 
6949
static SeqAlignSortPtr SeqAlignSortCopy (SeqAlignSortPtr s)
 
6950
{
 
6951
  SeqAlignSortPtr copy = NULL;
 
6952
 
 
6953
  if (s != NULL) {
 
6954
    copy = (SeqAlignSortPtr) MemNew (sizeof (SeqAlignSortData));
 
6955
    copy->salp = SeqAlignDup (s->salp);
 
6956
    AlnMgr2IndexSingleChildSeqAlign(copy->salp);
 
6957
    copy->row1 = SeqAlignRowCopy (s->row1);
 
6958
    copy->row2 = SeqAlignRowCopy (s->row2);
 
6959
  }
 
6960
  return copy;
 
6961
}
 
6962
 
 
6963
 
6680
6964
static ValNodePtr SeqAlignSortListNew (SeqAlignPtr salp)
6681
6965
{
6682
6966
  ValNodePtr list = NULL;
6707
6991
}
6708
6992
 
6709
6993
 
 
6994
static Boolean SeqAlignSortConflict (SeqAlignSortPtr s1, SeqAlignSortPtr s2)
 
6995
{
 
6996
  if (s1 == NULL || s2 == NULL) {
 
6997
    return FALSE;
 
6998
  } else if (SeqAlignRowConflict (s1->row1, s2->row1)) {
 
6999
    return TRUE;
 
7000
  } else if (SeqAlignRowConflict (s1->row2, s2->row2)) {
 
7001
    return TRUE;
 
7002
  } else {
 
7003
    return FALSE;
 
7004
  }
 
7005
}
 
7006
 
 
7007
 
 
7008
static Int4 SeqAlignSortListLongestInterval (ValNodePtr list)
 
7009
{
 
7010
  Int4 len, max = 0;
 
7011
  ValNodePtr vnp;
 
7012
  SeqAlignSortPtr s;
 
7013
 
 
7014
  for (vnp = list; vnp != NULL; vnp = vnp->next) {
 
7015
    s = vnp->data.ptrvalue;
 
7016
    if (s != NULL && s->row1 != NULL) {
 
7017
      len = SeqAlignRowLen (s->row1);
 
7018
      if (len > max) {
 
7019
        max = len;
 
7020
      }
 
7021
    }
 
7022
  }
 
7023
  return max;
 
7024
}
 
7025
 
 
7026
 
6710
7027
static SeqAlignRowPtr SeqAlignRowFromSeqAlignSort (SeqAlignSortPtr s, Int4 row)
6711
7028
{
6712
7029
  if (s == NULL) {
6734
7051
 
6735
7052
static Uint1 SeqAlignSortListFindBestStrand (ValNodePtr vnp, Int4 row)
6736
7053
{
6737
 
  Int4 num_plus = 0, num_minus = 0;
 
7054
  Int4 num_plus = 0, num_minus = 0, num_align, num = 0;
6738
7055
  SeqAlignSortPtr s;
6739
7056
 
6740
 
  while (vnp != NULL) {
 
7057
  /* count the alignments */
 
7058
  num_align = ValNodeLen (vnp);
 
7059
 
 
7060
  /* only look at strands from the first half of the alignments */
 
7061
  num_align = num_align / 2;
 
7062
 
 
7063
  while (vnp != NULL && num < num_align) {
6741
7064
    s = (SeqAlignSortPtr) vnp->data.ptrvalue;
6742
7065
    if (s != NULL) {
6743
7066
      if (SeqAlignSortRowStrand(s, row) == Seq_strand_minus) {
6747
7070
      }
6748
7071
    }
6749
7072
    vnp = vnp->next;
 
7073
    num++;
6750
7074
  }
6751
7075
 
6752
7076
  if (num_minus > num_plus) {
6768
7092
}
6769
7093
 
6770
7094
 
6771
 
static ValNodePtr SeqAlignSortListRemoveAll (ValNodePtr list)
6772
 
{
6773
 
  ValNodePtr vnp;
6774
 
  SeqAlignSortPtr s;
6775
 
 
6776
 
  for (vnp = list; vnp != NULL; vnp = vnp->next) {
6777
 
    s = vnp->data.ptrvalue;
6778
 
    if (s != NULL && s->salp != NULL) {
6779
 
      s->salp->next = NULL;
6780
 
      s->salp = SeqAlignFree (s->salp);
6781
 
    }
6782
 
  }
6783
 
 
6784
 
  list = SeqAlignSortListFree (list);
6785
 
  return list;
6786
 
}
6787
 
 
6788
 
 
6789
7095
static void SeqAlignSortListRemoveMarked (ValNodePtr PNTR list)
6790
7096
{
6791
7097
  ValNodePtr remove_list;
6795
7101
  }
6796
7102
 
6797
7103
  remove_list = ValNodeExtractList (list, 1);
6798
 
  remove_list = SeqAlignSortListRemoveAll (remove_list);
 
7104
  remove_list = SeqAlignSortListFree (remove_list);
6799
7105
}
6800
7106
 
6801
7107
 
6835
7141
      }
6836
7142
      salp_prev = s->salp;
6837
7143
      s->salp->next = NULL;
 
7144
      /* NULL out entry in SeqAlignSort so that it will not be freed later */
 
7145
      s->salp = NULL;
6838
7146
    }
6839
7147
    vnp = vnp->next;
6840
7148
  }
6936
7244
}
6937
7245
 
6938
7246
 
6939
 
static ValNodePtr SeqAlignSortListExtractRepeats (ValNodePtr PNTR list, Int4 row, Int4 fuzz)
 
7247
static ValNodePtr SeqAlignSortListMarkRepeats (ValNodePtr PNTR list, Int4 row, Int4 fuzz)
6940
7248
{
6941
 
  ValNodePtr repeat_start, repeat_prev = NULL, vnp_prev = NULL, vnp;
6942
 
  ValNodePtr repeat_list = NULL;
 
7249
  ValNodePtr repeat_start, vnp, vnp_mark;
 
7250
  ValNodePtr repeat_list = NULL, tmp_list;
6943
7251
  SeqAlignSortPtr s1, s2;
6944
7252
  SeqAlignRowPtr  interval, r2;
6945
7253
  Int4            diff;
6958
7266
  repeat_start = *list;
6959
7267
  s1 = repeat_start->data.ptrvalue;
6960
7268
  interval = SeqAlignRowCopy (SeqAlignRowFromSeqAlignSort(s1, row));
6961
 
  vnp_prev = *list;
6962
7269
  for (vnp = (*list)->next; vnp != NULL; vnp = vnp->next) {
6963
7270
    s2 = vnp->data.ptrvalue;
6964
7271
    is_repeat = FALSE;
6974
7281
      is_repeat = TRUE;
6975
7282
    }
6976
7283
    if (is_repeat) {
6977
 
      vnp_prev = vnp;
6978
7284
      if (interval->start > r2->start) {
6979
7285
        interval->start = r2->start;
6980
7286
      }
6982
7288
        interval->stop = r2->stop;
6983
7289
      }
6984
7290
    } else {
6985
 
      if (repeat_start->next == vnp) {
6986
 
        repeat_prev = vnp_prev;
6987
 
        vnp_prev = vnp;
6988
 
      } else {
6989
 
        if (repeat_prev == NULL) {
6990
 
          *list = vnp;
6991
 
        } else {
6992
 
          repeat_prev->next = vnp;
6993
 
        }
6994
 
        if (vnp_prev != NULL) {
6995
 
          vnp_prev->next = NULL;
6996
 
        }
6997
 
        ValNodeAddPointer (&repeat_list, 0, repeat_start);
6998
 
        vnp_prev = vnp;
 
7291
      if (repeat_start->next != vnp) {
 
7292
        tmp_list = NULL;
 
7293
        for (vnp_mark = repeat_start; vnp_mark != vnp; vnp_mark = vnp_mark->next) {
 
7294
          /* add copy to list of repeats */
 
7295
          ValNodeAddPointer (&tmp_list, 0, SeqAlignSortCopy (vnp_mark->data.ptrvalue));
 
7296
          /* mark as repeat for this row */
 
7297
          vnp_mark->choice = row;
 
7298
        }
 
7299
        ValNodeAddPointer (&repeat_list, 0, tmp_list);
6999
7300
      }
7000
7301
      repeat_start = vnp;
7001
7302
      s1 = vnp->data.ptrvalue;
7005
7306
  }
7006
7307
 
7007
7308
  if (repeat_start->next != NULL) {
7008
 
    if (repeat_prev == NULL) {
7009
 
      *list = NULL;
7010
 
    } else {
7011
 
      repeat_prev->next = NULL;
 
7309
    tmp_list = NULL;
 
7310
    for (vnp_mark = repeat_start; vnp_mark != vnp; vnp_mark = vnp_mark->next) {
 
7311
      /* add copy to list of repeats */
 
7312
      ValNodeAddPointer (&tmp_list, 0, SeqAlignSortCopy (vnp_mark->data.ptrvalue));
 
7313
      /* mark as repeat for this row */
 
7314
      vnp_mark->choice = row;
7012
7315
    }
7013
 
    ValNodeAddPointer (&repeat_list, 0, repeat_start);
 
7316
    ValNodeAddPointer (&repeat_list, 0, tmp_list);
7014
7317
  }
7015
7318
 
7016
7319
  interval = SeqAlignRowFree (interval);
7296
7599
    /* keep longest, mark others for removal */
7297
7600
    vnp = ExtractLongestSeqAlignRow (&repeat_list, row);
7298
7601
    ValNodeLink (sorted_list,vnp);
7299
 
    repeat_list = SeqAlignSortListRemoveAll (repeat_list);
 
7602
    repeat_list = SeqAlignSortListFree (repeat_list);
7300
7603
  } else {
7301
7604
    s_repeat = repeat_list->data.ptrvalue;
7302
7605
    found = FALSE;
7304
7607
 
7305
7608
    /* find first entry that is after this repeat, and insert before that */
7306
7609
    while (vnp != NULL && !found) {
 
7610
      if (SeqAlignSortConflict (s_repeat, vnp->data.ptrvalue)) {
 
7611
        found = TRUE;
 
7612
        break;
 
7613
      }
 
7614
 
7307
7615
      s = vnp->data.ptrvalue;
7308
7616
      r1 = SeqAlignRowFromSeqAlignSort (s, row);
7309
7617
      r2 = SeqAlignRowFromSeqAlignSort (s_repeat, row);
7310
7618
 
 
7619
      if (r1->start == r2->start && r1->stop == r2->stop) {
 
7620
        /* this is a duplicate.  throw it away. */
 
7621
        found = TRUE;
 
7622
        break;
 
7623
      }
 
7624
 
7311
7625
      if (r1->start > r2->start || r2->start - r1->start < fuzz) {
7312
7626
        while (repeat_list != NULL) {
7313
7627
          /* extract best repeat */
7314
7628
          vnp_new = FindBestRepeat (&repeat_list, s_before, vnp->data.ptrvalue, other_row, fuzz);
7315
7629
          if (vnp_new == NULL) {
7316
 
            repeat_list = SeqAlignSortListRemoveAll (repeat_list);
 
7630
            repeat_list = SeqAlignSortListFree (repeat_list);
7317
7631
          } else {
7318
7632
            RemoveRepeatsCoincidingWithBest (&repeat_list, vnp_new, row, fuzz);
7319
7633
            vnp_new->next = vnp;
7339
7653
        /* extract best repeat */
7340
7654
        vnp_new = FindBestRepeat (&repeat_list, s_before, NULL, other_row, fuzz);
7341
7655
        if (vnp_new == NULL) {
7342
 
          repeat_list = SeqAlignSortListRemoveAll (repeat_list);
 
7656
          repeat_list = SeqAlignSortListFree (repeat_list);
7343
7657
        } else {
7344
7658
          RemoveRepeatsCoincidingWithBest (&repeat_list, vnp_new, row, fuzz);
7345
7659
          vnp_new->next = NULL;
7360
7674
}
7361
7675
 
7362
7676
 
 
7677
static Int4 FindLongestRepeatInterval (ValNodePtr repeat_list)
 
7678
{
 
7679
  Int4 len, max = 0;
 
7680
  ValNodePtr vnp_r, vnp;
 
7681
  SeqAlignSortPtr s;
 
7682
 
 
7683
  for (vnp_r = repeat_list; vnp_r != NULL; vnp_r = vnp_r->next) {
 
7684
    for (vnp = vnp_r->data.ptrvalue; vnp != NULL; vnp = vnp->next) {
 
7685
      s = vnp->data.ptrvalue;
 
7686
      if (s != NULL && s->row1 != NULL) {
 
7687
        len = SeqAlignRowLen (s->row1);
 
7688
        if (len > max) {
 
7689
          max = len;
 
7690
        }
 
7691
      }
 
7692
    }
 
7693
  }
 
7694
  return max;
 
7695
}
 
7696
 
 
7697
 
 
7698
/* note - we want to sort from highest to lowest */
 
7699
static int LIBCALLBACK SortVnpByRepeatList (VoidPtr ptr1, VoidPtr ptr2)
 
7700
 
 
7701
{
 
7702
  ValNodePtr  vnp1;
 
7703
  ValNodePtr  vnp2;
 
7704
  Int4        len1, len2;
 
7705
  int         rval = 0;
 
7706
 
 
7707
  if (ptr1 != NULL && ptr2 != NULL) {
 
7708
    vnp1 = *((ValNodePtr PNTR) ptr1);
 
7709
    vnp2 = *((ValNodePtr PNTR) ptr2);
 
7710
    if (vnp1 != NULL && vnp2 != NULL) {
 
7711
      len1 = SeqAlignSortListLongestInterval (vnp1->data.ptrvalue);
 
7712
      len2 = SeqAlignSortListLongestInterval (vnp2->data.ptrvalue);
 
7713
      if (len1 < len2) {
 
7714
        rval = 1;
 
7715
      } else if (len2 < len1) {
 
7716
        rval = -1;
 
7717
      }
 
7718
    }
 
7719
  }
 
7720
  return rval;
 
7721
}
 
7722
 
 
7723
 
 
7724
 
 
7725
 
7363
7726
static void SelectBestRepeatsFromList (SeqAlignPtr PNTR salp)
7364
7727
{
7365
7728
  ValNodePtr list, vnp;
7367
7730
  Uint1 strand1, strand2;
7368
7731
  SeqAlignPtr    tmp_salp;
7369
7732
  Int4           fuzz = 15;
7370
 
 
7371
7733
  Int4           missing = 600;
 
7734
  Int4           len1, len2;
7372
7735
 
7373
7736
  if (salp == NULL || *salp == NULL || (*salp)->next == NULL) {
7374
7737
    return;
7387
7750
  FindSeqAlignSortWithPoint (list, missing, 1);
7388
7751
 
7389
7752
  if (list != NULL && list->next != NULL) {
7390
 
    row1_repeats = SeqAlignSortListExtractRepeats (&list, 1, fuzz);
7391
 
    row2_repeats = SeqAlignSortListExtractRepeats (&list, 2, fuzz);
 
7753
    row1_repeats = SeqAlignSortListMarkRepeats (&list, 1, fuzz);
 
7754
    row1_repeats = ValNodeSort (row1_repeats, SortVnpByRepeatList);
 
7755
    row2_repeats = SeqAlignSortListMarkRepeats (&list, 2, fuzz);
 
7756
    row2_repeats = ValNodeSort (row2_repeats, SortVnpByRepeatList);
 
7757
    vnp = ValNodeExtractList (&list, 1);
 
7758
    vnp = SeqAlignSortListFree (vnp);
 
7759
    vnp = ValNodeExtractList (&list, 2);
 
7760
    vnp = SeqAlignSortListFree (vnp);
7392
7761
 
7393
7762
    FindSeqAlignSortWithPoint (list, missing, 1);
7394
7763
 
7409
7778
 
7410
7779
    FindSeqAlignSortWithPoint (list, missing, 1);
7411
7780
 
7412
 
    /* for each repeat on row 1, we want to pick the most consistent interval for row 2 */
7413
 
    list = ValNodeSort (list, SortVnpBySeqAlignSortRow1);
7414
 
    for (vnp = row1_repeats; vnp != NULL; vnp = vnp->next) {   
7415
 
      InsertBestRepeat (vnp->data.ptrvalue, &list, 1, fuzz);
7416
 
    }
7417
 
    row1_repeats = ValNodeFree (row1_repeats);
7418
 
 
7419
 
    /* for each repeat on row 2, we want to pick the most consistent interval for row 1 */
7420
 
    list = ValNodeSort (list, SortVnpBySeqAlignSortRow2);
7421
 
    for (vnp = row2_repeats; vnp != NULL; vnp = vnp->next) {   
7422
 
      InsertBestRepeat (vnp->data.ptrvalue, &list, 2, fuzz);
7423
 
    }
7424
 
    row2_repeats = ValNodeFree (row2_repeats);
 
7781
    len1 = FindLongestRepeatInterval (row1_repeats);
 
7782
    len2 = FindLongestRepeatInterval (row2_repeats);
 
7783
 
 
7784
    if (len1 >= len2) {
 
7785
      /* for each repeat on row 1, we want to pick the most consistent interval for row 2 */
 
7786
      list = ValNodeSort (list, SortVnpBySeqAlignSortRow1);
 
7787
      for (vnp = row1_repeats; vnp != NULL; vnp = vnp->next) {   
 
7788
        InsertBestRepeat (vnp->data.ptrvalue, &list, 1, fuzz);
 
7789
      }
 
7790
      row1_repeats = ValNodeFree (row1_repeats);
 
7791
 
 
7792
      /* for each repeat on row 2, we want to pick the most consistent interval for row 1 */
 
7793
      list = ValNodeSort (list, SortVnpBySeqAlignSortRow2);
 
7794
      for (vnp = row2_repeats; vnp != NULL; vnp = vnp->next) {   
 
7795
        InsertBestRepeat (vnp->data.ptrvalue, &list, 2, fuzz);
 
7796
      }
 
7797
      row2_repeats = ValNodeFree (row2_repeats);
 
7798
    } else {
 
7799
      /* for each repeat on row 2, we want to pick the most consistent interval for row 1 */
 
7800
      list = ValNodeSort (list, SortVnpBySeqAlignSortRow2);
 
7801
      for (vnp = row2_repeats; vnp != NULL; vnp = vnp->next) {   
 
7802
        InsertBestRepeat (vnp->data.ptrvalue, &list, 2, fuzz);
 
7803
      }
 
7804
      row2_repeats = ValNodeFree (row2_repeats);
 
7805
 
 
7806
      /* for each repeat on row 1, we want to pick the most consistent interval for row 2 */
 
7807
      list = ValNodeSort (list, SortVnpBySeqAlignSortRow1);
 
7808
      for (vnp = row1_repeats; vnp != NULL; vnp = vnp->next) {   
 
7809
        InsertBestRepeat (vnp->data.ptrvalue, &list, 1, fuzz);
 
7810
      }
 
7811
      row1_repeats = ValNodeFree (row1_repeats);
 
7812
    }
7425
7813
  }
7426
7814
 
7427
7815
  list = ValNodeSort (list, SortVnpBySeqAlignSortRow1);
10311
10699
      case SEQID_EMBL :
10312
10700
      case SEQID_DDBJ :
10313
10701
      case SEQID_OTHER :
 
10702
      case SEQID_TPG :
 
10703
      case SEQID_TPE :
 
10704
      case SEQID_TPD :
 
10705
 
10314
10706
        tsip = (TextSeqIdPtr) sip->data.ptrvalue;
10315
10707
        if (tsip != NULL && (! StringHasNoText (tsip->accession))) {
10316
10708
          StringNCpy_0 (buf, tsip->accession, sizeof (buf));
10317
10709
        }
10318
10710
        break;
 
10711
 
10319
10712
      case SEQID_GI :
10320
10713
        /*
10321
10714
        gi = sip->data.intvalue;
11864
12257
  ValNodePtr         err_list, coverage_report, vnp, ids_list, match_errs;
11865
12258
  SeqAlignPtr        salp, salp_next;
11866
12259
  LogInfoPtr         lip;
 
12260
  SeqEntryPtr        sep;
11867
12261
 
11868
12262
  frm = (TSAAssemblyFormPtr) GetObjectExtra (b);
11869
12263
  if (frm == NULL) {
11904
12298
    ValNodeLink (&coverage_report, err_list);
11905
12299
    err_list = coverage_report;
11906
12300
 
 
12301
    lip = OpenLog ("TSA Table Problems");
11907
12302
    if (err_list != NULL) {
11908
 
      lip = OpenLog ("TSA Table Problems");
11909
12303
      for (vnp = err_list; vnp != NULL; vnp = vnp->next) {
11910
12304
        fprintf (lip->fp, "%s\n", vnp->data.ptrvalue);
11911
12305
      }
11912
12306
      lip->data_in_log = TRUE;
11913
 
      CloseLog (lip);
11914
 
      lip = FreeLog (lip);
11915
12307
      err_list = ValNodeFreeData (err_list);
11916
12308
    }
 
12309
    sep = GetTopSeqEntryForEntityID (frm->input_entityID);
 
12310
    VisitBioseqsInSep (sep, lip, ReportNonTSABioseqs);
 
12311
    CloseLog (lip);
 
12312
    lip = FreeLog (lip);
11917
12313
  }
11918
12314
 
11919
12315
  ObjMgrSetDirtyFlag (frm->input_entityID, TRUE);
13927
14323
 
13928
14324
 
13929
14325
/* data structure and functions for a generic form displaying a clickable list */
 
14326
typedef  void  (*Nlm_AddClickableListEntityIDProc) PROTO ((ButtoN, Uint2));
13930
14327
 
13931
14328
#define CLICKABLE_LIST_FORM_BLOCK   \
13932
14329
  FORM_MESSAGE_BLOCK                \
13933
14330
  ValNodePtr      clickable_list_data; \
13934
14331
  DialoG          clickable_list_dlg;  \
13935
14332
  ButtoN          recheck_btn;         \
 
14333
  CharPtr         log_name;            \
 
14334
  Nlm_AddClickableListEntityIDProc add_entity_proc;        \
13936
14335
  
13937
14336
typedef struct clickablelistform {
13938
14337
  CLICKABLE_LIST_FORM_BLOCK
13987
14386
          clfp->clickable_list_data = FreeClickableList (clfp->clickable_list_data);
13988
14387
          PointerToDialog (clfp->clickable_list_dlg, NULL);
13989
14388
          break;
 
14389
      case OM_MSG_CREATE:
 
14390
          /* when a new item is created, refresh */
 
14391
          if (clfp->add_entity_proc != NULL && clfp->recheck_btn != NULL) {
 
14392
              (clfp->add_entity_proc)(clfp->recheck_btn, ommsp->entityID);
 
14393
          }
 
14394
          break;
13990
14395
      default:
13991
14396
          break;
13992
14397
  }
14117
14522
    drfp->dcp = DiscrepancyConfigFree (drfp->dcp);
14118
14523
    ObjMgrFreeUserData (drfp->input_entityID, drfp->procid, drfp->proctype, drfp->userkey);
14119
14524
    ClearWindowForReportType ((WindoW) drfp->form);
 
14525
    drfp->log_name = MemFree (drfp->log_name);
14120
14526
  }
14121
14527
  StdCleanupFormProc (g, data);
14122
14528
}
14288
14694
  BioseqPtr  bsp;
14289
14695
  SeqDescrPtr sdp;
14290
14696
  ObjValNodePtr ovp;
14291
 
  
 
14697
  OMUserDataPtr omudp;
 
14698
  BaseFormPtr   bfp;
 
14699
  SeqSubmitPtr  ssp;
 
14700
  Uint2         procid;
 
14701
  Boolean       special_flag = FALSE;
 
14702
  Uint1         data_choice;
 
14703
  WindoW        w;
 
14704
 
14292
14705
  if (vnp == NULL)
14293
14706
  {
14294
14707
    return;
14295
14708
  }
14296
 
  if (vnp->choice == OBJ_SEQFEAT)
 
14709
 
 
14710
  data_choice = vnp->choice;
 
14711
  if (data_choice > OBJ_MAX) {
 
14712
    special_flag = TRUE;
 
14713
    data_choice -= OBJ_MAX;
 
14714
  }
 
14715
 
 
14716
  if (data_choice == OBJ_SEQFEAT)
14297
14717
  {
14298
14718
    sfp = (SeqFeatPtr) vnp->data.ptrvalue;
14299
14719
    if (sfp != NULL)
14307
14727
          }
14308
14728
        }
14309
14729
      }
14310
 
      GatherProcLaunch (OMPROC_EDIT, FALSE, sfp->idx.entityID, sfp->idx.itemID,
14311
 
                        OBJ_SEQFEAT, 0, 0, OBJ_SEQFEAT, 0);
 
14730
      if (special_flag && sfp->data.choice == SEQFEAT_PUB) {
 
14731
        w = EditCitFeatDirectly (sfp);
 
14732
        Show (w);
 
14733
      } else {
 
14734
        GatherProcLaunch (OMPROC_EDIT, FALSE, sfp->idx.entityID, sfp->idx.itemID,
 
14735
                          OBJ_SEQFEAT, 0, 0, OBJ_SEQFEAT, 0);
 
14736
      }
14312
14737
    }
14313
14738
  }
14314
 
  else if (vnp->choice == OBJ_BIOSEQ)
 
14739
  else if (data_choice == OBJ_BIOSEQ)
14315
14740
  {
14316
14741
    bsp = (BioseqPtr) vnp->data.ptrvalue;
14317
14742
    if (bsp != NULL)
14320
14745
                         OBJ_BIOSEQ, 0, 0, OBJ_BIOSEQ, 0);
14321
14746
    }
14322
14747
  }
14323
 
  else if (vnp->choice == OBJ_SEQDESC)
 
14748
  else if (data_choice == OBJ_SEQDESC)
14324
14749
  {
14325
14750
    sdp = (SeqDescrPtr) (vnp->data.ptrvalue);
14326
14751
    if (sdp != NULL && sdp->extended != 0)
14327
14752
    {
14328
14753
      ovp = (ObjValNodePtr) sdp;
14329
 
      GatherProcLaunch (OMPROC_EDIT, FALSE, ovp->idx.entityID, ovp->idx.itemID,
14330
 
                         OBJ_SEQDESC, 0, 0, OBJ_SEQDESC, 0);
 
14754
      if (special_flag && sdp->choice == Seq_descr_pub) {
 
14755
        w = EditCitDescDirectly (sdp);
 
14756
        Show (w);
 
14757
      } else {
 
14758
        GatherProcLaunch (OMPROC_EDIT, FALSE, ovp->idx.entityID, ovp->idx.itemID,
 
14759
                          OBJ_SEQDESC, 0, 0, OBJ_SEQDESC, 0);
 
14760
      }
 
14761
    }
 
14762
  }
 
14763
  else if (data_choice == OBJ_SEQSUB)
 
14764
  {
 
14765
    ssp = (SeqSubmitPtr) (vnp->data.ptrvalue);
 
14766
    procid = GetProcIdForItemEditor (ssp->idx.entityID, ssp->idx.itemID, OBJ_SEQSUB_CIT, 0);
 
14767
    omudp = ItemAlreadyHasEditor (ssp->idx.entityID, ssp->idx.itemID,
 
14768
                                    OBJ_SUBMIT_BLOCK, procid);
 
14769
    if (omudp == NULL) {
 
14770
      GatherProcLaunch (OMPROC_EDIT, FALSE, ssp->idx.entityID, ssp->idx.itemID,
 
14771
                        OBJ_SEQSUB_CIT, 0, 0, OBJ_SEQSUB_CIT, 0);
 
14772
      omudp = ItemAlreadyHasEditor (ssp->idx.entityID, ssp->idx.itemID,
 
14773
                                      OBJ_SUBMIT_BLOCK, procid);
 
14774
    }
 
14775
    if (omudp != NULL) {
 
14776
      bfp = (BaseFormPtr) omudp->userdata.ptrvalue;
 
14777
      if (bfp != NULL) {
 
14778
        Select (bfp->form);
 
14779
        SendMessageToForm (bfp->form, NUM_VIB_MSG + 1);
 
14780
      }
14331
14781
    }
14332
14782
  }
14333
14783
 
14416
14866
 
14417
14867
static void ExtendPartialsToEndOrGapCallback (ValNodePtr list, Pointer userdata)
14418
14868
{
14419
 
  ValNodePtr vnp, entityID_list = NULL;
14420
 
  SeqFeatPtr sfp;
 
14869
  ValNodePtr vnp, sep_list = NULL;
14421
14870
  LogInfoPtr lip;
14422
 
  CharPtr    orig_location, new_location;
 
14871
  Uint2      entityID;
14423
14872
 
14424
14873
  if (Message (MSG_OKC, "Extend partial ends of features to gaps/end of sequence if within two nucleotides?") == ANS_CANCEL) {
14425
14874
    return;
14427
14876
  WatchCursor();
14428
14877
  Update();
14429
14878
  lip = OpenLog ("Extended Features");
14430
 
  for (vnp = list; vnp != NULL; vnp = vnp->next) {
14431
 
    if (vnp->choice == OBJ_SEQFEAT && (sfp = vnp->data.ptrvalue) != NULL) {
14432
 
      orig_location = SeqLocPrintUseBestID (sfp->location);
14433
 
      if (ExtendPartialsToEndOrGap (sfp)) {
14434
 
        ValNodeAddInt (&entityID_list, 0, sfp->idx.entityID);
14435
 
        new_location = SeqLocPrintUseBestID (sfp->location);
14436
 
        fprintf (lip->fp, "Extended %s to %s\n", orig_location, new_location);
14437
 
        new_location = MemFree (new_location);
14438
 
        lip->data_in_log = TRUE;
14439
 
      }
14440
 
      orig_location = MemFree (orig_location);
14441
 
    }
14442
 
  }
14443
 
  entityID_list = ValNodeSort (entityID_list, SortByIntvalue);
14444
 
  ValNodeUnique (&entityID_list, SortByIntvalue, ValNodeFree);
14445
 
  for (vnp = entityID_list; vnp != NULL; vnp = vnp->next) {
14446
 
    ObjMgrSetDirtyFlag (vnp->data.intvalue, TRUE);
14447
 
    ObjMgrSendMsg (OM_MSG_UPDATE, vnp->data.intvalue, 0, 0);
14448
 
  }
 
14879
 
 
14880
  FixBacterialExtendablePartials (list, userdata, lip);
 
14881
 
 
14882
  sep_list = GetViewedSeqEntryList ();
 
14883
  for (vnp = sep_list; vnp != NULL; vnp = vnp->next) {
 
14884
    entityID = ObjMgrGetEntityIDForChoice (vnp->data.ptrvalue);
 
14885
    ObjMgrSetDirtyFlag (entityID, TRUE);
 
14886
    ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
 
14887
  }
 
14888
  sep_list = ValNodeFree (sep_list);
 
14889
 
 
14890
  ArrowCursor();
 
14891
  Update();
 
14892
  CloseLog (lip);
 
14893
  lip = FreeLog (lip);
 
14894
}
 
14895
 
 
14896
 
 
14897
static void AddNonExtendableExceptionsCallback (ValNodePtr list, Pointer userdata)
 
14898
{
 
14899
  ValNodePtr vnp, sep_list = NULL;
 
14900
  LogInfoPtr lip;
 
14901
  Uint2      entityID;
 
14902
 
 
14903
  if (Message (MSG_OKC, "Add Non-extendable exception to non-extendable partial features?") == ANS_CANCEL) {
 
14904
    return;
 
14905
  }
 
14906
  WatchCursor();
 
14907
  Update();
 
14908
  lip = OpenLog ("Added Exceptions to Features");
 
14909
  FixBacterialNonExtendablePartials (list, userdata, lip);
 
14910
 
 
14911
  sep_list = GetViewedSeqEntryList ();
 
14912
  for (vnp = sep_list; vnp != NULL; vnp = vnp->next) {
 
14913
    entityID = ObjMgrGetEntityIDForChoice (vnp->data.ptrvalue);
 
14914
    ObjMgrSetDirtyFlag (entityID, TRUE);
 
14915
    ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
 
14916
  }
 
14917
  sep_list = ValNodeFree (sep_list);
 
14918
 
 
14919
  ArrowCursor();
 
14920
  Update();
 
14921
  CloseLog (lip);
 
14922
  lip = FreeLog (lip);
 
14923
}
 
14924
 
 
14925
 
 
14926
static void MarkOverlappingCDSCallback (ValNodePtr list, Pointer userdata)
 
14927
{
 
14928
  ValNodePtr vnp, sep_list = NULL;
 
14929
  LogInfoPtr lip;
 
14930
  Uint2      entityID;
 
14931
 
 
14932
  if (Message (MSG_OKC, "Add comment to overlapping coding regions?") == ANS_CANCEL) {
 
14933
    return;
 
14934
  }
 
14935
  WatchCursor();
 
14936
  Update();
 
14937
  lip = OpenLog ("Added Comments to Overlapping Coding Regions");
 
14938
  MarkOverlappingCDSs (list, userdata, lip);
 
14939
 
 
14940
  sep_list = GetViewedSeqEntryList ();
 
14941
  for (vnp = sep_list; vnp != NULL; vnp = vnp->next) {
 
14942
    entityID = ObjMgrGetEntityIDForChoice (vnp->data.ptrvalue);
 
14943
    ObjMgrSetDirtyFlag (entityID, TRUE);
 
14944
    ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
 
14945
  }
 
14946
  sep_list = ValNodeFree (sep_list);
 
14947
 
14449
14948
  ArrowCursor();
14450
14949
  Update();
14451
14950
  CloseLog (lip);
14538
15037
  SeqDescrPtr   sdp;
14539
15038
  ObjValNodePtr ovp;
14540
15039
  BaseFormPtr   bfp;
 
15040
  Boolean       special_flag = FALSE;
 
15041
  Uint1         data_choice;
14541
15042
    
14542
15043
  if (vnp == NULL)
14543
15044
  {
14544
15045
    return;
14545
15046
  }
14546
 
  if (vnp->choice == OBJ_SEQFEAT)
 
15047
 
 
15048
  data_choice = vnp->choice;
 
15049
  if (data_choice > OBJ_MAX) {
 
15050
    special_flag = TRUE;
 
15051
    data_choice -= OBJ_MAX;
 
15052
  }
 
15053
 
 
15054
  if (data_choice == OBJ_SEQFEAT)
14547
15055
  {
14548
15056
    sfp = (SeqFeatPtr) vnp->data.ptrvalue;
14549
15057
    if (sfp != NULL)
14568
15076
      }
14569
15077
    }
14570
15078
  }
14571
 
  else if (vnp->choice == OBJ_BIOSEQ)
 
15079
  else if (data_choice == OBJ_BIOSEQ)
14572
15080
  {
14573
15081
    bsp = (BioseqPtr) vnp->data.ptrvalue;
14574
15082
    bfp = GetBaseFormForEntityID (bsp->idx.entityID);
14577
15085
      SetBioseqViewTargetByBioseq (bfp, bsp);
14578
15086
    }
14579
15087
  }
14580
 
  else if (vnp->choice == OBJ_SEQDESC)
 
15088
  else if (data_choice == OBJ_SEQDESC)
14581
15089
  {
14582
15090
    sdp = (SeqDescrPtr) (vnp->data.ptrvalue);
14583
15091
    if (sdp != NULL && sdp->extended != 0)
14646
15154
        cip->callback_func = ApplyTagToCodingRegionsCallback; 
14647
15155
      } else if (cip->clickable_item_type == DISC_BACTERIAL_PARTIAL_PROBLEMS) {
14648
15156
        cip->callback_func = ExtendPartialsToEndOrGapCallback;
 
15157
      } else if (cip->clickable_item_type == DISC_BACTERIAL_PARTIAL_NONEXTENDABLE_PROBLEMS) {
 
15158
        cip->callback_func = AddNonExtendableExceptionsCallback;
 
15159
      } else if (cip->clickable_item_type == DISC_OVERLAPPING_CDS) {
 
15160
        cip->callback_func = MarkOverlappingCDSCallback;
14649
15161
      } else {
14650
15162
        subtype = GetSubtypeForBulkEdit (cip->item_list);
14651
15163
        /* Note - using FEATDEF_rRNA to represent all editable RNA features */
14662
15174
static void RecheckDiscrepancyProc (ButtoN b)
14663
15175
{
14664
15176
  DiscrepancyReportFormPtr drfp;
14665
 
  ValNodePtr               sep_list;
14666
 
 
14667
 
  drfp = (DiscrepancyReportFormPtr) GetObjectExtra (b);
14668
 
  if (drfp != NULL)
14669
 
  {
14670
 
    WatchCursor();
14671
 
    Update();
14672
 
    drfp->clickable_list_data = FreeClickableList (drfp->clickable_list_data);
14673
 
    
14674
 
    sep_list = GetViewedSeqEntryList ();
14675
 
    drfp->clickable_list_data = CollectDiscrepancies (drfp->dcp, sep_list, CheckTaxNamesAgainstTaxDatabase);
 
15177
  ValNodePtr               sep_list, vnp;
 
15178
  Uint2                    entityID;
 
15179
 
 
15180
  drfp = (DiscrepancyReportFormPtr) GetObjectExtra (b);
 
15181
  if (drfp != NULL)
 
15182
  {
 
15183
    WatchCursor();
 
15184
    Update();
 
15185
    drfp->clickable_list_data = FreeClickableList (drfp->clickable_list_data);
 
15186
    
 
15187
    sep_list = GetViewedSeqEntryList ();
 
15188
    for (vnp = sep_list; vnp != NULL; vnp = vnp->next) {
 
15189
      entityID = ObjMgrGetEntityIDForChoice (vnp->data.ptrvalue);
 
15190
      SeqMgrClearFeatureIndexes (entityID, NULL);
 
15191
      SeqMgrIndexFeatures (entityID, NULL);
 
15192
    }
 
15193
 
 
15194
    drfp->clickable_list_data = CollectDiscrepancies (drfp->dcp, sep_list, CheckTaxNamesAgainstTaxDatabase);
 
15195
 
 
15196
    /* add bulk editing where appropriate */
 
15197
    AddBulkEditing (drfp->clickable_list_data);
 
15198
    
 
15199
    PointerToDialog (drfp->clickable_list_dlg, drfp->clickable_list_data);
 
15200
    ArrowCursor();
 
15201
    Update();
 
15202
  }
 
15203
}
 
15204
 
 
15205
 
 
15206
static void AddNewEntityDiscrepancyProc (ButtoN b, Uint2 new_entityID )
 
15207
{
 
15208
  DiscrepancyReportFormPtr drfp;
 
15209
  ValNodePtr               sep_list, vnp;
 
15210
  Uint2                    entityID;
 
15211
  Boolean                  found = FALSE;
 
15212
 
 
15213
  drfp = (DiscrepancyReportFormPtr) GetObjectExtra (b);
 
15214
  if (drfp != NULL)
 
15215
  {
 
15216
    WatchCursor();
 
15217
    Update();
 
15218
    drfp->clickable_list_data = FreeClickableList (drfp->clickable_list_data);
 
15219
    
 
15220
    sep_list = GetViewedSeqEntryList ();
 
15221
    for (vnp = sep_list; vnp != NULL; vnp = vnp->next) {
 
15222
      entityID = ObjMgrGetEntityIDForChoice (vnp->data.ptrvalue);
 
15223
      SeqMgrClearFeatureIndexes (entityID, NULL);
 
15224
      SeqMgrIndexFeatures (entityID, NULL);
 
15225
      if (entityID == new_entityID) {
 
15226
        found = TRUE;
 
15227
      }
 
15228
    }
 
15229
    if (!found) {
 
15230
      ValNodeAddPointer (&sep_list, 0, GetTopSeqEntryForEntityID (new_entityID));
 
15231
      SeqMgrClearFeatureIndexes (new_entityID, NULL);
 
15232
      SeqMgrIndexFeatures (new_entityID, NULL);
 
15233
    }
 
15234
 
 
15235
    drfp->clickable_list_data = CollectDiscrepancies (drfp->dcp, sep_list, CheckTaxNamesAgainstTaxDatabase);
 
15236
    sep_list = ValNodeFree (sep_list);
14676
15237
 
14677
15238
    /* add bulk editing where appropriate */
14678
15239
    AddBulkEditing (drfp->clickable_list_data);
14952
15513
}
14953
15514
 
14954
15515
 
 
15516
static void FixMarkedDiscrepanciesBtn (ButtoN b)
 
15517
{
 
15518
  DiscrepancyReportFormPtr d;
 
15519
  ValNodePtr vnp, sep_list;
 
15520
  Uint2      entityID;
 
15521
  LogInfoPtr lip = NULL;
 
15522
 
 
15523
  d = (DiscrepancyReportFormPtr) GetObjectExtra (b);
 
15524
  if (d == NULL) {
 
15525
    return;
 
15526
  }
 
15527
  WatchCursor();
 
15528
  Update();
 
15529
  if (d->log_name != NULL) {
 
15530
    lip = OpenLog (d->log_name);
 
15531
  }
 
15532
  AutofixDiscrepancies (d->clickable_list_data, FALSE, lip);
 
15533
  CloseLog (lip);
 
15534
  lip = FreeLog (lip);
 
15535
 
 
15536
  sep_list = GetViewedSeqEntryList ();
 
15537
  for (vnp = sep_list; vnp != NULL; vnp = vnp->next) {
 
15538
    entityID = ObjMgrGetEntityIDForChoice (vnp->data.ptrvalue);
 
15539
    ObjMgrSetDirtyFlag (entityID, TRUE);
 
15540
    ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
 
15541
  }
 
15542
  d->clickable_list_data = FreeClickableList (d->clickable_list_data);
 
15543
  d->clickable_list_data = CollectDiscrepancies (d->dcp, sep_list, CheckTaxNamesAgainstTaxDatabase);
 
15544
  sep_list = ValNodeFree (sep_list);
 
15545
 
 
15546
  /* add bulk editing where appropriate */
 
15547
  AddBulkEditing (d->clickable_list_data);
 
15548
  
 
15549
  PointerToDialog (d->clickable_list_dlg, d->clickable_list_data);
 
15550
 
 
15551
  ArrowCursor();
 
15552
  Update();
 
15553
 
 
15554
}
 
15555
 
 
15556
 
 
15557
static void MarkFixableDiscrepancies (ButtoN b)
 
15558
{
 
15559
  DiscrepancyReportFormPtr d;
 
15560
 
 
15561
  d = (DiscrepancyReportFormPtr) GetObjectExtra (b);
 
15562
  if (d == NULL) {
 
15563
    return;
 
15564
  }
 
15565
  ChooseFixableDiscrepancies (d->clickable_list_data);
 
15566
  PointerToDialog (d->clickable_list_dlg, d->clickable_list_data);
 
15567
}
 
15568
 
 
15569
 
14955
15570
extern void CreateReportWindow (EDiscrepancyReportType report_type)
14956
15571
{
14957
15572
  DiscrepancyReportFormPtr drfp;
14985
15600
 
14986
15601
  /* adjust for report type */
14987
15602
  AdjustConfigForReportType (report_type, drfp->dcp);
 
15603
 
 
15604
  /* Discrepancy Report uses log file for autofix */
 
15605
  if (report_type == eReportTypeDiscrepancy) {
 
15606
    drfp->log_name = StringSave ("Autofix Changes");
 
15607
  }
14988
15608
  
14989
15609
  /* register to receive update messages */
14990
15610
  drfp->userkey = OMGetNextUserKey ();
15015
15635
  b = PushButton (c1, "Contract All", ContractAllDiscReportItems);
15016
15636
  SetObjectExtra (b, drfp, NULL);
15017
15637
 
15018
 
  c = HiddenGroup (h, 4, 0, NULL);
 
15638
  c = HiddenGroup (h, 6, 0, NULL);
15019
15639
  SetGroupSpacing (c, 10, 10);
15020
15640
  b = PushButton (c, "Generate Report", GenerateDiscrepancyReport);
15021
15641
  SetObjectExtra (b, drfp, NULL);
15022
15642
  drfp->recheck_btn = PushButton (c, "Recheck", RecheckDiscrepancyProc);
15023
15643
  SetObjectExtra (drfp->recheck_btn, drfp, NULL);
 
15644
  if (report_type == eReportTypeOnCaller) {
 
15645
    drfp->add_entity_proc = AddNewEntityDiscrepancyProc;
 
15646
  }
 
15647
  b = PushButton (c, "Mark Fixable", MarkFixableDiscrepancies);
 
15648
  SetObjectExtra (b, drfp, NULL);
 
15649
 
 
15650
  b = PushButton (c, "Fix Marked", FixMarkedDiscrepanciesBtn);
 
15651
  SetObjectExtra (b, drfp, NULL);
15024
15652
  
15025
15653
  b = PushButton (c, "Configure", GetReportEditButtonProc (report_type));
15026
15654
  SetObjectExtra (b, drfp, NULL);
16258
16886
  }
16259
16887
}
16260
16888
 
16261
 
static WindoW RNAITSWindow = NULL;
16262
 
 
16263
16889
static void CleanupRNA_ITS (GraphiC g, VoidPtr data)
16264
16890
 
16265
16891
{