From c07224a62b5cf8c7c1244b0e38225a9babf6e964 Mon Sep 17 00:00:00 2001
From: psj1997 <1176894699@qq.com>
Date: Wed, 11 Aug 2021 20:45:10 +0800
Subject: [PATCH] Fix pd.merge warning

---
 SemiBin/generate_coverage.py | 21 +++++++++++----------
 setup.py                     |  5 ++---
 test/test_cov.py             |  3 +++
 3 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/SemiBin/generate_coverage.py b/SemiBin/generate_coverage.py
index dd598f5..ec11c5f 100644
--- a/SemiBin/generate_coverage.py
+++ b/SemiBin/generate_coverage.py
@@ -83,24 +83,27 @@ def calculate_coverage(depth_file, must_link_threshold, edge=75, is_combined=Fal
     contig_cov = np.concatenate((data_contig_list, coverage), axis=1, dtype=object)
 
     if is_combined:
+        column_name = '{0}_cov'.format(depth_file)
         contig_cov = pd.DataFrame(
-            data=contig_cov[:, 1:], index=contig_cov[:, 0], columns=['cov'])
-        contig_cov['cov'] = contig_cov['cov'].astype('float')
+            data=contig_cov[:, 1:], index=contig_cov[:, 0], columns=[column_name])
+        contig_cov[column_name] = contig_cov[column_name].astype('float')
         split_contig_list = np.expand_dims(np.array(split_contig_list), axis=1)
         split_coverage = np.expand_dims(np.array(split_coverage), axis=1)
         split_contig_cov = np.concatenate(
             (split_contig_list, split_coverage), axis=1, dtype=object)
         split_contig_cov = pd.DataFrame(
-            data=split_contig_cov[:, 1:], index=split_contig_cov[:, 0], columns=['cov'])
-        split_contig_cov['cov'] = split_contig_cov['cov'].astype('float')
+            data=split_contig_cov[:, 1:], index=split_contig_cov[:, 0], columns=[column_name])
+        split_contig_cov[column_name] = split_contig_cov[column_name].astype('float')
         return contig_cov, split_contig_cov
     else:
+        column_name_mean = '{0}_mean'.format(depth_file)
+        column_name_var = '{0}_var'.format(depth_file)
         var = np.expand_dims(np.array(var), axis=1)
         contig_cov = np.concatenate((contig_cov, var), axis=1, dtype=object)
         contig_cov = pd.DataFrame(
-            data=contig_cov[:, 1:], index=contig_cov[:, 0], columns=['mean', 'var'])
-        contig_cov['mean'] = contig_cov['mean'].astype('float')
-        contig_cov['var'] = contig_cov['var'].astype('float')
+            data=contig_cov[:, 1:], index=contig_cov[:, 0], columns=[column_name_mean, column_name_var])
+        contig_cov[column_name_mean] = contig_cov[column_name_mean].astype('float')
+        contig_cov[column_name_var] = contig_cov[column_name_var].astype('float')
         return contig_cov
 
 
@@ -129,9 +132,7 @@ def generate_cov(bam_file, bam_index, out, threshold,
             stdout=bedtools_out)
 
     if is_combined:
-        contig_cov, must_link_contig_cov = calculate_coverage(bam_depth, threshold, is_combined = is_combined, sep = sep,
-                                                              contig_threshold = contig_threshold if sep is None else 1000,
-                                                              contig_threshold_dict =  contig_threshold if sep is not None else None)
+        contig_cov, must_link_contig_cov = calculate_coverage(bam_depth, threshold, is_combined = is_combined, sep = sep, contig_threshold = contig_threshold if sep is None else 1000, contig_threshold_dict =  contig_threshold if sep is not None else None)
 
         contig_cov = contig_cov.apply(lambda x: x + 1e-5)
         must_link_contig_cov = must_link_contig_cov.apply(lambda x: x + 1e-5)
diff --git a/setup.py b/setup.py
index d66b31e..a88225b 100644
--- a/setup.py
+++ b/setup.py
@@ -16,7 +16,6 @@ setup(name='SemiBin',
         'Topic :: Scientific/Engineering :: Bio-Informatics',
         'Topic :: Scientific/Engineering :: Artificial Intelligence',
         'License :: OSI Approved :: MIT License',
-        'Programming Language :: Python :: 3.6',
         'Programming Language :: Python :: 3.7',
         'Programming Language :: Python :: 3.8',
         'Programming Language :: Python :: 3.9',
@@ -26,15 +25,15 @@ setup(name='SemiBin',
       author_email='shaojun1997777@gmail.com',
       license='MIT',
       packages = ['SemiBin'],
-      setup_requires=['numpy'],
       install_requires=[
+          'numpy',
           'Biopython',
           'tqdm',
           'pyyaml',
           'atomicwrites',
           'torch==1.8',
           'python-igraph',
-          'pandas==1.2.4',
+          'pandas',
           'scikit-learn',
           'requests',
       ],
diff --git a/test/test_cov.py b/test/test_cov.py
index 9438b48..07cc0a0 100644
--- a/test/test_cov.py
+++ b/test/test_cov.py
@@ -34,6 +34,8 @@ def test_cov(tmpdir):
         must_link_threshold=0,
         is_combined=True,
         contig_threshold=0)
+    cov.columns = ['cov']
+    cov_split.columns = ['cov']
     assert_frame_equal(cov, pd.DataFrame([2.581818, 2.627907], index=[
                        'k141_63080', 'k141_0'], columns=['cov']))
     assert_frame_equal(cov_split, pd.DataFrame([2.609756, 2.554217, 2.682243, 2.574074], index=[
@@ -44,5 +46,6 @@ def test_cov(tmpdir):
         must_link_threshold=0,
         is_combined=False,
         contig_threshold=0)
+    cov.columns = ['mean', 'var']
     assert_frame_equal(cov, pd.DataFrame([[2.581818, 0.606942], [
                        2.627907, 0.252244]], index=['k141_63080', 'k141_0'], columns=['mean', 'var']))
-- 
2.23.0.windows.1

