Esempio n. 1
0
static void ValidateOneFile (
  CharPtr directory,
  CharPtr base,
  CharPtr suffix,
  SeqEntryPtr sep
)

{
  Char            file [FILENAME_MAX], path [PATH_MAX];
  ErrSev          oldErrSev;
  ValidStructPtr  vsp;

  StringNCpy_0 (path, directory, sizeof (path));
  sprintf (file, "%s.%s", base, suffix);
  FileBuildPath (path, NULL, file);

  ErrSetOptFlags (EO_LOGTO_USRFILE);
  ErrSetLogfile (path, ELOG_APPEND | ELOG_NOCREATE);

  vsp = ValidStructNew ();
  if (vsp != NULL) {
    vsp->useSeqMgrIndexes = TRUE;
    vsp->suppressContext = TRUE;
    oldErrSev = ErrSetMessageLevel (SEV_NONE);
    ValidateSeqEntry (sep, vsp);
    ValidStructFree (vsp);
    ErrSetMessageLevel (oldErrSev);
  }

  ErrSetLogfile (NULL, ELOG_APPEND | ELOG_NOCREATE);
  ErrClearOptFlags  (EO_LOGTO_USRFILE);
}
Esempio n. 2
0
BEDataPtr BEMakeCLParam(void)
{
    BEDataPtr pBdata;
    FILE *fd;

    if (!GetArgs ("qserver", NUMARGS, BE_args))
        return NULL;
    
    if(!ErrSetLogfile (BE_args[7].strvalue, ELOG_APPEND))
        exit(1);
    
    pBdata = (BEDataPtr)MemNew(sizeof(BEData));

    pBdata->database      = BE_args[0].intvalue;
    pBdata->format        = BE_args[1].intvalue;
    pBdata->allset        = BE_args[2].intvalue;
    pBdata->html          = (Uchar) BE_args[3].intvalue;
    pBdata->query         = StringSave(BE_args[4].strvalue);

    if(BE_args[5].strvalue != NULL)
        pBdata->uids = StringSave(BE_args[5].strvalue);
    else if(BE_args[4].strvalue == NULL) {
        fd = FileOpen(BE_args[6].strvalue, "r");
        pBdata->uids = WWWReadFileInMemory(fd, 0, FALSE);
        FileClose(fd);
    }

    pBdata->commandline   = TRUE;

    if(pBdata->query == NULL && pBdata->uids == NULL) {
        MemFree(pBdata);
        ErrPostEx(SEV_ERROR, 88, 0, 
                  "Error in reading parameters. "
                  "Please check, that query string was set\n");
        return NULL;
    }

    return pBdata;
}
Esempio n. 3
0
int
#endif
main(int argc, char *argv[])
{
  Nlm_Int2 retval;

  Nlm_SetupArguments(argc, argv);

#ifdef MSC_VIRT
  if ( !_vheapinit(0, 1250, _VM_ALLSWAP) )
    {
      ErrPost(CTX_NCBIOBJ, 1, "Can't open virtual memory");
      return 1;
    }
#endif

  /* Initialize connection library's logger, registry and lock */
  CONNECT_Init(0);

  retval = Nlm_Main();

  NlmThreadJoinAll();

  Nlm_FreeConfigStruct();
  ErrSetLogfile(NULL, 0);
  Nlm_ReleaseAppContext();

#ifdef MSC_VIRT
  _vheapterm();
#endif

  NlmThreadDestroyAll();

#if   defined(OS_MSWIN)
  return retval;
#elif defined(OS_UNIX) || defined(OS_VMS)
  exit( retval );
#endif
}
Esempio n. 4
0
Int2 Main(void)
{
  ValNodePtr vnp2 = NULL, vnp = NULL;
  CharPtr pchar = NULL;
  Int4 i = 0;
  CharPtr pi = NULL;

  ErrSetOptFlags(EO_LOG_SEVERITY | EO_LOG_CODES | EO_LOG_FILELINE | EO_LOG_USRFILE);
  ErrSetLogfile("goquerylog", ELOG_BANNER);
  ErrSetLogLevel(SEV_INFO);
  ErrSetMessageLevel(SEV_MAX);	

  /*GODB_InitCodeBase();
  GODB_OpenAllDBs();*/

  if(!SHoundInit(FALSE, "goquery"))
  {
    printf("Cannot open SeqHound.\n");
    return 1;
  }

  printf("Starting the query\n");
  /*GODB_PrintAllRecords();*/

  printf("Children of 7612\n");
  vnp = SHoundGODBGetChildrenOf(7612);
  PrintValNodeOfInt(vnp);
  ValNodeFree(vnp);

  printf("Children of 4907\n");
  vnp = SHoundGODBGetChildrenOf(4907);
  PrintValNodeOfInt(vnp);
  ValNodeFree(vnp);

  printf("Children of 5381\n");
  vnp = SHoundGODBGetChildrenOf(5381);
  PrintValNodeOfInt(vnp);
  ValNodeFree(vnp);

  printf("Parent of 5381\n");
  vnp = SHoundGODBGetParentOf(5381);
  PrintValNodeOfInt(vnp);
  ValNodeFree(vnp);

  printf("Parent of 5367\n");
  vnp = SHoundGODBGetParentOf(5367);
  PrintValNodeOfInt(vnp);
  ValNodeFree(vnp);

  printf("Parent of 16883\n");
  vnp = SHoundGODBGetParentOf(16883);
  PrintValNodeOfInt(vnp);
  ValNodeFree(vnp);

  printf("Name of 7625\n");
  pchar = SHoundGODBGetNameByID(7625);
  printf("%s\n", IsNullStr(pchar));
  MemFree(pchar);

  printf("Name of 16882\n");
  pchar = SHoundGODBGetNameByID(16882);
  printf("%s\n", IsNullStr(pchar));
  MemFree(pchar);

  printf("Name of 15412\n");
  pchar = SHoundGODBGetNameByID(15412);
  printf("%s\n", IsNullStr(pchar));
  MemFree(pchar);

  printf("All ancestors of 7627\n");
  vnp2 = SHoundGODBGetAllAncestors(7627);
  PrintValNodeOfInt(vnp2);
  ValNodeFree(vnp2);

  printf("All ancestors of 5141\n");
  vnp2 = SHoundGODBGetAllAncestors(5141);
  PrintValNodeOfInt(vnp2);
  ValNodeFree(vnp2);

  printf("All children of 7627\n");
  vnp2 = SHoundGODBGetAllChildren(7627);
  PrintValNodeOfInt(vnp2);
  ValNodeFree(vnp2);

  printf("All children of 16787\n");
  vnp2 = SHoundGODBGetAllChildren(16787);
  PrintValNodeOfInt(vnp2);
  ValNodeFree(vnp2);

  printf("Getting those records with EC\n");
  vnp2 = SHoundGODBGetRecordByReference("EC");
  PrintValNodeOfInt(vnp2);
  ValNodeFree(vnp2);

  printf("Getting those records with ISBN\n");
  vnp2 = SHoundGODBGetRecordByReference("ISBN");
  PrintValNodeOfInt(vnp2);
  ValNodeFree(vnp2);

  printf("Geting classification\n");
  pi = SHoundGODBGetClassification(5935);
  printf("%s\n", IsNullStr(pi));

  ErrPostEx(SEV_INFO, 0, 0, "Done.");
  /*GODB_InitUndoCodeBase();*/
  SHoundFini();
  return 0;

}
Esempio n. 5
0
Int2 Main()
{
    PMSD  pmsdRoot = NULL;

    static char valfilein[PATH_MAX];
    Int2    iDotLen = 0;
	AsnIoPtr aip=NULL;
	NcbiMimeAsn1Ptr nmap=NULL;
	BiostrucPtr bsp=NULL;
	BiostrucSeqPtr bssp=NULL;
	PDNMS pdnmsModelstruc = NULL;
	ErrSev esMsg,esLog,esFatal;
	PDNML pdnmlModel;
	PMLD pmldThis;
	Boolean isMime = FALSE;
	Int4 iModels = 0, iNCBImodel = 0, iPDBmodel = 0, iAscii = 0;


    
/* Initialize MMDB-API */
        ErrSetLogfile("error_strSummary.log", ELOG_APPEND|ELOG_BANNER);
	ErrSetOptFlags(EO_SHOW_SEVERITY|EO_SHOW_CODES|EO_LOG_FILELINE|EO_SHOW_USERSTR|EO_SHOW_ERRTEXT|EO_BEEP|EO_WAIT_KEY|EO_LOGTO_USRFILE);

	if (!GetArgs("strSummary  reports on what is inside .val or .cn3 or .prt file to stdout.\nCaution - will not work on Biounits downloaded from NCBI, use Asymmetric Units\n",3,Rargs))
		return 1;


        /* we use exact filenames and extensions to avoid confusion */

	
        StringCpy(valfilein, Rargs[0].strvalue);
        if (FileLength(valfilein) == 0) 
	  {
			ErrPostEx(SEV_FATAL,13,1,"Unable to find input file %s",Rargs[0].strvalue);
			return 13;	
       	 }

	if (!OpenMMDBAPI(0,NULL)) {
		ErrPostEx(SEV_FATAL,12,1,"Unable to open MMDBAPI, check for missing bstdt.val dictionary file.");
		return 12;
	}
	



/* load an ASN.1 file *.val or *.c3d or *.prt write out Biostruc only */

	aip=AsnIoOpen(valfilein,"rb");
	if (aip==NULL) {
		
		ErrPostEx(SEV_FATAL,11,1,"Unable open ASN.1 stream in file %s",valfilein);
			return 11;
	}

/* first try biostruc load */
/* 	printf("try biostruc\n");  */
	esMsg=ErrGetMessageLevel();
	esLog=ErrGetLogLevel();
	esFatal=ErrGetFatalLevel();
        ErrSetMessageLevel(SEV_MAX);
        ErrSetLogLevel(SEV_MAX);
  	ErrSetFatalLevel(SEV_MAX);
	
 	bsp=BiostrucAsnRead(aip,NULL);
	AsnIoClose(aip);

  	ErrSetMessageLevel(esMsg);
  	ErrSetLogLevel(esLog);
  	ErrSetFatalLevel(esFatal);

	if (bsp == NULL) { /* try ascii */
		aip = AsnIoOpen(valfilein,"r");
		if (aip==NULL) {
			ErrPostEx(SEV_FATAL,10,1,"Unable open binary or ascii ASN.1 from file %s",valfilein);
			return 10;
		}

		esMsg=ErrGetMessageLevel();
		esLog=ErrGetLogLevel();
		esFatal=ErrGetFatalLevel();
     	 	ErrSetMessageLevel(SEV_MAX);
	        ErrSetLogLevel(SEV_MAX);
	  	ErrSetFatalLevel(SEV_MAX);
	
	 	bsp=BiostrucAsnRead(aip,NULL);
		AsnIoClose(aip);

	  	ErrSetMessageLevel(esMsg);
  		ErrSetLogLevel(esLog);
  		ErrSetFatalLevel(esFatal);
		if (bsp) iAscii = 1;


	}



	if (bsp==NULL) {
/*		printf("try mime binary\n"); */
		/* then try NCBIMime load */
		aip=NULL;
		aip=AsnIoOpen(valfilein,"rb");
  		ErrSetMessageLevel(SEV_MAX);
  		ErrSetLogLevel(SEV_MAX);
  		ErrSetFatalLevel(SEV_MAX);

		nmap=NcbiMimeAsn1AsnRead(aip,NULL);

  		ErrSetMessageLevel(esMsg);
  		ErrSetLogLevel(esLog);
  		ErrSetFatalLevel(esFatal);
		AsnIoClose(aip);

		if (nmap == NULL) {
/*			printf("try mime ascii\n"); */
			aip=AsnIoOpen(valfilein,"r");
  			ErrSetMessageLevel(SEV_MAX);
  			ErrSetLogLevel(SEV_MAX);
  			ErrSetFatalLevel(SEV_MAX);

			nmap=NcbiMimeAsn1AsnRead(aip,NULL);

  			ErrSetMessageLevel(esMsg);
  			ErrSetLogLevel(esLog);
  			ErrSetFatalLevel(esFatal);
			AsnIoClose(aip);
			if (nmap) iAscii = 1;
		}

        	if (nmap!=NULL) {
		/* got an NCBI mime */
			if (nmap->choice!=NcbiMimeAsn1_strucseq && nmap->choice!=NcbiMimeAsn1_strucseqs) {
				/* wrong MIME type */
				nmap=NcbiMimeAsn1Free(nmap);
		    		ErrPostEx(SEV_ERROR,9,1,"MIME-type wrapper is not a strucseq or strucseqs - no Biostruc to report in:  %s",valfilein);
				return 9;
			}
				isMime = TRUE;
			/* unwrap the mime and leave the bsp for PDB conversion */
				bssp=(BiostrucSeqPtr)(nmap->data.ptrvalue);
				bsp=bssp->structure;
                		bssp->structure = NULL;
/* may want to report on contents of wrapper ... */
				nmap=NcbiMimeAsn1Free(nmap); /* discard the wrapper */
				nmap = NULL;
				bssp = NULL;
			}
		}

	if (bsp == NULL) {
	    	ErrPostEx(SEV_ERROR,8,1,"No Biostruc in files to report in: %s",valfilein);
				return 8;
	}
	

        pdnmsModelstruc=MakeAModelstruc(bsp);
	if (pdnmsModelstruc==NULL) {
		ErrPostEx(SEV_ERROR,7,1,"Unable to convert Biostruc to Modelstruc");
		return 7;
	}

 	pmsdRoot=(PMSD)(pdnmsModelstruc->data.ptrvalue);

	if (pmsdRoot==NULL) {
		ErrPostEx(SEV_ERROR,6,1,"Internal error.");
		return 6;
	}

/* OK, Ready to Start Reporting */

	printf("Filename: %s\n", valfilein);
if (Rargs[1].intvalue == FALSE) {

        if (iAscii) printf("ASCII Asn.1 (.prt) ");
	else printf("Binary Asn.1 (.val) ");
	if (isMime) printf("Entry Point: NCBIMime\n");
	else printf("Entry Point: Biostruc\n");


        if (pmsdRoot->pcPDBName != NULL) printf("PDB code: %s\n",pmsdRoot->pcPDBName);
        printf("MMDB Id: %d\n", (int) pmsdRoot->iMMDBid);

	printf("Name: %s\n",GetStrucStrings(pdnmsModelstruc, LONG_NAME));
	printf("PDB Class: %s\n",GetStrucStrings(pdnmsModelstruc, PDB_CLASS));
	printf("PDB Source: %s\n",GetStrucStrings(pdnmsModelstruc, PDB_SOURCE)); 
	
	
	pdnmlModel=pmsdRoot->pdnmlModels;
	while (pdnmlModel) {
		iModels++;
		pmldThis=(PMLD)(pdnmlModel->data.ptrvalue);
		if (pmldThis->iType==Model_type_ncbi_all_atom) {
		 iNCBImodel = pdnmlModel->choice;
		}
		if (pmldThis->iType==Model_type_pdb_model) {
		 iPDBmodel = pdnmlModel->choice;
		}
		pdnmlModel=pdnmlModel->next;
	}

	printf("Number of Models: %d\n",iModels);
	if(iNCBImodel) printf("NCBI All Atom Model: %d\n",iNCBImodel); 
	if (iPDBmodel) printf("PDB All Atom Model: %d\n",iPDBmodel);
	if (pmsdRoot->pDictLocal) printf("Has Local Chemical Graph Dictionary\n");
        printf("Number of Molecules: %d\n", (int) pmsdRoot->iMolCount); /* number of molecules */
  	printf("Number of Objects: %d\n",(int)  pmsdRoot->iObjCount); /* number of objects */
   	printf("Number of Density Sets: %d\n",(int) pmsdRoot->iDensCount); /* number of densities */
        printf("Number of Inter-Molecule Bonds: %d\n", (int) pmsdRoot->iIMBCount); 
	if (Rargs[2].intvalue == TRUE) {
       		printf("\n\nRAMACHANDRAN Angles for all Proteins:\n");
       		if (iNCBImodel) {
       			printf("NCBI All Atom Coordinate Model Number %d\n\nChain, AA, Num, Phi, Psi\n",iNCBImodel); 
			WriteStdoutRamaOneModel(pmsdRoot, iNCBImodel );
		}
       		else if (iPDBmodel) {
       			printf("PDB All Atom Coordinate Model Number %d:\n\nChain, AA, Num, Phi, Psi\n",iPDBmodel); 
			WriteStdoutRamaOneModel(pmsdRoot, iPDBmodel );
		}
	}
}
        printf("\n\n");
/* Output FASTA for each chain and dump het list - oldie but goodie code ! */
	WriteFASTASeqHet(pdnmsModelstruc, stdout);
      

/* Shut Down MMDB-API */
/* All Modelstrucs remaining are freed in CloseMMDB-API() */
	CloseMMDBAPI();	
 	return 0;
}
Esempio n. 6
0
Int2 Main(void)
{
    WWWInfoPtr info;
    WWWErrorCode error;
    BEDataPtr pBdata;
    Int4 count;
    Uint4 *ids;
    Char tmp[512];

    if((error = WWWReadPosting(&info)) != WWWErrOk) {
        ErrPostEx(SEV_FATAL, 88, 0, "Error in processing WWW request");
        return 1;
    }

    if(WWWGetMethod(info) == COMMAND_LINE) {
        WWWInfoFree(info);
        
        if((pBdata = BEMakeCLParam()) == NULL)
            return 1;
        
    } else {
        
        if(!ErrSetLogfile (QSRV_LOGFILE_STD_NAME, ELOG_APPEND))
            return 1;
        
        if((pBdata = BEMakeWWWParam(info)) == NULL) {
            printf("Content-type: text/html\n\n");
            printf("QSRV_STATUS 802 Invalid input parameters <PRE><BR>\n");
            fflush(stdout);
            
            ErrPostEx(SEV_ERROR, 88, 0, 
                      "Error in reading parameters. "
                      "Please check, that query string was set\n");
            return 1;
        }
    }

    if(!pBdata->commandline) {
        if(pBdata->savetodisk) 
            printf("Content-type: chemical/seq-%s-genbank\n\n", 
                   pBdata->database == 0 ? "na" : "aa");
        else {
            printf("Content-type: text/html\n\n");
            printf("<HTML><HEADER><TITLE>Batch Entrez results"
                   "</TITLE></HEADER><PRE>\n");
        }
    }

    if (! ID1BioseqFetchEnable("Nbatch", TRUE)) {
        printf("Cannot initialize ID1\n");
        return 1;
    }

    if(pBdata->html) {
        init_www(); /* initializing WWW mode */
        head_tail_ff(NULL, BatchHead, BatchTail);
      
    }

    SeqEntryLoad();

    switch(pBdata->request_type) {
    case REQ_DEFAULT:
        if(pBdata->uids == NULL) {
            count = BEGetUidsFromQuery(pBdata->query, &ids, 
                               pBdata->database == 0, /* Nucleotide ? */
                               FALSE);
        } else {
            count = BE_ReadIds(pBdata, &ids);
        }
        break;
    case REQ_ADVANCED_QUERY:
    case REQ_ORGANISM:
        count = BEGetUidsFromQuery(pBdata->query, &ids, 
                                   pBdata->database == 0, /* Nucleotide ? */
                                   FALSE);
        break;
    case REQ_LIST_OF_GIS:
        count = BE_ReadIds(pBdata, &ids);
        break;    
    }
    pBdata->count = count;
    
    QSRVWriteLogInfo(pBdata);
    
    if(count < 0) {
        if(pBdata->commandline)
            ErrPostEx(SEV_ERROR, 0, count, "Error in searching the database");
        else
            printf("QSRV_STATUS %d Error in searching database\n", count);
        return 1;
    }
    
    if(count == 0) {
        if(pBdata->commandline)
            ErrPostEx(SEV_INFO, 0,0, "No entries found");
        else
            printf("QSRV_STATUS 901 OK No entries found\n", count);
        return 1;
    }
    
    if((count > 20000 && pBdata->format == F_GEN) ||
       (count > 100000 && pBdata->format != F_GILIST)) {

        if(pBdata->commandline)
            ErrPostEx(SEV_WARNING, 0,0, "Number of sequences %d exceed limit", 
                      count);
        else
            printf("QSRV_STATUS 803 Error Number of sequences %d "
                   "exceed limit\n", count);
        
        pBdata->format = F_GILIST;
    }

    if(!pBdata->noheader && !pBdata->commandline) 
        printf("QSRV_STATUS 900 OK: %d entr%s found <PRE><BR>\n", 
               count, count == 1? "y" : "ies");

    fflush(stdout);
    
    /* Printing results */
    
    BEPrintIds(pBdata, ids, count);
    
    /* Clearing memory */

    MemFree(ids);
    BEFreeCLParam(pBdata);

    return 0;
}