示例#1
0
static NIOptions* s_GetNIOptions
(const Char *conf_file, const Char *conf_section)
{
  static TNlmTls s_NIOptionsTLS;

  NIOptions *nio;
  Char       conn_mode[64];

  if (NlmTlsGetValue(s_NIOptionsTLS, (VoidPtr *)&nio)
      &&  nio  &&  nio->interface != eNII_Default)
    return nio;

  if ( !nio )
    nio = (NIOptions *)MemNew(sizeof(NIOptions));

  NI_GetEnvParam(conf_file, conf_section, ENV_CONN_MODE,
                 conn_mode, sizeof(conn_mode), "");
  if (StringICmp(conn_mode, SERVICE_MODE) == 0)
    nio->interface = eNII_Service;
  else if (StringICmp(conn_mode, DEBUG_MODE) == 0)
    nio->interface = eNII_Debug;
  else
    nio->interface = NII_DEFAULT;

  if ( !NI_IsInterfaceSupported(nio->interface) )
    nio->interface = NII_DEFAULT;
  ASSERT ( NI_IsInterfaceSupported(nio->interface) );

  NlmTlsSetValue(&s_NIOptionsTLS, (VoidPtr)nio, s_NIOptionsTLS_Cleanup);
  return nio;
}
示例#2
0
static Boolean GetGraphsProc (GatherObjectPtr gop)

{
  GphGetPtr    ggp;
  GphItemPtr   gip;
  SeqGraphPtr  sgp;

  if (gop == NULL || gop->itemtype != OBJ_SEQGRAPH) return TRUE;
  ggp = (GphGetPtr) gop->userdata;
  sgp = (SeqGraphPtr) gop->dataptr;
  if (ggp == NULL || sgp == NULL) return TRUE;
  /* only phrap or gap4 currently allowed */
  if (StringICmp (sgp->title, "Phrap Quality") == 0 ||
      StringICmp (sgp->title, "Gap4") == 0) {
    /* data type must be bytes */
    if (sgp->flags[2] == 3) {
      if (SeqIdForSameBioseq (SeqLocId (sgp->loc), SeqLocId (ggp->slp))) {
        gip = (GphItemPtr) MemNew (sizeof (GphItem));
        if (gip == NULL) return TRUE;
        gip->sgp = sgp;
        gip->left = GetOffsetInBioseq (sgp->loc, ggp->bsp, SEQLOC_LEFT_END);
        gip->right = GetOffsetInBioseq (sgp->loc, ggp->bsp, SEQLOC_RIGHT_END);
        ValNodeAddPointer (&(ggp->vnp), 0, (Pointer) gip);
      }
    }
  }
  return TRUE;
}
示例#3
0
static SeqIdPairPtr FindReplacementInSeqIdReplaceList (SeqIdPtr sip, SeqIdReplaceListPtr pair_list)
{
  Int4         l, r, m;
  Char         buf_find[100];
  int          cmp;

  if (sip == NULL || pair_list == NULL) return NULL;

  SeqIdWrite (sip, buf_find, PRINTID_REPORT, sizeof (buf_find) - 1);
  l = 0;
  r = pair_list->num_ids - 1;
  m = (r + l) / 2;

  while ((cmp = StringICmp (buf_find, pair_list->list[m].buf_find)) != 0 && l <= r) {
    if (cmp < 0) {
      r = m - 1;
    } else {
      l = m + 1;
    }
    m = (r + l) / 2;
  }
  if (cmp == 0) {
    return pair_list->list + m;
  } else {
    return NULL;
  }
}
示例#4
0
static int SeqIdPairCompare (SeqIdPairPtr sp1, SeqIdPairPtr sp2)
{
  if (sp1 == NULL || sp2 == NULL) {
    return 0;
  }
  return StringICmp (sp1->buf_find, sp2->buf_find);
}
示例#5
0
文件: taxcs.c 项目: hsptools/hsp-wrap
Int2 tax_getDivisionId(CharPtr div_cde, CharPtr div_txt)
{
    Int2 i;

    if(div_cde != NULL) {
	for(i= 0; i < div_alloced; i++) {
	    if(StringICmp(tax_div[i].div_cde, div_cde) == 0) return i;
	}
    }

    if(div_txt != NULL) {
	for(i= 0; i < div_alloced; i++) {
	    if(StringICmp(tax_div[i].div_txt, div_txt) == 0) return i;
	}
    }

    return -1;
}
示例#6
0
/*****************************************************************************

Function: DDV_UseNetwork()

Purpose:  Determines if DDV should use the network
  
Returns:  TRUE if yes

*****************************************************************************/
static Boolean DDV_UseNetwork(void)
{
Char str[64];

    if (GetAppParam
        ("DDV", "SETTINGS", "NETWORKAVAILABLE", NULL, str, sizeof(str))) {
        if (StringICmp(str, "TRUE") == 0) return TRUE;
    }
    return FALSE;
}
示例#7
0
Boolean IsValidId (CharPtr idStr)
{
  Int4    position;
  Boolean letterFound = FALSE;
  Int2    charType;

  /* Check for illegal characters */

  for (position = 0; idStr[position] != '\0'; position++)
    {
      charType = IsValidIdChar(idStr[position]);
      switch (charType)
	{
	case ID_GOOD_CHAR_LETTER :
	  letterFound = TRUE;
	  break;
	case ID_GOOD_CHAR_NUMBER :
	case ID_GOOD_CHAR_OTHER :
	  break;
	default:
	  return FALSE;
	}
    }

  if (!letterFound)
    return FALSE;

  /* Check to see if ID matches a reserved word */

  if (StringICmp (idStr,"MATRIX") == 0)
    return FALSE;
  else if (StringICmp (idStr,"BEGIN") == 0)
    return FALSE;
  else if (StringICmp (idStr, "END") == 0)
    return FALSE;

  /* If we passed all tests, mark */
  /* it as a valid ID.            */

  return TRUE;
}
示例#8
0
文件: taxcs.c 项目: hsptools/hsp-wrap
Int4 tax_getClass_cde(CharPtr class_txt)
{
    Int2 i;

    if(class_txt == NULL) return -1;

    for(i= 0; i < class_alloced; i++) {
	if(StringICmp(name_class[i].class_txt, class_txt) == 0) return (Int4)i;
    }

    return -1;
}
示例#9
0
文件: taxcs.c 项目: hsptools/hsp-wrap
Int2 tax_getRankId(CharPtr rank_txt)
{
    Int2 i;

    if(rank_txt == NULL) return -d_rank;

    for(i= 0; i < rank_alloced; i++) {
	if(StringICmp(tax_rank[i].rank_txt, rank_txt) == 0) return i - d_rank;
    }

    return -d_rank;
}
示例#10
0
文件: taxcs.c 项目: hsptools/hsp-wrap
Int2 tax_getGCId(CharPtr gc_txt)
{
    Int2 i;

    if(gc_txt == NULL) return -1;

    for(i= 0; i < gc_alloced; i++) {
	if(StringICmp(tax_gc[i].gc_name, gc_txt) == 0) return i;
    }

    return -1;
}
示例#11
0
static void DoImpCDSandTrna (SeqFeatPtr sfp, Pointer userdata)

{
  Uint1           from = 0;
  ImpFeatPtr      ifp;
  RnaRefPtr       rrp;
  ScanDataPtr     sdp;
  SeqMapTablePtr  smtp;
  tRNAPtr         trp;

  if (sfp->data.choice == SEQFEAT_IMP) {
    ifp = (ImpFeatPtr) sfp->data.value.ptrvalue;
    if (ifp == NULL) return;
    if (StringICmp (ifp->key, "CDS") != 0) return;

    sdp = (ScanDataPtr) userdata;
    (sdp->impCdsCount)++;
    /*
    PrintFeatureMessage (sfp, sdp, "IC", NULL);
    */
  } else if (sfp->data.choice == SEQFEAT_RNA) {
    rrp = (RnaRefPtr) sfp->data.value.ptrvalue;
    if (rrp != NULL && rrp->ext.choice == 2) {
      trp = (tRNAPtr) rrp->ext.value.ptrvalue;
      if (trp == NULL) return;
      if (trp->aatype == 2) return;
      switch (trp->aatype) {
        case 0 :
          from = 0;
          break;
        case 1 :
          from = Seq_code_iupacaa;
          break;
        case 2 :
          from = Seq_code_ncbieaa;
          break;
        case 3 :
          from = Seq_code_ncbi8aa;
          break;
        case 4 :
          from = Seq_code_ncbistdaa;
          break;
        default:
          break;
      }
      smtp = SeqMapTableFind (Seq_code_ncbieaa, from);
      if (smtp == NULL) {
        sdp = (ScanDataPtr) userdata;
        PrintFeatureMessage (sfp, sdp, "BT", NULL);
      }
    }
  }
}
示例#12
0
/****************************************************************************
*  GBQualSplit:
*  -- return index of the GBQual_names_split_ignore array if it is a valid
*     qualifier (ignore case), qual; otherwise return (-1) 
*                                                                   10-12-93
*****************************************************************************/
NLM_EXTERN Int2 GBQualSplit(CharPtr qual)
{
   Int2  i;

   for (i = 0; i < ParFlat_SPLIT_IGNORE && qual != NULL; i++) {
       if (StringICmp(qual, GBQual_names_split_ignore[i]) == 0)
          return (i);
   }

   return (-1);

} /* GBQualSplit */
示例#13
0
NLM_EXTERN Boolean check_syn(ValNodePtr syn, CharPtr symbol)
{

	if(syn == NULL)
	   return FALSE;

	while(syn){
	  if(StringICmp(syn->data.ptrvalue, symbol)==0)
	    return TRUE;
	  syn = syn->next;
	}

	return FALSE;

}
示例#14
0
/*returns 1 if string is equivalent to TRUE
  returns 0 if string is equivalent to FALSE
  returns -1 if string is equivalent to neither*/
Int2 LIBCALL Misc_IswwStringTrueOrFalse(CharPtr string)
{
	Int2 i=0;
	CharPtr yes[]= {"y", "yes", "t", "true", "affirmative", NULL};
	CharPtr no[] = {"n", "no", "f", "false", "negative", NULL};

	if(string==NULL)
		return(-1);

	/*check this against the array*/
	while(yes[i] != NULL) {
		if(StringICmp(yes[i], string) == 0)
			return 1;
		i++;
	}
	i=0;
	while(no[i] != NULL) {
		if(StringICmp(no[i], string) == 0)
			return 0;
		i++;
	}
	/*nothing found from yes,no lists*/
	return (-1);
}
示例#15
0
static Int4 get_tax_id(ValNodePtr dbnode)
{
  DbtagPtr dbtag;
  ObjectIdPtr object_id;

  while(dbnode != NULL) {
      dbtag= dbnode->data.ptrvalue;
      if(StringICmp(dbtag->db, "taxon") == 0) {
	  object_id= dbtag->tag;
	  return object_id->id;
      }
      dbnode= dbnode->next;
  }
  return 0;
}
示例#16
0
static void DoPseudoCDS (SeqFeatPtr sfp, Pointer userdata)

{
  GBQualPtr    gbq;
  SeqFeatPtr   gene;
  GeneRefPtr   grp;
  Boolean      pseudo = FALSE;
  ScanDataPtr  sdp;

  if (sfp->data.choice != SEQFEAT_CDREGION) return;

  if (sfp->pseudo) {
    pseudo = TRUE;
  }
  grp = SeqMgrGetGeneXref (sfp);
  if (grp == NULL) {
    gene = SeqMgrGetOverlappingGene (sfp->location, NULL);
    if (gene != NULL) {
      if (gene->pseudo) {
        pseudo = TRUE;
      }
    }
  }
  if (grp != NULL && grp->pseudo) {
    pseudo = TRUE;
  }

  if (! pseudo) return;

  sdp = (ScanDataPtr) userdata;

  if (sfp->product != NULL) {
    PrintFeatureMessage (sfp, sdp, "PC", NULL);
  }

  for (gbq = sfp->qual; gbq != NULL; gbq = gbq->next) {
    if (StringICmp (gbq->qual, "translation") == 0) {
      PrintFeatureMessage (sfp, sdp, "TR", NULL);
      return;
    }
  }
}
示例#17
0
static void LookForBulk (SeqDescrPtr vnp, Pointer userdata)

{
  BioSourcePtr  biop;
  MolInfoPtr    mip;
  OrgNamePtr    onp;
  OrgRefPtr     orp;
  ScanDataPtr   sdp;

  if (vnp->choice == Seq_descr_molinfo) {
    mip = (MolInfoPtr) vnp->data.ptrvalue;
    if (mip == NULL) return;
    if (mip->tech == MI_TECH_est ||
        mip->tech == MI_TECH_sts ||
        mip->tech == MI_TECH_survey ||
        mip->tech == MI_TECH_htgs_1 ||
        mip->tech == MI_TECH_htgs_2 ||
        mip->tech == MI_TECH_htgs_3 ||
        mip->tech == MI_TECH_htgs_0) {
      sdp = (ScanDataPtr) userdata;
      sdp->bulk = TRUE;
    }
  }

  if (vnp->choice == Seq_descr_source) {
    biop = (BioSourcePtr) vnp->data.ptrvalue;
    if (biop == NULL) return;
    orp = biop->org;
    if (orp == NULL) return;
    onp = orp->orgname;
    if (onp == NULL) return;
    if (StringICmp (onp->div, "SYN") == 0) {
      sdp = (ScanDataPtr) userdata;
      sdp->bulk = TRUE;
    }
  }
}
示例#18
0
static void AcceptNetConfigForm (ButtoN b)

{
  VoidProc      accepted;
  NetConfigPtr  ncp;
  Char          str [256];
  VoidProc      turnedOff;
  Int2          val;

  ncp = (NetConfigPtr) GetObjectExtra (b);
  if (ncp == NULL) return;

  val = GetValue (ncp->srvConnMode);
  if (val == 1) {
    turnedOff = ncp->turnedOff;
    Remove (ncp->form);
    if (turnedOff != NULL) {
      turnedOff ();
    }
    Update ();
    return;
  } else if (val == 3) {
    SetAppParam ("NCBI", "CONN", "FIREWALL", "TRUE");
    GetTitle (ncp->proxyHost, str, sizeof (str));
    if (! StringHasNoText (str)) {
      SetAppParam ("NCBI", "CONN", "HTTP_PROXY_HOST", str);
      GetTitle (ncp->proxyPort, str, sizeof (str));
      if (StringICmp (str, "80") == 0) {
        str [0] = '\0';
      }
      if (! StringHasNoText (str)) {
        SetAppParam ("NCBI", "CONN", "HTTP_PROXY_PORT", str);
      } else {
        SetAppParam ("NCBI", "CONN", "HTTP_PROXY_PORT", NULL);
      }
    } else {
      SetAppParam ("NCBI", "CONN", "HTTP_PROXY_HOST", NULL);
      SetAppParam ("NCBI", "CONN", "HTTP_PROXY_PORT", NULL);
    }
    GetTitle (ncp->firewallProxy, str, sizeof (str));
    if (! StringHasNoText (str)) {
      SetAppParam ("NCBI", "CONN", "PROXY_HOST", str);
    } else {
      SetAppParam ("NCBI", "CONN", "PROXY_HOST", NULL);
    }
  } else {
    SetAppParam ("NCBI", "CONN", "FIREWALL", NULL);
    SetAppParam ("NCBI", "CONN", "HTTP_PROXY_HOST", NULL);
    SetAppParam ("NCBI", "CONN", "HTTP_PROXY_PORT", NULL);
    SetAppParam ("NCBI", "CONN", "PROXY_HOST", NULL);
  }

  if (GetStatus (ncp->dnsAvailable)) {
    SetAppParam ("NCBI", "CONN", "HOST", NULL);
  } else {
    SetAppParam ("NCBI", "CONN", "HOST", "130.14.29.110");
  }

  switch (GetValue (ncp->timeOut)) {
    case 1 :
      SetAppParam ("NCBI", "CONN", "TIMEOUT", "10");
      break;
    case 3 :
      SetAppParam ("NCBI", "CONN", "TIMEOUT", "60");
      break;
    case 4 :
      SetAppParam ("NCBI", "CONN", "TIMEOUT", "300");
      break;
    default :
      SetAppParam ("NCBI", "CONN", "TIMEOUT", NULL);
      break;
  }

  /*
  if (GetAppParam ("NCBI", "NET_SERV", "SRV_ENGINE_PORT", NULL, str, sizeof (str))) {
    if (StringICmp (str, "80") == 0) {
      SetAppParam ("NCBI", "NET_SERV", "SRV_ENGINE_PORT", NULL);
    }
  }

  if (GetAppParam ("NCBI", "NET_SERV", "SRV_ENGINE_URL", NULL, str, sizeof (str))) {
    if (StringICmp (str, "/Service/nph-dispd.cgi") == 0) {
      SetAppParam ("NCBI", "NET_SERV", "SRV_ENGINE_URL", NULL);
    }
  }
  */

  if (NoEntryExists ("CONN", "FIREWALL") &&
      NoEntryExists ("CONN", "TIMEOUT") &&
      NoEntryExists ("CONN", "PROXY_HOST") &&
      NoEntryExists ("CONN", "HOST") &&
      NoEntryExists ("CONN", "HTTP_PROXY_HOST") &&
      NoEntryExists ("CONN", "HTTP_PROXY_PORT")) {
    SetAppParam ("NCBI", "CONN", NULL, NULL);
  }

  accepted = ncp->accepted;
  Remove (ncp->form);
  if (accepted != NULL) {
    accepted ();
  }
  Update ();
}
示例#19
0
/*****************************************************************************
*
*   Int2 PubMatch(a, b)
*   	returns 0 if can determine pubs POINT TO SAME CITATION (not that
*   		they are identical)
*   	returns positive or negative number if not the same,
*   		for arbitrary ordering
*       -2, +2  = different types
*       -1, +1  = different values, same type
*
*****************************************************************************/
NLM_EXTERN Int2 LIBCALL PubMatch (ValNodePtr a, ValNodePtr b)
{
	ValNode vn1;
	ValNodePtr ap, bp, tp, vnp[2];
	Int2 retval, i;
	Int4 muid[2];
	Int4 pmid[2];
	CitArtPtr cap[2];
	CharPtr country[2],   /* for patents */
		number[2],
		app_number[2];

	if (a == NULL) return 2;
	if (b == NULL) return -2;

	                        /* default return for different pub types */
	if (a->choice > b->choice)
		retval = 2;
	else
		retval = -2;

							/* if either is a Pub-equiv, treat as both */
	if ((a->choice == PUB_Equiv) || (b->choice == PUB_Equiv))
	{
		ap = (ValNodePtr)(a->data.ptrvalue);
		bp = (ValNodePtr)(b->data.ptrvalue);
		tp = NULL;
		if (a->choice != PUB_Equiv)
		{
			tp = a;
			ap = NULL;
		}
		else if (b->choice != PUB_Equiv)
		{
			tp = b;
			bp = NULL;
		}
		if (tp != NULL)   /* convert one */
		{
			MemCopy((Pointer)&vn1, tp, sizeof(ValNode));  /* make a copy of the Pub */
			vn1.next = NULL;                   /* remove from any chain */
			tp = (ValNodePtr)&vn1;
			if (ap == NULL)
				ap = tp;
			else
				bp = tp;
		}
		return PubEquivMatch(ap, bp);   /* use the PubEquivMatch() */
	}
                                   /** here we are just matching two pubs */
							/* handle Medline/CitArt combinations */
	                        /* handle CitPat, IdPat combinations */
	vnp[0] = a;
	vnp[1] = b;
	for (i = 0; i < 2; i++)
	{
		cap[i] = NULL;
		muid[i] = 0;
		pmid[i] = 0;
		country[i] = NULL;
		number[i] = NULL;
		app_number[i] = NULL;

		switch (vnp[i]->choice)
		{
			case PUB_Medline:
				muid[i] = ((MedlineEntryPtr)(vnp[i]->data.ptrvalue))->uid;
				cap[i] = ((MedlineEntryPtr)(vnp[i]->data.ptrvalue))->cit;
				pmid[i] = ((MedlineEntryPtr)(vnp[i]->data.ptrvalue))->pmid;
				break;
			case PUB_Muid:
				muid[i] = vnp[i]->data.intvalue;
				break;
			case PUB_Article:
				cap[i] = (CitArtPtr)(vnp[i]->data.ptrvalue);
				break;
			case PUB_Patent:
				country[i] = ((CitPatPtr)(vnp[i]->data.ptrvalue))->country;
				number[i] = ((CitPatPtr)(vnp[i]->data.ptrvalue))->number;
				app_number[i] = ((CitPatPtr)(vnp[i]->data.ptrvalue))->app_number;
				break;
			case PUB_Pat_id:
				country[i] = ((IdPatPtr)(vnp[i]->data.ptrvalue))->country;
				number[i] = ((IdPatPtr)(vnp[i]->data.ptrvalue))->number;
				app_number[i] = ((IdPatPtr)(vnp[i]->data.ptrvalue))->app_number;
				break;
			case PUB_PMid:
				pmid[i] = vnp[i]->data.intvalue;
				break;
		}
	}

	if ((pmid[0] > 0) && (pmid[1] > 0))   /* got 2 muids */
	{
		if (pmid[0] == pmid[1])
			return (Int2)0;
		else if (pmid[0] < pmid[1])
			return (Int2)-1;
		else
			return (Int2) 1;
	}

	if ((muid[0] > 0) && (muid[1] > 0))   /* got 2 muids */
	{
		if (muid[0] == muid[1])
			return (Int2)0;
		else if (muid[0] < muid[1])
			return (Int2)-1;
		else
			return (Int2) 1;
	}

	if ((cap[0] != NULL) && (cap[1] != NULL))  /* 2 articles */
	{
		return CitArtMatch(cap[0], cap[1]);
	}

	if ((country[0] != NULL) && (country[1] != NULL))  /* 2 patents */
	{
		retval = (Int2)StringICmp(country[0], country[1]);
		if (retval < 0)   /* different countries */
			return (Int2) -1;
		else if (retval > 0)
			return (Int2) 1;

		if ((number[0] != NULL) && (number[1] != NULL))
		{
			retval = (Int2)StringICmp(number[0], number[1]);
			if (retval < 0)   /* different number */
				return (Int2) -1;
			else if (retval > 0)
				return (Int2) 1;
			else
				return retval;
		}
		if ((app_number[0] != NULL) && (app_number[1] != NULL))
		{
			retval = (Int2)StringICmp(app_number[0], app_number[1]);
			if (retval < 0)   /* different appl number */
				return (Int2) -1;
			else if (retval > 0)
				return (Int2) 1;
			else
				return retval;
		}
		if (number[0] != NULL)
			return (Int2) -1;
		return (Int2) 1;
	}

	if (a->choice != b->choice)    /* all others must be same type */
	{
		return retval;
	}
							/* compare other types */
	switch (a->choice)
	{
		case PUB_Gen:        /* generic */
			return CitGenMatch((CitGenPtr)a->data.ptrvalue,
					(CitGenPtr)b->data.ptrvalue, TRUE);
		case PUB_Sub:        /* Submission */
		 	return CitSubMatch((CitSubPtr)a->data.ptrvalue,
					(CitSubPtr)b->data.ptrvalue);
		case PUB_Journal:
			return CitJourMatch((CitJourPtr)a->data.ptrvalue,
					(CitJourPtr)b->data.ptrvalue);
		case PUB_Book:
		case PUB_Proc:
		case PUB_Man:
			return CitBookMatch((CitBookPtr)a->data.ptrvalue,
					(CitBookPtr)b->data.ptrvalue);
	}

	return retval;
}
示例#20
0
Uint2 CheckTaxId(OrgRefPtr orp, CharPtr ** msg_out)
{
    Int4 tax_id;
    Taxon1DataPtr tdp;
    CharPtr* msg_arr= NULL;
    CharPtr msg;
    Uint2 n= 0;

    if(orp == NULL) {
	msg= StringSave("WARNING\t empty OrgRef");
	msg_arr= MemNew(sizeof(CharPtr));
	*msg_arr= msg;
	*msg_out= msg_arr;
	return 1;
    }
	
    tax_id= get_tax_id(orp->db);

    if(tax_id > 0) {
	/* check this tax_id */
	tdp= tax1_getbyid(tax_id);
	if(tdp == NULL) {
	    /* taxonomy id was killed */
	    msg= MemNew(80);
	    sprintf(msg, 
		    "ERROR\t taxid %d is killed in taxonomy database but exists in entry",
		    tax_id);
	    msg_arr= MemNew(sizeof(CharPtr));
	    *msg_arr= msg;
	    *msg_out= msg_arr;
	    return 1;
	}

	/* check that tax_id still correct */
	if(orp->taxname == NULL) {
	    msg= StringSave("WARNING\t empty taxname in OrgRef");
	    msg_arr= MemNew(sizeof(CharPtr));
	    *msg_arr= msg;
	    *msg_out= msg_arr;
	    return 1;
	}

	if(StringICmp(orp->taxname, tdp->org->taxname) != 0) {
	    msg= MemNew(256);
	    sprintf(msg,
    "WARNING: taxname in OrgRef <%s> is differ from the name in taxonomy <%s> tax_id=%d",
		    orp->taxname, tdp->org->taxname, tax_id);
	    msg_arr= MemNew(sizeof(CharPtr));
	    *msg_arr= msg;
	    *msg_out= msg_arr;
	    return 1;
	}
	return 0;
    }	    
    
    /* we have no tax_id */
    msg= StringSave("WARNING\t no taxid in OrgRef");
    *msg_out= msg_arr= MemNew(3*sizeof(CharPtr));
    msg_arr[0]= msg;
    n= 1;
    tdp= tax1_lookup(orp, 0);
    if(tdp == NULL) {
	/* no such organism */
	msg= MemNew(256);
	sprintf(msg,"WARNING\t organism not found [scientific name <%s> common name <%s>]",
		(orp->taxname == NULL)? "" : orp->taxname,
		(orp->common == NULL)? "" : orp->common);
	msg_arr[1]= msg;
	return 2;
    }

    tax_id= get_tax_id(tdp->org->db);
    msg= MemNew(80);
    sprintf(msg, "INFO\t OrgRef should be mapped to <%s> tax_id=%d",
	    tdp->org->taxname, tax_id);
    msg_arr[1]= msg;
    n= 2;

    if(orp->taxname == NULL) {
	msg= MemNew(256);
	sprintf(msg,"WARNING\t taxname <%s> does not exist in original OrgRef",
		tdp->org->taxname);
	msg_arr[2]= msg;
	n= 3;
    }
    else if(StringICmp(orp->taxname, tdp->org->taxname) != 0) {
	msg= MemNew(256);
	sprintf(msg,
		"WARNING: taxname in OrgRef <%s> is differ from the name in taxonomy <%s> tax_id=%d",
		    orp->taxname, tdp->org->taxname, tax_id);
	msg_arr[2]= msg;
	n= 3;
    }
	
    return n;
}
示例#21
0
extern void ShowNetConfigForm (WndActnProc activate, FormMessageFunc messages,
                               VoidProc accepted, VoidProc cancelled,
                               VoidProc turnedOff, Boolean netCurrentlyOn)
{
  ButtoN        b;
  GrouP         c;
  GrouP         g;
  GrouP         h;
  GrouP         j;
  Int2          len;
  NetConfigPtr  ncp;
  PrompT        ppt0, ppt1;
  ButtoN        rb;
  Char          str [256];
  WindoW        w;
  GrouP         x;
  GrouP         z;

  w = NULL;
  ncp = (NetConfigPtr) MemNew (sizeof (NetConfigData));
  if (ncp != NULL) {

    w = FixedWindow (-50, -33, -10, -10, "Network Configuration",
                     StdSendCloseWindowMessageProc);
    SetObjectExtra (w, ncp, StdCleanupFormProc);
    ncp->form = (ForM) w;
    ncp->formmessage = ConfigMessageProc;

    ncp->appmessage = messages;
    ncp->activate = activate;
    SetActivate (w, ConfigFormActivate);

    ncp->accepted = accepted;
    ncp->cancelled = cancelled;
    ncp->turnedOff = turnedOff;

    h = HiddenGroup (w, -1, 0, NULL);
    SetGroupSpacing (h, 5, 10);

    j = HiddenGroup (h, 2, 0, NULL);
    ppt0 = StaticPrompt (j, "Connection", 0, 0, programFont, 'l');
    ncp->srvConnMode = HiddenGroup (j, 4, 0, ChangeConnection);
    SetObjectExtra (ncp->srvConnMode, ncp, NULL);
    rb = RadioButton (ncp->srvConnMode, "None");
    RadioButton (ncp->srvConnMode, "Normal");
    RadioButton (ncp->srvConnMode, "Firewall");
    /* RadioButton (ncp->srvConnMode, "Stateless"); */
    SetValue (ncp->srvConnMode, 2);
    if (turnedOff == NULL) {
      Disable (rb);
    }
    AlignObjects (ALIGN_MIDDLE, (HANDLE) ppt0, (HANDLE) ncp->srvConnMode, NULL);

    ncp->netGroup = HiddenGroup (h, -1, 0, NULL);
    SetGroupSpacing (ncp->netGroup, 5, 10);
  
    SelectFont (programFont);
    len = StringWidth ("HTTP Proxy Server ") + 2;
    SelectFont (systemFont);

    z = HiddenGroup (ncp->netGroup, -2, 0, NULL);
    StaticPrompt (z, "HTTP Proxy Server", len, dialogTextHeight, programFont, 'l');
    ncp->proxyHost = DialogText (z, "", 12, ChangeProxy);
    SetObjectExtra (ncp->proxyHost, ncp, NULL);
    /*
    StaticPrompt (z, "", 0, 0, programFont, 'l');
    StaticPrompt (z, "", 0, 0, programFont, 'l');
    */
    ppt0 = StaticPrompt (z, "HTTP Proxy Port ", len, dialogTextHeight, programFont, 'l');
    ncp->proxyPort = DialogText (z, "", 3, NULL);
    x = MultiLinePrompt (z, "Non-transparent Proxy Server", len, programFont);
    ncp->firewallProxy = DialogText (z, "", 12, NULL);
    AlignObjects (ALIGN_MIDDLE, (HANDLE) x, (HANDLE) ncp->firewallProxy, NULL);
    /*
    AlignObjects (ALIGN_MIDDLE, (HANDLE) ppt0, (HANDLE) ncp->proxyPort,
                  (HANDLE) ncp->firewallProxy, NULL);
    */
    AlignObjects (ALIGN_RIGHT, (HANDLE) ncp->proxyHost, (HANDLE) ncp->firewallProxy, NULL);
    AlignObjects (ALIGN_LEFT, (HANDLE) ncp->proxyHost, (HANDLE) ncp->firewallProxy, NULL);

    g = HiddenGroup (ncp->netGroup, 5, 0, NULL);
    /*
    ppt0 = StaticPrompt (g, "Domain name server", 0, 0, programFont, 'l');
    ncp->dnsAvailable = CheckBox (g, "Available", NULL);
    */
    ncp->dnsAvailable = CheckBox (g, "Domain Name Server", NULL);
    SetStatus (ncp->dnsAvailable, TRUE);
    /* StaticPrompt (g, " ", 0, 0, programFont, 'l'); */
    ppt1 = StaticPrompt (g, "Timeout", 0, popupMenuHeight, programFont, 'l');
    ncp->timeOut = PopupList (g, TRUE, NULL);
    PopupItem (ncp->timeOut, "10 seconds");
    PopupItem (ncp->timeOut, "30 seconds");
    PopupItem (ncp->timeOut, "60 seconds");
    PopupItem (ncp->timeOut, " 5 minutes");
    SetValue (ncp->timeOut, 2);
    AlignObjects (ALIGN_MIDDLE, /* (HANDLE) ppt0, */ (HANDLE) ncp->dnsAvailable,
                  (HANDLE) ppt1, (HANDLE) ncp->timeOut, NULL);

    c = HiddenGroup (w, 4, 0, NULL);
    SetGroupSpacing (c, 10, 2);
    ncp->accept = PushButton (c, "Accept", AcceptNetConfigForm);
    SetObjectExtra (ncp->accept, ncp, NULL);
    b = PushButton (c, "Cancel", StdSendCancelButtonMessageProc);
    SetObjectExtra (b, ncp, NULL);

    /*
    AlignObjects (ALIGN_CENTER, (HANDLE) h, (HANDLE) c, NULL);
    */
    AlignObjects (ALIGN_CENTER, (HANDLE) j, (HANDLE) z, (HANDLE) g, (HANDLE) c, NULL);

    RealizeWindow (w);

    if (! netCurrentlyOn) {
      SafeSetValue (ncp->srvConnMode, 1);
      Hide (ncp->netGroup);
    } else if (GetAppParam ("NCBI", "CONN", "FIREWALL", NULL, str, sizeof (str))) {
      if (StringICmp (str, "TRUE") == 0) {
        SafeSetValue (ncp->srvConnMode, 3);
      }
    }
    if (GetAppParam ("NCBI", "CONN", "HTTP_PROXY_HOST", NULL, str, sizeof (str))) {
      if (! StringHasNoText (str)) {
        SafeSetTitle (ncp->proxyHost, str);
        if (GetValue (ncp->srvConnMode) == 2) {
          SafeSetValue (ncp->srvConnMode, 3);
        }
      }
    }
    if (GetAppParam ("NCBI", "CONN", "HTTP_PROXY_PORT", NULL, str, sizeof (str))) {
      if (! StringHasNoText (str)) {
        SafeSetTitle (ncp->proxyPort, str);
      }
    }
    if (GetAppParam ("NCBI", "CONN", "PROXY_HOST", NULL, str, sizeof (str))) {
      if (! StringHasNoText (str)) {
        SafeSetTitle (ncp->firewallProxy, str);
      }
    }
    if (GetAppParam ("NCBI", "CONN", "HOST", NULL, str, sizeof (str))) {
      if (StringICmp (str, "130.14.29.110") == 0) {
        SafeSetStatus (ncp->dnsAvailable, FALSE);
      }
    }
    if (GetAppParam ("NCBI", "CONN", "TIMEOUT", "30", str, sizeof (str))) {
      if (StringICmp (str, "10") == 0) {
        SafeSetValue (ncp->timeOut, 1);
      } else if (StringICmp (str, "60") == 0) {
        SafeSetValue (ncp->timeOut, 3);
      } else if (StringICmp (str, "300") == 0) {
        SafeSetValue (ncp->timeOut, 4);
      } else {
        SafeSetValue (ncp->timeOut, 2);
      }
    }

    ChangeConfigControls (ncp);

    Show (w);
    Select (w);
    Select (ncp->proxyHost);
  }
}
示例#22
0
SeqEntryPtr LIBCALL MakeBioseqs(BiostrucPtr bsp, BiostrucResidueGraphSetPtr stdDictionary)
{
  ValNodePtr vnp, seq_set, hetval, pvnThePoints;
  BiostrucHistoryPtr bhp;
  BiostrucSourcePtr bssp;
  BiostrucGraphPtr bsgp;
  BiostrucModelPtr bsmp;
  BiostrucFeatureSetPtr bsfsp;
  BiostrucFeaturePtr bsfp;
  ChemGraphPntrsPtr cgpp;
  ResiduePtr rs;
  ResidueGraphPtr rgp;
  ResiduePntrsPtr rpp;
  ResidueIntervalPntrPtr ripp;
  ResidueExplicitPntrsPtr rpp1=NULL, rpp2=NULL;
  MoleculeGraphPtr bp, het, currenthet, currentbp, mgp;
  InterResidueBondPtr currentabp, abp;
  DbtagPtr dtp;
  SeqEntryPtr pdb_entry;
  BioseqSetPtr biossp;
  BioseqPtr bioseqs[MAXNUM], current_bioseq;
  Int4 DomainNum, molId1, resId1, atmId1, molId2, resId2, atmId2;
  Int4 nbp, nhet, num_chain, index = 0, chnidx, bpchnidx, bpresidx, hetidx, rescount, bioseq_idx;
  Int4 ssresidx1, ssresidx2, ssmolidx1, ssmolidx2;
  CharPtr feature_name, rname;
  Boolean interchain, bonds, found1, found2;
  SeqAnnotPtr sap = NULL;
  SeqIdPtr sip;

  if (!bsp)
  {
    return NULL;
  }
      
  vnp = ValNodeFindNext(bsp->descr, NULL, BiostrucDescr_history);

  if (vnp)
  { 
    bhp = (BiostrucHistoryPtr) vnp->data.ptrvalue; 
    bssp = bhp->data_source;
  }

  bsgp = bsp->chemical_graph; 
  bsmp = bsp->model;
    
  nbp = NumberOfBioChains(bsgp->molecule_graphs);
   
  bp =  MakeBioGraphPtr(bsgp->molecule_graphs);

  nhet = NumberOfHetChains(bsgp->molecule_graphs, bp);
  
  het = MakeHetGraphPtr(bsgp->molecule_graphs, bp);
   
  pdb_entry = CreateSeqEntry(bssp, bsgp, bsmp, bsp->descr, nbp);
   
  if (IS_Bioseq(pdb_entry))
  {
    vnp = ValNodeFindNext(pdb_entry, NULL, 1);
    bioseqs[index] = (BioseqPtr) vnp->data.ptrvalue;
  }
  else
  {
    vnp = ValNodeFindNext(pdb_entry, NULL, 2);
    biossp = (BioseqSetPtr) vnp->data.ptrvalue;
    seq_set = biossp->seq_set;
      
    for (num_chain = 0; num_chain < nbp, seq_set; seq_set = seq_set->next, num_chain++, index++)
      bioseqs[index] = (BioseqPtr) seq_set->data.ptrvalue;
  }  
  
  dtp = (DbtagPtr)bssp->database_entry_id->data.ptrvalue;
   
  for (index = 0, currentbp = bp; index < nbp, currentbp != NULL; currentbp = currentbp->next, index++)
  {
     current_bioseq = bioseqs[index];
     if (currentbp->seq_id->choice == '\f')
     {
       current_bioseq->id = MakePDBId(bssp, currentbp, dtp);   
       sip = ValNodeNew(NULL);
       sip->choice = SEQID_GI;
       sip->data.intvalue = currentbp->seq_id->data.intvalue;
       current_bioseq->id->next = sip;
     }
     else if (currentbp->seq_id->choice == SEQID_LOCAL)
       current_bioseq->id = MakeLocalID(-99999, currentbp, dtp);
     current_bioseq->descr = MakeBioseqDescr(currentbp, current_bioseq->descr);
     current_bioseq->mol = MakeBioseqMol(currentbp);
     current_bioseq->length = CountNumOfResidues(currentbp);
     
     if (current_bioseq->mol == Seq_mol_aa)
	current_bioseq->seq_data_type = Seq_code_iupacaa;
     else
        current_bioseq->seq_data_type = Seq_code_iupacna;
     
     current_bioseq->seq_data = AddSeqData(currentbp, current_bioseq->mol, current_bioseq->length, bsgp, stdDictionary);
     current_bioseq->annot = AddNstdSeqAnnot(currentbp, current_bioseq->id, bsgp);
   }  
   /* Add information about Secondary Structure and Domains */
  for (bsfsp = bsp->features, DomainNum = 0; bsfsp; bsfsp = bsfsp->next)
  {
    if (vnp = ValNodeFindNext(bsfsp->descr, NULL, BiostrucFeatureSetDescr_name))
       feature_name = vnp->data.ptrvalue;
     
    if ((!StringICmp("NCBI assigned secondary structure", feature_name)) ||
       (!StringICmp("NCBI Domains", feature_name)))
    {
      for (bsfp = bsfsp->features; bsfp; bsfp = bsfp->next)
      {
        cgpp = (ChemGraphPntrsPtr)bsfp->Location_location->data.ptrvalue;
        rpp = (ResiduePntrsPtr)cgpp->data.ptrvalue;
        ripp = (ResidueIntervalPntrPtr)rpp->data.ptrvalue;
        chnidx = findChnidx(ripp->molecule_id, nbp, bp);
        current_bioseq = bioseqs[chnidx-1];
        
        if (!StringICmp("NCBI Domains", feature_name)) DomainNum++;
        
        if (current_bioseq->annot)
          current_bioseq->annot = AddSecDomToSeqAnnot(bsfp, feature_name, current_bioseq->annot, current_bioseq->id, DomainNum);
        else
          current_bioseq->annot = AddSecDomToSeqAnnot(bsfp, feature_name, NULL, current_bioseq->id, DomainNum); 
      }
    }
  }
  for (index = 0, currenthet = het; index < nhet, currenthet; currenthet = currenthet->next, index++)
  {
    hetval = MakeHetValNode(currenthet, stdDictionary, bsgp->residue_graphs);
    bioseq_idx = 0;
    interchain = FALSE;

    for (abp = bsgp->inter_molecule_bonds, bonds = FALSE, rescount = 0; abp; abp = abp->next)
    {
      molId1 = abp->atom_id_1->molecule_id;
      molId2 = abp->atom_id_2->molecule_id;
      resId1 = abp->atom_id_1->residue_id;
      resId2 = abp->atom_id_2->residue_id;
      atmId1 = abp->atom_id_1->atom_id;
      atmId2 = abp->atom_id_2->atom_id;
      
      if (isBiopoly(molId1, bp) && isHet(molId2, het))
      {
        bpchnidx = molId1 - 1;
	bpresidx = resId1 - 1;
	hetidx = getHetIdx(molId2, het);
        bonds = TRUE;
      }
      else if (isBiopoly(molId2, bp) && isHet(molId1, het))
      {
        bpchnidx = molId2 - 1;
	bpresidx = resId2 - 1;
	hetidx = getHetIdx(molId1, het);
        bonds = TRUE;
      }
      
      if (bonds)
      {
        if (hetidx == index)
        {
          if (!rescount) pvnThePoints = NULL;
          ValNodeAddInt(&pvnThePoints, 0, bpresidx);
          rescount++;
          if (bioseq_idx >= 0)
          {
             if (bioseq_idx != bpchnidx) interchain = TRUE;
          }
          bioseq_idx = bpchnidx;
        }
      }
    }
    
    if (rescount)
    {  
      if (!interchain)
      {
        current_bioseq = bioseqs[bioseq_idx];
        if (current_bioseq->annot)
          current_bioseq->annot = AddHetToSeqAnnot(current_bioseq->annot, current_bioseq->id, hetval, pvnThePoints, rescount);
        else
          current_bioseq->annot = AddHetToSeqAnnot(NULL, current_bioseq->id, hetval, pvnThePoints, rescount); 
      }
      if (interchain)
      {
        if (IS_Bioseq(pdb_entry))
	  sap = ((BioseqPtr)(pdb_entry->data.ptrvalue))->annot;
	else
          sap = ((BioseqSetPtr)(pdb_entry->data.ptrvalue))->annot;
	if (sap == NULL)
	{
	  sap = SeqAnnotNew();
	  sap->type = 1;
	  if (IS_Bioseq(pdb_entry))
	    ((BioseqPtr)(pdb_entry->data.ptrvalue))->annot = sap;
          else
	    ((BioseqSetPtr)(pdb_entry->data.ptrvalue))->annot = sap;
         }
         sap = AddHetToSeqAnnot(sap, bioseqs[bioseq_idx]->id, hetval, pvnThePoints, rescount);
      }
    }
    else
    {
      current_bioseq = bioseqs[bioseq_idx];
      vnp = current_bioseq->descr;
      if (vnp != NULL)
      { 
        while (vnp->next != NULL) vnp = vnp->next;
	vnp->next = hetval;
      }
      else current_bioseq->descr = hetval;
    }
  }      
  
  mgp = bsgp->molecule_graphs;
  abp = bsgp->inter_molecule_bonds;
  
  while(1)
  {
    if (mgp != NULL)
    { 
      currentabp = mgp->inter_residue_bonds;
      mgp = mgp->next;
    }
    
    while (currentabp != NULL)
    {
      molId1 = currentabp->atom_id_1->molecule_id;
      molId2 = currentabp->atom_id_2->molecule_id;
      resId1 = currentabp->atom_id_1->residue_id;
      resId2 = currentabp->atom_id_2->residue_id;
      atmId1 = currentabp->atom_id_1->atom_id;
      atmId2 = currentabp->atom_id_2->atom_id;

      interchain = FALSE;
      found1 = FALSE;
      found2 = FALSE;

      if ((getAtomElementIdx(molId1, resId1, atmId1, bsgp, stdDictionary)==16) 
         && (getAtomElementIdx(molId2, resId2, atmId2, bsgp, stdDictionary)==16))
      { 
	 /* Found possible disulfide bonds. */

        if (isBiopoly(molId1, bp) && isBiopoly(molId2, bp))  
	{
	  currentbp = bp;
	  for (index=0; index<findChnidx(molId1, nbp, bp)-1; index++)
	    currentbp = currentbp->next;

          rs = currentbp->residue_sequence;

	   while (rs)
	   {
	     if (rs->id == resId1)
	     {
               rgp = getResGraph(rs->residue_graph, bsgp, stdDictionary);
	       break;
             }
           
            rs = rs->next;
           }
           
          if (vnp = ValNodeFindNext(rgp->descr, NULL, BiomolDescr_name))
             rname = vnp->data.ptrvalue;
		 
          if (!StringICmp(rname, "CYS")) found1 = TRUE;

	  currentbp = bp;
	  for (index = 0; index < findChnidx(molId2, nbp, bp)-1; index++)
	     currentbp = currentbp->next;

          rs = currentbp->residue_sequence;

	  while (rs)
	  {
	    if (rs->id == resId2)
	    {
	      rgp = getResGraph(rs->residue_graph, bsgp, stdDictionary);
	      break;
             }

	    rs = rs->next;
          }

	  if (vnp = ValNodeFindNext(rgp->descr, NULL, BiomolDescr_name))
            rname = vnp->data.ptrvalue;
 
	  if (!StringICmp(rname, "CYS")) found2 = TRUE;

	  if (found1 && found2)
	  {
            ssresidx1 = resId1 - 1;
            ssresidx2 = resId2 - 1;
            ssmolidx1 = molId1 - 1;
            ssmolidx2 = molId2 - 1;
            chnidx = findChnidx(molId1, nbp, bp);
            
            if (ssmolidx1 == ssmolidx2) 
            {
              current_bioseq = bioseqs[chnidx - 1];
              if (current_bioseq->annot)
                current_bioseq->annot = AddDisulToSeqAnnot(current_bioseq->annot, ssresidx1, ssresidx2, current_bioseq->id, current_bioseq->id);
              else
                current_bioseq->annot = AddDisulToSeqAnnot(NULL, ssresidx1, ssresidx2, current_bioseq->id, current_bioseq->id);
            }
            else
            {
              if (IS_Bioseq(pdb_entry))
	        sap = ((BioseqPtr)(pdb_entry->data.ptrvalue))->annot;
	      else
                sap = ((BioseqSetPtr)(pdb_entry->data.ptrvalue))->annot;
	      if (sap == NULL)
	      {
	        sap = SeqAnnotNew();
	        sap->type = 1;
	        if (IS_Bioseq(pdb_entry))
	          ((BioseqPtr)(pdb_entry->data.ptrvalue))->annot = sap;
                else
	          ((BioseqSetPtr)(pdb_entry->data.ptrvalue))->annot = sap;
              }
              sap = AddDisulToSeqAnnot(sap, ssresidx1, ssresidx2, bioseqs[ssmolidx1]->id, bioseqs[ssmolidx2]->id);
            }   
          }
        }
      }   
      
      currentabp = currentabp->next;
    }
    
    if ((currentabp == NULL) && (mgp == NULL) && (abp == NULL)) break;
    
    else if((currentabp == NULL) && (mgp == NULL) && (abp != NULL))
    { 
      currentabp = abp;
      abp = NULL;
    }
  }

  return pdb_entry;
}
示例#23
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;
}
示例#24
0
文件: taxcs.c 项目: hsptools/hsp-wrap
Boolean tax_matchName(CharPtr orgName, CharPtr str, Int4 mode)
{
    if(StringICmp(orgName, str) == 0) return TRUE;
    
    if(mode == TAX_RE_SEARCH) {
	/* regular expression search */
	char nBuff[256];
	Int4 k;
	rex_handler rh;
	Boolean res;

	strncpy(&nBuff[1], str, 250);
	nBuff[0]= '@';
	k= strlen(nBuff);
	nBuff[k]= '@';
	nBuff[k+1]= '\0';
	rh= rex_setExpr(nBuff, REX_NO_CASE | REX_NO_SPACE);
	if(rh == NULL) return 0;

	nBuff[0]= '@';
	for(k= 0; (k < 250) && (orgName[k] != '\0'); k++) {
	    nBuff[k+1]= toupper(orgName[k]);
	}
	k++;
	nBuff[k]= '@';
	nBuff[k+1]= '\0';

	res= rex_cmp(rh, nBuff);

	free(rh);
	return res;
    }

    if(mode == TAX_TOKEN_SEARCH) {
	char nBuff[256];
	Int4 k;
	rex_handler rh[16];
	Int2 nof_rh, j, res;
	CharPtr tail= str;

	nBuff[0]= '*';
	nBuff[1]= ' ';
	for(nof_rh= 0; (nof_rh != 16) && (tail != NULL); nof_rh++) {
	    tail= get_token(tail, nBuff);
	    rh[nof_rh]= rex_setExpr(nBuff, REX_NO_CASE | REX_NO_SPACE);
	    if(rh[nof_rh] == NULL) nof_rh--;
	}
	if(nof_rh < 1) return FALSE;

	nBuff[0]= ' ';

	tail= orgName;
	for(k= 0; (k < 250) && (tail[k] != '\0'); k++) {
	    nBuff[k+1]= toupper(tail[k]);
	}
	k++;
	nBuff[k]= ' ';
	nBuff[k+1]= '\0';

	for(res= 1, j= 0; (j < nof_rh) && (res > 0); j++) {
	    res= rex_cmp(rh[j], nBuff);
	}

	for(j= 0; j < nof_rh; j++) {
	    free(rh[j]);
	}
	return (res != 0)? TRUE : FALSE; 
    }

    return FALSE;
}
示例#25
0
static Boolean s_ProcessOtherLine (AliConfigInfoPtr configPtr,
				   CharPtr          otherStr,
				   AlignFileDataPtr fileInfoPtr)
{
  CharPtr strPtr;
  CharPtr tmpStr;

  /* Check for datatype declaration */

  if (((strPtr = StringStr (otherStr, "datatype")) != NULL) ||
      ((strPtr = StringStr (otherStr, "DATATYPE")) != NULL) ||
      ((strPtr = StringStr (otherStr, "Datatype")) != NULL))
    {
      tmpStr = s_OtherGetValue(strPtr);
      if (StringICmp (tmpStr, "DNA") == 0)
	configPtr->declaredInfo.dataType = ALI_DATA_NUCLEOTIDE;
      else
	configPtr->declaredInfo.dataType = ALI_DATA_PROTEIN;
      MemFree (tmpStr);
    }

  /* Check for interleaved/contiguous */

  if (((strPtr = StringStr (otherStr, "INTERLEAVED")) != NULL) ||
      ((strPtr = StringStr (otherStr, "interleaved")) != NULL) ||
      ((strPtr = StringStr (otherStr, "Interleaved")) != NULL))
    configPtr->declaredInfo.contigOrInter = ALI_INTERLEAVED;
  else if (((strPtr = StringStr (otherStr, "CONTIGUOUS")) != NULL) ||
	   ((strPtr = StringStr (otherStr, "contiguous")) != NULL) ||
	   ((strPtr = StringStr (otherStr, "Contiguous")) != NULL))
    configPtr->declaredInfo.contigOrInter = ALI_CONTIGUOUS;

  /* Check for dimensions */

  if (((strPtr = StringStr (otherStr, "NTAX")) != NULL) ||
      ((strPtr = StringStr (otherStr, "ntax")) != NULL) ||
      ((strPtr = StringStr (otherStr, "nTax")) != NULL))
    {
      tmpStr = s_OtherGetValue (strPtr);
      configPtr->declaredInfo.idCount = atoi(tmpStr);
      MemFree (tmpStr);
    }

  if (((strPtr = StringStr (otherStr, "NCHAR")) != NULL) ||
      ((strPtr = StringStr (otherStr, "nchar")) != NULL) ||
      ((strPtr = StringStr (otherStr, "nChar")) != NULL))
    {
      tmpStr = s_OtherGetValue (strPtr);
      configPtr->declaredInfo.seqLength = atoi(tmpStr);
      MemFree (tmpStr);
    }

  /* Check for definition of missing character */
  
  if (((strPtr = StringStr (otherStr, "MISSING")) != NULL) ||
      ((strPtr = StringStr (otherStr, "missing")) != NULL) ||
      ((strPtr = StringStr (otherStr, "Missing")) != NULL))
    {
      tmpStr = s_OtherGetValue(strPtr);
      configPtr->missingChar = (CharPtr) MemNew (2);
      sprintf (configPtr->missingChar, "%c", tmpStr[0]);
      MemFree (tmpStr);

      /* If the new missing char conflicts with the */
      /* gap or unaligned char, then blank them out */
      /* to give the new one precedence.            */

      if (StringICmp (configPtr->missingChar, configPtr->gapChar) == 0)
	StringCpy (configPtr->gapChar, "");

      if (StringICmp (configPtr->missingChar, configPtr->unalignedChar) == 0)
	StringCpy (configPtr->unalignedChar, "");
	
    }
  
  /* Check for definition of gap character */
  
  if (((strPtr = StringStr (otherStr, "GAP")) != NULL) ||
      ((strPtr = StringStr (otherStr, "gap")) != NULL) ||
      ((strPtr = StringStr (otherStr, "Gap")) != NULL))
    {
      tmpStr = s_OtherGetValue(strPtr);
      configPtr->gapChar = (CharPtr) MemNew (2);
      sprintf (configPtr->gapChar, "%c", tmpStr[0]);
      MemFree (tmpStr);

      /* If the new gap char conflicts with the missing */
      /* or unaligned char, then blank them out to give */
      /* the new one precedence.                        */

      if (StringICmp (configPtr->gapChar, configPtr->missingChar) == 0)
	StringCpy (configPtr->missingChar, "");

      if (StringICmp (configPtr->gapChar, configPtr->unalignedChar) == 0)
	StringCpy (configPtr->unalignedChar, "");
	
    }
  
  /* Check for definition of unaligned character */
  
  if (((strPtr = StringStr (otherStr, "UNALIGNED")) != NULL) ||
      ((strPtr = StringStr (otherStr, "unaligned")) != NULL) ||
      ((strPtr = StringStr (otherStr, "Unaligned")) != NULL))
    {
      tmpStr = s_OtherGetValue(strPtr);
      configPtr->unalignedChar = (CharPtr) MemNew (2);
      sprintf (configPtr->unalignedChar, "%c", tmpStr[0]);
      MemFree (tmpStr);

      /* If the new unaligned char conflicts with the */
      /* gap or missing char, then blank them out to  */
      /* give the new one precedence.                 */

      if (StringICmp (configPtr->unalignedChar, configPtr->gapChar) == 0)
	StringCpy (configPtr->gapChar, "");

      if (StringICmp (configPtr->unalignedChar, configPtr->missingChar) == 0)
	StringCpy (configPtr->missingChar, "");
	
    }
  
  /* Return successfully */
  
  return TRUE;
}
示例#26
0
BEDataPtr BEMakeWWWParam(WWWInfoPtr info)
{
    BEDataPtr pBdata;
    CharPtr   chptr;
    Char tmp[512];

    pBdata = (BEDataPtr)MemNew(sizeof(BEData));

    /* Database to search */

    if((chptr = WWWGetValueByName(info, "DATABASE")) == NULL) {
        if((chptr = WWWGetValueByName(info, "DB")) == NULL)
            if((chptr = WWWGetValueByName(info, "DATALIB")) == NULL) {
                chptr = "n"; /* Default to nucleotides */
            }
    }
    
    switch(*chptr) {
    case 'n':
        pBdata->database = 0;
        break;
    case 'p':
        pBdata->database = 1;
        break;
    default:
        pBdata->database = 0;
        break;
    }

    if((chptr = WWWGetValueByName(info, "REQUEST_TYPE")) != NULL) {
        if(!StringICmp(chptr, "LIST_OF_GIS"))
            pBdata->request_type = REQ_LIST_OF_GIS;
        else if(!StringICmp(chptr, "ADVANCED_QUERY"))
            pBdata->request_type = REQ_ADVANCED_QUERY;
        else if(!StringICmp(chptr, "ORGANISM"))
            pBdata->request_type = REQ_ORGANISM;
    } else {
        pBdata->request_type = REQ_DEFAULT;
    }

    switch(pBdata->request_type) {
    case REQ_ADVANCED_QUERY:
    case REQ_LIST_OF_GIS:
    case REQ_DEFAULT:
        /* Query string */
        
        if((chptr = WWWGetValueByName(info, "TERM")) == NULL)
            chptr = WWWGetValueByName(info, "QUERY");
        
        if(chptr != NULL && *chptr != NULLB) {
            pBdata->query = StringSave(chptr);
            CleanCRLF(pBdata->query);
        }
        
        /* List of UIDs */
        
        if((chptr = WWWGetValueByName(info, "UID")) != NULL && 
           *chptr != NULLB) {
            pBdata->uids = StringSave(chptr);
        }
        break;
    case REQ_ORGANISM:
        /* Query for organism retrieval */
        
        if(((chptr = WWWGetValueByName(info, "ORGNAME")) != NULL && 
            *chptr != NULLB) || 
           ((chptr = WWWGetValueByName(info, "LIST_ORG")) != NULL && 
            *chptr != NULLB && StringICmp (chptr, "(None)"))) {
            sprintf(tmp, "%s[ORGN]", chptr);
            pBdata->query = StringSave(tmp);
        }
        break;
    }

    /* Checking for data consistency */
    
    if(pBdata->request_type == REQ_LIST_OF_GIS && pBdata->uids == NULL)
        goto fail_return;
    if((pBdata->request_type == REQ_ADVANCED_QUERY || 
        pBdata->request_type == REQ_ORGANISM) && pBdata->query == NULL)
        goto fail_return;
    if(pBdata->query == NULL && pBdata->uids == NULL)
        goto fail_return;
    
    /* Format of output */
    
    if((chptr = WWWGetValueByName(info, "FORMAT")) != NULL ||
       (chptr = WWWGetValueByName(info, "DOPT")) != NULL) {
        pBdata->format = atoi(chptr);
    } else {
        pBdata->format = F_GILIST;
    }
    
    /* HTML output */
    
    if((chptr = WWWGetValueByName(info, "HTML")) != NULL) {
        if(!StringICmp(chptr, "NO") || !StringICmp(chptr, "FALSE") ||
           !StringICmp(chptr, "0"))
            pBdata->html = FALSE;
        else
            pBdata->html = TRUE;
    }

    /* Output type */
    
    if((chptr = WWWGetValueByName(info, "SAVETO")) != NULL) {
        if(!StringICmp(chptr, "NO") || !StringICmp(chptr, "FALSE") ||
           !StringICmp(chptr, "0"))
            pBdata->savetodisk = FALSE;
        else
            pBdata->savetodisk = TRUE;
    }


    if((chptr = WWWGetValueByName(info, "ALLSET")) != NULL) {
        if(!StringICmp(chptr, "NO") || !StringICmp(chptr, "FALSE") ||
           !StringICmp(chptr, "0"))
            pBdata->allset = FALSE;
        else
            pBdata->allset = TRUE;
    }
    
    if((chptr = WWWGetValueByName(info, "MAXDOCS")) != NULL ||
       (chptr = WWWGetValueByName(info, "DISPMAX")) != NULL)
        pBdata->maxdocs = atol(chptr);

    if((chptr = WWWGetValueByName(info, "NOHEADER")) != NULL) {
        if(!StringICmp(chptr, "NO") || !StringICmp(chptr, "FALSE") ||
           !StringICmp(chptr, "0"))
            pBdata->noheader = FALSE;
        else
            pBdata->noheader = TRUE;
    }
    
    return pBdata;

 fail_return:
    MemFree(pBdata);
    return NULL;
}
示例#27
0
Int2 Main()
{
   AsnIoPtr           aip;
   BioseqPtr          bsp;
   Pointer            dataptr;
   Uint2              datatype;
   Boolean            found;
   SPI_mRNAToHerdPtr  h_head;
   SPI_mRNAToHerdPtr  h_prev;
   SPI_mRNAToHerdPtr  hptr;
   FILE               *ifp;
   Boolean            isGIlist;
   Char               line[60];
   Boolean            lowercase;
   SeqLocPtr          lcaseloc;
   FILE               *ofp;
   FILE               *ofp2;
   SeqAlignPtr        sap;
   SeqAnnotPtr        sanp;
   SeqEntryPtr        sep;
   FILE               *sfp;
   SeqIdPtr           sip;
   SeqLocPtr          slp;
   SPI_bsinfoPtr      spig;
   SPI_bsinfoPtr      spig_head;
   SPI_bsinfoPtr      spig_prev;
   SPI_bsinfoPtr      spim;
   SPI_bsinfoPtr      spim_head;
   SPI_bsinfoPtr      spim_prev;
   SPI_OptionsPtr     spot;
   SPI_RegionInfoPtr  srip = NULL;
   SPI_RegionInfoPtr  srip_head;
   SPI_RegionInfoPtr  srip_prev;
   CharPtr            str;
   CharPtr            txt;

   ID1BioseqFetchEnable("spidey", FALSE);
   LocalSeqFetchInit(FALSE);
   /* standard setup */
   ErrSetFatalLevel (SEV_MAX);
   ErrClearOptFlags (EO_SHOW_USERSTR);
   UseLocalAsnloadDataAndErrMsg ();
   ErrPathReset ();
   if (! AllObjLoad ())
   {
      Message (MSG_FATAL, "AllObjLoad failed");
      return 1;
   }
   if (! SubmitAsnLoad ())
   {
      Message (MSG_FATAL, "SubmitAsnLoad failed");
      return 1;
   }
   if (! FeatDefSetLoad ())
   {
      Message (MSG_FATAL, "FeatDefSetLoad failed");
      return 1;
   }
   if (! SeqCodeSetLoad ())
   {
      Message (MSG_FATAL, "SeqCodeSetLoad failed");
      return 1;
   }
   if (! GeneticCodeTableLoad ())
   {
      Message (MSG_FATAL, "GeneticCodeTableLoad failed");
      return 1;
   }
   if (!GetArgs("SPIDEY", NUMARGS, myargs))
      return 0;
   /* set the error message level high to suppress warnings from BLAST */
   isGIlist = (Boolean)myargs[MYARGGILIST].intvalue;
   txt = myargs[MYARGGENFILE].strvalue;
   ifp = FileOpen(txt, "r");
   spig_head = NULL;
   if (ifp == NULL)
   {
      bsp = SPI_GetBspFromGIOrAcc(txt);
      if (bsp == NULL)
      {
         ErrPostEx(SEV_ERROR, 0, 0, "Can't open genomic input file\n");
         return -1;
      } else
      {
         spig_head = (SPI_bsinfoPtr)MemNew(sizeof(SPI_bsinfo));
         spig_head->bsp = bsp;
      }
   }
   if (spig_head == NULL)
   {
      spig_prev = NULL;
      /* read in the genomic sequence(s) first and put them into bsinfo structures */
      while ((dataptr = ReadAsnFastaOrFlatFile (ifp, &datatype, NULL, FALSE, FALSE, TRUE, FALSE)) != NULL)
      {
         if (datatype == OBJ_BIOSEQ)
         {
            spig = (SPI_bsinfoPtr)MemNew(sizeof(SPI_bsinfo));
            spig->bsp = (BioseqPtr)dataptr;
            if (spig_head == NULL)
               spig_head = spig_prev = spig;
            else
            {
               spig_prev->next = spig;
               spig_prev = spig;
            }
         } else if (datatype == OBJ_SEQENTRY)
         {
            sep = (SeqEntryPtr)dataptr;
            SeqEntryExplore(sep, &spig_head, SPI_FindAllNuc);
         }
      }
      FileClose(ifp);
   }
   if (spig_head == NULL)
   {
      ErrPostEx(SEV_ERROR, 0, 0, "No valid bioseqs in genomic file\n");
      return -1;
   } else if (ISA_aa(spig_head->bsp->mol))
   {
      ErrPostEx(SEV_ERROR, 0, 0, "At least one of the genomic sequences appears to be a protein.\n");
      return -1;
   }
   if (spig_head->next != NULL)
   {
      ErrPostEx(SEV_ERROR, 0, 0, "This version can only process one genomic sequence at a time.  Only the first sequence in this file will be used.\n");
      spig_head->next = NULL;
   }
   spim_head = spim_prev = NULL;
   txt = myargs[MYARGMRNAFILE].strvalue;
   ifp = FileOpen(txt, "r");
   if (ifp == NULL)
   {
      bsp = SPI_GetBspFromGIOrAcc(txt);
      if (bsp == NULL)
      {
         ErrPostEx(SEV_ERROR, 0, 0, "Can't open mRNA input file\n");
         return -1;
      } else
      {
         spim_head = (SPI_bsinfoPtr)MemNew(sizeof(SPI_bsinfo));
         spim_head->bsp = bsp;
      }
   }
   if (spim_head == NULL)
   {
      lowercase = (Boolean)myargs[MYARGMASKED].intvalue;
      lcaseloc = NULL;
      /* if the mRNA has lowercase masking, read it in carefully to record the masking */
      if (lowercase == TRUE)
      {
         while ((sep = FastaToSeqEntryForDb(ifp, TRUE, NULL, TRUE, NULL, NULL, &lcaseloc)) != NULL)
         {
            SeqEntryExplore(sep, &spim_head, SPI_FindAllNuc);
            if (lcaseloc != NULL)  /* put masking info into the bsinfo structure */
            {
               spim = spim_head;
               sip = SeqLocId(lcaseloc);
               found = FALSE;
               while (spim != NULL && !found)
               {
                  if (SeqIdComp(sip, spim->bsp->id) == SIC_YES)
                  {
                     found = TRUE;
                     spim->lcaseloc = lcaseloc;
                  }
                  spim = spim->next;
               }
               lcaseloc = NULL;
            }
         }
      } else if (isGIlist) /* mRNA file is a list of GIs, must fetch the bioseqs */
      {
         str = ReadALine(line, sizeof(line), ifp);
         while (str != NULL)
         {
            bsp = SPI_GetBspFromGIOrAcc(str);
            if (bsp != NULL)
            {
               spim = (SPI_bsinfoPtr)MemNew(sizeof(SPI_bsinfo));
               spim->bsp = bsp;
               if (spim_head == NULL)
                  spim_head = spim_prev = spim;
               else
               {
                  spim_prev->next = spim;
                  spim_prev = spim;
               }
            }
            str = ReadALine(line, sizeof(line), ifp);
         }
      } else /* mRNAs are FASTA or ASN.1, read them all in */
      {
         while ((dataptr = ReadAsnFastaOrFlatFile (ifp, &datatype, NULL, FALSE, FALSE, TRUE, FALSE)) != NULL)
         {
            if (datatype == OBJ_BIOSEQ)
            {
               spim = (SPI_bsinfoPtr)MemNew(sizeof(SPI_bsinfo));
               spim->bsp = (BioseqPtr)dataptr;
               if (spim_head == NULL)
                  spim_head = spim_prev = spim;
               else
               {
                  spim_prev->next = spim;
                  spim_prev = spim;
               }
            } else if (datatype == OBJ_SEQENTRY)
            {
               sep = (SeqEntryPtr)dataptr;
               SeqEntryExplore(sep, &spim_head, SPI_FindAllNuc);
            }
         }
      }
      FileClose(ifp);
   }
   if (spim_head == NULL)
   {
      ErrPostEx(SEV_ERROR, 0, 0, "No valid bioseqs in mRNA file\n");
      return -1;
   } else if (ISA_aa(spim_head->bsp->mol))
   {
      ErrPostEx(SEV_ERROR, 0, 0, "At least one of the mRNA sequences appears to be a protein\n");
      return -1;
   }
   txt = myargs[MYARGTABLE].strvalue;
   if (txt != NULL)
   {
      ifp = FileOpen(txt, "r");
      if (ifp == NULL)
      {
         ErrPostEx(SEV_ERROR, 0, 0, "Unable to open table file\n");
         return -1;
      }
      SPI_ReadFeatureTable(ifp, spim_head);
      spim = spim_head;
      while (spim != NULL)
      {
         if (spim->lcaseloc != NULL)
         {
            slp = (SeqLocPtr)ValNodeNew(NULL);
            slp->choice = SEQLOC_MIX;
            slp->data.ptrvalue = (Pointer)spim->lcaseloc;
            spim->lcaseloc = slp;
         }
         spim = spim->next;
      }
   }
   spim = spim_head;
   spot = (SPI_OptionsPtr)MemNew(sizeof(SPI_Options));
   spot->printaln = myargs[MYARGPRALIGN].intvalue;
   txt = myargs[MYARGOUTFILE].strvalue;
   ofp = FileOpen(txt, "w");
   if (ofp == NULL && spot->printaln != 3)
   {
      ErrPostEx(SEV_ERROR, 0, 0, "Unable to open output file\n");
      return -1;
   }
   if (spot->printaln >= 2)
   {
      txt = myargs[MYARGALNFILE].strvalue;
      ofp2 = FileOpen(txt, "a");
      if (ofp2 == NULL)
      {
         ErrPostEx(SEV_ERROR, 0, 0, "Unable to open output file 2\n");
         return -1;
      }
   } else
      ofp2 = NULL;
   /** ErrSetMessageLevel(SEV_MAX); **/
   spot->firstpasseval = myargs[MYARG1STEVAL].floatvalue;
   spot->secpasseval = myargs[MYARG2NDEVAL].floatvalue;
   spot->thirdpasseval = myargs[MYARG3RDEVAL].floatvalue;
   spot->numreturns = myargs[MYARGNUMMOD].intvalue;
   spot->idcutoff = myargs[MYARGIDCUT].intvalue;
   spot->lencutoff = myargs[MYARGLENCUT].intvalue;
   spot->interspecies = (Boolean)myargs[MYARGSPEC].intvalue;
   spot->printasn = (Boolean)myargs[MYARGASN].intvalue;
   spot->fetchcds = (Boolean)myargs[MYARGGETCDS].intvalue;
   /*spot->ace = (Boolean)myargs[MYARGACEDB].intvalue;*/
   spot->from = myargs[MYARGFROM].intvalue;
   spot->to = myargs[MYARGTO].intvalue;
   spot->makemult = (Boolean)myargs[MYARGMULT].intvalue;
   /*KSK*/
   spot->bigintron = (Boolean)myargs[MYARGXL].intvalue; 
   spot->bigintron_size = myargs[MYARGXL_SIZE].intvalue;
   spot->repeat_db_file = myargs[MYARGREPDB].strvalue;
   txt = myargs[MYARGORG].strvalue;
   if (!StringICmp(txt, "d") || !StringICmp(txt, "D")){
       spot->organism = SPI_FLY;
   }
   else if (!StringICmp(txt, "p") || !StringICmp(txt, "P")){
       spot->organism = SPI_PLANT;
   }
   else if (!StringICmp(txt, "c") || !StringICmp(txt, "C")){
       spot->organism = SPI_CELEGANS;
   }
   else if (!StringICmp(txt, "m") || !StringICmp(txt, "M")){
       spot->organism = SPI_DICTY;
   }
   else {
       spot->organism = SPI_VERTEBRATE;
   }
   sap = NULL;
   if (spot->printasn)
      spot->sap_head = &sap;
   txt = myargs[MYARGSTRAND].strvalue;
   if (txt != NULL)
   {
      if (StrChr(txt, 'p') || StrChr(txt, 'P'))
         spot->strand = Seq_strand_plus;
      else
         spot->strand = Seq_strand_minus;
   } else
      spot->strand = Seq_strand_both;
   /*txt = myargs[MYARGDRAFTFILE].strvalue;
   if (txt != NULL)
      spot->draftfile = StringSave(txt);*/
   txt = myargs[MYARGDSPLICE].strvalue;
   if (txt != NULL)
   {
      sfp = FileOpen(txt, "r");
      SPI_GetSpliceInfo(spot, sfp, TRUE);
      FileClose(sfp);
   }
   txt = myargs[MYARGASPLICE].strvalue;
   if (txt != NULL)
   {
      sfp = FileOpen(txt, "r");
      SPI_GetSpliceInfo(spot, sfp, FALSE);
      FileClose(sfp);
   }
   h_head = h_prev = NULL;
   srip_head = srip_prev = NULL;
   while (spim != NULL)
   {
      spot->lcaseloc = spim->lcaseloc;
      if (spot->draftfile == NULL)
         srip = SPI_AlnSinglemRNAToGen(spig_head, spim, ofp, ofp2, spot);
      else
      {
         hptr = SPI_AlnSinglemRNAToPieces(spig_head, spim, ofp, ofp2, spot);
         if (h_head != NULL)
         {
            h_prev->next = hptr;
            h_prev = hptr;
         } else
            h_head = h_prev = hptr;
      }
      if (srip != NULL)
      {
         if (srip_head != NULL)
         {
            srip_prev->next = srip;
            srip_prev = srip;
         } else
            srip_head = srip_prev = srip;
      }
      spim = spim->next;
   }
   if (spot->makemult)
   {
      SPI_MakeMultipleAlignment(srip_head);
      SPI_PrintMultipleAlignment(srip_head, FALSE, spig_head->bsp, ofp);
      SPI_RegionListFree(srip_head);
   } else
      SPI_RegionListFree(srip_head);
   /* create the ASN.1 output, if requested; need to use the continuous alignment */
   /* that was generated */
   if (spot->printasn && *(spot->sap_head) != NULL && spot->draftfile == NULL)
   {
      sanp = SeqAnnotForSeqAlign(*(spot->sap_head));
      txt = myargs[MYARGASNFILE].strvalue;
      aip = AsnIoOpen(txt, "w");
      SeqAnnotAsnWrite(sanp, aip, NULL);
      AsnIoClose(aip);
      SeqAlignSetFree(*(spot->sap_head));
   }
   FileClose(ofp);
   FileClose(ofp2);
   SPI_OptionsFree(spot);
   SPI_bsinfoFreeList(spim_head);
   SPI_bsinfoFreeList(spig_head);
   LocalSeqFetchDisable();
   ID1BioseqFetchDisable();
   return 0;
}
示例#28
0
static void SetupAppProperties (void)

{
  Char     str [32];
  Int2     val;

  showAsnPage = TRUE;
  if (GetEntrezAppParam ("PREFERENCES", "SHOWASNPAGE", "", str, sizeof (str) - 1)) {
    if (StringICmp (str, "FALSE") == 0) {
      showAsnPage = FALSE;
    }
  }

  MemSet ((Pointer) (&medviewprocs), 0, sizeof (MedlineViewProcs));
  medviewprocs.cleanupObjectPtr = FALSE;
  medviewprocs.activateForm = MedlineViewFormActivated;
  medviewprocs.closeForm = NULL;
  medviewprocs.useFolderTabs = CHANGE_VIEW_POPUP;
  /*
  medviewprocs.initPage = CITATION_PAGE;
  */
#ifndef WIN_MAC
  medviewprocs.createMenus = MedlineViewFormMenus;
#endif
  medviewprocs.showAsnPage = showAsnPage;
  medviewprocs.useScrollText = FALSE;
  medviewprocs.handleMessages = EntrezMedlineFormMessage;
  medviewprocs.makeControls = DoMakeViewerLinkControls;
  SetAppProperty ("MedlineDisplayForm", &medviewprocs);

  MemSet ((Pointer) (&seqviewprocs), 0, sizeof (SeqViewProcs));
  seqviewprocs.hasTargetControl = TRUE;
  seqviewprocs.hasDoneButton = FALSE;
  seqviewprocs.hasDuplicateButton = FALSE;
  seqviewprocs.launchEditors = FALSE;
  seqviewprocs.launchSubviewers = TRUE;
  seqviewprocs.sendSelectMessages = TRUE;
  seqviewprocs.highlightSelections = TRUE;
  seqviewprocs.cleanupObjectPtr = FALSE;
  seqviewprocs.activateForm = BioseqViewFormActivated;
  seqviewprocs.closeForm = NULL;
  seqviewprocs.useFolderTabs = CHANGE_VIEW_POPUP;
  /*
  seqviewprocs.initNucPage = NUCASN2FF_PAGE_1;
  seqviewprocs.initProtPage = PROTGENPEPT_PAGE;
  */
#ifndef WIN_MAC
  seqviewprocs.createMenus = BioseqViewFormMenus;
#endif
  seqviewprocs.allowScrollText = FALSE;
  seqviewprocs.startInScrollText = FALSE;
  seqviewprocs.handleMessages = EntrezSeqViewFormMessage;
  seqviewprocs.makeControls = DoMakeViewerLinkControls;

  AddBioseqPageToList (&(seqviewprocs.pageSpecs), &mapPageData);
  AddBioseqPageToList (&(seqviewprocs.pageSpecs), &sumPageData);
  AddBioseqPageToList (&(seqviewprocs.pageSpecs), &gphPageData);
  AddBioseqPageToList (&(seqviewprocs.pageSpecs), &alnPageData);
  AddBioseqPageToList (&(seqviewprocs.pageSpecs), &seqPageData);
  AddBioseqPageToList (&(seqviewprocs.pageSpecs), &gbgnPageData);
  AddBioseqPageToList (&(seqviewprocs.pageSpecs), &gnbkPageData);
  AddBioseqPageToList (&(seqviewprocs.pageSpecs), &emblPageData);
  AddBioseqPageToList (&(seqviewprocs.pageSpecs), &gnptPageData);
  AddBioseqPageToList (&(seqviewprocs.pageSpecs), &fstaPageData);
  AddBioseqPageToList (&(seqviewprocs.pageSpecs), &qualPageData);
  if (showAsnPage) {
    AddBioseqPageToList (&(seqviewprocs.pageSpecs), &asnPageData);
    AddBioseqPageToList (&(seqviewprocs.pageSpecs), &dskPageData);
  }

  SetAppProperty ("SeqDisplayForm", &seqviewprocs);

  if (GetAppParam ("ENTREZ", "PREFERENCES", "TEXTEDITDISPLAYS", "", str, sizeof (str))) {
    if (StringICmp (str, "TRUE") == 0) {
      medviewprocs.useScrollText = TRUE;
      seqviewprocs.allowScrollText = TRUE;
      seqviewprocs.startInScrollText = TRUE;
    }
  }

  if (GetEntrezAppParam ("PREFERENCES", "MINPIXELWIDTH", "", str, sizeof (str))) {
    if (StrToInt (str, &val) && val > 0) {
      val = MIN (val, screenRect.right);
      medviewprocs.minPixelWidth = val;
      seqviewprocs.minPixelWidth = val;
    }
  }

  if (GetEntrezAppParam ("PREFERENCES", "MINPIXELHEIGHT", "", str, sizeof (str))) {
    if (StrToInt (str, &val) && val > 0) {
      val = MIN (val, screenRect.bottom);
      medviewprocs.minPixelHeight = val;
      seqviewprocs.minPixelHeight = val;
    }
  }

  if (GetEntrezAppParam ("PREFERENCES", "TEXTPIXELWIDTH", "", str, sizeof (str))) {
    if (StrToInt (str, &val) && val > 0) {
      val = MIN (val, screenRect.right);
      txtviewprocs.minPixelWidth = val;
    }
  }

  if (GetEntrezAppParam ("PREFERENCES", "TEXTPIXELHEIGHT", "", str, sizeof (str))) {
    if (StrToInt (str, &val) && val > 0) {
      val = MIN (val, screenRect.bottom);
      txtviewprocs.minPixelHeight = val;
    }
  }

  if (GetEntrezAppParam ("SETTINGS", "MEDPAGE", "Abstract", str, sizeof (str))) {
    medviewprocs.initMedLabel = StringSaveNoNull (str);
  }
  if (GetEntrezAppParam ("SETTINGS", "NUCPAGE", "GenBank", str, sizeof (str))) {
    seqviewprocs.initNucLabel = StringSaveNoNull (str);
  }
  if (GetEntrezAppParam ("SETTINGS", "PRTPAGE", "GenPept", str, sizeof (str))) {
    seqviewprocs.initProtLabel = StringSaveNoNull (str);
  }
  if (GetEntrezAppParam ("SETTINGS", "GENMPAGE", "Map", str, sizeof (str))) {
    seqviewprocs.initGenomeLabel = StringSaveNoNull (str);
  }

  MemSet ((Pointer) (&entrezglobals), 0, sizeof (EntrezGlobals));
  entrezglobals.retrieveDocsProc = DoRetrieveDocuments;
  entrezglobals.loadNamedUidProc = DoLoadNamedUidList;
  entrezglobals.launchViewerProc = DoLaunchRecordViewer;
#ifndef WIN_MAC
  entrezglobals.createTrmLstMenus = TermListFormMenus;
  entrezglobals.createDocSumMenus = DocSumFormMenus;
#endif
  SetAppProperty ("EntrezGlobals", &entrezglobals);

  entrezglobals.showAsn = showAsnPage;

  entrezglobals.persistDefault = TRUE;
  if (GetEntrezAppParam ("PREFERENCES", "PARENTSPERSIST", "", str, sizeof (str) - 1)) {
    if (StringICmp (str, "FALSE") == 0) {
      entrezglobals.persistDefault = FALSE;
    }
  }
  entrezglobals.alignDefault = TRUE;
  if (GetEntrezAppParam ("PREFERENCES", "ALIGNCHECKED", NULL, str, sizeof (str) - 1)) {
    if (StringICmp (str, "FALSE") == 0) {
      entrezglobals.alignDefault = FALSE;
    }
  }
  if (GetAppParam ("ENTREZ", "PREFERENCES", "POPDOWN", "", str, sizeof (str) - 1)) {
    if (StringICmp (str, "TRUE") == 0) {
      entrezglobals.popdownBehavior = TRUE;
    }
  }
  if (GetEntrezAppParam ("PREFERENCES", "LOOKUPDIRECT", "", str, sizeof (str) - 1)) {
    if (StringICmp (str, "TRUE") == 0) {
      entrezglobals.lookupDirect = TRUE;
    }
  }
  entrezglobals.sortFields = TRUE;
  if (GetAppParam ("ENTREZ", "PREFERENCES", "SORTFIELDS", "", str, sizeof (str) - 1)) {
    if (StringICmp (str, "FALSE") == 0) {
      entrezglobals.sortFields = FALSE;
    }
  }
  if (GetEntrezAppParam ("SETTINGS", "DATABASE", "MEDLINE", str, sizeof (str))) {
    entrezglobals.initDatabase = StringSaveNoNull (str);
  }
  if (GetEntrezAppParam ("SETTINGS", "FIELD", "All Fields", str, sizeof (str))) {
    entrezglobals.initField = StringSaveNoNull (str);
  }
  if (GetEntrezAppParam ("SETTINGS", "MODE", "Automatic", str, sizeof (str))) {
    entrezglobals.initMode = StringSaveNoNull (str);
  }

  if (GetEntrezAppParam ("SETTINGS", "BROWSER", NULL, str, sizeof (str))) {
    SetAppProperty ("MedviewBrowserPath", (void *) StringSave (str));
  }

  MemSet ((Pointer) (&stdedprocs), 0, sizeof (StdEditorProcs));
#ifdef WIN_MAC
  stdedprocs.activateForm = StdEditorFormActivated;
#endif
  stdedprocs.handleMessages = EntrezStdEditorFormMessage;
  SetAppProperty ("StdEditorForm", &stdedprocs);

  MemSet ((Pointer) (&txtviewprocs), 0, sizeof (TextViewProcs));
  txtviewprocs.useScrollText = FALSE;
  SetAppProperty ("TextDisplayForm", &txtviewprocs);
}
示例#29
0
Int2 Main_old (void)
 
{
	
	AsnIoPtr aip;
	BioseqPtr fake_bsp = NULL, fake_subject_bsp = NULL, query_bsp = NULL, 
                  subject_bsp = NULL;
        BioseqPtr bsp1, bsp2;
	BLAST_KarlinBlkPtr ka_params=NULL, ka_params_gap=NULL;
	BLAST_OptionsBlkPtr options=NULL;
	Boolean seq1_is_na, seq2_is_na;
	CharPtr params_buffer=NULL;
        DbtagPtr        dbtagptr;
	Uint1 align_type;
	Uint4 align_options;
	SeqAlignPtr  seqalign;
        SeqAnnotPtr seqannot;
	SeqEntryPtr sep = NULL, sep1 = NULL;
	CharPtr program_name, blast_outputfile;
	FILE *outfp;
	ValNodePtr  mask_loc, mask_loc_start, vnp, other_returns=NULL, error_returns=NULL;
	BLAST_MatrixPtr matrix;
        Int4Ptr PNTR txmatrix;
        int (LIBCALLBACK *handle_results)PROTO((VoidPtr search)) = NULL;
        Boolean entrez_lookup = FALSE;
        Boolean html, seqannot_output, believe_query;
        Uint1 tabular_output;
        Boolean gapped_calculation;

        entrez_lookup = (Boolean) myargs[ARG_ACCN].intvalue;
        html = (Boolean) myargs[ARG_HTML].intvalue;
        seqannot_output = (myargs[ARG_ASNOUT].strvalue != NULL);

        blast_outputfile = myargs [ARG_OUT].strvalue;

	program_name = StringSave(myargs[ARG_PROGRAM].strvalue);
	if (StringCmp(program_name, "blastn") && 
	    StringCmp(program_name, "blastp") && 
	    StringCmp(program_name, "blastx") && 
	    StringCmp(program_name, "tblastn") && 
	    StringCmp(program_name, "tblastx")) {
		ErrPostEx(SEV_FATAL, 1, 0, "Program name must be blastn, blastp, blastx, tblastn or tblastx\n");
		return (1);
	}
	   
	align_type = BlastGetTypes(program_name, &seq1_is_na, &seq2_is_na);

	if ((outfp = FileOpen(blast_outputfile, "w")) == NULL)
	{
		ErrPostEx(SEV_FATAL, 1, 0, "blast: Unable to open output file %s\n", blast_outputfile);
		return (1);
	}

        gapped_calculation = (Boolean) myargs[ARG_GAPPED].intvalue;
        believe_query = (seqannot_output || entrez_lookup); 

        options = BLASTOptionNewEx(program_name, gapped_calculation,
                                   (Boolean) myargs[ARG_USEMEGABLAST].intvalue);

        if (BL2SEQ_GetSequences(seq1_is_na, seq2_is_na, &query_bsp, &subject_bsp,
                                &sep, &sep1, &(options->query_lcase_mask), 
                                believe_query) == FALSE)
        {
            ErrPostEx(SEV_FATAL, 1, 0, "blast: Unable to get sequences");
            return (1);
        }

        if (!entrez_lookup) {
            if (!believe_query)
                fake_bsp = BlastMakeFakeBioseq(query_bsp, NULL);
            
            fake_subject_bsp = BioseqNew();
            fake_subject_bsp->descr = subject_bsp->descr;
            fake_subject_bsp->repr = subject_bsp->repr;
            fake_subject_bsp->mol = subject_bsp->mol;
            fake_subject_bsp->length = subject_bsp->length;
            fake_subject_bsp->seq_data = subject_bsp->seq_data;
            fake_subject_bsp->seq_data_type = subject_bsp->seq_data_type;
            dbtagptr = DbtagNew();
            dbtagptr->db = StringSave("BL_ORD_ID");
            dbtagptr->tag = ObjectIdNew();

            if (BioseqGetTitle(subject_bsp) != NULL)
              dbtagptr->tag->str = StringSave(BioseqGetTitle(subject_bsp));
            else
              dbtagptr->tag->str = StringSave("No definition line found");

            ValNodeAddPointer(&fake_subject_bsp->id, SEQID_GENERAL, dbtagptr);
            bsp1 = (believe_query ? query_bsp : fake_bsp);
            bsp2 = fake_subject_bsp;
        } else {
            bsp1 = query_bsp;
            bsp2 = subject_bsp;
        }

        tabular_output = (Uint1) myargs[ARG_FORMAT].intvalue; 


    	if (myargs[ARG_SEARCHSP].floatvalue)
           options->searchsp_eff = (Nlm_FloatHi) myargs[ARG_SEARCHSP].floatvalue;


	options->filter_string = StringSave(myargs[ARG_FILTER].strvalue);
	options->expect_value  = (Nlm_FloatHi) myargs [ARG_EVALUE].floatvalue;

        if (StringICmp("blastn", program_name) == 0)
        {
                options->penalty = myargs[ARG_MISMATCH].intvalue;
                options->reward = myargs[ARG_MATCH].intvalue;
        }

	options->db_length = (Int8) myargs[ARG_DBSIZE].floatvalue;

	options->discontinuous = FALSE;

        if (myargs[ARG_XDROP].intvalue != 0)
	{
               options->gap_x_dropoff = myargs[ARG_XDROP].intvalue;
	}
        if (myargs[ARG_WORDSIZE].intvalue != 0)
               options->wordsize = (Int2) myargs[ARG_WORDSIZE].intvalue;

	if (options->is_megablast_search) {
	   options->cutoff_s2 = options->wordsize*options->reward;
        }
	options->matrix = MemFree(options->matrix);
        BLASTOptionSetGapParams(options, myargs[ARG_MATRIX].strvalue, 0, 0); 

        if (myargs[ARG_GAPOPEN].intvalue != -1)
              options->gap_open = myargs[ARG_GAPOPEN].intvalue;
        if (myargs[ARG_GAPEXT].intvalue != -1)
               options->gap_extend = myargs[ARG_GAPEXT].intvalue;

	options->strand_option = myargs[ARG_STRAND].intvalue;

        /* Input longest intron length is in nucleotide scale; in the lower 
           level code it will be used in protein scale */
        if (myargs[ARG_INTRON].intvalue > 0) 
           options->longest_intron = myargs[ARG_INTRON].intvalue;


        if (!myargs[ARG_LOC1].strvalue && !myargs[ARG_LOC2].strvalue) {
           seqalign = BlastTwoSequencesWithCallback(bsp1, bsp2, program_name, 
              options, &other_returns, &error_returns, handle_results);
        } else {
            SeqLocPtr slp1=NULL, slp2=NULL;
            if (BL2SEQ_MakeSeqLoc(bsp1, bsp2, &slp1, &slp2, options->strand_option) == FALSE)
                return 1;
           seqalign = BlastTwoSequencesByLocWithCallback(slp1, slp2, program_name, options, &other_returns, &error_returns, handle_results, NULL);
           SeqLocFree(slp1);
           SeqLocFree(slp2);
        }

        if (error_returns) {
           BlastErrorPrint(error_returns);
           for (vnp = error_returns; vnp; vnp = vnp->next) {
              BlastDestroyErrorMessage((BlastErrorMsgPtr)vnp->data.ptrvalue);
           }
           ValNodeFree(error_returns);
        }
       
        ka_params = NULL;
        ka_params_gap = NULL;
        params_buffer = NULL;
        mask_loc = NULL;
        matrix = NULL;
        txmatrix = NULL;
        for (vnp=other_returns; vnp; vnp = vnp->next) {
           switch (vnp->choice) {
           case TXKABLK_NOGAP:
              ka_params = vnp->data.ptrvalue;
              break;
           case TXKABLK_GAP:
              ka_params_gap = vnp->data.ptrvalue;
              break;
           case TXPARAMETERS:
              params_buffer = vnp->data.ptrvalue;
              break;
           case TXMATRIX:
              matrix = vnp->data.ptrvalue;
              if (matrix && !tabular_output)
                 txmatrix = BlastMatrixToTxMatrix(matrix);
              break;
           case SEQLOC_MASKING_NOTSET:
           case SEQLOC_MASKING_PLUS1:
           case SEQLOC_MASKING_PLUS2:
           case SEQLOC_MASKING_PLUS3:
           case SEQLOC_MASKING_MINUS1:
           case SEQLOC_MASKING_MINUS2:
           case SEQLOC_MASKING_MINUS3:
              ValNodeAddPointer(&mask_loc, vnp->choice, vnp->data.ptrvalue);
              break;
           default:
              break;
           }
        }	
        if (!tabular_output || seqannot_output) {
           align_options = 0;
           align_options += TXALIGN_MATRIX_VAL;
           align_options += TXALIGN_SHOW_QS;
           align_options += TXALIGN_COMPRESS;
           align_options += TXALIGN_END_NUM;
           if (StringICmp("blastx", program_name) == 0) {
              align_options += TXALIGN_BLASTX_SPECIAL;
           }
           
           if (html)
              align_options += TXALIGN_HTML;

           seqannot = SeqAnnotNew();
           seqannot->type = 2;
           AddAlignInfoToSeqAnnot(seqannot, align_type);
           seqannot->data = seqalign;
           aip = NULL;
           if (seqannot_output)
              aip = AsnIoOpen (myargs[ARG_ASNOUT].strvalue,"w");
           
           if (aip && seqannot) {
              SeqAnnotAsnWrite((SeqAnnotPtr) seqannot, aip, NULL);
              AsnIoReset(aip);
              aip = AsnIoClose(aip);
           }
        }
        if (!tabular_output) {    
           AcknowledgeBlastQuery(query_bsp, 70, outfp, believe_query, html);
           ShowTextAlignFromAnnot(seqannot, 60, outfp, NULL, NULL, align_options, txmatrix, mask_loc, FormatScoreFunc);
           
           seqannot = SeqAnnotFree(seqannot);
           if (txmatrix)
              txmatrix = TxMatrixDestruct(txmatrix);
           init_buff_ex(85);
        
           if (ka_params) {
              PrintKAParameters(ka_params->Lambda, ka_params->K, ka_params->H, 70, outfp, FALSE);
           }
        
           if (ka_params_gap) {
              PrintKAParameters(ka_params_gap->Lambda, ka_params_gap->K, ka_params_gap->H, 70, outfp, TRUE);
           }
        
           PrintTildeSepLines(params_buffer, 70, outfp);
           free_buff();
        } else {
           PrintTabularOutputHeader(NULL, query_bsp, NULL, 
              program_name, 0, believe_query, outfp);

           BlastPrintTabulatedResults(seqalign, query_bsp, NULL, 
              1, program_name, !gapped_calculation,
              believe_query, 0, 0, outfp, FALSE);
           SeqAlignSetFree(seqalign);
        }

        matrix = BLAST_MatrixDestruct(matrix);
        MemFree(ka_params);
        MemFree(ka_params_gap);
        MemFree(params_buffer);
    
        mask_loc_start = mask_loc;
        while (mask_loc) {
           SeqLocSetFree(mask_loc->data.ptrvalue);
           mask_loc = mask_loc->next;
        }
        ValNodeFree(mask_loc_start);
        
        fake_bsp = BlastDeleteFakeBioseq(fake_bsp);

        other_returns = ValNodeFree(other_returns);
    options->query_lcase_mask = SeqLocSetFree(options->query_lcase_mask);
	options = BLASTOptionDelete(options);
	MemFree(program_name);
	FileClose(outfp);

        if (entrez_lookup) {
           BioseqFree(query_bsp);
           BioseqFree(subject_bsp);
        } else {
           SeqEntryFree(sep);
           SeqEntryFree(sep1);
        }
	return 0;
}
示例#30
0
/*****************************************************************************
*
*   PubLabelUnique(pubptr, buf, buflen, content, unique)
*   	makes a short label for any Pub in buf, up to buflen size
*   	content follows objmgr OM_LABEL_
*       if (unique is TRUE, appends a string based on title words to make
*           unique key base on ANSI std Z39.56-1991
*
*****************************************************************************/
NLM_EXTERN Int2 LIBCALL PubLabelUnique (ValNodePtr pub, CharPtr buf, Int2 buflen, Uint1 content, Boolean unique)
{
	CharPtr typelabel = NULL;
	static CharPtr pubtypes [14] = {
		"Unknown",
		"Generic",
		"Submit",
		"Medline",
		"MUID",
		"Article",
		"Journal",
		"Book",
		"Proceedings",
		"Patent",
		"PatID",
		"Manuscript",
		"Equiv" ,
		"PMID" };
	ValNodePtr vnp2=NULL, title=NULL;
	Int2 len, diff;
	Char tbuf[41];
	Boolean first = TRUE;

	Int4 muid = 0, pmid = 0;
	AuthListPtr alp=NULL;
	AuthorPtr ap;
	ImprintPtr imp = NULL;
	CharPtr year = NULL,
			volume = NULL,
			issue = NULL,
			pages = NULL,
			title1=NULL,
			title2=NULL,
			titleunique = NULL,
			part_sup = NULL,
			part_supi = NULL;
	CitArtPtr cap;
	CitJourPtr cjp;
	CitBookPtr cbp=NULL;
	CitSubPtr csp;
	CitPatPtr cpp;
	IdPatPtr ipp;
	CitGenPtr cgp;
	MedlineEntryPtr mep;
	DatePtr dp = NULL;
	Boolean unpublished = FALSE, done;
	ValNodePtr eq[5];
	Int2 i;
	CharPtr s, cit;



	if ((buf == NULL) || (buflen < 1)) return 0;

	buf[0] = '?';
	buf[1] = '\0';

	if (pub == NULL) return 0;

	if (pub->choice > 13)
		typelabel = pubtypes[0];
	else
		typelabel = pubtypes[pub->choice];

	len = buflen;

	if (content == OM_LABEL_TYPE)
		return LabelCopy(buf, typelabel, buflen);

	if (content == OM_LABEL_BOTH)
	{
		diff = LabelCopyExtra(buf, typelabel, buflen, NULL, ": ");
		buflen -= diff; buf += diff;
	}

	switch (pub->choice)
	{
		case PUB_Muid:
			sprintf(tbuf, "NLM%ld", (long)(pub->data.intvalue));
			diff = LabelCopy(buf, tbuf, buflen);
			buflen -= diff;
			return (len - buflen); /* already unique */
			break;
		case PUB_PMid:
			sprintf(tbuf, "PM%ld", (long)(pub->data.intvalue));
			diff = LabelCopy(buf, tbuf, buflen);
			buflen -= diff;
			return (len - buflen); /* already unique */
			break;
		case PUB_Equiv:
			for (i = 0; i < 5; i++)
				eq[i] = NULL;
			i = 0;
			for (vnp2 = (ValNodePtr)(pub->data.ptrvalue);
			              ((vnp2 != NULL) && (buflen)); vnp2 = vnp2->next)
			{
				switch (vnp2->choice)
				{
					case PUB_Muid:
						eq[3] = vnp2;
						break;
					case PUB_Gen:
						cgp = (CitGenPtr)(vnp2->data.ptrvalue);
						if (cgp->serial_number > 0)
						{
							eq[4] = vnp2;
							break;
						}
					default:
						if (i < 5)
							eq[i] = vnp2;
						i++;
						break;
				}	
			}
			for (i = 0; i < 5; i++)
			{
				if (eq[i] != NULL)
				{
					if (! first)
					{
						diff = LabelCopy(buf, " ", buflen);
						buflen -= diff; buf += diff;
					}
					else
						first = FALSE;

					diff = PubLabelUnique (eq[i], buf, buflen, OM_LABEL_CONTENT, unique);
					buflen -= diff; buf += diff;
				}
			}
			break;
		case PUB_Medline:
			mep = (MedlineEntryPtr)(pub->data.ptrvalue);
			if (mep->pmid > 0)
				sprintf(tbuf, "PM%ld", (long)(mep->pmid));
			else
				sprintf(tbuf, "NLM%ld", (long)(mep->uid));
			diff = LabelCopyExtra(buf, tbuf, buflen, NULL, " ");
		  buflen -= diff; buf += diff;
			cap = mep->cit;
			goto cit_art;
		case PUB_Article:
			cap = (CitArtPtr)(pub->data.ptrvalue);
cit_art:	alp = cap->authors;
			if (cap->title != NULL)
				titleunique = (CharPtr)(cap->title->data.ptrvalue);
			switch (cap->from)
			{
				case 1:
					cjp = (CitJourPtr)(cap->fromptr);
					goto cit_jour;
				case 2:
				case 3:
					cbp = (CitBookPtr)(cap->fromptr);
					goto cit_book;
			}
			break;
		case PUB_Journal:
			cjp = (CitJourPtr)(pub->data.ptrvalue);
cit_jour:	imp = cjp->imp;
			title = cjp->title;
			break;
		case PUB_Book:
		case PUB_Proc:
		case PUB_Man:
			cbp = (CitBookPtr)(pub->data.ptrvalue);
			title = cbp->title;
cit_book:   imp = cbp->imp;
			if (alp == NULL)
				alp = cbp->authors;
			break;
		case PUB_Sub:
			csp = (CitSubPtr)(pub->data.ptrvalue);
			alp = csp->authors;
			imp = csp->imp;
			dp = csp->date;
			break;
		case PUB_Patent:
			cpp = (CitPatPtr)(pub->data.ptrvalue);
			alp = cpp->authors;
			dp = cpp->date_issue;
			if (dp == NULL)
				dp = cpp->app_date;
			title1 = cpp->country;
			title2 = cpp->number;
			if (title2 == NULL)
				title2 = cpp->app_number;
			break;
		case PUB_Pat_id:
			ipp = (IdPatPtr)(pub->data.ptrvalue);
			title1 = ipp->country;
			title2 = ipp->number;
			if (title2 == NULL)
				title2 = ipp->app_number;
			break;
		case PUB_Gen:
			cgp = (CitGenPtr)(pub->data.ptrvalue);
			if (cgp->serial_number > 0)
			{
				sprintf(tbuf, "[%d]", (int)(cgp->serial_number));
				diff = LabelCopy(buf, tbuf, buflen);
				buflen -= diff; buf += diff;
			}
			if (cgp->muid > 0)
			{
				sprintf(tbuf, "NLM%ld", (long)(cgp->muid));
				diff = LabelCopy(buf, tbuf, buflen);
				buflen -= diff; buf += diff;

			}
			dp = cgp->date;
			title = cgp->journal;
			alp = cgp->authors;
			if (cgp->cit != NULL)
			{
				if (! StringICmp("Unpublished", cgp->cit))
					unpublished = TRUE;
				else if (title == NULL)
					title2 = cgp->cit;
			}
			volume = cgp->volume;
			issue=cgp->issue;
			pages=cgp->pages;
            if (cgp->title != NULL)
				titleunique = cgp->title;
			else if (title2 != NULL)
				titleunique = title2;
			else if (title == NULL)
				titleunique = cgp->cit;
			if (title == NULL && alp == NULL && cgp->title == NULL &&
				volume == NULL && pages == NULL && issue == NULL) {
				titleunique = NULL;
				if ((cit = StringSave(cgp->cit)) != NULL) {
					if (!unique) {
						for (s = cit + StringLen(cit) -1; 
									s > cit && *s !='|';   s--) continue;
						if (*s == '|' ) {
							*s = '\0';
						}
					}
					diff = LabelCopy(buf, cit, buflen);
					MemFree(cit);
				}
				return 0;
			}
			break;
		default:
			sprintf(tbuf,"Unknown pub[%d]", (int)(pub->choice));
			title2 = tbuf;
			break;

	}

	if (imp != NULL)
	{
		if (dp == NULL)
			dp = imp->date;
		if (volume == NULL)
			volume = imp->volume;
		if (issue == NULL)
			issue = imp->issue;
		if (pages == NULL)
			pages = imp->pages;
		part_sup = imp->part_sup;
		part_supi = imp->part_supi;
	}

	if (alp != NULL)
	{
		vnp2 = alp->names;
		if (vnp2 != NULL)
		{
			if (alp->choice == 1)   /* std name */
			{
				ap = (AuthorPtr)(vnp2->data.ptrvalue);
				diff = PersonIdLabel(ap->name, buf, buflen, PIDLABEL_GENBANK);
			}
			else
				diff = LabelCopy(buf, (CharPtr)(vnp2->data.ptrvalue), buflen);
		buflen -= diff;
		buf += diff;
		}
	}

	if (dp != NULL)
	{
		if (dp->data[0])
		{
			if (pub->choice == PUB_Sub && dp->data[2] != 0 && dp->data[3] != 0){
				sprintf(tbuf, "%d-%d-%d", (int)(dp->data[2]), 
						(int)(dp->data[3]), (int)(dp->data[1])+1900);
				year = tbuf;
			} else {
				sprintf(tbuf, "%d", (int)(dp->data[1])+1900);
				year = tbuf;
			}
		}
		else
			year = dp->str; 
		diff = LabelCopyExtra(buf, year, buflen, " (", ") ");
		buflen -= diff; buf += diff;
	}

	if ((title != NULL) && (titleunique == NULL))
		titleunique = (CharPtr)(title->data.ptrvalue);

	if (title2 == NULL)
	{
		if (title != NULL)
			title2 = (CharPtr)(title->data.ptrvalue);
			
	}

	if (title2 != NULL)
	{
		if (cbp != NULL)
			title1 = "(in) ";

		diff = LabelCopyExtra(buf, title2, buflen, title1, " ");
		buflen -= diff; buf += diff;
	}

	if (volume != NULL)
	{
		if (part_sup != NULL)
			title1 = part_sup;
		else
			title1 = ":";
			
		diff = LabelCopyExtra(buf, volume, buflen, NULL, title1);
		buflen -= diff; buf += diff;
		if (part_sup != NULL)
		{
			diff = LabelCopyExtra(buf, ":", buflen, NULL, NULL);
			buflen -= diff; buf += diff;
		}
	}

	if (issue != NULL)
	{
		if (part_supi != NULL)
			title1 = part_supi;
		else
			title1 = ")";
			
		diff = LabelCopyExtra(buf, issue, buflen, "(" , title1);
		buflen -= diff; buf += diff;
		if (part_supi != NULL)
		{
			diff = LabelCopyExtra(buf, ")", buflen, NULL, NULL);
			buflen -= diff; buf += diff;
		}
	}

	if (pages != NULL)
	{
		diff = LabelCopy(buf, pages, buflen);
		buflen -= diff; buf += diff;
	}
     
    if (unpublished)
    {
    	diff = LabelCopy(buf, "Unpublished", buflen);
    	buflen -= diff; buf += diff;
    }

	if (unique)  /* put on unique tag made from title */
	{
		done = FALSE;
		i=0;
		if (titleunique != NULL && *titleunique != '\0')
		{
			while ((! done) && (i < 40))
			{
				tbuf[i] = *titleunique;
				i++;
				while (! IS_WHITESP(*titleunique))
				{
					titleunique++;
					if (*titleunique == '\0')
					{
						done = TRUE;
						break;
					}
				}
				while (IS_WHITESP(*titleunique))
				{
					titleunique++;
					if (*titleunique == '\0')
					{
						done = TRUE;
						break;
					}
				}
			}
		}
		tbuf[i] = '\0';
		diff = LabelCopyExtra(buf, tbuf, buflen, "|" , NULL);
		buflen -= diff; buf += diff;
	}

    
	return (len - buflen);
}