Пример #1
0
def order_records(bed_file, output):
    records = defaultdict(list)
    for bed_record in Bed.parse(open(bed_file, "rU")):
        records[bed_record.strand].append(bed_record)

    records["+"].sort(key=lambda p: (p.name, p.chrom_start))
    records["-"].sort(key=lambda p: (p.name, -p.chrom_start))

    with open(output, "w") as output_handle:
        for _, bed_records in records.iteritems():
            output_handle.writelines(("%s\n" % str(bed_record)) for bed_record in bed_records)
Пример #2
0
 def _create_bins(self, genes):
     for record in Bed.parse(open(genes, "rU")):
         for start, end in self._get_bins(record.chrom_start,
                                          record.chrom_end):
             self.counter[record.name, start, end] = defaultdict(int)
             self.bins[record.name].append((start, end))