-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
80 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,9 @@ | ||
from collections import defaultdict | ||
import matplotlib.pyplot as plt | ||
import matplotlib.patches as patches | ||
import re | ||
#from scipy.stats import linregress, pearsonr | ||
#from matplotlib import figure | ||
import pandas as pd | ||
import numpy as np | ||
import pysam | ||
|
||
from matplotlib.path import Path | ||
from genda.formats.dosages import grab_gene_location | ||
from .annotation import (snp_arrow) | ||
from .plotting_utils import * | ||
|
||
|
||
def make_rectangle(start, end, y1, y2): | ||
verts = [(start, y1), | ||
(start, y2), | ||
(end, y2), | ||
(end, y1), | ||
(start, y1), | ||
] | ||
codes = [ | ||
Path.MOVETO, | ||
Path.LINETO, | ||
Path.LINETO, | ||
Path.LINETO, | ||
Path.CLOSEPOLY, | ||
] | ||
return (Path(verts, codes)) | ||
|
||
|
||
def create_path(gtf_iterator, gene, height=0.5, x_scale=1): | ||
""" Create a path for a given transcript | ||
:TODO change name | ||
""" | ||
transcripts = defaultdict(list) | ||
t_rxe = re.compile('transcript_id "(ENST[0-9]+)"') | ||
t_add = 0 | ||
for i in gtf_iterator: | ||
mverts = [] | ||
i = i.split("\t") | ||
if (i[3] == gene or gene in i[9]) and i[7] == 'exon': | ||
verts = [(int(i[1])/x_scale, t_add), | ||
(int(i[1])/x_scale, height + t_add), | ||
(int(i[2])/x_scale, height + t_add), | ||
(int(i[2])/x_scale, t_add), | ||
(int(i[1])/x_scale, t_add), | ||
] | ||
|
||
codes = [ | ||
Path.MOVETO, | ||
Path.LINETO, | ||
Path.LINETO, | ||
Path.LINETO, | ||
Path.CLOSEPOLY, | ||
] | ||
transcript = t_rxe.search(i[9]).group(1) | ||
if transcript not in transcripts.keys(): | ||
t_add += 1 | ||
else: pass | ||
transcripts[transcript].append(Path(verts, codes)) | ||
else: pass | ||
return(transcripts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
|
||
def snp_arrow(pos, height, snpid, ax): | ||
""" Draws an arrow pointing at a SNP in | ||
a Manhattan plot | ||
pos - an object with pos and height | ||
height - height | ||
ax - matplotlib axes | ||
""" | ||
|
||
rel_width = 25 | ||
|
||
p_width = ax.get_xlim() | ||
p_height = ax.get_ylim() | ||
''' | ||
spacer = (p_height[1] - p_height[0])/rel_width | ||
a_head_width = (p_width[1] - p_width[0])/rel_width | ||
a_head_length = p_height[1] - p_height[0]/rel_width | ||
arrow_length = p_height - height - spacer | ||
ax.arrow(pos, p_height[1], 0, | ||
arrow_length, | ||
head_width = a_head_width, | ||
head_length = a_head_length, | ||
fc = 'k') | ||
''' | ||
|
||
ax.annotate(snpid, xy=(pos, height), | ||
xytext = (pos, p_height[1]), | ||
arrowprops=dict(facecolor='black', shrink=0.05)) | ||
|
||
|
||
return ax | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters