Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions qtl/annotation.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import numpy as np
import pandas as pd
import os
import tempfile
import subprocess
import sys
import tempfile
import tqdm
import matplotlib.pyplot as plt
import matplotlib.patches as patches
import matplotlib.path as mpath
Expand Down Expand Up @@ -494,6 +496,7 @@ def __init__(self, varin, verbose=True):
else:
opener = open(gtfpath, 'r')

print("Loading genes from GTF ...", file = sys.stderr)
with opener as gtf:
for row in gtf:
if row[0] == '#':
Expand Down Expand Up @@ -585,9 +588,9 @@ def __init__(self, varin, verbose=True):
pass

if len(self.genes) % 1000 == 0 and verbose:
print(f'\rGenes parsed: {len(self.genes)}', end='')
print(f'\rGenes parsed: {len(self.genes)}', end='', file = sys.stderr)
if verbose:
print(f'\rGenes parsed: {len(self.genes)}')
print(f'\rGenes parsed: {len(self.genes)}', file = sys.stderr)

self.gene_ids = np.array(self.gene_ids)
self.gene_names = np.array(self.gene_names)
Expand All @@ -610,6 +613,15 @@ def __init__(self, varin, verbose=True):
self.chr_index = dict([(chrs[i], [sidx[i],eidx[i]]) for i in range(len(chrs))])
self.chr_genes = dict([(chrs[i], self.genes[sidx[i]:eidx[i]+1]) for i in range(len(chrs))])

# dataframe of all genes
columns = ["name", "chr", "start_pos", "end_pos", "tss", "transcripts", "strand", "type"]
self.gene_df = pd.DataFrame(index = self.gene_ids, columns = columns)
print("Making gene dataframe ...", file = sys.stderr)
for g in tqdm.tqdm(self.genes):
self.gene_df.loc[g.id, :] = pd.Series(
{ x : getattr(g, x) for x in columns }
)

# interval trees with gene starts/ends for each chr
self.gene_interval_trees = defaultdict()
for g in self.genes:
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
'seaborn',
'pyBigWig',
'bx-python',
'tqdm',
],
classifiers = [
"Programming Language :: Python :: 3",
Expand Down