Example #1
0
	def mask_array_construct(self):
		data = with_mode(0, r.read_table)(self.dataset_source, row_names=1)
		'''
		!Important!
		if the dataset_source has too few data, conversion from R to python will be a problem.
		The whole data matrix will be converted to a python string matrix.
		R's NA is not converted to nan in python.
		
		The problem has been found. 
		r.as_matrix converts small dataset to character type.
		r.matrix won't rig the class type, but it rigs the structure.
		The only to sovle this is add a colClasses vector to r.read_table.
		such as: colClasses=c('character',rep('double',11))
		But you have to know the no_of_cols in advance.
		
		As our dataset is really big, this problem hasn't appeared.
		
		'''
		#print r.as_matrix(data)
		array = ma.masked_inside(r.as_matrix(data),  -1.0e20, 1.0e20)
		#all are set to be masked except nan. weird! So have to do a converse.
		self.mask_array = ma.array(array, mask=ma.logical_not(ma.getmask(array)))
		self.genelabels = r.rownames(data)
		self.no_of_genes = len(self.genelabels)
		self.no_of_cols = len(array[0])
		self.mask_matrix=ma.identity(self.no_of_cols)
		del array ,data
Example #2
0
	def mask_array_construct(self):
		data =with_mode(0, r.read_table)(self.dataset_source)
		'''
		!Important!
		if the dataset_source has too few data, conversion from R to python will be a problem.
		The whole data matrix will be converted to a python string matrix.
		R's NA is not converted to nan in python.
		'''
		#print r.as_matrix(data)
		array = ma.masked_inside(r.as_matrix(data),  -1.0e20, 1.0e20)
		#all are set to be masked except nan. weird! So have to do a converse.
		self.mask_array = ma.array(array, mask=ma.logical_not(ma.getmask(array)))
		self.genelabels = r.rownames(data)
		self.no_of_genes = len(self.genelabels)
		self.no_of_cols = len(array[0])
		self.mask_matrix=ma.identity(self.no_of_cols)
		del array ,data