Skip to content

Commit 2ea571e

Browse files
committed
fixed deprecation warnings
1 parent 7cb3209 commit 2ea571e

File tree

11 files changed

+51
-48
lines changed

11 files changed

+51
-48
lines changed

spladder/alt_splice/events.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def make_unique_by_event(event_list):
107107
last_kept = i
108108

109109
print('events dropped: %i' % len(rm_idx))
110-
keep_idx = np.where(~np.in1d(np.arange(event_list.shape[0]), rm_idx))[0]
110+
keep_idx = np.where(~np.isin(np.arange(event_list.shape[0]), rm_idx))[0]
111111
event_list = event_list[keep_idx]
112112

113113
return event_list
@@ -158,7 +158,7 @@ def curate_alt_prime(event_list, options):
158158

159159
### remove events with non-overlapping alt_exons
160160
if len(rm_idx) > 0:
161-
keep_idx = np.where(~np.in1d(np.arange(event_list.shape[0]), rm_idx))[0]
161+
keep_idx = np.where(~np.isin(np.arange(event_list.shape[0]), rm_idx))[0]
162162
event_list = event_list[keep_idx]
163163

164164
print('Corrected %i events' % corr_count)

spladder/classes/event.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def get_exon_coordinate_strings(self):
5151
sidx = np.argsort([int(_.split('-')[0]) for _ in _iso_both])
5252
_iso_both = _iso_both[sidx]
5353

54-
_usage = (~(np.in1d(_iso_both, _iso1) & np.in1d(_iso_both, _iso2))).astype('int')
54+
_usage = (~(np.isin(_iso_both, _iso1) & np.isin(_iso_both, _iso2))).astype('int')
5555

5656
return ':'.join(_iso_both), ':'.join(_usage.astype('str'))
5757

spladder/classes/gene.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def label_alt(self):
8484
### handle start terminal exons -> no incoming edges
8585
if not np.any(edges[:i, i]):
8686
### find other exons with same end
87-
idx = np.where(~np.in1d(np.where(vertices[1, i] == vertices[1, :])[0], i))[0]
87+
idx = np.where(~np.isin(np.where(vertices[1, i] == vertices[1, :])[0], i))[0]
8888
if idx.shape[0] > 0:
8989
is_simple = True
9090
for j in idx:
@@ -105,7 +105,7 @@ def label_alt(self):
105105
### handle end terminal exons -> no outgoing edges
106106
if not np.any(edges[i, i+1:]):
107107
### find other exons with the same start
108-
idx = np.where(~np.in1d(np.where(vertices[0, i] == vertices[0, :])[0], i))[0]
108+
idx = np.where(~np.isin(np.where(vertices[0, i] == vertices[0, :])[0], i))[0]
109109
if idx.shape[0] > 0:
110110
is_simple = True
111111
for j in idx:
@@ -125,7 +125,7 @@ def label_alt(self):
125125
term_alt_idx.append(i)
126126

127127
### further only consider exons that are neither init_alt nor term_alt
128-
take_idx = np.where(~np.in1d(np.arange(num_exons), [init_alt_idx + term_alt_idx]))[0]
128+
take_idx = np.where(~np.isin(np.arange(num_exons), [init_alt_idx + term_alt_idx]))[0]
129129
if take_idx.shape[0] > 0:
130130
vertices = self.splicegraph.vertices[:, take_idx]
131131
edges = self.splicegraph.edges[take_idx, :][:, take_idx]

spladder/classes/splicegraph.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def uniquify(self):
284284
self.edges[j, :] = self.edges[j-1, :] | self.edges[j, :]
285285
rm_idx.append(j - 1)
286286

287-
keep_idx = np.where(~np.in1d(np.array(np.arange(self.vertices.shape[1])), rm_idx))[0]
287+
keep_idx = np.where(~np.isin(np.array(np.arange(self.vertices.shape[1])), rm_idx))[0]
288288
self.vertices = self.vertices[:, keep_idx]
289289
self.edges = self.edges[keep_idx, :][:, keep_idx]
290290
self.terminals = self.terminals[:, keep_idx]

spladder/editgraph.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ def remove_short_exons(genes, options):
6464
short_exon_skipped += 1
6565
j += 1
6666

67-
keep_idx = np.where(~np.in1d(np.array(np.arange(genes[i].splicegraph.vertices.shape[1])), exons_remove_idx))[0]
67+
keep_idx = np.where(~np.isin(np.array(np.arange(genes[i].splicegraph.vertices.shape[1])), exons_remove_idx))[0]
6868
genes[i].splicegraph.subset(keep_idx)
6969

70-
keep_idx = np.where(~np.in1d(np.arange(len(genes)), rm_idx))[0]
70+
keep_idx = np.where(~np.isin(np.arange(len(genes)), rm_idx))[0]
7171
genes = genes[keep_idx]
7272

7373
if options.verbose:
@@ -165,7 +165,7 @@ def reduce_splice_graph(genes):
165165
### <--- test_exon ----> <---- test_exon ---->>>>>>>>>>>>
166166
if ((vertices[1, exon_idx] >= vertices[0, test_exon_idx]) and (vertices[0, exon_idx] <= vertices[0, test_exon_idx])) or \
167167
((vertices[1, test_exon_idx] >= vertices[0, exon_idx]) and (vertices[0, test_exon_idx] <= vertices[0, exon_idx])) and \
168-
(np.sum(np.in1d(np.arange(min(vertices[0, exon_idx], vertices[0, test_exon_idx]), max(vertices[1, exon_idx], vertices[1, test_exon_idx])), intron_loc)) == 0):
168+
(np.sum(np.isin(np.arange(min(vertices[0, exon_idx], vertices[0, test_exon_idx]), max(vertices[1, exon_idx], vertices[1, test_exon_idx])), intron_loc)) == 0):
169169

170170
### merge exons if they overlap and they do not span any intronic position
171171
vertices[0, exon_idx] = min(vertices[0, exon_idx], vertices[0, test_exon_idx])
@@ -184,7 +184,7 @@ def reduce_splice_graph(genes):
184184
### ----- exon -----<
185185
### --- test_exon --<
186186
if (vertices[1, exon_idx] == vertices[1, test_exon_idx]) and \
187-
(np.sum(np.in1d(np.arange(min(vertices[0, exon_idx], vertices[0, test_exon_idx]), vertices[1, exon_idx]), intron_loc)) == 0):
187+
(np.sum(np.isin(np.arange(min(vertices[0, exon_idx], vertices[0, test_exon_idx]), vertices[1, exon_idx]), intron_loc)) == 0):
188188

189189
### merge exons if they share the same right boundary and do not span intronic positions
190190
vertices[0, exon_idx] = min(vertices[0, exon_idx], vertices[0, test_exon_idx])
@@ -204,7 +204,7 @@ def reduce_splice_graph(genes):
204204
### >---- exon ------
205205
### >-- test_exon ---
206206
if (vertices[0, exon_idx] == vertices[0, test_exon_idx]) and \
207-
(np.sum(np.in1d(np.arange(vertices[0, exon_idx], max(vertices[1, exon_idx], vertices[1, test_exon_idx])), intron_loc)) == 0):
207+
(np.sum(np.isin(np.arange(vertices[0, exon_idx], max(vertices[1, exon_idx], vertices[1, test_exon_idx])), intron_loc)) == 0):
208208

209209
### merge exons if they share the same left boundary and do not span intronic positions
210210
vertices[1, exon_idx] = max(vertices[1, exon_idx], vertices[1, test_exon_idx])
@@ -257,8 +257,8 @@ def filter_by_edgecount(genes, options):
257257
genes[i].splicegraph.edges = (genes[i].edge_count >= options.sg_min_edge_count).astype('int')
258258
### remove all exons that have no incoming or outgoing edges (caused by validation, keep single exon transcripts that occured before)
259259
k_idx2 = np.where(genes[i].splicegraph.edges.sum(axis = 1) > 0)[0]
260-
#rm_idx = np.where(~np.in1d(k_idx2, k_idx))[0]
261-
#keep_idx = np.where(~np.in1d(np.arange(genes[i].splicegraph.edges.shape[0]), rm_idx))[0]
260+
#rm_idx = np.where(~np.isin(k_idx2, k_idx))[0]
261+
#keep_idx = np.where(~np.isin(np.arange(genes[i].splicegraph.edges.shape[0]), rm_idx))[0]
262262
keep_idx = np.union1d(k_idx, k_idx2).astype('int')
263263
if keep_idx.shape[0] > 0:
264264
genes[i].splicegraph.subset(keep_idx)
@@ -279,7 +279,7 @@ def insert_intron_retentions(genes, bam_fnames, options):
279279

280280
### ignore contigs not present in bam files
281281
# TODO
282-
#keepidx = np.where(np.in1d(np.array([options.chrm_lookup[x.chr] for x in genes[chunk_idx]]), np.array([x.chr_num for x in regions])))[0]
282+
#keepidx = np.where(np.isin(np.array([options.chrm_lookup[x.chr] for x in genes[chunk_idx]]), np.array([x.chr_num for x in regions])))[0]
283283
#genes = genes[keepidx]
284284

285285
c = 0
@@ -509,7 +509,6 @@ def insert_intron_edges(genes, bam_fnames, options):
509509
genes[i].splicegraph.vertices[1, -2], genes[i].splicegraph.vertices[0, -1],
510510
genes[i].splicegraph.vertices[1, -1]), file=fd_log)
511511
intron_used = True
512-
513512
if not intron_used:
514513
unused_introns.append(j)
515514
continue # with next intron
@@ -672,6 +671,9 @@ def insert_intron_edges(genes, bam_fnames, options):
672671
tracks += tmp_
673672
tracks = np.asarray(tracks)
674673
else:
674+
#if i == 11:
675+
# import pdb
676+
# pdb.set_trace()
675677
tracks = add_reads_from_bam(np.array([gg], dtype='object'), bam_fnames, ['exon_track'], options.read_filter, options.var_aware, options.primary_only, options.ignore_mismatches, mm_tag=options.mm_tag, cram_ref=options.ref_genome)
676678

677679
### TODO: make configurable
@@ -835,7 +837,7 @@ def insert_cassette_exons(genes, bam_fnames, options):
835837

836838
### ignore contigs not present in bam files
837839
# TODO TODO
838-
#keepidx = np.where(np.in1d(np.array([CFG['chrm_lookup'][x.chr] for x in genes]), np.array([x.chr_num for x in regions])))[0]
840+
#keepidx = np.where(np.isin(np.array([CFG['chrm_lookup'][x.chr] for x in genes]), np.array([x.chr_num for x in regions])))[0]
839841
#genes = genes[keepidx]
840842

841843
c = 0

spladder/helpers.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def make_introns_feasible(introns, genes, bam_fnames, options):
3535
tmp2 = np.array([x.shape[0] for x in introns[:, 1]])
3636

3737
still_unfeas = np.where((tmp1 > 200) | (tmp2 > 200))[0]
38-
idx = np.where(~np.in1d(unfeas, still_unfeas))[0]
38+
idx = np.where(~np.isin(unfeas, still_unfeas))[0]
3939

4040
for i in unfeas[idx]:
4141
print('[feasibility] set criteria for gene %s to: min_ex %i, min_conf %i, max_mism %i' % (genes[i].name, options.read_filter['exon_len'], options.read_filter['mincount'], options.read_filter['mismatch']), file=fd_log)
@@ -113,7 +113,7 @@ def filter_introns(introns, genes, options):
113113
k_idx = []
114114
cnt_tot += introns[i, si].shape[0]
115115
for j in range(introns[i, si].shape[0]):
116-
if len(gene_trees[(s, genes[i].chr)].overlap(introns[i, si][j, 0] - offset, introns[i, si][j, 1] + offset)) == 1:
116+
if len(gene_trees[(s, genes[i].chr)].overlap(int(introns[i, si][j, 0]) - offset, int(introns[i, si][j, 1]) + offset)) == 1:
117117
k_idx.append(j)
118118
if len(k_idx) < introns[i, si].shape[0]:
119119
cnt_rem += (introns[i, si].shape[0] - len(k_idx))
@@ -206,13 +206,10 @@ def log_progress(idx, total, bins=50):
206206
sys.stdout.flush()
207207

208208
def codeUTF8(s):
209-
return s.view(np.chararray).encode('utf-8')
209+
return s.astype('bytes')
210210

211211
def decodeUTF8(s):
212-
return s.view(np.chararray).decode('utf-8')
213-
214-
def isUTF8(s):
215-
return hasattr(s.view(np.chararray), 'decode')
212+
return s.astype('str')
216213

217214
def rev_comp(s):
218215
R = {'A':'T', 'T':'A', 'a':'t', 't':'a',

spladder/helpers_viz.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def get_conf_events(options, gid):
160160
IN = h5py.File(os.path.join(options.outdir, 'merge_graphs_%s_C%i.counts.hdf5' % (event_type, options.confidence)), 'r')
161161
if 'conf_idx' in IN and IN['conf_idx'].shape[0] > 0:
162162
conf_idx = IN['conf_idx'][:]
163-
k_idx = sp.where(sp.in1d(IN['gene_idx'][:][conf_idx], gid))[0]
163+
k_idx = sp.where(sp.isin(IN['gene_idx'][:][conf_idx], gid))[0]
164164
if k_idx.shape[0] > 0:
165165
event_info.extend([[event_type, x] for x in conf_idx[k_idx]])
166166
IN.close()

spladder/merge.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def merge_duplicate_exons(genes, options):
3636
if remove[j]:
3737
continue
3838
idx = np.where((exons[0, j] == exons[0, :]) & (exons[1, j] == exons[1, :]))[0]
39-
idx = idx[np.where(~np.in1d(idx, j))[0]]
39+
idx = idx[np.where(~np.isin(idx, j))[0]]
4040
if idx.shape[0] > 0:
4141
remove[idx] = True
4242
for k in idx:

spladder/reads.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import h5py
88
import uuid
99

10+
from collections import defaultdict
11+
1012
if __package__ is None:
1113
__package__ = 'modules'
1214

@@ -27,8 +29,8 @@ def get_reads(fname, chr_name, start, stop, strand=None, filter=None, mapped=Tru
2729
j = []
2830

2931
read_cnt = 0
30-
introns_p = dict()
31-
introns_m = dict()
32+
introns_p = defaultdict(int)
33+
introns_m = defaultdict(int)
3234

3335
if collapse:
3436
read_matrix = np.zeros((1, stop - start), dtype='int')
@@ -67,25 +69,26 @@ def get_reads(fname, chr_name, start, stop, strand=None, filter=None, mapped=Tru
6769
# 6 / P - padding
6870
# 7 / = - sequence match
6971
# 8 / X - sequence mismatch
70-
p = read.pos
72+
p = int(read.pos)
7173
for o in read.cigar:
7274
if o[0] == 3:
7375
if is_minus:
74-
try:
75-
introns_m[(p, p + o[1])] += 1
76-
except KeyError:
77-
introns_m[(p, p + o[1])] = 1
76+
introns_m[(p, p + o[1])] += 1
7877
else:
79-
try:
80-
introns_p[(p, p + o[1])] += 1
81-
except KeyError:
82-
introns_p[(p, p + o[1])] = 1
78+
introns_p[(p, p + o[1])] += 1
8379
if o[0] in [0, 2, 7, 8]:
84-
_start = int(max(p-start, 0))
85-
_stop = int(min(p + o[1] - start, stop - start))
80+
if p + o[1] <= start:
81+
p += o[1]
82+
continue
83+
if p < start:
84+
_start = 0
85+
_len = int(o[1]) - int(start) + p
86+
else:
87+
_start = p - int(start)
88+
_len = int(o[1])
89+
_stop = min(_start + _len, int(stop))
8690
if _stop < 0 or _start > length:
87-
if o[0] in [0, 2, 3, 7, 8]:
88-
p += o[1]
91+
p += o[1]
8992
continue
9093
if collapse:
9194
read_matrix[0, _start:_stop] += 1
@@ -423,7 +426,7 @@ def get_intron_list(genes, bam_fnames, options):
423426
strands = ['+', '-']
424427

425428
### ignore contigs not present in bam files
426-
keepidx = np.where(np.in1d(np.array([options.chrm_lookup[x.chr] for x in genes]), np.array([x.chr_num for x in regions])))[0]
429+
keepidx = np.where(np.isin(np.array([options.chrm_lookup[x.chr] for x in genes]), np.array([x.chr_num for x in regions])))[0]
427430
genes = genes[keepidx]
428431

429432
c = 0
@@ -446,6 +449,7 @@ def get_intron_list(genes, bam_fnames, options):
446449

447450
gg = np.array([copy.copy(genes[i])], dtype='object')
448451
assert(gg[0].strand == s)
452+
# TODO intron window is hard coded --> make configurable
449453
gg[0].start = max(gg[0].start - 5000, 1)
450454
gg[0].stop = gg[0].stop + 5000
451455
assert(gg[0].chr == contig)

spladder/spladder_viz.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ def spladder_viz(options):
375375
if len(data_track.samples) > 0:
376376
seg_sample_idx = []
377377
for track_samples in data_track.samples:
378-
seg_sample_idx.append(np.where(np.in1d(samples, track_samples))[0])
378+
seg_sample_idx.append(np.where(np.isin(samples, track_samples))[0])
379379
cov_from_segments(genes[g], segments, edges, edge_idx, size_factors, ax, xlim=plotrange, log=options.log, grid=True, order='C', sample_idx=seg_sample_idx)
380380
ax.get_yaxis().set_label_coords(1.02,0.5)
381381
ax.set_ylabel('segment counts')

0 commit comments

Comments
 (0)