2
* ===========================================================================
5
* National Center for Biotechnology Information (NCBI)
7
* This software/database is a "United States Government Work" under the
8
* terms of the United States Copyright Act. It was written as part of
9
* the author's official duties as a United States Government employee and
10
* thus cannot be copyrighted. This software/database is freely available
11
* to the public for use. The National Library of Medicine and the U.S.
12
* Government do not place any restriction on its use or reproduction.
13
* We would, however, appreciate having the NCBI and the author cited in
14
* any work or product based on this material
16
* Although all reasonable efforts have been taken to ensure the accuracy
17
* and reliability of the software and data, the NLM and the U.S.
18
* Government do not and cannot warrant the performance or results that
19
* may be obtained by using this software or data. The NLM and the U.S.
20
* Government disclaim all warranties, express or implied, including
21
* warranties of performance, merchantability or fitness for any particular
24
* ===========================================================================
28
* Author: Colleen Bollin
30
* Version Creation Date: 11/8/2007
37
* --------------------------------------------------------------------------
38
* Date Name Description of modification
39
* ------- ---------- -----------------------------------------------------
42
* ==========================================================================
56
#define NLM_GENERATED_CODE_PROTO
60
/* structure and create/free functions for CGPSet, used for handling CDS-Gene-Prot sets */
67
} CGPSetData, PNTR CGPSetPtr;
71
static CGPSetPtr CGPSetNew (void)
75
c = (CGPSetPtr) MemNew (sizeof (CGPSetData));
84
static CGPSetPtr CGPSetFree (CGPSetPtr c)
87
c->cds_list = ValNodeFree (c->cds_list);
88
c->gene_list = ValNodeFree (c->gene_list);
89
c->prot_list = ValNodeFree (c->prot_list);
90
c->mrna_list = ValNodeFree (c->mrna_list);
97
static ValNodePtr FreeCGPSetList (ValNodePtr vnp)
101
while (vnp != NULL) {
102
vnp_next = vnp->next;
104
vnp->data.ptrvalue = CGPSetFree (vnp->data.ptrvalue);
105
vnp = ValNodeFree (vnp);
112
/* generic functions for mapping constraints */
114
typedef struct feattypefeatdef {
118
} FeatTypeFeatDefData, PNTR FeatTypeFeatDefPtr;
120
static FeatTypeFeatDefData feattype_featdef[] = {
121
{ Feature_type_any , FEATDEF_ANY , "any" } ,
122
{ Feature_type_gene , FEATDEF_GENE , "gene" } ,
123
{ Feature_type_org , FEATDEF_ORG , "org" } ,
124
{ Feature_type_cds , FEATDEF_CDS , "CDS" } ,
125
{ Feature_type_prot , FEATDEF_PROT , "Protein" } ,
126
{ Feature_type_preRNA , FEATDEF_preRNA , "preRNA" } ,
127
{ Feature_type_mRNA , FEATDEF_mRNA , "mRNA" } ,
128
{ Feature_type_tRNA , FEATDEF_tRNA , "tRNA" } ,
129
{ Feature_type_rRNA , FEATDEF_rRNA , "rRNA" } ,
130
{ Feature_type_snRNA , FEATDEF_snRNA , "snRNA" } ,
131
{ Feature_type_scRNA , FEATDEF_scRNA , "scRNA" } ,
132
{ Feature_type_otherRNA , FEATDEF_otherRNA , "misc_RNA" } ,
133
{ Feature_type_pub , FEATDEF_PUB , "pub" } ,
134
{ Feature_type_seq , FEATDEF_SEQ , "seq" } ,
135
{ Feature_type_imp , FEATDEF_IMP , "imp" } ,
136
{ Feature_type_allele , FEATDEF_allele , "allele" } ,
137
{ Feature_type_attenuator , FEATDEF_attenuator , "attenuator" } ,
138
{ Feature_type_c_region , FEATDEF_C_region , "c_region" } ,
139
{ Feature_type_caat_signal , FEATDEF_CAAT_signal , "caat_signal" } ,
140
{ Feature_type_imp_CDS , FEATDEF_Imp_CDS , "imp_CDS" } ,
141
{ Feature_type_conflict , FEATDEF_conflict , "conflict" } ,
142
{ Feature_type_d_loop , FEATDEF_D_loop , "d_loop" } ,
143
{ Feature_type_d_segment , FEATDEF_D_segment , "d_segment" } ,
144
{ Feature_type_enhancer , FEATDEF_enhancer , "enhancer" } ,
145
{ Feature_type_exon , FEATDEF_exon , "exon" } ,
146
{ Feature_type_gC_signal , FEATDEF_GC_signal , "gC_signal" } ,
147
{ Feature_type_iDNA , FEATDEF_iDNA , "iDNA" } ,
148
{ Feature_type_intron , FEATDEF_intron , "intron" } ,
149
{ Feature_type_j_segment , FEATDEF_J_segment , "j_segment" } ,
150
{ Feature_type_ltr , FEATDEF_LTR , "ltr" } ,
151
{ Feature_type_mat_peptide , FEATDEF_mat_peptide , "mat_peptide" } ,
152
{ Feature_type_misc_binding , FEATDEF_misc_binding , "misc_binding" } ,
153
{ Feature_type_misc_difference , FEATDEF_misc_difference , "misc_difference" } ,
154
{ Feature_type_misc_feature , FEATDEF_misc_feature , "misc_feature" } ,
155
{ Feature_type_misc_recomb , FEATDEF_misc_recomb , "misc_recomb" } ,
156
{ Feature_type_misc_RNA , FEATDEF_misc_RNA , "misc_RNA" } ,
157
{ Feature_type_misc_signal , FEATDEF_misc_signal , "misc_signal" } ,
158
{ Feature_type_misc_structure , FEATDEF_misc_structure , "misc_structure" } ,
159
{ Feature_type_modified_base , FEATDEF_modified_base , "modified_base" } ,
160
{ Feature_type_mutation , FEATDEF_mutation , "mutation" } ,
161
{ Feature_type_n_region , FEATDEF_N_region , "n_region" } ,
162
{ Feature_type_old_sequence , FEATDEF_old_sequence , "old_sequence" } ,
163
{ Feature_type_polyA_signal , FEATDEF_polyA_signal , "polyA_signal" } ,
164
{ Feature_type_polyA_site , FEATDEF_polyA_site , "polyA_site" } ,
165
{ Feature_type_precursor_RNA , FEATDEF_precursor_RNA , "precursor_RNA" } ,
166
{ Feature_type_prim_transcript , FEATDEF_prim_transcript , "prim_transcript" } ,
167
{ Feature_type_primer_bind , FEATDEF_primer_bind , "primer_bind" } ,
168
{ Feature_type_promoter , FEATDEF_promoter , "promoter" } ,
169
{ Feature_type_protein_bind , FEATDEF_protein_bind , "protein_bind" } ,
170
{ Feature_type_rbs , FEATDEF_RBS , "rbs" } ,
171
{ Feature_type_repeat_region , FEATDEF_repeat_region , "repeat_region" } ,
172
{ Feature_type_repeat_unit , FEATDEF_repeat_unit , "repeat_unit" } ,
173
{ Feature_type_rep_origin , FEATDEF_rep_origin , "rep_origin" } ,
174
{ Feature_type_s_region , FEATDEF_S_region , "s_region" } ,
175
{ Feature_type_satellite , FEATDEF_satellite , "satellite" } ,
176
{ Feature_type_sig_peptide , FEATDEF_sig_peptide , "sig_peptide" } ,
177
{ Feature_type_source , FEATDEF_source , "source" } ,
178
{ Feature_type_stem_loop , FEATDEF_stem_loop , "stem_loop" } ,
179
{ Feature_type_sts , FEATDEF_STS , "sts" } ,
180
{ Feature_type_tata_signal , FEATDEF_TATA_signal , "tata_signal" } ,
181
{ Feature_type_terminator , FEATDEF_terminator , "terminator" } ,
182
{ Feature_type_transit_peptide , FEATDEF_transit_peptide , "transit_peptide" } ,
183
{ Feature_type_unsure , FEATDEF_unsure , "unsure" } ,
184
{ Feature_type_v_region , FEATDEF_V_region , "v_region" } ,
185
{ Feature_type_v_segment , FEATDEF_V_segment , "v_segment" } ,
186
{ Feature_type_variation , FEATDEF_variation , "variation" } ,
187
{ Feature_type_virion , FEATDEF_virion , "virion" } ,
188
{ Feature_type_n3clip , FEATDEF_3clip , "3clip" } ,
189
{ Feature_type_n3UTR , FEATDEF_3UTR , "3UTR" } ,
190
{ Feature_type_n5clip , FEATDEF_5clip , "5clip" } ,
191
{ Feature_type_n5UTR , FEATDEF_5UTR , "5UTR" } ,
192
{ Feature_type_n10_signal , FEATDEF_10_signal , "10_signal" } ,
193
{ Feature_type_n35_signal , FEATDEF_35_signal , "35_signal" } ,
194
{ Feature_type_site_ref , FEATDEF_site_ref , "site_ref" } ,
195
{ Feature_type_region , FEATDEF_REGION , "region" } ,
196
{ Feature_type_comment , FEATDEF_COMMENT , "comment" } ,
197
{ Feature_type_bond , FEATDEF_BOND , "bond" } ,
198
{ Feature_type_site , FEATDEF_SITE , "site" } ,
199
{ Feature_type_rsite , FEATDEF_RSITE , "rsite" } ,
200
{ Feature_type_user , FEATDEF_USER , "user" } ,
201
{ Feature_type_txinit , FEATDEF_TXINIT , "txinit" } ,
202
{ Feature_type_num , FEATDEF_NUM , "num" } ,
203
{ Feature_type_psec_str , FEATDEF_PSEC_STR , "psec_str" } ,
204
{ Feature_type_non_std_residue , FEATDEF_NON_STD_RESIDUE , "non_std_residue" } ,
205
{ Feature_type_het , FEATDEF_HET , "het" } ,
206
{ Feature_type_biosrc , FEATDEF_BIOSRC , "biosrc" } ,
207
{ Feature_type_preprotein , FEATDEF_preprotein , "preprotein" } ,
208
{ Feature_type_mat_peptide_aa , FEATDEF_mat_peptide_aa , "mat_peptide_aa" } ,
209
{ Feature_type_sig_peptide_aa , FEATDEF_sig_peptide_aa , "sig_peptide_aa" } ,
210
{ Feature_type_transit_peptide_aa , FEATDEF_transit_peptide_aa , "transit_peptide_aa" } ,
211
{ Feature_type_snoRNA , FEATDEF_snoRNA , "snoRNA" } ,
212
{ Feature_type_gap , FEATDEF_gap , "gap" } ,
213
{ Feature_type_operon , FEATDEF_operon , "operon" } ,
214
{ Feature_type_oriT , FEATDEF_oriT , "oriT" } ,
215
{ Feature_type_ncRNA , FEATDEF_ncRNA , "ncRNA" } ,
216
{ Feature_type_tmRNA , FEATDEF_tmRNA , "tmRNA" }};
218
#define NUM_feattype_featdef sizeof (feattype_featdef) / sizeof (FeatTypeFeatDefData)
220
NLM_EXTERN Int4 GetFeatdefFromFeatureType (Int4 feature_type)
224
for (i = 0; i < NUM_feattype_featdef; i++) {
225
if (feature_type == feattype_featdef[i].feattype) {
226
return feattype_featdef[i].featdef;
233
NLM_EXTERN CharPtr GetFeatureNameFromFeatureType (Int4 feature_type)
238
for (i = 0; i < NUM_feattype_featdef && str == NULL; i++) {
239
if (feature_type == feattype_featdef[i].feattype) {
240
str = feattype_featdef[feature_type].featname;
244
str = "Unknown feature type";
250
static Boolean Matchnamestring (CharPtr name1, CharPtr name2)
252
if (name1 == NULL && name2 == NULL) {
254
} else if (name1 == NULL || name2 == NULL) {
257
while (*name1 != 0 && *name2 != 0) {
258
while (*name1 == ' ' || *name1 == '-' || *name1 == '_') {
261
while (*name2 == ' ' || *name2 == '-' || *name2 == '_') {
264
if (*name1 != *name2) {
270
if (*name1 == 0 && *name2 == 0) {
279
NLM_EXTERN Int4 GetFeatureTypeByName (CharPtr feat_name)
283
for (i = 0; i < NUM_feattype_featdef; i++) {
284
if (Matchnamestring (feattype_featdef[i].featname, feat_name)) {
285
return feattype_featdef[i].feattype;
292
NLM_EXTERN void AddImportFeaturesToChoiceList (ValNodePtr PNTR feature_type_list)
296
ValNodePtr tmp_list = NULL;
298
for (i = 1; i < NUM_feattype_featdef; i++) {
299
if (feattype_featdef[i].feattype == Feature_type_gap) continue;
300
seqfeattype = FindFeatFromFeatDefType (feattype_featdef[i].featdef);
301
if (seqfeattype == SEQFEAT_IMP) {
302
featname = GetFeatureNameFromFeatureType (feattype_featdef[i].feattype);
303
if (featname != NULL) {
304
ValNodeAddPointer (&tmp_list, feattype_featdef[i].feattype, StringSave (featname));
308
tmp_list = ValNodeSort (tmp_list, SortVnpByString);
309
ValNodeLink (feature_type_list, tmp_list);
314
static Boolean IsMostUsedFeature (Uint1 val)
316
if (val == Feature_type_gene
317
|| val == Feature_type_cds
318
|| val == Feature_type_prot
319
|| val == Feature_type_exon
320
|| val == Feature_type_intron
321
|| val == Feature_type_mRNA
322
|| val == Feature_type_rRNA
323
|| val == Feature_type_otherRNA) {
331
static int LIBCALLBACK SortVnpByFeatureName (VoidPtr ptr1, VoidPtr ptr2)
338
Boolean most_used1, most_used2;
340
if (ptr1 != NULL && ptr2 != NULL) {
341
vnp1 = *((ValNodePtr PNTR) ptr1);
342
vnp2 = *((ValNodePtr PNTR) ptr2);
343
if (vnp1 != NULL && vnp2 != NULL) {
344
most_used1 = IsMostUsedFeature (vnp1->choice);
345
most_used2 = IsMostUsedFeature (vnp2->choice);
346
if (most_used1 && !most_used2) {
348
} else if (!most_used1 && most_used2) {
351
str1 = (CharPtr) vnp1->data.ptrvalue;
352
str2 = (CharPtr) vnp2->data.ptrvalue;
353
if (str1 != NULL && str2 != NULL) {
354
return StringICmp (str1, str2);
363
NLM_EXTERN void AddAllFeaturesToChoiceList (ValNodePtr PNTR feature_type_list)
367
ValNodePtr tmp_list = NULL;
369
for (i = 1; i < NUM_feattype_featdef; i++) {
370
if (feattype_featdef[i].feattype == Feature_type_gap) continue;
371
featname = GetFeatureNameFromFeatureType (feattype_featdef[i].feattype);
372
if (featname != NULL) {
373
ValNodeAddPointer (&tmp_list, feattype_featdef[i].feattype, StringSave (featname));
376
tmp_list = ValNodeSort (tmp_list, SortVnpByFeatureName);
377
ValNodeLink (feature_type_list, tmp_list);
381
typedef struct featqualgbqual {
385
} FeatQualGBQualData, PNTR FeatQualGBQualPtr;
387
static FeatQualGBQualData featqual_gbqual[] = {
388
{ Feat_qual_legal_allele , GBQUAL_allele , "allele" } ,
389
{ Feat_qual_legal_anticodon , GBQUAL_anticodon , "anticodon" } ,
390
{ Feat_qual_legal_bound_moiety , GBQUAL_bound_moiety , "bound-moiety" } ,
391
{ Feat_qual_legal_chromosome , GBQUAL_chromosome , "chromosome" } ,
392
{ Feat_qual_legal_citation , GBQUAL_citation , "citation" } ,
393
{ Feat_qual_legal_codon , GBQUAL_codon , "codon" } ,
394
{ Feat_qual_legal_codon_start , GBQUAL_codon_start , "codon-start" } ,
395
{ Feat_qual_legal_compare , GBQUAL_compare , "compare" } ,
396
{ Feat_qual_legal_cons_splice , GBQUAL_cons_splice , "cons-splice" } ,
397
{ Feat_qual_legal_db_xref , GBQUAL_db_xref , "db-xref" } ,
398
{ Feat_qual_legal_direction , GBQUAL_direction , "direction" } ,
399
{ Feat_qual_legal_environmental_sample , GBQUAL_environmental_sample , "environmental-sample" } ,
400
{ Feat_qual_legal_evidence , GBQUAL_evidence , "evidence" } ,
401
{ Feat_qual_legal_exception , GBQUAL_exception , "exception" } ,
402
{ Feat_qual_legal_experiment , GBQUAL_experiment , "experiment" } ,
403
{ Feat_qual_legal_focus , GBQUAL_focus , "focus" } ,
404
{ Feat_qual_legal_frequency , GBQUAL_frequency , "frequency" } ,
405
{ Feat_qual_legal_function , GBQUAL_function , "function" } ,
406
{ Feat_qual_legal_gene , GBQUAL_gene , "locus" } ,
407
{ Feat_qual_legal_inference , GBQUAL_inference , "inference" } ,
408
{ Feat_qual_legal_label , GBQUAL_label , "label" } ,
409
{ Feat_qual_legal_locus_tag , GBQUAL_locus_tag , "locus-tag" } ,
410
{ Feat_qual_legal_map , GBQUAL_map , "map" } ,
411
{ Feat_qual_legal_mobile_element , GBQUAL_mobile_element , "mobile-element" } ,
412
{ Feat_qual_legal_mod_base , GBQUAL_mod_base , "mod-base" } ,
413
{ Feat_qual_legal_mol_type , GBQUAL_mol_type , "mol-type" } ,
414
{ Feat_qual_legal_ncRNA_class , GBQUAL_ncRNA_class , "ncRNA-class" } ,
415
{ Feat_qual_legal_note , GBQUAL_note , "note" } ,
416
{ Feat_qual_legal_number , GBQUAL_number , "number" } ,
417
{ Feat_qual_legal_old_locus_tag , GBQUAL_old_locus_tag , "old-locus-tag" } ,
418
{ Feat_qual_legal_operon , GBQUAL_operon , "operon" } ,
419
{ Feat_qual_legal_organism , GBQUAL_organism , "organism" } ,
420
{ Feat_qual_legal_organelle , GBQUAL_organelle , "organelle" } ,
421
{ Feat_qual_legal_partial , GBQUAL_partial , "partial" } ,
422
{ Feat_qual_legal_phenotype , GBQUAL_phenotype , "phenotype" } ,
423
{ Feat_qual_legal_plasmid , GBQUAL_plasmid , "plasmid" } ,
424
{ Feat_qual_legal_product , GBQUAL_product , "product" } ,
425
{ Feat_qual_legal_protein_id , GBQUAL_protein_id , "protein-id" } ,
426
{ Feat_qual_legal_pseudo , GBQUAL_pseudo , "pseudo" } ,
427
{ Feat_qual_legal_rearranged , GBQUAL_rearranged , "rearranged" } ,
428
{ Feat_qual_legal_replace , GBQUAL_replace , "replace" } ,
429
{ Feat_qual_legal_rpt_family , GBQUAL_rpt_family , "rpt-family" } ,
430
{ Feat_qual_legal_rpt_type , GBQUAL_rpt_type , "rpt-type" } ,
431
{ Feat_qual_legal_rpt_unit , GBQUAL_rpt_unit , "rpt-unit" } ,
432
{ Feat_qual_legal_rpt_unit_seq , GBQUAL_rpt_unit_seq , "rpt-unit-seq" } ,
433
{ Feat_qual_legal_rpt_unit_range , GBQUAL_rpt_unit_range , "rpt-unit-range" } ,
434
{ Feat_qual_legal_segment , GBQUAL_segment , "segment" } ,
435
{ Feat_qual_legal_sequenced_mol , GBQUAL_sequenced_mol , "sequenced-mol" } ,
436
{ Feat_qual_legal_standard_name , GBQUAL_standard_name , "standard-name" } ,
437
{ Feat_qual_legal_transcript_id , GBQUAL_transcript_id , "transcript-id" } ,
438
{ Feat_qual_legal_transgenic , GBQUAL_transgenic , "transgenic" } ,
439
{ Feat_qual_legal_translation , GBQUAL_translation , "translation" } ,
440
{ Feat_qual_legal_transl_except , GBQUAL_transl_except , "transl-except" } ,
441
{ Feat_qual_legal_transl_table , GBQUAL_transl_table , "transl-table" } ,
442
{ Feat_qual_legal_usedin , GBQUAL_usedin , "usedin" } };
444
#define NUM_featqual_gbqual sizeof (featqual_gbqual) / sizeof (FeatQualGBQualData)
447
NLM_EXTERN Int4 GetNumFeatQual (void)
449
return NUM_featqual_gbqual;
453
static Int4 GetGBQualFromFeatQual (Int4 featqual)
457
for (i = 0; i < NUM_featqual_gbqual; i++) {
458
if (featqual == featqual_gbqual[i].featqual) {
459
return featqual_gbqual[i].gbqual;
466
NLM_EXTERN CharPtr GetFeatQualName (Int4 featqual)
470
for (i = 0; i < NUM_featqual_gbqual; i++) {
471
if (featqual == featqual_gbqual[i].featqual) {
472
return featqual_gbqual[i].qualname;
479
NLM_EXTERN Int4 GetFeatQualByName (CharPtr qualname)
483
for (i = 0; i < NUM_featqual_gbqual; i++) {
484
if (Matchnamestring (featqual_gbqual[i].qualname, qualname)) {
485
return featqual_gbqual[i].featqual;
492
NLM_EXTERN void AddAllFeatureFieldsToChoiceList (ValNodePtr PNTR field_list)
496
for (i = 1; i < NUM_featqual_gbqual; i++) {
497
ValNodeAddPointer (field_list, featqual_gbqual[i].featqual, StringSave (featqual_gbqual[i].qualname));
506
typedef struct srcqualscqual {
511
} SrcQualSCQualData, PNTR SrcQualSCQualPtr;
513
static SrcQualSCQualData srcqual_scqual[] = {
514
{ Source_qual_acronym , ORGMOD_acronym , IS_ORGMOD , "acronym" } ,
515
{ Source_qual_anamorph , ORGMOD_anamorph , IS_ORGMOD , "anamorph" } ,
516
{ Source_qual_authority , ORGMOD_authority , IS_ORGMOD , "authority" } ,
517
{ Source_qual_bio_material , ORGMOD_bio_material , IS_ORGMOD , "bio-material" } ,
518
{ Source_qual_biotype , ORGMOD_biotype , IS_ORGMOD , "biotype" } ,
519
{ Source_qual_biovar , ORGMOD_biovar , IS_ORGMOD , "biovar" } ,
520
{ Source_qual_breed , ORGMOD_breed , IS_ORGMOD , "breed" } ,
521
{ Source_qual_cell_line , SUBSRC_cell_line , IS_SUBSRC , "cell-line" } ,
522
{ Source_qual_cell_type , SUBSRC_cell_type , IS_SUBSRC , "cell-type" } ,
523
{ Source_qual_chemovar , ORGMOD_chemovar , IS_ORGMOD , "chemovar" } ,
524
{ Source_qual_chromosome , SUBSRC_chromosome , IS_SUBSRC , "chromosome" } ,
525
{ Source_qual_clone , SUBSRC_clone , IS_SUBSRC , "clone" } ,
526
{ Source_qual_clone_lib , SUBSRC_clone_lib , IS_SUBSRC , "clone-lib" } ,
527
{ Source_qual_collected_by , SUBSRC_collected_by , IS_SUBSRC , "collected-by" } ,
528
{ Source_qual_collection_date , SUBSRC_collection_date , IS_SUBSRC , "collection-date" } ,
529
{ Source_qual_common , ORGMOD_common , IS_ORGMOD , "common" } ,
530
{ Source_qual_common_name , 0 , IS_OTHER , "common name" } ,
531
{ Source_qual_country , SUBSRC_country , IS_SUBSRC , "country" } ,
532
{ Source_qual_cultivar , ORGMOD_cultivar , IS_ORGMOD , "cultivar" } ,
533
{ Source_qual_culture_collection , ORGMOD_culture_collection , IS_ORGMOD , "culture-collection" } ,
534
{ Source_qual_dev_stage , SUBSRC_dev_stage , IS_SUBSRC , "dev-stage" } ,
535
{ Source_qual_division , 0 , IS_OTHER, "divistion" } ,
536
{ Source_qual_dosage , ORGMOD_dosage , IS_ORGMOD , "dosage" } ,
537
{ Source_qual_ecotype , ORGMOD_ecotype , IS_ORGMOD , "ecotype" } ,
538
{ Source_qual_endogenous_virus_name , SUBSRC_endogenous_virus_name , IS_SUBSRC , "endogenous-virus-name" } ,
539
{ Source_qual_environmental_sample , SUBSRC_environmental_sample , IS_SUBSRC , "environmental-sample" } ,
540
{ Source_qual_forma , ORGMOD_forma , IS_ORGMOD , "forma" } ,
541
{ Source_qual_forma_specialis , ORGMOD_forma_specialis , IS_ORGMOD , "forma-specialis" } ,
542
{ Source_qual_frequency , SUBSRC_frequency , IS_SUBSRC , "frequency" } ,
543
{ Source_qual_fwd_primer_name , SUBSRC_fwd_primer_name , IS_SUBSRC , "fwd-primer-name" } ,
544
{ Source_qual_fwd_primer_seq , SUBSRC_fwd_primer_seq , IS_SUBSRC , "fwd-primer-seq" } ,
545
{ Source_qual_gb_acronym , ORGMOD_gb_acronym , IS_ORGMOD , "gb-acronym" } ,
546
{ Source_qual_gb_anamorph , ORGMOD_gb_anamorph , IS_ORGMOD , "gb-anamorph" } ,
547
{ Source_qual_gb_synonym , ORGMOD_gb_synonym , IS_ORGMOD , "gb-synonym" } ,
548
{ Source_qual_genotype , SUBSRC_genotype , IS_SUBSRC , "genotype" } ,
549
{ Source_qual_germline , SUBSRC_germline , IS_SUBSRC , "germline" } ,
550
{ Source_qual_group , ORGMOD_group , IS_ORGMOD , "group" } ,
551
{ Source_qual_haplotype , SUBSRC_haplotype , IS_SUBSRC , "haplotype" } ,
552
{ Source_qual_identified_by , SUBSRC_identified_by , IS_SUBSRC , "identified-by" } ,
553
{ Source_qual_insertion_seq_name , SUBSRC_insertion_seq_name , IS_SUBSRC , "insertion-seq-name" } ,
554
{ Source_qual_isolate , ORGMOD_isolate , IS_ORGMOD , "isolate" } ,
555
{ Source_qual_isolation_source , SUBSRC_isolation_source , IS_SUBSRC , "isolation-source" } ,
556
{ Source_qual_lab_host , SUBSRC_lab_host , IS_SUBSRC , "lab-host" } ,
557
{ Source_qual_lat_lon , SUBSRC_lat_lon , IS_SUBSRC , "lat-lon" } ,
558
{ Source_qual_lineage , 0, IS_OTHER, "lineage" } ,
559
{ Source_qual_map , SUBSRC_map , IS_SUBSRC , "map" } ,
560
{ Source_qual_metagenome_source , ORGMOD_metagenome_source , IS_ORGMOD , "metagenome-source" } ,
561
{ Source_qual_metagenomic , SUBSRC_metagenomic , IS_SUBSRC , "metagenomic" } ,
562
{ Source_qual_old_lineage , ORGMOD_old_lineage , IS_ORGMOD , "old-lineage" } ,
563
{ Source_qual_old_name , ORGMOD_old_name , IS_ORGMOD , "old-name" } ,
564
{ Source_qual_orgmod_note , ORGMOD_other, IS_ORGMOD, "orgmod note" } ,
565
{ Source_qual_nat_host , ORGMOD_nat_host , IS_ORGMOD , "nat-host" } ,
566
{ Source_qual_pathovar , ORGMOD_pathovar , IS_ORGMOD , "pathovar" } ,
567
{ Source_qual_plasmid_name , SUBSRC_plasmid_name , IS_SUBSRC , "plasmid-name" } ,
568
{ Source_qual_plastid_name , SUBSRC_plastid_name , IS_SUBSRC , "plastid-name" } ,
569
{ Source_qual_pop_variant , SUBSRC_pop_variant , IS_SUBSRC , "pop-variant" } ,
570
{ Source_qual_rearranged , SUBSRC_rearranged , IS_SUBSRC , "rearranged" } ,
571
{ Source_qual_rev_primer_name , SUBSRC_rev_primer_name , IS_SUBSRC , "rev-primer-name" } ,
572
{ Source_qual_rev_primer_seq , SUBSRC_rev_primer_seq , IS_SUBSRC , "rev-primer-seq" } ,
573
{ Source_qual_segment , SUBSRC_segment , IS_SUBSRC , "segment" } ,
574
{ Source_qual_serogroup , ORGMOD_serogroup , IS_ORGMOD , "serogroup" } ,
575
{ Source_qual_serotype , ORGMOD_serotype , IS_ORGMOD , "serotype" } ,
576
{ Source_qual_serovar , ORGMOD_serovar , IS_ORGMOD , "serovar" } ,
577
{ Source_qual_sex , SUBSRC_sex , IS_SUBSRC , "sex" } ,
578
{ Source_qual_specimen_voucher , ORGMOD_specimen_voucher , IS_ORGMOD , "specimen-voucher" } ,
579
{ Source_qual_strain , ORGMOD_strain , IS_ORGMOD , "strain" } ,
580
{ Source_qual_subclone , SUBSRC_subclone , IS_SUBSRC , "subclone" } ,
581
{ Source_qual_subgroup , ORGMOD_subgroup , IS_ORGMOD , "subgroup" } ,
582
{ Source_qual_subsource_note , SUBSRC_other , IS_SUBSRC , "subsource note" } ,
583
{ Source_qual_sub_species , ORGMOD_sub_species , IS_ORGMOD , "sub-species" } ,
584
{ Source_qual_substrain , ORGMOD_substrain , IS_ORGMOD , "substrain" } ,
585
{ Source_qual_subtype , ORGMOD_subtype , IS_ORGMOD , "subtype" } ,
586
{ Source_qual_synonym , ORGMOD_synonym , IS_ORGMOD , "synonym" } ,
587
{ Source_qual_taxname , 0 , IS_OTHER , "taxname" } ,
588
{ Source_qual_teleomorph , ORGMOD_teleomorph , IS_ORGMOD , "teleomorph" } ,
589
{ Source_qual_tissue_lib , SUBSRC_tissue_lib , IS_SUBSRC , "tissue-lib" } ,
590
{ Source_qual_tissue_type , SUBSRC_tissue_type , IS_SUBSRC , "tissue-type" } ,
591
{ Source_qual_transgenic , SUBSRC_transgenic , IS_SUBSRC , "transgenic" } ,
592
{ Source_qual_transposon_name , SUBSRC_transposon_name , IS_SUBSRC , "transposon-name" } ,
593
{ Source_qual_type , ORGMOD_type , IS_ORGMOD , "type" } ,
594
{ Source_qual_variety , ORGMOD_variety , IS_ORGMOD , "variety" } };
596
#define NUM_srcqual_scqual sizeof (srcqual_scqual) / sizeof (SrcQualSCQualData)
598
static Int4 GetSubSrcQualFromSrcQual (Int4 srcqual)
602
for (i = 0; i < NUM_srcqual_scqual; i++) {
603
if (srcqual == srcqual_scqual[i].srcqual) {
604
if (srcqual_scqual[i].typeflag == IS_SUBSRC) {
605
return srcqual_scqual[i].subtype;
615
static Int4 GetOrgModQualFromSrcQual (Int4 srcqual)
619
for (i = 0; i < NUM_srcqual_scqual; i++) {
620
if (srcqual == srcqual_scqual[i].srcqual) {
621
if (srcqual_scqual[i].typeflag == IS_ORGMOD) {
622
return srcqual_scqual[i].subtype;
632
NLM_EXTERN Boolean IsNonTextSourceQual (Int4 srcqual)
634
if (srcqual == Source_qual_transgenic
635
|| srcqual == Source_qual_germline
636
|| srcqual == Source_qual_metagenomic
637
|| srcqual == Source_qual_environmental_sample
638
|| srcqual == Source_qual_rearranged)
649
NLM_EXTERN CharPtr GetSourceQualName (Int4 srcqual)
654
for (i = 0; i < NUM_srcqual_scqual && str == NULL; i++) {
655
if (srcqual_scqual[i].srcqual == srcqual) {
656
str = srcqual_scqual[i].qualname;
660
str = "Unknown source qualifier";
666
NLM_EXTERN Int4 GetSourceQualTypeByName (CharPtr qualname)
670
for (i = 0; i < NUM_srcqual_scqual; i++) {
671
if (Matchnamestring(srcqual_scqual[i].qualname, qualname)) {
672
return srcqual_scqual[i].srcqual;
679
NLM_EXTERN ValNodePtr GetSourceQualList (void)
681
ValNodePtr list = NULL;
684
for (i = 0; i < NUM_srcqual_scqual; i++) {
685
ValNodeAddPointer (&list, 0, StringSave (srcqual_scqual[i].qualname));
690
typedef struct srclocgenome {
694
} SrcLocGenomeData, PNTR SrcLocGenomePtr;
696
static SrcLocGenomeData srcloc_genome[] = {
697
{ Source_location_unknown , GENOME_unknown , "unknown" } ,
698
{ Source_location_genomic , GENOME_genomic , "genomic" } ,
699
{ Source_location_chloroplast , GENOME_chloroplast , "chloroplast" } ,
700
{ Source_location_chromoplast , GENOME_chromoplast , "chromoplast" } ,
701
{ Source_location_kinetoplast , GENOME_kinetoplast , "kinetoplast" } ,
702
{ Source_location_mitochondrion , GENOME_mitochondrion , "mitochondrion" } ,
703
{ Source_location_plastid , GENOME_plastid , "plastid" } ,
704
{ Source_location_macronuclear , GENOME_macronuclear , "macronuclear" } ,
705
{ Source_location_extrachrom , GENOME_extrachrom , "extrachrom" } ,
706
{ Source_location_plasmid , GENOME_plasmid , "plasmid" } ,
707
{ Source_location_transposon , GENOME_transposon , "transposon" } ,
708
{ Source_location_insertion_seq , GENOME_insertion_seq , "insertion-seq" } ,
709
{ Source_location_cyanelle , GENOME_cyanelle , "cyanelle" } ,
710
{ Source_location_proviral , GENOME_proviral , "proviral" } ,
711
{ Source_location_virion , GENOME_virion , "virion" } ,
712
{ Source_location_nucleomorph , GENOME_nucleomorph , "nucleomorph" } ,
713
{ Source_location_apicoplast , GENOME_apicoplast , "apicoplast" } ,
714
{ Source_location_leucoplast , GENOME_leucoplast , "leucoplast" } ,
715
{ Source_location_proplastid , GENOME_proplastid , "proplastid" } ,
716
{ Source_location_endogenous_virus , GENOME_endogenous_virus , "endogenous-virus" } ,
717
{ Source_location_hydrogenosome , GENOME_hydrogenosome , "hydrogenosome" } ,
718
{ Source_location_chromosome , 21 , "chromosome" } ,
719
{ Source_location_chromatophore , 22 , "chromatophore" } };
721
#define NUM_srcloc_genome sizeof (srcloc_genome) / sizeof (SrcLocGenomeData)
723
NLM_EXTERN Int4 GenomeFromSrcLoc (Int4 srcloc) \
727
for (i = 0; i < NUM_srcloc_genome; i++) {
728
if (srcloc_genome[i].srcloc == srcloc) {
729
return srcloc_genome[i].genome;
736
NLM_EXTERN CharPtr LocNameFromGenome (Int4 genome)
740
for (i = 0; i < NUM_srcloc_genome; i++) {
741
if (srcloc_genome[i].genome == genome) {
742
return srcloc_genome[i].name;
749
static Int4 GenomeFromLocName (CharPtr loc_name)
753
for (i = 0; i < NUM_srcloc_genome; i++) {
754
if (StringICmp (srcloc_genome[i].name, loc_name) == 0) {
755
return srcloc_genome[i].genome;
762
NLM_EXTERN ValNodePtr GetLocationList (Boolean for_remove)
764
ValNodePtr list = NULL;
767
for (i = 0; i < NUM_srcloc_genome; i++) {
768
if (for_remove && srcloc_genome[i].srcloc == Source_location_unknown) {
769
ValNodeAddPointer (&list, srcloc_genome[i].srcloc, StringSave ("any"));
771
ValNodeAddPointer (&list, srcloc_genome[i].srcloc, StringSave (srcloc_genome[i].name));
778
typedef struct srcorigorigin {
782
} SrcOrigOriginData, PNTR SrcrigOriginPtr;
784
static SrcOrigOriginData srcorig_origin[] = {
785
{ Source_origin_unknown , 0 , "unknown" } ,
786
{ Source_origin_natural , 1 , "natural" } ,
787
{ Source_origin_natmut , 2 , "natmut" } ,
788
{ Source_origin_mut , 3 , "mut" } ,
789
{ Source_origin_artificial , 4 , "artificial" } ,
790
{ Source_origin_synthetic , 5 , "synthetic" } ,
791
{ Source_origin_other , 255 , "other" } };
793
#define NUM_srcorig_origin sizeof (srcorig_origin) / sizeof (SrcOrigOriginData)
795
NLM_EXTERN Int4 OriginFromSrcOrig (Int4 srcorig)
799
for (i = 0; i < NUM_srcorig_origin; i++) {
800
if (srcorig_origin[i].srcorig == srcorig) {
801
return srcorig_origin[i].origin;
808
NLM_EXTERN CharPtr OriginNameFromOrigin (Int4 origin)
812
for (i = 0; i < NUM_srcorig_origin; i++) {
813
if (srcorig_origin[i].origin == origin) {
814
return srcorig_origin[i].name;
821
static Int4 OriginFromOriginName (CharPtr origin_name)
825
for (i = 0; i < NUM_srcorig_origin; i++) {
826
if (StringCmp (srcorig_origin[i].name, origin_name) == 0) {
827
return srcorig_origin[i].origin;
834
NLM_EXTERN ValNodePtr GetOriginList (Boolean for_remove)
836
ValNodePtr list = NULL;
839
for (i = 0; i < NUM_srcorig_origin; i++) {
840
if (for_remove && srcorig_origin[i].srcorig == Source_origin_unknown) {
841
ValNodeAddPointer (&list, srcorig_origin[i].srcorig, StringSave ("any"));
843
ValNodeAddPointer (&list, srcorig_origin[i].srcorig, StringSave (srcorig_origin[i].name));
850
typedef struct cdsgeneprotfieldname {
853
} CDSGeneProtFieldNameData, PNTR CDSGeneProtFieldNamePtr;
855
static CDSGeneProtFieldNameData cdsgeneprotfield_name[] = {
856
{ CDSGeneProt_field_cds_comment , "CDS comment" } ,
857
{ CDSGeneProt_field_gene_locus , "gene locus" } ,
858
{ CDSGeneProt_field_gene_description , "gene description" } ,
859
{ CDSGeneProt_field_gene_comment , "gene comment" } ,
860
{ CDSGeneProt_field_gene_allele , "allele" } ,
861
{ CDSGeneProt_field_gene_maploc , "maploc" } ,
862
{ CDSGeneProt_field_gene_locus_tag , "locus tag" } ,
863
{ CDSGeneProt_field_gene_synonym , "synonym" } ,
864
{ CDSGeneProt_field_gene_old_locus_tag , "old locus tag" } ,
865
{ CDSGeneProt_field_mrna_product , "mRNA product" } ,
866
{ CDSGeneProt_field_mrna_comment , "mRNA comment" } ,
867
{ CDSGeneProt_field_prot_name , "protein name" } ,
868
{ CDSGeneProt_field_prot_description , "protein description" } ,
869
{ CDSGeneProt_field_prot_ec_number , "protein EC number" } ,
870
{ CDSGeneProt_field_prot_activity , "protein activity" } ,
871
{ CDSGeneProt_field_prot_comment , "protein comment" } ,
872
{ CDSGeneProt_field_mat_peptide_name , "mat-peptide name" } ,
873
{ CDSGeneProt_field_mat_peptide_description , "mat-peptide description" } ,
874
{ CDSGeneProt_field_mat_peptide_ec_number , "mat-peptide EC number" } ,
875
{ CDSGeneProt_field_mat_peptide_activity , "mat-peptide activity" } ,
876
{ CDSGeneProt_field_mat_peptide_comment , "mat-peptide comment" } };
878
#define NUM_cdsgeneprotfield_name sizeof (cdsgeneprotfield_name) / sizeof (CDSGeneProtFieldNameData)
880
NLM_EXTERN CharPtr CDSGeneProtNameFromField (Int4 field)
884
for (i = 0; i < NUM_cdsgeneprotfield_name; i++) {
885
if (cdsgeneprotfield_name[i].field == field) {
886
return cdsgeneprotfield_name[i].name;
893
NLM_EXTERN void AddAllCDSGeneProtFieldsToChoiceList (ValNodePtr PNTR field_list)
897
for (i = 0; i < NUM_cdsgeneprotfield_name; i++) {
898
ValNodeAddPointer (field_list, cdsgeneprotfield_name[i].field, StringSave (cdsgeneprotfield_name[i].name));
903
typedef struct cdsgeneprotfeatname {
906
} CDSGeneProtFeatNameData, PNTR CDSGeneProtFeatNamePtr;
908
static CDSGeneProtFeatNameData cdsgeneprotfeat_name[] = {
909
{ CDSGeneProt_feature_type_constraint_gene , "gene" } ,
910
{ CDSGeneProt_feature_type_constraint_mRNA , "mRNA" } ,
911
{ CDSGeneProt_feature_type_constraint_cds , "CDS" } ,
912
{ CDSGeneProt_feature_type_constraint_prot , "protein" } ,
913
{ CDSGeneProt_feature_type_constraint_mat_peptide , "mat-peptide" }};
915
#define NUM_cdsgeneprotfeat_name sizeof (cdsgeneprotfeat_name) / sizeof (CDSGeneProtFeatNameData)
917
NLM_EXTERN CharPtr CDSGeneProtFeatureNameFromFeatureType (Int4 feature_type)
921
for (i = 0; i < NUM_cdsgeneprotfeat_name; i++) {
922
if (cdsgeneprotfeat_name[i].feature_type == feature_type) {
923
return cdsgeneprotfeat_name[i].name;
930
NLM_EXTERN void AddAllCDSGeneProtFeaturesToChoiceList (ValNodePtr PNTR field_list)
934
for (i = 0; i < NUM_cdsgeneprotfeat_name; i++) {
935
ValNodeAddPointer (field_list, cdsgeneprotfeat_name[i].feature_type, StringSave (cdsgeneprotfeat_name[i].name));
940
NLM_EXTERN FeatureFieldPtr FeatureFieldFromCDSGeneProtField (Uint2 cds_gene_prot_field)
942
FeatureFieldPtr f = NULL;
944
switch (cds_gene_prot_field) {
945
case CDSGeneProt_field_cds_comment:
946
f = FeatureFieldNew ();
947
f->type = Feature_type_cds;
948
f->field = ValNodeNew (NULL);
949
f->field->choice = FeatQualChoice_legal_qual;
950
f->field->data.intvalue = Feat_qual_legal_note;
952
case CDSGeneProt_field_gene_locus:
953
f = FeatureFieldNew ();
954
f->type = Feature_type_gene;
955
f->field = ValNodeNew (NULL);
956
f->field->choice = FeatQualChoice_legal_qual;
957
f->field->data.intvalue = Feat_qual_legal_gene;
959
case CDSGeneProt_field_gene_description:
960
f = FeatureFieldNew ();
961
f->type = Feature_type_gene;
962
f->field = ValNodeNew (NULL);
963
f->field->choice = FeatQualChoice_legal_qual;
964
f->field->data.intvalue = Feat_qual_legal_gene_description;
966
case CDSGeneProt_field_gene_comment:
967
f = FeatureFieldNew ();
968
f->type = Feature_type_gene;
969
f->field = ValNodeNew (NULL);
970
f->field->choice = FeatQualChoice_legal_qual;
971
f->field->data.intvalue = Feat_qual_legal_note;
973
case CDSGeneProt_field_gene_allele:
974
f = FeatureFieldNew ();
975
f->type = Feature_type_gene;
976
f->field = ValNodeNew (NULL);
977
f->field->choice = FeatQualChoice_legal_qual;
978
f->field->data.intvalue = Feat_qual_legal_allele;
980
case CDSGeneProt_field_gene_maploc:
981
f = FeatureFieldNew ();
982
f->type = Feature_type_gene;
983
f->field = ValNodeNew (NULL);
984
f->field->choice = FeatQualChoice_legal_qual;
985
f->field->data.intvalue = Feat_qual_legal_map;
987
case CDSGeneProt_field_gene_locus_tag:
988
f = FeatureFieldNew ();
989
f->type = Feature_type_gene;
990
f->field = ValNodeNew (NULL);
991
f->field->choice = FeatQualChoice_legal_qual;
992
f->field->data.intvalue = Feat_qual_legal_locus_tag;
994
case CDSGeneProt_field_gene_synonym:
995
f = FeatureFieldNew ();
996
f->type = Feature_type_gene;
997
f->field = ValNodeNew (NULL);
998
f->field->choice = FeatQualChoice_legal_qual;
999
f->field->data.intvalue = Feat_qual_legal_synonym;
1001
case CDSGeneProt_field_gene_old_locus_tag:
1002
f = FeatureFieldNew ();
1003
f->type = Feature_type_gene;
1004
f->field = ValNodeNew (NULL);
1005
f->field->choice = FeatQualChoice_legal_qual;
1006
f->field->data.intvalue = Feat_qual_legal_old_locus_tag;
1008
case CDSGeneProt_field_mrna_product:
1009
f = FeatureFieldNew ();
1010
f->type = Feature_type_mRNA;
1011
f->field = ValNodeNew (NULL);
1012
f->field->choice = FeatQualChoice_legal_qual;
1013
f->field->data.intvalue = Feat_qual_legal_product;
1015
case CDSGeneProt_field_mrna_comment:
1016
f = FeatureFieldNew ();
1017
f->type = Feature_type_mRNA;
1018
f->field = ValNodeNew (NULL);
1019
f->field->choice = FeatQualChoice_legal_qual;
1020
f->field->data.intvalue = Feat_qual_legal_note;
1022
case CDSGeneProt_field_prot_name:
1023
f = FeatureFieldNew ();
1024
f->type = Feature_type_prot;
1025
f->field = ValNodeNew (NULL);
1026
f->field->choice = FeatQualChoice_legal_qual;
1027
f->field->data.intvalue = Feat_qual_legal_product;
1029
case CDSGeneProt_field_prot_description:
1030
f = FeatureFieldNew ();
1031
f->type = Feature_type_prot;
1032
f->field = ValNodeNew (NULL);
1033
f->field->choice = FeatQualChoice_legal_qual;
1034
f->field->data.intvalue = Feat_qual_legal_description;
1036
case CDSGeneProt_field_prot_ec_number:
1037
f = FeatureFieldNew ();
1038
f->type = Feature_type_prot;
1039
f->field = ValNodeNew (NULL);
1040
f->field->choice = FeatQualChoice_legal_qual;
1041
f->field->data.intvalue = Feat_qual_legal_ec_number;
1043
case CDSGeneProt_field_prot_activity:
1044
f = FeatureFieldNew ();
1045
f->type = Feature_type_prot;
1046
f->field = ValNodeNew (NULL);
1047
f->field->choice = FeatQualChoice_legal_qual;
1048
f->field->data.intvalue = Feat_qual_legal_activity;
1050
case CDSGeneProt_field_prot_comment:
1051
f = FeatureFieldNew ();
1052
f->type = Feature_type_prot;
1053
f->field = ValNodeNew (NULL);
1054
f->field->choice = FeatQualChoice_legal_qual;
1055
f->field->data.intvalue = Feat_qual_legal_note;
1057
case CDSGeneProt_field_mat_peptide_name:
1058
f = FeatureFieldNew ();
1059
f->type = Feature_type_mat_peptide;
1060
f->field = ValNodeNew (NULL);
1061
f->field->choice = FeatQualChoice_legal_qual;
1062
f->field->data.intvalue = Feat_qual_legal_product;
1064
case CDSGeneProt_field_mat_peptide_description:
1065
f = FeatureFieldNew ();
1066
f->type = Feature_type_mat_peptide;
1067
f->field = ValNodeNew (NULL);
1068
f->field->choice = FeatQualChoice_legal_qual;
1069
f->field->data.intvalue = Feat_qual_legal_description;
1071
case CDSGeneProt_field_mat_peptide_ec_number:
1072
f = FeatureFieldNew ();
1073
f->type = Feature_type_mat_peptide;
1074
f->field = ValNodeNew (NULL);
1075
f->field->choice = FeatQualChoice_legal_qual;
1076
f->field->data.intvalue = Feat_qual_legal_ec_number;
1078
case CDSGeneProt_field_mat_peptide_activity:
1079
f = FeatureFieldNew ();
1080
f->type = Feature_type_mat_peptide;
1081
f->field = ValNodeNew (NULL);
1082
f->field->choice = FeatQualChoice_legal_qual;
1083
f->field->data.intvalue = Feat_qual_legal_activity;
1085
case CDSGeneProt_field_mat_peptide_comment:
1086
f = FeatureFieldNew ();
1087
f->type = Feature_type_mat_peptide;
1088
f->field = ValNodeNew (NULL);
1089
f->field->choice = FeatQualChoice_legal_qual;
1090
f->field->data.intvalue = Feat_qual_legal_note;
1097
/* Molinfo fields */
1098
typedef struct moleculetypebiomol {
1102
} MoleculeTypeBiomolData, PNTR MoleculeTypeBiomolPtr;
1104
static MoleculeTypeBiomolData moleculetype_biomol[] = {
1105
{ Molecule_type_unknown , 0, "unknown" } ,
1106
{ Molecule_type_genomic , MOLECULE_TYPE_GENOMIC , "genomic" } ,
1107
{ Molecule_type_precursor_RNA , MOLECULE_TYPE_PRE_MRNA , "precursor RNA" } ,
1108
{ Molecule_type_mRNA , MOLECULE_TYPE_MRNA , "mRNA" } ,
1109
{ Molecule_type_rRNA , MOLECULE_TYPE_RRNA , "rRNA" } ,
1110
{ Molecule_type_tRNA , MOLECULE_TYPE_TRNA , "tRNA" } ,
1111
{ Molecule_type_snRNA , MOLECULE_TYPE_SNRNA , "snRNA" } ,
1112
{ Molecule_type_scRNA , MOLECULE_TYPE_SCRNA , "scRNA" } ,
1113
{ Molecule_type_genomic_mRNA , MOLECULE_TYPE_GENOMIC_MRNA_MIX , "genomic mRNA" } ,
1114
{ Molecule_type_cRNA , MOLECULE_TYPE_CRNA , "cRNA" } ,
1115
{ Molecule_type_scRNA , MOLECULE_TYPE_SCRNA , "scRNA" } ,
1116
{ Molecule_type_scRNA , MOLECULE_TYPE_SCRNA , "scRNA" } ,
1117
{ Molecule_type_scRNA , MOLECULE_TYPE_SCRNA , "scRNA" } ,
1118
{ Molecule_type_snoRNA , MOLECULE_TYPE_SNORNA, "snoRNA" } ,
1119
{ Molecule_type_transcribed_RNA, MOLECULE_TYPE_TRANSCRIBED_RNA, "transcribed RNA" } ,
1120
{ Molecule_type_ncRNA, MOLECULE_TYPE_NCRNA, "ncRNA" } ,
1121
{ Molecule_type_transfer_messenger_RNA, MOLECULE_TYPE_TMRNA, "tmRNA" } ,
1122
{ Molecule_type_other, MOLECULE_TYPE_OTHER_GENETIC_MATERIAL, "other" }
1126
#define NUM_moleculetype_biomol sizeof (moleculetype_biomol) / sizeof (MoleculeTypeBiomolData)
1128
NLM_EXTERN Int4 BiomolFromMoleculeType (Int4 molecule_type)
1132
for (i = 0; i < NUM_moleculetype_biomol; i++) {
1133
if (moleculetype_biomol[i].molecule_type == molecule_type) {
1134
return moleculetype_biomol[i].biomol;
1141
NLM_EXTERN CharPtr BiomolNameFromBiomol (Int4 biomol)
1145
for (i = 0; i < NUM_moleculetype_biomol; i++) {
1146
if (moleculetype_biomol[i].biomol == biomol) {
1147
return moleculetype_biomol[i].name;
1154
static Int4 BiomolFromBiomolName (CharPtr biomol_name)
1158
for (i = 0; i < NUM_moleculetype_biomol; i++) {
1159
if (StringCmp (moleculetype_biomol[i].name, biomol_name) == 0) {
1160
return moleculetype_biomol[i].biomol;
1167
NLM_EXTERN ValNodePtr GetMoleculeTypeList (void)
1169
ValNodePtr list = NULL;
1172
for (i = 0; i < NUM_moleculetype_biomol; i++) {
1173
ValNodeAddPointer (&list, moleculetype_biomol[i].molecule_type, StringSave (moleculetype_biomol[i].name));
1179
/* Technique fields */
1180
typedef struct techniquetypetech {
1181
Int4 technique_type;
1184
} TechniqueTypeTechData, PNTR TechniqueTypeTechPtr;
1186
static TechniqueTypeTechData techniquetype_tech[] = {
1187
{ Technique_type_unknown , MI_TECH_unknown , "unknown" } ,
1188
{ Technique_type_standard , MI_TECH_standard , "standard" } ,
1189
{ Technique_type_est , MI_TECH_est , "EST" } ,
1190
{ Technique_type_sts , MI_TECH_sts , "STS" } ,
1191
{ Technique_type_survey , MI_TECH_survey , "survey" } ,
1192
{ Technique_type_genetic_map , MI_TECH_genemap , "genetic map" } ,
1193
{ Technique_type_physical_map , MI_TECH_physmap , "physical map" } ,
1194
{ Technique_type_derived , MI_TECH_derived , "derived" } ,
1195
{ Technique_type_concept_trans , MI_TECH_concept_trans , "concept-trans" } ,
1196
{ Technique_type_seq_pept , MI_TECH_seq_pept , "seq-pept" } ,
1197
{ Technique_type_both , MI_TECH_both , "both" } ,
1198
{ Technique_type_seq_pept_overlap , MI_TECH_seq_pept_overlap , "seq-pept-overlap" } ,
1199
{ Technique_type_seq_pept_homol , MI_TECH_seq_pept_homol, "seq-pept-homol" } ,
1200
{ Technique_type_concept_trans_a, MI_TECH_concept_trans_a, "concept-trans-a" } ,
1201
{ Technique_type_htgs_1, MI_TECH_htgs_1, "HTGS-1" } ,
1202
{ Technique_type_htgs_2, MI_TECH_htgs_2, "HTGS-2" } ,
1203
{ Technique_type_htgs_3, MI_TECH_htgs_3, "HTGS-3" } ,
1204
{ Technique_type_fli_cDNA, MI_TECH_fli_cdna, "fli-cDNA" } ,
1205
{ Technique_type_htgs_0, MI_TECH_htgs_0, "HTGS-0" } ,
1206
{ Technique_type_htc, MI_TECH_htc, "HTC" } ,
1207
{ Technique_type_wgs, MI_TECH_wgs, "WGS" } ,
1208
{ Technique_type_barcode, MI_TECH_barcode, "BARCODE" } ,
1209
{ Technique_type_composite_wgs_htgs, MI_TECH_composite_wgs_htgs, "composite WGS-HTGS" } ,
1210
{ Technique_type_tsa, MI_TECH_tsa, "TSA" } ,
1211
{ Technique_type_other, MI_TECH_other, "other" }
1215
#define NUM_techniquetype_tech sizeof (techniquetype_tech) / sizeof (TechniqueTypeTechData)
1217
NLM_EXTERN Int4 TechFromTechniqueType (Int4 technique_type)
1221
for (i = 0; i < NUM_techniquetype_tech; i++) {
1222
if (techniquetype_tech[i].technique_type == technique_type) {
1223
return techniquetype_tech[i].tech;
1230
NLM_EXTERN CharPtr TechNameFromTech (Int4 tech)
1234
for (i = 0; i < NUM_techniquetype_tech; i++) {
1235
if (techniquetype_tech[i].tech == tech) {
1236
return techniquetype_tech[i].name;
1243
static Int4 TechFromTechName (CharPtr tech_name)
1247
for (i = 0; i < NUM_techniquetype_tech; i++) {
1248
if (StringCmp (techniquetype_tech[i].name, tech_name) == 0) {
1249
return techniquetype_tech[i].tech;
1256
NLM_EXTERN ValNodePtr GetTechniqueTypeList (void)
1258
ValNodePtr list = NULL;
1261
for (i = 0; i < NUM_techniquetype_tech; i++) {
1262
ValNodeAddPointer (&list, techniquetype_tech[i].technique_type, StringSave (techniquetype_tech[i].name));
1268
/* Completedness fields */
1269
typedef struct completednesstypecompleteness {
1270
Int4 completedness_type;
1273
} CompletednessTypeCompletenessData, PNTR CompletednessTypeCompletenessPtr;
1275
static CompletednessTypeCompletenessData completednesstype_completeness[] = {
1276
{ Completedness_type_unknown, 0, "unknown" } ,
1277
{ Completedness_type_complete, 1, "complete" } ,
1278
{ Completedness_type_partial, 2, "partial" } ,
1279
{ Completedness_type_no_left, 3, "no left" } ,
1280
{ Completedness_type_no_right, 4, "no right" } ,
1281
{ Completedness_type_no_ends, 5, "no ends" } ,
1282
{ Completedness_type_has_left, 6, "has left" } ,
1283
{ Completedness_type_has_right, 7, "has right" } ,
1284
{ Completedness_type_other, 255, "other" }
1287
#define NUM_completednesstype_completeness sizeof (completednesstype_completeness) / sizeof (CompletednessTypeCompletenessData)
1289
NLM_EXTERN Int4 CompletenessFromCompletednessType (Int4 completedness_type)
1293
for (i = 0; i < NUM_completednesstype_completeness; i++) {
1294
if (completednesstype_completeness[i].completedness_type == completedness_type) {
1295
return completednesstype_completeness[i].completeness;
1302
NLM_EXTERN CharPtr CompletenessNameFromCompleteness (Int4 completeness)
1306
for (i = 0; i < NUM_completednesstype_completeness; i++) {
1307
if (completednesstype_completeness[i].completeness == completeness) {
1308
return completednesstype_completeness[i].name;
1315
static Int4 CompletenessFromCompletenessName (CharPtr completeness_name)
1319
for (i = 0; i < NUM_completednesstype_completeness; i++) {
1320
if (StringCmp (completednesstype_completeness[i].name, completeness_name) == 0) {
1321
return completednesstype_completeness[i].completeness;
1328
NLM_EXTERN ValNodePtr GetCompletednessTypeList (void)
1330
ValNodePtr list = NULL;
1333
for (i = 0; i < NUM_completednesstype_completeness; i++) {
1334
ValNodeAddPointer (&list, completednesstype_completeness[i].completedness_type, StringSave (completednesstype_completeness[i].name));
1340
/* Molecule class fields */
1341
typedef struct moleculeclasstypemol {
1342
Int4 moleculeclass_type;
1345
} MoleculeClassTypeMolData, PNTR MoleculeClassTypeMolPtr;
1347
static MoleculeClassTypeMolData moleculeclasstype_mol[] = {
1348
{ Molecule_class_type_unknown, 0, "unknown" } ,
1349
{ Molecule_class_type_dna, MOLECULE_CLASS_DNA, "DNA" } ,
1350
{ Molecule_class_type_rna, MOLECULE_CLASS_RNA, "RNA" } ,
1351
{ Molecule_class_type_protein, MOLECULE_CLASS_PROTEIN, "protein" } ,
1352
{ Molecule_class_type_nucleotide, MOLECULE_CLASS_NUC, "nucleotide" } ,
1353
{ Molecule_class_type_other, 255, "other" }
1357
#define NUM_moleculeclasstype_mol sizeof (moleculeclasstype_mol) / sizeof (MoleculeClassTypeMolData)
1359
NLM_EXTERN Int4 MolFromMoleculeClassType (Int4 moleculeclass_type)
1363
for (i = 0; i < NUM_moleculeclasstype_mol; i++) {
1364
if (moleculeclasstype_mol[i].moleculeclass_type == moleculeclass_type) {
1365
return moleculeclasstype_mol[i].mol;
1372
NLM_EXTERN CharPtr MolNameFromMol (Int4 mol)
1376
for (i = 0; i < NUM_moleculeclasstype_mol; i++) {
1377
if (moleculeclasstype_mol[i].mol == mol) {
1378
return moleculeclasstype_mol[i].name;
1385
static Int4 MolFromMolName (CharPtr mol_name)
1389
for (i = 0; i < NUM_moleculeclasstype_mol; i++) {
1390
if (StringCmp (moleculeclasstype_mol[i].name, mol_name) == 0) {
1391
return moleculeclasstype_mol[i].mol;
1398
NLM_EXTERN ValNodePtr GetMoleculeClassTypeList (void)
1400
ValNodePtr list = NULL;
1403
for (i = 0; i < NUM_moleculeclasstype_mol; i++) {
1404
ValNodeAddPointer (&list, moleculeclasstype_mol[i].moleculeclass_type, StringSave (moleculeclasstype_mol[i].name));
1410
/* Topology fields */
1411
typedef struct topologytypetopology {
1415
} TopologyTypeTopologyData, PNTR TopologyTypeTopologyPtr;
1417
static TopologyTypeTopologyData topologytype_topology[] = {
1418
{ Topology_type_unknown, 0, "unknown" } ,
1419
{ Topology_type_linear, TOPOLOGY_LINEAR, "linear" } ,
1420
{ Topology_type_circular, TOPOLOGY_CIRCULAR, "circular" } ,
1421
{ Topology_type_tandem, TOPOLOGY_TANDEM, "tandem" } ,
1422
{ Topology_type_other, 255, "other" }
1425
#define NUM_topologytype_topology sizeof (topologytype_topology) / sizeof (TopologyTypeTopologyData)
1427
NLM_EXTERN Int4 TopologyFromTopologyType (Int4 topology_type)
1431
for (i = 0; i < NUM_topologytype_topology; i++) {
1432
if (topologytype_topology[i].topology_type == topology_type) {
1433
return topologytype_topology[i].topology;
1440
NLM_EXTERN CharPtr TopologyNameFromTopology (Int4 topology)
1444
for (i = 0; i < NUM_topologytype_topology; i++) {
1445
if (topologytype_topology[i].topology == topology) {
1446
return topologytype_topology[i].name;
1453
static Int4 TopologyFromTopologyName (CharPtr topology_name)
1457
for (i = 0; i < NUM_topologytype_topology; i++) {
1458
if (StringCmp (topologytype_topology[i].name, topology_name) == 0) {
1459
return topologytype_topology[i].topology;
1466
NLM_EXTERN ValNodePtr GetTopologyTypeList (void)
1468
ValNodePtr list = NULL;
1471
for (i = 0; i < NUM_topologytype_topology; i++) {
1472
ValNodeAddPointer (&list, topologytype_topology[i].topology_type, StringSave (topologytype_topology[i].name));
1479
typedef struct strandtypestrand {
1483
} StrandTypeStrandData, PNTR StrandTypeStrandPtr;
1485
static StrandTypeStrandData strandtype_strand[] = {
1486
{ Strand_type_unknown, 0, "unknown" } ,
1487
{ Strand_type_single, STRANDEDNESS_SINGLE, "single" } ,
1488
{ Strand_type_double__, STRANDEDNESS_DOUBLE, "double" } ,
1489
{ Strand_type_mixed, 3, "mixed" } ,
1490
{ Strand_type_mixed_rev, 4, "mixed-rev" } ,
1491
{ Strand_type_other, 255, "other" }
1494
#define NUM_strandtype_strand sizeof (strandtype_strand) / sizeof (StrandTypeStrandData)
1496
NLM_EXTERN Int4 StrandFromStrandType (Int4 strand_type)
1500
for (i = 0; i < NUM_strandtype_strand; i++) {
1501
if (strandtype_strand[i].strand_type == strand_type) {
1502
return strandtype_strand[i].strand;
1509
NLM_EXTERN CharPtr StrandNameFromStrand (Int4 strand)
1513
for (i = 0; i < NUM_strandtype_strand; i++) {
1514
if (strandtype_strand[i].strand == strand) {
1515
return strandtype_strand[i].name;
1522
static Int4 StrandFromStrandName (CharPtr strand_name)
1526
for (i = 0; i < NUM_strandtype_strand; i++) {
1527
if (StringCmp (strandtype_strand[i].name, strand_name) == 0) {
1528
return strandtype_strand[i].strand;
1535
NLM_EXTERN ValNodePtr GetStrandTypeList (void)
1537
ValNodePtr list = NULL;
1540
for (i = 0; i < NUM_strandtype_strand; i++) {
1541
ValNodeAddPointer (&list, strandtype_strand[i].strand_type, StringSave (strandtype_strand[i].name));
1547
static CharPtr GetSequenceQualValName (ValNodePtr field)
1551
if (field == NULL) return NULL;
1552
switch (field->choice) {
1553
case MolinfoField_molecule:
1554
val = BiomolNameFromBiomol (BiomolFromMoleculeType (field->data.intvalue));
1556
case MolinfoField_technique:
1557
val = TechNameFromTech (TechFromTechniqueType (field->data.intvalue));
1559
case MolinfoField_completedness:
1560
val = CompletenessNameFromCompleteness (CompletenessFromCompletednessType (field->data.intvalue));
1562
case MolinfoField_mol_class:
1563
val = MolNameFromMol (MolFromMoleculeClassType (field->data.intvalue));
1565
case MolinfoField_topology:
1566
val = TopologyNameFromTopology (TopologyFromTopologyType (field->data.intvalue));
1568
case MolinfoField_strand:
1569
val = StrandNameFromStrand (StrandFromStrandType (field->data.intvalue));
1576
static CharPtr GetSequenceQualName (ValNodePtr field)
1578
CharPtr str = NULL, fieldname = "invalid field", val = "invalid value";
1579
CharPtr fmt = "%s %s";
1581
if (field == NULL) return NULL;
1582
switch (field->choice) {
1583
case MolinfoField_molecule:
1584
fieldname = "molecule";
1585
val = BiomolNameFromBiomol (BiomolFromMoleculeType (field->data.intvalue));
1587
case MolinfoField_technique:
1588
fieldname = "technique";
1589
val = TechNameFromTech (TechFromTechniqueType (field->data.intvalue));
1591
case MolinfoField_completedness:
1592
fieldname = "completeness";
1593
val = CompletenessNameFromCompleteness (CompletenessFromCompletednessType (field->data.intvalue));
1595
case MolinfoField_mol_class:
1596
fieldname = "class";
1597
val = MolNameFromMol (MolFromMoleculeClassType (field->data.intvalue));
1599
case MolinfoField_topology:
1600
fieldname = "topology";
1601
val = TopologyNameFromTopology (TopologyFromTopologyType (field->data.intvalue));
1603
case MolinfoField_strand:
1604
fieldname = "strand";
1605
val = StrandNameFromStrand (StrandFromStrandType (field->data.intvalue));
1609
val = "Invalid value";
1611
str = (CharPtr) MemNew (sizeof (Char) * (StringLen (fmt) + StringLen (fieldname) + StringLen (val)));
1612
sprintf (str, fmt, fieldname, val);
1617
/* Simple constraints */
1618
static Boolean IsWholeWordMatch (CharPtr start, CharPtr found, Int4 match_len)
1620
Boolean rval = TRUE;
1628
else if (start == NULL || found == NULL)
1634
char_after = *(found + match_len);
1637
char_before = *(found - 1);
1638
if (isalpha ((Int4) char_before) || isdigit ((Int4) char_before))
1643
if (char_after != 0 && (isalpha ((Int4) char_after) || isdigit ((Int4)char_after)))
1652
NLM_EXTERN Boolean IsStringConstraintEmpty (StringConstraintPtr scp)
1654
if (scp == NULL || StringHasNoText (scp->match_text)) return TRUE;
1659
NLM_EXTERN Boolean DoesSingleStringMatchConstraint (CharPtr str, StringConstraintPtr scp)
1662
Boolean rval = FALSE;
1663
Char char_after = 0;
1665
if (IsStringConstraintEmpty (scp)) return TRUE;
1666
if (StringHasNoText (str)) return FALSE;
1668
switch (scp->match_location)
1670
case String_location_contains:
1671
if (scp->case_sensitive)
1673
pFound = StringSearch (str, scp->match_text);
1677
pFound = StringISearch (str, scp->match_text);
1683
else if (scp->whole_word)
1685
rval = IsWholeWordMatch (str, pFound, StringLen (scp->match_text));
1686
while (!rval && pFound != NULL)
1688
if (scp->case_sensitive)
1690
pFound = StringSearch (pFound + 1, scp->match_text);
1694
pFound = StringISearch (pFound + 1, scp->match_text);
1698
rval = IsWholeWordMatch (str, pFound, StringLen (scp->match_text));
1707
case String_location_starts:
1708
if (scp->case_sensitive)
1710
pFound = StringSearch (str, scp->match_text);
1714
pFound = StringISearch (str, scp->match_text);
1718
if (scp->whole_word)
1720
rval = IsWholeWordMatch (str, pFound, StringLen (scp->match_text));
1728
case String_location_ends:
1729
if (scp->case_sensitive)
1731
pFound = StringSearch (str, scp->match_text);
1735
pFound = StringISearch (str, scp->match_text);
1737
while (pFound != NULL && !rval) {
1738
char_after = *(pFound + StringLen (scp->match_text));
1739
if (char_after == 0)
1741
if (scp->whole_word)
1743
rval = IsWholeWordMatch (str, pFound, StringLen (scp->match_text));
1749
/* stop the search, we're at the end of the string */
1754
if (scp->case_sensitive)
1756
pFound = StringSearch (pFound + 1, scp->match_text);
1760
pFound = StringISearch (pFound + 1, scp->match_text);
1765
case String_location_equals:
1766
if (scp->case_sensitive)
1768
if (StringCmp (str, scp->match_text) == 0)
1775
if (StringICmp (str, scp->match_text) == 0)
1781
case String_location_inlist:
1782
if (scp->case_sensitive)
1784
pFound = StringSearch (scp->match_text, str);
1788
pFound = StringISearch (scp->match_text, str);
1796
rval = IsWholeWordMatch (scp->match_text, pFound, StringLen (str));
1797
while (!rval && pFound != NULL)
1799
if (scp->case_sensitive)
1801
pFound = StringSearch (pFound + 1, str);
1805
pFound = StringISearch (pFound + 1, str);
1809
rval = IsWholeWordMatch (scp->match_text, pFound, StringLen (str));
1814
/* look for spans */
1815
rval = IsStringInSpanInList (str, scp->match_text);
1823
NLM_EXTERN Boolean DoesStringMatchConstraint (CharPtr str, StringConstraintPtr scp)
1827
rval = DoesSingleStringMatchConstraint (str, scp);
1828
if (scp != NULL && scp->not_present) {
1835
static Boolean DoesStringListMatchConstraint (ValNodePtr list, StringConstraintPtr scp)
1839
Boolean rval = FALSE;
1842
if (IsStringConstraintEmpty (scp)) {
1845
if (list == NULL) return FALSE;
1847
for (vnp = list; vnp != NULL; vnp = vnp->next) {
1848
len += StringLen (vnp->data.ptrvalue) + 2;
1851
tmp = (CharPtr) MemNew (sizeof (Char) * len);
1852
for (vnp = list; vnp != NULL; vnp = vnp->next) {
1853
StringCat (tmp, vnp->data.ptrvalue);
1854
if (vnp->next != NULL) {
1855
StringCat (tmp, "; ");
1859
rval = DoesStringMatchConstraint (tmp, scp);
1860
tmp = MemFree (tmp);
1865
static Boolean DoesStrandMatchConstraint (SeqLocPtr slp, LocationConstraintPtr lcp)
1868
Boolean rval = FALSE;
1874
else if (lcp == NULL || lcp->strand == Strand_constraint_any)
1880
strand = SeqLocStrand (slp);
1881
if (strand == Seq_strand_minus)
1883
if (lcp->strand == Strand_constraint_minus)
1894
if (lcp->strand == Strand_constraint_plus)
1908
static Boolean DoesBioseqMatchSequenceType (BioseqPtr bsp, Uint2 seq_type)
1910
Boolean rval = FALSE;
1912
if (bsp == NULL) return FALSE;
1913
if (seq_type == Seqtype_constraint_any) return TRUE;
1915
if (ISA_na (bsp->mol) && seq_type == Seqtype_constraint_nuc)
1919
else if (ISA_aa (bsp->mol) && seq_type == Seqtype_constraint_prot)
1927
static Boolean DoesSequenceTypeMatchContraint (SeqLocPtr slp, LocationConstraintPtr lcp)
1929
Boolean rval = FALSE;
1936
else if (lcp == NULL || lcp->seq_type == Seqtype_constraint_any)
1942
bsp = BioseqFindFromSeqLoc (slp);
1943
rval = DoesBioseqMatchSequenceType (bsp, lcp->seq_type);
1948
static Boolean DoesLocationMatchConstraint (SeqLocPtr slp, LocationConstraintPtr lcp)
1951
Boolean rval = FALSE;
1957
else if (lcp == NULL || (DoesStrandMatchConstraint (slp, lcp) && DoesSequenceTypeMatchContraint (slp, lcp)))
1965
static Boolean DoesObjectMatchLocationConstraint (Uint1 choice, Pointer data, LocationConstraintPtr constraint)
1970
BioseqPtr bsp = NULL;
1974
SeqMgrFeatContext context;
1976
if (data == NULL) return FALSE;
1978
if (constraint == NULL
1979
|| (constraint->strand == Strand_constraint_any
1980
&& constraint->seq_type == Seqtype_constraint_any)) {
1984
if (choice == OBJ_SEQFEAT) {
1985
sfp = (SeqFeatPtr) data;
1986
bsp = BioseqFindFromSeqLoc (sfp->location);
1987
} else if (choice == OBJ_SEQDESC) {
1988
sdp = (SeqDescrPtr) data;
1989
if (sdp->extended != 0) {
1990
ovp = (ObjValNodePtr) sdp;
1991
if (ovp->idx.parenttype == OBJ_BIOSEQSET) {
1992
bssp = (BioseqSetPtr) ovp->idx.parentptr;
1993
if (bssp != NULL && bssp->seq_set != NULL && IS_Bioseq_set (bssp->seq_set)) {
1994
bsp = (BioseqPtr) bssp->seq_set->data.ptrvalue;
1996
} else if (ovp->idx.parenttype == OBJ_BIOSEQ) {
1997
bsp = (BioseqPtr) ovp->idx.parentptr;
2000
} else if (choice == 0) {
2001
if (constraint->seq_type != Seqtype_constraint_any) {
2004
cgp = (CGPSetPtr) data;
2005
if (cgp->cds_list != NULL && cgp->cds_list->data.ptrvalue != NULL) {
2006
sfp = (SeqFeatPtr) cgp->cds_list->data.ptrvalue;
2007
bsp = BioseqFindFromSeqLoc (sfp->location);
2008
} else if (cgp->gene_list != NULL && cgp->gene_list->data.ptrvalue != NULL) {
2009
sfp = (SeqFeatPtr) cgp->gene_list->data.ptrvalue;
2010
bsp = BioseqFindFromSeqLoc (sfp->location);
2011
} else if (cgp->mrna_list != NULL && cgp->mrna_list->data.ptrvalue != NULL) {
2012
sfp = (SeqFeatPtr) cgp->mrna_list->data.ptrvalue;
2013
bsp = BioseqFindFromSeqLoc (sfp->location);
2014
} else if (cgp->prot_list != NULL && cgp->prot_list->data.ptrvalue != NULL) {
2015
sfp = (SeqFeatPtr) cgp->prot_list->data.ptrvalue;
2016
bsp = BioseqFindFromSeqLoc (sfp->location);
2019
if (!DoesBioseqMatchSequenceType(bsp, constraint->seq_type)) {
2022
if (constraint->strand != Strand_constraint_any && ISA_aa (bsp->mol)) {
2023
sfp = SeqMgrGetCDSgivenProduct (bsp, &context);
2024
if (constraint->strand == Strand_constraint_minus && context.strand != Seq_strand_minus) {
2027
if (constraint->strand == Strand_constraint_plus && context.strand == Seq_strand_minus) {
2030
} else if (constraint->strand != Strand_constraint_any) {
2032
/* strand for CDS-Gene-Prot group */
2033
cgp = (CGPSetPtr) data;
2034
for (vnp = cgp->cds_list; vnp != NULL; vnp = vnp->next) {
2035
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
2036
if (sfp != NULL && !DoesStrandMatchConstraint (sfp->location, constraint)) {
2040
for (vnp = cgp->gene_list; vnp != NULL; vnp = vnp->next) {
2041
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
2042
if (sfp != NULL && !DoesStrandMatchConstraint (sfp->location, constraint)) {
2046
for (vnp = cgp->mrna_list; vnp != NULL; vnp = vnp->next) {
2047
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
2048
if (sfp != NULL && !DoesStrandMatchConstraint (sfp->location, constraint)) {
2052
} else if (choice == OBJ_SEQFEAT) {
2053
sfp = (SeqFeatPtr) data;
2054
if (!DoesStrandMatchConstraint (sfp->location, constraint)) {
2058
/* descriptors can't meet strand constraints */
2066
/* for parsing and editing */
2067
static CharPtr GetTextPortionFromString (CharPtr str, TextPortionPtr text_portion)
2069
CharPtr portion = NULL;
2070
CharPtr found_start, found_end;
2073
if (StringHasNoText (str)) {
2076
if (text_portion == NULL) {
2077
return StringSave (str);
2080
if (text_portion->left_text == NULL || text_portion->left_text [0] == 0)
2086
if (text_portion->case_sensitive)
2088
found_start = StringSearch (str, text_portion->left_text);
2092
found_start = StringISearch (str, text_portion->left_text);
2095
if (text_portion->whole_word && ! IsWholeWordMatch (str, found_start, StringLen (text_portion->left_text)))
2101
if (found_start == NULL)
2106
if (!text_portion->include_left)
2108
found_start += StringLen (text_portion->left_text);
2111
if (text_portion->right_text == NULL || text_portion->right_text [0] == 0)
2113
found_len = StringLen (found_start);
2117
if (text_portion->case_sensitive)
2119
found_end = StringSearch (found_start, text_portion->right_text);
2123
found_end = StringISearch (found_start, text_portion->right_text);
2125
if (text_portion->whole_word && ! IsWholeWordMatch (str, found_end, StringLen (text_portion->right_text)))
2130
if (found_end == NULL)
2134
else if (text_portion->include_right)
2136
found_len = (Int4)(found_end - found_start) + StringLen (text_portion->right_text);
2140
found_len = found_end - found_start;
2146
portion = (CharPtr) MemNew (sizeof (Char) * (found_len + 1));
2147
StringNCpy (portion, found_start, found_len);
2148
portion[found_len] = 0;
2155
static CharPtr FindTextPortionLocationInString (CharPtr str, TextPortionPtr text_portion)
2157
CharPtr start, stop;
2159
if (str == NULL || text_portion == NULL) return FALSE;
2161
if (text_portion->left_text != NULL) {
2162
start = StringSearch (str, text_portion->left_text);
2163
if (start != NULL) {
2164
if (!text_portion->include_left) {
2165
start += StringLen (text_portion->left_text);
2171
if (start != NULL) {
2172
if (text_portion->right_text != NULL) {
2173
stop = StringSearch (start, text_portion->right_text);
2183
static void ReplaceStringForParse(CharPtr src_text, TextPortionPtr text_portion)
2187
if (src_text == NULL || text_portion == NULL) {
2191
dst = FindTextPortionLocationInString (src_text, text_portion);
2192
if (dst == NULL) return;
2193
if (text_portion->right_text == NULL) {
2196
src = StringSearch (src_text, text_portion->right_text);
2198
if (text_portion->include_right) {
2199
src += StringLen (text_portion->right_text);
2212
/* generic functions for getting string values */
2213
static Int4 GetDbtagStringLen (DbtagPtr db_tag)
2222
len = StringLen (db_tag->db) + 2;
2223
if (db_tag->tag != NULL)
2225
if (db_tag->tag->str != NULL)
2227
len += StringLen (db_tag->tag->str);
2238
static CharPtr GetDbtagString (DbtagPtr db_tag)
2243
if (db_tag == NULL) {
2247
len = GetDbtagStringLen (db_tag);
2252
str = (CharPtr) MemNew (len * sizeof (Char));
2254
StringCpy (str, db_tag->db);
2255
StringCat (str, ":");
2256
if (db_tag->tag != NULL) {
2257
if (db_tag->tag->str != NULL) {
2258
StringCat (str, db_tag->tag->str);
2260
sprintf (str + StringLen (str), "%d", db_tag->tag->id);
2268
/* generic functions for setting field values */
2269
static Boolean SetStringValue (CharPtr PNTR existing_val, CharPtr new_val, Uint2 existing_text)
2271
Boolean rval = FALSE;
2275
if (existing_val == NULL) {
2279
if (StringHasNoText (*existing_val)) {
2280
*existing_val = MemFree (*existing_val);
2281
*existing_val = StringSave (new_val);
2284
switch (existing_text) {
2285
case ExistingTextOption_replace_old :
2286
*existing_val = MemFree (*existing_val);
2287
*existing_val = StringSave (new_val);
2290
case ExistingTextOption_append_semi :
2291
len = StringLen (new_val) + StringLen (*existing_val) + 3;
2292
tmp = (CharPtr) MemNew (sizeof (Char) * len);
2294
sprintf (tmp, "%s; %s", *existing_val, new_val);
2295
MemFree (*existing_val);
2296
*existing_val = tmp;
2300
case ExistingTextOption_append_space :
2301
len = StringLen (new_val) + StringLen (*existing_val) + 2;
2302
tmp = (CharPtr) MemNew (sizeof (Char) * len);
2304
sprintf (tmp, "%s %s", *existing_val, new_val);
2305
MemFree (*existing_val);
2306
*existing_val = tmp;
2310
case ExistingTextOption_append_colon :
2311
len = StringLen (new_val) + StringLen (*existing_val) + 3;
2312
tmp = (CharPtr) MemNew (sizeof (Char) * len);
2314
sprintf (tmp, "%s: %s", *existing_val, new_val);
2315
MemFree (*existing_val);
2316
*existing_val = tmp;
2320
case ExistingTextOption_append_none :
2321
len = StringLen (new_val) + StringLen (*existing_val) + 1;
2322
tmp = (CharPtr) MemNew (sizeof (Char) * len);
2324
sprintf (tmp, "%s%s", *existing_val, new_val);
2325
MemFree (*existing_val);
2326
*existing_val = tmp;
2330
case ExistingTextOption_prefix_semi :
2331
len = StringLen (new_val) + StringLen (*existing_val) + 3;
2332
tmp = (CharPtr) MemNew (sizeof (Char) * len);
2334
sprintf (tmp, "%s; %s", new_val, *existing_val);
2335
MemFree (*existing_val);
2336
*existing_val = tmp;
2340
case ExistingTextOption_prefix_space :
2341
len = StringLen (new_val) + StringLen (*existing_val) + 2;
2342
tmp = (CharPtr) MemNew (sizeof (Char) * len);
2344
sprintf (tmp, "%s %s", new_val, *existing_val);
2345
MemFree (*existing_val);
2346
*existing_val = tmp;
2350
case ExistingTextOption_prefix_colon :
2351
len = StringLen (new_val) + StringLen (*existing_val) + 3;
2352
tmp = (CharPtr) MemNew (sizeof (Char) * len);
2354
sprintf (tmp, "%s: %s", new_val, *existing_val);
2355
MemFree (*existing_val);
2356
*existing_val = tmp;
2360
case ExistingTextOption_prefix_none :
2361
len = StringLen (new_val) + StringLen (*existing_val) + 1;
2362
tmp = (CharPtr) MemNew (sizeof (Char) * len);
2364
sprintf (tmp, "%s%s", new_val, *existing_val);
2365
MemFree (*existing_val);
2366
*existing_val = tmp;
2370
case ExistingTextOption_leave_old :
2378
static Boolean SetStringsInValNodeStringList (ValNodePtr PNTR list, StringConstraintPtr scp, CharPtr new_val, Uint2 existing_text)
2382
Boolean rval = FALSE;
2389
if (*list == NULL && (scp == NULL || StringHasNoText (scp->match_text))) {
2390
ValNodeAddPointer (list, 0, StringSave (new_val));
2392
} else if (existing_text == ExistingTextOption_append_semi) {
2393
if (DoesStringListMatchConstraint (*list, scp)) {
2394
ValNodeAddPointer (list, 0, StringSave (new_val));
2397
} else if (existing_text == ExistingTextOption_prefix_semi) {
2398
if (DoesStringListMatchConstraint (*list, scp)) {
2399
vnp = ValNodeNew (NULL);
2400
vnp->data.ptrvalue = StringSave (new_val);
2405
} else if (existing_text == ExistingTextOption_replace_old) {
2406
if (DoesStringListMatchConstraint (*list, scp)) {
2407
*list = ValNodeFreeData (*list);
2408
vnp = ValNodeNew (NULL);
2409
vnp->data.ptrvalue = StringSave (new_val);
2413
} else if (existing_text == ExistingTextOption_leave_old) {
2416
for (vnp = *list; vnp != NULL; vnp = vnp->next)
2418
cp = (CharPtr) vnp->data.ptrvalue;
2419
if (DoesStringMatchConstraint (cp, scp)) {
2420
rval |= SetStringValue (&cp, new_val, existing_text);
2421
vnp->data.ptrvalue = cp;
2429
static Boolean SetStringInGBQualList (GBQualPtr PNTR list, ValNodePtr field, StringConstraintPtr scp, CharPtr new_val, Uint2 existing_text)
2431
Boolean rval = FALSE;
2433
CharPtr qual_name = NULL;
2434
GBQualPtr gbq, last_gbq = NULL;
2436
if (field == NULL) return FALSE;
2438
if (field->choice == FeatQualChoice_legal_qual)
2440
gbqual = GetGBQualFromFeatQual (field->data.intvalue);
2442
qual_name = ParFlat_GBQual_names [gbqual].name;
2443
for (gbq = *list; gbq != NULL; gbq = gbq->next) {
2444
if (StringCmp (gbq->qual, qual_name) == 0
2445
&& DoesStringMatchConstraint (gbq->val, scp)) {
2446
rval |= SetStringValue (&(gbq->val), new_val, existing_text);
2450
if (!rval && (scp == NULL || scp->match_text == NULL)) {
2452
gbq->qual = StringSave (qual_name);
2453
gbq->val = StringSave (new_val);
2454
if (last_gbq == NULL) {
2457
last_gbq->next = gbq;
2462
} else if (field->choice == FeatQualChoice_illegal_qual) {
2463
for (gbq = *list; gbq != NULL; gbq = gbq->next) {
2464
if (DoesStringMatchConstraint (gbq->qual, field->data.ptrvalue)
2465
&& DoesStringMatchConstraint (gbq->val, scp)) {
2466
rval |= SetStringValue (&(gbq->val), new_val, existing_text);
2475
static Boolean IsAllDigits (CharPtr str)
2479
if (StringHasNoText (str)) return FALSE;
2482
while (*cp != 0 && isdigit (*cp)) {
2493
static Boolean SetObjectIdString (ObjectIdPtr oip, CharPtr value, Uint2 existing_text)
2495
Boolean rval = FALSE;
2504
sprintf (num, "%d", oip->id);
2505
tmp = StringSave (num);
2507
tmp = StringSaveNoNull (oip->str);
2509
if (SetStringValue (&tmp, value, existing_text)) {
2510
oip->str = MemFree (oip->str);
2512
if (IsAllDigits (tmp)) {
2513
oip->id = atoi (tmp);
2520
tmp = MemFree (tmp);
2525
static Boolean SetDbtagString (DbtagPtr db_tag, CharPtr value, Uint2 existing_text)
2527
Boolean rval = FALSE;
2533
if (db_tag == NULL || StringHasNoText (value)) {
2537
cp = StringChr (value, ':');
2539
tmp = StringSave (db_tag->db);
2540
if (SetStringValue (&tmp, value, existing_text)) {
2541
dbxvalid = IsDbxrefValid (tmp, NULL, NULL, TRUE, NULL);
2542
if (dbxvalid != 0) {
2543
db_tag->db = MemFree (db_tag->db);
2550
if (db_tag->tag == NULL) {
2551
db_tag->tag = ObjectIdNew();
2553
rval = SetObjectIdString (db_tag->tag, value, existing_text);
2555
tmp = MemFree (tmp);
2557
twoval = StringSave (value);
2558
cp = StringChr (twoval, ':');
2561
rval = SetStringValue (&(db_tag->db), twoval, existing_text);
2562
if (db_tag->tag == NULL) {
2563
db_tag->tag = ObjectIdNew ();
2565
rval |= SetObjectIdString (db_tag->tag, cp, existing_text);
2566
twoval = MemFree (twoval);
2572
static Boolean SetDbxrefString (SeqFeatPtr sfp, StringConstraintPtr scp, CharPtr value, Uint2 existing_text)
2575
Boolean rval = FALSE, skip;
2583
if ((sfp->dbxref == NULL || existing_text == ExistingTextOption_append_semi) && (scp == NULL || StringHasNoText (scp->match_text))) {
2584
dbtag = DbtagNew ();
2585
rval = SetDbtagString (dbtag, value, existing_text);
2587
ValNodeAddPointer (&(sfp->dbxref), 0, dbtag);
2589
dbtag = DbtagFree (dbtag);
2592
for (vnp = sfp->dbxref; vnp != NULL; vnp = vnp->next) {
2595
cp = GetDbtagString (vnp->data.ptrvalue);
2596
if (!DoesStringMatchConstraint (cp, scp)) {
2602
rval |= SetDbtagString (vnp->data.ptrvalue, value, existing_text);
2611
static CharPtr GetFirstValNodeStringMatch (ValNodePtr vnp, StringConstraintPtr scp)
2614
while (vnp != NULL && str == NULL) {
2615
if (!StringHasNoText (vnp->data.ptrvalue)
2616
&& DoesStringMatchConstraint (vnp->data.ptrvalue, scp)) {
2617
str = StringSave (vnp->data.ptrvalue);
2625
static Boolean RemoveValNodeStringMatch (ValNodePtr PNTR list, StringConstraintPtr scp)
2627
ValNodePtr vnp_prev = NULL, vnp_next, vnp;
2628
Boolean rval = FALSE;
2630
if (list == NULL) return FALSE;
2632
while (vnp != NULL) {
2633
vnp_next = vnp->next;
2634
if (!StringHasNoText (vnp->data.ptrvalue)
2635
&& DoesStringMatchConstraint (vnp->data.ptrvalue, scp)) {
2636
if (vnp_prev == NULL) {
2639
vnp_prev->next = vnp->next;
2642
vnp = ValNodeFreeData (vnp);
2653
static CharPtr GetFirstGBQualMatch (GBQualPtr qual, CharPtr qual_name, StringConstraintPtr scp)
2656
while (qual != NULL && str == NULL) {
2657
if (StringICmp (qual->qual, qual_name) == 0
2658
&&!StringHasNoText (qual->val)
2659
&& DoesStringMatchConstraint (qual->val, scp)) {
2660
str = StringSave (qual->val);
2668
static CharPtr GetFirstGBQualMatchConstraintName (GBQualPtr qual, StringConstraintPtr qual_name, StringConstraintPtr scp)
2671
while (qual != NULL && str == NULL) {
2672
if (DoesStringMatchConstraint (qual->qual, qual_name)
2673
&&!StringHasNoText (qual->val)
2674
&& DoesStringMatchConstraint (qual->val, scp)) {
2675
str = StringSave (qual->val);
2683
static Boolean RemoveGBQualMatch (GBQualPtr PNTR list, CharPtr qual_name, StringConstraintPtr scp)
2685
GBQualPtr qual_prev = NULL, qual_next, qual;
2686
Boolean rval = FALSE;
2688
if (list == NULL) return FALSE;
2690
while (qual != NULL) {
2691
qual_next = qual->next;
2692
if (StringICmp (qual->qual, qual_name) == 0
2693
&& !StringHasNoText (qual->val)
2694
&& DoesStringMatchConstraint (qual->val, scp)) {
2695
if (qual_prev == NULL) {
2698
qual_prev->next = qual->next;
2701
qual = GBQualFree (qual);
2712
static Boolean RemoveGBQualMatchConstraintName (GBQualPtr PNTR list, StringConstraintPtr qual_name, StringConstraintPtr scp)
2714
GBQualPtr qual_prev = NULL, qual_next, qual;
2715
Boolean rval = FALSE;
2717
if (list == NULL) return FALSE;
2719
while (qual != NULL) {
2720
qual_next = qual->next;
2721
if (DoesStringMatchConstraint (qual->qual, qual_name)
2722
&& !StringHasNoText (qual->val)
2723
&& DoesStringMatchConstraint (qual->val, scp)) {
2724
if (qual_prev == NULL) {
2727
qual_prev->next = qual->next;
2730
qual = GBQualFree (qual);
2741
static CharPtr GetDbxrefString (SeqFeatPtr sfp, StringConstraintPtr scp)
2745
CharPtr str = NULL, cp;
2747
if (sfp == NULL || sfp->dbxref == NULL) {
2751
for (vnp = sfp->dbxref; vnp != NULL; vnp = vnp->next) {
2752
cp = GetDbtagString (vnp->data.ptrvalue);
2753
if (cp != NULL && DoesStringMatchConstraint(cp, scp)) {
2754
len += StringLen (cp) + 1;
2763
str = (CharPtr) MemNew ((len + 1) * sizeof (Char));
2765
for (vnp = sfp->dbxref; vnp != NULL; vnp = vnp->next) {
2766
cp = GetDbtagString (vnp->data.ptrvalue);
2767
if (cp != NULL && DoesStringMatchConstraint(cp, scp)) {
2768
StringCat (str, cp);
2769
StringCat (str, ";");
2774
if (StringLen (str) >1) {
2775
/* remove final semicolon */
2776
str [StringLen (str) - 2] = 0;
2782
static Boolean RemoveDbxrefString (SeqFeatPtr sfp, StringConstraintPtr scp)
2784
ValNodePtr vnp, vnp_prev = NULL, vnp_next;
2786
Boolean rval = FALSE;
2788
if (sfp == NULL || sfp->dbxref == NULL) {
2793
while (vnp != NULL) {
2794
vnp_next = vnp->next;
2795
cp = GetDbtagString (vnp->data.ptrvalue);
2796
if (DoesStringMatchConstraint(cp, scp)) {
2797
if (vnp_prev == NULL) {
2798
sfp->dbxref = vnp->next;
2800
vnp_prev->next = vnp->next;
2803
vnp->data.ptrvalue = DbtagFree (vnp->data.ptrvalue);
2804
vnp = ValNodeFree (vnp);
2814
static CharPtr GetRNAProductString (SeqFeatPtr sfp, StringConstraintPtr scp)
2817
SeqMgrFeatContext context;
2820
if (sfp == NULL || sfp->data.choice != SEQFEAT_RNA || sfp->data.value.ptrvalue == NULL) {
2824
rrp = sfp->data.value.ptrvalue;
2825
if (rrp->ext.choice == 0
2826
|| (rrp->ext.choice == 1 && StringHasNoText (rrp->ext.value.ptrvalue))
2827
|| (rrp->ext.choice == 1
2828
&& (StringCmp (rrp->ext.value.ptrvalue, "ncRNA") == 0
2829
|| StringCmp (rrp->ext.value.ptrvalue, "tmRNA") == 0
2830
|| StringCmp (rrp->ext.value.ptrvalue, "misc_RNA") == 0))) {
2831
str = GetFirstGBQualMatch (sfp->qual, "product", scp);
2835
if (rrp->ext.choice == 1 && !StringHasNoText (rrp->ext.value.ptrvalue)
2836
&& StringCmp (rrp->ext.value.ptrvalue, "ncRNA") != 0
2837
&& StringCmp (rrp->ext.value.ptrvalue, "tmRNA") != 0
2838
&& StringCmp (rrp->ext.value.ptrvalue, "misc_RNA") != 0) {
2839
str = StringSave (rrp->ext.value.ptrvalue);
2840
} else if (rrp->ext.choice == 2 && rrp->ext.value.ptrvalue != NULL) {
2841
if (SeqMgrGetDesiredFeature (sfp->idx.entityID, NULL, 0, 0, sfp, &context) != NULL
2842
&& !StringHasNoText (context.label)
2843
&& StringCmp (context.label, "tRNA") != 0) {
2844
str = (CharPtr) MemNew (sizeof (Char) + (StringLen (context.label) + 6));
2845
sprintf (str, "tRNA-%s", context.label);
2848
if (!DoesStringMatchConstraint(str, scp)) {
2849
str = MemFree (str);
2856
static Boolean IsParseabletRNAName (CharPtr name_string)
2858
if (StringHasNoText(name_string))
2862
else if (StringNICmp (name_string, "trna-", 5) != 0)
2866
else if (StringLen (name_string) != 8)
2870
else if (ParseTRnaString (name_string, NULL, NULL, TRUE) == 0)
2881
static Boolean SetRNAProductString (SeqFeatPtr sfp, StringConstraintPtr scp, CharPtr new_val, Uint2 existing_text)
2884
Boolean rval = FALSE;
2888
Boolean justTrnaText = FALSE;
2891
if (sfp == NULL || sfp->data.choice != SEQFEAT_RNA || sfp->data.value.ptrvalue == NULL) {
2895
rrp = sfp->data.value.ptrvalue;
2896
if (rrp->ext.choice == 0
2897
|| (rrp->ext.choice == 1 && StringHasNoText (rrp->ext.value.ptrvalue))
2898
|| (rrp->ext.choice == 1
2899
&& (StringCmp (rrp->ext.value.ptrvalue, "ncRNA") == 0
2900
|| StringCmp (rrp->ext.value.ptrvalue, "tmRNA") == 0
2901
|| StringCmp (rrp->ext.value.ptrvalue, "misc_RNA") == 0))) {
2902
vn.choice = FeatQualChoice_legal_qual;
2903
vn.data.intvalue = Feat_qual_legal_product;
2905
rval = SetStringInGBQualList (&(sfp->qual), &vn, scp, new_val, existing_text);
2909
if ((rrp->ext.choice == 0 || (rrp->ext.choice == 1 && StringHasNoText (rrp->ext.value.ptrvalue)))
2910
&& (scp == NULL || scp->match_text == NULL)) {
2911
rrp->ext.value.ptrvalue = MemFree (rrp->ext.value.ptrvalue);
2912
rrp->ext.value.ptrvalue = StringSave (new_val);
2913
rrp->ext.choice = 1;
2915
} else if (rrp->ext.choice == 1
2916
&& StringCmp (rrp->ext.value.ptrvalue, "ncRNA") != 0
2917
&& StringCmp (rrp->ext.value.ptrvalue, "tmRNA") != 0
2918
&& StringCmp (rrp->ext.value.ptrvalue, "misc_RNA") != 0
2919
&& DoesStringMatchConstraint (rrp->ext.value.ptrvalue, scp)) {
2920
cp = rrp->ext.value.ptrvalue;
2921
rval = SetStringValue (&cp, new_val, existing_text);
2922
rrp->ext.value.ptrvalue = cp;
2924
} else if (rrp->ext.choice == 2) {
2925
tmp = GetRNAProductString (sfp, NULL);
2926
if (DoesStringMatchConstraint (tmp, scp)
2927
&& SetStringValue (&tmp, new_val, existing_text)) {
2928
trp = (tRNAPtr) rrp->ext.value.ptrvalue;
2930
trp = MemNew (sizeof (tRNA));
2932
MemSet (trp->codon, 255, sizeof (trp->codon));
2933
trp->anticodon = NULL;
2934
rrp->ext.value.ptrvalue = trp;
2937
if (!IsParseabletRNAName(tmp))
2939
if (trp->anticodon == NULL
2940
&& trp->codon[0] == 255
2941
&& trp->codon[1] == 255
2942
&& trp->codon[2] == 255
2943
&& trp->codon[3] == 255
2944
&& trp->codon[4] == 255
2945
&& trp->codon[5] == 255)
2947
trp = MemFree (trp);
2948
rrp->ext.choice = 1;
2949
rrp->ext.value.ptrvalue = tmp;
2955
vn.choice = FeatQualChoice_legal_qual;
2956
vn.data.intvalue = Feat_qual_legal_product;
2957
if (SetStringInGBQualList (&(sfp->qual), &vn, scp, new_val, existing_text)) {
2965
trp->aa = ParseTRnaString (tmp, &justTrnaText, codon, TRUE);
2969
tmp = MemFree (tmp);
2977
static Boolean RemoveRNAProductString (SeqFeatPtr sfp, StringConstraintPtr scp)
2980
Boolean rval = FALSE;
2982
if (sfp == NULL || sfp->data.choice != SEQFEAT_RNA || sfp->data.value.ptrvalue == NULL) {
2986
rrp = sfp->data.value.ptrvalue;
2987
if (rrp->ext.choice == 0
2988
|| (rrp->ext.choice == 1 && StringHasNoText (rrp->ext.value.ptrvalue))
2989
|| (rrp->ext.choice == 1
2990
&& (StringCmp (rrp->ext.value.ptrvalue, "ncRNA") == 0
2991
|| StringCmp (rrp->ext.value.ptrvalue, "tmRNA") == 0
2992
|| StringCmp (rrp->ext.value.ptrvalue, "misc_RNA") == 0))) {
2993
rval = RemoveGBQualMatch (&(sfp->qual), "product", scp);
2997
&& rrp->ext.choice == 1 && !StringHasNoText (rrp->ext.value.ptrvalue)
2998
&& StringCmp (rrp->ext.value.ptrvalue, "ncRNA") != 0
2999
&& StringCmp (rrp->ext.value.ptrvalue, "tmRNA") != 0
3000
&& StringCmp (rrp->ext.value.ptrvalue, "misc_RNA") != 0
3001
&& DoesStringMatchConstraint(rrp->ext.value.ptrvalue, scp)) {
3002
rrp->ext.value.ptrvalue = MemFree (rrp->ext.value.ptrvalue);
3003
rrp->ext.choice = 0;
3010
static SeqFeatPtr GetProtFeature (BioseqPtr protbsp)
3012
SeqMgrFeatContext fcontext;
3014
SeqFeatPtr prot_sfp;
3017
if (protbsp == NULL) return NULL;
3019
prot_sfp = SeqMgrGetNextFeature (protbsp, NULL, 0, FEATDEF_PROT, &fcontext);
3020
if (prot_sfp == NULL) {
3021
sap = protbsp->annot;
3022
while (sap != NULL && prot_sfp == NULL) {
3023
if (sap->type == 1) {
3024
prot_sfp = sap->data;
3025
while (prot_sfp != NULL
3026
&& (prot_sfp->data.choice != SEQFEAT_PROT
3027
|| (prp = prot_sfp->data.value.ptrvalue) == NULL
3028
|| prp->processed != 0)) {
3029
prot_sfp = prot_sfp->next;
3039
static ProtRefPtr GetProtRefForFeature (SeqFeatPtr sfp)
3043
ProtRefPtr prp = NULL;
3044
SeqFeatXrefPtr xref;
3046
if (sfp == NULL) return NULL;
3048
if (sfp->data.choice == SEQFEAT_PROT) {
3049
prp = (ProtRefPtr) sfp->data.value.ptrvalue;
3050
} else if (sfp->data.choice == SEQFEAT_CDREGION) {
3052
while (xref != NULL && xref->data.choice != SEQFEAT_PROT) {
3056
prp = xref->data.value.ptrvalue;
3058
if (prp == NULL && sfp->product != NULL) {
3059
protbsp = BioseqFindFromSeqLoc (sfp->product);
3060
protsfp = GetProtFeature (protbsp);
3061
if (protsfp != NULL) {
3062
prp = protsfp->data.value.ptrvalue;
3070
NLM_EXTERN CharPtr GetQualFromFeature (SeqFeatPtr sfp, FeatureFieldPtr field, StringConstraintPtr scp)
3073
GeneRefPtr grp = NULL;
3074
ProtRefPtr prp = NULL;
3077
if (sfp == NULL || field == NULL || field->field == NULL)
3081
if (field->type != Feature_type_any && sfp->idx.subtype != GetFeatdefFromFeatureType (field->type))
3087
if (sfp->idx.subtype == FEATDEF_GENE) {
3088
grp = sfp->data.value.ptrvalue;
3090
grp = SeqMgrGetGeneXref (sfp);
3093
// for protein fields
3094
prp = GetProtRefForFeature (sfp);
3096
/* fields common to all features */
3097
/* note, also known as comment */
3098
if ((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_note)
3099
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("note", field->field->data.ptrvalue)))
3101
if (!StringHasNoText (sfp->comment) && DoesStringMatchConstraint(sfp->comment, scp))
3103
str = StringSave (sfp->comment);
3108
&& ((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_db_xref)
3109
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("db_xref", field->field->data.ptrvalue))))
3111
str = GetDbxrefString (sfp, scp);
3115
&& ((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_exception)
3116
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("exception", field->field->data.ptrvalue))))
3118
if (!StringHasNoText (sfp->except_text) && DoesStringMatchConstraint(sfp->except_text, scp))
3120
str = StringSave (sfp->except_text);
3125
&& ((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_evidence)
3126
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("evidence", field->field->data.ptrvalue))))
3128
if (sfp->exp_ev == 1)
3130
str = StringSave ("experimental");
3132
else if (sfp->exp_ev == 2)
3134
str = StringSave ("non-experimental");
3136
if (!DoesStringMatchConstraint(str, scp)) {
3137
str = MemFree (str);
3141
/* fields common to some features */
3144
&& ((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_product)
3145
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("product", field->field->data.ptrvalue))))
3148
str = GetFirstValNodeStringMatch (prp->name, scp);
3149
} else if (sfp->data.choice == SEQFEAT_RNA) {
3150
str = GetRNAProductString (sfp, scp);
3157
&& ((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_gene)
3158
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("locus", field->field->data.ptrvalue)))
3161
if (!StringHasNoText (grp->locus) && DoesStringMatchConstraint(grp->locus, scp))
3163
str = StringSave (grp->locus);
3168
&& ((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_gene_description)
3169
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("description", field->field->data.ptrvalue)))
3172
if (!StringHasNoText (grp->desc) && DoesStringMatchConstraint(grp->desc, scp))
3174
str = StringSave (grp->desc);
3179
&& ((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_map)
3180
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("map", field->field->data.ptrvalue)))
3183
if (!StringHasNoText (grp->maploc) && DoesStringMatchConstraint(grp->maploc, scp))
3185
str = StringSave (grp->maploc);
3190
&& ((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_allele)
3191
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("allele", field->field->data.ptrvalue)))
3194
if (!StringHasNoText (grp->allele) && DoesStringMatchConstraint(grp->allele, scp))
3196
str = StringSave (grp->allele);
3201
&& ((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_locus_tag)
3202
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("locus_tag", field->field->data.ptrvalue)))
3205
if (!StringHasNoText (grp->locus_tag) && DoesStringMatchConstraint(grp->locus_tag, scp))
3207
str = StringSave (grp->locus_tag);
3212
&& ((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_synonym)
3213
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("synonym", field->field->data.ptrvalue)))
3216
str = GetFirstValNodeStringMatch (grp->syn, scp);
3220
/* protein fields */
3221
/* note - product handled above */
3224
&& ((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_description)
3225
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("description", field->field->data.ptrvalue)))
3228
if (!StringHasNoText (prp->desc) && DoesStringMatchConstraint(prp->desc, scp)) {
3229
str = StringSave (prp->desc);
3234
&& ((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_ec_number)
3235
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("ec_number", field->field->data.ptrvalue)))
3238
str = GetFirstValNodeStringMatch (prp->ec, scp);
3242
&& ((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_activity)
3243
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("activity", field->field->data.ptrvalue)))
3246
str = GetFirstValNodeStringMatch (prp->activity, scp);
3250
/* actual GenBank qualifiers */
3253
if (field->field->choice == FeatQualChoice_legal_qual)
3255
gbqual = GetGBQualFromFeatQual (field->field->data.intvalue);
3257
str = GetFirstGBQualMatch (sfp->qual, ParFlat_GBQual_names [gbqual].name, scp);
3259
/* need to do something with non-qualifier qualifiers */
3262
str = GetFirstGBQualMatchConstraintName (sfp->qual, field->field->data.ptrvalue, scp);
3269
static Boolean RemoveQualFromFeature (SeqFeatPtr sfp, FeatureFieldPtr field, StringConstraintPtr scp)
3271
Boolean rval = FALSE;
3272
GeneRefPtr grp = NULL;
3273
ProtRefPtr prp = NULL;
3278
if (sfp == NULL || field == NULL || field->field == NULL)
3282
if (field->type != Feature_type_any && sfp->idx.subtype != GetFeatdefFromFeatureType (field->type))
3288
if (sfp->idx.subtype == FEATDEF_GENE) {
3289
grp = sfp->data.value.ptrvalue;
3291
grp = SeqMgrGetGeneXref (sfp);
3294
// for protein fields
3295
prp = GetProtRefForFeature (sfp);
3298
if (sfp->data.choice == SEQFEAT_RNA) {
3299
rrp = (RnaRefPtr) sfp->data.value.ptrvalue;
3302
/* fields common to all features */
3303
/* note, also known as comment */
3304
if ((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_note)
3305
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("note", field->field->data.ptrvalue)))
3307
if (!StringHasNoText (sfp->comment) && DoesStringMatchConstraint (sfp->comment, scp))
3309
sfp->comment = MemFree (sfp->comment);
3314
if ((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_db_xref)
3315
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("db_xref", field->field->data.ptrvalue)))
3317
rval = RemoveDbxrefString (sfp, scp);
3320
if ((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_exception)
3321
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("exception", field->field->data.ptrvalue)))
3323
if (!StringHasNoText (sfp->except_text) && DoesStringMatchConstraint (sfp->except_text, scp))
3325
sfp->except_text = MemFree (sfp->except_text);
3330
if ((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_evidence)
3331
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("evidence", field->field->data.ptrvalue)))
3333
if ((sfp->exp_ev == 1 && DoesStringMatchConstraint("experimental", scp))
3334
|| (sfp->exp_ev == 2 && DoesStringMatchConstraint("non-experimental", scp))) {
3340
/* fields common to some features */
3342
if ((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_product)
3343
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("product", field->field->data.ptrvalue)))
3346
rval = RemoveValNodeStringMatch (&(prp->name), scp);
3347
} else if (sfp->data.choice == SEQFEAT_RNA) {
3348
rval = RemoveRNAProductString (sfp, scp);
3354
if (((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_gene)
3355
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("locus", field->field->data.ptrvalue)))
3358
if (!StringHasNoText (grp->locus) && DoesStringMatchConstraint (grp->locus, scp)) {
3359
grp->locus = MemFree (grp->locus);
3364
if (((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_gene_description)
3365
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("description", field->field->data.ptrvalue)))
3368
if (!StringHasNoText (grp->desc) && DoesStringMatchConstraint(grp->desc, scp))
3370
grp->desc = MemFree (grp->desc);
3375
if (((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_map)
3376
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("map", field->field->data.ptrvalue)))
3379
if (!StringHasNoText (grp->maploc) && DoesStringMatchConstraint(grp->maploc, scp))
3381
grp->maploc = MemFree (grp->maploc);
3386
if (((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_allele)
3387
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("allele", field->field->data.ptrvalue)))
3390
if (!StringHasNoText (grp->allele) && DoesStringMatchConstraint(grp->allele, scp))
3392
grp->allele = MemFree (grp->allele);
3397
if (((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_locus_tag)
3398
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("locus_tag", field->field->data.ptrvalue)))
3401
if (!StringHasNoText (grp->locus_tag) && DoesStringMatchConstraint(grp->locus_tag, scp))
3403
grp->locus_tag = MemFree (grp->locus_tag);
3408
if (((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_synonym)
3409
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("synonym", field->field->data.ptrvalue)))
3412
rval = RemoveValNodeStringMatch (&(grp->syn), scp);
3415
/* protein fields */
3416
/* note - product handled above */
3418
if (((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_description)
3419
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("description", field->field->data.ptrvalue)))
3422
if (!StringHasNoText (prp->desc) && DoesStringMatchConstraint(prp->desc, scp)) {
3423
prp->desc = MemFree (prp->desc);
3428
if (((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_ec_number)
3429
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("ec_number", field->field->data.ptrvalue)))
3432
rval = RemoveValNodeStringMatch (&(prp->ec), scp);
3435
if (((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_activity)
3436
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("activity", field->field->data.ptrvalue)))
3439
rval = RemoveValNodeStringMatch (&(prp->activity), scp);
3444
if (((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_anticodon)
3445
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("anticodon", field->field->data.ptrvalue)))
3446
&& rrp != NULL && rrp->ext.choice == 2)
3448
trp = (tRNAPtr) rrp->ext.value.ptrvalue;
3449
if (trp != NULL && trp->anticodon != NULL) {
3450
trp->anticodon = SeqLocFree (trp->anticodon);
3454
/* codons recognized */
3455
if (((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_anticodon)
3456
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("anticodon", field->field->data.ptrvalue)))
3457
&& rrp != NULL && rrp->ext.choice == 2)
3459
trp = (tRNAPtr) rrp->ext.value.ptrvalue;
3460
if (trp != NULL && (trp->codon[0] != 255 || trp->codon[1] != 255 || trp->codon[2] != 255
3461
|| trp->codon[3] != 255 || trp->codon[4] != 255 || trp->codon[5] != 255)) {
3462
trp->codon [0] = 255;
3463
trp->codon [1] = 255;
3464
trp->codon [2] = 255;
3465
trp->codon [3] = 255;
3466
trp->codon [4] = 255;
3467
trp->codon [5] = 255;
3473
/* actual GenBank qualifiers */
3474
if (field->field->choice == FeatQualChoice_legal_qual)
3476
gbqual = GetGBQualFromFeatQual (field->field->data.intvalue);
3478
rval = RemoveGBQualMatch (&(sfp->qual), ParFlat_GBQual_names [gbqual].name, scp);
3480
/* need to do something with non-qualifier qualifiers */
3483
rval = RemoveGBQualMatchConstraintName (&(sfp->qual), field->field->data.ptrvalue, scp);
3491
static Boolean ChooseBestFrame (SeqFeatPtr sfp)
3494
Uint1 new_frame = 0, i, orig_frame;
3498
Boolean retval = TRUE;
3500
if (sfp == NULL || sfp->data.choice != SEQFEAT_CDREGION) return FALSE;
3502
crp = sfp->data.value.ptrvalue;
3503
if (crp == NULL) return FALSE;
3504
orig_frame = crp->frame;
3507
for (i = 1; i <= 3; i++) {
3509
bs = ProteinFromCdRegionEx (sfp, FALSE, FALSE);
3510
lens[i - 1] = BSLen (bs);
3512
if (lens[i - 1] > max) {
3517
for (i = 1; i <= 3; i++) {
3518
if (lens [i - 1] == max && i != new_frame) {
3523
crp->frame = new_frame;
3525
crp->frame = orig_frame;
3531
static Boolean SetQualOnFeature (SeqFeatPtr sfp, FeatureFieldPtr field, StringConstraintPtr scp, CharPtr value, Uint2 existing_text)
3533
Boolean rval = FALSE;
3534
GeneRefPtr grp = NULL;
3535
ProtRefPtr prp = NULL;
3539
if (sfp == NULL || field == NULL || field->field == NULL)
3543
if (field->type != Feature_type_any && sfp->idx.subtype != GetFeatdefFromFeatureType (field->type))
3549
if (sfp->idx.subtype == FEATDEF_GENE) {
3550
grp = sfp->data.value.ptrvalue;
3552
grp = SeqMgrGetGeneXref (sfp);
3555
// for protein fields
3556
prp = GetProtRefForFeature (sfp);
3558
/* fields common to all features */
3559
/* note, also known as comment */
3560
if ((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_note)
3561
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("note", field->field->data.ptrvalue)))
3563
if (DoesStringMatchConstraint(sfp->comment, scp))
3565
rval = SetStringValue ( &(sfp->comment), value, existing_text);
3569
if ((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_db_xref)
3570
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("db_xref", field->field->data.ptrvalue)))
3572
rval = SetDbxrefString (sfp, scp, value, existing_text);
3575
if ((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_exception)
3576
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("exception", field->field->data.ptrvalue)))
3578
if (DoesStringMatchConstraint(sfp->except_text, scp))
3580
rval = SetStringValue ( &(sfp->except_text), value, existing_text);
3584
if ((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_evidence)
3585
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("evidence", field->field->data.ptrvalue)))
3588
if (sfp->exp_ev == 1)
3590
tmp = StringSave ("experimental");
3592
else if (sfp->exp_ev == 2)
3594
tmp = StringSave ("non-experimental");
3596
if (DoesStringMatchConstraint(tmp, scp)) {
3597
rval = SetStringValue (&tmp, value, existing_text);
3600
if (StringICmp (tmp, "experimental") == 0) {
3603
} else if (StringICmp (tmp, "non-experimental") == 0) {
3606
} else if (StringHasNoText (tmp)) {
3612
tmp = MemFree (tmp);
3616
/* fields common to some features */
3618
if ((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_product)
3619
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("product", field->field->data.ptrvalue)))
3622
rval = SetStringsInValNodeStringList (&(prp->name), scp, value, existing_text);
3623
} else if (sfp->data.choice == SEQFEAT_RNA) {
3624
rval = SetRNAProductString (sfp, scp, value, existing_text);
3630
if (((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_gene)
3631
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("locus", field->field->data.ptrvalue)))
3634
if (DoesStringMatchConstraint(grp->locus, scp))
3636
rval = SetStringValue (&(grp->locus), value, existing_text);
3640
if (((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_gene_description)
3641
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("description", field->field->data.ptrvalue)))
3644
if (DoesStringMatchConstraint(grp->desc, scp))
3646
rval = SetStringValue (&(grp->desc), value, existing_text);
3650
if (((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_map)
3651
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("map", field->field->data.ptrvalue)))
3654
if (DoesStringMatchConstraint(grp->maploc, scp))
3656
rval = SetStringValue (&(grp->maploc), value, existing_text);
3660
if (((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_allele)
3661
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("allele", field->field->data.ptrvalue)))
3664
if (DoesStringMatchConstraint(grp->allele, scp))
3666
rval = SetStringValue (&(grp->allele), value, existing_text);
3670
if (((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_locus_tag)
3671
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("locus_tag", field->field->data.ptrvalue)))
3674
if (DoesStringMatchConstraint(grp->locus_tag, scp))
3676
rval = SetStringValue (&(grp->locus_tag), value, existing_text);
3680
if (((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_synonym)
3681
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("synonym", field->field->data.ptrvalue)))
3684
rval = SetStringsInValNodeStringList (&(grp->syn), scp, value, existing_text);
3688
/* protein fields */
3689
/* note - product handled above */
3691
if (((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_description)
3692
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("description", field->field->data.ptrvalue)))
3695
if (DoesStringMatchConstraint(prp->desc, scp)) {
3696
rval = SetStringValue (&(prp->desc), value, existing_text);
3700
if (((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_ec_number)
3701
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("ec_number", field->field->data.ptrvalue)))
3704
rval = SetStringsInValNodeStringList (&(prp->ec), scp, value, existing_text);
3707
if (((field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_activity)
3708
|| (field->field->choice == FeatQualChoice_illegal_qual && DoesStringMatchConstraint ("activity", field->field->data.ptrvalue)))
3711
rval = SetStringsInValNodeStringList (&(prp->activity), scp, value, existing_text);
3714
if (field->field->choice == FeatQualChoice_legal_qual && field->field->data.intvalue == Feat_qual_legal_codon_start
3715
&& sfp->data.choice == SEQFEAT_CDREGION)
3717
crp = (CdRegionPtr) sfp->data.value.ptrvalue;
3718
if (StringICmp (value, "best") == 0)
3720
rval = ChooseBestFrame (sfp);
3722
else if (StringCmp (value, "1") == 0)
3727
else if (StringCmp (value, "2") == 0)
3732
else if (StringCmp (value, "3") == 0)
3739
/* actual GenBank qualifiers */
3742
rval = SetStringInGBQualList (&(sfp->qual), field->field, scp, value, existing_text);
3748
NLM_EXTERN CharPtr GetSourceQualFromBioSource (BioSourcePtr biop, SourceQualChoicePtr scp, StringConstraintPtr constraint)
3753
Int4 orgmod_subtype = -1, subsrc_subtype = -1;
3755
if (biop == NULL || scp == NULL) return NULL;
3757
switch (scp->choice)
3759
case SourceQualChoice_textqual:
3760
if (scp->data.intvalue == Source_qual_taxname) {
3761
if (biop->org != NULL && !StringHasNoText (biop->org->taxname)
3762
&& DoesStringMatchConstraint (biop->org->taxname, constraint)) {
3763
str = StringSave (biop->org->taxname);
3765
} else if (scp->data.intvalue == Source_qual_common_name) {
3766
if (biop->org != NULL && !StringHasNoText (biop->org->common)
3767
&& DoesStringMatchConstraint (biop->org->common, constraint)) {
3768
str = StringSave (biop->org->common);
3770
} else if (scp->data.intvalue == Source_qual_lineage) {
3771
if (biop->org != NULL && biop->org->orgname != NULL && !StringHasNoText (biop->org->orgname->lineage)
3772
&& DoesStringMatchConstraint (biop->org->orgname->lineage, constraint)) {
3773
str = StringSave (biop->org->orgname->lineage);
3775
} else if (scp->data.intvalue == Source_qual_division) {
3776
if (biop->org != NULL && biop->org->orgname != NULL && !StringHasNoText (biop->org->orgname->div)
3777
&& DoesStringMatchConstraint (biop->org->orgname->div, constraint)) {
3778
str = StringSave (biop->org->orgname->div);
3781
orgmod_subtype = GetOrgModQualFromSrcQual (scp->data.intvalue);
3782
if (orgmod_subtype == -1) {
3783
subsrc_subtype = GetSubSrcQualFromSrcQual (scp->data.intvalue);
3784
for (ssp = biop->subtype; ssp != NULL && str == NULL; ssp = ssp->next) {
3785
if (ssp->subtype == subsrc_subtype) {
3786
if (StringHasNoText (ssp->name)) {
3787
if (IsNonTextSourceQual (scp->data.intvalue)
3788
&& DoesStringMatchConstraint ("TRUE", constraint)) {
3789
str = StringSave ("TRUE");
3792
if (DoesStringMatchConstraint (ssp->name, constraint)) {
3793
str = StringSave (ssp->name);
3799
if (biop->org != NULL && biop->org->orgname != NULL) {
3800
for (mod = biop->org->orgname->mod; mod != NULL && str == NULL; mod = mod->next) {
3801
if (mod->subtype == orgmod_subtype) {
3802
if (StringHasNoText (mod->subname)) {
3803
if (IsNonTextSourceQual (scp->data.intvalue)
3804
&& DoesStringMatchConstraint ("TRUE", constraint)) {
3805
str = StringSave ("TRUE");
3808
if (DoesStringMatchConstraint (mod->subname, constraint)) {
3809
str = StringSave (mod->subname);
3818
case SourceQualChoice_location:
3819
str = LocNameFromGenome (biop->genome);
3820
if (DoesStringMatchConstraint (str, constraint)) {
3821
str = StringSave (str);
3826
case SourceQualChoice_origin:
3827
str = OriginNameFromOrigin (biop->origin);
3828
if (DoesStringMatchConstraint (str, constraint)) {
3829
str = StringSave (str);
3839
static Boolean RemoveSourceQualFromBioSource (BioSourcePtr biop, SourceQualChoicePtr scp, StringConstraintPtr constraint)
3841
SubSourcePtr ssp, ssp_prev = NULL, ssp_next;
3842
OrgModPtr mod, mod_prev = NULL, mod_next;
3843
Int4 orgmod_subtype = -1, subsrc_subtype = -1;
3845
Boolean rval = FALSE;
3847
if (biop == NULL || scp == NULL) return FALSE;
3849
switch (scp->choice)
3851
case SourceQualChoice_textqual:
3852
if (scp->data.intvalue == Source_qual_taxname) {
3853
if (biop->org != NULL && !StringHasNoText (biop->org->taxname)
3854
&& DoesStringMatchConstraint (biop->org->taxname, constraint)) {
3855
biop->org->taxname = MemFree (biop->org->taxname);
3858
} else if (scp->data.intvalue == Source_qual_common_name) {
3859
if (biop->org != NULL && !StringHasNoText (biop->org->common)
3860
&& DoesStringMatchConstraint (biop->org->common, constraint)) {
3861
biop->org->common = MemFree (biop->org->common);
3864
} else if (scp->data.intvalue == Source_qual_lineage) {
3865
if (biop->org != NULL && biop->org->orgname != NULL && !StringHasNoText (biop->org->orgname->lineage)
3866
&& DoesStringMatchConstraint (biop->org->orgname->lineage, constraint)) {
3867
biop->org->orgname->lineage = MemFree (biop->org->orgname->lineage);
3870
} else if (scp->data.intvalue == Source_qual_division) {
3871
if (biop->org != NULL && biop->org->orgname != NULL && !StringHasNoText (biop->org->orgname->div)
3872
&& DoesStringMatchConstraint (biop->org->orgname->div, constraint)) {
3873
biop->org->orgname->div = MemFree (biop->org->orgname->div);
3877
orgmod_subtype = GetOrgModQualFromSrcQual (scp->data.intvalue);
3878
if (orgmod_subtype == -1) {
3879
subsrc_subtype = GetSubSrcQualFromSrcQual (scp->data.intvalue);
3880
ssp = biop->subtype;
3881
while (ssp != NULL) {
3882
ssp_next = ssp->next;
3883
if (ssp->subtype == subsrc_subtype
3884
&& DoesStringMatchConstraint (ssp->name, constraint)) {
3885
if (ssp_prev == NULL) {
3886
biop->subtype = ssp->next;
3888
ssp_prev->next = ssp->next;
3891
ssp = SubSourceFree (ssp);
3899
if (biop->org != NULL && biop->org->orgname != NULL) {
3900
mod = biop->org->orgname->mod;
3901
while (mod != NULL) {
3902
mod_next = mod->next;
3903
if (mod->subtype == orgmod_subtype
3904
&& DoesStringMatchConstraint (mod->subname, constraint)) {
3905
if (mod_prev == NULL) {
3906
biop->org->orgname->mod = mod->next;
3908
mod_prev->next = mod->next;
3911
mod = OrgModFree (mod);
3922
case SourceQualChoice_location:
3923
str = LocNameFromGenome (biop->genome);
3924
if (DoesStringMatchConstraint (str, constraint)) {
3925
if (scp->data.intvalue == 0 || biop->genome == GenomeFromSrcLoc (scp->data.intvalue)) {
3931
case SourceQualChoice_origin:
3932
str = OriginNameFromOrigin (biop->origin);
3933
if (DoesStringMatchConstraint (str, constraint)) {
3934
if (scp->data.intvalue == 0 || biop->origin == OriginFromSrcOrig (scp->data.intvalue)) {
3945
NLM_EXTERN Boolean SetSourceQualInBioSource (BioSourcePtr biop, SourceQualChoicePtr scp, StringConstraintPtr constraint, CharPtr value, Uint2 existing_text)
3947
SubSourcePtr ssp, ssp_prev = NULL, ssp_next;
3948
OrgModPtr mod, mod_prev = NULL, mod_next;
3949
Int4 orgmod_subtype = -1, subsrc_subtype = -1;
3951
Boolean rval = FALSE, found = FALSE;
3953
if (biop == NULL || scp == NULL) return FALSE;
3955
switch (scp->choice)
3957
case SourceQualChoice_textqual:
3958
if (scp->data.intvalue == Source_qual_taxname) {
3959
if (biop->org != NULL
3960
&& DoesStringMatchConstraint (biop->org->taxname, constraint)) {
3961
rval = SetStringValue (&(biop->org->taxname), value, existing_text);
3963
} else if (scp->data.intvalue == Source_qual_common_name) {
3964
if (biop->org != NULL
3965
&& DoesStringMatchConstraint (biop->org->common, constraint)) {
3966
rval = SetStringValue (&(biop->org->common), value, existing_text);
3968
} else if (scp->data.intvalue == Source_qual_lineage) {
3969
if (biop->org != NULL && biop->org->orgname != NULL
3970
&& DoesStringMatchConstraint (biop->org->orgname->lineage, constraint)) {
3971
rval = SetStringValue (&(biop->org->orgname->lineage), value, existing_text);
3973
} else if (scp->data.intvalue == Source_qual_division) {
3974
if (biop->org != NULL && biop->org->orgname != NULL
3975
&& DoesStringMatchConstraint (biop->org->orgname->div, constraint)) {
3976
rval = SetStringValue (&(biop->org->orgname->div), value, existing_text);
3979
orgmod_subtype = GetOrgModQualFromSrcQual (scp->data.intvalue);
3980
if (orgmod_subtype == -1) {
3981
subsrc_subtype = GetSubSrcQualFromSrcQual (scp->data.intvalue);
3982
if (subsrc_subtype > -1) {
3983
ssp = biop->subtype;
3984
while (ssp != NULL) {
3985
ssp_next = ssp->next;
3986
if (ssp->subtype == subsrc_subtype
3987
&& DoesStringMatchConstraint (ssp->name, constraint)) {
3988
rval = SetStringValue (&(ssp->name), value, existing_text);
3990
if (rval && StringHasNoText (ssp->name) && !IsNonTextSourceQual(scp->data.intvalue)) {
3991
if (ssp_prev == NULL) {
3992
biop->subtype = ssp->next;
3994
ssp_prev->next = ssp->next;
3997
ssp = SubSourceFree (ssp);
4006
if (!found && IsStringConstraintEmpty (constraint)) {
4007
ssp = SubSourceNew ();
4008
ssp->subtype = subsrc_subtype;
4009
rval = SetStringValue (&(ssp->name), value, existing_text);
4010
if (ssp_prev == NULL) {
4011
biop->subtype = ssp;
4013
ssp_prev->next = ssp;
4018
if (biop->org != NULL && biop->org->orgname != NULL) {
4019
mod = biop->org->orgname->mod;
4020
while (mod != NULL) {
4021
mod_next = mod->next;
4022
if (mod->subtype == orgmod_subtype
4023
&& DoesStringMatchConstraint (mod->subname, constraint)) {
4024
rval = SetStringValue (&(mod->subname), value, existing_text);
4026
if (rval && StringHasNoText (mod->subname) && !IsNonTextSourceQual(scp->data.intvalue)) {
4027
if (mod_prev == NULL) {
4028
biop->org->orgname->mod = mod->next;
4030
mod_prev->next = mod->next;
4033
mod = OrgModFree (mod);
4043
if (!found && IsStringConstraintEmpty (constraint)) {
4044
if (biop->org == NULL) {
4045
biop->org = OrgRefNew();
4047
if (biop->org->orgname == NULL) {
4048
biop->org->orgname = OrgNameNew();
4051
mod->subtype = orgmod_subtype;
4052
rval = SetStringValue (&(mod->subname), value, existing_text);
4053
if (mod_prev == NULL) {
4054
biop->org->orgname->mod = mod;
4056
mod_prev->next = mod;
4062
case SourceQualChoice_location:
4063
str = LocNameFromGenome (biop->genome);
4064
if (DoesStringMatchConstraint (str, constraint)) {
4065
biop->genome = GenomeFromSrcLoc (scp->data.intvalue);
4069
case SourceQualChoice_origin:
4070
str = OriginNameFromOrigin (biop->origin);
4071
if (DoesStringMatchConstraint (str, constraint)) {
4072
biop->origin = OriginFromSrcOrig(scp->data.intvalue);
4081
static BioseqPtr GetSequenceForObject (Uint1 choice, Pointer data)
4083
BioseqPtr bsp = NULL;
4090
if (data == NULL) return NULL;
4094
bsp = (BioseqPtr) data;
4097
sfp = (SeqFeatPtr) data;
4098
bsp = BioseqFindFromSeqLoc (sfp->location);
4101
sdp = (SeqDescrPtr) data;
4102
if (sdp->extended) {
4103
ovp = (ObjValNodePtr) sdp;
4104
if (ovp->idx.parenttype == OBJ_BIOSEQ && ovp->idx.parentptr != NULL) {
4105
bsp = ovp->idx.parentptr;
4110
cgp = (CGPSetPtr) data;
4111
for (vnp = cgp->cds_list; vnp != NULL && bsp == NULL; vnp = vnp->next) {
4112
sfp = vnp->data.ptrvalue;
4114
bsp = BioseqFindFromSeqLoc (sfp->location);
4117
for (vnp = cgp->mrna_list; vnp != NULL && bsp == NULL; vnp = vnp->next) {
4118
sfp = vnp->data.ptrvalue;
4120
bsp = BioseqFindFromSeqLoc (sfp->location);
4124
for (vnp = cgp->gene_list; vnp != NULL && bsp == NULL; vnp = vnp->next) {
4125
sfp = vnp->data.ptrvalue;
4127
bsp = BioseqFindFromSeqLoc (sfp->location);
4136
NLM_EXTERN BioSourcePtr GetBioSourceFromObject (Uint1 choice, Pointer data)
4138
BioSourcePtr biop = NULL;
4141
BioseqPtr bsp = NULL;
4142
SeqMgrDescContext context;
4144
if (data == NULL) return NULL;
4149
sdp = (SeqDescrPtr) data;
4150
if (sdp->choice == Seq_descr_source) {
4151
biop = sdp->data.ptrvalue;
4155
sfp = (SeqFeatPtr) data;
4156
if (sfp->data.choice == SEQFEAT_BIOSRC) {
4157
biop = sfp->data.value.ptrvalue;
4162
bsp = GetSequenceForObject (choice, data);
4163
sdp = SeqMgrGetNextDescriptor (bsp, NULL, Seq_descr_source, &context);
4164
if (sdp != NULL && sdp->choice == Seq_descr_source) {
4165
biop = sdp->data.ptrvalue;
4172
/* functions for dealing with CDS-Gene-Prot sets */
4173
static CharPtr GetFieldValueFromCGPSet (CGPSetPtr c, Uint2 field, StringConstraintPtr scp)
4182
if (c == NULL) return NULL;
4184
case CDSGeneProt_field_cds_comment:
4185
for (vnp = c->cds_list; vnp != NULL && str == NULL; vnp = vnp->next) {
4186
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4187
if (sfp != NULL && !StringHasNoText (sfp->comment) && DoesStringMatchConstraint(sfp->comment, scp))
4189
str = StringSave (sfp->comment);
4193
case CDSGeneProt_field_gene_locus:
4194
for (vnp = c->gene_list; vnp != NULL && str == NULL; vnp = vnp->next) {
4195
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4196
if (sfp != NULL && sfp->data.choice == SEQFEAT_GENE
4197
&& (grp = sfp->data.value.ptrvalue) != NULL
4198
&& !StringHasNoText (grp->locus)
4199
&& DoesStringMatchConstraint(grp->locus, scp))
4201
str = StringSave (grp->locus);
4205
case CDSGeneProt_field_gene_description:
4206
for (vnp = c->gene_list; vnp != NULL && str == NULL; vnp = vnp->next) {
4207
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4208
if (sfp != NULL && sfp->data.choice == SEQFEAT_GENE
4209
&& (grp = sfp->data.value.ptrvalue) != NULL
4210
&& !StringHasNoText (grp->desc)
4211
&& DoesStringMatchConstraint(grp->desc, scp))
4213
str = StringSave (grp->desc);
4217
case CDSGeneProt_field_gene_comment:
4218
for (vnp = c->gene_list; vnp != NULL && str == NULL; vnp = vnp->next) {
4219
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4220
if (sfp != NULL && !StringHasNoText (sfp->comment) && DoesStringMatchConstraint(sfp->comment, scp))
4222
str = StringSave (sfp->comment);
4226
case CDSGeneProt_field_gene_allele:
4227
for (vnp = c->gene_list; vnp != NULL && str == NULL; vnp = vnp->next) {
4228
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4229
if (sfp != NULL && sfp->data.choice == SEQFEAT_GENE
4230
&& (grp = sfp->data.value.ptrvalue) != NULL
4231
&& !StringHasNoText (grp->allele)
4232
&& DoesStringMatchConstraint(grp->allele, scp))
4234
str = StringSave (grp->allele);
4238
case CDSGeneProt_field_gene_maploc:
4239
for (vnp = c->gene_list; vnp != NULL && str == NULL; vnp = vnp->next) {
4240
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4241
if (sfp != NULL && sfp->data.choice == SEQFEAT_GENE
4242
&& (grp = sfp->data.value.ptrvalue) != NULL
4243
&& !StringHasNoText (grp->maploc)
4244
&& DoesStringMatchConstraint(grp->maploc, scp))
4246
str = StringSave (grp->maploc);
4250
case CDSGeneProt_field_gene_locus_tag:
4251
for (vnp = c->gene_list; vnp != NULL && str == NULL; vnp = vnp->next) {
4252
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4253
if (sfp != NULL && sfp->data.choice == SEQFEAT_GENE
4254
&& (grp = sfp->data.value.ptrvalue) != NULL
4255
&& !StringHasNoText (grp->locus_tag)
4256
&& DoesStringMatchConstraint(grp->locus_tag, scp))
4258
str = StringSave (grp->locus_tag);
4262
case CDSGeneProt_field_gene_synonym:
4263
for (vnp = c->gene_list; vnp != NULL && str == NULL; vnp = vnp->next) {
4264
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4265
if (sfp != NULL && sfp->data.choice == SEQFEAT_GENE
4266
&& (grp = sfp->data.value.ptrvalue) != NULL)
4268
str = GetFirstValNodeStringMatch (grp->syn, scp);
4272
case CDSGeneProt_field_gene_old_locus_tag:
4273
for (vnp = c->gene_list; vnp != NULL && str == NULL; vnp = vnp->next) {
4274
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4276
str = GetFirstGBQualMatch (sfp->qual, "old-locus-tag", scp);
4280
case CDSGeneProt_field_mrna_product:
4281
for (vnp = c->mrna_list; vnp != NULL && str == NULL; vnp = vnp->next) {
4282
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4283
if (sfp != NULL && sfp->data.choice == SEQFEAT_RNA
4284
&& (rrp = sfp->data.value.ptrvalue) != NULL
4285
&& rrp->ext.choice == 1
4286
&& !StringHasNoText (rrp->ext.value.ptrvalue)
4287
&& DoesStringMatchConstraint(rrp->ext.value.ptrvalue, scp))
4289
str = StringSave (rrp->ext.value.ptrvalue);
4293
case CDSGeneProt_field_mrna_comment:
4294
for (vnp = c->mrna_list; vnp != NULL && str == NULL; vnp = vnp->next) {
4295
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4296
if (sfp != NULL && !StringHasNoText (sfp->comment) && DoesStringMatchConstraint(sfp->comment, scp))
4298
str = StringSave (sfp->comment);
4302
case CDSGeneProt_field_prot_name:
4303
for (vnp = c->prot_list; vnp != NULL && str == NULL; vnp = vnp->next) {
4304
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4305
if (sfp != NULL && sfp->data.choice == SEQFEAT_PROT
4306
&& sfp->idx.subtype == FEATDEF_PROT
4307
&& (prp = sfp->data.value.ptrvalue) != NULL)
4309
str = GetFirstValNodeStringMatch (prp->name, scp);
4313
case CDSGeneProt_field_prot_description:
4314
for (vnp = c->prot_list; vnp != NULL && str == NULL; vnp = vnp->next) {
4315
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4316
if (sfp != NULL && sfp->data.choice == SEQFEAT_PROT
4317
&& sfp->idx.subtype == FEATDEF_PROT
4318
&& (prp = sfp->data.value.ptrvalue) != NULL
4319
&& !StringHasNoText (prp->desc) && DoesStringMatchConstraint(prp->desc, scp)) {
4320
str = StringSave (prp->desc);
4324
case CDSGeneProt_field_prot_ec_number:
4325
for (vnp = c->prot_list; vnp != NULL && str == NULL; vnp = vnp->next) {
4326
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4327
if (sfp != NULL && sfp->data.choice == SEQFEAT_PROT
4328
&& sfp->idx.subtype == FEATDEF_PROT
4329
&& (prp = sfp->data.value.ptrvalue) != NULL)
4331
str = GetFirstValNodeStringMatch (prp->ec, scp);
4335
case CDSGeneProt_field_prot_activity:
4336
for (vnp = c->prot_list; vnp != NULL && str == NULL; vnp = vnp->next) {
4337
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4338
if (sfp != NULL && sfp->data.choice == SEQFEAT_PROT
4339
&& sfp->idx.subtype == FEATDEF_PROT
4340
&& (prp = sfp->data.value.ptrvalue) != NULL)
4342
str = GetFirstValNodeStringMatch (prp->activity, scp);
4346
case CDSGeneProt_field_prot_comment:
4347
for (vnp = c->prot_list; vnp != NULL && str == NULL; vnp = vnp->next) {
4348
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4349
if (sfp != NULL && sfp->idx.subtype == FEATDEF_PROT
4350
&& !StringHasNoText (sfp->comment) && DoesStringMatchConstraint(sfp->comment, scp))
4352
str = StringSave (sfp->comment);
4356
case CDSGeneProt_field_mat_peptide_name:
4357
for (vnp = c->prot_list; vnp != NULL && str == NULL; vnp = vnp->next) {
4358
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4359
if (sfp != NULL && sfp->data.choice == SEQFEAT_PROT
4360
&& sfp->idx.subtype == FEATDEF_mat_peptide_aa
4361
&& (prp = sfp->data.value.ptrvalue) != NULL)
4363
str = GetFirstValNodeStringMatch (prp->name, scp);
4367
case CDSGeneProt_field_mat_peptide_description:
4368
for (vnp = c->prot_list; vnp != NULL && str == NULL; vnp = vnp->next) {
4369
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4370
if (sfp != NULL && sfp->data.choice == SEQFEAT_PROT
4371
&& sfp->idx.subtype == FEATDEF_mat_peptide_aa
4372
&& (prp = sfp->data.value.ptrvalue) != NULL
4373
&& !StringHasNoText (prp->desc) && DoesStringMatchConstraint(prp->desc, scp)) {
4374
str = StringSave (prp->desc);
4378
case CDSGeneProt_field_mat_peptide_ec_number:
4379
for (vnp = c->prot_list; vnp != NULL && str == NULL; vnp = vnp->next) {
4380
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4381
if (sfp != NULL && sfp->data.choice == SEQFEAT_PROT
4382
&& sfp->idx.subtype == FEATDEF_mat_peptide_aa
4383
&& (prp = sfp->data.value.ptrvalue) != NULL)
4385
str = GetFirstValNodeStringMatch (prp->ec, scp);
4389
case CDSGeneProt_field_mat_peptide_activity:
4390
for (vnp = c->prot_list; vnp != NULL && str == NULL; vnp = vnp->next) {
4391
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4392
if (sfp != NULL && sfp->data.choice == SEQFEAT_PROT
4393
&& sfp->idx.subtype == FEATDEF_mat_peptide_aa
4394
&& (prp = sfp->data.value.ptrvalue) != NULL)
4396
str = GetFirstValNodeStringMatch (prp->activity, scp);
4400
case CDSGeneProt_field_mat_peptide_comment:
4401
for (vnp = c->prot_list; vnp != NULL && str == NULL; vnp = vnp->next) {
4402
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4403
if (sfp != NULL && sfp->idx.subtype == FEATDEF_mat_peptide_aa
4404
&& !StringHasNoText (sfp->comment) && DoesStringMatchConstraint(sfp->comment, scp))
4406
str = StringSave (sfp->comment);
4415
static Boolean RemoveFieldValueFromCGPSet (CGPSetPtr c, Uint2 field, StringConstraintPtr scp)
4417
Boolean rval = FALSE;
4424
if (c == NULL) return FALSE;
4426
case CDSGeneProt_field_cds_comment:
4427
for (vnp = c->cds_list; vnp != NULL; vnp = vnp->next) {
4428
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4429
if (sfp != NULL && !StringHasNoText (sfp->comment) && DoesStringMatchConstraint(sfp->comment, scp))
4431
sfp->comment = MemFree (sfp->comment);
4436
case CDSGeneProt_field_gene_locus:
4437
for (vnp = c->gene_list; vnp != NULL; vnp = vnp->next) {
4438
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4439
if (sfp != NULL && sfp->data.choice == SEQFEAT_GENE
4440
&& (grp = sfp->data.value.ptrvalue) != NULL
4441
&& !StringHasNoText (grp->locus)
4442
&& DoesStringMatchConstraint(grp->locus, scp))
4444
grp->locus = MemFree (grp->locus);
4449
case CDSGeneProt_field_gene_description:
4450
for (vnp = c->gene_list; vnp != NULL; vnp = vnp->next) {
4451
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4452
if (sfp != NULL && sfp->data.choice == SEQFEAT_GENE
4453
&& (grp = sfp->data.value.ptrvalue) != NULL
4454
&& !StringHasNoText (grp->desc)
4455
&& DoesStringMatchConstraint(grp->desc, scp))
4457
grp->desc = MemFree(grp->desc);
4462
case CDSGeneProt_field_gene_comment:
4463
for (vnp = c->gene_list; vnp != NULL; vnp = vnp->next) {
4464
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4465
if (sfp != NULL && !StringHasNoText (sfp->comment) && DoesStringMatchConstraint(sfp->comment, scp))
4467
sfp->comment = MemFree (sfp->comment);
4472
case CDSGeneProt_field_gene_allele:
4473
for (vnp = c->gene_list; vnp != NULL; vnp = vnp->next) {
4474
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4475
if (sfp != NULL && sfp->data.choice == SEQFEAT_GENE
4476
&& (grp = sfp->data.value.ptrvalue) != NULL
4477
&& !StringHasNoText (grp->allele)
4478
&& DoesStringMatchConstraint(grp->allele, scp))
4480
grp->allele = MemFree (grp->allele);
4485
case CDSGeneProt_field_gene_maploc:
4486
for (vnp = c->gene_list; vnp != NULL; vnp = vnp->next) {
4487
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4488
if (sfp != NULL && sfp->data.choice == SEQFEAT_GENE
4489
&& (grp = sfp->data.value.ptrvalue) != NULL
4490
&& !StringHasNoText (grp->maploc)
4491
&& DoesStringMatchConstraint(grp->maploc, scp))
4493
grp->maploc = MemFree (grp->maploc);
4498
case CDSGeneProt_field_gene_locus_tag:
4499
for (vnp = c->gene_list; vnp != NULL; vnp = vnp->next) {
4500
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4501
if (sfp != NULL && sfp->data.choice == SEQFEAT_GENE
4502
&& (grp = sfp->data.value.ptrvalue) != NULL
4503
&& !StringHasNoText (grp->locus_tag)
4504
&& DoesStringMatchConstraint(grp->locus_tag, scp))
4506
grp->locus_tag = MemFree (grp->locus_tag);
4511
case CDSGeneProt_field_gene_synonym:
4512
for (vnp = c->gene_list; vnp != NULL; vnp = vnp->next) {
4513
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4514
if (sfp != NULL && sfp->data.choice == SEQFEAT_GENE
4515
&& (grp = sfp->data.value.ptrvalue) != NULL)
4517
rval |= RemoveValNodeStringMatch (&(grp->syn), scp);
4521
case CDSGeneProt_field_gene_old_locus_tag:
4522
for (vnp = c->gene_list; vnp != NULL; vnp = vnp->next) {
4523
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4525
rval |= RemoveGBQualMatch (&(sfp->qual), "old-locus-tag", scp);
4529
case CDSGeneProt_field_mrna_product:
4530
for (vnp = c->mrna_list; vnp != NULL; vnp = vnp->next) {
4531
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4532
if (sfp != NULL && sfp->data.choice == SEQFEAT_RNA
4533
&& (rrp = sfp->data.value.ptrvalue) != NULL
4534
&& rrp->ext.choice == 1
4535
&& !StringHasNoText (rrp->ext.value.ptrvalue)
4536
&& DoesStringMatchConstraint(rrp->ext.value.ptrvalue, scp))
4538
rrp->ext.value.ptrvalue = MemFree (rrp->ext.value.ptrvalue);
4539
rrp->ext.choice = 0;
4544
case CDSGeneProt_field_mrna_comment:
4545
for (vnp = c->mrna_list; vnp != NULL; vnp = vnp->next) {
4546
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4547
if (sfp != NULL && !StringHasNoText (sfp->comment) && DoesStringMatchConstraint(sfp->comment, scp))
4549
sfp->comment = MemFree (sfp->comment);
4554
case CDSGeneProt_field_prot_name:
4555
for (vnp = c->prot_list; vnp != NULL; vnp = vnp->next) {
4556
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4557
if (sfp != NULL && sfp->data.choice == SEQFEAT_PROT
4558
&& sfp->idx.subtype == FEATDEF_PROT
4559
&& (prp = sfp->data.value.ptrvalue) != NULL)
4561
rval |= RemoveValNodeStringMatch (&(prp->name), scp);
4565
case CDSGeneProt_field_prot_description:
4566
for (vnp = c->prot_list; vnp != NULL; vnp = vnp->next) {
4567
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4568
if (sfp != NULL && sfp->data.choice == SEQFEAT_PROT
4569
&& sfp->idx.subtype == FEATDEF_PROT
4570
&& (prp = sfp->data.value.ptrvalue) != NULL
4571
&& !StringHasNoText (prp->desc) && DoesStringMatchConstraint(prp->desc, scp)) {
4572
prp->desc = MemFree (prp->desc);
4577
case CDSGeneProt_field_prot_ec_number:
4578
for (vnp = c->prot_list; vnp != NULL; vnp = vnp->next) {
4579
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4580
if (sfp != NULL && sfp->data.choice == SEQFEAT_PROT
4581
&& sfp->idx.subtype == FEATDEF_PROT
4582
&& (prp = sfp->data.value.ptrvalue) != NULL)
4584
rval |= RemoveValNodeStringMatch (&(prp->ec), scp);
4588
case CDSGeneProt_field_prot_activity:
4589
for (vnp = c->prot_list; vnp != NULL; vnp = vnp->next) {
4590
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4591
if (sfp != NULL && sfp->data.choice == SEQFEAT_PROT
4592
&& sfp->idx.subtype == FEATDEF_PROT
4593
&& (prp = sfp->data.value.ptrvalue) != NULL)
4595
rval |= RemoveValNodeStringMatch (&(prp->activity), scp);
4599
case CDSGeneProt_field_prot_comment:
4600
for (vnp = c->prot_list; vnp != NULL; vnp = vnp->next) {
4601
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4602
if (sfp != NULL && sfp->idx.subtype == FEATDEF_PROT
4603
&& !StringHasNoText (sfp->comment) && DoesStringMatchConstraint(sfp->comment, scp))
4605
sfp->comment = MemFree (sfp->comment);
4610
case CDSGeneProt_field_mat_peptide_name:
4611
for (vnp = c->prot_list; vnp != NULL; vnp = vnp->next) {
4612
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4613
if (sfp != NULL && sfp->data.choice == SEQFEAT_PROT
4614
&& sfp->idx.subtype == FEATDEF_mat_peptide_aa
4615
&& (prp = sfp->data.value.ptrvalue) != NULL)
4617
rval |= RemoveValNodeStringMatch (&(prp->name), scp);
4621
case CDSGeneProt_field_mat_peptide_description:
4622
for (vnp = c->prot_list; vnp != NULL; vnp = vnp->next) {
4623
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4624
if (sfp != NULL && sfp->data.choice == SEQFEAT_PROT
4625
&& sfp->idx.subtype == FEATDEF_mat_peptide_aa
4626
&& (prp = sfp->data.value.ptrvalue) != NULL
4627
&& !StringHasNoText (prp->desc) && DoesStringMatchConstraint(prp->desc, scp)) {
4628
prp->desc = MemFree (prp->desc);
4633
case CDSGeneProt_field_mat_peptide_ec_number:
4634
for (vnp = c->prot_list; vnp != NULL; vnp = vnp->next) {
4635
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4636
if (sfp != NULL && sfp->data.choice == SEQFEAT_PROT
4637
&& sfp->idx.subtype == FEATDEF_mat_peptide_aa
4638
&& (prp = sfp->data.value.ptrvalue) != NULL)
4640
rval |= RemoveValNodeStringMatch (&(prp->ec), scp);
4644
case CDSGeneProt_field_mat_peptide_activity:
4645
for (vnp = c->prot_list; vnp != NULL; vnp = vnp->next) {
4646
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4647
if (sfp != NULL && sfp->data.choice == SEQFEAT_PROT
4648
&& sfp->idx.subtype == FEATDEF_mat_peptide_aa
4649
&& (prp = sfp->data.value.ptrvalue) != NULL)
4651
rval |= RemoveValNodeStringMatch (&(prp->activity), scp);
4655
case CDSGeneProt_field_mat_peptide_comment:
4656
for (vnp = c->prot_list; vnp != NULL; vnp = vnp->next) {
4657
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4658
if (sfp != NULL && sfp->idx.subtype == FEATDEF_mat_peptide_aa
4659
&& !StringHasNoText (sfp->comment) && DoesStringMatchConstraint(sfp->comment, scp))
4661
sfp->comment = MemFree (sfp->comment);
4671
static SeqFeatPtr CreateGeneForCGPSet (CGPSetPtr c)
4673
SeqFeatPtr gene = NULL, sfp = NULL;
4677
if (c == NULL) return NULL;
4679
for (vnp = c->cds_list; vnp != NULL && sfp == NULL; vnp = vnp->next) {
4680
sfp = vnp->data.ptrvalue;
4682
for (vnp = c->mrna_list; vnp != NULL && sfp == NULL; vnp = vnp->next) {
4683
sfp = vnp->data.ptrvalue;
4686
bsp = BioseqFindFromSeqLoc (sfp->location);
4688
gene = CreateNewFeatureOnBioseq (bsp, SEQFEAT_GENE, sfp->location);
4690
gene->data.value.ptrvalue = GeneRefNew();
4698
static Boolean SetFieldValueInCGPSet (CGPSetPtr c, Uint2 field, StringConstraintPtr scp, CharPtr value, Uint2 existing_text)
4700
Boolean rval = FALSE;
4706
if (c == NULL) return FALSE;
4708
case CDSGeneProt_field_cds_comment:
4709
for (vnp = c->cds_list; vnp != NULL; vnp = vnp->next) {
4710
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4711
if (sfp != NULL && DoesStringMatchConstraint(sfp->comment, scp))
4713
rval |= SetStringValue ( &(sfp->comment), value, existing_text);
4717
case CDSGeneProt_field_gene_locus:
4718
if (c->gene_list == NULL && scp == NULL) {
4719
sfp = CreateGeneForCGPSet (c);
4721
ValNodeAddPointer (&(c->gene_list), 0, sfp);
4724
for (vnp = c->gene_list; vnp != NULL; vnp = vnp->next) {
4725
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4726
if (sfp != NULL && sfp->data.choice == SEQFEAT_GENE
4727
&& (grp = sfp->data.value.ptrvalue) != NULL
4728
&& DoesStringMatchConstraint(grp->locus, scp))
4730
rval |= SetStringValue ( &(grp->locus), value, existing_text);
4734
case CDSGeneProt_field_gene_description:
4735
for (vnp = c->gene_list; vnp != NULL; vnp = vnp->next) {
4736
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4737
if (sfp != NULL && sfp->data.choice == SEQFEAT_GENE
4738
&& (grp = sfp->data.value.ptrvalue) != NULL
4739
&& DoesStringMatchConstraint(grp->desc, scp))
4741
rval |= SetStringValue ( &(grp->desc), value, existing_text);
4745
case CDSGeneProt_field_gene_comment:
4746
for (vnp = c->gene_list; vnp != NULL; vnp = vnp->next) {
4747
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4748
if (sfp != NULL && DoesStringMatchConstraint(sfp->comment, scp))
4750
rval |= SetStringValue ( &(sfp->comment), value, existing_text);
4754
case CDSGeneProt_field_gene_allele:
4755
for (vnp = c->gene_list; vnp != NULL; vnp = vnp->next) {
4756
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4757
if (sfp != NULL && sfp->data.choice == SEQFEAT_GENE
4758
&& (grp = sfp->data.value.ptrvalue) != NULL
4759
&& DoesStringMatchConstraint(grp->allele, scp))
4761
rval |= SetStringValue (&(grp->allele), value, existing_text);
4765
case CDSGeneProt_field_gene_maploc:
4766
for (vnp = c->gene_list; vnp != NULL; vnp = vnp->next) {
4767
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4768
if (sfp != NULL && sfp->data.choice == SEQFEAT_GENE
4769
&& (grp = sfp->data.value.ptrvalue) != NULL
4770
&& DoesStringMatchConstraint(grp->maploc, scp))
4772
rval |= SetStringValue ( &(grp->maploc), value, existing_text);
4776
case CDSGeneProt_field_gene_locus_tag:
4777
for (vnp = c->gene_list; vnp != NULL; vnp = vnp->next) {
4778
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4779
if (sfp != NULL && sfp->data.choice == SEQFEAT_GENE
4780
&& (grp = sfp->data.value.ptrvalue) != NULL
4781
&& DoesStringMatchConstraint(grp->locus_tag, scp))
4783
rval |= SetStringValue ( &(grp->locus_tag), value, existing_text);
4787
case CDSGeneProt_field_gene_synonym:
4788
for (vnp = c->gene_list; vnp != NULL; vnp = vnp->next) {
4789
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4790
if (sfp != NULL && sfp->data.choice == SEQFEAT_GENE
4791
&& (grp = sfp->data.value.ptrvalue) != NULL)
4793
rval |= SetStringsInValNodeStringList (&(grp->syn), scp, value, existing_text);
4797
case CDSGeneProt_field_gene_old_locus_tag:
4798
for (vnp = c->gene_list; vnp != NULL; vnp = vnp->next) {
4799
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4801
rval |= RemoveGBQualMatch (&(sfp->qual), "old-locus-tag", scp);
4805
case CDSGeneProt_field_mrna_product:
4806
for (vnp = c->mrna_list; vnp != NULL; vnp = vnp->next) {
4807
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4808
rval |= SetRNAProductString (sfp, scp, value, existing_text);
4811
case CDSGeneProt_field_mrna_comment:
4812
for (vnp = c->mrna_list; vnp != NULL; vnp = vnp->next) {
4813
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4814
if (sfp != NULL&& DoesStringMatchConstraint(sfp->comment, scp))
4816
rval |= SetStringValue ( &(sfp->comment), value, existing_text);
4820
case CDSGeneProt_field_prot_name:
4821
for (vnp = c->prot_list; vnp != NULL; vnp = vnp->next) {
4822
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4823
if (sfp != NULL && sfp->data.choice == SEQFEAT_PROT
4824
&& sfp->idx.subtype == FEATDEF_PROT
4825
&& (prp = sfp->data.value.ptrvalue) != NULL)
4827
rval |= SetStringsInValNodeStringList (&(prp->name), scp, value, existing_text);
4831
case CDSGeneProt_field_prot_description:
4832
for (vnp = c->prot_list; vnp != NULL; vnp = vnp->next) {
4833
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4834
if (sfp != NULL && sfp->data.choice == SEQFEAT_PROT
4835
&& sfp->idx.subtype == FEATDEF_PROT
4836
&& (prp = sfp->data.value.ptrvalue) != NULL
4837
&& DoesStringMatchConstraint(prp->desc, scp)) {
4838
rval |= SetStringValue ( &(prp->desc), value, existing_text);
4842
case CDSGeneProt_field_prot_ec_number:
4843
for (vnp = c->prot_list; vnp != NULL; vnp = vnp->next) {
4844
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4845
if (sfp != NULL && sfp->data.choice == SEQFEAT_PROT
4846
&& sfp->idx.subtype == FEATDEF_PROT
4847
&& (prp = sfp->data.value.ptrvalue) != NULL)
4849
rval |= SetStringsInValNodeStringList (&(prp->ec), scp, value, existing_text);
4853
case CDSGeneProt_field_prot_activity:
4854
for (vnp = c->prot_list; vnp != NULL; vnp = vnp->next) {
4855
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4856
if (sfp != NULL && sfp->data.choice == SEQFEAT_PROT
4857
&& sfp->idx.subtype == FEATDEF_PROT
4858
&& (prp = sfp->data.value.ptrvalue) != NULL)
4860
rval |= SetStringsInValNodeStringList (&(prp->activity), scp, value, existing_text);
4864
case CDSGeneProt_field_prot_comment:
4865
for (vnp = c->prot_list; vnp != NULL; vnp = vnp->next) {
4866
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4867
if (sfp != NULL && sfp->idx.subtype == FEATDEF_PROT
4868
&& DoesStringMatchConstraint(sfp->comment, scp))
4870
rval |= SetStringValue ( &(sfp->comment), value, existing_text);
4874
case CDSGeneProt_field_mat_peptide_name:
4875
for (vnp = c->prot_list; vnp != NULL; vnp = vnp->next) {
4876
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4877
if (sfp != NULL && sfp->data.choice == SEQFEAT_PROT
4878
&& sfp->idx.subtype == FEATDEF_mat_peptide_aa
4879
&& (prp = sfp->data.value.ptrvalue) != NULL)
4881
rval |= SetStringsInValNodeStringList (&(prp->name), scp, value, existing_text);
4885
case CDSGeneProt_field_mat_peptide_description:
4886
for (vnp = c->prot_list; vnp != NULL; vnp = vnp->next) {
4887
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4888
if (sfp != NULL && sfp->data.choice == SEQFEAT_PROT
4889
&& sfp->idx.subtype == FEATDEF_mat_peptide_aa
4890
&& (prp = sfp->data.value.ptrvalue) != NULL
4891
&& DoesStringMatchConstraint(prp->desc, scp)) {
4892
rval |= SetStringValue ( &(prp->desc), value, existing_text);
4896
case CDSGeneProt_field_mat_peptide_ec_number:
4897
for (vnp = c->prot_list; vnp != NULL; vnp = vnp->next) {
4898
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4899
if (sfp != NULL && sfp->data.choice == SEQFEAT_PROT
4900
&& sfp->idx.subtype == FEATDEF_mat_peptide_aa
4901
&& (prp = sfp->data.value.ptrvalue) != NULL)
4903
rval |= SetStringsInValNodeStringList (&(prp->ec), scp, value, existing_text);
4907
case CDSGeneProt_field_mat_peptide_activity:
4908
for (vnp = c->prot_list; vnp != NULL; vnp = vnp->next) {
4909
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4910
if (sfp != NULL && sfp->data.choice == SEQFEAT_PROT
4911
&& sfp->idx.subtype == FEATDEF_mat_peptide_aa
4912
&& (prp = sfp->data.value.ptrvalue) != NULL)
4914
rval |= SetStringsInValNodeStringList (&(prp->activity), scp, value, existing_text);
4918
case CDSGeneProt_field_mat_peptide_comment:
4919
for (vnp = c->prot_list; vnp != NULL; vnp = vnp->next) {
4920
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
4921
if (sfp != NULL && sfp->idx.subtype == FEATDEF_mat_peptide_aa
4922
&& DoesStringMatchConstraint(sfp->comment, scp))
4924
rval |= SetStringValue ( &(sfp->comment), value, existing_text);
4933
static MolInfoPtr GetMolInfoForBioseq (BioseqPtr bsp)
4935
MolInfoPtr m = NULL;
4938
if (bsp == NULL) return NULL;
4940
while (sdp != NULL && sdp->choice != Seq_descr_molinfo) {
4944
m = (MolInfoPtr) sdp->data.ptrvalue;
4950
static CharPtr GetSequenceQualFromBioseq (BioseqPtr bsp, ValNodePtr field)
4952
CharPtr rval = NULL;
4955
if (bsp == NULL || field == NULL) return NULL;
4957
switch (field->choice) {
4958
case MolinfoField_molecule:
4959
m = GetMolInfoForBioseq (bsp);
4961
rval = BiomolNameFromBiomol (m->biomol);
4964
case MolinfoField_technique:
4965
m = GetMolInfoForBioseq (bsp);
4967
rval = TechNameFromTech (m->tech);
4970
case MolinfoField_completedness:
4971
m = GetMolInfoForBioseq (bsp);
4973
rval = CompletenessNameFromCompleteness (m->completeness);
4976
case MolinfoField_mol_class:
4977
rval = MolNameFromMol (bsp->mol);
4979
case MolinfoField_topology:
4980
rval = TopologyNameFromTopology (bsp->topology);
4982
case MolinfoField_strand:
4983
rval = StrandNameFromStrand (bsp->strand);
4986
if (rval != NULL) rval = StringSave (rval);
4991
static Boolean RemoveSequenceQualFromBioseq (BioseqPtr bsp, ValNodePtr field)
4994
Boolean rval = FALSE;
4996
if (bsp == NULL || field == NULL) return FALSE;
4998
switch (field->choice) {
4999
case MolinfoField_molecule:
5000
m = GetMolInfoForBioseq (bsp);
5006
case MolinfoField_technique:
5007
m = GetMolInfoForBioseq (bsp);
5013
case MolinfoField_completedness:
5014
m = GetMolInfoForBioseq (bsp);
5016
m->completeness = 0;
5020
case MolinfoField_mol_class:
5024
case MolinfoField_topology:
5028
case MolinfoField_strand:
5037
static MolInfoPtr AddMolInfoToBioseq (BioseqPtr bsp)
5042
sdp = CreateNewDescriptorOnBioseq (bsp, Seq_descr_molinfo);
5044
sdp->data.ptrvalue = m;
5049
static Boolean SetSequenceQualOnBioseq (BioseqPtr bsp, ValNodePtr field)
5052
Boolean rval = FALSE;
5054
if (bsp == NULL || field == NULL) return FALSE;
5056
switch (field->choice) {
5057
case MolinfoField_molecule:
5058
m = GetMolInfoForBioseq (bsp);
5060
m = AddMolInfoToBioseq (bsp);
5062
m->biomol = BiomolFromMoleculeType (field->data.intvalue);
5065
case MolinfoField_technique:
5066
m = GetMolInfoForBioseq (bsp);
5068
m = AddMolInfoToBioseq (bsp);
5070
m->tech = TechFromTechniqueType (field->data.intvalue);
5073
case MolinfoField_completedness:
5074
m = GetMolInfoForBioseq (bsp);
5076
m = AddMolInfoToBioseq (bsp);
5078
m->completeness = CompletenessFromCompletednessType (field->data.intvalue);
5081
case MolinfoField_mol_class:
5082
bsp->mol = MolFromMoleculeClassType (field->data.intvalue);
5085
case MolinfoField_topology:
5086
bsp->topology = TopologyFromTopologyType (field->data.intvalue);
5089
case MolinfoField_strand:
5090
bsp->strand = StrandFromStrandType (field->data.intvalue);
5098
NLM_EXTERN FieldTypePtr GetFromFieldFromFieldPair (FieldPairTypePtr fieldpair)
5100
SourceQualChoicePtr ss = NULL;
5101
SourceQualPairPtr sqpp;
5102
FeatureFieldPairPtr fp;
5104
FieldTypePtr f = NULL;
5105
CDSGeneProtFieldPairPtr cp;
5106
MolinfoFieldPairPtr mp;
5109
if (fieldpair == NULL) return NULL;
5110
switch (fieldpair->choice) {
5111
case FieldPairType_source_qual:
5112
sqpp = (SourceQualPairPtr) fieldpair->data.ptrvalue;
5114
ss = ValNodeNew (NULL);
5115
ss->choice = SourceQualChoice_textqual;
5116
ss->data.intvalue = sqpp->field_from;
5117
f = ValNodeNew (NULL);
5118
f->choice = FieldType_source_qual;
5119
f->data.ptrvalue = ss;
5122
case FieldPairType_feature_field:
5123
fp = (FeatureFieldPairPtr) fieldpair->data.ptrvalue;
5125
fs = FeatureFieldNew ();
5126
fs->type = fp->type;
5127
fs->field = (FeatQualChoicePtr) AsnIoMemCopy (fp->field_from, (AsnReadFunc) FeatQualChoiceAsnRead, (AsnWriteFunc) FeatQualChoiceAsnWrite);
5128
f = ValNodeNew (NULL);
5129
f->choice = FieldType_feature_field;
5130
f->data.ptrvalue = fs;
5133
case FieldPairType_cds_gene_prot:
5134
cp = (CDSGeneProtFieldPairPtr) fieldpair->data.ptrvalue;
5136
f = ValNodeNew (NULL);
5137
f->choice = FieldType_cds_gene_prot;
5138
f->data.intvalue = cp->field_from;
5141
case FieldPairType_molinfo_field:
5142
mp = (MolinfoFieldPairPtr) fieldpair->data.ptrvalue;
5143
if (mp != NULL && mp->data.ptrvalue != NULL) {
5145
switch (mp->choice) {
5146
case MolinfoFieldPair_molecule:
5147
vnp = ValNodeNew (NULL);
5148
vnp->choice = MolinfoField_molecule;
5149
vnp->data.intvalue = ((MolinfoMoleculePairPtr)mp->data.ptrvalue)->from;
5151
case MolinfoFieldPair_technique:
5152
vnp = ValNodeNew (NULL);
5153
vnp->choice = MolinfoField_technique;
5154
vnp->data.intvalue = ((MolinfoTechniquePairPtr)mp->data.ptrvalue)->from;
5156
case MolinfoFieldPair_completedness:
5157
vnp = ValNodeNew (NULL);
5158
vnp->choice = MolinfoField_completedness;
5159
vnp->data.intvalue = ((MolinfoCompletednessPairPtr)mp->data.ptrvalue)->from;
5161
case MolinfoFieldPair_mol_class:
5162
vnp = ValNodeNew (NULL);
5163
vnp->choice = MolinfoField_mol_class;
5164
vnp->data.intvalue = ((MolinfoMolClassPairPtr)mp->data.ptrvalue)->from;
5166
case MolinfoFieldPair_topology:
5167
vnp = ValNodeNew (NULL);
5168
vnp->choice = MolinfoField_topology;
5169
vnp->data.intvalue = ((MolinfoTopologyPairPtr)mp->data.ptrvalue)->from;
5171
case MolinfoFieldPair_strand:
5172
vnp = ValNodeNew (NULL);
5173
vnp->choice = MolinfoField_strand;
5174
vnp->data.intvalue = ((MolinfoStrandPairPtr)mp->data.ptrvalue)->from;
5178
f = ValNodeNew (NULL);
5179
f->choice = FieldType_molinfo_field;
5180
f->data.ptrvalue = vnp;
5189
NLM_EXTERN FieldTypePtr GetToFieldFromFieldPair (FieldPairTypePtr fieldpair)
5191
SourceQualChoicePtr ss = NULL;
5192
SourceQualPairPtr sqpp;
5193
FeatureFieldPairPtr fp;
5195
FieldTypePtr f = NULL;
5196
CDSGeneProtFieldPairPtr cp;
5197
MolinfoFieldPairPtr mp;
5200
if (fieldpair == NULL) return NULL;
5201
switch (fieldpair->choice) {
5202
case FieldPairType_source_qual:
5203
sqpp = (SourceQualPairPtr) fieldpair->data.ptrvalue;
5205
ss = ValNodeNew (NULL);
5206
ss->choice = SourceQualChoice_textqual;
5207
ss->data.intvalue = sqpp->field_to;
5208
f = ValNodeNew (NULL);
5209
f->choice = FieldType_source_qual;
5210
f->data.ptrvalue = ss;
5213
case FieldPairType_feature_field:
5214
fp = (FeatureFieldPairPtr) fieldpair->data.ptrvalue;
5216
fs = FeatureFieldNew ();
5217
fs->type = fp->type;
5218
fs->field = (FeatQualChoicePtr) AsnIoMemCopy (fp->field_to, (AsnReadFunc) FeatQualChoiceAsnRead, (AsnWriteFunc) FeatQualChoiceAsnWrite);
5219
f = ValNodeNew (NULL);
5220
f->choice = FieldType_feature_field;
5221
f->data.ptrvalue = fs;
5224
case FieldPairType_cds_gene_prot:
5225
cp = (CDSGeneProtFieldPairPtr) fieldpair->data.ptrvalue;
5227
f = ValNodeNew (NULL);
5228
f->choice = FieldType_cds_gene_prot;
5229
f->data.intvalue = cp->field_to;
5232
case FieldPairType_molinfo_field:
5233
mp = (MolinfoFieldPairPtr) fieldpair->data.ptrvalue;
5234
if (mp != NULL && mp->data.ptrvalue != NULL) {
5236
switch (mp->choice) {
5237
case MolinfoFieldPair_molecule:
5238
vnp = ValNodeNew (NULL);
5239
vnp->choice = MolinfoField_molecule;
5240
vnp->data.intvalue = ((MolinfoMoleculePairPtr)mp->data.ptrvalue)->to;
5242
case MolinfoFieldPair_technique:
5243
vnp = ValNodeNew (NULL);
5244
vnp->choice = MolinfoField_technique;
5245
vnp->data.intvalue = ((MolinfoTechniquePairPtr)mp->data.ptrvalue)->to;
5247
case MolinfoFieldPair_completedness:
5248
vnp = ValNodeNew (NULL);
5249
vnp->choice = MolinfoField_completedness;
5250
vnp->data.intvalue = ((MolinfoCompletednessPairPtr)mp->data.ptrvalue)->to;
5252
case MolinfoFieldPair_mol_class:
5253
vnp = ValNodeNew (NULL);
5254
vnp->choice = MolinfoField_mol_class;
5255
vnp->data.intvalue = ((MolinfoMolClassPairPtr)mp->data.ptrvalue)->to;
5257
case MolinfoFieldPair_topology:
5258
vnp = ValNodeNew (NULL);
5259
vnp->choice = MolinfoField_topology;
5260
vnp->data.intvalue = ((MolinfoTopologyPairPtr)mp->data.ptrvalue)->to;
5262
case MolinfoFieldPair_strand:
5263
vnp = ValNodeNew (NULL);
5264
vnp->choice = MolinfoField_strand;
5265
vnp->data.intvalue = ((MolinfoStrandPairPtr)mp->data.ptrvalue)->to;
5269
f = ValNodeNew (NULL);
5270
f->choice = FieldType_molinfo_field;
5271
f->data.ptrvalue = vnp;
5280
static Uint1 FieldTypeChoiceFromFieldPairTypeChoice (Uint1 field_pair_choice)
5282
Uint1 field_type_choice = 0;
5284
switch (field_pair_choice) {
5285
case FieldPairType_source_qual:
5286
field_type_choice = FieldType_source_qual;
5288
case FieldPairType_feature_field:
5289
field_type_choice = FieldType_feature_field;
5291
case FieldPairType_cds_gene_prot:
5292
field_type_choice = FieldType_cds_gene_prot;
5294
case FieldPairType_molinfo_field:
5295
field_type_choice = FieldType_molinfo_field;
5299
return field_type_choice;
5303
NLM_EXTERN Uint1 FieldTypeFromAECRAction (AECRActionPtr action)
5305
Uint1 field_type = 0;
5312
AECRParseActionPtr p;
5314
if (action == NULL || action->action == NULL || action->action->data.ptrvalue == NULL) {
5317
switch (action->action->choice) {
5318
case ActionChoice_apply:
5319
a = (ApplyActionPtr) action->action->data.ptrvalue;
5320
if (a->field != NULL) {
5321
field_type = a->field->choice;
5324
case ActionChoice_edit:
5325
e = (EditActionPtr) action->action->data.ptrvalue;
5326
if (e->field != NULL) {
5327
field_type = e->field->choice;
5330
case ActionChoice_convert:
5331
v = (ConvertActionPtr) action->action->data.ptrvalue;
5332
field_type = FieldTypeChoiceFromFieldPairTypeChoice (v->fields->choice);
5334
case ActionChoice_copy:
5335
c = (CopyActionPtr) action->action->data.ptrvalue;
5336
field_type = FieldTypeChoiceFromFieldPairTypeChoice (c->fields->choice);
5338
case ActionChoice_swap:
5339
s = (SwapActionPtr) action->action->data.ptrvalue;
5340
field_type = FieldTypeChoiceFromFieldPairTypeChoice (s->fields->choice);
5342
case ActionChoice_remove:
5343
r = (RemoveActionPtr) action->action->data.ptrvalue;
5344
if (r->field != NULL) {
5345
field_type = r->field->choice;
5348
case ActionChoice_parse:
5349
p = (AECRParseActionPtr) action->action->data.ptrvalue;
5350
field_type = FieldTypeChoiceFromFieldPairTypeChoice (p->fields->choice);
5357
static CharPtr GetFieldValueForObject (Uint1 choice, Pointer data, FieldTypePtr field, StringConstraintPtr scp)
5360
FeatureFieldPtr feature_field;
5362
if (data == NULL || field == NULL || field->data.ptrvalue == NULL) return FALSE;
5364
switch (field->choice) {
5365
case FieldType_source_qual :
5366
str = GetSourceQualFromBioSource (GetBioSourceFromObject (choice, data), (SourceQualChoicePtr) field->data.ptrvalue, scp);
5368
case FieldType_feature_field :
5369
if (choice == OBJ_SEQFEAT) {
5370
str = GetQualFromFeature ((SeqFeatPtr) data, (FeatureFieldPtr) field->data.ptrvalue, scp);
5373
case FieldType_cds_gene_prot :
5375
str = GetFieldValueFromCGPSet ((CGPSetPtr) data, field->data.intvalue, scp);
5376
} else if (choice == OBJ_SEQFEAT) {
5377
feature_field = FeatureFieldFromCDSGeneProtField (field->data.intvalue);
5378
str = GetQualFromFeature ((SeqFeatPtr) data, feature_field, scp);
5379
feature_field = FeatureFieldFree (feature_field);
5382
case FieldType_molinfo_field :
5383
if (choice == OBJ_BIOSEQ) {
5384
str = GetSequenceQualFromBioseq ((BioseqPtr) data, field->data.ptrvalue);
5392
static Boolean RemoveFieldValueForObject (Uint1 choice, Pointer data, FieldTypePtr field, StringConstraintPtr scp)
5394
Boolean rval = FALSE;
5395
FeatureFieldPtr feature_field;
5397
if (data == NULL || field == NULL || field->data.ptrvalue == NULL) return FALSE;
5399
switch (field->choice) {
5400
case FieldType_source_qual :
5401
rval = RemoveSourceQualFromBioSource (GetBioSourceFromObject (choice, data), (SourceQualChoicePtr) field->data.ptrvalue, scp);
5403
case FieldType_feature_field :
5404
if (choice == OBJ_SEQFEAT) {
5405
rval = RemoveQualFromFeature ((SeqFeatPtr) data, (FeatureFieldPtr) field->data.ptrvalue, scp);
5408
case FieldType_cds_gene_prot:
5410
rval = RemoveFieldValueFromCGPSet ((CGPSetPtr) data, field->data.intvalue, scp);
5411
} else if (choice == OBJ_SEQFEAT) {
5412
feature_field = FeatureFieldFromCDSGeneProtField (field->data.intvalue);
5413
rval = RemoveQualFromFeature ((SeqFeatPtr) data, feature_field, scp);
5414
feature_field = FeatureFieldFree (feature_field);
5417
case FieldType_molinfo_field :
5418
if (choice == OBJ_BIOSEQ) {
5419
rval = RemoveSequenceQualFromBioseq ((BioseqPtr) data, field->data.ptrvalue);
5427
static Boolean SetFieldValueForObject (Uint1 choice, Pointer data, FieldTypePtr field, StringConstraintPtr scp, CharPtr value, Uint2 existing_text)
5429
Boolean rval = FALSE;
5430
FeatureFieldPtr feature_field;
5432
if (data == NULL || field == NULL || field->data.ptrvalue == NULL) return FALSE;
5434
switch (field->choice) {
5435
case FieldType_source_qual :
5436
rval = SetSourceQualInBioSource (GetBioSourceFromObject (choice, data), (SourceQualChoicePtr) field->data.ptrvalue, scp, value, existing_text);
5438
case FieldType_feature_field :
5439
if (choice == OBJ_SEQFEAT) {
5440
rval = SetQualOnFeature ((SeqFeatPtr) data, (FeatureFieldPtr) field->data.ptrvalue, scp, value, existing_text);
5443
case FieldType_cds_gene_prot:
5445
rval = SetFieldValueInCGPSet ((CGPSetPtr) data, field->data.intvalue, scp, value, existing_text);
5446
} else if (choice == OBJ_SEQFEAT) {
5447
feature_field = FeatureFieldFromCDSGeneProtField (field->data.intvalue);
5448
rval = SetQualOnFeature ((SeqFeatPtr) data, feature_field, scp, value, existing_text);
5449
feature_field = FeatureFieldFree (feature_field);
5452
case FieldType_molinfo_field:
5453
if (choice == OBJ_BIOSEQ) {
5454
rval = SetSequenceQualOnBioseq ((BioseqPtr) data, field->data.ptrvalue);
5462
static Boolean IsObjectAppropriateForFieldValue (Uint1 choice, Pointer data, FieldTypePtr field)
5467
Boolean rval = FALSE;
5469
if (data == NULL || field == NULL) return FALSE;
5471
switch (field->choice) {
5472
case FieldType_source_qual :
5473
if (choice == OBJ_SEQFEAT) {
5474
sfp = (SeqFeatPtr) data;
5475
if (sfp->data.choice == SEQFEAT_BIOSRC) {
5478
} else if (choice == OBJ_SEQDESC) {
5479
sdp = (SeqDescrPtr) data;
5480
if (sdp->choice == Seq_descr_source) {
5485
case FieldType_feature_field :
5486
if (choice == OBJ_SEQFEAT) {
5487
sfp = (SeqFeatPtr) data;
5488
fp = (FeatureFieldPtr) field->data.ptrvalue;
5489
if (fp != NULL && (fp->type == Feature_type_any || GetFeatdefFromFeatureType (fp->type) == sfp->idx.subtype)) {
5494
case FieldType_cds_gene_prot :
5499
case FieldType_molinfo_field :
5500
if (choice == OBJ_BIOSEQ) {
5509
static Boolean IsObjectAppropriateForFieldPair (Uint1 choice, Pointer data, FieldPairTypePtr fieldpair)
5514
f = GetFromFieldFromFieldPair(fieldpair);
5515
rval = IsObjectAppropriateForFieldValue(choice, data, f);
5516
f = FieldTypeFree (f);
5521
static Boolean DoFieldTypesMatch (FieldTypePtr field1, FieldTypePtr field2)
5523
Boolean rval = FALSE;
5524
SourceQualChoicePtr scp1, scp2;
5525
FeatureFieldPtr fp1, fp2;
5527
if (field1 == NULL || field2 == NULL) return FALSE;
5528
if (field1->choice != field2->choice) return FALSE;
5530
switch (field1->choice) {
5531
case FieldType_source_qual :
5532
scp1 = (SourceQualChoicePtr) field1->data.ptrvalue;
5533
scp2 = (SourceQualChoicePtr) field2->data.ptrvalue;
5534
if (scp1 != NULL && scp2 != NULL && scp1->choice == scp2->choice) {
5535
switch (scp1->choice) {
5536
case SourceQualChoice_textqual:
5537
if (scp1->data.intvalue == scp2->data.intvalue) {
5541
case SourceQualChoice_location:
5542
case SourceQualChoice_origin:
5548
case FieldType_feature_field :
5549
fp1 = (FeatureFieldPtr) field1->data.ptrvalue;
5550
fp2 = (FeatureFieldPtr) field2->data.ptrvalue;
5551
if (fp1 != NULL && fp2 != NULL
5552
&& (fp1->type == fp2->type || fp1->type == Feature_type_any || fp2->type == Feature_type_any)
5553
&& fp1->field != NULL && fp2->field != NULL
5554
&& fp1->field->choice == FeatQualChoice_legal_qual && fp2->field->choice == FeatQualChoice_legal_qual
5555
&& fp1->field->data.intvalue == fp2->field->data.intvalue) {
5559
case FieldType_cds_gene_prot :
5560
if (field1->data.intvalue == field2->data.intvalue) {
5569
static Boolean IsNonTextSourceQualPresent (BioSourcePtr biop, Int4 srcqual)
5571
Int4 orgmod_subtype, subsrc_subtype;
5574
Boolean rval = FALSE;
5576
if (biop == NULL) return FALSE;
5578
orgmod_subtype = GetOrgModQualFromSrcQual (srcqual);
5579
if (orgmod_subtype == -1) {
5580
subsrc_subtype = GetSubSrcQualFromSrcQual (srcqual);
5581
for (ssp = biop->subtype; ssp != NULL && !rval; ssp = ssp->next) {
5582
if (ssp->subtype == subsrc_subtype) {
5587
if (biop->org != NULL && biop->org->orgname != NULL) {
5588
for (mod = biop->org->orgname->mod; mod != NULL && !rval; mod = mod->next) {
5589
if (mod->subtype == orgmod_subtype) {
5599
static Boolean IsSourceQualPresent (BioSourcePtr biop, SourceQualChoicePtr scp)
5601
Boolean rval = FALSE;
5604
if (biop == NULL) return FALSE;
5605
if (scp == NULL) return TRUE;
5607
switch (scp->choice) {
5608
case SourceQualChoice_textqual:
5609
if (IsNonTextSourceQual (scp->data.intvalue)) {
5610
rval = IsNonTextSourceQualPresent (biop, scp->data.intvalue);
5612
str = GetSourceQualFromBioSource (biop, scp, NULL);
5613
if (!StringHasNoText (str)) {
5616
str = MemFree (str);
5619
case SourceQualChoice_location:
5620
if (biop->genome != 0) {
5624
case SourceQualChoice_origin:
5625
if (biop->origin != 0) {
5634
typedef struct objecthasstring
5636
StringConstraintPtr scp;
5638
} ObjectHasStringData, PNTR ObjectHasStringPtr;
5641
static void LIBCALLBACK AsnWriteConstraintCallBack (AsnExpOptStructPtr pAEOS)
5645
ObjectHasStringPtr ohsp;
5647
ohsp = (ObjectHasStringPtr) pAEOS->data;
5648
if (ISA_STRINGTYPE (AsnFindBaseIsa (pAEOS->atp)))
5650
pchSource = (CharPtr) pAEOS->dvp->ptrvalue;
5651
ohsp->found |= DoesSingleStringMatchConstraint (pchSource, ohsp->scp);
5656
static Boolean DoesObjectMatchStringConstraint (Uint1 choice, Pointer data, StringConstraintPtr scp)
5663
ObjectHasStringData ohsd;
5664
SeqFeatPtr sfp, prot;
5665
SeqMgrFeatContext fcontext;
5669
Boolean all_match = TRUE, any_match = FALSE, rval;
5672
if (data == NULL) return FALSE;
5673
if (scp == NULL) return TRUE;
5676
/* CDS-Gene-Prot set */
5677
c = (CGPSetPtr) data;
5678
for (vnp = c->gene_list; vnp != NULL && (!any_match || all_match); vnp = vnp->next) {
5679
if (DoesObjectMatchStringConstraint (OBJ_SEQFEAT, vnp->data.ptrvalue, scp)) {
5685
for (vnp = c->cds_list; vnp != NULL && (!any_match || all_match); vnp = vnp->next) {
5686
if (DoesObjectMatchStringConstraint (OBJ_SEQFEAT, vnp->data.ptrvalue, scp)) {
5692
for (vnp = c->mrna_list; vnp != NULL && (!any_match || all_match); vnp = vnp->next) {
5693
if (DoesObjectMatchStringConstraint (OBJ_SEQFEAT, vnp->data.ptrvalue, scp)) {
5699
for (vnp = c->prot_list; vnp != NULL && (!any_match || all_match); vnp = vnp->next) {
5700
if (DoesObjectMatchStringConstraint (OBJ_SEQFEAT, vnp->data.ptrvalue, scp)) {
5706
if (scp->not_present) {
5713
omtp = ObjMgrTypeFind (omp, choice, NULL, NULL);
5714
if (omtp == NULL) return FALSE;
5715
aip = AsnIoNullOpen ();
5716
aeop = AsnExpOptNew (aip, NULL, NULL, AsnWriteConstraintCallBack);
5720
aeop->user_data = (Pointer) &ohsd;
5723
(omtp->asnwrite) (data, aip, NULL);
5725
if (!ohsd.found && omtp->datatype == OBJ_SEQFEAT)
5727
sfp = (SeqFeatPtr) data;
5728
if (sfp->data.choice == SEQFEAT_CDREGION) {
5729
protbsp = BioseqFindFromSeqLoc (sfp->product);
5730
prot = SeqMgrGetNextFeature (protbsp, NULL, 0, FEATDEF_PROT, &fcontext);
5732
(omtp->asnwrite) (prot, aip, NULL);
5735
if (SeqMgrFeaturesAreIndexed(sfp->idx.entityID) == 0) {
5736
SeqMgrIndexFeatures (sfp->idx.entityID, NULL);
5738
if (sfp->idx.subtype == FEATDEF_tRNA) {
5739
sfp = SeqMgrGetDesiredFeature (sfp->idx.entityID, NULL, sfp->idx.itemID, 0, sfp, &fcontext);
5740
ohsd.found = DoesSingleStringMatchConstraint (fcontext.label, ohsd.scp);
5741
if (!ohsd.found && sfp != NULL && sfp->idx.subtype == FEATDEF_tRNA)
5743
search_txt = (CharPtr) MemNew ((StringLen (fcontext.label) + 6) * sizeof (Char));
5744
if (search_txt != NULL)
5746
sprintf (search_txt, "tRNA-%s", fcontext.label);
5747
ohsd.found = DoesSingleStringMatchConstraint (search_txt, ohsd.scp);
5748
search_txt = MemFree (search_txt);
5755
if (scp->not_present) {
5765
NLM_EXTERN Boolean IsSourceConstraintEmpty (SourceConstraintPtr scp)
5767
if (scp == NULL) return TRUE;
5769
if (scp->field1 == NULL
5770
&& scp->field2 == NULL
5771
&& IsStringConstraintEmpty(scp->constraint)) {
5778
NLM_EXTERN Boolean DoesBiosourceMatchConstraint (BioSourcePtr biop, SourceConstraintPtr scp)
5780
Boolean rval = FALSE;
5784
if (biop == NULL) return FALSE;
5785
if (scp == NULL) return TRUE;
5787
if (IsStringConstraintEmpty(scp->constraint)) {
5788
/* looking for qual present */
5789
if (scp->field1 != NULL && scp->field2 == NULL) {
5790
rval = IsSourceQualPresent (biop, scp->field1);
5791
} else if (scp->field2 != NULL && scp->field1 == NULL) {
5792
rval = IsSourceQualPresent (biop, scp->field2);
5793
/* looking for quals to match */
5794
} else if (scp->field1 != NULL && scp->field2 != NULL) {
5795
str1 = GetSourceQualFromBioSource (biop, scp->field1, NULL);
5796
str2 = GetSourceQualFromBioSource (biop, scp->field2, NULL);
5797
if (StringCmp (str1, str2) == 0) {
5800
str1 = MemFree (str1);
5801
str2 = MemFree (str2);
5803
/* nothing specified, automatic match */
5807
if (scp->field1 != NULL && scp->field2 == NULL) {
5808
str1 = GetSourceQualFromBioSource (biop, scp->field1, scp->constraint);
5810
if (scp->constraint->not_present) {
5811
str1 = GetSourceQualFromBioSource (biop, scp->field1, NULL);
5816
} else if (!StringHasNoText (str1)) {
5819
str1 = MemFree (str1);
5820
} else if (scp->field2 != NULL && scp->field1 == NULL) {
5821
str2 = GetSourceQualFromBioSource (biop, scp->field2, scp->constraint);
5823
if (scp->constraint->not_present) {
5824
str2 = GetSourceQualFromBioSource (biop, scp->field2, NULL);
5829
} else if (!StringHasNoText (str2)) {
5832
str2 = MemFree (str2);
5833
} else if (scp->field1 != NULL && scp->field2 != NULL) {
5834
str1 = GetSourceQualFromBioSource (biop, scp->field1, scp->constraint);
5835
str2 = GetSourceQualFromBioSource (biop, scp->field2, scp->constraint);
5836
if (StringCmp (str1, str2) == 0) {
5839
str1 = MemFree (str1);
5840
str2 = MemFree (str2);
5842
/* generic string constraint */
5843
vn.choice = Seq_descr_source;
5846
vn.data.ptrvalue = biop;
5847
rval = DoesObjectMatchStringConstraint (OBJ_SEQDESC, &vn, scp->constraint);
5854
static Boolean DoesCGPSetMatchPseudoConstraint (CGPSetPtr c, CDSGeneProtPseudoConstraintPtr constraint)
5856
Boolean any_pseudo = FALSE;
5859
Boolean rval = FALSE;
5861
if (c == NULL) return FALSE;
5862
if (constraint == NULL) return TRUE;
5864
switch (constraint->feature) {
5865
case CDSGeneProt_feature_type_constraint_gene :
5866
for (vnp = c->gene_list; vnp != NULL && !any_pseudo; vnp = vnp->next) {
5867
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
5868
if (sfp != NULL && sfp->pseudo) {
5873
case CDSGeneProt_feature_type_constraint_mRNA :
5874
for (vnp = c->mrna_list; vnp != NULL && !any_pseudo; vnp = vnp->next) {
5875
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
5876
if (sfp != NULL && sfp->pseudo) {
5881
case CDSGeneProt_feature_type_constraint_cds :
5882
for (vnp = c->mrna_list; vnp != NULL && !any_pseudo; vnp = vnp->next) {
5883
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
5884
if (sfp != NULL && sfp->pseudo) {
5889
case CDSGeneProt_feature_type_constraint_prot :
5890
for (vnp = c->mrna_list; vnp != NULL && !any_pseudo; vnp = vnp->next) {
5891
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
5892
if (sfp != NULL && sfp->pseudo && sfp->idx.subtype == FEATDEF_PROT) {
5897
case CDSGeneProt_feature_type_constraint_mat_peptide :
5898
for (vnp = c->mrna_list; vnp != NULL && !any_pseudo; vnp = vnp->next) {
5899
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
5900
if (sfp != NULL && sfp->pseudo && sfp->idx.subtype == FEATDEF_mat_peptide_aa) {
5907
if ((any_pseudo && constraint->is_pseudo)
5908
|| (!any_pseudo && !constraint->is_pseudo)) {
5915
NLM_EXTERN Boolean IsCDSGeneProtQualConstraintEmpty (CDSGeneProtQualConstraintPtr constraint)
5917
if (constraint == NULL) return TRUE;
5918
if (constraint->field1 == NULL && constraint->field2 == NULL && IsStringConstraintEmpty (constraint->constraint)) {
5926
static Boolean DoesCGPSetMatchQualConstraint (CGPSetPtr c, CDSGeneProtQualConstraintPtr constraint)
5928
Boolean rval = FALSE, any_match = FALSE, all_match = TRUE;
5929
CharPtr str, str1, str2;
5931
if (c == NULL) return FALSE;
5932
if (constraint == NULL) return TRUE;
5934
if (IsStringConstraintEmpty (constraint->constraint)) {
5935
/* looking for qual present */
5936
if (constraint->field1 != NULL && constraint->field2 == NULL) {
5937
str = GetFieldValueFromCGPSet (c, constraint->field1->data.intvalue, NULL);
5940
str = MemFree (str);
5942
} else if (constraint->field2 != NULL && constraint->field1 == NULL) {
5943
str = GetFieldValueFromCGPSet (c, constraint->field2->data.intvalue, NULL);
5947
str = MemFree (str);
5949
/* looking for quals to match */
5950
} else if (constraint->field1 != NULL && constraint->field2 != NULL) {
5951
str1 = GetFieldValueFromCGPSet (c, constraint->field1->data.intvalue, NULL);
5952
str2 = GetFieldValueFromCGPSet (c, constraint->field2->data.intvalue, NULL);
5953
if (StringCmp (str1, str2) == 0) {
5956
str1 = MemFree (str1);
5957
str2 = MemFree (str2);
5959
/* nothing specified, automatic match */
5963
if (constraint->field1 != NULL && constraint->field2 == NULL) {
5964
str1 = GetFieldValueFromCGPSet (c, constraint->field1->data.intvalue, constraint->constraint);
5966
if (constraint->constraint->not_present) {
5967
str1 = GetFieldValueFromCGPSet (c, constraint->field1->data.intvalue, NULL);
5972
} else if (!StringHasNoText (str1)) {
5975
str1 = MemFree (str1);
5976
} else if (constraint->field2 != NULL && constraint->field1 == NULL) {
5977
str2 = GetFieldValueFromCGPSet (c, constraint->field2->data.intvalue, constraint->constraint);
5979
if (constraint->constraint->not_present) {
5980
str2 = GetFieldValueFromCGPSet (c, constraint->field2->data.intvalue, NULL);
5985
} else if (!StringHasNoText (str2)) {
5988
str2 = MemFree (str2);
5989
} else if (constraint->field1 != NULL && constraint->field2 != NULL) {
5990
str1 = GetFieldValueFromCGPSet (c, constraint->field1->data.intvalue, constraint->constraint);
5991
str2 = GetFieldValueFromCGPSet (c, constraint->field2->data.intvalue, constraint->constraint);
5992
if (StringCmp (str1, str2) == 0) {
5995
str1 = MemFree (str1);
5996
str2 = MemFree (str2);
5998
/* generic string constraint */
5999
rval = DoesObjectMatchStringConstraint (0, c, constraint->constraint);
6006
NLM_EXTERN Boolean IsSequenceConstraintEmpty (SequenceConstraintPtr constraint)
6008
if (constraint == NULL) return TRUE;
6009
if (constraint->seqtype != NULL && constraint->seqtype->choice != SequenceConstraintMolTypeConstraint_any) return FALSE;
6010
if (constraint->feature != Feature_type_any) return FALSE;
6011
if (!IsStringConstraintEmpty (constraint->id)) return FALSE;
6016
extern Boolean DoesSeqIDListMeetStringConstraint (SeqIdPtr sip, StringConstraintPtr string_constraint)
6021
Boolean match, changed;
6027
if (string_constraint == NULL)
6034
/* temporary disconnect ID from list */
6038
SeqIdWrite (sip, id, PRINTID_FASTA_LONG, sizeof (id) - 1);
6039
match = DoesSingleStringMatchConstraint (id, string_constraint);
6043
/* remove terminating pipe character */
6044
if (id[StringLen(id) - 1] == '|')
6046
id[StringLen(id) - 1] = 0;
6049
/* remove leading pipe identifier */
6050
cp = StringChr (id, '|');
6066
match = DoesSingleStringMatchConstraint (id, string_constraint);
6069
/* if search text doesn't have ., try ID without version */
6070
if (!match && StringChr (string_constraint->match_text, '.') == NULL)
6072
cp = StringChr (id, '.');
6076
match = DoesSingleStringMatchConstraint (id, string_constraint);
6084
if (string_constraint->not_present)
6095
if (string_constraint->not_present)
6106
typedef struct rnatypebiomol {
6110
} RnaTypeBiomolData, PNTR RnaTypeBiomolPtr;
6112
static RnaTypeBiomolData rna_type_biomol[] = {
6113
{ Sequence_constraint_rnamol_genomic , MOLECULE_TYPE_GENOMIC, "Genomic RNA" } ,
6114
{ Sequence_constraint_rnamol_precursor_RNA , MOLECULE_TYPE_PRE_MRNA , "Precursor RNA" } ,
6115
{ Sequence_constraint_rnamol_mRNA , MOLECULE_TYPE_MRNA , "mRNA [cDNA]" } ,
6116
{ Sequence_constraint_rnamol_rRNA , MOLECULE_TYPE_RRNA , "Ribosomal RNA" } ,
6117
{ Sequence_constraint_rnamol_tRNA , MOLECULE_TYPE_TRNA , "Transfer RNA" } ,
6118
{ Sequence_constraint_rnamol_snRNA , MOLECULE_TYPE_SNRNA , "Small nuclear RNA" } ,
6119
{ Sequence_constraint_rnamol_scRNA , MOLECULE_TYPE_SCRNA , "Small cytoplasmic RNA" } ,
6120
{ Sequence_constraint_rnamol_genomic_mRNA , MOLECULE_TYPE_GENOMIC_MRNA_MIX , "Genomic-mRNA" } ,
6121
{ Sequence_constraint_rnamol_cRNA , MOLECULE_TYPE_CRNA , "cRNA" } ,
6122
{ Sequence_constraint_rnamol_snoRNA , MOLECULE_TYPE_SNORNA , "Small nucleolar RNA" } ,
6123
{ Sequence_constraint_rnamol_transcribed_RNA , MOLECULE_TYPE_TRANSCRIBED_RNA , "Transcribed RNA" } ,
6124
{ Sequence_constraint_rnamol_ncRNA , MOLECULE_TYPE_NCRNA , "Non-coding RNA" } ,
6125
{ Sequence_constraint_rnamol_transfer_messenger_RNA , MOLECULE_TYPE_TMRNA , "Transfer-messenger RNA" } } ;
6127
#define NUM_rna_type_biomol sizeof (rna_type_biomol) / sizeof (RnaTypeBiomolData)
6130
NLM_EXTERN Uint1 GetBiomolForRnaType (Int4 rnatype)
6134
for (i = 0; i < NUM_rna_type_biomol; i++) {
6135
if (rna_type_biomol[i].rnatype == rnatype) {
6136
return rna_type_biomol[i].biomol;
6143
NLM_EXTERN CharPtr GetBiomolNameForRnaType (Int4 rnatype)
6147
for (i = 0; i < NUM_rna_type_biomol; i++) {
6148
if (rna_type_biomol[i].rnatype == rnatype) {
6149
return rna_type_biomol[i].rnamolname;
6152
return "invalid RNA type";
6155
NLM_EXTERN void AddAllRNASubtypesToChoiceList (ValNodePtr PNTR field_list)
6159
if (field_list == NULL) return;
6161
ValNodeAddPointer (field_list, Sequence_constraint_rnamol_any, StringSave ("Any RNA"));
6162
for (i = 0; i < NUM_rna_type_biomol; i++) {
6163
ValNodeAddPointer (field_list, rna_type_biomol[i].rnatype, StringSave (rna_type_biomol[i].rnamolname));
6168
static Boolean DoesSequenceMatchSequenceConstraint (BioseqPtr bsp, SequenceConstraintPtr constraint)
6171
SeqMgrFeatContext fcontext;
6173
SeqMgrDescContext dcontext;
6176
if (bsp == NULL) return FALSE;
6177
if (IsSequenceConstraintEmpty (constraint)) return TRUE;
6179
if (constraint->seqtype != NULL && constraint->seqtype->choice != SequenceConstraintMolTypeConstraint_any) {
6180
switch (constraint->seqtype->choice) {
6181
case SequenceConstraintMolTypeConstraint_nucleotide :
6182
if (ISA_aa (bsp->mol)) {
6186
case SequenceConstraintMolTypeConstraint_dna :
6187
if (bsp->mol != Seq_mol_dna) {
6191
case SequenceConstraintMolTypeConstraint_rna :
6192
if (bsp->mol != Seq_mol_rna) {
6195
if (constraint->seqtype->data.intvalue != Sequence_constraint_rnamol_any) {
6196
sdp = SeqMgrGetNextDescriptor (bsp, NULL, Seq_descr_molinfo, &dcontext);
6197
if (sdp == NULL || sdp->data.ptrvalue == NULL || sdp->choice != Seq_descr_molinfo) {
6200
mip = (MolInfoPtr) sdp->data.ptrvalue;
6201
if (GetBiomolForRnaType (constraint->seqtype->data.intvalue) != mip->biomol) {
6206
case SequenceConstraintMolTypeConstraint_protein :
6207
if (!ISA_aa (bsp->mol)) {
6214
if (constraint->feature != Feature_type_any) {
6215
sfp = SeqMgrGetNextFeature (bsp, NULL, 0, GetFeatdefFromFeatureType (constraint->feature), &fcontext);
6221
if (!IsStringConstraintEmpty (constraint->id) && !DoesSeqIDListMeetStringConstraint (bsp->id, constraint->id)) {
6227
static Boolean DoesSequenceInSetMatchSequenceConstraint (BioseqSetPtr bssp, SequenceConstraintPtr constraint)
6229
Boolean rval = FALSE;
6232
if (bssp == NULL) return FALSE;
6233
if (IsSequenceConstraintEmpty (constraint)) return TRUE;
6235
for (sep = bssp->seq_set; sep != NULL && !rval; sep = sep->next) {
6236
if (IS_Bioseq (sep)) {
6237
rval = DoesSequenceMatchSequenceConstraint ((BioseqPtr) sep->data.ptrvalue, constraint);
6238
} else if (IS_Bioseq_set (sep)) {
6239
rval = DoesSequenceInSetMatchSequenceConstraint ((BioseqSetPtr) sep->data.ptrvalue, constraint);
6246
static Boolean DoesObjectMatchSequenceConstraint (Uint1 choice, Pointer data, SequenceConstraintPtr constraint)
6251
Boolean rval = FALSE;
6253
if (data == NULL) return FALSE;
6254
if (IsSequenceConstraintEmpty (constraint)) return TRUE;
6256
bsp = GetSequenceForObject (choice, data);
6258
if (choice == OBJ_SEQDESC) {
6259
sdp = (SeqDescrPtr) data;
6260
if (sdp->extended) {
6261
ovp = (ObjValNodePtr) sdp;
6262
if (ovp->idx.parenttype == OBJ_BIOSEQSET && ovp->idx.parentptr != NULL) {
6263
rval = DoesSequenceInSetMatchSequenceConstraint ((BioseqSetPtr) ovp->idx.parentptr, constraint);
6268
rval = DoesSequenceMatchSequenceConstraint (bsp, constraint);
6274
static Boolean DoesObjectMatchConstraint (Uint1 choice, Pointer data, ConstraintChoicePtr constraint)
6276
Boolean rval = TRUE;
6278
if (data == NULL) return FALSE;
6279
if (constraint == NULL) return TRUE;
6281
switch (constraint->choice) {
6282
case ConstraintChoice_string :
6283
rval = DoesObjectMatchStringConstraint (choice, data, constraint->data.ptrvalue);
6285
case ConstraintChoice_location :
6286
rval = DoesObjectMatchLocationConstraint (choice, data, constraint->data.ptrvalue);
6288
case ConstraintChoice_source :
6289
rval = DoesBiosourceMatchConstraint (GetBioSourceFromObject (choice, data), constraint->data.ptrvalue);
6291
case ConstraintChoice_cdsgeneprot_qual :
6293
rval = DoesCGPSetMatchQualConstraint (data, constraint->data.ptrvalue);
6298
case ConstraintChoice_cdsgeneprot_pseudo :
6300
rval = DoesCGPSetMatchPseudoConstraint (data, constraint->data.ptrvalue);
6305
case ConstraintChoice_sequence :
6306
rval = DoesObjectMatchSequenceConstraint (choice, data, constraint->data.ptrvalue);
6313
static Boolean DoesObjectMatchConstraintChoiceSet (Uint1 choice, Pointer data, ConstraintChoiceSetPtr csp)
6315
Boolean rval = TRUE;
6317
if (data == NULL) return FALSE;
6319
while (csp != NULL && rval) {
6320
rval = DoesObjectMatchConstraint (choice, data, csp);
6327
NLM_EXTERN StringConstraintPtr FindStringConstraintInConstraintSetForField (FieldTypePtr field, ConstraintChoiceSetPtr csp)
6329
StringConstraintPtr scp = NULL;
6330
ConstraintChoicePtr constraint;
6331
SourceConstraintPtr source_constraint;
6332
CDSGeneProtQualConstraintPtr cgp_constraint;
6334
while (csp != NULL) {
6335
constraint = (ConstraintChoicePtr) csp->data.ptrvalue;
6336
switch (constraint->choice) {
6337
case ConstraintChoice_string :
6338
scp = constraint->data.ptrvalue;
6340
case ConstraintChoice_source :
6341
source_constraint = (SourceConstraintPtr) constraint->data.ptrvalue;
6342
if (source_constraint != NULL && source_constraint->constraint != NULL
6343
&& ((source_constraint->field1 != NULL
6344
&& DoFieldTypesMatch (field, source_constraint->field1))
6345
|| (source_constraint->field2 != NULL
6346
&& DoFieldTypesMatch (field, source_constraint->field2)))) {
6347
scp = source_constraint->constraint;
6350
case ConstraintChoice_cdsgeneprot_qual :
6351
cgp_constraint = (CDSGeneProtQualConstraintPtr) field->data.ptrvalue;
6352
if (field->choice == FieldType_cds_gene_prot
6353
&& cgp_constraint != NULL && cgp_constraint->constraint != NULL
6354
&& ((cgp_constraint->field1 != NULL && cgp_constraint->field1->data.intvalue == field->data.intvalue)
6355
|| (cgp_constraint->field2 != NULL && cgp_constraint->field2->data.intvalue == field->data.intvalue))) {
6356
scp = cgp_constraint->constraint;
6366
NLM_EXTERN StringConstraintPtr FindStringConstraintInConstraintSetForFieldPair (FieldPairTypePtr fieldpair, ConstraintChoiceSetPtr csp)
6368
StringConstraintPtr scp;
6371
f = GetFromFieldFromFieldPair (fieldpair);
6372
scp = FindStringConstraintInConstraintSetForField (f, csp);
6373
f = FieldTypeFree (f);
6378
NLM_EXTERN StringConstraintPtr StringConstraintFromFieldEdit (FieldEditPtr edit)
6380
StringConstraintPtr scp;
6382
if (edit == NULL || edit->find_txt == NULL) return NULL;
6383
scp = StringConstraintNew ();
6384
scp->match_text = StringSave (edit->find_txt);
6386
switch (edit->location) {
6387
case Field_edit_location_anywhere :
6388
scp->match_location = String_location_contains;
6390
case Field_edit_location_beginning :
6391
scp->match_location = String_location_starts;
6393
case Field_edit_location_end :
6394
scp->match_location = String_location_ends;
6398
scp->case_sensitive = TRUE;
6399
scp->whole_word = FALSE;
6400
scp->not_present = FALSE;
6406
static CharPtr ApplyEditToString (CharPtr str, FieldEditPtr edit)
6408
CharPtr cp_found, new_str;
6409
Int4 found_len, replace_len, new_len;
6411
if (edit == NULL) return StringSave (str);
6413
str = StringSave (str);
6414
cp_found = StringISearch (str, edit->find_txt);
6416
found_len = StringLen (edit->find_txt);
6417
replace_len = StringLen (edit->repl_txt);
6418
if (edit->location == Field_edit_location_beginning
6419
&& cp_found != str) {
6422
while (cp_found != NULL)
6424
if (edit->location == Field_edit_location_end
6425
&& cp_found != str + StringLen (str) - found_len) {
6426
cp_found = StringISearch (cp_found + found_len, edit->find_txt);
6428
new_len = StringLen (str) + 1 - found_len + replace_len;
6429
new_str = (CharPtr) MemNew (new_len * sizeof (Char));
6430
if (new_str != NULL)
6432
if (cp_found != str)
6434
StringNCpy (new_str, str, cp_found - str);
6436
StringCat (new_str, edit->repl_txt);
6437
StringCat (new_str, cp_found + found_len);
6438
cp_found = new_str + (cp_found - str) + replace_len;
6439
str = MemFree (str);
6442
cp_found = StringISearch (cp_found, edit->find_txt);
6449
typedef struct objectcollection {
6450
AECRActionPtr action;
6451
ValNodePtr object_list;
6452
} ObjectCollectionData, PNTR ObjectCollectionPtr;
6455
static void AECRActionObjectCollectionItemCallback (Uint1 objecttype, Pointer objectdata, ObjectCollectionPtr o)
6463
AECRParseActionPtr p;
6464
CharPtr str, portion;
6465
StringConstraintPtr scp;
6466
FieldTypePtr field_from = NULL, field_to = NULL;
6468
if (objectdata == NULL || o == NULL) return;
6470
/* check to make sure object is appropriate for field and meets filter */
6471
switch (o->action->action->choice) {
6472
case ActionChoice_apply :
6473
a = (ApplyActionPtr) o->action->action->data.ptrvalue;
6475
&& IsObjectAppropriateForFieldValue (objecttype, objectdata, a->field)
6476
&& DoesObjectMatchConstraintChoiceSet (objecttype, objectdata, o->action->constraint)) {
6477
ValNodeAddPointer (&(o->object_list), objecttype, objectdata);
6480
case ActionChoice_edit :
6481
e = (EditActionPtr) o->action->action->data.ptrvalue;
6483
&& IsObjectAppropriateForFieldValue (objecttype, objectdata, e->field)
6484
&& DoesObjectMatchConstraintChoiceSet (objecttype, objectdata, o->action->constraint)) {
6485
scp = StringConstraintFromFieldEdit (e->edit);
6486
str = GetFieldValueForObject (objecttype, objectdata, e->field, scp);
6487
if (!StringHasNoText (str)) {
6488
ValNodeAddPointer (&(o->object_list), objecttype, objectdata);
6490
str = MemFree (str);
6493
case ActionChoice_convert :
6494
v = (ConvertActionPtr) o->action->action->data.ptrvalue;
6496
&& (field_from = GetFromFieldFromFieldPair(v->fields)) != NULL
6497
&& IsObjectAppropriateForFieldValue (objecttype, objectdata, field_from)
6498
&& DoesObjectMatchConstraintChoiceSet (objecttype, objectdata, o->action->constraint)) {
6499
scp = FindStringConstraintInConstraintSetForField (field_from, o->action->constraint);
6500
str = GetFieldValueForObject (objecttype, objectdata, field_from, scp);
6501
if (!StringHasNoText (str)) {
6502
ValNodeAddPointer (&(o->object_list), objecttype, objectdata);
6504
str = MemFree (str);
6506
field_from = FieldTypeFree (field_from);
6508
case ActionChoice_copy :
6509
c = (CopyActionPtr) o->action->action->data.ptrvalue;
6511
&& (field_from = GetFromFieldFromFieldPair(c->fields)) != NULL
6512
&& (field_to = GetFromFieldFromFieldPair(c->fields)) != NULL
6513
&& IsObjectAppropriateForFieldValue (objecttype, objectdata, field_from)
6514
&& IsObjectAppropriateForFieldValue (objecttype, objectdata, field_to)
6515
&& DoesObjectMatchConstraintChoiceSet (objecttype, objectdata, o->action->constraint)) {
6516
ValNodeAddPointer (&(o->object_list), objecttype, objectdata);
6518
field_from = FieldTypeFree (field_from);
6519
field_to = FieldTypeFree (field_to);
6521
case ActionChoice_swap :
6522
s = (SwapActionPtr) o->action->action->data.ptrvalue;
6524
&& (field_from = GetFromFieldFromFieldPair(s->fields)) != NULL
6525
&& (field_to = GetFromFieldFromFieldPair(s->fields)) != NULL
6526
&& IsObjectAppropriateForFieldValue (objecttype, objectdata, field_from)
6527
&& IsObjectAppropriateForFieldValue (objecttype, objectdata, field_to)
6528
&& DoesObjectMatchConstraintChoiceSet (objecttype, objectdata, o->action->constraint)) {
6529
ValNodeAddPointer (&(o->object_list), objecttype, objectdata);
6531
field_from = FieldTypeFree (field_from);
6532
field_to = FieldTypeFree (field_to);
6534
case ActionChoice_remove :
6535
r = (RemoveActionPtr) o->action->action->data.ptrvalue;
6537
&& IsObjectAppropriateForFieldValue (objecttype, objectdata, r->field)
6538
&& DoesObjectMatchConstraintChoiceSet (objecttype, objectdata, o->action->constraint)) {
6539
ValNodeAddPointer (&(o->object_list), objecttype, objectdata);
6542
case ActionChoice_parse :
6543
p = (AECRParseActionPtr) o->action->action->data.ptrvalue;
6545
&& (field_from = GetFromFieldFromFieldPair(p->fields)) != NULL
6546
&& (field_to = GetFromFieldFromFieldPair(p->fields)) != NULL
6547
&& IsObjectAppropriateForFieldValue (objecttype, objectdata, field_from)
6548
&& IsObjectAppropriateForFieldValue (objecttype, objectdata, field_to)
6549
&& DoesObjectMatchConstraintChoiceSet (objecttype, objectdata, o->action->constraint)) {
6550
scp = FindStringConstraintInConstraintSetForField (field_from, o->action->constraint);
6551
str = GetFieldValueForObject (objecttype, objectdata, field_from, scp);
6552
portion = GetTextPortionFromString (str, p->portion);
6553
if (!StringHasNoText (portion)) {
6554
ValNodeAddPointer (&(o->object_list), objecttype, objectdata);
6556
portion = MemFree (portion);
6557
str = MemFree (str);
6559
field_from = FieldTypeFree (field_from);
6560
field_to = FieldTypeFree (field_to);
6567
static void AECRActionObjectCollectionFeatureCallback (SeqFeatPtr sfp, Pointer data)
6569
ObjectCollectionPtr o;
6570
if (sfp == NULL || data == NULL) return;
6572
o = (ObjectCollectionPtr) data;
6573
AECRActionObjectCollectionItemCallback (OBJ_SEQFEAT, sfp, o);
6578
static void AECRActionObjectCollectionDescriptorCallback (SeqDescrPtr sdp, Pointer data)
6580
ObjectCollectionPtr o;
6582
if (sdp == NULL || data == NULL) return;
6584
o = (ObjectCollectionPtr) data;
6585
AECRActionObjectCollectionItemCallback (OBJ_SEQDESC, sdp, o);
6589
static void AECRObjectCollectionBioseqCallback (BioseqPtr bsp, Pointer data)
6591
ObjectCollectionPtr o;
6593
if (bsp == NULL || data == NULL) return;
6595
o = (ObjectCollectionPtr) data;
6596
AECRActionObjectCollectionItemCallback (OBJ_BIOSEQ, bsp, o);
6600
NLM_EXTERN ValNodePtr GetObjectListForAECRAction (SeqEntryPtr sep, AECRActionPtr action)
6602
ObjectCollectionData ocd;
6604
ocd.action = action;
6605
ocd.object_list = NULL;
6607
if (action == NULL) return NULL;
6608
if (FieldTypeFromAECRAction (action) == FieldType_molinfo_field) {
6609
VisitBioseqsInSep (sep, &ocd, AECRObjectCollectionBioseqCallback);
6611
VisitFeaturesInSep (sep, &ocd, AECRActionObjectCollectionFeatureCallback);
6612
VisitDescriptorsInSep (sep, &ocd, AECRActionObjectCollectionDescriptorCallback);
6614
return ocd.object_list;
6618
typedef struct buildcgpset
6620
ValNodePtr cds_list;
6621
ValNodePtr mrna_list;
6622
ValNodePtr gene_list;
6623
} BuildCGPSetData, PNTR BuildCGPSetPtr;
6625
static void BuildCGPSetCallback (SeqFeatPtr sfp, Pointer userdata)
6629
if (sfp == NULL || sfp->idx.deleteme || userdata == NULL) return;
6630
b = (BuildCGPSetPtr) userdata;
6631
if (sfp->data.choice == SEQFEAT_CDREGION)
6633
ValNodeAddPointer (&(b->cds_list), OBJ_SEQFEAT, sfp);
6635
else if (sfp->data.choice == SEQFEAT_GENE)
6637
ValNodeAddPointer (&(b->gene_list), OBJ_SEQFEAT, sfp);
6639
else if (sfp->idx.subtype == FEATDEF_mRNA)
6641
ValNodeAddPointer (&(b->mrna_list), OBJ_SEQFEAT, sfp);
6643
else if (SeqMgrGetGeneXref (sfp) != NULL)
6645
ValNodeAddPointer (&(b->gene_list), OBJ_SEQFEAT, sfp);
6650
static CGPSetPtr BuildCGPSetFromCodingRegion (SeqFeatPtr cds, BoolPtr indexing_needed)
6652
SeqMgrFeatContext fcontext;
6653
SeqFeatPtr gene = NULL, mrna, prot;
6658
if (cds == NULL || cds->data.choice != SEQFEAT_CDREGION) return NULL;
6660
cdsp = (CGPSetPtr) MemNew (sizeof (CGPSetData));
6661
ValNodeAddPointer (&(cdsp->cds_list), 0, cds);
6663
gene = GetGeneForFeature (cds);
6666
ValNodeAddPointer (&(cdsp->gene_list), 0, gene);
6667
/* mark gene, so that we'll know it isn't lonely */
6668
gene->idx.deleteme = TRUE;
6671
mrna = SeqMgrGetOverlappingmRNA (cds->location, &fcontext);
6674
ValNodeAddPointer (&(cdsp->mrna_list), 0, mrna);
6675
/* mark mrna, so that we'll know it's already in a set */
6676
mrna->idx.deleteme = TRUE;
6679
if (cds->product != NULL)
6681
protbsp = BioseqFindFromSeqLoc (cds->product);
6682
if (protbsp != NULL)
6684
prot = SeqMgrGetNextFeature (protbsp, NULL, SEQFEAT_PROT, FEATDEF_PROT, &fcontext);
6685
/* if there is no full-length protein feature, make one */
6688
prp = ProtRefNew ();
6689
prot = CreateNewFeatureOnBioseq (protbsp, SEQFEAT_PROT, NULL);
6692
prot->data.value.ptrvalue = prp;
6693
if (indexing_needed != NULL)
6695
*indexing_needed = TRUE;
6701
ValNodeAddPointer (&(cdsp->prot_list), 0, prot);
6704
/* also add in mat_peptides from protein feature */
6705
prot = SeqMgrGetNextFeature (protbsp, NULL, SEQFEAT_PROT, FEATDEF_mat_peptide_aa, &fcontext);
6706
while (prot != NULL)
6708
ValNodeAddPointer (&(cdsp->prot_list), 0, prot);
6709
prot = SeqMgrGetNextFeature (protbsp, prot, SEQFEAT_PROT, FEATDEF_mat_peptide_aa, &fcontext);
6717
static CGPSetPtr BuildCGPSetFrommRNA (SeqFeatPtr mrna)
6722
if (mrna == NULL || mrna->idx.deleteme || mrna->idx.subtype != FEATDEF_mRNA) return NULL;
6724
cdsp = (CGPSetPtr) MemNew (sizeof (CGPSetData));
6725
ValNodeAddPointer (&(cdsp->mrna_list), 0, mrna);
6727
gene = GetGeneForFeature (mrna);
6730
ValNodeAddPointer (&(cdsp->gene_list), 0, gene);
6731
/* mark gene, so that we'll know it isn't lonely */
6732
gene->idx.deleteme = TRUE;
6739
static void UnmarkFeatureList (ValNodePtr list)
6743
while (list != NULL)
6745
sfp = list->data.ptrvalue;
6748
sfp->idx.deleteme = FALSE;
6755
static ValNodePtr BuildCGPSetList (Uint2 entityID, ValNodePtr constraint)
6760
ValNodePtr vnp, vnp_next, vnp_prev;
6761
ValNodePtr cdset_list = NULL;
6762
SeqFeatPtr cds, gene, mrna;
6763
Boolean need_indexing = FALSE;
6765
sep = GetTopSeqEntryForEntityID (entityID);
6771
VisitFeaturesInSep (sep, &b, BuildCGPSetCallback);
6773
/* build cdsets that have coding regions */
6774
for (vnp = b.cds_list; vnp != NULL; vnp = vnp->next)
6776
cds = (SeqFeatPtr) vnp->data.ptrvalue;
6777
if (cds == NULL) continue;
6778
cdsp = BuildCGPSetFromCodingRegion (cds, &need_indexing);
6781
ValNodeAddPointer (&cdset_list, 0, cdsp);
6786
/* indexing because we have created full-length protein features */
6787
SeqMgrIndexFeatures (entityID, NULL);
6790
/* build cdsets for mrna features that don't have coding regions */
6791
for (vnp = b.mrna_list; vnp != NULL; vnp = vnp->next)
6793
mrna = (SeqFeatPtr) vnp->data.ptrvalue;
6794
if (mrna == NULL || mrna->idx.deleteme) continue;
6795
cdsp = BuildCGPSetFrommRNA (mrna);
6798
ValNodeAddPointer (&cdset_list, 0, cdsp);
6802
/* build cdsets for lonely genes / features with gene xrefs that are not coding regions or mrnas */
6803
for (vnp = b.gene_list; vnp != NULL; vnp = vnp->next)
6805
gene = (SeqFeatPtr) vnp->data.ptrvalue;
6806
if (gene == NULL || gene->idx.deleteme) continue;
6807
cdsp = CGPSetNew ();
6808
ValNodeAddPointer (&(cdsp->gene_list), 0, gene);
6809
ValNodeAddPointer (&cdset_list, 0, cdsp);
6812
/* now unmark features */
6813
UnmarkFeatureList (b.cds_list);
6814
UnmarkFeatureList (b.mrna_list);
6815
UnmarkFeatureList (b.gene_list);
6817
b.cds_list = ValNodeFree (b.cds_list);
6818
b.mrna_list = ValNodeFree (b.mrna_list);
6819
b.gene_list = ValNodeFree (b.gene_list);
6821
/* now remove sets that don't match our choice constraint */
6823
for (vnp = cdset_list; vnp != NULL; vnp = vnp_next)
6825
vnp_next = vnp->next;
6826
if (!DoesObjectMatchConstraintChoiceSet (0, vnp->data.ptrvalue, constraint))
6828
if (vnp_prev == NULL)
6830
cdset_list = vnp->next;
6834
vnp_prev->next = vnp->next;
6837
FreeCGPSetList (vnp);
6849
NLM_EXTERN Int4 DoApplyActionToObjectList (ApplyActionPtr action, ValNodePtr object_list, StringConstraintPtr scp)
6852
Int4 num_succeed = 0, num_fail = 0;
6854
if (action == NULL || object_list == NULL) return 0;
6856
for (vnp = object_list; vnp != NULL; vnp = vnp->next) {
6857
if (SetFieldValueForObject (vnp->choice, vnp->data.ptrvalue, action->field, scp, action->value, action->existing_text)) {
6867
NLM_EXTERN Int4 DoEditActionToObjectList (EditActionPtr action, ValNodePtr object_list)
6870
Int4 num_succeed = 0, num_fail = 0;
6871
StringConstraintPtr scp;
6872
CharPtr str, new_str;
6874
if (action == NULL || object_list == NULL) return 0;
6875
scp = StringConstraintFromFieldEdit (action->edit);
6877
for (vnp = object_list; vnp != NULL; vnp = vnp->next) {
6878
str = GetFieldValueForObject (vnp->choice, vnp->data.ptrvalue, action->field, scp);
6879
new_str = ApplyEditToString (str, action->edit);
6880
if (StringCmp (str, new_str) != 0
6881
&& SetFieldValueForObject (vnp->choice, vnp->data.ptrvalue, action->field, scp, new_str, ExistingTextOption_replace_old)) {
6886
new_str = MemFree (new_str);
6887
str = MemFree (str);
6893
NLM_EXTERN Int4 DoConvertActionToObjectList (ConvertActionPtr action, ValNodePtr object_list, StringConstraintPtr scp)
6896
Int4 num_succeed = 0, num_fail = 0;
6897
CharPtr str, from_val;
6898
FieldTypePtr field_from, field_to;
6900
if (action == NULL || object_list == NULL || action->fields == NULL) return 0;
6902
field_from = GetFromFieldFromFieldPair (action->fields);
6903
field_to = GetToFieldFromFieldPair (action->fields);
6905
if (action->fields->choice == FieldPairType_molinfo_field) {
6906
for (vnp = object_list; vnp != NULL; vnp = vnp->next) {
6907
str = GetFieldValueForObject (vnp->choice, vnp->data.ptrvalue, field_from, NULL);
6908
from_val = GetSequenceQualValName (field_from->data.ptrvalue);
6909
if (StringCmp (str, from_val) == 0
6910
&& SetFieldValueForObject (vnp->choice, vnp->data.ptrvalue, field_to, NULL, str, ExistingTextOption_replace_old)) {
6913
str = MemFree (str);
6916
for (vnp = object_list; vnp != NULL; vnp = vnp->next) {
6917
str = GetFieldValueForObject (vnp->choice, vnp->data.ptrvalue, field_from, scp);
6918
if (SetFieldValueForObject (vnp->choice, vnp->data.ptrvalue, field_to, NULL, str, action->existing_text)
6919
&& RemoveFieldValueForObject (vnp->choice, vnp->data.ptrvalue, field_from, scp)) {
6924
str = MemFree (str);
6928
field_from = FieldTypeFree (field_from);
6929
field_to = FieldTypeFree (field_to);
6935
NLM_EXTERN Int4 DoCopyActionToObjectList (CopyActionPtr action, ValNodePtr object_list, StringConstraintPtr scp)
6938
Int4 num_succeed = 0, num_fail = 0;
6940
FieldTypePtr field_from, field_to;
6942
if (action == NULL || object_list == NULL) return 0;
6943
field_from = GetFromFieldFromFieldPair (action->fields);
6944
field_to = GetToFieldFromFieldPair (action->fields);
6946
for (vnp = object_list; vnp != NULL; vnp = vnp->next) {
6947
str = GetFieldValueForObject (vnp->choice, vnp->data.ptrvalue, field_from, scp);
6948
if (SetFieldValueForObject (vnp->choice, vnp->data.ptrvalue, field_to, NULL, str, action->existing_text)) {
6953
str = MemFree (str);
6956
field_from = FieldTypeFree (field_from);
6957
field_to = FieldTypeFree (field_to);
6962
NLM_EXTERN Int4 DoSwapActionToObjectList (SwapActionPtr action, ValNodePtr object_list, StringConstraintPtr scp)
6965
Int4 num_succeed = 0, num_fail = 0;
6967
FieldTypePtr field_from, field_to;
6969
if (action == NULL || object_list == NULL) return 0;
6970
field_from = GetFromFieldFromFieldPair (action->fields);
6971
field_to = GetToFieldFromFieldPair (action->fields);
6973
for (vnp = object_list; vnp != NULL; vnp = vnp->next) {
6974
str1 = GetFieldValueForObject (vnp->choice, vnp->data.ptrvalue, field_from, scp);
6975
str2 = GetFieldValueForObject (vnp->choice, vnp->data.ptrvalue, field_to, NULL);
6976
if (SetFieldValueForObject (vnp->choice, vnp->data.ptrvalue, field_to, NULL, str1, ExistingTextOption_replace_old)
6977
&& SetFieldValueForObject (vnp->choice, vnp->data.ptrvalue, field_from, scp, str2, ExistingTextOption_replace_old)) {
6982
str1 = MemFree (str1);
6983
str2 = MemFree (str2);
6985
field_from = FieldTypeFree (field_from);
6986
field_to = FieldTypeFree (field_to);
6991
NLM_EXTERN Int4 DoRemoveActionToObjectList (RemoveActionPtr action, ValNodePtr object_list, StringConstraintPtr scp)
6994
Int4 num_succeed = 0, num_fail = 0;
6996
if (action == NULL || object_list == NULL) return 0;
6998
for (vnp = object_list; vnp != NULL; vnp = vnp->next) {
6999
if (RemoveFieldValueForObject (vnp->choice, vnp->data.ptrvalue, action->field, scp)) {
7009
NLM_EXTERN Int4 DoParseActionToObjectList (AECRParseActionPtr action, ValNodePtr object_list, StringConstraintPtr scp)
7012
CharPtr str1, str2, cp;
7013
Int4 len, num_succeed = 0;
7014
FieldTypePtr field_from, field_to;
7016
if (action == NULL || object_list == NULL) return 0;
7017
field_from = GetFromFieldFromFieldPair (action->fields);
7018
field_to = GetToFieldFromFieldPair (action->fields);
7020
for (vnp = object_list; vnp != NULL; vnp = vnp->next) {
7021
str1 = GetFieldValueForObject (vnp->choice, vnp->data.ptrvalue, field_from, scp);
7022
str2 = GetTextPortionFromString (str1, action->portion);
7024
if (action->remove_from_parsed) {
7025
cp = StringSearch (str1, str2);
7026
len = StringLen (str2);
7027
StringCpy (cp, cp + len);
7028
SetFieldValueForObject (vnp->choice, vnp->data.ptrvalue, field_from, scp, str1, ExistingTextOption_replace_old);
7030
if (SetFieldValueForObject (vnp->choice, vnp->data.ptrvalue, field_to, NULL, str1, action->existing_text)) {
7034
str1 = MemFree (str1);
7035
str2 = MemFree (str2);
7037
field_from = FieldTypeFree (field_from);
7038
field_to = FieldTypeFree (field_to);
7043
static Int4 ApplyAECRActionToSeqEntry (AECRActionPtr act, SeqEntryPtr sep)
7045
StringConstraintPtr scp;
7047
ValNodePtr object_list = NULL;
7050
Int4 num_succeed = 0;
7052
if (act == NULL || act->action == NULL) return 0;
7053
field_type = FieldTypeFromAECRAction (act);
7054
if (field_type == FieldType_cds_gene_prot) {
7055
entityID = ObjMgrGetEntityIDForChoice(sep);
7056
object_list = BuildCGPSetList (entityID, act->constraint);
7058
object_list = GetObjectListForAECRAction (sep, act);
7061
switch (act->action->choice) {
7062
case ActionChoice_apply:
7063
a = (ApplyActionPtr) act->action->data.ptrvalue;
7064
scp = FindStringConstraintInConstraintSetForField (a->field, act->constraint);
7065
num_succeed = DoApplyActionToObjectList (act->action->data.ptrvalue, object_list, scp);
7066
scp = StringConstraintFree (scp);
7068
case ActionChoice_edit:
7069
num_succeed = DoEditActionToObjectList (act->action->data.ptrvalue, object_list);
7071
case ActionChoice_convert:
7072
num_succeed = DoConvertActionToObjectList (act->action->data.ptrvalue, object_list, NULL);
7074
case ActionChoice_swap:
7075
num_succeed = DoSwapActionToObjectList (act->action->data.ptrvalue, object_list, NULL);
7077
case ActionChoice_copy:
7078
num_succeed = DoCopyActionToObjectList (act->action->data.ptrvalue, object_list, NULL);
7080
case ActionChoice_remove:
7081
num_succeed = DoRemoveActionToObjectList (act->action->data.ptrvalue, object_list, NULL);
7083
case ActionChoice_parse:
7084
num_succeed = DoRemoveActionToObjectList (act->action->data.ptrvalue, object_list, NULL);
7087
object_list = ValNodeFree (object_list);
7092
/* This section handles parsing where the source field and destination field may not be on the same
7093
* group of objects. */
7094
typedef struct parsesourceinfo
7100
ValNodePtr dest_list;
7101
CharPtr parse_src_txt;
7102
} ParseSourceInfoData, PNTR ParseSourceInfoPtr;
7104
static ParseSourceInfoPtr ParseSourceInfoNew (BioseqPtr bsp, SeqFeatPtr sfp, SeqDescrPtr sdp, SeqIdPtr sip, CharPtr parse_src_txt)
7106
ParseSourceInfoPtr psip;
7108
psip = (ParseSourceInfoPtr) MemNew (sizeof (ParseSourceInfoData));
7114
psip->dest_list = NULL;
7115
psip->parse_src_txt = parse_src_txt;
7121
static ParseSourceInfoPtr ParseSourceInfoFree (ParseSourceInfoPtr psip)
7125
psip->dest_list = ValNodeFree (psip->dest_list);
7126
psip->parse_src_txt = MemFree (psip->parse_src_txt);
7127
psip = MemFree (psip);
7132
static ParseSourceInfoPtr ParseSourceInfoCopy (ParseSourceInfoPtr psip)
7134
ParseSourceInfoPtr pcopy = NULL;
7138
pcopy = (ParseSourceInfoPtr) MemNew (sizeof (ParseSourceInfoData));
7139
if (pcopy != NULL) {
7140
pcopy->bsp = psip->bsp;
7141
pcopy->sfp = psip->sfp;
7142
pcopy->sdp = psip->sdp;
7143
pcopy->sip = psip->sip;
7144
pcopy->dest_list = NULL;
7145
pcopy->parse_src_txt = NULL;
7151
static ValNodePtr ParseSourceListFree (ValNodePtr vnp)
7153
ValNodePtr vnp_next;
7154
while (vnp != NULL) {
7155
vnp_next = vnp->next;
7157
vnp->data.ptrvalue = ParseSourceInfoFree (vnp->data.ptrvalue);
7158
vnp = ValNodeFree (vnp);
7166
GetDeflineSourcesForBioseq
7168
TextPortionPtr portion,
7169
ValNodePtr PNTR source_list)
7172
SeqMgrDescContext dcontext;
7174
ParseSourceInfoPtr psip;
7176
if (bsp == NULL || source_list == NULL)
7181
sdp = SeqMgrGetNextDescriptor (bsp, NULL, Seq_descr_title, &dcontext);
7184
str = GetTextPortionFromString (sdp->data.ptrvalue, portion);
7186
psip = ParseSourceInfoNew (bsp, NULL, sdp, NULL, str);
7188
ValNodeAddPointer (source_list, 0, psip);
7190
str = MemFree (str);
7193
sdp = SeqMgrGetNextDescriptor (bsp, sdp, Seq_descr_title, &dcontext);
7198
static CharPtr GetIDSrc (SeqIdPtr sip, Uint1 id_type, CharPtr tag)
7200
DbtagPtr dbt = NULL;
7201
ObjectIdPtr oip = NULL;
7203
CharPtr str_src = NULL;
7205
if (sip == NULL || sip->choice != id_type) return NULL;
7207
if (id_type == SEQID_GENERAL)
7209
dbt = (DbtagPtr) sip->data.ptrvalue;
7210
if (dbt == NULL || (tag != NULL && StringCmp (dbt->db, tag) != 0)) return NULL;
7213
else if (id_type == SEQID_LOCAL)
7215
oip = sip->data.ptrvalue;
7220
SeqIdWrite (sip, id_str, PRINTID_REPORT, sizeof (id_str));
7221
str_src = StringSave (id_str);
7225
if (oip->str == NULL)
7227
sprintf (id_str, "%d", oip->id);
7228
str_src = StringSave (id_str);
7232
str_src = StringSave (oip->str);
7240
GetIDSourcesForBioseq
7242
TextPortionPtr portion,
7245
ValNodePtr PNTR source_list)
7248
ParseSourceInfoPtr psip;
7249
CharPtr src_str = NULL, str;
7251
if (bsp == NULL || source_list == NULL)
7259
if ((src_str = GetIDSrc (sip, id_type, tag)) != NULL) {
7260
str = GetTextPortionFromString (src_str, portion);
7262
psip = ParseSourceInfoNew (bsp, NULL, NULL, sip, str);
7264
ValNodeAddPointer (source_list, 0, psip);
7266
str = MemFree (str);
7269
src_str = MemFree (src_str);
7277
GetLocalIDSourcesForBioseq
7280
ValNodePtr PNTR source_list)
7282
GetIDSourcesForBioseq (bsp, tp, SEQID_LOCAL, NULL, source_list);
7286
static void GetNcbiFileSourceForBioseq
7289
ValNodePtr PNTR source_list)
7291
GetIDSourcesForBioseq (bsp, tp, SEQID_GENERAL, "NCBIFILE", source_list);
7295
static void StripBankitCommentForParse (SeqDescrPtr sdp, TextPortionPtr tp)
7301
if (sdp == NULL || sdp->choice != Seq_descr_user || tp == NULL) {
7305
/* Bankit Comments */
7306
uop = (UserObjectPtr) sdp->data.ptrvalue;
7307
if (uop != NULL && StringCmp (uop->_class, "SMART_V1.0") != 0) {
7309
if (oip != NULL && StringCmp (oip->str, "Submission") == 0) {
7310
for (ufp = uop->data; ufp != NULL; ufp = ufp->next) {
7312
if (oip != NULL && StringCmp (oip->str, "AdditionalComment") == 0) {
7313
ReplaceStringForParse (ufp->data.ptrvalue, tp);
7321
static void StripStructuredCommentForParse (SeqDescrPtr sdp, CharPtr comment_field, TextPortionPtr tp)
7327
if (sdp == NULL || sdp->choice != Seq_descr_user || tp == NULL || StringHasNoText (comment_field)) {
7331
uop = (UserObjectPtr) sdp->data.ptrvalue;
7333
if (oip != NULL && StringCmp (oip->str, "StructuredComment") == 0) {
7334
for (ufp = uop->data; ufp != NULL; ufp = ufp->next) {
7336
if (oip != NULL && StringCmp (oip->str, comment_field) == 0) {
7337
ReplaceStringForParse (ufp->data.ptrvalue, tp);
7345
GetBankitCommentSourcesForBioseq
7348
ValNodePtr PNTR source_list)
7351
SeqMgrDescContext dcontext;
7352
ParseSourceInfoPtr psip;
7358
if (bsp == NULL || source_list == NULL) {
7362
sdp = SeqMgrGetNextDescriptor (bsp, NULL, Seq_descr_user, &dcontext);
7363
while (sdp != NULL) {
7364
if (sdp->extended != 0) {
7365
/* Bankit Comments */
7366
uop = (UserObjectPtr) sdp->data.ptrvalue;
7367
if (uop != NULL && StringCmp (uop->_class, "SMART_V1.0") != 0) {
7369
if (oip != NULL && StringCmp (oip->str, "Submission") == 0) {
7370
for (ufp = uop->data; ufp != NULL; ufp = ufp->next) {
7372
if (oip != NULL && StringCmp (oip->str, "AdditionalComment") == 0) {
7373
str = GetTextPortionFromString (ufp->data.ptrvalue, tp);
7375
psip = ParseSourceInfoNew (bsp, NULL, sdp, NULL, str);
7377
str = MemFree (str);
7379
ValNodeAddPointer (source_list, 0, psip);
7387
sdp = SeqMgrGetNextDescriptor (bsp, sdp, Seq_descr_user, &dcontext);
7393
GetCommentSourcesForBioseq
7396
ValNodePtr PNTR source_list)
7400
SeqMgrFeatContext fcontext;
7401
SeqMgrDescContext dcontext;
7402
ParseSourceInfoPtr psip;
7405
if (bsp == NULL || source_list == NULL) {
7409
sdp = SeqMgrGetNextDescriptor (bsp, NULL, Seq_descr_comment, &dcontext);
7410
while (sdp != NULL) {
7411
str = GetTextPortionFromString (sdp->data.ptrvalue, tp);
7413
psip = ParseSourceInfoNew (bsp, NULL, sdp, NULL, str);
7415
str = MemFree (str);
7417
ValNodeAddPointer (source_list, 0, psip);
7420
sdp = SeqMgrGetNextDescriptor (bsp, sdp, Seq_descr_comment, &dcontext);
7423
sfp = SeqMgrGetNextFeature (bsp, NULL, SEQFEAT_COMMENT, 0, &fcontext);
7424
while (sfp != NULL) {
7425
str = GetTextPortionFromString (sfp->data.value.ptrvalue, tp);
7427
psip = ParseSourceInfoNew (bsp, sfp, NULL, NULL, str);
7429
str = MemFree (str);
7431
ValNodeAddPointer (source_list, 0, psip);
7434
sfp = SeqMgrGetNextFeature (bsp, sfp, SEQFEAT_COMMENT, 0, &fcontext);
7436
GetBankitCommentSourcesForBioseq (bsp, tp, source_list);
7441
GetStructuredCommentSourcesForBioseq
7444
CharPtr comment_field,
7445
ValNodePtr PNTR source_list)
7451
SeqMgrDescContext dcontext;
7453
ParseSourceInfoPtr psip;
7455
if (bsp == NULL || source_list == NULL)
7460
sdp = SeqMgrGetNextDescriptor (bsp, NULL, Seq_descr_user, &dcontext);
7461
while (sdp != NULL) {
7462
if (sdp->extended != 0
7463
&& sdp->data.ptrvalue != NULL) {
7464
uop = (UserObjectPtr) sdp->data.ptrvalue;
7466
if (oip != NULL && StringCmp (oip->str, "StructuredComment") == 0) {
7467
for (ufp = uop->data; ufp != NULL; ufp = ufp->next) {
7469
if (oip != NULL && StringCmp (oip->str, comment_field) == 0) {
7470
str = GetTextPortionFromString (ufp->data.ptrvalue, tp);
7472
psip = ParseSourceInfoNew (bsp, NULL, sdp, NULL, str);
7474
str = MemFree (str);
7476
ValNodeAddPointer (source_list, 0, psip);
7483
sdp = SeqMgrGetNextDescriptor (bsp, sdp, Seq_descr_user, &dcontext);
7488
const CharPtr nomial_keywords[] = {
7496
const Int4 num_nomial_keywords = sizeof(nomial_keywords) / sizeof (CharPtr);
7498
static CharPtr GetTextAfterNomial (CharPtr taxname)
7501
CharPtr ptr, nomial_end;
7503
Boolean found_keyword = TRUE;
7505
ptr = StringChr (taxname, ' ');
7506
if (ptr == NULL) return NULL;
7507
/* skip over the first word and the spaces after it. */
7508
while (*ptr == ' ') {
7511
ptr = StringChr (ptr, ' ');
7512
/* if there are only two words, give up. */
7517
while (*ptr == ' ') {
7521
while (found_keyword) {
7522
found_keyword = FALSE;
7523
/* if the next word is a nomial keyword, skip that plus the first word that follows it. */
7524
for (i = 0; i < num_nomial_keywords && *nomial_end != 0; i++) {
7525
if (StringNCmp (ptr, nomial_keywords[i], StringLen(nomial_keywords[i])) == 0) {
7526
ptr += StringLen(nomial_keywords[i]);
7527
while (*ptr == ' ' ) {
7530
nomial_end = StringChr (ptr, ' ');
7531
if (nomial_end == NULL) {
7532
nomial_end = ptr + StringLen (ptr);
7535
while (*ptr == ' ') {
7538
found_keyword = TRUE;
7548
GetOrgParseSourcesForBioSource
7555
ValNodePtr PNTR source_list)
7557
CharPtr str = NULL, portion, tmp;
7559
ParseSourceInfoPtr psip;
7561
if (biop == NULL || o == NULL || o->field == NULL || source_list == NULL) return;
7563
switch (o->field->choice) {
7564
case ParseSrcOrgChoice_source_qual :
7565
vn.choice = SourceQualChoice_textqual;
7566
vn.data.intvalue = o->field->data.intvalue;
7568
str = GetSourceQualFromBioSource (biop, &vn, NULL);
7570
case ParseSrcOrgChoice_taxname_after_binomial :
7571
vn.choice = SourceQualChoice_textqual;
7572
vn.data.intvalue = Source_qual_taxname;
7574
str = GetSourceQualFromBioSource (biop, &vn, NULL);
7575
tmp = GetTextAfterNomial (str);
7576
tmp = StringSave (tmp);
7577
str = MemFree (str);
7581
portion = GetTextPortionFromString (str, tp);
7582
if (portion != NULL) {
7583
psip = ParseSourceInfoNew (bsp, sfp, sdp, NULL, portion);
7585
portion = MemFree (portion);
7587
ValNodeAddPointer (source_list, 0, psip);
7590
str = MemFree (str);
7594
static void GetOrgParseSourcesForBioseq (BioseqPtr bsp, ParseSrcOrgPtr o, TextPortionPtr tp, ValNodePtr PNTR source_list)
7598
SeqMgrFeatContext fcontext;
7599
SeqMgrDescContext dcontext;
7601
if (bsp == NULL || o == NULL || source_list == NULL) return;
7603
if (o->type == Object_type_constraint_any || o->type == Object_type_constraint_descriptor) {
7604
for (sdp = SeqMgrGetNextDescriptor (bsp, NULL, Seq_descr_source, &dcontext);
7606
sdp = SeqMgrGetNextDescriptor (bsp, sdp, Seq_descr_source, &dcontext)) {
7607
GetOrgParseSourcesForBioSource (sdp->data.ptrvalue, bsp, sdp, NULL, o, tp, source_list);
7611
if (o->type == Object_type_constraint_any || o->type == Object_type_constraint_feature) {
7612
for (sfp = SeqMgrGetNextFeature (bsp, NULL, SEQFEAT_BIOSRC, 0, &fcontext);
7614
sfp = SeqMgrGetNextFeature (bsp, sfp, SEQFEAT_BIOSRC, 0, &fcontext)) {
7615
GetOrgParseSourcesForBioSource (sfp->data.value.ptrvalue, bsp, NULL, sfp, o, tp, source_list);
7621
typedef struct parsesrccollection {
7623
TextPortionPtr portion;
7624
ValNodePtr src_list;
7625
} ParseSrcCollectionData, PNTR ParseSrcCollectionPtr;
7628
static void FindParseSourceBioseqCallback (BioseqPtr bsp, Pointer userdata)
7630
ParseSrcCollectionPtr psp;
7632
if (bsp == NULL || userdata == NULL)
7637
psp = (ParseSrcCollectionPtr) userdata;
7638
if (psp->src == NULL) return;
7640
switch (psp->src->choice)
7642
case ParseSrc_defline:
7643
if (!ISA_aa (bsp->mol)) {
7644
GetDeflineSourcesForBioseq (bsp, psp->portion, &(psp->src_list));
7647
case ParseSrc_local_id:
7648
if (! ISA_aa (bsp->mol) && bsp->repr != Seq_repr_seg) {
7649
GetLocalIDSourcesForBioseq (bsp, psp->portion, &(psp->src_list));
7652
case ParseSrc_file_id:
7653
GetNcbiFileSourceForBioseq (bsp, psp->portion, &(psp->src_list));
7656
GetOrgParseSourcesForBioseq (bsp, psp->src->data.ptrvalue, psp->portion, &(psp->src_list));
7658
case ParseSrc_comment:
7659
GetCommentSourcesForBioseq (bsp, psp->portion, &(psp->src_list));
7661
case ParseSrc_structured_comment:
7662
GetStructuredCommentSourcesForBioseq(bsp, psp->portion, psp->src->data.ptrvalue, &(psp->src_list));
7664
case ParseSrc_bankit_comment:
7665
if (!ISA_aa (bsp->mol)) {
7666
GetBankitCommentSourcesForBioseq (bsp, psp->portion, &(psp->src_list));
7673
static void GetOrgNamesInRecordCallback (BioSourcePtr biop, Pointer userdata)
7675
ValNodePtr PNTR org_names;
7677
if (biop == NULL || biop->org == NULL || StringHasNoText (biop->org->taxname)
7678
|| userdata == NULL)
7683
org_names = (ValNodePtr PNTR) userdata;
7685
ValNodeAddPointer (org_names, 0, biop->org->taxname);
7689
static void SetToUpper (CharPtr cp)
7691
if (cp == NULL) return;
7693
if (isalpha (*cp)) {
7694
*cp = toupper (*cp);
7702
FixCapitalizationInString
7703
(CharPtr PNTR pTitle,
7704
Uint2 capitalization,
7705
ValNodePtr org_names)
7707
if (pTitle == NULL || capitalization == Cap_change_none) return;
7709
switch (capitalization) {
7710
case Cap_change_tolower:
7711
ResetCapitalization (FALSE, *pTitle);
7712
FixAbbreviationsInElement (pTitle);
7713
FixOrgNamesInString (*pTitle, org_names);
7715
case Cap_change_toupper:
7716
SetToUpper (*pTitle);
7717
FixAbbreviationsInElement (pTitle);
7718
FixOrgNamesInString (*pTitle, org_names);
7720
case Cap_change_firstcap:
7721
ResetCapitalization (TRUE, *pTitle);
7722
FixAbbreviationsInElement (pTitle);
7723
FixOrgNamesInString (*pTitle, org_names);
7729
static void AddDeflineDestinationsForBioseq (BioseqPtr bsp, ValNodePtr PNTR dest_list)
7732
SeqMgrDescContext dcontext;
7734
if (bsp == NULL || dest_list == NULL) {
7738
sdp = SeqMgrGetNextDescriptor (bsp, NULL, Seq_descr_title, &dcontext);
7739
while (sdp != NULL) {
7740
ValNodeAddPointer (dest_list, OBJ_SEQDESC, sdp);
7741
sdp = SeqMgrGetNextDescriptor (bsp, sdp, Seq_descr_title, &dcontext);
7746
static void AddFeatureDestinationsForBioseq (BioseqPtr bsp, FeatureFieldLegalPtr featfield, ValNodePtr PNTR dest_list)
7749
SeqMgrFeatContext fcontext;
7752
if (bsp == NULL || featfield == NULL || dest_list == NULL) return;
7754
featdef = GetFeatdefFromFeatureType (featfield->type);
7755
for (sfp = SeqMgrGetNextFeature (bsp, NULL, 0, featdef, &fcontext);
7757
sfp = SeqMgrGetNextFeature (bsp, sfp, 0, featdef, &fcontext)) {
7758
ValNodeAddPointer (dest_list, OBJ_SEQFEAT, sfp);
7763
static void GetBioSourceDestinationsForBioseq (BioseqPtr bsp, Uint2 object_type, ValNodePtr PNTR dest_list)
7767
SeqMgrFeatContext fcontext;
7768
SeqMgrDescContext dcontext;
7770
if (bsp == NULL || dest_list == NULL)
7775
if (object_type == Object_type_constraint_any || object_type == Object_type_constraint_descriptor)
7777
sdp = SeqMgrGetNextDescriptor (bsp, NULL, Seq_descr_source, &dcontext);
7780
ValNodeAddPointer (dest_list, OBJ_SEQDESC, sdp);
7781
sdp = SeqMgrGetNextDescriptor (bsp, sdp, Seq_descr_source, &dcontext);
7785
if (object_type == Object_type_constraint_any || object_type == Object_type_constraint_feature)
7787
sfp = SeqMgrGetNextFeature (bsp, NULL, SEQFEAT_BIOSRC, 0, &fcontext);
7790
ValNodeAddPointer (dest_list, OBJ_SEQFEAT, sfp);
7791
sfp = SeqMgrGetNextFeature (bsp, sfp, SEQFEAT_BIOSRC, 0, &fcontext);
7797
static void AddParseDestinations (ParseSourceInfoPtr psip, ParseDestPtr dst)
7801
if (psip == NULL || dst == NULL) return;
7803
switch (dst->choice) {
7804
case ParseDest_defline :
7805
AddDeflineDestinationsForBioseq (psip->bsp, &(psip->dest_list));
7807
case ParseDest_org :
7808
o = (ParseDstOrgPtr) dst->data.ptrvalue;
7809
if ((o->type == Object_type_constraint_any || o->type == Object_type_constraint_descriptor)
7810
&& psip->sdp != NULL && psip->sdp->choice == Seq_descr_source) {
7811
ValNodeAddPointer (&(psip->dest_list), OBJ_SEQDESC, psip->sdp);
7812
} else if ((o->type == Object_type_constraint_any || o->type == Object_type_constraint_feature)
7813
&& psip->sfp != NULL && psip->sfp->data.choice == SEQFEAT_BIOSRC) {
7814
ValNodeAddPointer (&(psip->dest_list), OBJ_SEQFEAT, psip->sfp);
7816
GetBioSourceDestinationsForBioseq (psip->bsp, o->type, &(psip->dest_list));
7819
case ParseDest_featqual :
7820
AddFeatureDestinationsForBioseq (psip->bsp, dst->data.ptrvalue, &(psip->dest_list));
7822
case ParseDest_dbxref :
7823
GetBioSourceDestinationsForBioseq (psip->bsp, Object_type_constraint_any, &(psip->dest_list));
7829
static Boolean SourceHasOneUndeletedDestination (ParseSourceInfoPtr source)
7835
|| source->dest_list == NULL)
7840
vnp = source->dest_list;
7841
while (vnp != NULL && num_seen < 2)
7843
if (vnp->choice > 1)
7860
static void CombineSourcesForDestinations (ValNodePtr PNTR source_list)
7862
ValNodePtr source1_vnp, source2_vnp, dest1_vnp, dest2_vnp;
7863
ValNodePtr source_new, del_vnp;
7864
ParseSourceInfoPtr psip1, psip2, new_psip;
7867
for (source1_vnp = *source_list;
7868
source1_vnp != NULL;
7869
source1_vnp = source1_vnp->next)
7871
psip1 = (ParseSourceInfoPtr) source1_vnp->data.ptrvalue;
7872
if (psip1 == NULL || psip1->dest_list == NULL)
7876
for (source2_vnp = source1_vnp->next;
7877
source2_vnp != NULL;
7878
source2_vnp = source2_vnp->next)
7880
if (source2_vnp->choice > 0)
7882
/* already marked for deletion */
7885
psip2 = (ParseSourceInfoPtr) source2_vnp->data.ptrvalue;
7886
if (psip2 == NULL || psip2->dest_list == NULL)
7890
for (dest1_vnp = psip1->dest_list;
7892
dest1_vnp = dest1_vnp->next)
7894
if (dest1_vnp->choice == 0)
7896
/* already marked for deletion */
7899
for (dest2_vnp = psip2->dest_list;
7901
dest2_vnp = dest2_vnp->next)
7903
if (dest2_vnp->choice == 0)
7905
/* already marked for deletion */
7908
if (dest1_vnp->choice == dest2_vnp->choice
7909
&& dest1_vnp->data.ptrvalue == dest2_vnp->data.ptrvalue)
7911
comb_txt = (CharPtr) (MemNew (sizeof (Char)
7912
* (StringLen (psip1->parse_src_txt)
7913
+ StringLen (psip2->parse_src_txt)
7915
StringCpy (comb_txt, psip1->parse_src_txt);
7916
StringCat (comb_txt, ";");
7917
StringCat (comb_txt, psip2->parse_src_txt);
7919
/* If the first source has a single destination, then we can
7920
* add the text from the second source to the first and remove
7921
* the destination from the second source.
7923
if (SourceHasOneUndeletedDestination (psip1))
7926
psip1->parse_src_txt = MemFree (psip1->parse_src_txt);
7927
psip1->parse_src_txt = comb_txt;
7928
dest2_vnp->choice = 0;
7930
/* If the first source has more than one destination and
7931
* the second source has a single destination, then we can
7932
* remove the repeated desination from the first source
7933
* and add the text from the first source to the second source.
7935
else if (SourceHasOneUndeletedDestination (psip2))
7937
psip2->parse_src_txt = MemFree (psip2->parse_src_txt);
7938
psip2->parse_src_txt = comb_txt;
7939
dest1_vnp->choice = 0;
7941
/* If the first and second sources have multiple destinations,
7942
* we need to remove the repeated destination from both the first
7943
* and second source and create a new source with the combined
7944
* text for just the repeated destination.
7948
new_psip = ParseSourceInfoNew (NULL, NULL, NULL, NULL, comb_txt);
7949
ValNodeAddPointer (&(new_psip->dest_list),
7951
dest1_vnp->data.ptrvalue);
7952
dest1_vnp->choice = 0;
7953
dest2_vnp->choice = 0;
7954
source_new = ValNodeNew (NULL);
7955
source_new->choice = 0;
7956
source_new->data.ptrvalue = new_psip;
7957
source_new->next = source1_vnp->next;
7958
source1_vnp->next = source_new;
7964
del_vnp = ValNodeExtractList (&(psip1->dest_list), 0);
7965
del_vnp = ValNodeFree (del_vnp);
7966
if (psip1->dest_list == NULL)
7968
source1_vnp->choice = 1;
7970
del_vnp = ValNodeExtractList (&(psip2->dest_list), 0);
7971
del_vnp = ValNodeFree (del_vnp);
7972
if (psip2->dest_list == NULL)
7974
source2_vnp->choice = 1;
7979
/* now remove sources deleted */
7980
del_vnp = ValNodeExtractList (source_list, 1);
7981
del_vnp = ParseSourceListFree (del_vnp);
7985
static BioseqSetPtr GetPartsForSourceDescriptorOnSegSet (SeqDescrPtr sdp)
7991
if (sdp == NULL || sdp->extended != 1) {
7994
ovp = (ObjValNodePtr) sdp;
7995
if (ovp->idx.parenttype != OBJ_BIOSEQSET || ovp->idx.parentptr == NULL) {
7998
bssp = (BioseqSetPtr) ovp->idx.parentptr;
8000
if (bssp->_class == BioseqseqSet_class_nuc_prot
8001
&& IS_Bioseq_set (bssp->seq_set)
8002
&& bssp->seq_set->data.ptrvalue != NULL) {
8003
bssp = (BioseqSetPtr) bssp->seq_set->data.ptrvalue;
8006
if (bssp->_class == BioseqseqSet_class_segset) {
8007
sep = bssp->seq_set;
8008
while (sep != NULL) {
8009
if (IS_Bioseq_set (sep) && sep->data.ptrvalue != NULL) {
8010
bssp = (BioseqSetPtr) sep->data.ptrvalue;
8011
if (bssp->_class == BioseqseqSet_class_parts) {
8023
static SeqDescrPtr FindSourceDescriptorInSeqEntry (SeqEntryPtr sep)
8027
SeqDescrPtr sdp = NULL;
8029
if (sep != NULL && sep->data.ptrvalue != NULL) {
8030
if (IS_Bioseq (sep)) {
8031
bsp = (BioseqPtr) sep->data.ptrvalue;
8033
} else if (IS_Bioseq_set (sep)) {
8034
bssp = (BioseqSetPtr) sep->data.ptrvalue;
8037
while (sdp != NULL && sdp->choice != Seq_descr_source)
8046
static SeqDescrPtr PropagateToSeqEntry (SeqEntryPtr sep, SeqDescrPtr sdp)
8050
SeqDescrPtr new_sdp = NULL;
8052
if (sep != NULL && sep->data.ptrvalue != NULL) {
8053
if (IS_Bioseq (sep)) {
8054
bsp = (BioseqPtr) sep->data.ptrvalue;
8055
new_sdp = AsnIoMemCopy ((Pointer) sdp,
8056
(AsnReadFunc) SeqDescrAsnRead,
8057
(AsnWriteFunc) SeqDescrAsnWrite);
8058
ValNodeLink (&(bsp->descr), new_sdp);
8059
} else if (IS_Bioseq_set (sep)) {
8060
bssp = (BioseqSetPtr) sep->data.ptrvalue;
8061
new_sdp = AsnIoMemCopy ((Pointer) sdp,
8062
(AsnReadFunc) SeqDescrAsnRead,
8063
(AsnWriteFunc) SeqDescrAsnWrite);
8064
ValNodeLink (&(bssp->descr), new_sdp);
8071
static void PropagateSourceOnSegSetForParse (ValNodePtr parse_source_list)
8073
ParseSourceInfoPtr psip;
8074
ValNodePtr vnp_src, vnp_dst;
8075
SeqDescrPtr sdp, other_sdp;
8077
ValNodePtr extra_dests = NULL;
8078
BioseqSetPtr parts_bssp;
8080
for (vnp_src = parse_source_list; vnp_src != NULL; vnp_src = vnp_src->next) {
8081
psip = (ParseSourceInfoPtr) vnp_src->data.ptrvalue;
8083
for (vnp_dst = psip->dest_list; vnp_dst != NULL; vnp_dst = vnp_dst->next) {
8084
if (vnp_dst->choice == OBJ_SEQDESC) {
8085
sdp = (SeqDescrPtr) vnp_dst->data.ptrvalue;
8086
if (sdp != NULL && sdp->choice == Seq_descr_source) {
8087
parts_bssp = GetPartsForSourceDescriptorOnSegSet (sdp);
8088
if (parts_bssp != NULL) {
8089
for (sep = parts_bssp->seq_set; sep != NULL; sep = sep->next) {
8090
if (IS_Bioseq(sep) && sep->data.ptrvalue == psip->bsp) {
8091
other_sdp = FindSourceDescriptorInSeqEntry (sep);
8092
if (other_sdp == NULL) {
8093
other_sdp = PropagateToSeqEntry (sep, sdp);
8094
ValNodeAddPointer (&extra_dests, OBJ_SEQDESC, other_sdp);
8099
/* set choice to 0 so master won't be a destination */
8100
vnp_dst->choice = 0;
8106
/* add extra destinations to list */
8107
ValNodeLink (&psip->dest_list, extra_dests);
8115
static Boolean SetDBxrefForBioSource (BioSourcePtr biop, CharPtr db_name, CharPtr str, Uint2 existing_text)
8119
Boolean found = FALSE;
8121
Boolean rval = FALSE;
8123
if (biop == NULL || StringHasNoText (db_name) || StringHasNoText (str)) {
8127
if (biop->org == NULL)
8129
biop->org = OrgRefNew();
8131
dbx = biop->org->db;
8132
while (dbx != NULL && !found)
8134
dbtag = (DbtagPtr) dbx->data.ptrvalue;
8135
if (dbtag != NULL && dbtag->tag != NULL
8136
&& StringCmp (dbtag->db, db_name) == 0)
8148
dbtag->db = StringSave (db_name);
8149
ValNodeAddPointer (&(biop->org->db), 0, dbtag);
8151
if (dbtag->tag == NULL)
8153
dbtag->tag = ObjectIdNew();
8155
/* if it was a number before, make it a string now */
8156
if (dbtag->tag->id > 0 && dbtag->tag->str == NULL)
8158
sprintf (buf, "%s", dbtag->tag->id);
8160
dbtag->tag->str = StringSave (buf);
8162
rval = SetStringValue (&(dbtag->tag->str), str, existing_text);
8167
static Int4 SetFieldForDestList (ValNodePtr dest_list, ParseDestPtr field, CharPtr str, Uint2 existing_text)
8174
FeatureFieldLegalPtr fl;
8176
Int4 num_succeeded = 0;
8178
if (dest_list == NULL || field == NULL) return 0;
8180
switch (field->choice) {
8181
case ParseDest_defline :
8182
for (vnp = dest_list; vnp != NULL; vnp = vnp->next) {
8183
if (vnp->choice == OBJ_SEQDESC && vnp->data.ptrvalue != NULL) {
8184
sdp = (SeqDescrPtr) vnp->data.ptrvalue;
8185
if (sdp->choice == Seq_descr_title) {
8186
cp = sdp->data.ptrvalue;
8187
if (SetStringValue (&cp, str, existing_text)) {
8190
sdp->data.ptrvalue = cp;
8195
case ParseDest_org :
8196
o = (ParseDstOrgPtr) field->data.ptrvalue;
8198
for (vnp = dest_list; vnp != NULL; vnp = vnp->next) {
8199
biop = GetBioSourceFromObject (vnp->choice, vnp->data.ptrvalue);
8200
if (SetSourceQualInBioSource (biop, o->field, NULL, str, existing_text)) {
8206
case ParseDest_featqual:
8207
fl = (FeatureFieldLegalPtr) field->data.ptrvalue;
8210
f.field = ValNodeNew(NULL);
8211
f.field->next = NULL;
8212
f.field->choice = FeatQualChoice_legal_qual;
8213
f.field->data.intvalue = fl->field;
8214
for (vnp = dest_list; vnp != NULL; vnp = vnp->next) {
8215
if (SetQualOnFeature (vnp->data.ptrvalue, &f, NULL, str, existing_text)) {
8219
f.field = ValNodeFree (f.field);
8222
case ParseDest_dbxref:
8223
if (!StringHasNoText (field->data.ptrvalue)) {
8224
for (vnp = dest_list; vnp != NULL; vnp = vnp->next) {
8225
biop = GetBioSourceFromObject (vnp->choice, vnp->data.ptrvalue);
8226
if (SetDBxrefForBioSource (biop, field->data.ptrvalue, str, existing_text)) {
8233
return num_succeeded;
8237
static void StripFieldForSrcList (ParseSourceInfoPtr psip, ParseSrcPtr field, TextPortionPtr text_portion)
8243
if (psip == NULL || field == NULL || text_portion == NULL) return;
8245
switch (field->choice) {
8246
case ParseSrc_defline :
8247
if (psip->sdp != NULL && psip->sdp->choice == Seq_descr_title) {
8248
ReplaceStringForParse (psip->sdp->data.ptrvalue, text_portion);
8252
o = (ParseSrcOrgPtr) field->data.ptrvalue;
8254
if (psip->sdp != NULL && psip->sdp->choice == Seq_descr_source) {
8255
biop = (BioSourcePtr) psip->sdp->data.ptrvalue;
8256
str = GetSourceQualFromBioSource (biop, o->field, NULL);
8257
ReplaceStringForParse (str, text_portion);
8258
SetSourceQualInBioSource (biop, o->field, NULL, str, ExistingTextOption_replace_old);
8259
str = MemFree (str);
8260
} else if (psip->sfp != NULL && psip->sfp->data.choice == SEQFEAT_BIOSRC) {
8261
biop = (BioSourcePtr) psip->sfp->data.value.ptrvalue;
8262
str = GetSourceQualFromBioSource (biop, o->field, NULL);
8263
ReplaceStringForParse (str, text_portion);
8264
SetSourceQualInBioSource (biop, o->field, NULL, str, ExistingTextOption_replace_old);
8265
str = MemFree (str);
8269
case ParseSrc_comment:
8270
if (psip->sdp != NULL) {
8271
if (psip->sdp->choice == Seq_descr_user) {
8272
StripBankitCommentForParse (psip->sdp, text_portion);
8273
} else if (psip->sdp->choice == Seq_descr_comment) {
8274
ReplaceStringForParse (psip->sdp->data.ptrvalue, text_portion);
8277
if (psip->sfp != NULL && psip->sfp->data.choice == SEQFEAT_COMMENT) {
8278
ReplaceStringForParse (psip->sfp->data.value.ptrvalue, text_portion);
8281
case ParseSrc_bankit_comment:
8282
if (psip->sdp != NULL && psip->sdp->choice == Seq_descr_user) {
8283
StripBankitCommentForParse (psip->sdp, text_portion);
8286
case ParseSrc_structured_comment:
8287
if (psip->sdp != NULL && psip->sdp->choice == Seq_descr_user) {
8288
StripStructuredCommentForParse (psip->sdp, field->data.ptrvalue, text_portion);
8295
static Int4 ApplyParseActionToSeqEntry (ParseActionPtr action, SeqEntryPtr sep)
8297
ParseSrcCollectionData psd;
8298
ParseSourceInfoPtr psip;
8299
ValNodePtr orgnames = NULL, source_list_for_removal = NULL, vnp;
8300
Int4 num_succeeded = 0;
8302
if (action == NULL || sep == NULL) return 0;
8304
psd.src = action->src;
8305
psd.portion = action->portion;
8306
psd.src_list = NULL;
8308
/* first, we need to get a list of the parse sources */
8309
VisitBioseqsInSep (sep, &psd, FindParseSourceBioseqCallback);
8311
if (action->capitalization != Cap_change_none) {
8312
/* if we will be fixing capitalization, get org names to use in fixes */
8313
VisitBioSourcesInSep (sep, &orgnames, GetOrgNamesInRecordCallback);
8316
/* for each parse source, we need to get a list of the destinations */
8317
for (vnp = psd.src_list; vnp != NULL; vnp = vnp->next)
8319
if (vnp->data.ptrvalue == NULL) continue;
8320
psip = (ParseSourceInfoPtr) vnp->data.ptrvalue;
8321
if (action->remove_from_parsed) {
8322
ValNodeAddPointer (&source_list_for_removal, 0, ParseSourceInfoCopy (psip));
8324
/* fix source text */
8325
FixCapitalizationInString (&(psip->parse_src_txt), action->capitalization, orgnames);
8327
/* find destinations */
8328
AddParseDestinations (psip, action->dest);
8332
/* free orgname list if we created it */
8333
orgnames = ValNodeFree (orgnames);
8335
CombineSourcesForDestinations (&(psd.src_list));
8337
if (action->dest->choice == ParseDest_org) {
8338
PropagateSourceOnSegSetForParse (psd.src_list);
8341
/* now do the parsing */
8342
for (vnp = psd.src_list; vnp != NULL; vnp = vnp->next) {
8343
psip = (ParseSourceInfoPtr) vnp->data.ptrvalue;
8344
num_succeeded += SetFieldForDestList (psip->dest_list, action->dest, psip->parse_src_txt, action->existing_text);
8347
/* now remove strings from sources */
8348
for (vnp = source_list_for_removal; vnp != NULL; vnp = vnp->next)
8350
if (vnp->data.ptrvalue == NULL) continue;
8351
psip = (ParseSourceInfoPtr) vnp->data.ptrvalue;
8352
StripFieldForSrcList (psip, action->src, action->portion);
8354
return num_succeeded;
8358
static void SetCdRegionGeneticCode (SeqFeatPtr cds)
8361
SeqEntryPtr parent_sep;
8364
ValNodePtr code, vnp;
8366
if (cds == NULL || cds->data.choice != SEQFEAT_CDREGION) return;
8367
if (cds->data.value.ptrvalue == NULL) {
8368
cds->data.value.ptrvalue = CdRegionNew();
8370
crp = (CdRegionPtr) cds->data.value.ptrvalue;
8371
bsp = BioseqFindFromSeqLoc (cds->location);
8372
if (bsp == NULL) return;
8373
parent_sep = GetBestTopParentForData (bsp->idx.entityID, bsp);
8374
genCode = SeqEntryToGeneticCode (parent_sep, NULL, NULL, 0);
8376
code = ValNodeNew (NULL);
8379
vnp = ValNodeNew (NULL);
8380
code->data.ptrvalue = vnp;
8383
vnp->data.intvalue = genCode;
8386
crp->genetic_code = code;
8390
static void CreateDataForFeature (SeqFeatPtr sfp, Int4 feature_type)
8392
Int4 featdef, seqfeattype;
8393
CharPtr label = NULL;
8398
featdef = GetFeatdefFromFeatureType (feature_type);
8399
sfp->idx.subtype = featdef;
8400
seqfeattype = FindFeatFromFeatDefType (featdef);
8401
switch (seqfeattype) {
8403
sfp->data.value.ptrvalue = GeneRefNew();
8405
case SEQFEAT_CDREGION:
8406
sfp->data.value.ptrvalue = CdRegionNew();
8407
SetCdRegionGeneticCode (sfp);
8411
rrp->ext.choice = 0;
8412
sfp->data.value.ptrvalue = rrp;
8414
case FEATDEF_preRNA:
8415
rrp->type = RNA_TYPE_premsg;
8418
rrp->type = RNA_TYPE_mRNA;
8421
rrp->type = RNA_TYPE_tRNA;
8424
rrp->type = RNA_TYPE_rRNA;
8427
rrp->type = RNA_TYPE_other;
8428
rrp->ext.choice = 1;
8429
rrp->ext.value.ptrvalue = StringSave ("ncRNA");
8431
gbq->qual = StringSave ("ncRNA_class");
8432
gbq->val = StringSave ("snRNA");
8435
rrp->type = RNA_TYPE_other;
8436
rrp->ext.choice = 1;
8437
rrp->ext.value.ptrvalue = StringSave ("ncRNA");
8439
gbq->qual = StringSave ("ncRNA_class");
8440
gbq->val = StringSave ("scRNA");
8443
rrp->type = RNA_TYPE_other;
8444
rrp->ext.choice = 1;
8445
rrp->ext.value.ptrvalue = StringSave ("tmRNA");
8448
rrp->type = RNA_TYPE_other;
8449
rrp->ext.choice = 1;
8450
rrp->ext.value.ptrvalue = StringSave ("ncRNA");
8456
sfp->data.value.ptrvalue = ifp;
8457
label = GetFeatureNameFromFeatureType (feature_type);
8458
ifp->key = StringSave (label);
8464
static void ExtraCDSCreationActions (SeqFeatPtr cds, SeqEntryPtr parent_sep)
8471
SeqEntryPtr psep, nsep;
8473
ValNodePtr vnp, descr;
8474
SeqFeatPtr prot_sfp;
8476
Boolean partial5, partial3;
8478
if (cds == NULL) return;
8480
CheckSeqLocForPartial (cds->location, &partial5, &partial3);
8482
/* Create corresponding protein sequence data for the CDS */
8484
bs = ProteinFromCdRegionEx (cds, TRUE, FALSE);
8488
prot = BSMerge (bs, NULL);
8495
while (ch != '\0') {
8496
*ptr = TO_UPPER (ch);
8500
i = StringLen (prot);
8501
if (i > 0 && prot [i - 1] == '*') {
8502
prot [i - 1] = '\0';
8507
BSWrite (bs, (VoidPtr) ptr, (Int4) StringLen (ptr));
8510
/* Create the product protein Bioseq */
8516
bsp->repr = Seq_repr_raw;
8517
bsp->mol = Seq_mol_aa;
8518
bsp->seq_data_type = Seq_code_ncbieaa;
8519
bsp->seq_data = (SeqDataPtr) bs;
8520
bsp->length = BSLen (bs);
8522
bsp->id = MakeNewProteinSeqId (cds->location, NULL);
8523
SeqMgrAddToBioseqIndex (bsp);
8525
/* Create a new SeqEntry for the Prot Bioseq */
8527
psep = SeqEntryNew ();
8532
psep->data.ptrvalue = (Pointer) bsp;
8533
SeqMgrSeqEntry (SM_BIOSEQ, (Pointer) bsp, psep);
8535
/* Add a descriptor to the protein Bioseq */
8537
mip = MolInfoNew ();
8543
if (partial5 && partial3) {
8544
mip->completeness = 5;
8545
} else if (partial5) {
8546
mip->completeness = 3;
8547
} else if (partial3) {
8548
mip->completeness = 4;
8550
vnp = CreateNewDescriptor (psep, Seq_descr_molinfo);
8554
vnp->data.ptrvalue = (Pointer) mip;
8558
descr = ExtractBioSourceAndPubs (parent_sep);
8560
AddSeqEntryToSeqEntry (parent_sep, psep, TRUE);
8561
nsep = FindNucSeqEntry (parent_sep);
8562
ReplaceBioSourceAndPubs (parent_sep, descr);
8563
SetSeqFeatProduct (cds, bsp);
8565
prp = ProtRefNew ();
8568
prot_sfp = CreateNewFeature (psep, NULL, SEQFEAT_PROT, NULL);
8569
if (prot_sfp != NULL) {
8570
prot_sfp->data.value.ptrvalue = (Pointer) prp;
8571
SetSeqLocPartial (prot_sfp->location, partial5, partial3);
8572
prot_sfp->partial = (partial5 || partial3);
8578
static SeqLocPtr LocationFromApplyFeatureAction (BioseqPtr bsp, ApplyFeatureActionPtr action)
8580
LocationIntervalPtr l;
8581
SeqLocPtr slp = NULL;
8582
Uint1 strand = Seq_strand_plus;
8585
if (bsp == NULL || action == NULL || action->location == NULL) return NULL;
8587
if (!action->plus_strand) {
8588
strand = Seq_strand_minus;
8590
if (action->location->choice == LocationChoice_interval) {
8591
l = (LocationIntervalPtr) action->location->data.ptrvalue;
8593
from = MIN (l->from, l->to);
8594
to = MAX (l->from, l->to);
8595
slp = SeqLocIntNew (from, to, strand, SeqIdFindWorst (bsp->id));
8597
} else if (action->location->choice == LocationChoice_whole_sequence) {
8598
slp = SeqLocIntNew (0, bsp->length - 1, strand, SeqIdFindWorst (bsp->id));
8600
SetSeqLocPartial (slp, action->partial5, action->partial3);
8605
static Boolean OkToApplyToBioseq (ApplyFeatureActionPtr action, BioseqPtr bsp)
8608
SeqMgrFeatContext context;
8610
Boolean rval = TRUE;
8612
if (action == NULL || bsp == NULL) return FALSE;
8614
if (!action->add_redundant) {
8615
featdef = GetFeatdefFromFeatureType (action->type);
8616
sfp = SeqMgrGetNextFeature (bsp, NULL, 0, featdef, &context);
8624
static void AddParts (ApplyFeatureActionPtr action, BioseqSetPtr parts, ValNodePtr PNTR bsp_list)
8629
if (action == NULL || !action->apply_to_parts
8630
|| parts == NULL || parts->_class != BioseqseqSet_class_parts
8631
|| bsp_list == NULL) {
8635
if (action->only_seg_num > -1) {
8637
sep = parts->seq_set;
8638
while (seg_num < action->only_seg_num && sep != NULL) {
8642
if (sep != NULL && IS_Bioseq (sep) && OkToApplyToBioseq (action, sep->data.ptrvalue)) {
8643
ValNodeAddPointer (bsp_list, OBJ_BIOSEQ, sep->data.ptrvalue);
8646
for (sep = parts->seq_set; sep != NULL; sep = sep->next) {
8647
if (IS_Bioseq (sep) && OkToApplyToBioseq (action, sep->data.ptrvalue)) {
8648
ValNodeAddPointer (bsp_list, OBJ_BIOSEQ, sep->data.ptrvalue);
8655
static void AddSequenceOrParts (ApplyFeatureActionPtr action, BioseqPtr bsp, ValNodePtr PNTR bsp_list)
8657
BioseqSetPtr bssp, parts;
8660
if (action == NULL || bsp == NULL || bsp_list == NULL) return;
8662
if (bsp->idx.parenttype == OBJ_BIOSEQSET && bsp->idx.parentptr != NULL) {
8663
bssp = (BioseqSetPtr) bsp->idx.parentptr;
8664
if (bssp->_class == BioseqseqSet_class_segset) {
8665
if (action->apply_to_parts) {
8666
sep = bssp->seq_set;
8667
while (sep != NULL && !IS_Bioseq_set (sep)) {
8671
AddParts (action, sep->data.ptrvalue, bsp_list);
8674
if (OkToApplyToBioseq (action, bsp)) {
8675
ValNodeAddPointer (bsp_list, OBJ_BIOSEQ, bsp);
8678
} else if (bssp->_class == BioseqseqSet_class_parts) {
8679
if (action->apply_to_parts) {
8680
AddParts (action, bssp, bsp_list);
8683
if (parts->idx.parenttype == OBJ_BIOSEQSET && parts->idx.parentptr != NULL) {
8684
bssp = (BioseqSetPtr) parts->idx.parentptr;
8685
if (IS_Bioseq (bssp->seq_set) && OkToApplyToBioseq (action, bssp->seq_set->data.ptrvalue)) {
8686
ValNodeAddPointer (bsp_list, OBJ_BIOSEQ, bsp_list);
8691
if (OkToApplyToBioseq (action, bsp)) {
8692
ValNodeAddPointer (bsp_list, OBJ_BIOSEQ, bsp);
8696
if (OkToApplyToBioseq (action, bsp)) {
8697
ValNodeAddPointer (bsp_list, OBJ_BIOSEQ, bsp);
8702
static void AddSequenceOrPartsFromSeqEntry (ApplyFeatureActionPtr action, SeqEntryPtr sep, ValNodePtr PNTR bsp_list)
8705
SeqEntryPtr seq_set;
8707
if (action == NULL || sep == NULL) return;
8709
while (sep != NULL) {
8710
if (IS_Bioseq (sep)) {
8711
AddSequenceOrParts (action, sep->data.ptrvalue, bsp_list);
8712
} else if (IS_Bioseq_set (sep)) {
8713
bssp = (BioseqSetPtr) sep->data.ptrvalue;
8714
if (bssp->_class == BioseqseqSet_class_segset) {
8715
/* find master segment */
8716
seq_set = bssp->seq_set;
8717
while (seq_set != NULL && !IS_Bioseq (seq_set)) {
8718
seq_set = seq_set->next;
8720
if (seq_set != NULL) {
8721
AddSequenceOrParts (action, seq_set->data.ptrvalue, bsp_list);
8723
} else if (bssp->_class == BioseqseqSet_class_nuc_prot) {
8724
/* find nucleotide sequence */
8725
seq_set = bssp->seq_set;
8726
if (seq_set != NULL) {
8727
if (IS_Bioseq_set (seq_set)) {
8728
/* nucleotide is segmented set */
8729
bssp = (BioseqSetPtr) seq_set->data.ptrvalue;
8730
if (bssp != NULL && bssp->_class == BioseqseqSet_class_segset
8731
&& bssp->seq_set != NULL && IS_Bioseq (bssp->seq_set)) {
8732
AddSequenceOrParts (action, bssp->seq_set->data.ptrvalue, bsp_list);
8734
} else if (IS_Bioseq (seq_set)) {
8735
AddSequenceOrParts (action, seq_set->data.ptrvalue, bsp_list);
8739
/* add from set members */
8740
AddSequenceOrPartsFromSeqEntry (action, bssp->seq_set, bsp_list);
8748
static void AdjustProteinSequenceForReadingFrame (SeqFeatPtr cds)
8750
BioseqPtr protbsp, bsp;
8752
SeqFeatPtr prot_sfp;
8753
Boolean partial5, partial3;
8755
if (cds == NULL || cds->data.choice != SEQFEAT_CDREGION) return;
8757
protbsp = BioseqFindFromSeqLoc (cds->product);
8759
if (protbsp == NULL) {
8760
bsp = BioseqFindFromSeqLoc (cds->location);
8762
ExtraCDSCreationActions (cds, GetBestTopParentForData (bsp->idx.entityID, bsp));
8765
bs = ProteinFromCdRegionExWithTrailingCodonHandling (cds,
8769
protbsp->seq_data = (SeqDataPtr) BSFree ((ByteStorePtr)(protbsp->seq_data));
8770
protbsp->seq_data = (SeqDataPtr) bs;
8771
protbsp->length = BSLen (bs);
8772
prot_sfp = GetProtFeature (protbsp);
8773
if (prot_sfp == NULL) {
8774
CheckSeqLocForPartial (cds->location, &partial5, &partial3);
8775
prot_sfp = CreateNewFeatureOnBioseq (protbsp, SEQFEAT_PROT, NULL);
8776
prot_sfp->data.value.ptrvalue = ProtRefNew ();
8777
SetSeqLocPartial (prot_sfp->location, partial5, partial3);
8778
prot_sfp->partial = (partial5 || partial3);
8780
if (SeqLocLen (prot_sfp->location) != protbsp->length) {
8781
prot_sfp->location = SeqLocFree (prot_sfp->location);
8782
prot_sfp->location = SeqLocIntNew (0, protbsp->length - 1, Seq_strand_plus, SeqIdFindWorst (protbsp->id));
8789
static Int4 ApplyApplyFeatureActionToSeqEntry (ApplyFeatureActionPtr action, SeqEntryPtr sep)
8791
ValNodePtr bsp_list = NULL, vnp, field_vnp;
8792
Int4 featdef, seqfeattype;
8796
FeatQualLegalValPtr q;
8800
Int4 num_created = 0;
8802
if (sep == NULL || action == NULL) return 0;
8804
/* first, get list of Bioseqs to apply features to */
8805
/* relevant values : seq_list, add_redundant, apply_to_parts, only_seg_num */
8806
if (action->seq_list != NULL && action->seq_list->choice == SequenceListChoice_list) {
8807
for (vnp = action->seq_list->data.ptrvalue; vnp != NULL; vnp = vnp->next) {
8808
sip = CreateSeqIdFromText (vnp->data.ptrvalue, sep);
8809
bsp = BioseqFind (sip);
8811
AddSequenceOrParts (action, bsp, &bsp_list);
8815
AddSequenceOrPartsFromSeqEntry (action, sep, &bsp_list);
8818
/* now add feature to each bioseq in list */
8819
for (vnp = bsp_list; vnp != NULL; vnp = vnp->next) {
8820
bsp = vnp->data.ptrvalue;
8821
if (bsp == NULL) continue;
8822
featdef = GetFeatdefFromFeatureType (action->type);
8823
seqfeattype = FindFeatFromFeatDefType (featdef);
8824
slp = LocationFromApplyFeatureAction (bsp, action);
8825
sfp = CreateNewFeatureOnBioseq (bsp, seqfeattype, slp);
8826
if (sfp == NULL) continue;
8827
CreateDataForFeature (sfp, action->type);
8828
/* any extra actions */
8829
switch (action->type) {
8830
case (Feature_type_cds) :
8831
ExtraCDSCreationActions (sfp, GetBestTopParentForData (bsp->idx.entityID, bsp));
8835
for (field_vnp = action->fields; field_vnp != NULL; field_vnp = field_vnp->next) {
8836
q = (FeatQualLegalValPtr) field_vnp->data.ptrvalue;
8838
f.field = ValNodeNew(NULL);
8839
f.field->next = NULL;
8840
f.field->choice = FeatQualChoice_legal_qual;
8841
f.field->data.intvalue = q->qual;
8842
if (sfp->data.choice != SEQFEAT_GENE
8843
&& (q->qual == Feat_qual_legal_gene || q->qual == Feat_qual_legal_gene_description)) {
8845
gene = CreateNewFeatureOnBioseq (bsp, SEQFEAT_GENE, slp);
8846
CreateDataForFeature (gene, Feature_type_gene);
8848
f.type = Feature_type_gene;
8849
SetQualOnFeature (gene, &f, NULL, q->val, ExistingTextOption_replace_old);
8851
f.type = action->type;
8852
SetQualOnFeature (sfp, &f, NULL, q->val, ExistingTextOption_replace_old);
8856
if (action->type == Feature_type_cds) {
8857
/* retranslate, to account for change in reading frame */
8858
AdjustProteinSequenceForReadingFrame (sfp);
8859
/* after the feature has been created, then adjust it for gaps */
8860
/* Note - this step may result in multiple coding regions being created. */
8861
AdjustCDSLocationsForUnknownGapsCallback (sfp, NULL);
8869
typedef struct convertandremovefeaturecollection {
8871
ValNodePtr constraint_set;
8872
ValNodePtr feature_list;
8873
} ConvertAndRemoveFeatureCollectionData, PNTR ConvertAndRemoveFeatureCollectionPtr;
8875
static void ConvertAndRemoveFeatureCollectionCallback (SeqFeatPtr sfp, Pointer data)
8877
ConvertAndRemoveFeatureCollectionPtr p;
8879
if (sfp == NULL || data == NULL) return;
8881
p = (ConvertAndRemoveFeatureCollectionPtr) data;
8882
if (sfp->idx.subtype == p->featdef && DoesObjectMatchConstraintChoiceSet (OBJ_SEQFEAT, sfp, p->constraint_set)) {
8883
ValNodeAddPointer (&(p->feature_list), OBJ_SEQFEAT, sfp);
8888
static Int4 ApplyRemoveFeatureActionToSeqEntry (RemoveFeatureActionPtr action, SeqEntryPtr sep)
8890
ConvertAndRemoveFeatureCollectionData d;
8893
Int4 num_deleted = 0;
8895
if (action == NULL) return 0;
8897
d.featdef = GetFeatdefFromFeatureType (action->type);
8898
d.constraint_set = action->constraint;
8899
d.feature_list = NULL;
8901
VisitFeaturesInSep (sep, &d, ConvertAndRemoveFeatureCollectionCallback);
8902
for (vnp = d.feature_list; vnp != NULL; vnp = vnp->next) {
8903
sfp = vnp->data.ptrvalue;
8905
sfp->idx.deleteme = TRUE;
8909
DeleteMarkedObjects (ObjMgrGetEntityIDForChoice(sep), 0, NULL);
8914
static Boolean DoesStrandMatch (Int4 strand_choice, Uint1 strand_val)
8916
Boolean rval = FALSE;
8918
switch (strand_choice)
8920
case Feature_location_strand_from_any:
8923
case Feature_location_strand_from_unknown:
8924
if (strand_val == Seq_strand_unknown)
8929
case Feature_location_strand_from_plus:
8930
if (strand_val != Seq_strand_minus)
8935
case Feature_location_strand_from_minus:
8936
if (strand_val == Seq_strand_minus)
8941
case Feature_location_strand_from_both:
8942
if (strand_val == Seq_strand_both)
8952
static Uint1 GetNewStrandValue (Int4 strand_choice, Uint1 strand_val)
8954
Uint1 rval = Seq_strand_unknown;
8956
switch (strand_choice)
8958
case Feature_location_strand_to_reverse:
8961
case Seq_strand_plus:
8962
case Seq_strand_unknown:
8963
rval = Seq_strand_minus;
8965
case Seq_strand_minus:
8966
rval = Seq_strand_plus;
8973
case Feature_location_strand_to_unknown:
8974
rval = Seq_strand_unknown;
8976
case Feature_location_strand_to_plus:
8977
rval = Seq_strand_plus;
8979
case Feature_location_strand_to_minus:
8980
rval = Seq_strand_minus;
8982
case Feature_location_strand_to_both:
8983
rval = Seq_strand_both;
8990
static Boolean ConvertLocationStrand (SeqLocPtr slp, Int4 fromStrand, Int4 toStrand)
8997
Boolean rval = FALSE;
9000
while (slp != NULL) {
9001
switch (slp->choice) {
9008
sinp = (SeqIntPtr) slp->data.ptrvalue;
9009
if (sinp != NULL && DoesStrandMatch (fromStrand, sinp->strand))
9011
strand_orig = sinp->strand;
9012
sinp->strand = GetNewStrandValue (toStrand, sinp->strand);
9013
if (strand_orig != sinp->strand) {
9019
spp = (SeqPntPtr) slp->data.ptrvalue;
9020
if (spp != NULL && DoesStrandMatch (fromStrand, spp->strand))
9022
strand_orig = spp->strand;
9023
spp->strand = GetNewStrandValue (toStrand, spp->strand);
9024
if (strand_orig != spp->strand) {
9029
case SEQLOC_PACKED_PNT :
9030
psp = (PackSeqPntPtr) slp->data.ptrvalue;
9031
if (psp != NULL && DoesStrandMatch (fromStrand, psp->strand))
9033
strand_orig = psp->strand;
9034
psp->strand = GetNewStrandValue (toStrand, psp->strand);
9035
if (strand_orig != psp->strand) {
9040
case SEQLOC_PACKED_INT :
9043
loc = (SeqLocPtr) slp->data.ptrvalue;
9044
while (loc != NULL) {
9045
rval |= ConvertLocationStrand (loc, fromStrand, toStrand);
9050
sbp = (SeqBondPtr) slp->data.ptrvalue;
9052
spp = (SeqPntPtr) sbp->a;
9053
if (spp != NULL && DoesStrandMatch (fromStrand, spp->strand))
9055
strand_orig = spp->strand;
9056
spp->strand = GetNewStrandValue (toStrand, spp->strand);
9057
if (strand_orig != spp->strand) {
9061
spp = (SeqPntPtr) sbp->b;
9062
if (spp != NULL && DoesStrandMatch (fromStrand, spp->strand))
9064
strand_orig = spp->strand;
9065
spp->strand = GetNewStrandValue (toStrand, spp->strand);
9066
if (strand_orig != spp->strand) {
9083
static Boolean ApplyEditLocationStrandToSeqFeat (EditLocationStrandPtr edit, SeqFeatPtr sfp)
9085
Boolean rval = FALSE;
9087
if (edit == NULL || sfp == NULL) {
9091
rval = ConvertLocationStrand (sfp->location, edit->strand_from, edit->strand_to);
9096
static Boolean At5EndOfSequence (SeqLocPtr slp, BioseqPtr bsp)
9100
Boolean at_end = FALSE;
9102
if (slp == NULL || bsp == NULL) return FALSE;
9104
strand = SeqLocStrand (slp);
9106
if (strand == Seq_strand_minus) {
9107
start = SeqLocStop (slp);
9108
if (start == bsp->length - 1) {
9112
start = SeqLocStart (slp);
9121
static Boolean HasGoodStartCodon (SeqFeatPtr sfp)
9125
Boolean has_start = FALSE;
9127
if (sfp != NULL && sfp->data.choice == SEQFEAT_CDREGION) {
9128
bs = ProteinFromCdRegionEx (sfp, TRUE, FALSE);
9130
prot = BSMerge (bs, NULL);
9132
if (prot != NULL && *prot == 'M') {
9135
prot = MemFree (prot);
9142
static Boolean ApplyPartial5SetActionToSeqFeat (Partial5SetActionPtr action, SeqFeatPtr sfp)
9144
Boolean rval = FALSE;
9145
Boolean make_partial = FALSE;
9149
Boolean partial5, partial3;
9151
if (action == NULL || sfp == NULL) return FALSE;
9152
bsp = BioseqFindFromSeqLoc (sfp->location);
9153
strand = SeqLocStrand (sfp->location);
9155
switch (action->constraint) {
9156
case Partial_5_set_constraint_all:
9157
make_partial = TRUE;
9159
case Partial_5_set_constraint_at_end:
9160
make_partial = At5EndOfSequence (sfp->location, bsp);
9162
case Partial_5_set_constraint_bad_start:
9163
make_partial = HasGoodStartCodon (sfp);
9165
case Partial_5_set_constraint_frame_not_one:
9166
if (sfp->data.choice == SEQFEAT_CDREGION
9167
&& (crp = sfp->data.value.ptrvalue) != NULL
9168
&& crp->frame != 0 && crp->frame != 1) {
9169
make_partial = TRUE;
9175
CheckSeqLocForPartial (sfp->location, &partial5, &partial3);
9177
SetSeqLocPartial (sfp->location, TRUE, partial3);
9178
if (action->extend && bsp != NULL) {
9179
ExtendSeqLocToEnd (sfp->location, bsp, TRUE);
9188
static Boolean ApplyClear5PartialToSeqFeat (Int4 action, SeqFeatPtr sfp)
9190
Boolean rval = FALSE, clear_partial = FALSE;
9191
Boolean partial5, partial3;
9193
if (sfp == NULL) return FALSE;
9196
case Partial_5_clear_constraint_all:
9197
clear_partial = TRUE;
9199
case Partial_5_clear_constraint_not_at_end:
9200
clear_partial = !At5EndOfSequence(sfp->location, BioseqFindFromSeqLoc (sfp->location));
9202
case Partial_5_clear_constraint_good_start:
9203
clear_partial = !HasGoodStartCodon(sfp);
9206
if (clear_partial) {
9207
CheckSeqLocForPartial (sfp->location, &partial5, &partial3);
9209
SetSeqLocPartial (sfp->location, FALSE, partial3);
9217
static Boolean At3EndOfSequence (SeqLocPtr slp, BioseqPtr bsp)
9221
Boolean at_end = FALSE;
9223
if (slp == NULL || bsp == NULL) return FALSE;
9225
strand = SeqLocStrand (slp);
9227
if (strand == Seq_strand_minus) {
9228
stop = SeqLocStart (slp);
9233
stop = SeqLocStop (slp);
9234
if (stop == bsp->length - 1) {
9242
static Boolean HasGoodStopCodon (SeqFeatPtr sfp)
9246
Boolean has_stop = FALSE;
9248
if (sfp != NULL && sfp->data.choice == SEQFEAT_CDREGION) {
9249
bs = ProteinFromCdRegionEx (sfp, TRUE, FALSE);
9251
prot = BSMerge (bs, NULL);
9253
if (prot != NULL && prot[StringLen (prot) - 1] == '*') {
9256
prot = MemFree (prot);
9263
static Boolean ApplyPartial3SetActionToSeqFeat (Partial3SetActionPtr action, SeqFeatPtr sfp)
9265
Boolean rval = FALSE;
9266
Boolean make_partial = FALSE;
9269
Boolean partial5, partial3;
9271
if (action == NULL || sfp == NULL) return FALSE;
9272
bsp = BioseqFindFromSeqLoc (sfp->location);
9273
strand = SeqLocStrand (sfp->location);
9275
switch (action->constraint) {
9276
case Partial_3_set_constraint_all:
9277
make_partial = TRUE;
9279
case Partial_3_set_constraint_at_end:
9280
make_partial = At3EndOfSequence (sfp->location, bsp);
9282
case Partial_3_set_constraint_bad_end:
9283
make_partial = HasGoodStopCodon (sfp);
9288
CheckSeqLocForPartial (sfp->location, &partial5, &partial3);
9290
SetSeqLocPartial (sfp->location, partial5, TRUE);
9291
if (action->extend && bsp != NULL) {
9292
ExtendSeqLocToEnd (sfp->location, bsp, FALSE);
9301
static Boolean ApplyClear3PartialToSeqFeat (Int4 action, SeqFeatPtr sfp)
9303
Boolean rval = FALSE, clear_partial = FALSE;
9304
Boolean partial5, partial3;
9306
if (sfp == NULL) return FALSE;
9309
case Partial_3_clear_constraint_all:
9310
clear_partial = TRUE;
9312
case Partial_3_clear_constraint_not_at_end:
9313
clear_partial = !At3EndOfSequence(sfp->location, BioseqFindFromSeqLoc (sfp->location));
9315
case Partial_3_clear_constraint_good_end:
9316
clear_partial = !HasGoodStopCodon(sfp);
9319
if (clear_partial) {
9320
CheckSeqLocForPartial (sfp->location, &partial5, &partial3);
9322
SetSeqLocPartial (sfp->location, partial5, FALSE);
9330
static Boolean ApplyConvertLocationToSeqFeat (Int4 convert_location, SeqFeatPtr sfp)
9332
Boolean hasNulls, rval = FALSE;
9335
Boolean partial5, partial3;
9337
if (sfp == NULL || (bsp = BioseqFindFromSeqLoc (sfp->location))== NULL) {
9341
CheckSeqLocForPartial (sfp->location, &partial5, &partial3);
9342
hasNulls = LocationHasNullsBetween (sfp->location);
9343
switch (convert_location)
9345
case Convert_location_type_join :
9348
slp = SeqLocMerge (bsp, sfp->location, NULL, FALSE, FALSE, FALSE);
9349
sfp->location = SeqLocFree (sfp->location);
9350
sfp->location = slp;
9351
if (bsp->repr == Seq_repr_seg)
9353
slp = SegLocToPartsEx (bsp, sfp->location, FALSE);
9354
sfp->location = SeqLocFree (sfp->location);
9355
sfp->location = slp;
9356
hasNulls = LocationHasNullsBetween (sfp->location);
9357
sfp->partial = (sfp->partial || hasNulls);
9359
FreeAllFuzz (sfp->location);
9360
SetSeqLocPartial (sfp->location, partial5, partial3);
9364
case Convert_location_type_order :
9367
slp = SeqLocMerge (bsp, sfp->location, NULL, FALSE, FALSE, TRUE);
9368
sfp->location = SeqLocFree (sfp->location);
9369
sfp->location = slp;
9370
if (bsp->repr == Seq_repr_seg)
9372
slp = SegLocToPartsEx (bsp, sfp->location, TRUE);
9373
sfp->location = SeqLocFree (sfp->location);
9374
sfp->location = slp;
9375
hasNulls = LocationHasNullsBetween (sfp->location);
9376
sfp->partial = (sfp->partial || hasNulls);
9378
FreeAllFuzz (sfp->location);
9379
SetSeqLocPartial (sfp->location, partial5, partial3);
9383
case Convert_location_type_merge :
9384
if (sfp->location->choice != SEQLOC_INT) {
9385
slp = SeqLocMerge (bsp, sfp->location, NULL, TRUE, FALSE, FALSE);
9386
sfp->location = SeqLocFree (sfp->location);
9387
sfp->location = slp;
9388
SetSeqLocPartial (sfp->location, partial5, partial3);
9398
static Boolean ApplyLocationEditTypeToSeqFeat (ValNodePtr action, SeqFeatPtr sfp)
9400
Boolean rval = FALSE;
9402
if (action == NULL || sfp == NULL) {
9406
switch (action->choice) {
9407
case LocationEditType_strand:
9408
rval = ApplyEditLocationStrandToSeqFeat (action->data.ptrvalue, sfp);
9410
case LocationEditType_set_5_partial:
9411
rval = ApplyPartial5SetActionToSeqFeat (action->data.ptrvalue, sfp);
9413
case LocationEditType_clear_5_partial:
9414
rval = ApplyClear5PartialToSeqFeat (action->data.intvalue, sfp);
9416
case LocationEditType_set_3_partial:
9417
rval = ApplyPartial3SetActionToSeqFeat (action->data.ptrvalue, sfp);
9419
case LocationEditType_clear_3_partial:
9420
rval = ApplyClear3PartialToSeqFeat (action->data.intvalue, sfp);
9422
case LocationEditType_convert:
9423
rval = ApplyConvertLocationToSeqFeat (action->data.intvalue, sfp);
9430
static Int4 ApplyEditFeatureLocationActionToSeqEntry (EditFeatureLocationActionPtr action, SeqEntryPtr sep)
9432
ConvertAndRemoveFeatureCollectionData d;
9435
Int4 num_affected = 0;
9437
if (action == NULL) return 0;
9439
d.featdef = GetFeatdefFromFeatureType (action->type);
9440
d.constraint_set = action->constraint;
9441
d.feature_list = NULL;
9443
VisitFeaturesInSep (sep, &d, ConvertAndRemoveFeatureCollectionCallback);
9444
for (vnp = d.feature_list; vnp != NULL; vnp = vnp->next) {
9445
sfp = vnp->data.ptrvalue;
9446
if (sfp != NULL && ApplyLocationEditTypeToSeqFeat (action->action, sfp)) {
9450
return num_affected;
9454
NLM_EXTERN void ApplyMacroToSeqEntry (SeqEntryPtr sep, ValNodePtr macro, Int4Ptr pNumFields, Int4Ptr pNumFeat)
9456
Int4 num_AECR = 0, num_parse = 0, num_feature = 0, num_fields = 0;
9458
while (macro != NULL) {
9459
switch (macro->choice) {
9460
case MacroActionChoice_aecr:
9461
num_AECR += ApplyAECRActionToSeqEntry ((AECRActionPtr) macro->data.ptrvalue, sep);
9463
case MacroActionChoice_parse:
9464
num_parse += ApplyParseActionToSeqEntry ((ParseActionPtr) macro->data.ptrvalue, sep);
9466
case MacroActionChoice_add_feature:
9467
num_feature += ApplyApplyFeatureActionToSeqEntry ((ApplyFeatureActionPtr) macro->data.ptrvalue, sep);
9468
SeqMgrIndexFeatures (ObjMgrGetEntityIDForChoice(sep), NULL);
9470
case MacroActionChoice_remove_feature:
9471
num_feature += ApplyRemoveFeatureActionToSeqEntry ((RemoveFeatureActionPtr) macro->data.ptrvalue, sep);
9473
case MacroActionChoice_edit_location:
9474
num_fields += ApplyEditFeatureLocationActionToSeqEntry ((EditFeatureLocationActionPtr) macro->data.ptrvalue, sep);
9477
macro = macro->next;
9479
if (pNumFields != NULL) {
9480
*pNumFields = num_AECR + num_parse + num_fields;
9482
if (pNumFeat != NULL) {
9483
*pNumFeat = num_feature;
9488
/* for generating text descriptions of macro objects */
9489
NLM_EXTERN CharPtr SummarizeSourceQual (ValNodePtr field)
9491
CharPtr summ = NULL, locname, origname;
9492
Int4 genome, origin;
9493
CharPtr loc_fmt = "location %s";
9494
CharPtr orig_fmt = "origin %s";
9496
if (field == NULL) return NULL;
9497
switch (field->choice) {
9498
case SourceQualChoice_textqual:
9499
summ = StringSave (GetSourceQualName (field->data.intvalue));
9501
case SourceQualChoice_location:
9502
genome = GenomeFromSrcLoc (field->data.intvalue);
9503
locname = LocNameFromGenome (genome);
9504
summ = (CharPtr) MemNew (sizeof (Char) * (StringLen (loc_fmt) + StringLen (locname)));
9505
sprintf (summ, loc_fmt, locname);
9507
case SourceQualChoice_origin:
9508
origin = OriginFromSrcOrig (field->data.intvalue);
9509
origname = OriginNameFromOrigin (origin);
9510
summ = (CharPtr) MemNew (sizeof (Char) * (StringLen (orig_fmt) + StringLen (origname)));
9511
sprintf (summ, orig_fmt, origname);
9518
NLM_EXTERN CharPtr FeatureFieldLabel (CharPtr feature_name, ValNodePtr field)
9521
CharPtr label = NULL;
9522
CharPtr legal_fmt = "%s %s";
9523
CharPtr illegal_fmt = "constrained field on %s";
9525
if (feature_name == NULL) {
9526
feature_name = "Unknown feature";
9529
if (field == NULL) {
9530
return StringSave ("missing field");
9531
} else if (field->choice == FeatQualChoice_legal_qual) {
9532
cp = GetFeatQualName (field->data.intvalue);
9533
if (cp == NULL) cp = "Unknown field type";
9534
label = (CharPtr) MemNew (sizeof (Char) * (StringLen (legal_fmt) + StringLen (feature_name) + StringLen (cp)));
9535
sprintf (label, legal_fmt, feature_name, cp);
9536
} else if (field->choice == FeatQualChoice_illegal_qual) {
9537
label = (CharPtr) MemNew (sizeof (Char) * (StringLen (illegal_fmt) + StringLen (feature_name)));
9538
sprintf (label, illegal_fmt, feature_name);
9540
label = StringSave ("illegal field value");
9546
NLM_EXTERN Boolean IsFeatureFieldEmpty (FeatureFieldPtr field)
9548
if (field == NULL) return TRUE;
9549
if (field->field == NULL) return TRUE;
9554
NLM_EXTERN Boolean IsFieldTypeEmpty (FieldTypePtr field)
9556
Boolean rval = TRUE;
9558
if (field == NULL) return TRUE;
9559
switch (field->choice) {
9560
case FieldType_source_qual:
9561
if (field->data.ptrvalue != NULL) {
9565
case FieldType_feature_field:
9566
if (!IsFeatureFieldEmpty (field->data.ptrvalue)) {
9570
case FieldType_cds_gene_prot:
9578
NLM_EXTERN CharPtr SummarizeFieldType (ValNodePtr vnp)
9580
FeatureFieldPtr ffp;
9582
CharPtr label = NULL;
9585
str = StringSave ("missing field");
9587
switch (vnp->choice) {
9588
case FieldType_source_qual:
9589
str = SummarizeSourceQual (vnp->data.ptrvalue);
9591
case FieldType_feature_field:
9592
ffp = (FeatureFieldPtr) vnp->data.ptrvalue;
9593
if (ffp == NULL || ffp->field == NULL) {
9594
str = StringSave ("missing field");
9596
label = GetFeatureNameFromFeatureType (ffp->type);
9597
str = FeatureFieldLabel (label, ffp->field);
9600
case FieldType_cds_gene_prot:
9601
str = StringSaveNoNull (CDSGeneProtNameFromField (vnp->data.intvalue));
9603
str = StringSave ("Invalid CDS-Gene-Prot Field");
9606
case FieldType_molinfo_field:
9607
str = GetSequenceQualName (vnp->data.ptrvalue);
9609
str = StringSave ("Invalid Sequence Qual Field");
9613
str = StringSave ("Invalid field type");
9621
/* for table readers that use the macro language functions */
9622
NLM_EXTERN TabColumnConfigPtr TabColumnConfigNew (void)
9624
TabColumnConfigPtr t;
9626
t = (TabColumnConfigPtr) MemNew (sizeof (TabColumnConfigData));
9628
t->existing_text = ExistingTextOption_replace_old;
9629
t->skip_blank = TRUE;
9635
NLM_EXTERN TabColumnConfigPtr TabColumnConfigFree (TabColumnConfigPtr t)
9638
t->field = FieldTypeFree (t->field);
9645
NLM_EXTERN TabColumnConfigPtr TabColumnConfigCopy (TabColumnConfigPtr orig)
9647
TabColumnConfigPtr t = NULL;
9650
t = TabColumnConfigNew ();
9651
t->match_type = orig->match_type;
9652
t->existing_text = orig->existing_text;
9653
t->skip_blank = orig->skip_blank;
9654
t->match_mrna = orig->match_mrna;
9655
t->field = AsnIoMemCopy (orig->field, (AsnReadFunc) FieldTypeAsnRead, (AsnWriteFunc) FieldTypeAsnWrite);
9661
NLM_EXTERN ValNodePtr TabColumnConfigListFree (ValNodePtr columns)
9663
ValNodePtr vnp_next;
9665
while (columns != NULL) {
9666
vnp_next = columns->next;
9667
columns->data.ptrvalue = TabColumnConfigFree (columns->data.ptrvalue);
9668
columns->next = NULL;
9669
columns = ValNodeFree (columns);
9676
NLM_EXTERN ValNodePtr TabColumnConfigListCopy (ValNodePtr orig)
9678
ValNodePtr new_list = NULL;
9679
TabColumnConfigPtr t;
9681
while (orig != NULL) {
9682
t = TabColumnConfigCopy (orig->data.ptrvalue);
9683
ValNodeAddPointer (&new_list, 0, t);
9691
/* This checks the column names and returns a list of the feature fields */
9692
NLM_EXTERN ValNodePtr ValidateFeatureFieldColumnNames (ValNodePtr header_line, ValNodePtr PNTR perr_list)
9694
ValNodePtr header_vnp;
9695
ValNodePtr err_list = NULL, col_list = NULL;
9696
Boolean rval = TRUE;
9697
TabColumnConfigPtr t;
9698
FeatureFieldPtr field;
9699
Int4 featqual, feat_type;
9700
CharPtr first_space;
9702
if (header_line == NULL)
9707
header_vnp = header_line->data.ptrvalue;
9708
if (header_vnp == NULL || header_vnp->next == NULL)
9713
/* skip ID column */
9714
header_vnp = header_vnp->next;
9715
while (header_vnp != NULL && rval)
9717
first_space = StringChr (header_vnp->data.ptrvalue, ' ');
9718
if (first_space != NULL) {
9720
feat_type = GetFeatureTypeByName (header_vnp->data.ptrvalue);
9721
featqual = GetFeatQualByName (first_space + 1);
9723
if (feat_type < 0 || featqual < 0) {
9724
/* unable to recognize column name */
9725
ValNodeAddPointer (&err_list, 0, StringSave (header_vnp->data.ptrvalue));
9726
/* if we're not able to send back a list of errors, just quit now */
9727
if (perr_list == NULL) {
9730
} else if (err_list == NULL) {
9731
/* if we've already found errors, don't bother collecting more fields */
9732
field = FeatureFieldNew ();
9733
field->type = feat_type;
9734
field->field = ValNodeNew (NULL);
9735
field->field->choice = FeatQualChoice_legal_qual;
9736
field->field->data.intvalue = featqual;
9737
t = TabColumnConfigNew ();
9738
t->field = ValNodeNew (NULL);
9739
t->field->choice = FieldType_feature_field;
9740
t->field->data.ptrvalue = field;
9741
ValNodeAddPointer (&col_list, 0, t);
9744
featqual = GetFeatQualByName (header_vnp->data.ptrvalue);
9746
/* unable to recognize column name */
9747
ValNodeAddPointer (&err_list, 0, StringSave (header_vnp->data.ptrvalue));
9748
/* if we're not able to send back a list of errors, just quit now */
9749
if (perr_list == NULL) {
9752
} else if (err_list == NULL) {
9753
/* if we've already found errors, don't bother collecting more fields */
9754
field = FeatureFieldNew ();
9755
field->type = Feature_type_any;
9756
field->field = ValNodeNew (NULL);
9757
field->field->choice = FeatQualChoice_legal_qual;
9758
field->field->data.intvalue = featqual;
9759
t = TabColumnConfigNew ();
9760
t->field = ValNodeNew (NULL);
9761
t->field->choice = FieldType_feature_field;
9762
t->field->data.ptrvalue = field;
9763
ValNodeAddPointer (&col_list, 0, t);
9766
header_vnp = header_vnp->next;
9768
if (err_list != NULL) {
9769
col_list = TabColumnConfigListFree (col_list);
9770
if (perr_list != NULL) {
9771
*perr_list = err_list;
9773
err_list = ValNodeFreeData (err_list);
9779
typedef struct findgenelocustag {
9781
ValNodePtr gene_list;
9782
} FindGeneLocusTagData, PNTR FindGeneLocusTagPtr;
9784
static void FindGeneByLocusTagBioseqCallback (BioseqPtr bsp, Pointer userdata)
9786
FindGeneLocusTagPtr p;
9788
SeqMgrFeatContext fcontext;
9790
if (bsp == NULL || userdata == NULL || !ISA_na (bsp->mol)) {
9794
p = (FindGeneLocusTagPtr) userdata;
9796
gene = SeqMgrGetGeneByLocusTag (bsp, p->locus_tag, &fcontext);
9798
ValNodeAddPointer (&p->gene_list, OBJ_SEQFEAT, gene);
9803
typedef struct objbystr {
9804
ValNodePtr obj_list;
9806
} ObjByStrData, PNTR ObjByStrPtr;
9808
static void GetFeaturesByDbxrefCallback (SeqFeatPtr sfp, Pointer userdata)
9814
Boolean found = FALSE;
9816
if (sfp == NULL || sfp->dbxref == NULL || userdata == NULL) return;
9817
p = (ObjByStrPtr) userdata;
9819
if (StringHasNoText (p->str)) return;
9821
for (vnp = sfp->dbxref; vnp != NULL && !found; vnp = vnp->next) {
9822
dbt = (DbtagPtr) vnp->data.ptrvalue;
9823
if (dbt != NULL && dbt->tag != NULL) {
9824
if (dbt->tag->id > 0) {
9825
sprintf (buf, "%d", dbt->tag->id);
9826
if (StringCmp (buf, p->str) == 0) {
9829
} else if (StringCmp (dbt->tag->str, p->str) == 0) {
9835
ValNodeAddPointer (&(p->obj_list), OBJ_SEQFEAT, sfp);
9841
static ValNodePtr GetFeaturesByDbxref (SeqEntryPtr sep, CharPtr dbxref)
9847
VisitFeaturesInSep (sep, &d, GetFeaturesByDbxrefCallback);
9852
static void GetBioSourcesByTaxNameDescriptorCallback (SeqDescrPtr sdp, Pointer userdata)
9857
if (sdp == NULL || sdp->choice != Seq_descr_source || userdata == NULL) return;
9858
p = (ObjByStrPtr) userdata;
9860
if (StringHasNoText (p->str)) return;
9862
biop = (BioSourcePtr) sdp->data.ptrvalue;
9863
if (biop != NULL && biop->org != NULL && StringCmp (biop->org->taxname, p->str) == 0) {
9864
ValNodeAddPointer (&(p->obj_list), OBJ_SEQDESC, sdp);
9870
static void GetBioSourcesByTaxNameFeatureCallback (SeqFeatPtr sfp, Pointer userdata)
9875
if (sfp == NULL || sfp->data.choice != SEQFEAT_BIOSRC || userdata == NULL) return;
9876
p = (ObjByStrPtr) userdata;
9878
if (StringHasNoText (p->str)) return;
9880
biop = (BioSourcePtr) sfp->data.value.ptrvalue;
9881
if (biop != NULL && biop->org != NULL && StringCmp (biop->org->taxname, p->str) == 0) {
9882
ValNodeAddPointer (&(p->obj_list), OBJ_SEQFEAT, sfp);
9888
static ValNodePtr GetBioSourcesByTaxName (SeqEntryPtr sep, CharPtr taxname)
9894
VisitDescriptorsInSep (sep, &d, GetBioSourcesByTaxNameDescriptorCallback);
9896
VisitFeaturesInSep (sep, &d, GetBioSourcesByTaxNameFeatureCallback);
9904
(ValNodePtr match_type,
9908
ValNodePtr match_list = NULL;
9910
BioseqPtr bsp, nbsp = NULL;
9911
FindGeneLocusTagData fd;
9913
SeqMgrFeatContext fcontext;
9915
if (match_type == NULL || sep == NULL) return NULL;
9917
switch (match_type->choice) {
9918
case eTableMatchFeatureID:
9919
sfp = SeqMgrGetFeatureByFeatID (entityID, NULL, match_type->data.ptrvalue, NULL, &fcontext);
9921
ValNodeAddPointer (&match_list, OBJ_SEQFEAT, sfp);
9924
case eTableMatchGeneLocusTag:
9925
fd.locus_tag = match_type->data.ptrvalue;
9926
fd.gene_list = NULL;
9927
VisitBioseqsInSep (sep, &fd, FindGeneByLocusTagBioseqCallback);
9928
ValNodeLink (&match_list, fd.gene_list);
9930
case eTableMatchProteinID:
9931
case eTableMatchNucID:
9932
sip = CreateSeqIdFromText (match_type->data.ptrvalue, sep);
9933
bsp = BioseqFind (sip);
9934
sip = SeqIdFree (sip);
9937
ValNodeAddPointer (&match_list, OBJ_BIOSEQ, bsp);
9940
case eTableMatchDbxref:
9941
match_list = GetFeaturesByDbxref (sep, match_type->data.ptrvalue);
9943
case eTableMatchBioSource:
9944
match_list = GetBioSourcesByTaxName (sep, match_type->data.ptrvalue);
9951
static ValNodePtr GetFeatureListForProteinBioseq (Uint1 featdef, BioseqPtr bsp)
9953
ValNodePtr feat_list = NULL;
9954
SeqFeatPtr sfp, cds;
9955
SeqMgrFeatContext fcontext;
9958
if (bsp == NULL || !ISA_aa (bsp->mol))
9963
seqfeattype = FindFeatFromFeatDefType (featdef);
9964
if (seqfeattype == SEQFEAT_PROT)
9966
for (sfp = SeqMgrGetNextFeature (bsp, NULL, 0, featdef, &fcontext);
9968
sfp = SeqMgrGetNextFeature (bsp, sfp, 0, featdef, &fcontext))
9970
ValNodeAddPointer (&feat_list, OBJ_SEQFEAT, sfp);
9975
cds = SeqMgrGetCDSgivenProduct (bsp, NULL);
9978
if (featdef == FEATDEF_CDS)
9982
else if (featdef == FEATDEF_GENE)
9984
sfp = GetGeneForFeature (cds);
9986
else if (featdef == FEATDEF_mRNA)
9988
sfp = SeqMgrGetOverlappingmRNA (cds->location, &fcontext);
9992
ValNodeAddPointer (&feat_list, OBJ_SEQFEAT, sfp);
10000
static ValNodePtr GetFeatureListForNucleotideBioseq (Uint1 featdef, BioseqPtr bsp)
10002
ValNodePtr feat_list = NULL;
10004
SeqMgrFeatContext fcontext;
10006
BioseqPtr prot_bsp;
10008
if (bsp == NULL || ISA_aa (bsp->mol))
10013
seqfeattype = FindFeatFromFeatDefType (featdef);
10014
if (seqfeattype == SEQFEAT_PROT)
10016
for (sfp = SeqMgrGetNextFeature (bsp, NULL, 0, FEATDEF_CDS, &fcontext);
10018
sfp = SeqMgrGetNextFeature (bsp, sfp, 0, FEATDEF_CDS, &fcontext))
10020
prot_bsp = BioseqFindFromSeqLoc (sfp->product);
10021
ValNodeLink (&feat_list, GetFeatureListForProteinBioseq (featdef, prot_bsp));
10026
for (sfp = SeqMgrGetNextFeature (bsp, NULL, 0, featdef, &fcontext);
10028
sfp = SeqMgrGetNextFeature (bsp, sfp, 0, featdef, &fcontext))
10030
ValNodeAddPointer (&feat_list, OBJ_SEQFEAT, sfp);
10037
static ValNodePtr GetFeaturesForGene (SeqFeatPtr gene, Uint1 featdef)
10041
ValNodePtr feat_list = NULL;
10042
SeqMgrFeatContext fcontext;
10043
Int4 start, stop, swap;
10045
if (gene == NULL) return NULL;
10047
bsp = BioseqFindFromSeqLoc (gene->location);
10048
start = SeqLocStart (gene->location);
10049
stop = SeqLocStop (gene->location);
10056
for (sfp = SeqMgrGetNextFeature (bsp, NULL, 0, featdef, &fcontext);
10057
sfp != NULL && fcontext.left < stop;
10058
sfp = SeqMgrGetNextFeature (bsp, sfp, 0, featdef, &fcontext))
10060
if (fcontext.right >= start && gene == GetGeneForFeature (sfp))
10062
ValNodeAddPointer (&feat_list, OBJ_SEQFEAT, sfp);
10069
static ValNodePtr GetFeatureListForGene (Uint1 featdef, SeqFeatPtr gene)
10071
ValNodePtr feat_list = NULL, cds_list, vnp;
10072
SeqFeatPtr sfp, cds;
10073
SeqMgrFeatContext fcontext;
10081
if (featdef == FEATDEF_GENE)
10083
ValNodeAddPointer (&feat_list, OBJ_SEQFEAT, gene);
10085
else if (FindFeatFromFeatDefType (featdef == SEQFEAT_PROT))
10087
cds_list = GetFeaturesForGene (gene, FEATDEF_CDS);
10088
for (vnp = cds_list; vnp != NULL; vnp = vnp->next)
10090
cds = vnp->data.ptrvalue;
10093
protbsp = BioseqFindFromSeqLoc (cds->product);
10094
for (sfp = SeqMgrGetNextFeature (protbsp, NULL, 0, featdef, &fcontext);
10096
sfp = SeqMgrGetNextFeature (protbsp, sfp, 0, featdef, &fcontext))
10098
ValNodeAddPointer (&feat_list, OBJ_SEQFEAT, sfp);
10102
cds_list = ValNodeFree (cds_list);
10106
feat_list = GetFeaturesForGene (gene, featdef);
10113
static ValNodePtr AddFeaturesFromBioseqSet (BioseqSetPtr bssp, Uint1 featdef)
10118
ValNodePtr item_list = NULL;
10120
if (bssp == NULL) return NULL;
10122
seqfeattype = FindFeatFromFeatDefType (featdef);
10123
for (sep = bssp->seq_set; sep != NULL; sep = sep->next) {
10124
if (sep->data.ptrvalue == NULL) continue;
10125
if (IS_Bioseq (sep)) {
10126
bsp = sep->data.ptrvalue;
10127
if (seqfeattype == SEQFEAT_PROT) {
10128
if (ISA_aa (bsp->mol)) {
10129
ValNodeLink (&item_list, GetFeatureListForProteinBioseq (featdef, bsp));
10131
} else if (!ISA_aa (bsp->mol)) {
10132
ValNodeLink (&item_list, GetFeatureListForNucleotideBioseq (featdef, bsp));
10134
} else if (IS_Bioseq_set (sep)) {
10135
ValNodeLink (&item_list, AddFeaturesFromBioseqSet (sep->data.ptrvalue, featdef));
10142
static ValNodePtr GetFeatureListForBioSourceObjects (ValNodePtr item_list, FeatureFieldPtr field)
10149
ValNodePtr feature_list = NULL;
10151
if (item_list == NULL || field == NULL) return NULL;
10153
for (vnp = item_list; vnp != NULL; vnp = vnp->next) {
10154
if (vnp->choice == OBJ_SEQFEAT) {
10155
sfp = vnp->data.ptrvalue;
10157
bsp = BioseqFindFromSeqLoc (sfp->location);
10158
ValNodeLink (&feature_list, GetFeatureListForNucleotideBioseq (GetFeatdefFromFeatureType(field->type), bsp));
10160
} else if (vnp->choice == OBJ_SEQDESC) {
10161
sdp = vnp->data.ptrvalue;
10162
if (sdp != NULL && sdp->extended != 0) {
10163
ovp = (ObjValNodePtr) sdp;
10164
if (ovp->idx.parenttype == OBJ_BIOSEQSET) {
10165
ValNodeLink (&feature_list, AddFeaturesFromBioseqSet (ovp->idx.parentptr, GetFeatdefFromFeatureType(field->type)));
10166
} else if (ovp->idx.parenttype == OBJ_BIOSEQ) {
10167
bsp = (BioseqPtr) ovp->idx.parentptr;
10168
ValNodeLink (&feature_list, GetFeatureListForNucleotideBioseq (GetFeatdefFromFeatureType(field->type), bsp));
10173
return feature_list;
10177
static ValNodePtr ValNodeCopyPtr (ValNodePtr orig)
10179
ValNodePtr new_list = NULL, last_vnp = NULL, vnp;
10181
while (orig != NULL) {
10182
vnp = ValNodeNew (NULL);
10183
vnp->choice = orig->choice;
10184
vnp->data.ptrvalue = orig->data.ptrvalue;
10185
if (last_vnp == NULL) {
10188
last_vnp->next = vnp;
10197
static ValNodePtr GetFeatureListForRowAndColumn (Uint1 match_type, ValNodePtr match_list, FeatureFieldPtr field)
10199
ValNodePtr feature_list = NULL, vnp;
10201
if (match_list == NULL || field == NULL) return NULL;
10203
switch (match_type) {
10204
case eTableMatchFeatureID:
10205
feature_list = ValNodeCopyPtr (match_list);
10207
case eTableMatchGeneLocusTag:
10208
for (vnp = match_list; vnp != NULL; vnp = vnp->next) {
10209
ValNodeLink (&feature_list, GetFeatureListForGene (GetFeatdefFromFeatureType(field->type), vnp->data.ptrvalue));
10212
case eTableMatchProteinID:
10213
for (vnp = match_list; vnp != NULL; vnp = vnp->next) {
10214
ValNodeLink (&feature_list, GetFeatureListForProteinBioseq (GetFeatdefFromFeatureType(field->type), vnp->data.ptrvalue));
10217
case eTableMatchDbxref:
10218
feature_list = ValNodeCopyPtr (match_list);
10220
case eTableMatchNucID:
10221
for (vnp = match_list; vnp != NULL; vnp = vnp->next) {
10222
ValNodeLink (&feature_list, GetFeatureListForNucleotideBioseq (GetFeatdefFromFeatureType(field->type), vnp->data.ptrvalue));
10225
case eTableMatchBioSource:
10226
ValNodeLink (&feature_list, GetFeatureListForBioSourceObjects (match_list, field));
10229
return feature_list;
10233
static void AddBioSourcesForBioseq (BioseqPtr bsp, ValNodePtr PNTR feature_list)
10236
SeqMgrDescContext context;
10238
if (feature_list == NULL) return;
10239
for (sdp = SeqMgrGetNextDescriptor (bsp, NULL, Seq_descr_source, &context);
10241
sdp = SeqMgrGetNextDescriptor (bsp, sdp, Seq_descr_source, &context)) {
10242
ValNodeAddPointer (feature_list, OBJ_SEQDESC, sdp);
10246
static void AddBioSourcesForFeature (SeqFeatPtr sfp, ValNodePtr PNTR feature_list)
10250
if (sfp == NULL || feature_list == NULL) return;
10252
if (sfp->data.choice == SEQFEAT_BIOSRC) {
10253
ValNodeAddPointer (feature_list, OBJ_SEQFEAT, sfp);
10255
bsp = BioseqFindFromSeqLoc (sfp->location);
10256
AddBioSourcesForBioseq (bsp, feature_list);
10261
static ValNodePtr GetBioSourceListForRowAndColumn (Uint1 match_type, ValNodePtr match_list, FeatureFieldPtr field)
10263
ValNodePtr feature_list = NULL, vnp;
10265
if (match_list == NULL || field == NULL) return NULL;
10267
switch (match_type) {
10268
case eTableMatchFeatureID:
10269
for (vnp = match_list; vnp != NULL; vnp = vnp->next) {
10270
if (vnp->choice == OBJ_SEQFEAT && vnp->data.ptrvalue != NULL) {
10271
AddBioSourcesForFeature (vnp->data.ptrvalue, &feature_list);
10275
case eTableMatchGeneLocusTag:
10276
for (vnp = match_list; vnp != NULL; vnp = vnp->next) {
10277
if (vnp->choice == OBJ_SEQFEAT && vnp->data.ptrvalue != NULL) {
10278
AddBioSourcesForFeature (vnp->data.ptrvalue, &feature_list);
10282
case eTableMatchProteinID:
10283
case eTableMatchNucID:
10284
for (vnp = match_list; vnp != NULL; vnp = vnp->next) {
10285
if (vnp->choice == OBJ_BIOSEQ) {
10286
AddBioSourcesForBioseq (vnp->data.ptrvalue, &feature_list);
10290
case eTableMatchDbxref:
10291
for (vnp = match_list; vnp != NULL; vnp = vnp->next) {
10292
if (vnp->choice == OBJ_SEQFEAT && vnp->data.ptrvalue != NULL) {
10293
AddBioSourcesForFeature (vnp->data.ptrvalue, &feature_list);
10297
case eTableMatchBioSource:
10298
feature_list = ValNodeCopyPtr (match_list);
10301
return feature_list;
10305
static ValNodePtr GetTargetListForRowAndColumn (Uint1 match_type, ValNodePtr match_list, FieldTypePtr field)
10307
ValNodePtr target_list = NULL;
10308
FeatureFieldPtr feature_field;
10310
if (field == NULL) return NULL;
10311
switch (field->choice) {
10312
case FieldType_source_qual:
10313
target_list = GetBioSourceListForRowAndColumn (match_type, match_list, field->data.ptrvalue);
10315
case FieldType_feature_field:
10316
target_list = GetFeatureListForRowAndColumn (match_type, match_list, field->data.ptrvalue);
10318
case FieldType_cds_gene_prot:
10319
feature_field = FeatureFieldFromCDSGeneProtField (field->data.intvalue);
10320
target_list = GetFeatureListForRowAndColumn (match_type, match_list, feature_field);
10321
feature_field = FeatureFieldFree (feature_field);
10324
return target_list;
10328
static void ReportMissingTargets (ValNodePtr PNTR perr_list, FieldTypePtr ft, CharPtr match_val, Int4 col_num, Int4 line_num)
10331
FeatureFieldPtr field;
10332
CharPtr no_feat_fmt = "No %s feature for %s (column %d, line %d)";
10333
CharPtr no_src_fmt = "No biosource for %s (column %d, line %d)";
10336
if (perr_list == NULL || ft == NULL || match_val == NULL) return;
10338
switch (ft->choice) {
10339
case FieldType_source_qual:
10340
err_msg = (CharPtr) MemNew (sizeof (Char) * (StringLen (no_feat_fmt)
10341
+ StringLen (match_val)
10343
sprintf (err_msg, no_src_fmt, match_val, col_num, line_num);
10344
ValNodeAddPointer (perr_list, 0, err_msg);
10346
case FieldType_feature_field:
10347
field = (FeatureFieldPtr) ft->data.ptrvalue;
10348
if (field != NULL) {
10349
feat_name = GetFeatureNameFromFeatureType (field->type);
10350
err_msg = (CharPtr) MemNew (sizeof (Char) * (StringLen (no_feat_fmt)
10351
+ StringLen (feat_name)
10352
+ StringLen (match_val)
10354
sprintf (err_msg, no_feat_fmt, feat_name, match_val, col_num, line_num);
10355
ValNodeAddPointer (perr_list, 0, err_msg);
10358
case FieldType_cds_gene_prot:
10359
field = FeatureFieldFromCDSGeneProtField (ft->data.intvalue);
10360
if (field != NULL) {
10361
feat_name = GetFeatureNameFromFeatureType (field->type);
10362
err_msg = (CharPtr) MemNew (sizeof (Char) * (StringLen (no_feat_fmt)
10363
+ StringLen (feat_name)
10364
+ StringLen (match_val)
10366
sprintf (err_msg, no_feat_fmt, feat_name, match_val, col_num, line_num);
10367
ValNodeAddPointer (perr_list, 0, err_msg);
10369
field = FeatureFieldFree (field);
10375
static void ReportEmptyIDColumn (ValNodePtr PNTR perr_list, Int4 line_num)
10378
CharPtr missing_id_fmt = "No ID for line %d";
10380
err_msg = (CharPtr) MemNew (sizeof (Char) * (StringLen (missing_id_fmt) + 15));
10381
sprintf (err_msg, missing_id_fmt, line_num);
10382
ValNodeAddPointer (perr_list, 0, err_msg);
10385
static ValNodePtr FindMatchChoiceInLine (ValNodePtr val_vnp, ValNodePtr col_vnp)
10387
TabColumnConfigPtr t;
10389
while (val_vnp != NULL && col_vnp != NULL) {
10390
t = (TabColumnConfigPtr) col_vnp->data.ptrvalue;
10391
if (t != NULL && t->match_type > 0) {
10392
val_vnp->choice = (Uint1) t->match_type;
10395
val_vnp = val_vnp->next;
10396
col_vnp = col_vnp->next;
10402
NLM_EXTERN SeqFeatPtr GetmRNAForFeature (SeqFeatPtr sfp)
10404
SeqMgrFeatContext fcontext;
10407
if (sfp == NULL) return NULL;
10408
if (sfp->data.choice == SEQFEAT_PROT)
10410
pbsp = BioseqFindFromSeqLoc (sfp->location);
10411
sfp = SeqMgrGetCDSgivenProduct (pbsp, NULL);
10412
if (sfp == NULL) return NULL;
10414
return SeqMgrGetOverlappingmRNA (sfp->location, &fcontext);
10418
NLM_EXTERN Boolean AdjustmRNAProductToMatchProteinProduct (SeqFeatPtr sfp)
10424
if (sfp == NULL || sfp->data.choice != SEQFEAT_PROT) return FALSE;
10426
prp = (ProtRefPtr) sfp->data.value.ptrvalue;
10427
mrna = GetmRNAForFeature (sfp);
10429
if (mrna == NULL) return FALSE;
10431
rrp = (RnaRefPtr) mrna->data.value.ptrvalue;
10435
mrna->data.value.ptrvalue = rrp;
10438
rrp->ext.value.ptrvalue = MemFree (rrp->ext.value.ptrvalue);
10439
if (prp == NULL || prp->name == NULL || StringHasNoText (prp->name->data.ptrvalue))
10441
rrp->ext.choice = 0;
10445
rrp->ext.choice = 1;
10446
rrp->ext.value.ptrvalue = StringSave (prp->name->data.ptrvalue);
10452
NLM_EXTERN Boolean IsFieldTypeCDSProduct (FieldTypePtr ft)
10454
FeatureFieldPtr field;
10455
Boolean rval = FALSE;
10457
if (ft == NULL) return FALSE;
10458
if (ft->choice == FieldType_feature_field) {
10459
field = (FeatureFieldPtr) ft->data.ptrvalue;
10460
if (field != NULL && field->type == Feature_type_cds
10461
&& field->field != NULL
10462
&& field->field->choice == FeatQualChoice_legal_qual
10463
&& field->field->data.intvalue == Feat_qual_legal_product) {
10466
} else if (ft->choice == FieldType_cds_gene_prot) {
10467
if (ft->data.intvalue == CDSGeneProt_field_prot_name) {
10475
static Boolean IsFieldTypeGeneLocusTag (FieldTypePtr ft)
10477
FeatureFieldPtr field;
10478
Boolean rval = FALSE;
10480
if (ft == NULL) return FALSE;
10481
if (ft->choice == FieldType_feature_field) {
10482
field = (FeatureFieldPtr) ft->data.ptrvalue;
10483
if (field != NULL && field->type == Feature_type_gene
10484
&& field->field != NULL
10485
&& field->field->choice == FeatQualChoice_legal_qual
10486
&& field->field->data.intvalue == Feat_qual_legal_locus_tag) {
10489
} else if (ft->choice == FieldType_cds_gene_prot) {
10490
if (ft->data.intvalue == CDSGeneProt_field_gene_locus_tag) {
10499
NLM_EXTERN ValNodePtr ValidateTabTableValues (ValNodePtr table, ValNodePtr columns)
10501
ValNodePtr err_list = NULL;
10502
ValNodePtr line_vnp, col_vnp, val_vnp;
10503
Int4 line_num, col_num;
10504
TabColumnConfigPtr t;
10505
ValNodePtr locus_tag_values = NULL, bad_locus_tags = NULL, vnp;
10506
CharPtr bad_format_fmt = "Locus tag %s has incorrect format";
10507
CharPtr dup_fmt = "Locus tag %s appears in the table more than once";
10508
CharPtr inconsistent_fmt = "Locus tag prefix for %s is inconsistent";
10511
if (table == NULL || columns == NULL) {
10515
for (line_vnp = table, line_num = 1;
10517
line_vnp = line_vnp->next, line_num++) {
10518
for (val_vnp = line_vnp->data.ptrvalue, col_vnp = columns, col_num = 1;
10519
val_vnp != NULL && col_vnp != NULL;
10520
val_vnp = val_vnp->next, col_vnp = col_vnp->next, col_num++) {
10521
t = (TabColumnConfigPtr) col_vnp->data.ptrvalue;
10522
if (t == NULL || t->match_type > 0 || val_vnp == NULL || StringHasNoText (val_vnp->data.ptrvalue)) {
10525
if (IsFieldTypeGeneLocusTag (t->field)) {
10526
ValNodeAddPointer (&locus_tag_values, 0, val_vnp->data.ptrvalue);
10531
bad_locus_tags = FindBadLocusTagsInList (locus_tag_values);
10532
for (vnp = bad_locus_tags; vnp != NULL; vnp = vnp->next) {
10533
switch (vnp->choice) {
10534
case eLocusTagErrorBadFormat:
10535
err_msg = (CharPtr) MemNew (sizeof (Char) * (StringLen (bad_format_fmt) + StringLen (vnp->data.ptrvalue)));
10536
sprintf (err_msg, bad_format_fmt, vnp->data.ptrvalue);
10537
ValNodeAddPointer (&err_list, 0, err_msg);
10539
case eLocusTagErrorDuplicate:
10540
err_msg = (CharPtr) MemNew (sizeof (Char) * (StringLen (dup_fmt) + StringLen (vnp->data.ptrvalue)));
10541
sprintf (err_msg, dup_fmt, vnp->data.ptrvalue);
10542
ValNodeAddPointer (&err_list, 0, err_msg);
10544
case eLocusTagErrorInconsistentPrefix:
10545
err_msg = (CharPtr) MemNew (sizeof (Char) * (StringLen (inconsistent_fmt) + StringLen (vnp->data.ptrvalue)));
10546
sprintf (err_msg, inconsistent_fmt, vnp->data.ptrvalue);
10547
ValNodeAddPointer (&err_list, 0, err_msg);
10551
locus_tag_values = ValNodeFree (locus_tag_values);
10556
NLM_EXTERN ValNodePtr GetObjectTableForTabTable (SeqEntryPtr sep, ValNodePtr table, ValNodePtr columns, ValNodePtr PNTR p_err_list)
10558
ValNodePtr err_list = NULL;
10559
ValNodePtr line_vnp, val_vnp, col_vnp;
10560
ValNodePtr obj_table = NULL, obj_row;
10561
Int4 line_num = 1, col_num;
10563
ValNodePtr match_list, match_choice, target_list;
10564
TabColumnConfigPtr t;
10566
CharPtr no_match_fmt = "No match for %s, line %d";
10567
CharPtr bad_col_val_fmt = "Did not set value for column %d, line %d";
10568
CharPtr num_affected_fmt = "%d fields affected";
10569
Int4 num_fields_affected = 0;
10572
ValNodeAddPointer (&err_list, 0, StringSave ("No SeqEntry"));
10574
if (table == NULL) {
10575
ValNodeAddPointer (&err_list, 0, StringSave ("No table"));
10577
if (columns == NULL) {
10578
ValNodeAddPointer (&err_list, 0, StringSave ("No column information"));
10580
if (err_list != NULL) {
10581
if (p_err_list == NULL) {
10582
err_list = ValNodeFreeData (err_list);
10584
*p_err_list = err_list;
10589
entityID = SeqMgrGetEntityIDForSeqEntry (sep);
10591
for (line_vnp = table, line_num = 1; line_vnp != NULL; line_vnp = line_vnp->next, line_num++) {
10593
match_choice = FindMatchChoiceInLine (line_vnp->data.ptrvalue, columns);
10594
if (match_choice == NULL || StringHasNoText (match_choice->data.ptrvalue)) {
10595
ReportEmptyIDColumn (&err_list, line_num);
10597
match_list = FindMatchForRow (match_choice, entityID, sep);
10598
if (match_list == NULL) {
10599
err_msg = (CharPtr) MemNew (sizeof (Char) * (StringLen (no_match_fmt) + StringLen (match_choice->data.ptrvalue) + 15));
10600
sprintf (err_msg, no_match_fmt, match_choice->data.ptrvalue, line_num);
10601
ValNodeAddPointer (&err_list, 0, err_msg);
10603
for (val_vnp = line_vnp->data.ptrvalue, col_vnp = columns, col_num = 1;
10605
col_vnp = col_vnp->next, col_num++) {
10606
target_list = NULL;
10607
t = (TabColumnConfigPtr) col_vnp->data.ptrvalue;
10608
if (t == NULL || t->match_type > 0
10609
|| (t->skip_blank && (val_vnp == NULL || StringHasNoText (val_vnp->data.ptrvalue)))) {
10612
target_list = GetTargetListForRowAndColumn (match_choice->choice, match_list, t->field);
10613
if (target_list == NULL) {
10614
ReportMissingTargets (&err_list, t->field, match_choice->data.ptrvalue, col_num, line_num);
10617
ValNodeAddPointer (&obj_row, 0, target_list);
10618
if (val_vnp != NULL) {
10619
val_vnp = val_vnp->next;
10624
ValNodeAddPointer (&obj_table, 0, obj_row);
10627
if (err_list != NULL) {
10628
if (p_err_list == NULL) {
10629
err_list = ValNodeFreeData (err_list);
10631
*p_err_list = err_list;
10638
NLM_EXTERN ValNodePtr FreeObjectTableForTabTable (ValNodePtr table)
10640
ValNodePtr vnp_next, vnp_row, vnp_row_next;
10642
while (table != NULL) {
10643
vnp_next = table->next;
10644
table->next = NULL;
10645
vnp_row = table->data.ptrvalue;
10646
while (vnp_row != NULL) {
10647
vnp_row_next = vnp_row->next;
10648
vnp_row->next = NULL;
10649
vnp_row->data.ptrvalue = ValNodeFree (vnp_row->data.ptrvalue);
10650
vnp_row = ValNodeFree (vnp_row);
10651
vnp_row = vnp_row_next;
10653
table = ValNodeFree (table);
10660
typedef struct countfeat {
10663
} CountFeatData, PNTR CountFeatPtr;
10666
static void CountFeaturesCallback (SeqFeatPtr sfp, Pointer userdata)
10670
if (sfp == NULL || userdata == NULL) return;
10672
p = (CountFeatPtr) userdata;
10673
if (sfp->idx.subtype == p->featdef) {
10678
static void CountBioSourceDescriptorsCallback (SeqDescrPtr sdp, Pointer userdata)
10682
p = (Int4Ptr) userdata;
10683
if (sdp != NULL && p != NULL && sdp->choice == Seq_descr_source) {
10689
static ValNodePtr CountObjectsForColumnFields (SeqEntryPtr sep, ValNodePtr columns)
10691
ValNodePtr count_list = NULL, vnp;
10692
TabColumnConfigPtr t;
10700
for (vnp = columns; vnp != NULL; vnp = vnp->next) {
10702
t = (TabColumnConfigPtr) vnp->data.ptrvalue;
10703
if (t != NULL && t->match_type == 0 && t->field != NULL) {
10704
switch (t->field->choice) {
10705
case FieldType_source_qual:
10706
if (featdef != FEATDEF_BIOSRC) {
10707
d.featdef = FEATDEF_BIOSRC;
10709
VisitFeaturesInSep (sep, &d, CountFeaturesCallback);
10710
VisitDescriptorsInSep (sep, &(d.num), CountBioSourceDescriptorsCallback);
10714
case FieldType_feature_field:
10715
f = (FeatureFieldPtr) t->field->data.ptrvalue;
10717
featdef = GetFeatdefFromFeatureType(f->type);
10718
if (featdef != d.featdef) {
10719
d.featdef = featdef;
10721
VisitFeaturesInSep (sep, &d, CountFeaturesCallback);
10726
case FieldType_cds_gene_prot:
10727
f = FeatureFieldFromCDSGeneProtField (t->field->data.intvalue);
10729
featdef = GetFeatdefFromFeatureType(f->type);
10730
if (featdef != d.featdef) {
10731
d.featdef = featdef;
10733
VisitFeaturesInSep (sep, &d, CountFeaturesCallback);
10737
f = FeatureFieldFree (f);
10741
ValNodeAddInt (&count_list, 0, num);
10747
NLM_EXTERN ValNodePtr ApplyTableValuesToObjectTable (SeqEntryPtr sep, ValNodePtr table, ValNodePtr columns, ValNodePtr obj_table)
10749
ValNodePtr val_line_vnp, obj_line_vnp;
10750
ValNodePtr val_vnp, obj_vnp, col_vnp;
10751
ValNodePtr target_vnp;
10752
TabColumnConfigPtr t;
10753
CharPtr val, qual_name;
10754
ValNodePtr err_list = NULL, count_list, count_affected_list = NULL, count_vnp, count_tot_vnp;
10756
CharPtr bad_col_val_fmt = "Did not set value for column %d, line %d";
10757
CharPtr num_affected_fmt = "%d fields affected";
10758
CharPtr col_num_affected_fmt = "For %s (column %d), %d items were affected out of %d total";
10759
Int4 num_fields_affected = 0, col_num, line_num, num_this_column;
10761
ValNodePtr count_msg = NULL;
10763
count_list = CountObjectsForColumnFields (sep, columns);
10765
for (val_line_vnp = table, obj_line_vnp = obj_table, line_num = 1;
10766
val_line_vnp != NULL && obj_line_vnp != NULL;
10767
val_line_vnp = val_line_vnp->next, obj_line_vnp = obj_line_vnp->next, line_num++) {
10768
val_vnp = val_line_vnp->data.ptrvalue;
10769
obj_vnp = obj_line_vnp->data.ptrvalue;
10772
count_vnp = count_affected_list;
10773
while (obj_vnp != NULL && col_vnp != NULL) {
10774
num_this_column = 0;
10775
if (obj_vnp->data.ptrvalue != NULL) {
10776
t = (TabColumnConfigPtr) col_vnp->data.ptrvalue;
10777
if (t == NULL || t->match_type > 0
10778
|| (t->skip_blank && (val_vnp == NULL || StringHasNoText (val_vnp->data.ptrvalue)))) {
10779
/* ignore column or skip blank value */
10781
if (val_vnp == NULL || val_vnp->data.ptrvalue == NULL) {
10784
val = val_vnp->data.ptrvalue;
10786
for (target_vnp = obj_vnp->data.ptrvalue; target_vnp != NULL; target_vnp = target_vnp->next) {
10788
success = RemoveFieldValueForObject (target_vnp->choice, target_vnp->data.ptrvalue, t->field, NULL);
10790
success = SetFieldValueForObject (target_vnp->choice, target_vnp->data.ptrvalue, t->field, NULL,
10791
val_vnp->data.ptrvalue, t->existing_text);
10794
num_fields_affected++;
10796
if (t->match_mrna && IsFieldTypeCDSProduct (t->field)
10797
&& target_vnp->choice == OBJ_SEQFEAT) {
10798
if (AdjustmRNAProductToMatchProteinProduct (target_vnp->data.ptrvalue)) {
10799
num_fields_affected++;
10803
err_msg = (CharPtr) MemNew (sizeof (Char) * (StringLen (bad_col_val_fmt) + 30));
10804
sprintf (err_msg, bad_col_val_fmt, col_num, line_num);
10805
ValNodeAddPointer (&err_list, 0, err_msg);
10810
if (val_vnp != NULL) {
10811
val_vnp = val_vnp->next;
10813
if (count_vnp == NULL) {
10814
ValNodeAddInt (&count_affected_list, 0, num_this_column);
10816
count_vnp->data.intvalue ++;
10817
count_vnp = count_vnp->next;
10819
obj_vnp = obj_vnp->next;
10820
col_vnp = col_vnp->next;
10825
/* put message at top of list for number of fields affected */
10826
err_msg = (CharPtr) MemNew (sizeof (Char) * (StringLen (num_affected_fmt) + 15));
10827
sprintf (err_msg, num_affected_fmt, num_fields_affected);
10828
ValNodeAddPointer (&count_msg, 0, err_msg);
10830
/* if any affected, list number of fields per column, and the total in the record */
10831
if (num_fields_affected > 0) {
10832
for (count_vnp = count_affected_list, count_tot_vnp = count_list, col_vnp = columns, col_num = 1;
10833
count_vnp != NULL && count_tot_vnp != NULL && col_vnp != NULL;
10834
count_vnp = count_vnp->next, count_tot_vnp = count_tot_vnp->next, col_vnp = col_vnp->next, col_num++) {
10835
t = (TabColumnConfigPtr) col_vnp->data.ptrvalue;
10836
if (t != NULL && t->match_type == 0) {
10837
qual_name = SummarizeFieldType (t->field);
10838
err_msg = (CharPtr) MemNew (sizeof (Char) * (StringLen (col_num_affected_fmt) + StringLen (qual_name) + 45));
10839
sprintf (err_msg, col_num_affected_fmt, qual_name, col_num, count_vnp->data.intvalue, count_tot_vnp->data.intvalue);
10840
ValNodeAddPointer (&count_msg, 0, err_msg);
10841
qual_name = MemFree (qual_name);
10846
ValNodeLink (&count_msg, err_list);
10848
count_list = ValNodeFree (count_list);
10849
count_affected_list = ValNodeFree (count_affected_list);
10855
static int LIBCALLBACK SortVnpByChoiceAndPtrvalue (VoidPtr ptr1, VoidPtr ptr2)
10861
if (ptr1 != NULL && ptr2 != NULL) {
10862
vnp1 = *((ValNodePtr PNTR) ptr1);
10863
vnp2 = *((ValNodePtr PNTR) ptr2);
10864
if (vnp1 != NULL && vnp2 != NULL) {
10865
if (vnp1->choice > vnp2->choice) {
10867
} else if (vnp1->choice < vnp2->choice) {
10869
} else if (vnp1->data.ptrvalue > vnp2->data.ptrvalue) {
10871
} else if (vnp2->data.ptrvalue < vnp2->data.ptrvalue) {
10882
NLM_EXTERN ValNodePtr CheckObjTableForRowsThatApplyToTheSameDestination (ValNodePtr obj_table)
10885
ValNodePtr line_vnp, col_vnp, obj_vnp, vnp;
10886
ValNodePtr col_list = NULL, col_obj_list;
10887
Boolean any_column_values_left;
10888
ValNodePtr err_list = NULL;
10889
Boolean found_multi;
10890
CharPtr multi_fmt = "Multiple rows apply to the same object for column %d";
10893
/* now, for each row, get pointer to first column */
10894
for (line_vnp = obj_table; line_vnp != NULL; line_vnp = line_vnp->next) {
10895
ValNodeAddPointer (&col_list, 0, line_vnp->data.ptrvalue);
10898
/* now for each column, make a list of all features in the column, then sort to see if there are duplicates */
10899
any_column_values_left = TRUE;
10901
while (any_column_values_left) {
10902
any_column_values_left = FALSE;
10903
col_obj_list = NULL;
10904
for (vnp = col_list; vnp != NULL; vnp = vnp->next) {
10905
col_vnp = vnp->data.ptrvalue;
10906
if (col_vnp != NULL) {
10907
obj_vnp = col_vnp->data.ptrvalue;
10908
ValNodeLink (&col_obj_list, ValNodeCopyPtr (obj_vnp));
10909
vnp->data.ptrvalue = col_vnp->next;
10910
any_column_values_left = TRUE;
10913
if (col_obj_list != NULL) {
10914
found_multi = FALSE;
10915
col_obj_list = ValNodeSort (col_obj_list, SortVnpByChoiceAndPtrvalue);
10916
for (vnp = col_obj_list; vnp != NULL && vnp->next != NULL && !found_multi; vnp = vnp->next) {
10917
if (vnp->choice == vnp->next->choice
10918
&& vnp->data.ptrvalue == vnp->next->data.ptrvalue) {
10919
found_multi = TRUE;
10923
err_msg = (CharPtr) MemNew (sizeof (Char) * (StringLen (multi_fmt)
10925
sprintf (err_msg, multi_fmt, col_num);
10926
ValNodeAddPointer (&err_list, col_num, err_msg);
10928
col_obj_list = ValNodeFree (col_obj_list);
10932
col_list = ValNodeFree (col_list);
10937
NLM_EXTERN ValNodePtr CheckObjTableForExistingText (SeqEntryPtr sep, ValNodePtr table, ValNodePtr columns, ValNodePtr obj_table)
10939
ValNodePtr err_list = NULL, vnp;
10940
ValNodePtr val_line_vnp, obj_line_vnp;
10941
ValNodePtr val_vnp, obj_vnp, col_vnp;
10942
Int4 line_num = 1, col_num, num_existing_text = 0;
10944
TabColumnConfigPtr t;
10945
CharPtr err_msg, str, qual_name, val;
10946
CharPtr already_has_val_fmt = "%s already has value '%s' (column %d), line %d. Replacement is '%s'";
10947
CharPtr num_existing_text_fmt = "%d fields already have text.";
10948
CharPtr mrna_warn_fmt = "%d coding region features have mRNAs, but %d do not.";
10949
ValNodePtr target_list, feat_vnp;
10950
Int4 num_with_mrna = 0, num_without_mrna = 0;
10953
ValNodeAddPointer (&err_list, 1, StringSave ("No SeqEntry"));
10955
if (table == NULL) {
10956
ValNodeAddPointer (&err_list, 1, StringSave ("No table"));
10958
if (columns == NULL) {
10959
ValNodeAddPointer (&err_list, 1, StringSave ("No column information"));
10961
if (err_list != NULL) {
10965
entityID = SeqMgrGetEntityIDForSeqEntry (sep);
10967
for (val_line_vnp = table, obj_line_vnp = obj_table, line_num = 1;
10968
val_line_vnp != NULL && obj_line_vnp != NULL;
10969
val_line_vnp = val_line_vnp->next, obj_line_vnp = obj_line_vnp->next, line_num++) {
10970
val_vnp = val_line_vnp->data.ptrvalue;
10971
obj_vnp = obj_line_vnp->data.ptrvalue;
10973
if (val_vnp == NULL || obj_vnp == NULL) continue;
10975
while (obj_vnp != NULL && col_vnp != NULL) {
10976
if (obj_vnp->data.ptrvalue != NULL) {
10977
t = (TabColumnConfigPtr) col_vnp->data.ptrvalue;
10978
if (t == NULL || t->match_type > 0
10979
|| (t->skip_blank && (val_vnp == NULL || StringHasNoText (val_vnp->data.ptrvalue)))) {
10980
/* ignore column or skip blank value */
10982
target_list = obj_vnp->data.ptrvalue;
10983
if (val_vnp == NULL || val_vnp->data.ptrvalue == NULL) {
10986
val = val_vnp->data.ptrvalue;
10988
for (feat_vnp = target_list; feat_vnp != NULL; feat_vnp = feat_vnp->next) {
10989
/* check for existing text */
10990
str = GetFieldValueForObject (feat_vnp->choice, feat_vnp->data.ptrvalue, t->field, NULL);
10991
if (!StringHasNoText (str)) {
10992
qual_name = SummarizeFieldType (t->field);
10993
err_msg = (CharPtr) MemNew (sizeof (Char) * (StringLen (already_has_val_fmt)
10994
+ StringLen (qual_name) + StringLen (str)
10997
sprintf (err_msg, already_has_val_fmt, qual_name, str, col_num, line_num, val);
10998
ValNodeAddPointer (&err_list, col_num, err_msg);
10999
num_existing_text ++;
11001
str = MemFree (str);
11002
/* check for mrna if changing CDS product */
11003
if (IsFieldTypeCDSProduct (t->field) && feat_vnp->choice == OBJ_SEQFEAT) {
11004
if (GetmRNAForFeature (feat_vnp->data.ptrvalue) != NULL) {
11007
num_without_mrna++;
11013
if (val_vnp != NULL) {
11014
val_vnp = val_vnp->next;
11016
obj_vnp = obj_vnp->next;
11017
col_vnp = col_vnp->next;
11021
if (num_existing_text > 0) {
11022
err_msg = (CharPtr) MemNew (sizeof (Char) * (StringLen (num_existing_text_fmt)
11024
sprintf (err_msg, num_existing_text_fmt, num_existing_text);
11025
vnp = ValNodeNew (NULL);
11027
vnp->data.ptrvalue = err_msg;
11028
vnp->next = err_list;
11031
if (num_with_mrna > 0 && num_without_mrna > 0) {
11032
err_msg = (CharPtr) MemNew (sizeof (Char) * (StringLen (mrna_warn_fmt)
11034
sprintf (err_msg, mrna_warn_fmt, num_with_mrna, num_without_mrna);
11035
vnp = ValNodeNew (NULL);
11037
vnp->data.ptrvalue = err_msg;
11038
vnp->next = err_list;
11046
NLM_EXTERN ValNodePtr ApplyTableToFeatures (SeqEntryPtr sep, ValNodePtr table, ValNodePtr columns)
11048
ValNodePtr err_list = NULL;
11049
ValNodePtr line_vnp, val_vnp, col_vnp;
11050
Int4 line_num = 1, col_num;
11052
ValNodePtr match_list, match_choice, target_list, feat_vnp, vnp;
11053
TabColumnConfigPtr t;
11055
CharPtr no_match_fmt = "No match for %s, line %d";
11056
CharPtr bad_col_val_fmt = "Did not set value for column %d, line %d";
11057
CharPtr num_affected_fmt = "%d fields affected";
11058
Int4 num_fields_affected = 0;
11063
ValNodeAddPointer (&err_list, 0, StringSave ("No SeqEntry"));
11065
if (table == NULL) {
11066
ValNodeAddPointer (&err_list, 0, StringSave ("No table"));
11068
if (columns == NULL) {
11069
ValNodeAddPointer (&err_list, 0, StringSave ("No column information"));
11071
if (err_list != NULL) {
11075
entityID = SeqMgrGetEntityIDForSeqEntry (sep);
11077
for (line_vnp = table, line_num = 1; line_vnp != NULL; line_vnp = line_vnp->next, line_num++) {
11078
match_choice = FindMatchChoiceInLine (line_vnp->data.ptrvalue, columns);
11079
if (match_choice == NULL || StringHasNoText (match_choice->data.ptrvalue)) {
11080
ReportEmptyIDColumn (&err_list, line_num);
11082
match_list = FindMatchForRow (match_choice, entityID, sep);
11083
if (match_list == NULL) {
11084
err_msg = (CharPtr) MemNew (sizeof (Char) * (StringLen (no_match_fmt) + StringLen (match_choice->data.ptrvalue) + 15));
11085
sprintf (err_msg, no_match_fmt, match_choice->data.ptrvalue, line_num);
11086
ValNodeAddPointer (&err_list, 0, err_msg);
11088
for (val_vnp = line_vnp->data.ptrvalue, col_vnp = columns, col_num = 1;
11090
col_vnp = col_vnp->next, col_num++) {
11091
t = (TabColumnConfigPtr) col_vnp->data.ptrvalue;
11092
if (t == NULL || t->match_type > 0
11093
|| (t->skip_blank && (val_vnp == NULL || StringHasNoText (val_vnp->data.ptrvalue)))) {
11094
if (val_vnp != NULL) {
11095
val_vnp = val_vnp->next;
11100
target_list = GetTargetListForRowAndColumn (match_choice->choice, match_list, t->field);
11101
if (target_list == NULL) {
11102
ReportMissingTargets (&err_list, t->field, match_choice->data.ptrvalue, col_num, line_num);
11104
if (val_vnp == NULL || val_vnp->data.ptrvalue == NULL) {
11107
val = val_vnp->data.ptrvalue;
11109
for (feat_vnp = target_list; feat_vnp != NULL; feat_vnp = feat_vnp->next) {
11111
success = RemoveFieldValueForObject (feat_vnp->choice, feat_vnp->data.ptrvalue, t->field, NULL);
11113
success = SetFieldValueForObject (feat_vnp->choice, feat_vnp->data.ptrvalue, t->field, NULL,
11114
val_vnp->data.ptrvalue, t->existing_text);
11117
num_fields_affected++;
11118
if (t->match_mrna && IsFieldTypeCDSProduct (t->field)
11119
&& feat_vnp->choice == OBJ_SEQFEAT) {
11120
if (AdjustmRNAProductToMatchProteinProduct (feat_vnp->data.ptrvalue)) {
11121
num_fields_affected++;
11125
err_msg = (CharPtr) MemNew (sizeof (Char) * (StringLen (bad_col_val_fmt) + 30));
11126
sprintf (err_msg, bad_col_val_fmt, col_num, line_num);
11127
ValNodeAddPointer (&err_list, 0, err_msg);
11131
target_list = ValNodeFree (target_list);
11132
if (val_vnp != NULL) {
11133
val_vnp = val_vnp->next;
11137
match_list = ValNodeFree (match_list);
11141
err_msg = (CharPtr) MemNew (sizeof (Char) * (StringLen (num_affected_fmt) + 15));
11142
sprintf (err_msg, num_affected_fmt, num_fields_affected);
11143
vnp = ValNodeNew (NULL);
11144
vnp->data.ptrvalue = err_msg;
11145
vnp->next = err_list;
11152
NLM_EXTERN ValNodePtr CheckTableForExistingText (SeqEntryPtr sep, ValNodePtr table, ValNodePtr columns)
11154
ValNodePtr err_list = NULL, vnp;
11155
ValNodePtr line_vnp, val_vnp, col_vnp;
11156
Int4 line_num = 1, col_num, num_existing_text = 0;
11158
TabColumnConfigPtr t;
11159
CharPtr err_msg, str, qual_name, val;
11160
CharPtr no_match_fmt = "No match for %s, line %d";
11161
CharPtr no_feat_fmt = "No %s feature for %s (column %d, line %d)";
11162
CharPtr already_has_val_fmt = "%s already has value '%s' (column %d), line %d. Replacement is '%s'";
11163
CharPtr num_existing_text_fmt = "%d fields already have text.";
11164
ValNodePtr match_choice, match_list;
11165
ValNodePtr target_list, feat_vnp;
11168
ValNodeAddPointer (&err_list, 1, StringSave ("No SeqEntry"));
11170
if (table == NULL) {
11171
ValNodeAddPointer (&err_list, 1, StringSave ("No table"));
11173
if (columns == NULL) {
11174
ValNodeAddPointer (&err_list, 1, StringSave ("No column information"));
11176
if (err_list != NULL) {
11180
entityID = SeqMgrGetEntityIDForSeqEntry (sep);
11182
for (line_vnp = table, line_num = 1; line_vnp != NULL; line_vnp = line_vnp->next, line_num++) {
11183
match_choice = FindMatchChoiceInLine (line_vnp->data.ptrvalue, columns);
11184
if (match_choice == NULL || StringHasNoText (match_choice->data.ptrvalue)) {
11185
ReportEmptyIDColumn (&err_list, line_num);
11187
match_list = FindMatchForRow (match_choice, entityID, sep);
11188
if (match_list == NULL) {
11189
err_msg = (CharPtr) MemNew (sizeof (Char) * (StringLen (no_match_fmt) + StringLen (match_choice->data.ptrvalue) + 15));
11190
sprintf (err_msg, no_match_fmt, match_choice->data.ptrvalue, line_num);
11191
ValNodeAddPointer (&err_list, 0, err_msg);
11193
for (val_vnp = line_vnp->data.ptrvalue, col_vnp = columns, col_num = 1;
11195
col_vnp = col_vnp->next, col_num++) {
11196
t = (TabColumnConfigPtr) col_vnp->data.ptrvalue;
11197
if (t == NULL || t->match_type > 0
11198
|| (t->skip_blank && (val_vnp == NULL || StringHasNoText (val_vnp->data.ptrvalue)))) {
11199
if (val_vnp != NULL) {
11200
val_vnp = val_vnp->next;
11204
target_list = GetTargetListForRowAndColumn (match_choice->choice, match_list, t->field);
11205
if (target_list == NULL) {
11206
ReportMissingTargets (&err_list, t->field, match_choice->data.ptrvalue, col_num, line_num);
11208
if (val_vnp == NULL || val_vnp->data.ptrvalue == NULL) {
11211
val = val_vnp->data.ptrvalue;
11213
for (feat_vnp = target_list; feat_vnp != NULL; feat_vnp = feat_vnp->next) {
11214
str = GetFieldValueForObject (feat_vnp->choice, feat_vnp->data.ptrvalue, t->field, NULL);
11215
if (!StringHasNoText (str)) {
11216
qual_name = SummarizeFieldType (t->field);
11217
err_msg = (CharPtr) MemNew (sizeof (Char) * (StringLen (already_has_val_fmt)
11218
+ StringLen (qual_name) + StringLen (str)
11221
sprintf (err_msg, already_has_val_fmt, qual_name, str, col_num, line_num, val);
11222
ValNodeAddPointer (&err_list, col_num, err_msg);
11223
num_existing_text ++;
11225
str = MemFree (str);
11228
target_list = ValNodeFree (target_list);
11229
if (val_vnp != NULL) {
11230
val_vnp = val_vnp->next;
11234
match_list = ValNodeFree (match_list);
11237
if (num_existing_text > 0) {
11238
err_msg = (CharPtr) MemNew (sizeof (Char) * (StringLen (num_existing_text_fmt)
11240
sprintf (err_msg, num_existing_text_fmt, num_existing_text);
11241
vnp = ValNodeNew (NULL);
11243
vnp->data.ptrvalue = err_msg;
11244
vnp->next = err_list;