Пример #1
0
	def readGff(self, filename, types):
		"""Reads features from file. Will read in GFF, not GTF, so last column (gene name etc)
		must be identical between exons."""
		file = smartopen(filename)
		for line in file:
			if len(line) > 1:
				if line[0] != '#':
					words = self.__splitLine(line)
					try:
						ref = words[0]
						source = words[1]
						type = words[2]
						a = int(words[3])
						b = int(words[4])
						if words[5] == '.': score = None
						else: score = float(words[5])
						strand = words[6]
						frame = words[7]
						if words[7] == '.': frame = None
						else: frame = int(words[7])
						name = words[8]
					except StandardError, msg:
						raise StandardError, msg, 'Invalid GFF file format'
					start,end = min(a,b), max(a,b)
					if type in types or not types:
						self.addFeature(Feature(ref, source, type, [[start,end]], score, strand, frame, name))
Пример #2
0
	def writeGff(self, filename, reflist=None, mode = 'w'):
		"""Outputs list of gene features to gff file"""
		output = smartopen(filename, mode)
		if not reflist: reflist = self.features.keys()
		if type(reflist) == str: reflist = [reflist]
		for ref in reflist:
			if ref in self.features:
				for gene in self.features[ref]:
					output.write(str(self.features[ref][gene]))
		return