Skip to content

Commit

Permalink
Bug fix. Removed the use of np.int (as it is now depreciated).
Browse files Browse the repository at this point in the history
  • Loading branch information
mnshgl0110 committed Jan 20, 2022
1 parent 3582389 commit a6bc387
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 128 deletions.
55 changes: 24 additions & 31 deletions syri/pyxFiles/findsv.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ def getSV(cwdPath, allAlignments, prefix, offset):
j_prop = abs(n) / (blocksAlign.iat[j, 3] - blocksAlign.iat[j, 2])
j1_prop = abs(n) / (blocksAlign.iat[j + 1, 3] - blocksAlign.iat[j + 1, 2])
sCoord = round(
blocksAlign.iat[j, 1] - j_prop * (blocksAlign.iat[j, 1] - blocksAlign.iat[j, 0])).astype(int)
blocksAlign.iat[j, 1] - j_prop * (blocksAlign.iat[j, 1] - blocksAlign.iat[j, 0]))
eCoord = round(blocksAlign.iat[j + 1, 0] + j1_prop * (
blocksAlign.iat[j + 1, 1] - blocksAlign.iat[j + 1, 0])).astype(int)
blocksAlign.iat[j + 1, 1] - blocksAlign.iat[j + 1, 0]))
fout.write("\t".join(["CPL",
str(sCoord),
str(eCoord),
Expand All @@ -181,9 +181,9 @@ def getSV(cwdPath, allAlignments, prefix, offset):
j_prop = abs(n) / (blocksAlign.iat[j, 2] - blocksAlign.iat[j, 3])
j1_prop = abs(n) / (blocksAlign.iat[j + 1, 2] - blocksAlign.iat[j + 1, 3])
sCoord = round(
blocksAlign.iat[j, 1] - j_prop * (blocksAlign.iat[j, 1] - blocksAlign.iat[j, 0])).astype(int)
blocksAlign.iat[j, 1] - j_prop * (blocksAlign.iat[j, 1] - blocksAlign.iat[j, 0]))
eCoord = round(blocksAlign.iat[j + 1, 0] + j1_prop * (
blocksAlign.iat[j + 1, 1] - blocksAlign.iat[j + 1, 0])).astype(int)
blocksAlign.iat[j + 1, 1] - blocksAlign.iat[j + 1, 0]))
fout.write("\t".join(["CPL",
str(sCoord),
str(eCoord),
Expand Down Expand Up @@ -257,9 +257,9 @@ def getSV(cwdPath, allAlignments, prefix, offset):
j_prop = abs(n) / (blocksAlign.iat[j, 3] - blocksAlign.iat[j, 2])
j1_prop = abs(n) / (blocksAlign.iat[j + 1, 3] - blocksAlign.iat[j + 1, 2])
sCoord = round(
blocksAlign.iat[j, 1] - j_prop * (blocksAlign.iat[j, 1] - blocksAlign.iat[j, 0])).astype(int)
blocksAlign.iat[j, 1] - j_prop * (blocksAlign.iat[j, 1] - blocksAlign.iat[j, 0]))
eCoord = round(blocksAlign.iat[j + 1, 0] + j1_prop * (
blocksAlign.iat[j + 1, 1] - blocksAlign.iat[j + 1, 0])).astype(int)
blocksAlign.iat[j + 1, 1] - blocksAlign.iat[j + 1, 0]))
fout.write("\t".join(["CPL",
str(sCoord),
str(eCoord),
Expand All @@ -271,9 +271,9 @@ def getSV(cwdPath, allAlignments, prefix, offset):
j_prop = abs(n) / (blocksAlign.iat[j, 2] - blocksAlign.iat[j, 3])
j1_prop = abs(n) / (blocksAlign.iat[j + 1, 2] - blocksAlign.iat[j + 1, 3])
sCoord = round(
blocksAlign.iat[j, 1] - j_prop * (blocksAlign.iat[j, 1] - blocksAlign.iat[j, 0])).astype(int)
blocksAlign.iat[j, 1] - j_prop * (blocksAlign.iat[j, 1] - blocksAlign.iat[j, 0]))
eCoord = round(blocksAlign.iat[j + 1, 0] + j1_prop * (
blocksAlign.iat[j + 1, 1] - blocksAlign.iat[j + 1, 0])).astype(int)
blocksAlign.iat[j + 1, 1] - blocksAlign.iat[j + 1, 0]))
fout.write("\t".join(["CPL",
str(sCoord),
str(eCoord),
Expand Down Expand Up @@ -328,9 +328,9 @@ def getSV(cwdPath, allAlignments, prefix, offset):
j_prop = abs(n) / (blocksAlign.iat[j, 3] - blocksAlign.iat[j, 2])
j1_prop = abs(n) / (blocksAlign.iat[j + 1, 3] - blocksAlign.iat[j + 1, 2])
sCoord = round(
blocksAlign.iat[j, 1] - j_prop * (blocksAlign.iat[j, 1] - blocksAlign.iat[j, 0])).astype(int)
blocksAlign.iat[j, 1] - j_prop * (blocksAlign.iat[j, 1] - blocksAlign.iat[j, 0]))
eCoord = round(blocksAlign.iat[j + 1, 0] + j1_prop * (
blocksAlign.iat[j + 1, 1] - blocksAlign.iat[j + 1, 0])).astype(int)
blocksAlign.iat[j + 1, 1] - blocksAlign.iat[j + 1, 0]))
fout.write("\t".join(["CPL",
str(sCoord),
str(eCoord),
Expand All @@ -341,15 +341,10 @@ def getSV(cwdPath, allAlignments, prefix, offset):
else:
j_prop = abs(n) / (blocksAlign.iat[j, 2] - blocksAlign.iat[j, 3])
j1_prop = abs(n) / (blocksAlign.iat[j + 1, 2] - blocksAlign.iat[j + 1, 3])
# sCoord = round(
# blocksAlign.iat[j, 1] - j_prop * (blocksAlign.iat[j, 1] - blocksAlign.iat[j, 0])).astype(
# int)
# eCoord = round(blocksAlign.iat[j + 1, 0] + j1_prop * (
# blocksAlign.iat[j + 1, 1] - blocksAlign.iat[j + 1, 0])).astype(int)
sCoord = round(
blocksAlign.iat[j, 1] - j_prop * (blocksAlign.iat[j, 1] - blocksAlign.iat[j, 0])).astype(int)
blocksAlign.iat[j, 1] - j_prop * (blocksAlign.iat[j, 1] - blocksAlign.iat[j, 0]))
eCoord = round(blocksAlign.iat[j + 1, 0] + j1_prop * (
blocksAlign.iat[j + 1, 1] - blocksAlign.iat[j + 1, 0])).astype(int)
blocksAlign.iat[j + 1, 1] - blocksAlign.iat[j + 1, 0]))
fout.write("\t".join(["CPL",
str(sCoord),
str(eCoord),
Expand All @@ -366,9 +361,9 @@ def getSV(cwdPath, allAlignments, prefix, offset):
if n >= offset:
if ordered:
sCoord = round(
blocksAlign.iat[j, 3] - j_prop * (blocksAlign.iat[j, 3] - blocksAlign.iat[j, 2])).astype(int)
blocksAlign.iat[j, 3] - j_prop * (blocksAlign.iat[j, 3] - blocksAlign.iat[j, 2]))
eCoord = round(blocksAlign.iat[j + 1, 2] + j1_prop * (
blocksAlign.iat[j + 1, 3] - blocksAlign.iat[j + 1, 2])).astype(int)
blocksAlign.iat[j + 1, 3] - blocksAlign.iat[j + 1, 2]))
fout.write("\t".join(["CPG",
str(blocksAlign.iat[j + 1, 0]),
str(blocksAlign.iat[j, 1]),
Expand All @@ -377,10 +372,8 @@ def getSV(cwdPath, allAlignments, prefix, offset):
blocksAlign.iat[0, 5],
blocksAlign.iat[0, 6]]) + "\n")
else:
sCoord = round(
blocksAlign.iat[j, 3] + j_prop * (blocksAlign.iat[j, 2] - blocksAlign.iat[j, 3])).astype(int)
eCoord = round(blocksAlign.iat[j + 1, 2] - j1_prop * (
blocksAlign.iat[j + 1, 2] - blocksAlign.iat[j + 1, 3])).astype(int)
sCoord = round(blocksAlign.iat[j, 3] + j_prop * (blocksAlign.iat[j, 2] - blocksAlign.iat[j, 3]))
eCoord = round(blocksAlign.iat[j + 1, 2] - j1_prop * (blocksAlign.iat[j + 1, 2] - blocksAlign.iat[j + 1, 3]))
fout.write("\t".join(["CPG",
str(blocksAlign.iat[j + 1, 0]),
str(blocksAlign.iat[j, 1]),
Expand All @@ -397,9 +390,9 @@ def getSV(cwdPath, allAlignments, prefix, offset):
if abs(m) > abs(n):
if ordered:
sCoord = round(blocksAlign.iat[j, 3] - j_prop * (
blocksAlign.iat[j, 3] - blocksAlign.iat[j, 2])).astype(int)
blocksAlign.iat[j, 3] - blocksAlign.iat[j, 2]))
eCoord = round(blocksAlign.iat[j + 1, 2] + j1_prop * (
blocksAlign.iat[j + 1, 3] - blocksAlign.iat[j + 1, 2])).astype(int)
blocksAlign.iat[j + 1, 3] - blocksAlign.iat[j + 1, 2]))
fout.write("\t".join(["TDM",
str(blocksAlign.iat[j + 1, 0]),
str(blocksAlign.iat[j, 1]),
Expand All @@ -410,9 +403,9 @@ def getSV(cwdPath, allAlignments, prefix, offset):

else:
sCoord = round(blocksAlign.iat[j, 3] + j_prop * (
blocksAlign.iat[j, 2] - blocksAlign.iat[j, 3])).astype(int)
blocksAlign.iat[j, 2] - blocksAlign.iat[j, 3]))
eCoord = round(blocksAlign.iat[j + 1, 2] - j1_prop * (
blocksAlign.iat[j + 1, 2] - blocksAlign.iat[j + 1, 3])).astype(int)
blocksAlign.iat[j + 1, 2] - blocksAlign.iat[j + 1, 3]))
fout.write("\t".join(["TDM",
str(blocksAlign.iat[j + 1, 0]),
str(blocksAlign.iat[j, 1]),
Expand All @@ -425,9 +418,9 @@ def getSV(cwdPath, allAlignments, prefix, offset):
k_prop = abs(n) / (blocksAlign.iat[j, 3] - blocksAlign.iat[j, 2])
k1_prop = abs(n) / (blocksAlign.iat[j + 1, 3] - blocksAlign.iat[j + 1, 2])
sCoord = round(blocksAlign.iat[j, 1] - k_prop * (
blocksAlign.iat[j, 1] - blocksAlign.iat[j, 0])).astype(int)
blocksAlign.iat[j, 1] - blocksAlign.iat[j, 0]))
eCoord = round(blocksAlign.iat[j + 1, 0] + k1_prop * (
blocksAlign.iat[j + 1, 1] - blocksAlign.iat[j + 1, 0])).astype(int)
blocksAlign.iat[j + 1, 1] - blocksAlign.iat[j + 1, 0]))
fout.write("\t".join(["TDM",
str(sCoord),
str(eCoord),
Expand All @@ -439,9 +432,9 @@ def getSV(cwdPath, allAlignments, prefix, offset):
k_prop = abs(n) / (blocksAlign.iat[j, 2] - blocksAlign.iat[j, 3])
k1_prop = abs(n) / (blocksAlign.iat[j + 1, 2] - blocksAlign.iat[j + 1, 3])
sCoord = round(blocksAlign.iat[j, 1] - k_prop * (
blocksAlign.iat[j, 1] - blocksAlign.iat[j, 0])).astype(int)
blocksAlign.iat[j, 1] - blocksAlign.iat[j, 0]))
eCoord = round(blocksAlign.iat[j + 1, 0] + k1_prop * (
blocksAlign.iat[j + 1, 1] - blocksAlign.iat[j + 1, 0])).astype(int)
blocksAlign.iat[j + 1, 1] - blocksAlign.iat[j + 1, 0]))
fout.write("\t".join(["TDM",
str(sCoord),
str(eCoord),
Expand Down
95 changes: 9 additions & 86 deletions syri/pyxFiles/inversions.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ cdef getProfitable(invblocks, long[:] aStart, long[:] aEnd, long[:] bStart, long
float maxscore, synscore
float w, revenue, cost
Py_ssize_t index
long[:] n = np.array(range(len(invblocks)), dtype=np.int)
long[:] n = np.array(range(len(invblocks)), dtype=int)
long[:] topo
long[:] source, target
long[:] pred
Expand Down Expand Up @@ -127,7 +127,7 @@ cdef getProfitable(invblocks, long[:] aStart, long[:] aEnd, long[:] bStart, long
print('Cycle found')
sys.exit()

topo = np.array(toporder, dtype = np.int)
topo = np.array(toporder, dtype = int)
n_topo = len(topo)
# Get order in which the edges need to be transversed
source = np.zeros_like(invG.es['source'], dtype=int)
Expand Down Expand Up @@ -193,7 +193,7 @@ cdef getProfitable(invblocks, long[:] aStart, long[:] aEnd, long[:] bStart, long
if i in uniend:
continue
nodepath.clear()
pred = np.array([-1]* <Py_ssize_t> len(n), dtype = np.int)
pred = np.array([-1]* <Py_ssize_t> len(n), dtype = int)
dist = np.array([np.float32('inf')]* <Py_ssize_t> len(n), dtype = np.float32)
dist[i] = 0
# Process vertices in topological order
Expand Down Expand Up @@ -321,10 +321,10 @@ cdef getProfitable(invblocks, long[:] aStart, long[:] aEnd, long[:] bStart, long
path.clear()
lp = st.size()
totscore = np.array([profit[i] for i in range(<Py_ssize_t> profit.size())], dtype=np.float32)
st_list = np.array([st[i] for i in range(<Py_ssize_t> st.size())], dtype=np.int)
end_list = np.array([end[i] for i in range(<Py_ssize_t> end.size())], dtype=np.int)
stb_list = np.array([stb[i] for i in range(<Py_ssize_t> stb.size())], dtype=np.int)
endb_list = np.array([endb[i] for i in range(<Py_ssize_t> endb.size())], dtype=np.int)
st_list = np.array([st[i] for i in range(<Py_ssize_t> st.size())], dtype=int)
end_list = np.array([end[i] for i in range(<Py_ssize_t> end.size())], dtype=int)
stb_list = np.array([stb[i] for i in range(<Py_ssize_t> stb.size())], dtype=int)
endb_list = np.array([endb[i] for i in range(<Py_ssize_t> endb.size())], dtype=int)
profit_list = np.array([profit[i] for i in range(<Py_ssize_t> profit.size())], dtype=np.float32)

parents = np.array([-1]*lp, dtype = 'int')
Expand All @@ -338,84 +338,7 @@ cdef getProfitable(invblocks, long[:] aStart, long[:] aEnd, long[:] bStart, long
parents[j] = i
else:
break

"""
Attempt to speed up goodinv identification, but not working as of now
print('starting')
parentscore = np.zeros(lp, np.float32)
for i in range(lp):
canmap[st_list[i]][stb_list[i]].push_back(i)
staenda[st_list[i]][end_list[i]].push_back(i)
print('graph generated')
i = 0
sorted_sa = np.zeros(<Py_ssize_t> canmap.size(), np.int64)
canmap_rit=canmap.rbegin()
while canmap_rit != canmap.rend():
sorted_sa[i] = deref(canmap_rit).first
i+=1
inc(canmap_rit)
sorted_sa = np.array(sorted(sorted_sa))
print('Pruning graph')
for i in sorted_sa:
canmap_rit2 = canmap[i].rbegin()
while canmap_rit2 != canmap[i].rend():
minparentscore[i][deref(canmap_rit2).first] = 0
inc(canmap_rit2)
print(np.array(sorted_sa))
count = 0
changed=False
for i in sorted_sa:
if i==12592489:
print(i, str(datetime.now()))
count+=1
staenda_it2 = staenda[i].rbegin()
while staenda_it2 != staenda[i].rend():
if i==12592489:
print(i, deref(staenda_it2).first, deref(staenda_it2).second.size())
for j in range(<Py_ssize_t> deref(staenda_it2).second.size()):
current = deref(staenda_it2).second[j]
canmap_rit = canmap.rbegin()
while canmap_rit != canmap.rend():
if deref(canmap_rit).first > end_list[current]-threshold:
if i==12592489:
print(i, deref(staenda_it2).first, deref(staenda_it2).second.size(), deref(canmap_rit).first)
canmap_rit2 = deref(canmap_rit).second.rbegin()
while canmap_rit2 != deref(canmap_rit).second.rend():
if i==12592489 and deref(staenda_it2).first == 12989685 and deref(canmap_rit).first == 13050974 and deref(canmap_rit2).first == 12368020:
print('gg parent set1')
print(i, deref(staenda_it2).first, deref(staenda_it2).second.size(), deref(canmap_rit).first)
if totscore[current] > minparentscore[deref(canmap_rit).first][deref(canmap_rit2).first]:
changed = False
if deref(canmap_rit2).first > endb_list[current]-threshold:
if i==12592489 and deref(staenda_it2).first == 12989685 and deref(canmap_rit).first == 13050974 and deref(canmap_rit2).first == 12368020:
print('gg parent set2')
print(i, deref(staenda_it2).first, deref(staenda_it2).second.size(), deref(canmap_rit).first)
for k in range(<Py_ssize_t> deref(canmap_rit2).second.size()):
if parentscore[deref(canmap_rit2).second[k]] < totscore[current]:
if i==12592489 and deref(staenda_it2).first == 12989685 and deref(canmap_rit).first == 13050974 and deref(canmap_rit2).first == 12368020:
print('gg parent set3')
print(i, deref(staenda_it2).first, deref(staenda_it2).second.size(), deref(canmap_rit).first)
changed = True
totscore[deref(canmap_rit2).second[k]] = totscore[current] + profit_list[deref(canmap_rit2).second[k]]
parentscore[deref(canmap_rit2).second[k]] = totscore[current]
parents[deref(canmap_rit2).second[k]] = current
if changed:
minvalue = np.inf
for k in range(<Py_ssize_t> deref(canmap_rit2).second.size()):
if parentscore[deref(canmap_rit2).second[k]] < minvalue:
minvalue = parentscore[deref(canmap_rit2).second[k]]
minparentscore[deref(canmap_rit).first][deref(canmap_rit2).first] = minvalue
else:
break
inc(canmap_rit2)
else:
break
inc(canmap_rit)
inc(staenda_it2)
"""


maxid = -1
maxscore = -1
for i in range(lp):
Expand All @@ -435,7 +358,7 @@ cdef getProfitable(invblocks, long[:] aStart, long[:] aEnd, long[:] bStart, long
if i in uniend:
continue
nodepath.clear()
pred = np.array([-1]* <Py_ssize_t> len(n), dtype = np.int)
pred = np.array([-1]* <Py_ssize_t> len(n), dtype = int)
dist = np.array([np.float32('inf')]* <Py_ssize_t> len(n), dtype = np.float32)
dist[i] = 0

Expand Down
Loading

0 comments on commit a6bc387

Please sign in to comment.