예제 #1
0
	def  readDB(self):
		prefix, dbId = self.getDBId(self.database)
		if not prefix or not dbId or (self.probe and string.lower(self.probe) in ("all","mm","pm")):
			self.contents.append("###Error: source trait doesn't exist or SELECT more than one trait.")
			self.contents.append(self.example)
			self.contents.append(self.accessCode)
			return
		RISet = self.getRISet(prefix, dbId)
		traitdata, heads = self.getTraitData(prefix, dbId, self.probeset, self.probe)
		if not traitdata:
			self.contents.append("###Error: source trait doesn't exist or SELECT more than one trait.")
			self.contents.append(self.example)
			self.contents.append(self.accessCode)
			return
			
		dataset = reaper.Dataset()
		dataset.read(os.path.join(webqtlConfig.GENODIR, RISet + '.geno'))
		strainList = list(dataset.prgy)
		
		strains = []
		trait = []
		_prgy = dataset.prgy
		for item in traitdata:
			if item[0] in _prgy:
				strains.append(item[0])	
				trait.append(item[1])
		
		qtlscan = dataset.regression(strains, trait)
		LRS = dataset.permutation(strains, trait)
		nperm = len(LRS)	
		if qtlscan:
			self.contents.append("Locus\tLRS\tChr\tAdditive\tp-value") 
			qtlresult = []
			if self.returnnumber:
				self.returnnumber = min(self.returnnumber,len(qtlscan))
				if self.sort == 'lrs':
					qtlscan.sort(self.cmpLRS)
					for item in qtlscan[:self.returnnumber]:
						p_value = reaper.pvalue(item.lrs,LRS)	
						qtlresult.append((item.locus.name,item.lrs,item.locus.chr,item.additive,p_value))
				else:#sort by position
					qtlscan2 = qtlscan[:]
					qtlscan2.sort(self.cmpLRS)
					LRSthresh = qtlscan2[self.returnnumber].lrs
					for item in qtlscan:
						if item.lrs >= LRSthresh:
							p_value = reaper.pvalue(item.lrs,LRS)	
							qtlresult.append((item.locus.name,item.lrs,item.locus.chr,item.additive,p_value))
			else:
				for item in qtlscan:
					p_value = reaper.pvalue(item.lrs,LRS)
					qtlresult.append((item.locus.name,item.lrs,item.locus.chr,item.additive,p_value))
				if self.sort == 'lrs':
					qtlresult.sort(self.cmpLRS2)
			for item in qtlresult:
				self.contents.append("%s\t%2.5f\t%s\t%2.5f\t%1.5f" % item)
		else:
			self.contents.append("###Error: Error occurs while regression.")
			return
예제 #2
0
def read(file_geno, file_pheno, file_result1, file_result2):
	genotype = reaper.Dataset()
	genotype.read(file_geno)

	##open output file
	outputFile = file_result1
	fout = open(outputFile, "wb")
	fout.write("ID\tLocus\tChr\tcM\tLRS\tAdditive\tpValue\n")
	outputFile2 = file_result2
	fout2 = open(outputFile2, "wb")
	fout2.write("ID\tLocus\tChr\tcM\tLRS\tAdditive\tpValue\n")

	##Open Trait File
	DataStart = 1
	fp = open(file_pheno, "rb")
	header = fp.readline()
	header = map(string.strip, header.strip().split("\t"))
	_strains = header[DataStart:]

	##Read input file line by line
	line = fp.readline()
	while line:
		line = map(string.strip, line.strip().split("\t"))
		traitName = line[0]
		print "Calculate Trait %s" % traitName
		_traitData = map(float, line[DataStart:])

		qtlresults = genotype.regression(strains = _strains, trait = _traitData)
		permu = genotype.permutation(strains = _strains, trait = _traitData)

		##Save all the results
		for qtl in qtlresults:
			pvalue = reaper.pvalue(qtl.lrs, permu)
			fout.write("%s\t%s\t%s\t%2.3f\t%2.3f\t%2.3f\t%2.3f\t\n" % (traitName,
				qtl.locus.name, qtl.locus.chr, qtl.locus.cM, qtl.lrs, qtl.additive, pvalue))
		##Save highest LRS only
		maxqtl = max(qtlresults)
		pvalue = reaper.pvalue(maxqtl.lrs, permu)
		fout2.write("%s\t%s\t%s\t%2.3f\t%2.3f\t%2.3f\t%2.3f\t\n" % (traitName,
				maxqtl.locus.name, maxqtl.locus.chr, maxqtl.locus.cM, maxqtl.lrs, maxqtl.additive, pvalue))

		line = fp.readline()

	fp.close()
	fout.close()
	fout2.close()
예제 #3
0
	def  readDB(self):
		prefix, dbId = self.getDBId(self.database)
		if not prefix or not dbId or (self.probe and string.lower(self.probe) in ("all","mm","pm")):
			self.contents.append("###Error: source trait doesn't exist or SELECT more than one trait.")
			self.contents.append(self.example)
			self.contents.append(self.accessCode)
			return
		RISet = self.getRISet(prefix, dbId)
		traitdata, heads = self.getTraitData(prefix, dbId, self.probeset, self.probe)
		if not traitdata:
			self.contents.append("###Error: source trait doesn't exist or SELECT more than one trait.")
			self.contents.append(self.example)
			self.contents.append(self.accessCode)
			return
			
		dataset0 = reaper.Dataset()
		dataset0.read(os.path.join(webqtlConfig.GENODIR, RISet + '.geno'))
		strainList = list(dataset0.prgy)
		dataset = dataset0.addinterval()
		if self.chr != None:
			for _chr in dataset:
				if string.lower(_chr.name) ==  string.lower(self.chr):
					dataset.chromosome = [_chr]
					break
		
		strains = []
		trait = []
		_prgy = dataset.prgy
		for item in traitdata:
			if item[0] in _prgy:
				strains.append(item[0])	
				trait.append(item[1])

		qtlscan = dataset.regression(strains, trait)
		LRS = dataset.permutation(strains, trait)
		nperm = len(LRS)
		
		#print inter1[0]
		returnPeak = []
		nqtl = len(qtlscan)
		if self.peak:
			for i in range(nqtl):
				if i == 0 or qtlscan[i].locus.chr != qtlscan[i-1].locus.chr:
					if qtlscan[i].lrs < qtlscan[i+1].lrs:
						continue
				elif i == nqtl-1 or qtlscan[i].locus.chr != qtlscan[i+1].locus.chr:
					if qtlscan[i].lrs < qtlscan[i-1].lrs:
						continue
				else:
					if qtlscan[i].lrs < qtlscan[i+1].lrs or qtlscan[i].lrs < qtlscan[i-1].lrs:
						continue
				returnPeak.append(qtlscan[i])
		else:
			returnPeak = qtlscan[:]
			
		if returnPeak:
			self.contents.append("Locus\tLRS\tChr\tAdditive\tp-value\tcM") 
			qtlresult = []
			for item in returnPeak:
				p_value = reaper.pvalue(item.lrs,LRS)
				qtlresult.append((item.locus.name,item.lrs,item.locus.chr,item.additive,p_value, item.locus.cM))
			if self.sort == 'lrs':
				qtlresult.sort(self.cmpLRS2)
			for item in qtlresult:
				self.contents.append("%s\t%2.4f\t%s\t%2.4f\t%1.4f\t%s" % item)
		else:
			self.contents.append("###Error: Error occurs while regression.")
			return
예제 #4
0
header = map(string.strip, header.strip().split("\t"))
_strains = header[DataStart:]

##Read input file line by line
line = fp.readline()
while line:
	line = map(string.strip, line.strip().split("\t"))
	traitName = line[0]
	print "Calculate Trait %s" % traitName
	_traitData = map(float, line[DataStart:])

	qtlresults = genotype.regression(strains = _strains, trait = _traitData)
	permu = genotype.permutation(strains = _strains, trait = _traitData)

	##Save all the results
	for qtl in qtlresults:
		pvalue = reaper.pvalue(qtl.lrs, permu)
		fout.write("%s\t%s\t%s\t%2.3f\t%2.3f\t%2.3f\t%2.3f\t\n" % (traitName,
			qtl.locus.name, qtl.locus.chr, qtl.locus.cM, qtl.lrs, qtl.additive, pvalue))
	##Save highest LRS only
	maxqtl = max(qtlresults)
	pvalue = reaper.pvalue(maxqtl.lrs, permu)
	fout2.write("%s\t%s\t%s\t%2.3f\t%2.3f\t%2.3f\t%2.3f\t\n" % (traitName,
			maxqtl.locus.name, maxqtl.locus.chr, maxqtl.locus.cM, maxqtl.lrs, maxqtl.additive, pvalue))

	line = fp.readline()

fp.close()
fout.close()
fout2.close()