Skip to content

Commit

Permalink
bugfix: a3m.py check functions did not return True... never...
Browse files Browse the repository at this point in the history
  • Loading branch information
meiermark committed Jul 12, 2017
1 parent 000ecb9 commit f74f336
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/ffindex
17 changes: 14 additions & 3 deletions scripts/a3m.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,20 @@ def check_and_add_annotation(self, header, sequence):
return False

def check_match_states(self, match_states):
if not self.nr_match_states:
self.nr_match_states = match_states

if match_states == 0:
raise A3MFormatError("Sequence with zero match states!")
elif self.nr_match_states and match_states != self.nr_match_states:
elif match_states != self.nr_match_states:
raise A3MFormatError(
("Sequence with diverging number "
"of match states ({} vs. {})!").format(
match_states,
self.nr_match_states
)
)
else:
self.nr_match_states = match_states


def check_ss_conf(self, sequence):
count_match_states = sum((c in self.VALID_SS_CONF_STATES
Expand All @@ -96,6 +98,8 @@ def check_ss_conf(self, sequence):
raise A3MFormatError(
("Undefined character(s) '{}' in predicted "
"secondary structure confidence!").format(invalid_states))
else:
return True

def check_ss_pred(self, sequence):
count_match_states = sum((c in self.VALID_SS_STATES
Expand All @@ -110,6 +114,8 @@ def check_ss_pred(self, sequence):
raise A3MFormatError(
("Undefined character(s) '{}' in predicted "
"secondary structure!").format(invalid_states))
else:
return True

def check_dssp(self, sequence):
count_match_states = sum(
Expand All @@ -122,13 +128,16 @@ def check_dssp(self, sequence):
raise A3MFormatError(
("Undefined character(s) '{}' in "
"dssp annotation!").format(invalid_states))
else:
return True

def check_sequence(self, sequence):
count_match_states = sum((c in self.VALID_MATCH_STATES
or c in self.VALID_GAP_STATES)
for c in sequence)
self.check_match_states(count_match_states)


invalid_states = set(sequence) - self.VALID_MATCH_STATES
invalid_states -= self.VALID_GAP_STATES
invalid_states -= self.VALID_INSERTION_STATES
Expand All @@ -137,6 +146,8 @@ def check_sequence(self, sequence):
raise A3MFormatError(
("Undefined character(s) '{}' in "
"protein sequence!").format(invalid_states))
else:
return True

def get_sub_sequence(self, sequence, limits):
sub_sequence = []
Expand Down
9 changes: 4 additions & 5 deletions scripts/check_a3m.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@

def check_a3m(filename):
a3m = A3M_Container()

if(filename.lower() == "stdin"):
fh = sys.stdin
else:
fh = open(filename, "r")

try:
a3m.read_a3m(fh)
except A3MFormatError as e:
sys.stderr.write(e)
sys.stderr.write(str(e))
exit(1)


def main():
filename = sys.argv[1]
Expand All @@ -27,4 +27,3 @@ def main():

if __name__ == "__main__":
main()

0 comments on commit f74f336

Please sign in to comment.