Skip to content

Commit

Permalink
Merge pull request #231 from alneberg/fix_warnings
Browse files Browse the repository at this point in the history
Fix warnings regarding the .ix depreciation
  • Loading branch information
alneberg committed Dec 18, 2018
2 parents c7d69a6 + f6e15fd commit 4a08818
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion bin/concoct
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def main(args):
sys.exit(-1)

if cov is not None:
joined = composition.join(cov.ix[:,cov_range[0]:cov_range[1]],how="inner")
joined = composition.join(cov.loc[:,cov_range[0]:cov_range[1]],how="inner")
else:
joined = composition

Expand Down
16 changes: 8 additions & 8 deletions concoct/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,32 +87,32 @@ def load_coverage(cov_file, contig_lengths, no_cov_normalization, add_total_cove
cov_range = (cov.columns[0],cov.columns[-1])

# Adding pseudo count
cov.ix[:,cov_range[0]:cov_range[1]] = cov.ix[:,cov_range[0]:cov_range[1]].add(
cov.loc[:,cov_range[0]:cov_range[1]] = cov.loc[:,cov_range[0]:cov_range[1]].add(
(read_length/contig_lengths),
axis='index')

if not no_cov_normalization:
#Normalize per sample first
cov.ix[:,cov_range[0]:cov_range[1]] = \
_normalize_per_sample(cov.ix[:,cov_range[0]:cov_range[1]])
cov.loc[:,cov_range[0]:cov_range[1]] = \
_normalize_per_sample(cov.loc[:,cov_range[0]:cov_range[1]])

temp_cov_range = None
# Total coverage should be calculated after per sample normalization
if add_total_coverage:
cov['total_coverage'] = cov.ix[:,cov_range[0]:cov_range[1]].sum(axis=1)
cov['total_coverage'] = cov.loc[:,cov_range[0]:cov_range[1]].sum(axis=1)
temp_cov_range = (cov_range[0],'total_coverage')

if not no_cov_normalization:
# Normalize contigs next
cov.ix[:,cov_range[0]:cov_range[1]] = \
_normalize_per_contig(cov.ix[:,cov_range[0]:cov_range[1]])
cov.loc[:,cov_range[0]:cov_range[1]] = \
_normalize_per_contig(cov.loc[:,cov_range[0]:cov_range[1]])

if temp_cov_range:
cov_range = temp_cov_range

# Log transform
cov.ix[:,cov_range[0]:cov_range[1]] = np.log(
cov.ix[:,cov_range[0]:cov_range[1]])
cov.loc[:,cov_range[0]:cov_range[1]] = np.log(
cov.loc[:,cov_range[0]:cov_range[1]])

logging.info('Successfully loaded coverage data.')
return cov, cov_range
Expand Down
16 changes: 8 additions & 8 deletions tests/test_gen_input_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ def test_with_bamfiles(self):

new_output = os.path.join(tmp_dir_path, 'inputtable.tsv')
df = pd.read_csv(new_output, sep='\t', index_col=0)
assert_almost_equal(df['cov_mean_sample_ten_reads'].ix['contig-75000034'], 10*100.0/1615, 5)
assert_almost_equal(df['cov_mean_sample_ten_reads'].ix['contig-21000001'], 10*100.0/9998, 5)
assert_almost_equal(df['cov_mean_sample_twenty_reads'].ix['contig-75000034'], 20*100.0/1615, 5)
assert_almost_equal(df['cov_mean_sample_twenty_reads'].ix['contig-21000001'], 20*100.0/9998, 5)
assert_almost_equal(df['cov_mean_sample_ten_reads'].loc['contig-75000034'], 10*100.0/1615, 5)
assert_almost_equal(df['cov_mean_sample_ten_reads'].loc['contig-21000001'], 10*100.0/9998, 5)
assert_almost_equal(df['cov_mean_sample_twenty_reads'].loc['contig-75000034'], 20*100.0/1615, 5)
assert_almost_equal(df['cov_mean_sample_twenty_reads'].loc['contig-21000001'], 20*100.0/9998, 5)


#assert_equal(new_output, old_output,
Expand All @@ -111,8 +111,8 @@ def test_with_bedfiles(self):

new_output = os.path.join(tmp_dir_path, 'inputtable.tsv')
df = pd.read_csv(new_output, sep='\t', index_col=0)
assert_almost_equal(df['cov_mean_sample_ten_reads'].ix['contig-75000034'], 10*100.0/1615, 5)
assert_almost_equal(df['cov_mean_sample_ten_reads'].ix['contig-21000001'], 10*100.0/9998, 5)
assert_almost_equal(df['cov_mean_sample_twenty_reads'].ix['contig-75000034'], 20*100.0/1615, 5)
assert_almost_equal(df['cov_mean_sample_twenty_reads'].ix['contig-21000001'], 20*100.0/9998, 5)
assert_almost_equal(df['cov_mean_sample_ten_reads'].loc['contig-75000034'], 10*100.0/1615, 5)
assert_almost_equal(df['cov_mean_sample_ten_reads'].loc['contig-21000001'], 10*100.0/9998, 5)
assert_almost_equal(df['cov_mean_sample_twenty_reads'].loc['contig-75000034'], 20*100.0/1615, 5)
assert_almost_equal(df['cov_mean_sample_twenty_reads'].loc['contig-21000001'], 20*100.0/9998, 5)

6 changes: 3 additions & 3 deletions tests/test_unittest_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_load_composition(self):
assert_equal(len(c_len), len(contig_lengths))
# All equal
for ix in ids:
assert_equal(c_len.ix[ix], contig_lengths.ix[ix])
assert_equal(c_len.loc[ix], contig_lengths.loc[ix])


def test__calculate_composition(self):
Expand All @@ -67,15 +67,15 @@ def test__calculate_composition(self):

for seq_id, s in seq_strings.items():
c = count_substrings(s, "".join(kmer_s))
assert_equal(composition.ix[seq_id, feature_mapping[kmer_s]], c+1)
assert_equal(composition.loc[seq_id, feature_mapping[kmer_s]], c+1)

# Check that non palindromic kmers works as well:
kmer_s = ('A', 'G', 'G', 'G')
reverse_kmer_s = ('C', 'C', 'C', 'T')
for seq_id, s in seq_strings.items():
c_1 = count_substrings(s, "".join(kmer_s))
c_2 = count_substrings(s, "".join(reverse_kmer_s))
assert_equal(composition.ix[seq_id, feature_mapping[kmer_s]], c_1 + c_2 + 1)
assert_equal(composition.loc[seq_id, feature_mapping[kmer_s]], c_1 + c_2 + 1)


def count_substrings(s, subs):
Expand Down

0 comments on commit 4a08818

Please sign in to comment.