Exemple #1
0
/***************************************************************************
*
*  SPI_ReadFeatureTable reads in a tab-delimited file and converts it
*  to feature information:
*
*  sequence id	name of feature		start	stop
*  NM_004377.1	repetitive_region	12	40
*
*  Masking and other feature information for all mRNAs should be in the
*  same file; ids not in the mRNA list or unknown feature names will be
*  ignored.
*
***************************************************************************/
static void SPI_ReadFeatureTable(FILE *ifp, SPI_bsinfoPtr spim_head)
{
   Char           c;
   CharPtr        fields[5];
   Boolean        found;
   Char           line[60];
   Int4           i;
   CharPtr        ptr;
   SeqIdPtr       sip;
   SeqLocPtr      slp;
   SPI_bsinfoPtr  spim;
   CharPtr        str;
   ValNode        vn;

   str = ReadALine(line, sizeof(line), ifp);
   while (str != NULL)
   {
      ptr = strtok(str, " \t");
      for (i=0; i<4; i++)
      {
         fields[i] = StringSave(ptr);
         ptr = strtok(NULL, " \t");
      }
      if (fields[1] != NULL && !StrCmp(fields[1], "repetitive_region"))
      {
         c = *fields[0];
         if (IS_ALPHA(c))
            sip = SeqIdFromAccessionDotVersion(fields[0]);
         else
         {
            vn.choice = SEQID_GI;
            vn.data.intvalue = atoi(fields[0]);
            vn.next = NULL;
            sip = &vn;
         }
         spim = spim_head;
         found = FALSE;
         while (!found && spim != NULL)
         {
            if (SeqIdIn(sip, spim->bsp->id) == TRUE)
               found = TRUE;
            else
               spim = spim->next;
         }
         if (found)
         {
            slp = SeqLocIntNew(atoi(fields[2]), atoi(fields[3]), Seq_strand_both, spim->bsp->id);
            slp->next = spim->lcaseloc;
            spim->lcaseloc = slp;
         }
      }
      str = ReadALine(line, sizeof(line), ifp);
   }
}
Exemple #2
0
void RegressLoad()// test load for a server
{
	
	FILE* in = fopen("REGRESS/bigregress.txt","rb");
	if (!in) return;
	
	// treat each invocation as a new judge
	FILE* in1 = fopen("load.txt","rb");
	int id = 0;
	char buffer[8000];
	if (in1)
	{
		fread(buffer,1,100,in1);
		fclose(in1);
		id = atoi(buffer);
	}
	++id;
	FILE* out = fopen("load.txt","wb");
	fprintf(out,"%d\r\n",id);
	fclose(out);

	printf("\r\n\r\n** Load %d launched\r\n",id);
	char data[MAX_WORD_SIZE];
	char from[100];
	sprintf(from,"%d",id);
	char* bot = "";
	sprintf(logbuffer,"log-%s.txt",from);
	unsigned int msg = 0;
	unsigned int volleys = 0;
	unsigned int longVolleys = 0;
	unsigned int xlongVolleys = 0;

	int maxTime = 0;
	int cycleTime = 0;
	int currentCycleTime = 0;
	int avgTime = 0;

	// message to server is 3 strings-   username, botname, null (start conversation) or message
	echo = 1;
	char* ptr = data;
	strcpy(ptr,from);
	ptr += strlen(ptr) + 1;
	strcpy(ptr,bot);
	ptr += strlen(ptr) + 1;
	*buffer = 0;
	int counter = 0;
	while (1)
	{

		if (!ReadALine(revertBuffer+1,in)) break; // end of input
		// when reading from file, see if line is empty or comment
		char word[MAX_WORD_SIZE];
		char* at = SkipWhitespace(revertBuffer+1); 
		ReadCompiledWord(at,word);
		if (!*word || *word == '#' || *word == ':') continue;

		strcpy(ptr,revertBuffer+1);
		try 
		{
			unsigned int len = (ptr-data) + 1 + strlen(ptr);
			++volleys;
			clock_t start_time = ElapsedMilliseconds();

			TCPSocket *sock = new TCPSocket(serverIP, port);
			sock->send(data, len );
	
			int bytesReceived = 1;              // Bytes read on each recv()
			int totalBytesReceived = 0;         // Total bytes read
			char* base = ptr;
			while (bytesReceived > 0) 
			{
				// Receive up to the buffer size bytes from the sender
				bytesReceived = sock->recv(base, MAX_WORD_SIZE);
				totalBytesReceived += bytesReceived;
				base += bytesReceived;
			}
			clock_t end_time = ElapsedMilliseconds();
	
			delete(sock);
			*base = 0;
			int diff = end_time - start_time;
			if (diff > maxTime) maxTime = diff;
			if ( diff > 2000) ++longVolleys;
			if (diff > 5000) ++ xlongVolleys;
			currentCycleTime += diff;

			// chatbot replies this
			printf("real:%d avg:%d max:%d volley:%d 2slong:%d 5slong:%d %s => %s\r\n",diff,avgTime,maxTime,volleys,longVolleys,xlongVolleys,ptr,base);
		}
		catch(SocketException e) { printf("failed to connect to server\r\n"); exit(0);}
		if (++counter == 100) 
		{
			counter = 0;
			cycleTime = currentCycleTime;
			currentCycleTime = 0;
			avgTime = cycleTime / 100;
		}
		else msg++;
	}
}
Exemple #3
0
static void SPI_GetSpliceInfo(SPI_OptionsPtr spot, FILE *sfp, Boolean donor)
{
   Char               line[1000];
   CharPtr            ptr = NULL;
   SPI_SpliceInfoPtr  ssp = NULL;
   SPI_SpliceInfoPtr  ssp_head = NULL;
   SPI_SpliceInfoPtr  ssp_prev = NULL;
   CharPtr            str = NULL;
   enum { _a = 0, _c = 1, _g = 2, _t = 3};
   int base = 0;

   if (sfp == NULL){
       printf("Matrix file not found\n");
       return;
   }
   /* read the first line which is the column dividing donor / acceptor
      sequencs ('GT', 'AG') should just be a single number */   
   str = ReadALine(line, sizeof(line), sfp);
   if (donor){
       spot->dsplicejunc = atoi(str);
   }
   else {
       spot->asplicejunc = atoi(str);
   }
   
   for (base = 0; base < (_t + 1); ++base){       
       str = ReadALine(line, sizeof(line), sfp);
       switch (base){
       case _a:
           for (ptr = strtok(str, "\t"); ptr != NULL; 
                ptr = strtok(NULL, "\t")){
               ssp = (SPI_SpliceInfoPtr)MemNew(sizeof(SPI_SpliceInfo));
               ssp->a = atof(ptr);
               if (ssp_prev != NULL){
                   ssp_prev->next = ssp;
                   ssp_prev = ssp;
               }
               else {
                   ssp_head = ssp_prev = ssp;
                   if (donor){
                       spot->dssp_head = ssp_head;
                   }
                   else {
                       spot->assp_head = ssp_head; 
                   }
               }
           };
           break;
       case _c:
       case _t:
       case _g:
           for (ssp = ssp_head, ptr = strtok(str, "\t"); ptr != NULL && ssp != NULL;
                ptr = strtok(NULL, "\t"), ssp = ssp->next){
               switch (base){
               case _c:
                   ssp->c = atof(ptr);
                   break;
               case _g:
                   ssp->g = atof(ptr);
                   break;
               case _t:
                   ssp->t = atof(ptr);
                   break;
               }
           }
           if ((ptr != NULL && ssp == NULL) || 
               (ssp != NULL && ptr == NULL)){
               switch (base){
               case _c:
                   donor 
                       ? ErrPostEx(SEV_ERROR, 0, 0,
                                   "Donor atrix file error -- C matrix column number is different than preceding.")
                       : ErrPostEx(SEV_ERROR, 0, 0,
                                   "Acceptor matrix file error -- C matrix column number is different than preceding.");
                       break;
               case _g:
                   donor 
                       ? ErrPostEx(SEV_ERROR, 0, 0,
                                   "Donor matrix file error -- G matrix column number is different than preceding.")
                       : ErrPostEx(SEV_ERROR, 0, 0,
                                   "Acceptor matrix file error -- G matrix column number is different than preceding.");
                       break;
               case _t:
                   donor
                       ? ErrPostEx(SEV_ERROR, 0, 0,
                                   "Donor matrix file error -- T matrix column number is different than preceding.")
                       : ErrPostEx(SEV_ERROR, 0, 0,
                                   "Acceptor matrix file error -- T matrix column number is different than preceding.");
                       break;
               }
           }
       }
   }
}
Exemple #4
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;
}
Exemple #5
0
static Boolean LIBCALLBACK SecondVecScreenCallback (
  CONN conn,
  Nlm_VoidPtr userdata,
  EIO_Status  status
)

{
  VQueuePtr  cqp;
  FILE       *fp;
  Char       line [256];
  Char       path [PATH_MAX];
  CharPtr    rid;
  CharPtr    sttus;
  CharPtr    str;
  Boolean    success = FALSE;
  Boolean    waiting = FALSE;

  /* look for waiting, failure, or success */

  cqp = (VQueuePtr) userdata;

  TmpNam (path);
  fp = FileOpen (path, "w");
  QUERY_CopyResultsToFile (conn, fp);
  FileClose (fp);

  fp = FileOpen (path, "r");
  str = ReadALine (line, sizeof (line), fp);
  while (str != NULL) {
    if (! StringHasNoText (line)) {
      if (line [0] == '>') {
        if (StringNICmp (line, ">Vector", 7) == 0) {
          rid = StringStr (line, "RID: ");
          if (rid != NULL) {
            rid += 5;
            sttus = StringStr (rid, " Status: ");
            if (sttus != NULL) {
              *sttus = '\0';
              sttus += 9;
              if (StringCmp (cqp->rid, rid) != 0) {
                ErrPostEx (SEV_ERROR, 0, 0, "RID mismatch '%s' vs '%s'", cqp->rid, rid);
                cqp->done = TRUE;
              } else if (StringStr (sttus, "FAILED") != NULL) {
                cqp->done = TRUE;
              } else if (StringStr (sttus, "unknown") != NULL) {
                ErrPostEx (SEV_ERROR, 0, 0, "RID unknown '%s'", rid);
                cqp->done = TRUE;
              } else if (StringStr (sttus, "SUCCESS") != NULL) {
                success = TRUE;
              } else if (StringStr (sttus, "WAITING") != NULL) {
                waiting = TRUE;
                /*
                Message (MSG_POST, "WAITING");
                */
              }
            }
          }
        } else if (StringNICmp (line, ">Message", 8) == 0) {
          str = ReadALine (line, sizeof (line), fp);
          while (str != NULL && StringNCmp (line, "//", 2) != 0) {
            Message (MSG_POST, "%s\n", str);
            if (StringStr (line, "FAILURE") != NULL) {
              if (! waiting) {
                cqp->done = TRUE;
              }
            }
            str = ReadALine (line, sizeof (line), fp);
          }
        }
      }
    }
    str = ReadALine (line, sizeof (line), fp);
  }
  FileClose (fp);

  if (success) {
    cqp->resultproc (path, cqp->userdata, cqp->rid, cqp->seqid, success);
    cqp->done = TRUE;
  } else if (cqp->done) {
    cqp->resultproc (NULL, cqp->userdata, cqp->rid, cqp->seqid, success);
  }

  FileRemove (path);

  return TRUE;
}
Exemple #6
0
static Boolean LIBCALLBACK FirstVecScreenCallback (
  CONN conn,
  Nlm_VoidPtr userdata,
  EIO_Status  status
)

{
  VQueuePtr  cqp;
  FILE       *fp;
  Char       line [256];
  Char       path [PATH_MAX];
  CharPtr    rid;
  CharPtr    rtoe;
  CharPtr    str;
  long int   val;

  /* read rID or failure message */

  cqp = (VQueuePtr) userdata;

  TmpNam (path);
  fp = FileOpen (path, "w");
  QUERY_CopyResultsToFile (conn, fp);
  FileClose (fp);

  fp = FileOpen (path, "r");
  str = ReadALine (line, sizeof (line), fp);
  while (str != NULL) {
    if (! StringHasNoText (line)) {
      if (line [0] == '>') {
        if (StringNICmp (line, ">Vector", 7) == 0) {
          rid = StringStr (line, "RID: ");
          if (rid != NULL) {
            rid += 5;
            rtoe = StringStr (rid, " RTOE: ");
            if (rtoe != NULL) {
              *rtoe = '\0';
              rtoe += 7;
              StringNCpy_0 (cqp->rid, rid, sizeof (cqp->rid));
              if (sscanf (rtoe, "%ld", &val) == 1) {
                cqp->estTime = (time_t) val;
                cqp->secondsToWait = (Int2) val + 2;
              } else {
                cqp->secondsToWait = 15;
              }
              if (cqp->secondsToWait > 15) {
                cqp->secondsToWait = 15;
              }
              if (cqp->announceproc != NULL) {
                cqp->announceproc (rid, cqp->seqid, (Int2) val);
              }
            }
          } else if (StringStr (line, "FAILED") != NULL) {
            cqp->done = TRUE;
            if (cqp->resultproc != NULL) {
              cqp->resultproc (NULL, cqp->userdata, cqp->rid, cqp->seqid, FALSE);
            }
          }
        } else if (StringNICmp (line, ">Message", 8) == 0) {
          str = ReadALine (line, sizeof (line), fp);
          while (str != NULL && StringNCmp (line, "//", 2) != 0) {
            Message (MSG_POST, "%s\n", str);
            if (StringStr (line, "FAILURE") != NULL) {
              cqp->done = TRUE;
            }
            str = ReadALine (line, sizeof (line), fp);
          }
        }
      }
    }
    str = ReadALine (line, sizeof (line), fp);
  }
  FileClose (fp);

  FileRemove (path);

  return TRUE;
}
Exemple #7
0
static mStatus RegisterServicesInFile(const char *filePath)
{
    mStatus     status = mStatus_NoError;
    FILE *      fp = fopen(filePath, "r");
    int         junk;
    
    if (fp == NULL) {
        status = mStatus_UnknownErr;
    }
    if (status == mStatus_NoError) {
        mDNSBool good = mDNStrue;
        do {
			int         ch;
			char name[256];
			char type[256];
			const char *dom = kDefaultServiceDomain;
			char rawText[1024];
			mDNSu8  text[sizeof(RDataBody)];
			unsigned int textLen = 0;
			char port[256];

            // Skip over any blank lines.
            do ch = fgetc(fp); while ( ch == '\n' || ch == '\r' );
            if (ch != EOF) good = (ungetc(ch, fp) == ch);
            
            // Read three lines, check them for validity, and register the service.
			good = ReadALine(name, sizeof(name), fp);               
			if (good) {
				good = ReadALine(type, sizeof(type), fp);
			}
			if (good) {
				char *p = type;
				while (*p && *p != ' ') p++;
				if (*p) {
					*p = 0;
					dom = p+1;
				}
			}
			if (good) {
				good = ReadALine(port, sizeof(port), fp);
			}
			if (good) {
				good =     CheckThatRichTextNameIsUsable(name, mDNSfalse)
						&& CheckThatServiceTypeIsUsable(type, mDNSfalse)
						&& CheckThatPortNumberIsUsable(atol(port), mDNSfalse);
			}
			if (good) {
				while (1) {
					int len;
					if (!ReadALine(rawText, sizeof(rawText), fp)) break;
					len = strlen(rawText);
					if (len <= 255)
						{
						unsigned int newlen = textLen + 1 + len;
						if (len == 0 || newlen >= sizeof(text)) break;
						text[textLen] = len;
						memcpy(text + textLen + 1, rawText, len);
						textLen = newlen;
						}
					else
						fprintf(stderr, "%s: TXT attribute too long for name = %s, type = %s, port = %s\n", 
							gProgramName, name, type, port);
				}
			}
			if (good) {
				status = RegisterOneService(name, type, dom, text, textLen, atol(port));
				if (status != mStatus_NoError) {
					fprintf(stderr, "%s: Failed to register service, name = %s, type = %s, port = %s\n", 
							gProgramName, name, type, port);
					status = mStatus_NoError;       // keep reading
				}
			}
        } while (good && !feof(fp));

        if ( ! good ) {
            fprintf(stderr, "%s: Error reading service file %s\n", gProgramName, filePath);
        }
    }
    
    if (fp != NULL) {
        junk = fclose(fp);
        assert(junk == 0);
    }
    
    return status;
}
int SwitchChannel(SChannel* channel)
{
	int i=0;
#ifdef RESTORE_SCREEN_ON_ZAPPING
	int was_fullscreen = FullscreenMode;
	int old_width = window_width, old_height = window_height;
#endif
	
	if(ChunkerPlayerCore_IsRunning())
		ChunkerPlayerCore_Stop();

#ifdef PSNR_PUBLICATION
	remove("NetworkID");
#endif
	
	ChunkerPlayerGUI_SetChannelRatio(channel->Ratio);
	ChunkerPlayerGUI_SetChannelTitle(channel->Title);
	ChunkerPlayerGUI_ForceResize(channel->Width, channel->Height);

	if (!scale_with_sdl) {	//TODO: maybe move to GUI
		int w=0, h=0;
		ChunkerPlayerGUI_AspectRatioResize((float)channel->Ratio, channel->Width, channel->Height, &w, &h);
		ChunkerPlayerCore_SetupOverlay(w, h);
	} else {
		ChunkerPlayerCore_SetupOverlay(channel->Width, channel->Height);
	}
	
	if(ChunkerPlayerCore_InitCodecs(channel->VideoCodec, channel->Width, channel->Height, channel->AudioCodec, channel->SampleRate, channel->AudioChannels) < 0)
	{
		printf("ERROR, COULD NOT INITIALIZE CODECS\n");
		exit(2);
	}
	
	//reset quality info
	channel->startTime = time(NULL);
	channel->instant_score = 0.0;
	channel->average_score = 0.0;
	channel->history_index = 0;
	for(i=0; i<CHANNEL_SCORE_HISTORY_SIZE; i++)
		channel->score_history[i] = -1;
	sprintf(channel->quality, "EVALUATING...");

	StartStreamer(channel);

#ifdef RESTORE_SCREEN_ON_ZAPPING
	if(SilentMode == 0) {
		if(was_fullscreen)
			ChunkerPlayerGUI_ToggleFullscreen();
		else
		{
			ChunkerPlayerGUI_HandleResize(old_width, old_height);
		}
	}
#endif

#ifdef PSNR_PUBLICATION
	if(RepoAddress[0]!='\0')	// TODO: search for RepoAddress currently disabled on linux
	{
	    // Open Repository
	    if(repoclient)
		    repClose(repoclient);
	    repoclient=NULL;

	    repoclient = repOpen(RepoAddress,0);
	    if (repoclient == NULL)
		    printf("Unable to initialize PSNR publication in repoclient %s\n", RepoAddress);
    }
    else {
	    printf("Repository address not present in streames launch string. Publication disabled\n");
    }
#endif


#ifdef PSNR_PUBLICATION
	// Read the Network ID
	int Error=true;
	char Line1[255], Line2[255];
	while(Error)
	{
	    FILE* fp=fopen("NetworkID","r");	//TODO: better error handling needed, this could block the player if there are no write permissions
	    if(fp)
	    {
	        if(ReadALine(fp,Line1,255)!=-1)
	            if(ReadALine(fp,Line2,255)!=-1)
	            {
	                if(strcmp(Line2,"IDEnd")==0)
	                {
	                    strcpy(NetworkID,Line1);
	                    Error=false;
	                }
	            }
	        fclose(fp);
	    }
	    if(Error) usleep(100000);
	}
	
	printf("NetworkID = %s\n",NetworkID);
#endif
	
	ChunkerPlayerCore_Play();
	ChunkerPlayerGUI_ChannelSwitched();
	return 0;
}
Exemple #9
0
void ReadUserData()
{	
	*priorMessage = 0;
	tokenControl = 0;	// change nothing of the data
    chatbotFacts = factFree; 
	sprintf(readBuffer,"USERS/topic_%s_%s%s.txt",loginID,computerID,fileID);
    FILE* in = fopen(readBuffer,"rb");
	*fileID = 0;
	if ( in) // check validity stamp
	{
		ReadALine(readBuffer,in);
		if (stricmp(readBuffer,saveVersion)) // obsolete format
		{
			fclose(in);
			in = 0;
		}
	}

    if (!in) //   this is a new user
    {
		ReadNewUser(); 
		start_rejoinder_Topic = rejoinder_Topic; 
		start_Rejoinder_at = rejoinder_at; 
		char* value = GetUserVariable("$token");
		tokenControl = (*value) ? atoi(value) : (DO_INTERJECTION_SPLITTING|DO_SUBSTITUTES|DO_NUMBER_MERGE|DO_PROPERNAME_MERGE|DO_SPELLCHECK|DO_UTF8_CONVERT);
		return;
    }

	ReadTopicData(in);
 
    //   ready in recently used messages
    for (humanSaidIndex = 0; humanSaidIndex < MAX_USED; ++humanSaidIndex) 
    {
        ReadALine(humanSaid[humanSaidIndex], in);
		if (humanSaid[humanSaidIndex][0] == '#') break; // #end
    }

	for (chatbotSaidIndex = 0; chatbotSaidIndex < MAX_USED; ++chatbotSaidIndex) 
    {
        ReadALine(chatbotSaid[chatbotSaidIndex], in);
		if (chatbotSaid[chatbotSaidIndex][0] == '#') break; // #end
    }

    //   read in fact sets
    char word[MAX_WORD_SIZE];
    *word = 0;
    ReadALine(readBuffer, in); //   setControl
	ReadHex(readBuffer,setControl);
    while (ReadALine(readBuffer, in)) 
    {
        char* ptr = ReadCompiledWord(readBuffer,word);
        unsigned int setid;
        unsigned int count;
        ptr = ReadInt(ptr,setid); 
        ptr = ReadInt(ptr,count); 
        factSet[setid][0] = (FACT*) count;
        for (unsigned int i = 1; i <= count; ++i) 
        {
            if (!ReadALine(readBuffer, in)) break; 
			ptr = readBuffer;
            factSet[setid][i] = ReadFact(ptr);
        }
    }
    
    fclose(in);

	start_rejoinder_Topic = rejoinder_Topic; 
	start_Rejoinder_at = rejoinder_at; 

	//   read user facts
    char name[MAX_WORD_SIZE];
    sprintf(name,"USERS/fact_%s.txt",loginID);
    ReadFacts(name,0); 

	userFactBase = factFree;	// note waterline of facts, to see if more are added..
	// BUG -- need delete of facts to alter userFactBase also.

	char* value = GetUserVariable("$token");
	tokenControl = (*value) ? atoi(value) : (DO_INTERJECTION_SPLITTING|DO_SUBSTITUTES|DO_NUMBER_MERGE|DO_PROPERNAME_MERGE|DO_SPELLCHECK|DO_UTF8_CONVERT);
	
	// for server logging
	char* prior = (chatbotSaidIndex < 1) ? ((char*)"") : chatbotSaid[chatbotSaidIndex-1];
	strcpy(priorMessage,prior);

 }
Exemple #10
0
Int2 Main (void)

{
  AsnIoPtr    aip;
  AsnTypePtr  atp;
  FILE        *dfp = NULL;
  Boolean     do_nuc = FALSE;
  Boolean     do_prot = FALSE;
  XtraPtr     extra;
  FILE        *fp;
  GBSeq       gbsq;
  GBSet       gbst;
  Boolean     get_var;
  Char        line [256];
  Boolean     only_new;
  CharPtr     str;
  Char        xmlbuf [128];
  XtraBlock   xtra;

  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 (! SeqCodeSetLoad ()) {
    Message (MSG_FATAL, "SeqCodeSetLoad failed");
    return 1;
  }
  if (! GeneticCodeTableLoad ()) {
    Message (MSG_FATAL, "GeneticCodeTableLoad failed");
    return 1;
  }
  if (! objgbseqAsnLoad ()) {
    Message (MSG_POSTERR, "objgbseqAsnLoad failed");
    return 1;
  }

  if (! GetArgs ("gbseqget", sizeof (myargs) / sizeof (Args), myargs)) {
    return 0;
  }

  fp = FileOpen (myargs [i_argInputFile].strvalue, "r");
  if (fp == NULL) {
    return 1;
  }

  if (! StringHasNoText (myargs [d_argDateFile].strvalue)) {
    dfp = FileOpen (myargs [d_argDateFile].strvalue, "r");
    if (dfp == NULL) {
      return 1;
    }
  }

  if (GetAppParam ("NCBI", "SETTINGS", "XMLPREFIX", NULL, xmlbuf, sizeof (xmlbuf))) {
    AsnSetXMLmodulePrefix (StringSave (xmlbuf));
  }

  MemSet ((Pointer) &xtra, 0, sizeof (XtraBlock));
  MemSet ((Pointer) &gbsq, 0, sizeof (GBSeq));
  xtra.gbseq = &gbsq;
  aip = AsnIoOpen (myargs [o_argOutputFile].strvalue, "wx");

  if (aip == NULL) {
    Message (MSG_POSTERR, "AsnIoOpen failed");
    FileClose (fp);
    return 1;
  }

  only_new = (Boolean) myargs [n_argNewRecords].intvalue;
  get_var = (Boolean) myargs [v_argVariations].intvalue;

  str = myargs [m_argMolecule].strvalue;
  if (StringICmp (str, "n") == 0) {
    do_nuc = TRUE;
  } else if (StringICmp (str, "p") == 0) {
    do_prot = TRUE;
  } else if (StringICmp (str, "b") == 0) {
    do_nuc = TRUE;
    do_prot = TRUE;
  } else {
    do_nuc = TRUE;
  }

  PubSeqFetchEnable ();

  xtra.aip = aip;
  atp = AsnLinkType (NULL, AsnFind ("GBSet"));
  xtra.atp = AsnLinkType (NULL, AsnFind ("GBSet.E"));
  if (atp == NULL || xtra.atp == NULL) {
    Message (MSG_POSTERR, "AsnLinkType or AsnFind failed");
    return 1;
  }
  extra = &xtra;
  MemSet ((Pointer) &gbst, 0, sizeof (GBSet));
  AsnOpenStruct (aip, atp, (Pointer) &gbst);

  if (dfp != NULL) {
    DoQuery (fp, dfp, extra, get_var, do_nuc, do_prot);
  } else {
    str = ReadALine (line, sizeof (line), fp);
    while (str != NULL) {
      if (! StringHasNoText (str)) {
        ProcessAccession (str, extra, only_new, get_var, do_nuc, do_prot);
      }
      str = ReadALine (line, sizeof (line), fp);
    }
  }

  AsnCloseStruct (aip, atp, NULL);
  AsnPrintNewLine (aip);
  AsnIoClose (aip);

  FileClose (dfp);
  FileClose (fp);

  PubSeqFetchDisable ();

  return 0;
}
Exemple #11
0
static void DoQuery (
  FILE *fp,
  FILE *dfp,
  XtraPtr extra,
  Boolean get_var,
  Boolean do_nuc,
  Boolean do_prot
)

{
  Entrez2BooleanReplyPtr  e2br;
  Entrez2IdListPtr        e2lp;
  Entrez2RequestPtr       e2rq;
  Entrez2ReplyPtr         e2ry;
  Int4                    flags = 0;
  Int4                    i;
  Char                    line [256];
  E2ReplyPtr              reply;
  SeqEntryPtr             sep;
  CharPtr                 str;
  Uint4                   uid;

  if (get_var) {
    flags = 1;
  }

  e2rq = EntrezCreateBooleanRequest (TRUE, FALSE, "Nucleotide", NULL, 0, 0, NULL, 0, 0);
  if (e2rq == NULL) return;

  EntrezAddToBooleanRequest (e2rq, NULL, ENTREZ_OP_LEFT_PAREN, NULL, NULL, NULL, 0, 0, NULL, NULL, TRUE, TRUE);
  EntrezAddToBooleanRequest (e2rq, NULL, ENTREZ_OP_LEFT_PAREN, NULL, NULL, NULL, 0, 0, NULL, NULL, TRUE, TRUE);

  str = ReadALine (line, sizeof (line), fp);
  if (! StringHasNoText (str)) {
    EntrezAddToBooleanRequest (e2rq, NULL, 0, "ACCN", str, NULL, 0, 0, NULL, NULL, TRUE, TRUE);
  }

  while (str != NULL) {
    if (! StringHasNoText (str)) {
      EntrezAddToBooleanRequest (e2rq, NULL, ENTREZ_OP_OR, NULL, NULL, NULL, 0, 0, NULL, NULL, TRUE, TRUE);
      EntrezAddToBooleanRequest (e2rq, NULL, 0, "ACCN", str, NULL, 0, 0, NULL, NULL, TRUE, TRUE);
    }
    str = ReadALine (line, sizeof (line), fp);
  }

  EntrezAddToBooleanRequest (e2rq, NULL, ENTREZ_OP_RIGHT_PAREN, NULL, NULL, NULL, 0, 0, NULL, NULL, TRUE, TRUE);
  EntrezAddToBooleanRequest (e2rq, NULL, ENTREZ_OP_AND, NULL, NULL, NULL, 0, 0, NULL, NULL, TRUE, TRUE);
  EntrezAddToBooleanRequest (e2rq, NULL, ENTREZ_OP_LEFT_PAREN, NULL, NULL, NULL, 0, 0, NULL, NULL, TRUE, TRUE);

  str = ReadALine (line, sizeof (line), dfp);
  if (! StringHasNoText (str)) {
    EntrezAddToBooleanRequest (e2rq, NULL, 0, "MDAT", str, NULL, 0, 0, NULL, NULL, TRUE, TRUE);
  }

  while (str != NULL) {
    if (! StringHasNoText (str)) {
      EntrezAddToBooleanRequest (e2rq, NULL, ENTREZ_OP_OR, NULL, NULL, NULL, 0, 0, NULL, NULL, TRUE, TRUE);
      EntrezAddToBooleanRequest (e2rq, NULL, 0, "MDAT", str, NULL, 0, 0, NULL, NULL, TRUE, TRUE);
    }
    str = ReadALine (line, sizeof (line), dfp);
  }

  EntrezAddToBooleanRequest (e2rq, NULL, ENTREZ_OP_RIGHT_PAREN, NULL, NULL, NULL, 0, 0, NULL, NULL, TRUE, TRUE);
  EntrezAddToBooleanRequest (e2rq, NULL, ENTREZ_OP_RIGHT_PAREN, NULL, NULL, NULL, 0, 0, NULL, NULL, TRUE, TRUE);

  e2ry = EntrezSynchronousQuery (e2rq);
  e2rq = Entrez2RequestFree (e2rq);

  if (e2ry == NULL) return;
  reply = e2ry->reply;
  if (reply == NULL || reply->choice != E2Reply_eval_boolean) return;
  e2br = EntrezExtractBooleanReply (e2ry);
  if (e2br == NULL) return;

  e2lp = e2br->uids;
  if (e2lp != NULL) {
    BSSeek (e2lp->uids, 0, SEEK_SET);
    for (i = 0; i < e2lp->num; i++) {
      uid = Nlm_BSGetUint4 (e2lp->uids);
      if (uid < 1) continue;

      sep = PubSeqSynchronousQuery (uid, 0, flags);
      if (sep == NULL) continue;

      if (do_nuc) {
        DoSeqEntryToGnbk (sep, GENBANK_FMT, extra);
      }
      if (do_prot) {
        DoSeqEntryToGnbk (sep, GENPEPT_FMT, extra);
      }

      SeqEntryFree (sep);
    }
  }

  Entrez2BooleanReplyFree (e2br);
}