Exemple #1
0
	def filtertaxonomy(self):
		items=self.bMainList.selectedItems()
		if len(items)!=1:
			print("Need 1 item")
			return
		for citem in items:
			cname=str(citem.text())
			cexp=self.explist[cname]
			val,ok=QtGui.QInputDialog.getText(self,'Filter taxonomy','Taxonomy to filter')
			if ok:
				newexp=hs.filtertaxonomy(cexp,tax=str(val),exact=False)
				newexp.studyname=newexp.studyname+'_ftax'
				self.addexp(newexp)
Exemple #2
0
	def cleantaxonomy(self):
		items=self.bMainList.selectedItems()
		if len(items)!=1:
			print("Need 1 item")
			return
		for citem in items:
			cname=str(citem.text())
			cexp=self.explist[cname]
			ctwin = CleanTaxonomyWindow(cexp)
			res=ctwin.exec_()
			if res==QtGui.QDialog.Accepted:
				newexp=hs.copyexp(cexp)
				if ctwin.cMitochondria.checkState():
					newexp=hs.filtertaxonomy(newexp,'mitochondria',exclude=True)
				if ctwin.cChloroplast.checkState():
					newexp=hs.filtertaxonomy(newexp,'Streptophyta',exclude=True)
					newexp=hs.filtertaxonomy(newexp,'Chloroplast',exclude=True)
				if ctwin.cUnknown.checkState():
					newexp=hs.filtertaxonomy(newexp,'nknown',exclude=True)
				if ctwin.cBacteria.checkState():
					newexp=hs.filtertaxonomy(newexp,'Bacteria;',exclude=True,exact=True)
				newexp=hs.normalizereads(newexp)
				newexp.studyname=cexp.studyname+'.ct'
				self.addexp(newexp)
Exemple #3
0
def cleantaxonomy(expdat,mitochondria=True,chloroplast=True,bacteria=True,unknown=True,exclude=True):
	"""
	remove common non-16s sequences from the experiment and renormalize

	input:
	expdat : Experiment
	mitochondria : bool
		remove mitochondrial sequences
	chloroplast : bool
		remove chloroplast sequences
	bacteria : bool
		remove sequences only identified as "Bacteria" (no finer identification)
	unknown : bool
		remove unknown sequences
	exclude : bool
		True (default) to remove these sequecnes, False to keep them and throw other

	output:
	newexp : Experiment
		the renormalized experiment without these bacteria
	"""
	params=locals()

	newexp=hs.copyexp(expdat)
	if mitochondria:
		if exclude:
			newexp=hs.filtertaxonomy(newexp,'mitochondria',exclude=True)
		else:
			ne1=hs.filtertaxonomy(newexp,'mitochondria',exclude=False)
	if chloroplast:
		if exclude:
			newexp=hs.filtertaxonomy(newexp,'Streptophyta',exclude=True)
			newexp=hs.filtertaxonomy(newexp,'Chloroplast',exclude=True)
		else:
			ne2=hs.filtertaxonomy(newexp,'Streptophyta',exclude=False)
			ne3=hs.filtertaxonomy(newexp,'Chloroplast',exclude=False)
	if unknown:
		if exclude:
			newexp=hs.filtertaxonomy(newexp,'Unknown',exclude=True)
			newexp=hs.filtertaxonomy(newexp,'Unclassified;',exclude=True,exact=True)
		else:
			ne4=hs.filtertaxonomy(newexp,'Unknown',exclude=False)
			ne5=hs.filtertaxonomy(newexp,'Unclassified;',exclude=False,exact=True)
	if bacteria:
		if exclude:
			newexp=hs.filtertaxonomy(newexp,'Bacteria;',exclude=True,exact=True)
		else:
			ne6=hs.filtertaxonomy(newexp,'Bacteria;',exclude=False,exact=True)
	if exclude:
		newexp=hs.normalizereads(newexp)
	else:
		allseqs=[]
		allseqs+=(ne1.seqs)
		allseqs+=(ne2.seqs)
		allseqs+=(ne3.seqs)
		allseqs+=(ne4.seqs)
		allseqs+=(ne5.seqs)
		allseqs+=(ne6.seqs)
		allseqs=list(set(allseqs))
		newexp=hs.filterseqs(newexp,allseqs)
	newexp.filters.append('Clean Taxonomy (remove mitochondria etc.)')
	hs.addcommand(newexp,"cleantaxonomy",params=params,replaceparams={'expdat':expdat})
	hs.Debug(6,'%d sequences before filtering, %d after' % (len(expdat.seqs),len(newexp.seqs)))
	return newexp