10467
static CharPtr hupfetchproc = "HUPBioseqFetch";
10469
static CharPtr hupfetchcmd = NULL;
10471
extern Pointer ReadFromHUP (CharPtr accn, Uint2Ptr datatype, Uint2Ptr entityID);
10472
extern Pointer ReadFromHUP (CharPtr accn, Uint2Ptr datatype, Uint2Ptr entityID)
10478
Char path [PATH_MAX];
10480
if (datatype != NULL) {
10483
if (entityID != NULL) {
10486
if (! dirsubMode) return NULL;
10487
if (StringHasNoText (accn)) return NULL;
10489
if (hupfetchcmd == NULL) {
10490
if (GetAppParam ("SEQUIN", "HUP", "FETCHSCRIPT", NULL, cmmd, sizeof (cmmd))) {
10491
hupfetchcmd = StringSaveNoNull (cmmd);
10494
if (hupfetchcmd == NULL) return NULL;
10499
sprintf (cmmd, "csh %s %s > %s", hupfetchcmd, accn, path);
10503
sprintf (cmmd, "%s %s -o %s", hupfetchcmd, accn, path);
10507
fp = FileOpen (path, "r");
10512
dataptr = ReadAsnFastaOrFlatFile (fp, datatype, entityID, FALSE, FALSE, TRUE, FALSE);
10519
static Int2 LIBCALLBACK HUPBioseqFetchFunc (Pointer data)
10528
OMProcControlPtr ompcp;
10529
ObjMgrProcPtr ompp;
10530
Char path [PATH_MAX];
10531
SeqEntryPtr sep = NULL;
10534
OMUserDataPtr omudp;
10536
ompcp = (OMProcControlPtr) data;
10537
if (ompcp == NULL) return OM_MSG_RET_ERROR;
10538
ompp = ompcp->proc;
10539
if (ompp == NULL) return OM_MSG_RET_ERROR;
10540
sip = (SeqIdPtr) ompcp->input_data;
10541
if (sip == NULL) return OM_MSG_RET_ERROR;
10543
if (sip->choice != SEQID_GENBANK) return OM_MSG_RET_ERROR;
10544
tsip = (TextSeqIdPtr) sip->data.ptrvalue;
10545
if (tsip == NULL || StringHasNoText (tsip->accession)) return OM_MSG_RET_ERROR;
10547
if (hupfetchcmd == NULL) {
10548
if (GetAppParam ("SEQUIN", "HUP", "FETCHSCRIPT", NULL, cmmd, sizeof (cmmd))) {
10549
hupfetchcmd = StringSaveNoNull (cmmd);
10552
if (hupfetchcmd == NULL) return OM_MSG_RET_ERROR;
10557
sprintf (cmmd, "csh %s %s > %s", hupfetchcmd, tsip->accession, path);
10561
sprintf (cmmd, "%s %s -o %s", hupfetchcmd, tsip->accession, path);
10565
fp = FileOpen (path, "r");
10568
return OM_MSG_RET_ERROR;
10570
dataptr = ReadAsnFastaOrFlatFile (fp, &datatype, &entityID, FALSE, FALSE, TRUE, FALSE);
10574
if (dataptr == NULL) return OM_MSG_RET_OK;
10576
sep = GetTopSeqEntryForEntityID (entityID);
10577
if (sep == NULL) return OM_MSG_RET_ERROR;
10578
bsp = BioseqFindInSeqEntry (sip, sep);
10579
ompcp->output_data = (Pointer) bsp;
10580
ompcp->output_entityID = ObjMgrGetEntityIDForChoice (sep);
10582
omudp = ObjMgrAddUserData(ompcp->output_entityID, ompp->procid, OMPROC_FETCH, 0);
10585
return OM_MSG_RET_DONE;
10588
static Boolean HUPFetchEnable (void)
10591
ObjMgrProcLoad (OMPROC_FETCH, hupfetchproc, hupfetchproc,
10592
OBJ_SEQID, 0, OBJ_BIOSEQ, 0, NULL,
10593
HUPBioseqFetchFunc, PROC_PRIORITY_DEFAULT);
10361
10597
static CharPtr tpasmartfetchproc = "TPASmartBioseqFetch";
10363
10599
static CharPtr tpasmartfetchcmd = NULL;
11747
12023
CloseLog (lip);
11748
12024
lip = FreeLog (lip);
12028
typedef struct updatefeaturesform {
12030
DialoG new_features;
12031
ValNodePtr feat_list;
12033
} UpdateFeaturesFormData, PNTR UpdateFeaturesFormPtr;
12036
static void CleanupUpdateFeaturesForm (GraphiC g, VoidPtr data)
12038
UpdateFeaturesFormPtr f;
12040
f = (UpdateFeaturesFormPtr) data;
12042
f->feat_list = FreeClickableList (f->feat_list);
12043
f->sap = SeqAnnotFree (f->sap);
12045
StdCleanupFormProc (g, data);
12050
static CharPtr GetNewItemDescription (SeqFeatPtr sfp)
12052
CharPtr location, label, row_text;
12055
location = SeqLocPrintUseBestID (sfp->location);
12056
label = (CharPtr) FeatDefTypeLabel(sfp);
12058
FeatDefLabel (sfp, buf, sizeof (buf) - 1, OM_LABEL_CONTENT);
12060
row_text = (CharPtr) MemNew (sizeof (Char) *
12063
+ StringLen (location)
12065
sprintf (row_text, "%s:%s:%s\n", label, buf, location);
12066
location = MemFree (location);
12071
static ClickableItemPtr PutFeaturesInOldItem (ValNodePtr item_list)
12073
ClickableItemPtr cip_olditems, cip;
12076
cip_olditems = (ClickableItemPtr) MemNew (sizeof (ClickableItemData));
12077
if (item_list == NULL) {
12078
cip_olditems->description = StringSave ("No old features found");
12079
cip_olditems->chosen = FALSE;
12081
for (vnp = item_list; vnp != NULL; vnp = vnp->next) {
12082
cip = (ClickableItemPtr) MemNew (sizeof (ClickableItemData));
12083
cip->description = GetNewItemDescription (vnp->data.ptrvalue);
12084
cip->chosen = TRUE;
12085
ValNodeAddPointer (&(cip->item_list), OBJ_SEQFEAT, vnp->data.ptrvalue);
12086
ValNodeAddPointer (&(cip_olditems->subcategories), 0, cip);
12088
cip_olditems->description = StringSave ("Old Features (check to delete)");
12089
cip_olditems->chosen = TRUE;
12091
return cip_olditems;
12095
static void MarkChosenFeatures (ValNodePtr item_list, Boolean delete_marked)
12097
ClickableItemPtr cip;
12101
while (item_list != NULL) {
12102
cip = (ClickableItemPtr) item_list->data.ptrvalue;
12104
for (vnp = cip->item_list; vnp != NULL; vnp = vnp->next) {
12105
if (vnp->choice == OBJ_SEQFEAT) {
12106
sfp = (SeqFeatPtr) vnp->data.ptrvalue;
12107
if ((cip->chosen && delete_marked) || (!cip->chosen && !delete_marked)) {
12108
sfp->idx.deleteme = TRUE;
12113
item_list = item_list->next;
12118
static void MarkChosenFeaturesForBioseqs (ValNodePtr feat_list)
12120
ClickableItemPtr cip, cip_new, cip_old;
12122
if (feat_list == NULL) return;
12123
cip = (ClickableItemPtr) feat_list->data.ptrvalue;
12124
if (cip->item_list != NULL && cip->item_list->choice == OBJ_BIOSEQ) {
12125
if (cip->subcategories != NULL) {
12126
cip_new = (ClickableItemPtr) cip->subcategories->data.ptrvalue;
12127
MarkChosenFeatures (cip_new->subcategories, FALSE);
12128
if (cip->subcategories->next != NULL) {
12129
cip_old = (ClickableItemPtr) cip->subcategories->next->data.ptrvalue;
12130
MarkChosenFeatures (cip_old->subcategories, TRUE);
12133
MarkChosenFeaturesForBioseqs (feat_list->next);
12134
} else if (feat_list->next != NULL && feat_list->next->next == NULL && cip->item_list == NULL) {
12135
cip_new = (ClickableItemPtr) feat_list->data.ptrvalue;
12136
cip_old = (ClickableItemPtr) feat_list->next->data.ptrvalue;
12137
MarkChosenFeatures (cip_new->subcategories, FALSE);
12138
MarkChosenFeatures (cip_old->subcategories, TRUE);
12143
static void DoUpdateFeatures (ButtoN b)
12145
UpdateFeaturesFormPtr f;
12147
f = (UpdateFeaturesFormPtr) GetObjectExtra (b);
12148
if (f == NULL) return;
12150
MarkChosenFeaturesForBioseqs (f->feat_list);
12152
SmartAttachSeqAnnotToSeqEntry (f->input_entityID, f->sap, NULL);
12155
DeleteMarkedObjects (f->input_entityID, 0, NULL);
12156
ObjMgrSetDirtyFlag (f->input_entityID, TRUE);
12157
ObjMgrSendMsg (OM_MSG_UPDATE, f->input_entityID, 0, 0);
12163
extern void UpdateFeatures (IteM i)
12170
Char path [PATH_MAX];
12173
ValNodePtr new_feat_list = NULL, no_bsp_list = NULL, old_item_list;
12174
Int4 leftmost = -1, rightmost = -1, new_left, new_right, tmp;
12175
BioseqPtr bsp, last_bsp = NULL;
12176
ClickableItemPtr cip = NULL, cip_newitems = NULL, cip_olditems, cip_newfeat;
12181
UpdateFeaturesFormPtr f;
12185
bfp = currentFormDataPtr;
12187
bfp = GetObjectExtra (i);
12189
if (bfp == NULL) return;
12190
sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
12191
if (sep == NULL) return;
12194
if (!GetInputFileName (path, sizeof (path), "", "TEXT")) {
12198
fp = FileOpen (path, "r");
12200
Message (MSG_ERROR, "Unable to open file!");
12203
dataptr = ReadAsnFastaOrFlatFile (fp, &datatype, NULL, FALSE, FALSE,
12206
if (dataptr == NULL || datatype != OBJ_SEQANNOT) {
12207
Message (MSG_ERROR, "File does not contain feature table!");
12211
sap = (SeqAnnotPtr) dataptr;
12212
if (sap->type != 1) {
12213
Message (MSG_ERROR, "File does not contain feature table!");
12214
sap = SeqAnnotFree (sap);
12218
// list features for each bioseq
12219
for (sfp = sap->data; sfp != NULL; sfp = sfp->next) {
12220
bsp = BioseqFindFromSeqLoc (sfp->location);
12222
ValNodeAddPointer (&no_bsp_list, OBJ_SEQFEAT, sfp);
12224
if (bsp != last_bsp) {
12225
if (last_bsp != NULL) {
12226
slp = SeqLocIntNew (leftmost, rightmost, Seq_strand_plus, SeqIdDup (SeqIdFindWorst (bsp->id)));
12227
old_item_list = ListFeaturesOverlappingLocation (last_bsp, slp, 0, 0);
12228
slp = SeqLocFree (slp);
12229
cip_olditems = PutFeaturesInOldItem (old_item_list);
12230
old_item_list = ValNodeFree (old_item_list);
12231
ValNodeAddPointer (&(cip->subcategories), 0, cip_olditems);
12233
cip = (ClickableItemPtr) MemNew (sizeof (ClickableItemData));
12234
ValNodeAddPointer (&(cip->item_list), OBJ_BIOSEQ, bsp);
12236
SeqIdWrite (SeqIdFindBest (bsp->id, SEQID_GENBANK), id, PRINTID_FASTA_LONG, sizeof (id) - 1);
12237
cip->description = StringSave (id);
12238
cip_newitems = (ClickableItemPtr) MemNew (sizeof (ClickableItemData));
12239
cip_newitems->description = StringSave ("New Features (check to import)");
12240
cip_newitems->chosen = TRUE;
12241
ValNodeAddPointer (&(cip->subcategories), 0, cip_newitems);
12243
ValNodeAddPointer (&new_feat_list, 0, cip);
12247
cip_newfeat = (ClickableItemPtr) MemNew (sizeof (ClickableItemData));
12248
cip_newfeat->description = GetNewItemDescription (sfp);
12249
cip_newfeat->chosen = TRUE;
12250
ValNodeAddPointer (&(cip_newfeat->item_list), OBJ_SEQFEAT, sfp);
12251
ValNodeAddPointer (&(cip_newitems->subcategories), 0, cip_newfeat);
12252
new_left = SeqLocStart (sfp->location);
12253
new_right = SeqLocStop (sfp->location);
12254
if (new_left > new_right) {
12256
new_left = new_right;
12259
if (leftmost == -1 || new_left < leftmost) {
12260
leftmost = new_left;
12262
if (rightmost == -1 || new_right > rightmost) {
12263
rightmost = new_right;
12267
if (last_bsp != NULL) {
12268
slp = SeqLocIntNew (leftmost, rightmost, Seq_strand_plus, SeqIdDup (SeqIdFindWorst (bsp->id)));
12269
old_item_list = ListFeaturesOverlappingLocation (last_bsp, slp, 0, 0);
12270
slp = SeqLocFree (slp);
12271
cip_olditems = PutFeaturesInOldItem (old_item_list);
12272
old_item_list = ValNodeFree (old_item_list);
12273
ValNodeAddPointer (&(cip->subcategories), 0, cip_olditems);
12276
if (no_bsp_list != NULL) {
12277
Message (MSG_ERROR, "%d features in table are not found on a Bioseq in this record!", ValNodeLen (no_bsp_list));
12278
no_bsp_list = ValNodeFree (no_bsp_list);
12281
if (new_feat_list == NULL) {
12282
Message (MSG_ERROR, "No features found!");
12283
sap = SeqAnnotFree (sap);
12286
if (new_feat_list->next == NULL) {
12287
no_bsp_list = new_feat_list;
12288
cip = (ClickableItemPtr) new_feat_list->data.ptrvalue;
12289
new_feat_list = cip->subcategories;
12290
cip->subcategories = NULL;
12291
no_bsp_list = FreeClickableList (no_bsp_list);
12295
/* Now create dialog to allow user to select new features to import and existing features to delete */
12296
f = (UpdateFeaturesFormPtr) MemNew (sizeof (UpdateFeaturesFormData));
12297
w = FixedWindow (-50, -33, -10, -10, "Update Features", StdCloseWindowProc);
12298
SetObjectExtra (w, f, CleanupUpdateFeaturesForm);
12299
f->form = (ForM) w;
12300
f->input_entityID = bfp->input_entityID;
12301
f->feat_list = new_feat_list;
12303
h = HiddenGroup (w, -1, 0, NULL);
12304
SetGroupSpacing (h, 10, 10);
12305
g = HiddenGroup (h, 2, 0, NULL);
12306
f->new_features = CreateClickableListDialog (g, "New Features (check to import)", "label1", NULL, NULL, NULL, GetDiscrepancyItemText);
12307
PointerToDialog (f->new_features, new_feat_list);
12308
/* f->old_features = CreateClickableListDialog (g, "Old Features", "label1",
12309
ScrollToDiscrepancyItem, EditDiscrepancyItem, bfp,
12310
GetDiscrepancyItemText); */
12311
c = HiddenGroup (h, 4, 0, NULL);
12312
b = PushButton (c, "Accept", DoUpdateFeatures);
12313
SetObjectExtra (b, f, NULL);
12314
PushButton (c, "Cancel", StdCancelButtonProc);
12316
AlignObjects (ALIGN_CENTER, (HANDLE) g, (HANDLE) c, NULL);