Exemple #1
0
BiostrucFeaturePtr CpyPBSF(BiostrucFeaturePtr pbsfParent, Int4 newMolNum, Int4 lastFeatId, ResidueIntervalPntrPtr pri) {
	BiostrucFeaturePtr pbsfNew;
	ResidueIntervalPntrPtr priNew;
	ValNodePtr vnp, vnp2, vnp3;

	pbsfNew = BiostrucFeatureNew();
	pbsfNew->id = lastFeatId + 1;
	pbsfNew->name = StringSave(pbsfParent->name);
	pbsfNew->type = pbsfParent->type;
	
	priNew = ResidueIntervalPntrNew();
	priNew->molecule_id = newMolNum;
	priNew->from = pri->from;
	priNew->to = pri->to;

	vnp3=ValNodeNew(NULL);
        vnp3->choice=ResiduePntrs_interval;
        vnp3->data.ptrvalue=(VoidPtr)priNew;
        vnp2=ValNodeNew(NULL);
        vnp2->choice=ChemGraphPntrs_residues;
        vnp2->data.ptrvalue=(VoidPtr)vnp3;
        vnp=ValNodeNew(NULL); 
        vnp->choice=Location_location_subgraph;
        vnp->data.ptrvalue=(VoidPtr)vnp2;

	pbsfNew->Location_location=vnp;

	return pbsfNew;
}
Exemple #2
0
static void MakeFetchItemIndex(ValNodePtr fetch_list)
{
  Int4 num;
  ValNodePtr tmp_list = NULL, prev = NULL, vnp, vnp_new;

  if (sFetchIndex != NULL) {
    sFetchIndex = MemFree (sFetchIndex);
    sFetchIndexSize = 0;
  }

  if (fetch_list == NULL) {
    return;
  }

  tmp_list = ValNodeNew (NULL);
  tmp_list->data.ptrvalue = fetch_list->data.ptrvalue;
  prev = tmp_list;
  for (vnp = fetch_list->next; vnp != NULL; vnp = vnp->next) {
    vnp_new = ValNodeNew (prev);
    vnp_new->data.ptrvalue = vnp->data.ptrvalue;
    prev = vnp_new;
  }

  tmp_list = ValNodeSort (tmp_list, SortVnpByFetchItem);
  sFetchIndexSize = ValNodeLen (tmp_list);
  sFetchIndex = (FetchItemPtr PNTR) MemNew (sizeof (FetchItemPtr) * sFetchIndexSize);
  for (vnp = tmp_list, num = 0; vnp != NULL; vnp = vnp->next, num++) {
    sFetchIndex[num] = vnp->data.ptrvalue;
  }
  tmp_list = ValNodeFree (tmp_list);
}
Exemple #3
0
PVNMA CpyPVNMAList(PVNMA pvnma, PMGD pmgdNew) {
	PVNMA pvnmaNew = NULL, pvnmaNewHead = NULL, pvnmaLast = NULL;
	PMAD pmad, pmadNew = NULL;

	while(pvnma) {
		pmad = (PMAD)(pvnma->data.ptrvalue);
		pvnmaNew = ValNodeNew(NULL);
		pvnmaNew->choice = pvnma->choice;
		pmadNew = NewMAD();

		pmadNew->pfbParent = (PFB)pmgdNew;
		pmadNew->bWhat = pmad->bWhat;
		pmadNew->pvnmaLink = pvnmaNew;
		pmadNew->pcAName = pmad->pcAName;
		
		pmadNew->iIndex = pmad->iIndex;
		pmadNew->pvnalLocate = CpyPVNALList(pmad->pvnalLocate, pmadNew);

		pvnmaNew->data.ptrvalue = (VoidPtr)pmadNew;

		if(pvnmaNewHead == NULL) {
			pvnmaNewHead = pvnmaNew;
			pvnmaLast = pvnmaNew;
		}
		else {
			pvnmaLast->next = pvnmaNew;
			pvnmaLast = pvnmaNew;
		}

		pvnma = pvnma->next;
	}

	return pvnmaNewHead;
}
Exemple #4
0
static SeqIdPtr
s_ID1ArchSeqIdsGet (Uint4 gi,AsnIoPtr aiopr, Boolean PNTR not_found)
{
    ID1serverRequestPtr id1reqp;
    ID1serverBackPtr id1bp;
    SeqIdPtr sip;

    *not_found=FALSE;

    id1reqp = ValNodeNew(NULL);
    id1reqp->choice = ID1serverRequest_getseqidsfromgi;
    id1reqp->data.intvalue = gi;
    ID1serverRequestAsnWrite (id1reqp, asnout, NULL);
    AsnIoReset(asnout);
    ID1serverRequestFree (id1reqp);

    if ((id1bp = NetID1servReadAsn()) == NULL)
        return NULL;

    if (id1bp->choice != ID1serverBack_ids) {
        ID1serverBackFree (id1bp);
        return NULL;
    }
    if(aiopr){
        ID1serverBackAsnWrite(id1bp,aiopr,NULL);
        AsnIoReset(aiopr);
    }
    sip = (id1bp->data.ptrvalue);
    id1bp->data.ptrvalue = NULL;
    ID1serverBackFree (id1bp);
    if(sip==NULL) *not_found=TRUE;
    return sip;
}
Exemple #5
0
static Int4
s_ID1ArchGIGet (SeqIdPtr sip)
{
    ID1serverRequestPtr id1reqp;
    ID1serverBackPtr id1bp;
    Int4 gi;

    id1reqp = ValNodeNew(NULL);
    id1reqp->choice = ID1serverRequest_getgi;
    id1reqp->data.ptrvalue = sip;
    ID1serverRequestAsnWrite (id1reqp, asnout, NULL);
    AsnIoReset(asnout);
    id1reqp->data.ptrvalue = NULL;
    ID1serverRequestFree (id1reqp);

    if ((id1bp = NetID1servReadAsn()) == NULL)
        return -1;

    if (id1bp->choice != ID1serverBack_gotgi)
    {
        ID1serverBackFree (id1bp);
        return 0;
    }
    gi = (id1bp->data.intvalue);
    ID1serverBackFree (id1bp);

    return gi;
}
Exemple #6
0
static Int4
s_ID1ArcgGIStateGet(Uint4 gi)
{
    ID1serverRequestPtr id1reqp;
    ID1serverBackPtr id1bp;

    Int4 state;

    id1reqp = ValNodeNew(NULL);
    id1reqp->choice = ID1serverRequest_getgistate;
    id1reqp->data.intvalue = gi;
    ID1serverRequestAsnWrite (id1reqp, asnout, NULL);
    AsnIoReset(asnout);
    ID1serverRequestFree (id1reqp);

    if ((id1bp = NetID1servReadAsn()) == NULL)
        return -1;

    if (id1bp->choice != ID1serverBack_gistate)
    {
        ID1serverBackFree (id1bp);
        return -1;
    }
    state = id1bp->data.intvalue;
    ID1serverBackFree (id1bp);
    return state;
}
Exemple #7
0
static ID1SeqHistPtr
s_ID1ArchGIHistGet(Uint4 gi,Boolean rev,AsnIoPtr aiopr,Boolean PNTR not_found)
{
    ID1serverRequestPtr id1reqp;
    ID1serverBackPtr id1bp;

    ID1SeqHistPtr ishp;

    *not_found=FALSE;
    id1reqp = ValNodeNew(NULL);
    id1reqp->choice = rev? ID1serverRequest_getgirev : ID1serverRequest_getgihist;
    id1reqp->data.intvalue = gi;
    ID1serverRequestAsnWrite (id1reqp, asnout, NULL);
    AsnIoReset(asnout);
    ID1serverRequestFree (id1reqp);

    if ((id1bp = NetID1servReadAsn()) == NULL)
        return NULL;

    if (id1bp->choice != ID1serverBack_girevhist && id1bp->choice != ID1serverBack_gihist)
    {
        ID1serverBackFree (id1bp);
        return NULL;
    }
    if(aiopr){
	ID1serverBackAsnWrite(id1bp,aiopr,NULL);
	AsnIoReset(aiopr);
    }
    ishp = (id1bp->data.ptrvalue);
    id1bp->data.ptrvalue = NULL;
    ID1serverBackFree (id1bp);
    if(ishp==NULL) *not_found=TRUE;
    return ishp;
}
Exemple #8
0
PVNAL CpyPVNALList(PVNAL pvnal, PMAD pmadNew) {
	PVNAL pvnalNew = NULL, pvnalNewHead = NULL, pvnalLast = NULL;
	PALD pald, paldNew = NULL;

	/* One atom location for each model */
	while(pvnal) {
		pald = (PALD)(pvnal->data.ptrvalue);
		pvnalNew = ValNodeNew(NULL);
		pvnalNew->choice = pvnal->choice;

		paldNew = CpyPALD(pald, pmadNew, pvnalNew);
		
		pvnalNew->data.ptrvalue = (VoidPtr)paldNew;
	
		if(pvnalNewHead == NULL) {
			pvnalNewHead = pvnalNew;
			pvnalLast = pvnalNew;
		}	
		else {
			pvnalLast->next = pvnalNew;
			pvnalLast = pvnalNew;
		}

		pvnal = pvnal->next;
	}

	return pvnalNewHead;
}
Exemple #9
0
static void AddBioSourceToSeqEntry (SeqEntryPtr sep)
{
  BioseqPtr    bsp;
  ValNodePtr   descorp;
  BioSourcePtr biop;
  OrgNamePtr   onp;
  OrgRefPtr    orp;

  if (sep == NULL)
    return;
  if ((bsp = sep->data.ptrvalue) == NULL)
    return;

  descorp = ValNodeNew (bsp->descr);
  descorp->choice = Seq_descr_source;
  biop = BioSourceNew ();
  descorp->data.ptrvalue = biop;
  orp = OrgRefNew ();
  biop->org = orp;
  onp = OrgNameNew ();
  orp->orgname = onp;
  biop->genome = 1;
  onp->gcode = 1;
  onp->mgcode = 1;

  if (bsp->descr == NULL)
    bsp->descr = descorp;

  return;
}
Exemple #10
0
static SeqAnnotPtr MakeMrnaSeqAnnot (void)

{
  AnnotDescrPtr  adp;
  SeqAnnotPtr    annot;
  ObjectIdPtr    oip;
  UserFieldPtr   ufp;
  UserObjectPtr  uop;

  annot = SeqAnnotNew ();
  annot->type = 2;

  adp = ValNodeNew (NULL);
  adp->choice = Annot_descr_user;
  uop = UserObjectNew ();
  adp->data.ptrvalue = uop;
  oip = ObjectIdNew ();
  oip->str = StringSave ("Blast Type");
  ufp = UserFieldNew ();
  uop->type = oip;
  uop->data = ufp;
  oip = ObjectIdNew ();
  oip->str = StringSave ("BLASTN - mrna");
  ufp->label = oip;
  ufp->choice = 2;
  ufp->data.intvalue = 1;
  annot->desc = adp;

  adp = ValNodeNew (NULL);
  adp->choice = Annot_descr_user;
  uop = UserObjectNew ();
  adp->data.ptrvalue = uop;
  oip = ObjectIdNew ();
  oip->str = StringSave ("Hist Seqalign");
  ufp = UserFieldNew ();
  uop->type = oip;
  uop->data = ufp;
  oip = ObjectIdNew ();
  oip->str = StringSave ("Hist Seqalign");
  ufp->label = oip;
  ufp->choice = 4;
  ufp->data.boolvalue = TRUE;
  adp->next = annot->desc;
  annot->desc = adp;

  return annot;
}
Exemple #11
0
static SeqEntryPtr
s_ID1ArchSeqEntryGet (Int4 uid, CharPtr db, Int4 ent,Int4Ptr status, Int2 maxplex)

{
    ID1serverRequestPtr id1reqp;
    SeqEntryPtr sep;
    ID1serverMaxcomplexPtr mcp;
    ID1serverBackPtr id1bp;


    if(status)
	*status=0;

    id1reqp = ValNodeNew(NULL);
    id1reqp->choice = ID1serverRequest_getsefromgi;
		mcp = ID1serverMaxcomplexNew();
    id1reqp->data.ptrvalue = mcp;
		mcp -> gi = uid;
		mcp -> maxplex = maxplex;
		if(ent > 0){
			mcp->ent = ent;
			if(db){
				mcp->sat=StringSave(db);
			}
		}
    ID1serverRequestAsnWrite (id1reqp, asnout, NULL);
    AsnIoReset(asnout);
    ID1serverRequestFree (id1reqp);

    SeqMgrHoldIndexing(TRUE);
    id1bp = NetID1servReadAsn();
    SeqMgrHoldIndexing(FALSE);

    if (id1bp == NULL)
        return NULL;

    if (id1bp->choice != ID1serverBack_gotseqentry &&
			id1bp->choice !=  ID1serverBack_gotdeadseqentry)
    {
	if(status && id1bp->choice == ID1serverBack_error){
		*status = id1bp->data.intvalue;
	}
        ID1serverBackFree (id1bp);
        return NULL;
    }
		if (status != NULL){
			if (id1bp->choice == ID1serverBack_gotdeadseqentry){
				* status = 3;
			}else{
				* status = 0;
			}
		}
    sep = (SeqEntryPtr) (id1bp->data.ptrvalue);
    id1bp->data.ptrvalue = NULL; /* for clean free */
    ID1serverBackFree (id1bp);

    return sep;
}
Exemple #12
0
extern FloatHiPtr BiasScoreBioseq (BioseqPtr bsp, Int4Ptr tableGlobal,
                                   Int4 tripletwindow, Int4 xframe,
                                   Uint1 xstrand)
{
  FloatHiPtr score;
  Int4       iscore;

  SeqLocPtr  slp;
  SeqIntPtr  sint;
  Int4       start, stop, xstop, xwindow;
  Int4Ptr    cutp;

  if (bsp == NULL)
    return NULL;
  if (!ISA_na (bsp->mol))
    return NULL;
  if (bsp->length < tripletwindow)
    return NULL;

  slp = ValNodeNew (NULL);
  sint = SeqIntNew ();
  slp->choice = SEQLOC_INT;
  slp->data.ptrvalue = sint;

  xwindow = tripletwindow;
  xstop = (bsp->length + 3 - xframe - xwindow) / 3;
  score = (FloatHiPtr) MemNew ((size_t) (sizeof (FloatHi) * xstop));
  xwindow -= 3;
  xstop--;

  start = xframe;
  stop = start + xwindow - 1;
  sint->from = start;
  sint->to = stop;
  sint->strand = xstrand;
  cutp = CodonTableFromSeqLoc (bsp, slp);

  iscore = 0;

  xstop = bsp->length - 3;
  for (start = stop + 1; start <= xstop; start += 3)
  {
    sint->from = start;
    sint->to = start + 2;
    AddSeqLocToCodonTable (cutp, bsp, slp, TRUE);
    score[iscore++] = Confide (cutp, tableGlobal);
    sint->from -= xwindow;
    sint->to -= xwindow;
    AddSeqLocToCodonTable (cutp, bsp, slp, FALSE);
  }

  FreeCodonTable (cutp);
  slp->data.ptrvalue = (Pointer) SeqIntFree (sint);
  SeqLocFree (slp);
  return score;
}
Exemple #13
0
static ValNodePtr FieldsFromFieldListString (CharPtr str)
{
  CharPtr cpy, val, comma;
  Int4    qual;
  ValNodePtr field_list = NULL, qc;

  if (StringHasNoText (str)) {
    return NULL;
  }
  cpy = StringSave (str);
  val = cpy;
  comma = StringChr(val, ',');
  while (comma != NULL) {
    *comma = 0;
    qual = GetSourceQualTypeByName(val);
    if (qual < 0) {
      Message (MSG_ERROR, "%s is not a recognized source field name", val);
    } else {
      qc = ValNodeNew (NULL);
      qc->choice = SourceQualChoice_textqual;
      qc->data.intvalue = qual;
      ValNodeAddPointer (&field_list, FieldType_source_qual, qc);
    }
    *comma = ',';
    val = comma + 1;
    comma = StringChr (val, ',');
  }

  qual = GetSourceQualTypeByName(val);
  if (qual < 0) {
    Message (MSG_ERROR, "%s is not a recognized source field name", val);
  } else {
    qc = ValNodeNew (NULL);
    qc->choice = SourceQualChoice_textqual;
    qc->data.intvalue = qual;
    ValNodeAddPointer (&field_list, FieldType_source_qual, qc);
  }

  cpy = MemFree (cpy);
  return field_list;
}
Exemple #14
0
NLM_EXTERN SeqIdReplaceListPtr ReadSeqIdPairListFromFile (FILE *fp)
{
  ReadBufferData rbd;
  CharPtr        linestring, cp, id2, buf = NULL;
  Int4           len, buf_len = 0;
  SeqIdPairPtr   pair;
  ValNodePtr     pair_list = NULL, last = NULL, vnp;
  SeqIdReplaceListPtr replace_list = NULL;
  
  if (fp == NULL) return NULL;

  rbd.fp = fp;
  rbd.current_data = NULL;

  linestring = AbstractReadFunction (&rbd);
  while (linestring != NULL && linestring[0] != EOF) {
    cp = linestring + StringSpn (linestring, " \t");
    if (*cp != 0) {
      len = StringCSpn (cp, " \t");
      id2 = cp + len + StringSpn (cp + len, " \t");
      if (*id2 != 0) {
        if (len + 1 > buf_len) {
          buf = MemFree (buf);
          buf_len = len + 1;
          buf = (CharPtr) MemNew (sizeof (Char) * buf_len);
        }
        StringNCpy (buf, cp, len);
        buf[len] = 0;
        pair = SeqIdPairNew ();
        pair->sip_find = MakeSeqID (buf);
        SeqIdWrite (pair->sip_find, pair->buf_find, PRINTID_REPORT, sizeof (pair->buf_find) - 1);
        pair->sip_replace = MakeSeqID (id2);
        vnp = ValNodeNew (NULL);
        vnp->data.ptrvalue = pair;
        if (last == NULL) {
          pair_list = vnp;
        } else {
          last->next = vnp;
        }
        last = vnp;
      }
    }
    free (linestring);
    linestring = AbstractReadFunction (&rbd);     
  }
  pair_list = ValNodeSort (pair_list, SortSeqIdPairList);

  replace_list = SeqIdReplaceListNew (pair_list);
  pair_list = SeqIdPairListFree (pair_list);

  return replace_list;
}
Exemple #15
0
static void HistoClickProc (PaneL pn, PoinT pt)
{
  VieweR    v;
  Uint2     segID, primID, primCt;
  SegmenT   s;
  PrimitivE p;
  GraphViewFormPtr gvp;
  SeqIntPtr sint;
  PntInfo   pnt;

  segID = 0;
  primID = 0;
  primCt = 0;

  v = (VieweR) pn;
  s = FindSegment (v, pt, &segID, &primID, &primCt);

  gvp = GetObjectExtra (v);
  if (primID < 1)
  {
    WatchCursor ();
    ExploreSegment (s, v, UnHLSeg);
    ObjMgrDeSelectAll ();
    ArrowCursor ();
  }
  else
  {
    WatchCursor ();
    ExploreSegment (s, v, UnHLSeg);
    ObjMgrDeSelectAll ();
    ArrowCursor ();
    p = GetPrimitive (s, primCt);
    HighlightPrimitive (v, s, p, FRAME_PRIMITIVE);
    gvp->slp = (SeqLocPtr) ValNodeNew (NULL);
    sint = SeqIntNew ();
    sint->id = SeqIdDup (gvp->bsp->id);
    if (primID == 1)
      sint->strand = Seq_strand_plus;
    else
      sint->strand = Seq_strand_minus;
    MapViewerToWorld (v, pt, &pnt);
    gvp->start = pnt.x * gvp->zoom;
    gvp->stop = gvp->start+gvp->window;
    sint->from = gvp->start;
    sint->to = gvp->stop;
    gvp->slp->choice = SEQLOC_INT;
    gvp->slp->data.ptrvalue = (Pointer) sint;
    ObjMgrSelect (gvp->entityID, gvp->itemID, OBJ_BIOSEQ, OM_REGION_SEQLOC,
                  gvp->slp);
  }
  return;
}
Exemple #16
0
/*============================================================================*\
 * Function:
 *	SuggestInit
 *
 * Purpose:
 *	Initializes Suggest API
 *
 * Parameters:
 *	none
 *
 * Return:
 *	TRUE if successful, FALSE otherwise
 *
\*----------------------------------------------------------------------------*/
Boolean
SuggestInit(void)
{
    SuggestRequestPtr	pRequest;
    SuggestResponsePtr	pResponse;

/*    myNetInit = SuggestInit;
*/
    if (!NetInit())
        return FALSE;

    svcp = NI_GenericGetService(dispatcher, NULL, "SUGGEST", "Suggest", TRUE);
    if (svcp == NULL)
    {
        ErrPostEx(SEV_ERROR, 0, 0, "NI_ServiceGet [%s] (%s)",
		  ni_errlist[ni_errno], ni_errtext);
        SuggestFini();

        return FALSE;
    }

    pAsnIn = svcp->raip;
    pAsnOut = svcp->waip;

    pRequest = ValNodeNew(NULL);
    pRequest->choice = SuggestRequest_init;
    SuggestRequestAsnWrite (pRequest, pAsnOut, NULL);
    AsnIoReset(pAsnOut);
    SuggestRequestFree(pRequest);

    if ((pResponse = NetSuggestReadAsn()) == NULL)
    {
        return FALSE;
    }

    if (pResponse->choice == SuggestResponse_error) {
	ErrorFromServer(pResponse->data.ptrvalue);
	if (((SuggestErrorPtr)pResponse->data.ptrvalue)->level
	    == Suggest_error_level_fatal)
	    bSendFini = FALSE;
	SuggestFini();
	SuggestResponseFree(pResponse->data.ptrvalue);
	
	return FALSE;
    }
    
    pResponse->data.ptrvalue = NULL;
    SuggestResponseFree(pResponse);

    return TRUE;
}
Exemple #17
0
/*---------------- make new LocalId ------------------------*/
SeqIdPtr MakeLocalId(Char *str)
{
  SeqIdPtr sip;
  ObjectIdPtr oip;

  oip = ObjectIdNew();
  oip->str = str;

  sip = ValNodeNew(NULL);
  sip->choice = SEQID_LOCAL;
  sip->data.ptrvalue = oip;     

  return(sip);
}
Exemple #18
0
static ValNodePtr ValNodeCopyCharPtr (ValNodePtr v1)
{
  ValNodePtr vhead, v2;

  vhead = v2 = NULL;
  while (v1 != NULL)
  {
    v2 = ValNodeNew (vhead);
    if (vhead == NULL)
      vhead = v2;
    v2->data.ptrvalue = StringSave (v1->data.ptrvalue);
    v1 = v1->next;
  }
  return vhead;
}
Exemple #19
0
PVNMB CpyPVNMBList(PVNMB pvnmb, PDNMG pdnmgNewHead, Pointer parentPtr) {
	PDNMG pdnmg, pdnmgNew, pdnmgPmadFrom = NULL, pdnmgPmadTo = NULL;
	PMGD pmgd, pmgdNew, pmgdTmp = NULL;
	PVNMB pvnmbNew, pvnmbNewHead = NULL, pvnmbLast = NULL;
	PMBD pmbd, pmbdNew;

	while(pvnmb) {
		pmbd = (PMBD)(pvnmb->data.ptrvalue);	
		pvnmbNew = ValNodeNew(NULL);
		pvnmbNew->choice = pvnmb->choice;

		pmbdNew = NewMBD();

		pmbdNew->pfbParent = (PFB)parentPtr;
		pmbdNew->pvnmbLink = pvnmbNew;
		pmbdNew->bWhat = pmbd->bWhat;
		
		pmgdTmp = (PMGD)(pmbd->pmadFrom->pfbParent);
		pdnmgPmadFrom = GetPDNMGFromIndex(pdnmgNewHead, ((PDNMG)(pmgdTmp->pdnmgLink))->choice);
		pmbdNew->pmadFrom = GetPMADFromName(((PMGD)(pdnmgPmadFrom->data.ptrvalue))->pvnmaAHead, pmbd->pmadFrom->pcAName);

		pmgdTmp = (PMGD)(pmbd->pmadTo->pfbParent);
		pdnmgPmadTo = GetPDNMGFromIndex(pdnmgNewHead, ((PDNMG)(pmgdTmp->pdnmgLink))->choice);
		pmbdNew->pmadTo = GetPMADFromName(((PMGD)(pdnmgPmadTo->data.ptrvalue))->pvnmaAHead, pmbd->pmadTo->pcAName);

		/* Add PMBD to the appropriate PMADs */
		ValNodeAddPointer(&pmbdNew->pmadFrom->pvnBonds, 0, (VoidPtr)pmbdNew);			
		ValNodeAddPointer(&pmbdNew->pmadTo->pvnBonds, 0, (VoidPtr)pmbdNew);			
		
		pvnmbNew->data.ptrvalue = (VoidPtr)pmbdNew;

		if(pvnmbNewHead == NULL) {
                        pvnmbNewHead = pvnmbNew;
                        pvnmbLast = pvnmbNew;
                }
                else {
                        pvnmbLast->next = pvnmbNew;
                        pvnmbLast = pvnmbNew;
                }

		pvnmb = pvnmb->next;
	}

	return pvnmbNewHead;
}
Exemple #20
0
/*============================================================================*\
 * Function:
 *	SuggestFindIntervals
 *
 * Purpose:
 *
 *
 * Parameters:
 *	pIntervals	- pointer to SuggestIntervals structure which contains
 *		the data for processing;
 *
 * Return:
 *	pointer to SeqAnnot structure which will contain the result of
 * 	the processing or NULL if error occurred.
 *
 * Note:
 *	SuggestResponse structure can contain an error from Suggest Server, so
 *	if this function returns not NULL it does not mean that all right. The
 *	caller of this function should check the structure on errors.
 *
 *	This function does not free input structure pointed pIntervals.
 *
\*----------------------------------------------------------------------------*/
SeqAnnotPtr SuggestFindIntervals(SuggestIntervalsPtr pIntervals)
{
    SuggestRequestPtr	pReq;
    SuggestResponsePtr	pResp;
    SeqAnnotPtr		pSeqAnnot;

    if (pIntervals == NULL)
	return NULL;

    /* Create request and send it to the server
     */
    pReq = ValNodeNew(NULL);
    if (pReq == NULL)
	return NULL;
	
    pReq->choice = SuggestRequest_intervals;
    pReq->data.ptrvalue = pIntervals;
    SuggestRequestAsnWrite(pReq, pAsnOut, NULL);
    AsnIoReset(pAsnOut);
    
    pReq->data.ptrvalue = NULL;	/* The function doesn't free input data */
    SuggestRequestFree(pReq);

    /* Read response from the server
     */
    pResp = NetSuggestReadAsn();
    if (pResp == NULL)
	return NULL;

    if (pResp->choice == SuggestResponse_error) {
	/* Error occurred on server's side, report it
	 */
	ErrorFromServer(pResp->data.ptrvalue);
	SuggestResponseFree(pResp);

	return NULL;
    }

    pSeqAnnot = pResp->data.ptrvalue;
    pResp->data.ptrvalue = NULL;
    SuggestResponseFree(pResp);
    
    return pSeqAnnot;
}
Exemple #21
0
static Pointer DialogToEndPoint (DialoG d)
{
  ValNodePtr         ephead, eplist, vnp;
  TagListPtr         tlp;

  ephead = eplist = NULL;
  tlp = (TagListPtr) GetObjectExtra (d);
  if (tlp != NULL && tlp->vnp != NULL)
  {
    for (vnp = tlp->vnp; vnp != NULL; vnp = vnp->next)
    {
      eplist = ValNodeNew (ephead);
      if (ephead == NULL)
        ephead = eplist;
      eplist->data.ptrvalue = StringSave ((CharPtr) vnp->data.ptrvalue);
    }
  }
  return ephead;
}
Exemple #22
0
/******************************************************************
***
*	general_id_make(): make SeqIdPtr with SEQID_LOCAL choice
*
*******************************************************************
***/
NLM_EXTERN SeqIdPtr general_id_make(CharPtr name, CharPtr dbase)
{
   SeqIdPtr new_id;
   ObjectIdPtr obj_id;
   DbtagPtr db_tag;


	new_id=(SeqIdPtr)ValNodeNew(NULL);
	new_id->choice = SEQID_GENERAL;
	db_tag = DbtagNew();
	db_tag->db = StringSave(dbase);

	obj_id = ObjectIdNew();
	obj_id->str = StringSave(name);
	db_tag->tag = obj_id;

	new_id->data.ptrvalue = db_tag;

	return new_id;
}
Exemple #23
0
static BioseqPtr FetchOnlyBioseqFromID (CharPtr str)
{
   BioseqPtr    bsp = NULL;
   Uint2        entityID;
   SeqEntryPtr  sep;
   SeqIdPtr     sip = NULL;
   Int4         uid;
   time_t       t1, t2;

   t1 = time (NULL);
   uid = 0;
   TrimSpacesAroundString (str);
   if (IsAllDigits (str)) {
     if (PvtStrToLong (str, &uid)) {
       sip = ValNodeNew(NULL);
       sip->choice = SEQID_GI;
       sip->data.intvalue = uid;
     } else {
      uid = 0;
     }
   } else {
     sip = SeqIdFromAccessionDotVersion (str);
     uid = AccessionToGi (str);
   }
   sep = NULL;
   if (uid > 0) {
     sep = PubSeqSynchronousQuery (uid, 3, 0); /* retcode was 0 */
     if (sep != NULL) {
       bsp = BioseqFindInSeqEntry (sip, sep);
       entityID = ObjMgrGetEntityIDForChoice (sep); 
     }
   }
   sip = SeqIdFree (sip);
   if (debug_mode) {
    t2 = time (NULL);
    if (t2 - t1 > 1) {
      printf ("Time to download %s from ID:%d\n", str, (int) (t2 - t1));
    }
   }
   return bsp;
}
Exemple #24
0
/*************************************************************************
***
*	gb_id_make(): make the Seq-id for Genbank with tsip->name = name
*	tsip->acc.
*
*************************************************************************
***/
NLM_EXTERN SeqIdPtr gb_id_make(CharPtr name, CharPtr acc)
{
   SeqIdPtr new_id;
   TextSeqIdPtr tsip;

	   new_id= (SeqIdPtr)ValNodeNew(NULL);
	   new_id->choice = SEQID_GENBANK;
	   tsip = TextSeqIdNew();
	   if(name)
	   {
	   if(StringLen(name) >3 && IS_ALPHA(name[0]))
	     tsip->name = StringSave(name);
	   }
	   if(acc)
	   {
	   if(StringLen(acc) >3 && IS_ALPHA(acc[0]))
	     tsip->accession = StringSave(acc);
	   }
	   new_id->data.ptrvalue = tsip;
	   return new_id;
}
Exemple #25
0
static ValNodePtr FetchItemListFromTable (ValNodePtr table)
{
  ValNodePtr       list = NULL, prev = NULL, this_item, row, col;

  if (table == NULL || table->next == NULL) {
    return NULL;
  }
  for (row = table->next; row != NULL; row = row->next) {
    col = (ValNodePtr) row->data.ptrvalue;
    if (col != NULL) {
      this_item = ValNodeNew (NULL);
      this_item->data.ptrvalue = FetchItemNew (col->data.ptrvalue);
      if (prev == NULL) {
        list = this_item;
      } else {
        prev->next = this_item;
      }
      prev = this_item;
    }
  }
  return list;
}
Exemple #26
0
/*============================================================================*\
 * Function:
 *	SuggestFini
 *
 * Purpose:
 *	Frees all resources allocated by the API.
 *
 * Parameters:
 *	none
 *
 * Return:
 *	TRUE if successful, FALSE otherwise
 *
\*----------------------------------------------------------------------------*/
Boolean
SuggestFini(void)
{
    short erract;
    ErrDesc err;
    Boolean retval = TRUE;

    ErrGetOpts(&erract, NULL);
    ErrSetOpts(ERR_IGNORE, 0);
    ErrFetch(&err);

    if (pAsnOut != NULL && pAsnIn != NULL && bSendFini)
    {
	SuggestRequestPtr	pReq;
	SuggestResponsePtr	pResp;

        pReq = ValNodeNew(NULL);
        pReq->choice = SuggestRequest_fini;
        SuggestRequestAsnWrite(pReq, pAsnOut, NULL);
        AsnIoReset(pAsnOut);
        SuggestRequestFree(pReq);

	if ((pResp = NetSuggestReadAsn()) == NULL) {
	    retval = FALSE;
	} else {
	    pResp->data.ptrvalue = NULL;
	    SuggestResponseFree(pResp);
	    retval = TRUE;
	}
    }

    NetFini();

    ErrSetOpts(erract, 0);
    ErrFetch(&err);

    return retval;
}
Exemple #27
0
NLM_EXTERN ValNodePtr LIBCALL AsnGenericBaseSeqOfAsnRead (AsnIoPtr aip, AsnModulePtr amp, AsnTypePtr orig, int whichvalslot, BoolPtr isError)
{
   AsnTypePtr      start_atp;
   ValNodePtr      current;
   ValNodePtr      head = NULL;
   ValNodePtr      prev = NULL;
   AsnTypePtr      atp = orig;
   DataVal         av;

   if (isError != NULL)
      *isError = FALSE;

   if (aip == NULL)
      return NULL;

   if (AsnReadVal (aip, atp, &av) <= 0)	/* START_STRUCT */
      goto erret;

   start_atp = atp;

   while ((atp = AsnReadId (aip, amp, atp)) != start_atp) {
      if (atp == NULL)
	 goto erret;

      current = ValNodeNew (prev);
      if (current == NULL)
	 goto erret;
      switch (whichvalslot) {
      case ASNCODE_PTRVAL_SLOT:
      case ASNCODE_BYTEVAL_SLOT:
	 if (AsnReadVal (aip, atp, &av) <= 0)
	    goto erret;
	 current->data.ptrvalue = av.ptrvalue;
	 break;
      case ASNCODE_REALVAL_SLOT:
	 if (AsnReadVal (aip, atp, &av) <= 0)
	    goto erret;
	 current->data.realvalue = av.realvalue;
	 break;
      case ASNCODE_INTVAL_SLOT:
	 if (AsnReadVal (aip, atp, &av) <= 0)
	    goto erret;
	 current->data.intvalue = av.intvalue;
	 break;
      case ASNCODE_BIGINTVAL_SLOT:
	 if (AsnReadVal (aip, atp, &av) <= 0)
	    goto erret;
	 current->data.bigintvalue = av.bigintvalue;
	 break;
      case ASNCODE_BOOLVAL_SLOT:
	 if (AsnReadVal (aip, atp, &av) <= 0)
	    goto erret;
	 current->data.boolvalue = av.boolvalue;
	 break;
      }

      if (head == NULL)
	 head = current;
      else
	 prev->next = current;
      prev = current;
   }
   if (AsnReadVal (aip, atp, &av) <= 0)	/* END_STRUCT */
      goto erret;

ret:
   return head;

erret:
   head = ValNodeFree (head);
   if (isError != NULL)
      *isError = TRUE;
   goto ret;
}
Exemple #28
0
static BioSourcePtr OldParseTitleIntoBioSource (
  SqnTagPtr stp,
  BioseqPtr bsp,
  CharPtr organism
)

{
  BioSourcePtr  biop = NULL;
  ValNodePtr    db;
  DbtagPtr      dbt;
  Int2          idx;
  ObjectIdPtr   oip;
  OrgModPtr     omp;
  OrgNamePtr    onp;
  OrgRefPtr     orp;
  SubSourcePtr  ssp;
  CharPtr       str;
  int           val;

  if (stp == NULL && StringHasNoText (organism)) return NULL;

  str = SqnTagFind (stp, "top");
  if (str != NULL && bsp != NULL) {
    if (StringICmp (str, "linear") == 0) {
      bsp->topology = TOPOLOGY_LINEAR;
    } else if (StringICmp (str, "circular") == 0) {
      bsp->topology = TOPOLOGY_CIRCULAR;
    }
  }
  str = SqnTagFind (stp, "org");
  if (str == NULL) {
    str = organism;
  }
  if (StringHasNoText (str)) return NULL;
   biop = BioSourceNew ();
  if (biop == NULL) return NULL;
  orp = OrgRefNew ();
  if (orp == NULL) return NULL;
  biop->org = orp;
  onp = OrgNameNew ();
  if (onp == NULL) return NULL;
  orp->orgname = onp;
  orp->taxname = StringSave (str);

  /* look for entry of organisms in commonOrgStuff table */

  for (idx = 0; commonOrgStuff [idx].taxname != NULL; idx++) {
    if (StringICmp (orp->taxname, commonOrgStuff [idx].taxname) == 0) {
      onp->gcode = commonOrgStuff [idx].gcode;
      onp->mgcode = commonOrgStuff [idx].mgcode;
      onp->div = StringSave (commonOrgStuff [idx].division);
      onp->lineage = StringSave (commonOrgStuff [idx].lineage);
      db = ValNodeNew (NULL);
      if (db != NULL) {
        dbt = DbtagNew ();
        if (dbt != NULL) {
          oip = ObjectIdNew ();
          if (oip != NULL) {
            oip->id = commonOrgStuff [idx].taxID;
            dbt->db = StringSave ("taxon");
            dbt->tag = oip;
            db->data.ptrvalue = (Pointer) dbt;
            orp->db = db;
          }
        }
      }
    }
  }

  /* otherwise can get genetic codes from FASTA defline */

  str = SqnTagFind (stp, "gcode");
  if (str != NULL && sscanf (str, "%d", &val) == 1) {
    onp->gcode = (Uint1) val; /* cytoplasmic */
  }

  str = SqnTagFind (stp, "mgcode");
  if (str != NULL && sscanf (str, "%d", &val) == 1) {
    onp->mgcode = (Uint1) val; /* mitochondrial */
  }

  str = SqnTagFind (stp, "location");
  if (str != NULL && StringICmp (str, "mitochondrion") == 0) {
    biop->genome = GENOME_mitochondrion;
  } else {
    biop->genome = GENOME_genomic;
  }

  str = SqnTagFind (stp, "strain");
  if (str != NULL) {
    omp = OrgModNew ();
    if (omp != NULL) {
      omp->subtype = ORGMOD_strain;
      omp->subname = StringSave (str);
      onp->mod = omp;
    }
  }

  str = SqnTagFind (stp, "chromosome");
  if (str != NULL) {
    ssp = SubSourceNew ();
    if (ssp != NULL) {
      ssp->subtype = SUBSRC_chromosome;
      ssp->name = StringSave (str);
      biop->subtype = ssp;
    }
  }

  return biop;
}
Exemple #29
0
/*****************************************************************************
*
*   PubSetAsnRead(aip, atp)
*   	atp is the current type (if identifier of a parent struct)
*            assumption is readIdent has occurred
*       if atp == NULL, then assumes it stands alone and read ident
*            has not occurred.
*
*****************************************************************************/
NLM_EXTERN ValNodePtr LIBCALL PubSetAsnRead (AsnIoPtr aip, AsnTypePtr orig)
{
	DataVal av;
	AsnTypePtr atp, settype;
    Pointer pnt;
    ValNodePtr anp=NULL, cit, curr;
    Uint1 choice;
    AsnReadFunc func;
    Boolean first;

	if (! loaded)
	{
		if (! PubAsnLoad())
			return anp;
	}

	if (aip == NULL)
		return anp;

	if (orig == NULL)           /* PubSet ::= (self contained) */
		atp = AsnReadId(aip, amp, PUB_SET);
	else
		atp = AsnLinkType(orig, PUB_SET);    /* link in local tree */
    if (atp == NULL) return anp;

	anp = ValNodeNew(NULL);
    if (anp == NULL) goto erret;

	if (AsnReadVal(aip, atp, &av) <= 0)    /* read the CHOICE value (nothing) */
        goto erret;
	settype = AsnReadId(aip, amp, atp);  /* find the choice */
    if (settype == NULL) goto erret;
    if (AsnReadVal(aip, settype, &av) <= 0)    /* read START_STRUCT */
        goto erret;

	if (settype == PUB_SET_pub)
    {
        choice = 1;
        func = (AsnReadFunc) PubAsnRead;
    }
    else if (settype == PUB_SET_medline)
    {
        choice = 3;
        func = (AsnReadFunc) MedlineEntryAsnRead;
    }
    else if (settype == PUB_SET_article)
    {
        choice = 5;
        func = (AsnReadFunc) CitArtAsnRead;
    }
    else if (settype == PUB_SET_journal)
    {
        choice = 6;
        func = (AsnReadFunc) CitJourAsnRead;
    }
    else if (settype == PUB_SET_book)
    {
        choice = 7;
        func = (AsnReadFunc) CitBookAsnRead;
    }
    else if (settype == PUB_SET_proc)
    {
        choice = 8;
        func = (AsnReadFunc) CitBookAsnRead;
    }
    else if (settype == PUB_SET_patent)
    {
        choice = 9;
        func = (AsnReadFunc) CitPatAsnRead;
    }

    anp->choice = choice;
    first = TRUE;
    curr = NULL;
    while ((atp = AsnReadId(aip, amp, settype)) != settype)
    {
        if (atp == NULL) goto erret;
        pnt = (* func)(aip, atp);
        if (pnt == NULL) goto erret;
        if (settype == PUB_SET_pub)   /* already a Pub */
        {
            cit = (ValNodePtr)pnt;
        }
        else                          /* make into a Pub */
        {
            cit = ValNodeNew(NULL);
            if (cit == NULL) goto erret;
            cit->data.ptrvalue = pnt;
            cit->choice = choice;
        }

        if (first)
        {
            anp->data.ptrvalue = (Pointer)cit;
            first = FALSE;
        }
        else
        {
            curr->next = cit;
        }
        curr = cit;
    }
    if (AsnReadVal(aip, settype, &av) <= 0)   /* read END_STRUCT for SET OF */
        goto erret;
	if (anp == NULL)
		ErrPost(CTX_NCBIOBJ, 1, "Empty SET OF Pub.  line %ld", aip->linenumber);
ret:
	AsnUnlinkType(orig);       /* unlink local tree */
	return anp;
erret:
    anp = PubSetFree(anp);
    goto ret;
}
Exemple #30
0
/*****************************************************************************
*
*   PubAsnRead(aip, atp)
*   	atp is the current type (if identifier of a parent struct)
*            assumption is readIdent has occurred
*       if atp == NULL, then assumes it stands alone and read ident
*            has not occurred.
*
*****************************************************************************/
NLM_EXTERN ValNodePtr LIBCALL PubAsnRead (AsnIoPtr aip, AsnTypePtr orig)
{
	DataVal av;
	AsnTypePtr atp;
    ValNodePtr anp=NULL;
    Uint1 choice = 0;
    AsnReadFunc func = NULL;

	if (! loaded)
	{
		if (! PubAsnLoad())
			return anp;
	}

	if (aip == NULL)
		return anp;

	if (orig == NULL)           /* Pub ::= (self contained) */
		atp = AsnReadId(aip, amp, PUB);
	else
		atp = AsnLinkType(orig, PUB);    /* link in local tree */
    if (atp == NULL) return anp;

	anp = ValNodeNew(NULL);
    if (anp == NULL) goto erret;

	if (AsnReadVal(aip, atp, &av) <= 0) goto erret;    /* read the CHOICE value (nothing) */
	atp = AsnReadId(aip, amp, atp);  /* find the choice */
    if (atp == NULL) goto erret;

	if (atp == PUB_gen)
    {
        choice = 1;
        func = (AsnReadFunc) CitGenAsnRead;
    }
    else if (atp == PUB_sub)
    {
        choice = 2;
        func = (AsnReadFunc) CitSubAsnRead;
    }
    else if (atp == PUB_medline)
    {
        choice = 3;
        func = (AsnReadFunc) MedlineEntryAsnRead;
    }
    else if (atp == PUB_muid)
    {
        choice = 4;
        if (AsnReadVal(aip, atp, &anp->data) <= 0) goto erret;
    }
    else if (atp == PUB_article)
    {
        choice = 5;
        func = (AsnReadFunc) CitArtAsnRead;
    }
    else if (atp == PUB_journal)
    {
        choice = 6;
        func = (AsnReadFunc) CitJourAsnRead;
    }
    else if (atp == PUB_book)
    {
        choice = 7;
        func = (AsnReadFunc) CitBookAsnRead;
    }
    else if (atp == PUB_proc)
    {
        choice = 8;
        func = (AsnReadFunc) CitProcAsnRead;
    }
    else if (atp == PUB_patent)
    {
        choice = 9;
        func = (AsnReadFunc) CitPatAsnRead;
    }
    else if (atp == PUB_pat_id)
    {
        choice = 10;
        func = (AsnReadFunc) IdPatAsnRead;
    }
    else if (atp == PUB_man)
    {
        choice = 11;
        func = (AsnReadFunc) CitLetAsnRead;
    }
    else if (atp == PUB_equiv)
    {
        choice = 12;
        func = (AsnReadFunc) PubEquivAsnRead;
    }
    else if (atp == PUB_pmid)
    {
        choice = 13;
        if (AsnReadVal(aip, atp, &anp->data) <= 0) goto erret;
    }

    anp->choice = choice;
    if ((choice != 4) && (choice != 13) && func != NULL)
    {
        anp->data.ptrvalue = (* func)(aip, atp);
        if (anp->data.ptrvalue == NULL) goto erret;
    }
ret:
	AsnUnlinkType(orig);       /* unlink local tree */
	return anp;
erret:
    anp = PubFree(anp);
    goto ret;
}