forked from daviddaiweizhang/fraposa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
28 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,28 @@ | ||
from dataclasses import dataclass | ||
class SampleID: | ||
""" A sample ID from a plink fam file, including FID and IID """ | ||
def __init__(self, fid, iid): | ||
self._fid = fid | ||
self._iid = iid | ||
|
||
def __repr__(self): | ||
return f"{self.__class__.__name__}(fid={repr(self.fid)}, iid={repr(self.iid)})" | ||
|
||
@dataclass(frozen=True) | ||
class SampleID: | ||
""" A sample ID from a plink fam/psam file, including FID and IID """ | ||
FID: str | ||
IID: str | ||
@property | ||
def fid(self): | ||
if self._fid == "0": # 0 means missing :) | ||
return self._iid | ||
else: | ||
return self._fid | ||
|
||
@property | ||
def iid(self): | ||
return self._iid | ||
|
||
def __hash__(self): | ||
return hash((self.fid, self.iid)) | ||
|
||
def __eq__(self, other): | ||
if not isinstance(other, SampleID): | ||
return NotImplemented | ||
|
||
return self.fid == other.fid and self.iid == other.iid |