<jupyter_start><jupyter_text><jupyter_code>import pandas as pd
import re
import json
!wget http://ftp.ensembl.org/pub/release-96/gtf/mus_musculus/Mus_musculus.GRCm38.96.gtf.gz
gtf = pd.read_csv('Mus_musculus.GRCm38.96.gtf.gz', sep='\t', skiprows=5, header=None, low_memory=False)
gtf.columns = ['seqname', 'source', 'feature', 'start', 'end', 'score', 'strand', 'frame', 'attribute']
gtf.head()
gene_biotype = gtf['attribute'].str.extract(r'gene_biotype \"(\w+)\"')
gtf['gene_biotype'] = gene_biotype
gene_id = gtf['attribute'].str.extract(r'gene_id \"(ENSMUSG\d+)\"')
gtf['gene_id'] = gene_id
gtf.head()
id_biotype = gtf[['gene_biotype','gene_id']]
id_biotype.head()
# build dictionary linking gene id to biotype
id_biotype_dict = dict(zip(id_biotype.gene_id,id_biotype.gene_biotype))
json = json.dumps(id_biotype_dict)
# export dictionary
f = open("id2biotype.json","w")
f.write(json)
f.close()
# test dictionary
id_biotype_dict['ENSMUSG00000102693']
# check number or rRNA genes
len([k for k,v in id_biotype_dict.items() if v == 'rRNA'])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17850467289719626, 'fraction_numerical': 0.02149532710280374, 'mean_word_length': 7.2384615384615385, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, '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}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '451838', 'license': 'MIT', 'n_tokens_mistral': 466, 'n_tokens_neox': 433, 'n_words': 74, 'path': 'build_biotype_dictionary.ipynb', 'repo_name': 'jgalazka/genelab-tools', 'size': '1070'}