diff utils.py @ 6:4f1896782f7c draft default tip

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit 05dc325ce687441e5d3bdbdedcc0e3529cd5e070"
author bgruening
date Wed, 14 Apr 2021 09:31:11 +0000
parents f8f53668d5a2
children
line wrap: on
line diff
--- a/utils.py	Tue Jul 28 08:48:35 2020 -0400
+++ b/utils.py	Wed Apr 14 09:31:11 2021 +0000
@@ -4,40 +4,54 @@
 """
 
 from __future__ import print_function
-import sys, gzip
+
+import gzip
+import sys
+
 from rdkit import Chem
 
+
 def log(*args, **kwargs):
-    """Log output to STDERR
-    """
+    """Log output to STDERR"""
     print(*args, file=sys.stderr, **kwargs)
 
+
 def open_file_for_reading(filename):
     """Open the file gunzipping it if it ends with .gz."""
-    if filename.lower().endswith('.gz'):
-        return gzip.open(filename, 'rb')
+    if filename.lower().endswith(".gz"):
+        return gzip.open(filename, "rb")
     else:
-        return open(filename, 'rb')
+        return open(filename, "rb")
+
 
 def open_file_for_writing(filename):
-    if filename.lower().endswith('.gz'):
-        return gzip.open(filename, 'at')
+    if filename.lower().endswith(".gz"):
+        return gzip.open(filename, "at")
     else:
-        return open(filename, 'w+')
+        return open(filename, "w+")
+
 
 def read_single_molecule(filename, index=1, format=None):
     """Read a single molecule as a RDKit Mol object. This can come from a file in molfile or SDF format.
     If SDF then you can also specify an index of the molecule that is read (default is the first)
     """
     mol = None
-    if format == 'mol' or filename.lower().endswith('.mol') or filename.lower().endswith('.mol.gz'):
+    if (
+        format == "mol"
+        or filename.lower().endswith(".mol")
+        or filename.lower().endswith(".mol.gz")
+    ):
         file = open_file_for_reading(filename)
         mol = Chem.MolFromMolBlock(file.read())
         file.close()
-    elif format == 'sdf' or filename.lower().endswith('.sdf') or filename.lower().endswith('.sdf.gz'):
+    elif (
+        format == "sdf"
+        or filename.lower().endswith(".sdf")
+        or filename.lower().endswith(".sdf.gz")
+    ):
         file = open_file_for_reading(filename)
         supplier = Chem.ForwardSDMolSupplier(file)
-        for i in range(0,index):
+        for i in range(0, index):
             if supplier.atEnd():
                 break
             mol = next(supplier)
@@ -46,4 +60,4 @@
     if not mol:
         raise ValueError("Unable to read molecule")
 
-    return mol
\ No newline at end of file
+    return mol