Skip to content

Instantly share code, notes, and snippets.

@Swarchal
Created October 7, 2016 12:49
Show Gist options
  • Save Swarchal/9da1aeaa4b5a4e91feaae238f14c445e to your computer and use it in GitHub Desktop.
Save Swarchal/9da1aeaa4b5a4e91feaae238f14c445e to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
from sys import argv
from math import factorial
def parse_fasta(in_file):
""" return sequence from single fasta """
seqs = [line for line in open(in_file) if not line.startswith(">")]
return "".join(seqs).replace("\n", "")
def pmch(seq):
""" return number of perfect matchings of basepair edges in sequence """
return factorial(seq.count("A")) * factorial(seq.count("C"))
def main(fasta_path):
sequence = parse_fasta(fasta_path)
return pmch(sequence)
if __name__ == "__main__":
print(main(argv[1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment