Sleipnir
|
00001 /***************************************************************************** 00002 * This file is provided under the Creative Commons Attribution 3.0 license. 00003 * 00004 * You are free to share, copy, distribute, transmit, or adapt this work 00005 * PROVIDED THAT you attribute the work to the authors listed below. 00006 * For more information, please see the following web page: 00007 * http://creativecommons.org/licenses/by/3.0/ 00008 * 00009 * This file is a component of the Sleipnir library for functional genomics, 00010 * authored by: 00011 * Curtis Huttenhower (chuttenh@princeton.edu) 00012 * Mark Schroeder 00013 * Maria D. Chikina 00014 * Olga G. Troyanskaya (ogt@princeton.edu, primary contact) 00015 * 00016 * If you use this library, the included executable tools, or any related 00017 * code in your work, please cite the following publication: 00018 * Curtis Huttenhower, Mark Schroeder, Maria D. Chikina, and 00019 * Olga G. Troyanskaya. 00020 * "The Sleipnir library for computational functional genomics" 00021 *****************************************************************************/ 00022 #include "stdafx.h" 00023 #include "cmdline.h" 00024 00025 static int Genes( const char*, CGenes& ); 00026 00027 int main( int iArgs, char** aszArgs ) { 00028 IBayesNet* pBN; 00029 gengetopt_args_info sArgs; 00030 CPCL PCLOut; 00031 CPCLPair PCLIn; 00032 CGenome Genome; 00033 CGenes GenesIn( Genome ), GenesEx( Genome ); 00034 size_t i, j; 00035 int iRet; 00036 vector<string> vecstrGenes, vecstrExperiments, vecstrNodes, vecstrFeatures; 00037 vector<size_t> veciGenes; 00038 ofstream ofsm; 00039 00040 if( cmdline_parser( iArgs, aszArgs, &sArgs ) ) { 00041 cmdline_parser_print_help( ); 00042 return 1; } 00043 CMeta Meta( sArgs.verbosity_arg ); 00044 00045 CBayesNetSmile BNSmile( !!sArgs.group_flag ); 00046 #ifdef PNL_ENABLED 00047 CBayesNetPNL BNPNL( !!sArgs.group_flag ); 00048 #endif // PNL_ENABLED 00049 CBayesNetFN BNFN; 00050 00051 if( sArgs.function_flag ) { 00052 if( !BNFN.Open( sArgs.input_arg ) ) { 00053 cerr << "Couldn't open: " << sArgs.input_arg << endl; 00054 return 1; } 00055 pBN = &BNFN; } 00056 else { 00057 if( !BNSmile.Open( sArgs.input_arg ) ) { 00058 cerr << "Couldn't open: " << sArgs.input_arg << endl; 00059 return 1; } 00060 #ifdef PNL_ENABLED 00061 if( sArgs.pnl_flag ) { 00062 BNSmile.Convert( BNPNL ); 00063 pBN = &BNPNL; } 00064 else 00065 #endif // PNL_ENABLED 00066 pBN = &BNSmile; } 00067 00068 if( ( iRet = Genes( sArgs.genes_arg, GenesIn ) ) || 00069 ( iRet = Genes( sArgs.genex_arg, GenesEx ) ) ) 00070 return iRet; 00071 if( !PCLIn.Open( sArgs.data_arg, sArgs.skip_arg ) ) { 00072 cerr << "Couldn't open: " << ( sArgs.data_arg ? sArgs.data_arg : "PCL" ) << endl; 00073 return 1; } 00074 00075 for( i = 0; i < PCLIn.GetGenes( ); ++i ) { 00076 if( GenesIn.GetGenes( ) && !GenesIn.IsGene( PCLIn.GetGene( i ) ) ) 00077 continue; 00078 if( GenesEx.GetGenes( ) && GenesEx.IsGene( PCLIn.GetGene( i ) ) ) 00079 continue; 00080 veciGenes.push_back( i ); 00081 vecstrGenes.push_back( PCLIn.GetGene( i ) ); } 00082 00083 pBN->GetNodes( vecstrNodes ); 00084 for( i = 0; i < vecstrNodes.size( ); ++i ) { 00085 for( j = 0; j < PCLIn.GetExperiments( ); ++j ) 00086 if( vecstrNodes[ i ] == PCLIn.GetExperiment( j ) ) 00087 break; 00088 if( j < PCLIn.GetExperiments( ) ) 00089 continue; 00090 for( j = 0; j < pBN->GetValues( i ); ++j ) { 00091 char acTmp[ 1024 ]; 00092 00093 #pragma warning( disable : 4996 ) 00094 sprintf( acTmp, "%s:%d", vecstrNodes[ i ].c_str( ), j ); 00095 #pragma warning( default : 4996 ) 00096 vecstrExperiments.push_back( acTmp ); } } 00097 00098 PCLOut.Open( vecstrGenes, vecstrExperiments, vecstrFeatures ); 00099 pBN->Evaluate( PCLIn, PCLOut, !!sArgs.zero_flag, sArgs.algorithm_arg ); 00100 if( sArgs.output_arg ) 00101 ofsm.open( sArgs.output_arg ); 00102 PCLOut.Save( sArgs.output_arg ? (ostream&)ofsm : cout ); 00103 if( sArgs.output_arg ) 00104 ofsm.close( ); 00105 00106 return 0; } 00107 00108 static int Genes( const char* szGenes, CGenes& Genes ) { 00109 ifstream ifsm; 00110 00111 if( !szGenes ) 00112 return 0; 00113 00114 ifsm.open( szGenes ); 00115 if( !Genes.Open( ifsm ) ) { 00116 cerr << "Couldn't open: " << szGenes << endl; 00117 return 1; } 00118 ifsm.close( ); 00119 return 0; }