2012-10-04 72 views
1

我使用痛飲環繞這個C++項目,並已經導入所有的頭文件到我的Python代碼後,我現在正在重新產生在蟒蛇的主類,但我m無法查找相應的數據結構和數據類型。 以下是下的main.cpp端口C++代碼到Python

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; 
} 

例如主要方法當我嘗試通過如上進行,在Python中,我得到了錯誤的空字符串(repeat_file)到filtparam()

在方法「new_filt_param」型「字符串常量&」的說法5

怎樣才能聲明Python中的「字符串常量&」型?

也有像蟒蛇「地圖」的結構?

+0

你可以通過http://stackoverflow.com/questions/2682745/creating-constant-in-python&http://code.activestate.com/recipes/65207-constants-in-python/?in=用戶97991 – avasal

回答

2

你在找什麼是dict,它基本上類似於C++的map。更多信息可在documentation中找到。

不同的問題:有沒有你在Python重建main()而不是簡單的包裝是一個與SWIG任何理由?雖然SWIG能夠處理以有限的方式之類的東西std::string,我會嘗試使用指針使用更簡單的界面/陣列只,而不是試圖通過任何C++對象或結構。

+0

原諒我的無知,但我不知道,你可以圍繞主類包裝爲好,痛飲文檔指出它不應該生C++源文件,但只有頭文件使用。實際上,我試圖創建使用wxPython的這個項目的接口,所以以爲我可以直接從GUI調整的參數,如果我能以某種方式重新創建主。你能指導我環繞主課嗎? – Priyanka

+0

這有點「hacky」:只要寫一個包含'main()'前向聲明的頭文件,就完成了。如教程中所解釋的那樣使用它。將參數'-cpp'傳遞給swig,它應該接受C++代碼。諸如調用約定等都是由SWIG處理的。 – Mario

+0

Heyy它的工作!非常感謝! – Priyanka