-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from JLSteenwyk/efficient
Efficient
- Loading branch information
Showing
94 changed files
with
1,318 additions
and
1,482 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
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
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,14 +1,16 @@ | ||
from .base import Alignment | ||
|
||
from typing import Dict | ||
|
||
|
||
class AlignmentLength(Alignment): | ||
def __init__(self, args) -> None: | ||
super().__init__(**self.process_args(args)) | ||
|
||
def run(self): | ||
alignment, _ = self.get_alignment_and_format() | ||
def run(self) -> None: | ||
alignment, _, _ = self.get_alignment_and_format() | ||
aln_len = alignment.get_alignment_length() | ||
print(aln_len) | ||
|
||
def process_args(self, args): | ||
def process_args(self, args) -> Dict[str, str]: | ||
return dict(alignment_file_path=args.alignment) |
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,40 +1,62 @@ | ||
from argparse import Namespace | ||
from typing import Dict, Tuple | ||
|
||
from Bio.Align import MultipleSeqAlignment | ||
|
||
from .base import Alignment | ||
|
||
|
||
class AlignmentLengthNoGaps(Alignment): | ||
def __init__(self, args) -> None: | ||
super().__init__(**self.process_args(args)) | ||
|
||
def run(self): | ||
alignment, alignment_format = self.get_alignment_and_format() | ||
def run(self) -> None: | ||
alignment, _, is_protein = self.get_alignment_and_format() | ||
( | ||
aln_len_no_gaps, | ||
aln_len, | ||
aln_len_no_gaps_per, | ||
) = self.calculate_alignment_length_no_gaps(alignment) | ||
) = self.calculate_alignment_length_no_gaps(alignment, is_protein) | ||
print(f"{aln_len_no_gaps}\t{aln_len}\t{round(aln_len_no_gaps_per, 4)}") | ||
|
||
def process_args(self, args): | ||
def process_args( | ||
self, | ||
args: Namespace, | ||
) -> Dict[str, str]: | ||
return dict(alignment_file_path=args.alignment) | ||
|
||
def calculate_alignment_length_no_gaps(self, alignment): | ||
def calculate_alignment_length_no_gaps( | ||
self, | ||
alignment: MultipleSeqAlignment, | ||
is_protein: bool, | ||
) -> Tuple[int, int, float]: | ||
aln_len = alignment.get_alignment_length() | ||
aln_len_no_gaps = self.get_sites_no_gaps_count(alignment, aln_len) | ||
aln_len_no_gaps = self.get_sites_no_gaps_count( | ||
alignment, | ||
aln_len, | ||
is_protein | ||
) | ||
|
||
# calculate percent of variable sites | ||
aln_len_no_gaps_per = (aln_len_no_gaps / aln_len) * 100 | ||
|
||
return aln_len_no_gaps, aln_len, aln_len_no_gaps_per | ||
|
||
def get_sites_no_gaps_count(self, alignment, aln_len): | ||
def get_sites_no_gaps_count( | ||
self, | ||
alignment: MultipleSeqAlignment, | ||
aln_len: int, | ||
is_protein: bool, | ||
) -> int: | ||
""" | ||
Count sites in the alignment with no gaps | ||
""" | ||
aln_len_no_gaps = 0 | ||
for i in range(0, aln_len): | ||
seq_at_position = "" | ||
seq_at_position += alignment[:, i] | ||
if "-" not in seq_at_position: | ||
|
||
gap_chars = self.get_gap_chars() | ||
|
||
for i in range(aln_len): | ||
column = set(alignment[:, i]) | ||
if column.isdisjoint(gap_chars): | ||
aln_len_no_gaps += 1 | ||
|
||
return aln_len_no_gaps |
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
Oops, something went wrong.