Exemplo n.º 1
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;
}
Exemplo n.º 2
0
/*****************************************************************************
*
*   PrintTemplateSetPtr PrintTemplateSetLoad()
*       loads PrintTemplates
*       If path== NULL, looks for "prt.prt" in the "data" directory
*
*****************************************************************************/
static Boolean PrintTemplateSetLoadInt ( CharPtr path, Boolean verbose )
{
	AsnIoPtr aip;
	FILE *f;
	Boolean retval;
	Char filename [80];
	Char fullpath [PATH_MAX];
	CharPtr ptr;
	ErrSev lastLevel;

	aip = NULL;
	if (path != NULL && *path != '\0' && StringRChr (path, DIRDELIMCHR) != NULL) {
		StringNCpy (fullpath, path, sizeof (fullpath) - 1);
		if ((aip = AsnIoOpen (fullpath, "r")) == NULL) {
		    if (verbose) {
	    		ErrPost(CTX_NCBIOBJ, 1, "Couldn't open [%s]", fullpath);
		    }
			return FALSE;
		}
	} else {
		if (path != NULL && *path != '\0') {
			StringNCpy (filename, path, sizeof (filename) - 1);
		} else {
			StringCpy (filename, "prt.prt");
		}
		ProgramPath (fullpath, sizeof (fullpath) - 1);
		ptr = StringRChr (fullpath, DIRDELIMCHR);
		if (ptr != NULL) {
			*ptr = '\0';
		}
		FileBuildPath (fullpath, NULL, filename);
		/* silence SEV_INFO errors from FileOpen() */
		if ((lastLevel = ErrGetMessageLevel()) < SEV_WARNING)
			ErrSetMessageLevel (SEV_WARNING);
		if ((f = FileOpen (fullpath, "r")) == NULL) {
			ErrSetMessageLevel (lastLevel);
			if (FindPath ("NCBI", "NCBI", "DATA", fullpath, sizeof (fullpath) - 1)) {
				FileBuildPath (fullpath, NULL, filename);
				if ((aip = AsnIoOpen (fullpath, "r")) == NULL) {
				    if (verbose) {
					    ErrPost(CTX_NCBIOBJ, 1, "Couldn't open [%s]", fullpath);
				    }
					return FALSE;
				}
			} else {
			    if (verbose) {
			    	ErrPost(CTX_NCBIOBJ, 1, "FindPath failed in PrintTemplateSetLoad - ncbi configuration file missing or incorrect");
			    }
				return FALSE;
			}
		} else {
			ErrSetMessageLevel (lastLevel);
			FileClose (f);
			if ((aip = AsnIoOpen(fullpath, "r")) == NULL) {
			    if (verbose) {
				    ErrPost(CTX_NCBIOBJ, 1, "Couldn't open [%s]", fullpath);
			    }
				return FALSE;
			}
		}
	}

    retval = PrintTemplateSetAsnRead(aip);

    AsnIoClose(aip);
    return retval;
}