Skip to content

Commit

Permalink
Ignoring of useless-object-inheritance now ignored as test as it is r…
Browse files Browse the repository at this point in the history
…equired for py2 and py3 compatibility. Added the ability to test if the bam file contained paired end reads
  • Loading branch information
markmcdowall committed Aug 2, 2018
1 parent a48694a commit f7d9523
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
33 changes: 31 additions & 2 deletions mg_common/tool/bam_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
# ------------------------------------------------------------------------------

# Object inheritance is required for py2 compatiblity
class bamUtils(object): # pylint: disable=invalid-name,useless-object-inheritance
class bamUtils(object): # pylint: disable=invalid-name
"""
Tool for handling bam files
"""
Expand All @@ -61,6 +61,16 @@ def bam_count_reads(bam_file, aligned=False):

return pysam.view("-c", bam_file).strip() # pylint: disable=no-member

@staticmethod
def bam_paired_reads(bam_file):
"""
Wrapper to test if a bam file contains paired end reads
"""
paired_count = pysam.view("-c", "-f", "1", bam_file).strip() # pylint: disable=no-member
if int(paired_count) > 0:
return True
return False

@staticmethod
def bam_sort(bam_file):
"""
Expand Down Expand Up @@ -359,7 +369,7 @@ def check_header(bam_file):


# Object inheritance is required for py2 compatiblity
class bamUtilsTask(object): # pylint: disable=invalid-name,useless-object-inheritance
class bamUtilsTask(object): # pylint: disable=invalid-name
"""
Wrappers so that the function above can be used as part of a @task within
COMPSs avoiding the files being copied around the infrastructure too many
Expand Down Expand Up @@ -685,6 +695,25 @@ def bam_stats(self, bam_file): # pylint: disable=no-self-use
bam_handle = bamUtils()
return bam_handle.bam_stats(bam_file)

@task(returns=bool, bam_file=FILE_IN)
def bam_paired_reads(self, bam_file): # pylint: disable=no-self-use
"""
Wrapper for the pysam SAMtools view function to identify if a bam file
contains paired end reads
Parameters
----------
bam_file : str
Location of the bam file that is to be indexed
Returns
-------
bool
True if the bam file contains paired end reads
"""
bam_handle = bamUtils()
return bam_handle.bam_stats(bam_file)

@task(bam_file=FILE_IN)
def check_header(self, bam_file): # pylint: disable=no-self-use
"""
Expand Down
4 changes: 2 additions & 2 deletions mg_common/tool/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@


# Object inheritance is required for py2 compatiblity
class cd(object): # pylint: disable=too-few-public-methods, invalid-name, useless-object-inheritance
class cd(object): # pylint: disable=too-few-public-methods, invalid-name
"""
Context manager for changing the current working directory
"""
Expand All @@ -42,7 +42,7 @@ def __exit__(self, etype, value, traceback):


# Object inheritance is required for py2 compatiblity
class common(object): # pylint: disable=too-few-public-methods, invalid-name, useless-object-inheritance
class common(object): # pylint: disable=too-few-public-methods, invalid-name
"""
Common functions that can be used generically across tools and pipelines
"""
Expand Down
2 changes: 1 addition & 1 deletion scripts/travis/pylint_harness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

disabled="--disable=similarities,invalid-name,too-many-statements,too-many-arguments,too-many-locals,too-few-public-methods,relative-import,no-self-use"
disabled="--disable=similarities,invalid-name,too-many-statements,too-many-arguments,too-many-locals,too-few-public-methods,relative-import,no-self-use,useless-object-inheritance"

pylint ${disabled} --rcfile pylintrc mg_common/ > output.err

Expand Down

0 comments on commit f7d9523

Please sign in to comment.