<commit_before>#!/usr/bin/env python
# encoding: utf-8
# original version from https://gist.github.com/brantfaircloth/893580
"""
gb_to_bed.py file.gb file.bed genome_name

grab the gene records from a genbank file (edit for other record types).

- requires:  biopython

"""
 
from Bio import SeqIO
 
import sys
import pdb
 
def main():
    outf = open(sys.argv[2], 'w')
    genome = sys.argv[3]
    for record in SeqIO.parse(open(sys.argv[1], "rU"), "genbank") :
        for feature in record.features:
            if feature.type == 'gene':
                start = feature.location.start.position
                stop = feature.location.end.position
                try:
                    name = feature.qualifiers['gene'][0]
                except:
                    # some features only have a locus tag
                    name = feature.qualifiers['locus_tag'][0]
                if feature.strand < 0:
                    tmp = start
                    start = stop
                    stop = tmp
                bed_line = "{0}_gi\t{1}\t{2}\t{0}_{3}\n".format(genome, start, stop, name)
                sys.stdout.write("\"{0}_{3}\":{{\"karyo\":\"{0}_gi\",\"start\":{1},\"end\":{2},\"group\":\"gen\"}},".format(genome, start, stop, name));
                outf.write(bed_line)
    outf.close()
 
if __name__ == '__main__':
    main()<commit_msg>adjusted gb to bed json script to handle subparts of a feature<commit_after>#!/usr/bin/env python
# encoding: utf-8
# original version from https://gist.github.com/brantfaircloth/893580
"""
gb_to_bed.py file.gb file.bed genome_name

grab the gene records from a genbank file (edit for other record types).

- requires:  biopython

"""
 
from Bio import SeqIO
from pprint import pprint

import sys
import pdb
 
def main():
    outf = open(sys.argv[2], 'w')
    genome = sys.argv[3]
    for record in SeqIO.parse(open(sys.argv[1], "rU"), "genbank") :
        for feature in record.features:
            if feature.type == 'gene':
                counter = 0;
                for part in feature.location.parts:
                    start = part.start.position
                    stop = part.end.position
                    try:
                        name = feature.qualifiers['gene'][0] + "_" + str(counter)
                        counter += 1
                    except:
                        # some features only have a locus tag
                        name = feature.qualifiers['locus_tag'][0] + "_" + str(counter)
                        counter += 1
                        if feature.strand < 0:
                            tmp = start
                            start = stop
                            stop = tmp
                            bed_line = "{0}_gi\t{1}\t{2}\t{0}_{3}\n".format(genome, start, stop, name)
                            sys.stdout.write("\"{0}_{3}\":{{\"karyo\":\"{0}_gi\",\"start\":{1},\"end\":{2},\"group\":\"gen\"}},".format(genome, start, stop, name));
                            outf.write(bed_line)
    outf.close()
 
if __name__ == '__main__':
    main()
{'fraction_non_alphanumeric': 0.14033366045142295, 'fraction_numerical': 0.01602878639188747, 'mean_word_length': 1.6591304347826088, 'pattern_counts': {'":': 10, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4023380', 'n_tokens_mistral': 955, 'n_tokens_neox': 891, 'n_words': 218}