1

私は swig を使用してこの C++ プロジェクトをラップしています。すべてのヘッダー ファイルを Python コードにインポートした後、Python でメイン クラスを再作成しようとしていますが、対応するデータを探すのに問題があります。構造とデータ型。以下は、main.cpp の下のメイン メソッドです。

int main( int argc, char *argv[] )
{
string exe_name = argv[ 0 ];

string usage = "Usage: " + exe_name + " unigene.fasta [options]\n\
Options:\n\
-g <GC content> \tminimum GC content in percentage (Default 45).\n\
-G <GC content> \tmaximum GC content in percentage (Default 55).\n\
-m <temperature> \tlowest melting temperature in degrees of celsius (Default 0).\n\
-M <temperature> \thighest melting temperature in degrees of celsius (Default 100).\n\
-r <repeat.fasta> \tfasta file containing repeat DNA sequences.\n\
-t <top number> \tnumber of top oligos selected for each unigene (Default 1).\n\n";

string unigene_file;
// options only, each must have an associated value
int min_gc = 45;
int max_gc = 55;
int min_tm = 0;
int max_tm = 100; 
int top_num = 1;
string repeat_file;
vector< string > m_argument;
for ( int i = 0; i < argc; i ++ ) {
    string new_arg = argv[ i ];
    m_argument.push_back( new_arg );
}

parse_argument( m_argument, usage, unigene_file, 
                min_gc, max_gc, min_tm, max_tm, top_num, repeat_file );

// initialize filtration parameters
float norm_min_gc = (float)min_gc / 100.0;
float norm_max_gc = (float)max_gc / 100.0;
string splice_file; // empty splice file
filt_param m_filtparam( norm_min_gc, norm_max_gc, min_tm, max_tm, 
                        repeat_file, splice_file );

// screen unigenes for unique oligos
seqs m_unigene;
m_unigene.init( unigene_file );

// map from unigene names to oligo sequences
map< string, vector< string > > uniq_oligo;
get_unique_oligo( m_unigene, m_filtparam, top_num, uniq_oligo );

// output oligos
if ( uniq_oligo.empty() ) {
  cout << "No valid oligo has been found. " << endl <<
    "It could be due to one of the following reasons: " << endl <<
    "1. input sequences are not unique, or " << endl << 
    "2. they are repetitive DNAs, or " << endl << 
    "3. GC% range is too restricted, etc. " << endl;
}
map< string, vector< string > > :: const_iterator m_itr;
for ( m_itr = uniq_oligo.begin(); m_itr != uniq_oligo.end(); m_itr ++ ) {
    for ( int o_idx = 0; o_idx < (int)m_itr->second.size(); o_idx ++ ) {
        cout << ">unique-oligo-" << o_idx+1 << "-of-unigene-" << 
                m_itr->first << endl;
        cout << m_itr->second[ o_idx ] << endl;
    }
}

//system("PAUSE");
return 1;
}

たとえば、上記のように空の文字列 (repeat_file) を filtparam() に渡そうとすると、Python でエラーが発生します。

メソッド 'new_filt_param' で、型 'string const &' の引数 5

Pythonで「string const &」タイプをどのように宣言しますか?

また、Pythonに「マップ」のような構造はありますか?

4

1 に答える 1

2

探しているのはdict、基本的にC++と同様に機能するmapです。詳細については、ドキュメントを参照してください。

別の質問:main()Pythonで単純にラップするのではなく、Pythonで再作成する理由はありますか?SWIGはstd::string限られた方法でそのようなことを処理できますが、C ++オブジェクトや構造体を渡すのではなく、ポインター/配列のみを使用するより単純なインターフェイスを使用しようとします。

于 2012-10-04T08:52:36.817 に答える