Skip to content

Commit ed0e9bb

Browse files
authored
Merge pull request #114 from databio/dev
Release 0.9.1
2 parents c781e5d + 8ad8035 commit ed0e9bb

File tree

5 files changed

+48
-20
lines changed

5 files changed

+48
-20
lines changed

doc/source/changelog.rst

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
Changelog
22
******************************
3+
- **v0.9.1** (*2019-01-29*):
4+
5+
- Fixed a bug in NGSTk that caused errors for read counting functions on
6+
MACOS. MACOS ``wc`` returns leading whitespace, which caused these functions
7+
to fail.
38

49
- **v0.9.0** (*2018-11-19*):
510

pypiper/_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.9.0"
1+
__version__ = "0.9.1"

pypiper/manager.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
from .flags import *
2727
from .utils import \
2828
check_shell, check_shell_pipes, checkpoint_filepath, clear_flags, flag_name, \
29-
make_lock_name, pipeline_filepath, CHECKPOINT_SPECIFICATIONS, split_by_pipes
29+
is_multi_target, make_lock_name, pipeline_filepath, \
30+
CHECKPOINT_SPECIFICATIONS, split_by_pipes
3031
from ._version import __version__
3132
import __main__
3233

@@ -553,8 +554,8 @@ def run(self, cmd, target=None, lock_name=None, shell="guess",
553554
554555
:param cmd: Shell command(s) to be run.
555556
:type cmd: str or list
556-
:param target: Output file to be produced. Optional.
557-
:type target: str or None
557+
:param target: Output file(s) to produce, optional
558+
:type target: None or str or Sequence of str
558559
:param lock_name: Name of lock file. Optional.
559560
:type lock_name: str or None
560561
:param shell: If command requires should be run in its own shell.
@@ -612,7 +613,7 @@ def run(self, cmd, target=None, lock_name=None, shell="guess",
612613

613614
# If the target is a list, for now let's just strip it to the first target.
614615
# Really, it should just check for all of them.
615-
if isinstance(target, list):
616+
if is_multi_target(target):
616617
target = target[0]
617618
#primary_target = target[0]
618619
# Create lock file:
@@ -1171,7 +1172,7 @@ def report_object(self, key, filename, anchor_text=None, anchor_image=None,
11711172
relative_anchor_image = os.path.relpath(anchor_image, self.outfolder) \
11721173
if os.path.isabs(anchor_image) else anchor_image
11731174
else:
1174-
relative_anchor_image = ""
1175+
relative_anchor_image = "None"
11751176

11761177

11771178
message_raw = "{key}\t{filename}\t{anchor_text}\t{anchor_image}\t{annotation}".format(

pypiper/ngstk.py

+15-14
Original file line numberDiff line numberDiff line change
@@ -655,22 +655,22 @@ def merge_fastq(self, inputs, output, run=False, remove_inputs=False):
655655

656656
def count_lines(self, file_name):
657657
"""
658-
Uses the command-line utility wc to count the number of lines in a file.
658+
Uses the command-line utility wc to count the number of lines in a file. For MacOS, must strip leading whitespace from wc.
659659
660660
:param file_name: name of file whose lines are to be counted
661661
:type file_name: str
662662
"""
663-
x = subprocess.check_output("wc -l " + file_name + " | cut -f1 -d' '", shell=True)
664-
return x
663+
x = subprocess.check_output("wc -l " + file_name + " | sed -E 's/^[[:space:]]+//' | cut -f1 -d' '", shell=True)
664+
return x.strip()
665665

666666
def count_lines_zip(self, file_name):
667667
"""
668-
Uses the command-line utility wc to count the number of lines in a file.
668+
Uses the command-line utility wc to count the number of lines in a file. For MacOS, must strip leading whitespace from wc.
669669
For compressed files.
670670
:param file: file_name
671671
"""
672-
x = subprocess.check_output("gunzip -c " + file_name + " | wc -l | cut -f1 -d' '", shell=True)
673-
return x
672+
x = subprocess.check_output("gunzip -c " + file_name + " | wc -l | sed -E 's/^[[:space:]]+//' | cut -f1 -d' '", shell=True)
673+
return x.strip()
674674

675675
def get_chrs_from_bam(self, file_name):
676676
"""
@@ -701,10 +701,10 @@ def count_unique_reads(self, file_name, paired_end):
701701
if file_name.endswith("bam"):
702702
param = ""
703703
if paired_end:
704-
r1 = self.samtools_view(file_name, param=param + " -f64", postpend=" | cut -f1 | sort -k1,1 -u | wc -l ")
705-
r2 = self.samtools_view(file_name, param=param + " -f128", postpend=" | cut -f1 | sort -k1,1 -u | wc -l ")
704+
r1 = self.samtools_view(file_name, param=param + " -f64", postpend=" | cut -f1 | sort -k1,1 -u | wc -l | sed -E 's/^[[:space:]]+//'")
705+
r2 = self.samtools_view(file_name, param=param + " -f128", postpend=" | cut -f1 | sort -k1,1 -u | wc -l | sed -E 's/^[[:space:]]+//'")
706706
else:
707-
r1 = self.samtools_view(file_name, param=param + "", postpend=" | cut -f1 | sort -k1,1 -u | wc -l ")
707+
r1 = self.samtools_view(file_name, param=param + "", postpend=" | cut -f1 | sort -k1,1 -u | wc -l | sed -E 's/^[[:space:]]+//'")
708708
r2 = 0
709709
return int(r1) + int(r2)
710710

@@ -733,11 +733,11 @@ def count_unique_mapped_reads(self, file_name, paired_end):
733733
else:
734734
raise ValueError("Not a SAM or BAM: '{}'".format(file_name))
735735

736-
if paired_end:
737-
r1 = self.samtools_view(file_name, param=param + " -f64", postpend=" | cut -f1 | sort -k1,1 -u | wc -l ")
738-
r2 = self.samtools_view(file_name, param=param + " -f128", postpend=" | cut -f1 | sort -k1,1 -u | wc -l ")
736+
if paired_end:
737+
r1 = self.samtools_view(file_name, param=param + " -f64", postpend=" | cut -f1 | sort -k1,1 -u | wc -l | sed -E 's/^[[:space:]]+//'")
738+
r2 = self.samtools_view(file_name, param=param + " -f128", postpend=" | cut -f1 | sort -k1,1 -u | wc -l | sed -E 's/^[[:space:]]+//'")
739739
else:
740-
r1 = self.samtools_view(file_name, param=param + "", postpend=" | cut -f1 | sort -k1,1 -u | wc -l ")
740+
r1 = self.samtools_view(file_name, param=param + "", postpend=" | cut -f1 | sort -k1,1 -u | wc -l | sed -E 's/^[[:space:]]+//'")
741741
r2 = 0
742742

743743
return int(r1) + int(r2)
@@ -867,7 +867,8 @@ def count_concordant(self, aligned_bam):
867867
:type aligned_bam: str
868868
"""
869869
cmd = self.tools.samtools + " view " + aligned_bam + " | "
870-
cmd += "grep 'YT:Z:CP'" + " | uniq -u | wc -l"
870+
cmd += "grep 'YT:Z:CP'" + " | uniq -u | wc -l | sed -E 's/^[[:space:]]+//'"
871+
871872
return subprocess.check_output(cmd, shell=True)
872873

873874

pypiper/utils.py

+21
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,27 @@ def make_lock_name(original_path, path_base_folder):
430430
return original_path.replace(path_base_folder, "").replace(os.sep, "__")
431431

432432

433+
def is_multi_target(target):
434+
"""
435+
Determine if pipeline manager's run target is multiple.
436+
437+
:param None or str or Sequence of str target: 0, 1, or multiple targets
438+
:return bool: Whether there are multiple targets
439+
:raise TypeError: if the argument is neither None nor string nor Sequence
440+
"""
441+
if sys.version_info < (3, 3):
442+
from collections import Sequence
443+
else:
444+
from collections.abc import Sequence
445+
if target is None or isinstance(target, str):
446+
return False
447+
elif isinstance(target, Sequence):
448+
return len(target) > 1
449+
else:
450+
raise TypeError("Could not interpret argument as a target: {} ({})".
451+
format(target, type(target)))
452+
453+
433454
def parse_cores(cores, pm, default):
434455
"""
435456
Framework to finalize number of cores for an operation.

0 commit comments

Comments
 (0)