111
113
#define REGISTER_UPDATE_SEQALIGN ObjMgrProcLoadEx (OMPROC_FILTER, "Update SeqAlign","UpdateSeqAlign",OBJ_SEQALIGN,0,OBJ_SEQALIGN,0,NULL,NewUpdateSeqAlign,PROC_PRIORITY_DEFAULT, "Alignment")
115
#define REGISTER_FIX_ALIGNMENT_OVER_GAPS ObjMgrProcLoadEx (OMPROC_FILTER, "Fix Alignment Over Gaps", "FixAlignmentOverGaps", 0,0,0,0,NULL,FixAlignmentOverGaps,PROC_PRIORITY_DEFAULT, "Alignment")
117
#define REGISTER_FIX_ALIGNMENT_GAP_GAPS ObjMgrProcLoadEx (OMPROC_FILTER, "Fix Alignment Gaps Containing Known Gaps", "FixKnownGapAlignmentGaps", 0,0,0,0,NULL,ConsolidateGapGaps, PROC_PRIORITY_DEFAULT, "Alignment")
113
119
#define REGISTER_DELETE_BY_TEXT ObjMgrProcLoadEx (OMPROC_FILTER, "Delete By Text","DeleteByText",0,0,0,0,NULL,CreateDeleteByTextWindow,PROC_PRIORITY_DEFAULT, "Indexer")
115
121
#define REGISTER_SEGREGATE_BY_TEXT ObjMgrProcLoadEx (OMPROC_FILTER, "Segregate By Text","SegregateByText",0,0,0,0,NULL,CreateSegregateByTextWindow,PROC_PRIORITY_DEFAULT, "Indexer")
121
127
#define REGISTER_SEGREGATE_BY_MOLECULE_TYPE ObjMgrProcLoadEx (OMPROC_FILTER, "Segregate By Molecule Type","SegregateByMoleculeType",0,0,0,0,NULL,CreateSegregateByMoleculeTypeWindow,PROC_PRIORITY_DEFAULT, "Indexer")
129
#define REGISTER_REORDER_BY_ID ObjMgrProcLoadEx (OMPROC_FILTER, "Reorder by ID","ReorderByID",0,0,0,0,NULL,ReorderSetByAccession,PROC_PRIORITY_DEFAULT, "Indexer")
123
131
#define REGISTER_CONVERTSEQALIGN ObjMgrProcLoadEx (OMPROC_FILTER,"Convert SeqAlign","ConvertSeqAlign",0,0,0,0,NULL,ConvertToTrueMultipleAlignment,PROC_PRIORITY_DEFAULT, "Alignment")
125
133
#define REGISTER_CONVERTTOSEGSETALIGN ObjMgrProcLoadEx (OMPROC_FILTER,"Convert to SegSetAlign","ConvertSegSetAlign",0,0,0,0,NULL,ConvertToSegSetAlignment,PROC_PRIORITY_DEFAULT, "Alignment")
127
135
#define REGISTER_MAKESEQALIGN ObjMgrProcLoadEx (OMPROC_FILTER,"Make SeqAlign","CreateSeqAlign",0,0,0,0,NULL,GenerateSeqAlignFromSeqEntry,PROC_PRIORITY_DEFAULT, "Alignment")
137
#define REGISTER_MAKESEQALIGNNEWBLAST ObjMgrProcLoadEx (OMPROC_FILTER,"Make SeqAlign, New BLAST","CreateSeqAlignNewBLAST",0,0,0,0,NULL,GenerateSeqAlignFromSeqEntryUseNewBlast,PROC_PRIORITY_DEFAULT, "Alignment")
129
139
#define REGISTER_MAKESEQALIGNMASTER ObjMgrProcLoadEx (OMPROC_FILTER,"Make SeqAlign Choose Master","CreateSeqAlignChooseMaster",0,0,0,0,NULL,GenerateSeqAlignFromSeqEntryChooseMaster,PROC_PRIORITY_DEFAULT, "Alignment")
141
#define REGISTER_MAKESEQALIGNMASTERNEWBLAST ObjMgrProcLoadEx (OMPROC_FILTER,"Make SeqAlign Choose Master, New BLAST","CreateSeqAlignChooseMasterNewBLAST",0,0,0,0,NULL,GenerateSeqAlignFromSeqEntryChooseMasterUseNewBlast,PROC_PRIORITY_DEFAULT, "Alignment")
131
143
#define REGISTER_MAKESEQALIGNP ObjMgrProcLoadEx (OMPROC_FILTER,"Make Protein SeqAlign","CreateSeqAlignProt",0,0,0,0,NULL,GenerateSeqAlignFromSeqEntryProt,PROC_PRIORITY_DEFAULT, "Alignment")
145
#define REGISTER_MAKESEQALIGNPNEWBLAST ObjMgrProcLoadEx (OMPROC_FILTER,"Make Protein SeqAlign, New BLAST","CreateSeqAlignProtNewBLAST",0,0,0,0,NULL,GenerateSeqAlignFromSeqEntryProtUseNewBlast,PROC_PRIORITY_DEFAULT, "Alignment")
133
147
#define REGISTER_NORMSEQALIGN ObjMgrProcLoadEx (OMPROC_FILTER,"Validate SeqAlign","ValidateSeqAlign",0,0,0,0,NULL,ValidateSeqAlignFromData,PROC_PRIORITY_DEFAULT, "Alignment")
135
149
#define REGISTER_NOMORESEGGAP ObjMgrProcLoadEx (OMPROC_FILTER,"Get Rid of Seg Gap","GetRidOfSegGap",0,0,0,0,NULL,NoMoreSegGap,PROC_PRIORITY_DEFAULT, "Alignment")
362
typedef struct descriptorextraction
364
Int2 descriptor_choice;
365
SeqDescrPtr sdp_list;
366
} DescriptorExtractionData, PNTR DescriptorExtractionPtr;
368
static void ExtractSegSetDescriptorsBioseqSetCallback (BioseqSetPtr bssp, Pointer userdata)
370
DescriptorExtractionPtr dep;
371
ValNodePtr extracted_list;
373
dep = (DescriptorExtractionPtr) userdata;
374
if (bssp == NULL || dep == NULL || bssp->descr == NULL)
379
extracted_list = ValNodeExtractList (&(bssp->descr), dep->descriptor_choice);
380
ValNodeLink (&dep->sdp_list, extracted_list);
383
static void ExtractSegSetDescriptorsBioseqCallback (BioseqPtr bsp, Pointer userdata)
385
DescriptorExtractionPtr dep;
386
ValNodePtr extracted_list;
388
dep = (DescriptorExtractionPtr) userdata;
389
if (bsp == NULL || dep == NULL || bsp->descr == NULL)
394
extracted_list = ValNodeExtractList (&(bsp->descr), dep->descriptor_choice);
395
ValNodeLink (&dep->sdp_list, extracted_list);
382
static Boolean DoDescriptorsMatch (SeqDescrPtr sdp1, SeqDescrPtr sdp2)
384
if (sdp1 == NULL || sdp2 == NULL || sdp1->choice != sdp2->choice)
389
/* compare publications */
390
if (sdp1->choice == Seq_descr_pub
391
&& PubdescContentMatch (sdp1->data.ptrvalue, sdp2->data.ptrvalue))
395
/* compare sources */
396
else if (sdp1->choice == Seq_descr_source
397
&& BioSourceMatch (sdp1->data.ptrvalue, sdp2->data.ptrvalue))
401
/* compare update dates */
402
else if (sdp1->choice == Seq_descr_update_date
403
&& DateMatch (sdp1->data.ptrvalue, sdp2->data.ptrvalue, TRUE))
413
static Boolean FindIdenticalDescriptorInEachBioseqInList (SeqDescrPtr sdp, SeqEntryPtr sep)
415
SeqDescrPtr check_sdp;
416
Boolean found_match = FALSE;
428
if (!IS_Bioseq(sep) || sep->data.ptrvalue == NULL)
433
bsp = (BioseqPtr) sep->data.ptrvalue;
434
check_sdp = bsp->descr;
435
while (check_sdp != NULL && !found_match)
437
found_match = DoDescriptorsMatch (check_sdp, sdp);
438
check_sdp = check_sdp->next;
443
found_match = FindIdenticalDescriptorInEachBioseqInList (sdp, sep->next);
450
static void RemoveIdenticalDescriptorInEachBioseqInList (SeqDescrPtr sdp, SeqEntryPtr sep)
452
SeqDescrPtr check_sdp, prev = NULL;
455
if (sdp == NULL || sep == NULL || !IS_Bioseq(sep) || sep->data.ptrvalue == NULL)
460
bsp = (BioseqPtr) sep->data.ptrvalue;
461
check_sdp = bsp->descr;
462
while (check_sdp != NULL)
464
if (DoDescriptorsMatch (check_sdp, sdp))
468
bsp->descr = check_sdp->next;
472
prev->next = check_sdp->next;
474
check_sdp->next = NULL;
475
check_sdp = SeqDescrFree (check_sdp);
480
check_sdp = check_sdp->next;
484
RemoveIdenticalDescriptorInEachBioseqInList (sdp, sep->next);
399
MoveSegSetDescriptorsUp
489
MoveUpIdenticalSegSetDescriptors
400
490
(BioseqPtr segseq,
401
491
BioseqSetPtr parts,
402
492
BioseqSetPtr segset,
403
493
Int2 descriptor_choice)
407
DescriptorExtractionData ded;
408
497
BioseqSetPtr bssp;
411
if (segseq == NULL || parts == NULL || parts->seq_set == NULL || segset == NULL) return;
498
SeqDescrPtr sdp, sdp_next, prev = NULL;
499
SeqDescrPtr moved_list = NULL;
501
if (segseq == NULL || parts == NULL || parts->seq_set == NULL || segset == NULL
502
|| ! IS_Bioseq (parts->seq_set) || parts->seq_set->data.ptrvalue == NULL)
412
507
sep = GetBestTopParentForData (segseq->idx.entityID, segseq);
415
510
sep = SeqMgrGetSeqEntryForData (segset);
418
if (sep == NULL || sep->data.ptrvalue == NULL) return;
420
ded.descriptor_choice = descriptor_choice;
423
VisitSetsInSep (sep, &ded, ExtractSegSetDescriptorsBioseqSetCallback);
424
VisitBioseqsInSep (sep, &ded, ExtractSegSetDescriptorsBioseqCallback);
513
bsp = (BioseqPtr) parts->seq_set->data.ptrvalue;
518
sdp_next = sdp->next;
519
if (sdp->choice == descriptor_choice
520
&& FindIdenticalDescriptorInEachBioseqInList (sdp, parts->seq_set->next))
522
RemoveIdenticalDescriptorInEachBioseqInList (sdp, parts->seq_set->next);
525
bsp->descr = sdp->next;
529
prev->next = sdp->next;
532
ValNodeLink (&moved_list, sdp);
426
541
if (IS_Bioseq_set (sep))
428
543
bssp = (BioseqSetPtr) sep->data.ptrvalue;
429
ValNodeLink (&(bssp->descr), ded.sdp_list);
544
ValNodeLink (&(bssp->descr), moved_list);
431
546
else if (IS_Bioseq (sep))
433
548
bsp = (BioseqPtr) sep->data.ptrvalue;
434
ValNodeLink (&(bsp->descr), ded.sdp_list);
549
ValNodeLink (&(bsp->descr), moved_list);
438
554
static void DoUpdateSegSet (BioseqPtr segseq, BioseqSetPtr parts, Boolean ask, Boolean force_intersperse)
3639
3745
return OM_MSG_RET_OK;
3748
static Boolean IsIntervalGap (BioseqPtr bsp, Int4 start, Int4 stop)
3753
Int4 seq_offset = 0, len;
3754
Boolean interval_in_gap = TRUE;
3755
Boolean this_is_gap;
3758
|| bsp->repr != Seq_repr_delta
3759
|| bsp->seq_ext_type != 4
3761
|| stop >= bsp->length)
3766
for (dsp = (DeltaSeqPtr) bsp->seq_ext;
3767
dsp != NULL && dsp->next != NULL && seq_offset < stop;
3771
this_is_gap = FALSE;
3772
if (dsp->choice == 1)
3774
loc = (SeqLocPtr) dsp->data.ptrvalue;
3775
len = SeqLocLen (loc);
3777
else if (dsp->choice == 2)
3779
litp = (SeqLitPtr) dsp->data.ptrvalue;
3783
if (litp->seq_data == NULL)
3790
if (seq_offset <= start && seq_offset + len >= stop)
3794
else if ((seq_offset <= start && seq_offset + len > start)
3795
|| (seq_offset < stop && seq_offset + len > stop)
3796
|| (seq_offset >= start && seq_offset + len <= stop))
3809
CollapseTwoGapSegments
3812
BioseqPtr PNTR bsparray)
3816
Uint1Ptr newstrands = NULL;
3817
Int4 row_num, seg_num;
3819
if (dsp == NULL || seg_num_first > dsp->numseg - 2)
3824
if (dsp->lens [seg_num_first] != dsp->lens [seg_num_first + 1])
3829
for (row_num = 0; row_num < dsp->dim; row_num++)
3831
if (dsp->starts [seg_num_first * dsp->dim + row_num] != -1
3832
&& dsp->starts [(seg_num_first + 1) * dsp->dim + row_num] != -1)
3837
/* segment must be over a gap for all rows not in gap */
3838
/* for the first segment */
3839
if (dsp->starts [seg_num_first * dsp->dim + row_num] != -1
3840
&& ! IsIntervalGap (bsparray[row_num],
3841
dsp->starts [seg_num_first * dsp->dim + row_num],
3842
dsp->starts [seg_num_first * dsp->dim + row_num] + dsp->lens[seg_num_first]))
3847
/* and for the second segment */
3848
if (dsp->starts [(seg_num_first + 1) * dsp->dim + row_num] != -1
3849
&& ! IsIntervalGap (bsparray[row_num],
3850
dsp->starts [(seg_num_first + 1) * dsp->dim + row_num],
3851
dsp->starts [(seg_num_first + 1) * dsp->dim + row_num] + dsp->lens[seg_num_first + 1]))
3858
newstarts = (Int4Ptr) MemNew (sizeof (Int4) * dsp->dim * (dsp->numseg - 1));
3859
newlens = (Int4Ptr) MemNew (sizeof (Int4) * (dsp->numseg - 1));
3860
if (dsp->strands != NULL)
3862
newstrands = (Uint1Ptr) MemNew (sizeof (Uint1) * dsp->dim * (dsp->numseg - 1));
3865
/* copy the portion of the alignment before the segments to be collapsed */
3866
for (seg_num = 0; seg_num < seg_num_first; seg_num++)
3868
for (row_num = 0; row_num < dsp->dim; row_num++)
3870
newstarts [seg_num * dsp->dim + row_num] = dsp->starts [seg_num * dsp->dim + row_num];
3871
if (dsp->strands != NULL)
3873
newstrands [seg_num * dsp->dim + row_num] = dsp->strands[seg_num * dsp->dim + row_num];
3876
newlens[seg_num] = dsp->lens[seg_num];
3879
/* collapse the two segments */
3880
for (row_num = 0; row_num < dsp->dim; row_num++)
3882
if (dsp->starts [seg_num * dsp->dim + row_num] == -1)
3884
newstarts [seg_num * dsp->dim + row_num] = dsp->starts [(seg_num + 1) * dsp->dim + row_num];
3885
if (dsp->strands != NULL)
3887
newstrands [seg_num * dsp->dim + row_num] = dsp->strands [(seg_num + 1) * dsp->dim + row_num];
3892
newstarts [seg_num * dsp->dim + row_num] = dsp->starts [seg_num * dsp->dim + row_num];
3893
if (dsp->strands != NULL)
3895
newstrands [seg_num * dsp->dim + row_num] = dsp->strands [seg_num * dsp->dim + row_num];
3899
newlens [seg_num] = dsp->lens [seg_num];
3902
/* copy the remaining segments after the collapsed pair */
3903
while (seg_num < dsp->numseg - 1)
3905
for (row_num = 0; row_num < dsp->dim; row_num++)
3907
newstarts [seg_num * dsp->dim + row_num] = dsp->starts [(seg_num + 1) * dsp->dim + row_num];
3908
if (dsp->strands != NULL)
3910
newstrands [seg_num * dsp->dim + row_num] = dsp->strands[(seg_num + 1) * dsp->dim + row_num];
3913
newlens[seg_num] = dsp->lens[(seg_num + 1)];
3917
/* replace the starts, strands, lens, and numseg in dsp */
3918
dsp->starts = MemFree (dsp->starts);
3919
dsp->starts = newstarts;
3920
dsp->strands = MemFree (dsp->strands);
3921
dsp->strands = newstrands;
3922
dsp->lens = MemFree (dsp->lens);
3923
dsp->lens = newlens;
3928
extern void ConsolidateSegmentsOverKnownLengthGaps (SeqAlignPtr salp)
3932
BioseqPtr PNTR bsparray;
3933
Int4 row_num, seg_num;
3935
if (salp == NULL || salp->segtype != SAS_DENSEG || salp->segs == NULL)
3940
if (salp->saip != NULL)
3942
SeqAlignIndexFree(salp->saip);
3946
dsp = (DenseSegPtr) salp->segs;
3948
bsparray = (BioseqPtr PNTR) MemNew (sizeof (BioseqPtr) * dsp->dim);
3951
for (sip = dsp->ids, row_num = 0;
3952
sip != NULL && row_num < dsp->dim;
3953
sip = sip->next, row_num++)
3955
bsparray [row_num] = BioseqFind (sip);
3959
while (seg_num < dsp->numseg - 1)
3961
if (!CollapseTwoGapSegments (dsp, seg_num, bsparray))
3967
AlnMgr2IndexSeqAlignEx(salp, FALSE);
3968
bsparray = MemFree (bsparray);
3971
static Int2 LIBCALLBACK ConsolidateGapGaps (Pointer data)
3974
OMProcControlPtr ompcp;
3975
SeqAlignPtr salp=NULL;
3977
SeqAnnotPtr sanp_old;
3979
ompcp = (OMProcControlPtr) data;
3980
if (ompcp == NULL || ompcp->proc == NULL) return OM_MSG_RET_ERROR;
3982
if (ompcp->input_data == NULL) return OM_MSG_RET_ERROR;
3984
switch(ompcp->input_itemtype)
3987
salp = (SeqAlignPtr) ompcp->input_data;
3990
sanp_old = (SeqAnnotPtr) ompcp->input_data;
3991
if (sanp_old->type == 2)
3993
salp = sanp_old->data;
3997
return OM_MSG_RET_ERROR;
4000
return OM_MSG_RET_ERROR;
4001
entityID = ompcp->input_entityID;
4003
return OM_MSG_RET_ERROR;
4005
ConsolidateSegmentsOverKnownLengthGaps (salp);
4007
ObjMgrSetDirtyFlag (entityID, TRUE);
4009
ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
4011
return OM_MSG_RET_OK;
4015
/* NOTE - need to call DeleteMarkedObjects after calling this function */
4016
extern void FixOneAlignmentOverGaps (SeqAlignPtr salp, Uint2 entityID)
4018
SeqAnnotPtr sanp_old, sanp_new;
4019
SeqAlignPtr salp_copy, salp_tmp;
4020
BioseqSetPtr bssp = NULL;
4022
sanp_old = GetSeqAnnotForAlignment (salp);
4023
if (sanp_old == NULL)
4028
if (sanp_old->idx.parenttype == OBJ_BIOSEQSET)
4030
bssp = (BioseqSetPtr) sanp_old->idx.parentptr;
4033
/* make a copy of the alignment */
4034
salp_copy = (SeqAlignPtr) AsnIoMemCopy (salp, (AsnReadFunc) SeqAlignAsnRead,
4035
(AsnWriteFunc) SeqAlignAsnWrite);
4036
/* the copy function doesn't copy the index, so the alignment must be
4039
AlnMgr2IndexSeqAlignEx(salp_copy, FALSE);
4040
/* break the alignment at gaps, if the set contains any delta sequences */
4041
salp_copy = MakeDiscontiguousAlignments (salp_copy);
4043
for (salp_tmp = salp_copy; salp_tmp != NULL; salp_tmp = salp_tmp->next)
4045
NoMoreSegGapForOneAlignment (salp_tmp, NULL);
4048
/* break the chain of alignments and create separate SeqAnnots for each one */
4049
CreateSeqAnnotsForDiscontiguousAlignments (salp_copy, entityID, bssp);
4051
/* need to index the alignments before we can find the new alignment and remove the old */
4052
ObjMgrSetDirtyFlag (entityID, TRUE);
4053
ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
4055
sanp_new = GetSeqAnnotForAlignment (salp_copy);
4057
if (sanp_new != NULL)
4059
salp->idx.deleteme = TRUE;
4063
static Int2 LIBCALLBACK FixAlignmentOverGaps (Pointer data)
4066
OMProcControlPtr ompcp;
4067
SeqAlignPtr salp=NULL;
4069
SeqAnnotPtr sanp_old;
4071
ompcp = (OMProcControlPtr) data;
4072
if (ompcp == NULL || ompcp->proc == NULL) return OM_MSG_RET_ERROR;
4074
if (ompcp->input_data == NULL) return OM_MSG_RET_ERROR;
4076
switch(ompcp->input_itemtype)
4079
salp = (SeqAlignPtr) ompcp->input_data;
4082
sanp_old = (SeqAnnotPtr) ompcp->input_data;
4083
if (sanp_old->type == 2)
4085
salp = sanp_old->data;
4089
return OM_MSG_RET_ERROR;
4092
return OM_MSG_RET_ERROR;
4093
entityID = ompcp->input_entityID;
4095
return OM_MSG_RET_ERROR;
4097
FixOneAlignmentOverGaps (salp, entityID);
4098
DeleteMarkedObjects (entityID, 0, NULL);
4100
ObjMgrSetDirtyFlag (entityID, TRUE);
4102
ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
4104
return OM_MSG_RET_OK;
3642
4108
typedef struct sqn_bsp {
3644
4110
struct sqn_bsp PNTR next;
4686
5171
ValidateSeqAlign (salp_mult, entityID, TRUE, FALSE, TRUE, FALSE, FALSE, &dirty);
4687
5172
SeqAlignSetFree(salp_head);
4688
sap = SeqAnnotForSeqAlign(salp_mult);
5174
/* index multiple alignment */
5175
AlnMgr2IndexSeqAlignEx(salp_mult, FALSE);
5177
/* break up alignment if it covers gaps of unknown length */
5178
salp_mult = MakeDiscontiguousAlignments (salp_mult);
4693
sep = GetTopSeqEntryForEntityID (entityID);
4694
if (sep != NULL && sep->data.ptrvalue != NULL) {
4696
if (IS_Bioseq (sep)) {
4697
bsp = (BioseqPtr) sep->data.ptrvalue;
4698
sapp = &(bsp->annot);
4699
} else if (IS_Bioseq_set (sep)) {
4700
bssp = (BioseqSetPtr) sep->data.ptrvalue;
4701
sapp = &(bssp->annot);
4704
if (*sapp != NULL) {
4706
while (curr->next != NULL) {
4714
ObjMgrSetDirtyFlag (entityID, TRUE);
4715
ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
5183
if (salp_mult != NULL)
5185
/* create separate SeqAnnots for each alignment in the chain */
5186
CreateSeqAnnotsForDiscontiguousAlignments (salp_mult, entityID, bssp);
5187
ObjMgrSetDirtyFlag (entityID, TRUE);
5188
ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
4718
5190
if (num_reversed > 0)
11094
11615
FindReplaceString (&(ssp->name), "Vietnam", "Viet Nam", FALSE, TRUE);
11095
11616
FindReplaceString (&(ssp->name), "Ivory Coast", "Cote d'Ivoire", FALSE, TRUE);
11096
11617
FindReplaceString (&(ssp->name), "UK", "United Kingdom", FALSE, TRUE);
11618
FindReplaceString (&(ssp->name), "United States of America", "USA", FALSE, TRUE);
11619
FindReplaceString (&(ssp->name), "United States", "USA", FALSE, TRUE);
11620
FindReplaceString (&(ssp->name), "U.S.A.", "USA", FALSE, TRUE);
11623
static CharPtr MoveStateAndAddComma (CharPtr cntry_str, CharPtr state_match, Int4 len_cntry)
11625
CharPtr newname = NULL, cp;
11626
Int4 len_state, len_qual, len_after, len_before;
11628
if (StringHasNoText (cntry_str) || StringHasNoText (state_match) || len_cntry < 1)
11633
cp = StringISearch (cntry_str + len_cntry + 2, state_match);
11636
len_state = StringLen (state_match);
11637
len_qual = StringLen (cntry_str);
11639
if (cp == cntry_str + len_cntry + 2)
11641
/* state is at beginning of string */
11642
len_after = len_qual - len_cntry - 2 - len_state;
11643
if (len_after == 0 || cntry_str [len_cntry + 2 + len_state] == ',')
11645
/* already in correct format, nothing after state name */
11646
/* just copy in state name, in case we are correcting case */
11647
StringNCpy (cp, state_match, len_state);
11653
newname = (CharPtr) MemNew (StringLen (cntry_str) + 3);
11654
StringNCpy (newname, cntry_str, len_cntry + 2 + len_state);
11655
newname [len_cntry + 2 + len_state] = 0;
11656
StringCat (newname, ",");
11657
StringCat (newname, cntry_str + len_cntry + 2 + len_state);
11658
cntry_str = MemFree (cntry_str);
11659
cntry_str = newname;
11664
newname = (CharPtr) MemNew (StringLen (cntry_str) + 3);
11665
StringNCpy (newname, cntry_str, len_cntry + 2);
11666
newname [len_cntry + 2] = 0;
11667
StringCat (newname, state_match);
11668
StringCat (newname, ", ");
11669
len_before = cp - cntry_str - 3 - len_cntry;
11670
StringNCpy (newname + len_cntry + 2 + len_state + 2,
11671
cntry_str + len_cntry + 2,
11673
newname [len_cntry + 2 + len_state + 2 + len_before] = 0;
11674
StringCat (newname, cp + len_state);
11675
cntry_str = MemFree (cntry_str);
11676
cntry_str = newname;
11099
11682
static void FindCountryName (SubSourcePtr ssp, CharPtr PNTR country_list)
11101
11684
CharPtr best_match, state_match;
11102
CharPtr cp, before, newname;
11685
CharPtr cp, before, newname, after;
11103
11686
Int4 len_cntry, len_qual, len_name;
11105
11688
if (ssp == NULL || ssp->subtype != SUBSRC_country || StringHasNoText (ssp->name))
11133
11716
else if (best_match != NULL)
11135
cp = StringStr (ssp->name, best_match);
11718
cp = StringISearch (ssp->name, best_match);
11136
11719
len_cntry = StringLen (best_match);
11720
after = cp + len_cntry;
11721
while (isspace (*after) || ispunct(*after))
11138
11726
if (cp != NULL && !isalpha ((Int4)(cp [len_cntry])))
11140
11728
len_qual = StringLen (ssp->name);
11141
11729
if (cp == ssp->name)
11143
if (len_cntry == len_qual || ssp->name [len_cntry] == ':')
11145
/* exact match, don't need to do anything */
11148
ssp->name [len_cntry] = ':';
11731
newname = (CharPtr) MemNew (len_cntry + StringLen (after) + 3);
11732
sprintf (newname, "%s: %s", best_match, after);
11153
newname = (CharPtr) MemNew (len_qual + 3);
11736
/* strip spaces and punctuation from before */
11154
11737
*(cp - 1) = 0;
11155
before = StringSave (ssp->name);
11156
StringNCpy (newname, best_match, len_cntry);
11157
newname [len_cntry] = ':';
11158
newname [len_cntry + 1] = ' ';
11159
StringNCpy (newname + len_cntry + 2, before, StringLen (before));
11160
StringCpy (newname + len_cntry + 2 + StringLen (before), cp + len_cntry);
11161
len_name = StringLen (newname);
11162
while (isspace ((Int4)(newname[len_name - 1])) || ispunct ((Int4)(newname [len_name - 1])))
11164
newname [len_name - 1] = 0;
11167
before = MemFree (before);
11168
MemFree (ssp->name);
11169
ssp->name = newname;
11739
while (before >= ssp->name
11740
&& (isspace (*before) || ispunct (*before)))
11745
before = ssp->name;
11746
while (isspace (*before) || ispunct(*before))
11751
newname = (CharPtr) MemNew (len_cntry + StringLen (before) + StringLen (after) + 4);
11752
sprintf (newname, "%s: %s%s%s", best_match, before,
11753
StringHasNoText (before) || StringHasNoText(after) ? "" : " ",
11756
if (state_match != NULL)
11758
newname = MoveStateAndAddComma (newname, state_match, len_cntry);
11761
/* remove trailing spaces and punctuation */
11762
len_name = StringLen (newname);
11763
while (isspace ((Int4)(newname[len_name - 1])) || ispunct ((Int4)(newname [len_name - 1])))
11765
newname [len_name - 1] = 0;
11768
MemFree (ssp->name);
11769
ssp->name = newname;
12481
extern CharPtr FixInfluenzaVirusName (CharPtr orig_name)
12483
CharPtr desired_name = "Influenza A virus";
12484
Int4 desired_len = StringLen (desired_name);
12485
CharPtr new_name = NULL, cp, src_cp, dst_cp;
12487
if (StringHasNoText(orig_name)
12488
|| StringNICmp (orig_name, desired_name, desired_len) != 0)
12493
cp = orig_name + desired_len;
12499
/* allow one space and only one space between virus and the strain/serotype */
12503
new_name = (CharPtr) MemNew (sizeof (Char) * (StringLen (orig_name) + 2));
12504
sprintf (new_name, "%s %s", desired_name, cp);
12508
new_name = StringSave (orig_name);
12511
dst_cp = new_name + desired_len;
12513
if (*dst_cp != ' ')
12515
new_name = MemFree (new_name);
12522
/* skip over spaces */
12523
while (isspace (*src_cp))
12527
if (*src_cp != '(')
12529
new_name = MemFree (new_name);
12532
/* copy first open paren */
12537
/* skip over spaces */
12538
while (*src_cp == ' ' || *src_cp == '\t')
12542
/* copy to next open paren */
12543
while (*src_cp != '(' && *src_cp != 0)
12551
new_name = MemFree (new_name);
12554
/* skip back past spaces */
12555
while (*(dst_cp - 1) == ' ' || *(dst_cp - 1) == '\t')
12559
/* copy to first close paren */
12560
while (*src_cp != ')' && *src_cp != 0)
12568
new_name = MemFree (new_name);
12571
/* skip back past spaces */
12572
while (*(dst_cp - 1) == ' ' || *(dst_cp - 1) == '\t')
12576
/* copy first close paren */
12580
/* skip over spaces */
12581
while (*src_cp == ' ' || *src_cp == '\t')
12585
/* copy to second close paren */
12586
while (*src_cp != ')' && *src_cp != 0)
12594
new_name = MemFree (new_name);
12597
/* skip back past spaces */
12598
while (*(dst_cp - 1) == ' ' || *(dst_cp - 1) == '\t')
12602
/* copy second close paren */
12606
while (*src_cp == ' ' || *src_cp == '\t')
12612
new_name = MemFree (new_name);
12620
FixupInfluenzaAVirusNamesCallback
12621
(BioSourcePtr biop,
12626
if (biop == NULL || biop->org == NULL)
12631
new_name = FixInfluenzaVirusName (biop->org->taxname);
12633
if (new_name != NULL)
12635
SetTaxNameAndRemoveTaxRef (biop->org, new_name);
12636
RemoveOldName(biop->org);
12641
extern void FixupInfluenzaAVirusNames(IteM i)
12647
bfp = currentFormDataPtr;
12649
bfp = GetObjectExtra (i);
12651
if (bfp == NULL) return;
12653
sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
12654
if (sep == NULL) return;
12655
VisitBioSourcesInSep (sep, NULL, FixupInfluenzaAVirusNamesCallback);
12656
ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
12657
ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
11805
12661
/* The following code is used for global publication editing. */
11806
12662
/* This section of code is used to create a Publication Constraint */
16807
static void PropagateMasterSourceToSegments (BioseqSetPtr bssp)
16809
SeqEntryPtr sep, seg_entry;
16810
SeqDescrPtr sdp, copy_sdp, sdp_next;
16811
SeqMgrDescContext dcontext;
16812
BioseqSetPtr parts_set;
16813
BioseqPtr bsp, part_bsp;
16821
if (bssp->_class == BioseqseqSet_class_segset)
16823
sep = bssp->seq_set;
16824
/* find master segment */
16825
while (sep != NULL && (!IS_Bioseq (sep) || sep->data.ptrvalue == NULL))
16831
bsp = (BioseqPtr) sep->data.ptrvalue;
16832
sdp = SeqMgrGetNextDescriptor (bsp, NULL, Seq_descr_source, &dcontext);
16835
/* don't want to copy descriptors after Bioseq */
16836
sdp_next = sdp->next;
16839
/* find parts set */
16840
sep = bssp->seq_set;
16842
while (sep != NULL && parts_set == NULL)
16844
if (IS_Bioseq_set (sep) && sep->data.ptrvalue != NULL)
16846
parts_set = (BioseqSetPtr) sep->data.ptrvalue;
16847
if (parts_set->_class != BioseqseqSet_class_parts)
16854
if (parts_set != NULL)
16856
/* add a copy of the master source to each segment */
16857
for (seg_entry = parts_set->seq_set;
16859
seg_entry = seg_entry->next)
16861
if (!IS_Bioseq (seg_entry) || seg_entry->data.ptrvalue == NULL)
16865
part_bsp = (BioseqPtr) seg_entry->data.ptrvalue;
16866
copy_sdp = (SeqDescrPtr) AsnIoMemCopy (sdp,
16867
(AsnReadFunc) SeqDescrAsnRead,
16868
(AsnWriteFunc) SeqDescrAsnWrite);
16869
ValNodeLink (&(part_bsp->descr),copy_sdp);
16872
sdp->next = sdp_next;
16873
/* we want to remove the source descriptor from the master */
16874
if (sdp->extended != 0) {
16875
ovp = (ObjValNodePtr) sdp;
16876
ovp->idx.deleteme = TRUE;
16883
for (sep = bssp->seq_set; sep != NULL; sep = sep->next)
16885
if (IS_Bioseq_set (sep))
16887
PropagateMasterSourceToSegments (sep->data.ptrvalue);
16894
static Int2 LIBCALLBACK CopyMasterSourceToSegments (Pointer data)
16897
OMProcControlPtr ompcp;
16898
SeqEntryPtr sep = NULL;
16900
ompcp = (OMProcControlPtr) data;
16901
if (ompcp == NULL || ompcp->proc == NULL) return OM_MSG_RET_ERROR;
16902
switch (ompcp->input_itemtype) {
16904
sep = GetTopSeqEntryForEntityID (ompcp->input_entityID);
16906
case OBJ_BIOSEQSET :
16907
sep = SeqMgrGetSeqEntryForData (ompcp->input_data);
16910
return OM_MSG_RET_ERROR;
16912
return OM_MSG_RET_ERROR;
16914
if (sep == NULL || !IS_Bioseq_set (sep) || sep->data.ptrvalue == NULL) return OM_MSG_RET_ERROR;
16916
PropagateMasterSourceToSegments(sep->data.ptrvalue);
16918
DeleteMarkedObjects (ompcp->input_entityID, 0, NULL);
16919
ObjMgrSetDirtyFlag (ompcp->input_entityID, TRUE);
16920
ObjMgrSendMsg (OM_MSG_UPDATE, ompcp->input_entityID, 0, 0);
16921
return OM_MSG_RET_DONE;