Sleipnir
tools/Dat2PCL/Dat2PCL.cpp
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 #include "statistics.h"
00025 
00026 int main(int iArgs, char** aszArgs) {
00027     gengetopt_args_info sArgs;
00028     CGenome Genome;
00029     CGenes Genes(Genome);       
00030     CPCL PCL;
00031     CPCL aPCL;
00032     CDat Dat;
00033     size_t i, j, iArg;
00034     bool fModified;
00035     vector<string> features;
00036     vector<string> input_files;
00037     
00038     if (cmdline_parser(iArgs, aszArgs, &sArgs)) {
00039         cmdline_parser_print_help();
00040         return 1;
00041     }
00042     CMeta Meta(sArgs.verbosity_arg);
00043     
00044     if(sArgs.input_given){
00045       if( !Dat.Open( sArgs.input_arg, false, 0, false, true)){
00046         cerr << "Could not open: " << sArgs.input_arg << endl;
00047         return 1; }
00048       
00049       PCL.Open( Dat.GetGeneNames( ), Dat.GetGeneNames( ), features);
00050     
00051       cerr << "Gene count: " << Dat.GetGenes() << endl;
00052     
00053       PCL.populate( sArgs.input_arg );
00054     }
00055     else{
00056       if(sArgs.inputs_num > 0){
00057         input_files.resize( sArgs.inputs_num );
00058         copy( sArgs.inputs, sArgs.inputs + sArgs.inputs_num, input_files.begin( ) );
00059         
00060         for( iArg = 0; iArg < input_files.size(); ++iArg ) {
00061           
00062           if( !aPCL.Open(input_files[ iArg ].c_str(), sArgs.skip_arg, false, sArgs.rPCL_flag ) ) {
00063         cerr << "Could not open: " << input_files[ iArg ] << endl;
00064         return 1; }
00065           
00066           cerr << "Open: " << input_files[ iArg ] << endl;
00067           
00068           if(iArg == 0)
00069         PCL.Open(aPCL);
00070           else{
00071         for( i = 0; i < PCL.GetGenes( ); ++i )
00072           for( j = 0; j < PCL.GetExperiments( ); ++j )
00073             PCL.Set(i,j, aPCL.Get(i,j)+PCL.Get(i,j) );
00074           }
00075         }
00076       }
00077       else{
00078         return 1;
00079       }
00080     }
00081     
00082     
00083     if (sArgs.output_arg) {   
00084       PCL.Save(sArgs.output_arg);
00085     } else {
00086       PCL.Save(cout, NULL);
00087       cout.flush();
00088     }   
00089     return 0;
00090 }