本文整理汇总了Python中pymodule.PassingData.target_id_set方法的典型用法代码示例。如果您正苦于以下问题:Python PassingData.target_id_set方法的具体用法?Python PassingData.target_id_set怎么用?Python PassingData.target_id_set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymodule.PassingData
的用法示例。
在下文中一共展示了PassingData.target_id_set方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getStrainidTargetidFromFile
# 需要导入模块: from pymodule import PassingData [as 别名]
# 或者: from pymodule.PassingData import target_id_set [as 别名]
def getStrainidTargetidFromFile(self, db, QC_method_id, input_fname, max_mismatch_rate, min_no_of_non_NAs=20):
"""
2008-09-10
column in input_fname is determined on the fly
2008-08-29
to get strain id and target id set from the qc_cross_match result file.
"""
sys.stderr.write("Getting set of strain_id & target_id ... \n")
reader = csv.reader(open(input_fname), delimiter='\t')
#figure out which variable is in which column
header = reader.next()
col_name2index = {}
for i in range(len(header)):
column_name = header[i]
col_name2index[column_name] = i
strain_id_set = Set()
target_id_set = Set()
i = 0
for row in reader:
#id, strainid, target_id, qc_method_id, mismatch_rate, no_of_mismatches, no_of_non_NA_pairs, readme_id =row
strainid = int(row[col_name2index['strainid']]) #2008-09-10
target_id = int(row[col_name2index['target_id']])
qc_method_id = int(row[col_name2index['qc_method_id']])
mismatch_rate = float(row[col_name2index['mismatch_rate']])
no_of_mismatches = int(row[col_name2index['no_of_mismatches']])
no_of_non_NA_pairs = int(row[col_name2index['no_of_non_NA_pairs']])
if qc_method_id == QC_method_id and no_of_non_NA_pairs>=min_no_of_non_NAs and mismatch_rate<=max_mismatch_rate:
if QC_method_id==4: #strain_id_set = target_id_set
strain_id_set.add(strainid)
strain_id_set.add(target_id)
else:
strain_id_set.add(strainid)
target_id_set.add(target_id)
i +=1
if self.report and i%100000==0:
sys.stderr.write("%s\t%s"%('\x08'*40, i))
if self.debug and i>1000000:
break
if self.report:
sys.stderr.write("%s\t%s\n"%('\x08'*40, i))
return_data = PassingData()
return_data.strain_id_set = strain_id_set
return_data.target_id_set = target_id_set
del reader
sys.stderr.write("%s strainids and %s target_ids. Done.\n"%(len(strain_id_set), len(target_id_set)))
return return_data
示例2: run
# 需要导入模块: from pymodule import PassingData [as 别名]
# 或者: from pymodule.PassingData import target_id_set [as 别名]
def run(self):
if self.debug:
import pdb
pdb.set_trace()
db = StockDB.StockDB(drivername=self.drivername, username=self.db_user,
password=self.db_passwd, hostname=self.hostname, database=self.dbname, schema=self.schema)
db.setup(create_tables=False)
session = db.session
order_by_sentence = " order by c.longitude, c.latitude, e.longitude, e.latitude, e.nativename " #how to order strains.
if self.QC_method_id ==4:
sql_table_str = "from %s e, %s s, %s a, %s c"%(StockDB.Ecotype.table.name, StockDB.Site.table.name, StockDB.Address.table.name,\
StockDB.Country.table.name)
common_where_condition = "where e.siteid=s.id and s.addressid=a.id and a.countryid=c.id %s " + order_by_sentence
strain_where_condition = common_where_condition%(" and e.id=st.ecotypeid")
strain_id_info_query = "select distinct st.id as strainid, e.id as ecotypeid, e.nativename, s.name as sitename, c.abbr %s, %s st %s"%(sql_table_str, StockDB.Strain.table.name, strain_where_condition)
else:
sql_table_str = "from %s q, %s e, %s s, %s a, %s c"%(StockDB.QCCrossMatch.table.name, StockDB.Ecotype.table.name, StockDB.Site.table.name, StockDB.Address.table.name,\
StockDB.Country.table.name)
common_where_condition = "where e.siteid=s.id and s.addressid=a.id and a.countryid=c.id %s"+ " and q.qc_method_id=%s and q.no_of_non_NA_pairs>=%s and q.mismatch_rate<=%s "%\
(self.QC_method_id, self.min_no_of_non_NAs, self.max_mismatch_rate) + order_by_sentence
strain_where_condition = common_where_condition%(" and e.id=st.ecotypeid and st.id=q.strainid")
strain_id_info_query = "select distinct q.strainid, e.id as ecotypeid, e.nativename, s.name as sitename, c.abbr %s, %s st %s"%(sql_table_str, StockDB.Strain.table.name, strain_where_condition)
if self.how_to_group_strains==2 or self.how_to_group_strains==3:
plate_info = self.alignStrainsAccordingToSeqPlate(db)
id_set_data = PassingData()
id_set_data.strain_id_set = None
id_set_data.target_id_set = None
elif self.input_fname:
id_set_data = self.getStrainidTargetidFromFile(db, self.QC_method_id, self.input_fname, self.max_mismatch_rate, self.min_no_of_non_NAs)
else:
id_set_data = PassingData()
id_set_data.strain_id_set = None
id_set_data.target_id_set = None
if self.how_to_group_strains==2 or self.how_to_group_strains==3:
strain_id_info = self.getStrainInfoGivenPlateInfo(db, plate_info, strain_id_info_query, strain_id_set=None)
else:
strain_id_info = self.getStrainIDInfo(db, strain_id_info_query, id_set_data.strain_id_set)
if self.QC_method_id==4:
if self.how_to_group_strains==3:
#2008-09-15 column strain id is in country, strain-longitude order
target_id_info = self.getStrainIDInfo(db, strain_id_info_query, id_set_data.strain_id_set)
else:
target_id_info = strain_id_info
else:
target_where_condition = common_where_condition%(" and e.id=q.target_id")
target_id_info_query = "select distinct e.id as strainid, e.id as ecotypeid, e.nativename, s.name as sitename, c.abbr %s %s"%(sql_table_str, target_where_condition)
target_id_info = self.getStrainIDInfo(db, target_id_info_query)
if self.input_fname:
rdata = self.get_data_matrixFromFile(db, strain_id_info, target_id_info, self.QC_method_id, self.input_fname, self.max_mismatch_rate, self.min_no_of_non_NAs)
else:
rdata = self.get_data_matrix(db, strain_id_info, target_id_info, self.QC_method_id, self.max_mismatch_rate, self.min_no_of_non_NAs)
rdata.data_matrix = self.markDataMatrixBoundary(rdata.data_matrix, strain_id_info, target_id_info)
header = ['strain info', ''] + target_id_info.strain_label_ls
strain_acc_list = strain_id_info.strain_label_ls
category_list = [1]*len(strain_acc_list)
if SNPData.isDataMatrixEmpty(rdata.data_matrix):
sys.stderr.write("Nothing fetched from database.\n")
sys.exit(3)
if self.output_fname:
write_data_matrix(rdata.data_matrix, self.output_fname, header, strain_acc_list, category_list)
if self.fig_fname:
font = get_font(self.font_path, font_size=self.font_size) #2008-08-01
value2color_func = lambda x: Value2Color.value2HSLcolor(x, rdata.min_value, rdata.max_value)
im_legend = drawContinousLegend(rdata.min_value, rdata.max_value, self.no_of_ticks, value2color_func, font)
#im.save('%s_legend.png'%self.fig_fname_prefix)
im = drawMatrix(rdata.data_matrix, value2color_func, strain_id_info.strain_label_ls,\
target_id_info.strain_label_ls, with_grid=1, font=font)
im = combineTwoImages(im, im_legend, font=font)
im.save(self.fig_fname)