Skip to content

Commit

Permalink
Produce consensus sequence not just table (resolve #3)
Browse files Browse the repository at this point in the history
  • Loading branch information
arendsee committed Sep 18, 2018
1 parent 53dd141 commit 620d227
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions smof.py
Original file line number Diff line number Diff line change
Expand Up @@ -2146,9 +2146,15 @@ def _parse(self):
help="finds the consensus sequence for aligned sequence",
description="""Given input in aligned FASTA file format, where all
sequences are of equal length (possibly with gaps), `consensus`
will find the most common character in each column. Optionall, it
will instead provide the counts or proportions of each character at
each position."""
will find the most common character in each column. Ties are
resolved alphabetically. Optionally, it will instead provide the
counts or proportions of each character at each position."""
)
parser.add_argument(
"-t", "--table",
help="Print count table instead of consensus",
action="store_true",
default=False
)
parser.add_argument(
'fh',
Expand All @@ -2172,12 +2178,18 @@ def write(self, args, gen, out=sys.stdout):
counts = Counter(('').join([s.seq for s in seqs]))
characters = list(counts.keys())

out.write("\t".join(characters))
out.write("\n")
for column in transpose:
c = Counter(column)
out.write("\t".join([str(c[x]) for x in characters]))
if args.table:
out.write("\t".join(characters))
out.write("\n")
for column in transpose:
c = Counter(column)
out.write("\t".join([str(c[x]) for x in characters]))
out.write("\n")

else:
consensus = [Counter(c).most_common()[0][0] for c in transpose]
header = "Consensus"
FSeq(header, ''.join(consensus)).print()


# ==============
Expand Down

0 comments on commit 620d227

Please sign in to comment.