Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
sv-conflict-analysis/ambiguity_distances.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
51 lines (40 sloc)
1.51 KB
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
from itertools import combinations | |
import sys | |
import matplotlib.pyplot as plt | |
from general_functions import load_sv_conflict | |
def log_bins(base, end): | |
res = [] | |
x = base | |
while x < end: | |
res.append(x) | |
x *= base | |
res.append(x) | |
return res | |
if __name__ == '__main__': | |
fn = sys.argv[1] | |
method = sys.argv[2] | |
direction_start = sys.argv[3] == "start" | |
max_dist = int(sys.argv[4]) | |
f = open(fn, "r") | |
distances = [] | |
for line in f: | |
called_svs = load_sv_conflict(line) | |
break_positions = [] | |
for sv in called_svs: | |
if sv.startswith(method): | |
info = sv.split("_") | |
# info looks like ["svim", "DEL", "-133", "232424", "323242", ...] | |
if direction_start: | |
break_positions.append(int(info[3])) | |
else: | |
break_positions.append(int(info[4])) | |
# iterate over all 2-combinations of the conflicting SV calls | |
for a, b in combinations(break_positions, 2): | |
if (dist := abs(a - b)) < max_dist: | |
distances.append(dist) | |
plt.hist(distances, log=True)#, bins=log_bins(2, max(distances))) | |
plt.xlabel(f"{'Start' if direction_start else 'End'} breakpoint " + | |
"distances between ambiguous SV calls in a region") | |
plt.ylabel("Frequency") | |
plt.title("Distribution of breakend distances between ambiguous SVs in a graph") | |
plt.savefig(f"ambiguity_distance_distribution_{method}.png", bbox_inches="tight") |