Skip to content

Commit

Permalink
Merge pull request #32 from pepkit/dev
Browse files Browse the repository at this point in the history
version 0.3.2
  • Loading branch information
nsheff authored May 9, 2019
2 parents 5f028e4 + f1a2e78 commit 3aed27e
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 338 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ open_pipelines/
*RESERVE*

# Build-related stuff
build/
dist/
peppy.egg-info/
divvy.egg-info/

#ipynm checkpoints
*ipynb_checkpoints*
Expand Down
2 changes: 1 addition & 1 deletion divvy/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "0.4dev"
__version__ = "0.3.2"

1 change: 1 addition & 0 deletions divvy/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ def add_subparser(cmd):
cmd, description=msg_by_cmd[cmd], help=msg_by_cmd[cmd])

write_subparser = add_subparser("write")
list_subparser = add_subparser("list")

write_subparser.add_argument(
"-S", "--settings",
Expand Down
105 changes: 0 additions & 105 deletions divvy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import random
import re
import string
import subprocess as sp
import sys
if sys.version_info < (3, 0):
from urlparse import urlparse
Expand All @@ -21,58 +20,6 @@
_LOGGER = logging.getLogger(__name__)


def add_project_sample_constants(sample, project):
"""
Update a Sample with constants declared by a Project.
:param Sample sample: sample instance for which to update constants
based on Project
:param Project project: Project with which to update Sample; it
may or may not declare constants. If not, no update occurs.
:return Sample: Updates Sample instance, according to any and all
constants declared by the Project.
"""
sample.update(project.constants)
return sample


def check_bam(bam, o):
"""
Check reads in BAM file for read type and lengths.
:param str bam: BAM file path.
:param int o: Number of reads to look at for estimation.
"""
try:
p = sp.Popen(['samtools', 'view', bam], stdout=sp.PIPE)
# Count paired alignments
paired = 0
read_lengths = defaultdict(int)
while o > 0: # Count down number of lines
line = p.stdout.readline().decode().split("\t")
flag = int(line[1])
read_lengths[len(line[9])] += 1
if 1 & flag: # check decimal flag contains 1 (paired)
paired += 1
o -= 1
p.kill()
except OSError:
reason = "Note (samtools not in path): For NGS inputs, " \
"pep needs samtools to auto-populate " \
"'read_length' and 'read_type' attributes; " \
"these attributes were not populated."
raise OSError(reason)

_LOGGER.debug("Read lengths: {}".format(read_lengths))
_LOGGER.debug("paired: {}".format(paired))
return read_lengths, paired


def check_fastq(fastq, o):
raise NotImplementedError("Detection of read type/length for "
"fastq input is not yet implemented.")


def check_sample_sheet_row_count(sheet, filepath):
"""
Quick-and-dirt proxy for Sample count validation.
Expand Down Expand Up @@ -104,38 +51,6 @@ def copy(self):
return obj


def expandpath(path):
"""
Expand a filesystem path that may or may not contain user/env vars.
:param str path: path to expand
:return str: expanded version of input path
"""
return os.path.expandvars(os.path.expanduser(path)).replace("//", "/")


def get_file_size(filename):
"""
Get size of all files in gigabytes (Gb).
:param str | collections.Iterable[str] filename: A space-separated
string or list of space-separated strings of absolute file paths.
:return float: size of file(s), in gigabytes.
"""
if filename is None:
return float(0)
if type(filename) is list:
return float(sum([get_file_size(x) for x in filename]))
try:
total_bytes = sum([float(os.stat(f).st_size)
for f in filename.split(" ") if f is not ''])
except OSError:
# File not found
return 0.0
else:
return float(total_bytes) / (1024 ** 3)


def import_from_source(module_filepath):
"""
Import a module from a particular filesystem location.
Expand Down Expand Up @@ -206,26 +121,6 @@ def parse_config_file(conf_file):
return env_settings


def parse_ftype(input_file):
"""
Checks determine filetype from extension.
:param str input_file: String to check.
:return str: filetype (extension without dot prefix)
:raises TypeError: if file does not appear of a supported type
"""
if input_file.endswith(".bam"):
return "bam"
elif input_file.endswith(".fastq") or \
input_file.endswith(".fq") or \
input_file.endswith(".fq.gz") or \
input_file.endswith(".fastq.gz"):
return "fastq"
else:
raise TypeError("Type of input file ends in neither '.bam' "
"nor '.fastq' [file: '" + input_file + "']")


def parse_text_data(lines_or_path, delimiter=os.linesep):
"""
Interpret input argument as lines of data. This is intended to support
Expand Down
2 changes: 2 additions & 0 deletions docs/autodoc_build/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
207 changes: 0 additions & 207 deletions docs/autodoc_build/divvy.md

This file was deleted.

Loading

0 comments on commit 3aed27e

Please sign in to comment.