Skip to content

Commit

Permalink
Release 1.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
lemieuxl committed Feb 8, 2017
2 parents b61ce30 + 468cd80 commit a7e2853
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 28 deletions.
32 changes: 10 additions & 22 deletions pyplink/pyplink.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def _read_bim(self):
# Saving the data in the object
self._bim = bim[["chrom", "pos", "cm", "a1", "a2", "i"]]
self._nb_markers = self._bim.shape[0]
self._markers = np.array(list(self._bim.index))
self._markers = self._bim.index.values

def get_bim(self):
"""Returns the BIM file."""
Expand Down Expand Up @@ -346,26 +346,14 @@ def iter_geno_marker(self, markers, return_seek=False):
if isinstance(markers, str):
markers = [markers]

# Checking the list of required markers
unknown_markers = set(markers) - set(self._bim.index)
if len(unknown_markers) > 0:
raise ValueError("{}: marker not in BIM".format(
sorted(unknown_markers)
))

# Getting the required markers
required_markers = self._bim.loc[markers, :]

# Then, we iterate
for snp, seek_position in required_markers.i.iteritems():
# Seeking to the correct position
self.seek(seek_position)

# Getting the value
if return_seek:
yield snp, self._read_current_marker(), seek_position
else:
yield snp, self._read_current_marker()
# Iterating over all markers
if return_seek:
for marker in markers:
geno, seek = self.get_geno_marker(marker, return_seek=True)
yield marker, geno, seek
else:
for marker in markers:
yield marker, self.get_geno_marker(marker)

def iter_acgt_geno_marker(self, markers):
"""Iterates over genotypes for given markers (ACGT format)."""
Expand All @@ -380,7 +368,7 @@ def get_geno_marker(self, marker, return_seek=False):
raise UnsupportedOperation("not available in 'w' mode")

# Check if the marker exists
if marker not in set(self._bim.index):
if marker not in self._bim.index:
raise ValueError("{}: marker not in BIM".format(marker))

# Seeking to the correct position
Expand Down
12 changes: 6 additions & 6 deletions pyplink/tests/test_pyplink.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from __future__ import print_function

import os
import sys
import stat
import random
import shutil
Expand Down Expand Up @@ -66,10 +67,11 @@ def get_plink(tmp_dir):
plink_path += ".exe"

if find_executable(plink_path) is None:
print("Downloading Plink")
print("Downloading Plink", file=sys.stderr)

# The url for each platform
url = "http://pngu.mgh.harvard.edu/~purcell/plink/dist/{filename}"
url = ("http://statgen.org/wp-content/uploads/Softwares/"
"plink-1.0.7/{filename}")

# Getting the name of the file
filename = ""
Expand Down Expand Up @@ -601,8 +603,7 @@ def test_iter_geno_marker(self):
markers.extend(["unknown_1", "unknown_2"])
with self.assertRaises(ValueError) as cm:
[i for i in self.pedfile.iter_geno_marker(markers)]
self.assertEqual("['unknown_1', 'unknown_2']: marker not in BIM",
str(cm.exception))
self.assertEqual("unknown_1: marker not in BIM", str(cm.exception))

def test_iter_geno_marker_w_mode(self):
"""Tests that an exception is raised if in write mode."""
Expand Down Expand Up @@ -642,8 +643,7 @@ def test_iter_acgt_geno_marker(self):
markers.extend(["unknown_3", "unknown_4"])
with self.assertRaises(ValueError) as cm:
[i for i in self.pedfile.iter_acgt_geno_marker(markers)]
self.assertEqual("['unknown_3', 'unknown_4']: marker not in BIM",
str(cm.exception))
self.assertEqual("unknown_3: marker not in BIM", str(cm.exception))

def test_iter_acgt_geno_marker_w_mode(self):
"""Tests that an exception is raised if in write mode."""
Expand Down

0 comments on commit a7e2853

Please sign in to comment.