def newFeature(self, chrom, feature): # Put the fields in the right order # if self.indices: line = [feature[i] if i != None else '' for i in self.indices] else: line = list(feature) # Convert the score # try: line[3] = format_float(line[3]) except IndexError: pass # Convert the strand # try: line[4] = int_to_strand(line[4]) except IndexError: pass # Make sure eveything is a string # line = [str(f) for f in line] # Write one line # self.file.write('\t'.join([chrom] + line) + '\n')
def newFeature(self, chrom, feature): # Put the fields in the right order # line = range(len(all_fields)) for n,i in enumerate(self.indices): if i == -1: line[n] = defaults[n] else: line[n] = feature[i] # Convert the score # line[4] = format_float(line[4]) # Convert the strand # line[5] = int_to_strand(line[5]) # Convert the frame # if line[6] == '' or line[6] == None: line[6] = '.' # Make sure eveything is a string # line = [str(f) for f in line] # Write one line # self.file.write('\t'.join([chrom] + line) + '\n')
def newFeature(self, chrom, feature): # function to obtain attribute column key-value string def attribute_str(key, value): return '%s "%s";' % (key, value) # Put the fields in the right order # # GTF entries always have 8 columns (excluding the seqname column) line = range(8) for n, i in enumerate(self.indices): # i == -1 indicates we should use the default value # if i == -1: if n < 7: # Everything before the attribute column # line[n] = defaults[n] elif n == 7: # "gene_id" annotation # line[n] = attribute_str(self.fields[n], defaults[n]) elif n == 8: # "transcript_id annotation # attr = attribute_str(self.fields[n], defaults[n]) line[7] = '%s %s' % (line[7], attr) else: # Annotations of the attribute columns without defaults # raise ValueError("Default value for the %r attribute " "column is not defined." % self.fields[n]) else: if n < 7: line[n] = feature[i] elif n == 7: # "gene_id" annotation # line[n] = attribute_str(self.fields[n], feature[i]) else: # Everything after the "gene_id" annotation # attr = attribute_str(self.fields[n], feature[i]) line[7] = '%s %s' % (line[7], attr) # Convert end from UCSC back to Ensembl # line[3] = line[3] - 1 # Convert the strand # line[5] = int_to_strand(line[5]) # Convert the frame # if line[6] == '' or line[6] == None: line[6] = '.' # Make sure eveything is a string # line = [str(f) for f in line] # Write one line # self.file.write('\t'.join([chrom] + line) + '\n')
def newFeature(self, chrom, feature): # function to obtain attribute column key-value string def attribute_str(key, value): return '%s "%s";' % (key, value) # Put the fields in the right order # # GTF entries always have 8 columns (excluding the seqname column) line = range(8) for n, i in enumerate(self.indices): # i == -1 indicates we should use the default value # if i == -1: if n < 7: # Everything before the attribute column # line[n] = defaults[n] elif n == 7: # "gene_id" annotation # line[n] = attribute_str(self.fields[n], defaults[n]) elif n == 8: # "transcript_id annotation # attr = attribute_str(self.fields[n], defaults[n]) line[7] = '%s %s' % (line[7], attr) else: # Annotations of the attribute columns without defaults # raise ValueError("Default value for the %r attribute " "column is not defined." % self.fields[n]) else: if n < 7: line[n] = feature[i] elif n == 7: # "gene_id" annotation # line[n] = attribute_str(self.fields[n], feature[i]) else: # Everything after the "gene_id" annotation # attr = attribute_str(self.fields[n], feature[i]) line[7] = '%s %s' % (line[7], attr) # Convert the strand # line[5] = int_to_strand(line[5]) # Convert the frame # if line[6] == '' or line[6] == None: line[6] = '.' # Make sure eveything is a string # line = [str(f) for f in line] # Write one line # self.file.write('\t'.join([chrom] + line) + '\n')