#! /usr/bin/env python

"""
runs the manual tests without the need to build and install
"""

import os
import sys
import shutil
import logging

from collections import OrderedDict

sys.path.insert(0, "..")

from tfasta import *

if __name__ == "__main__":

  logging.basicConfig(level=logging.INFO)

  logging.info("%%%%%%%%%%%%%%%%%%%% testing %%%%%%%%%%%%%%%%%%%%")

  # if os.path.exists('output'):
  #   logging.info("Removing 'output' directory.")
  #   shutil.rmtree('output')

  # logging.info("Running _chemfigit()")
  # texgentest._texgentest.main()

  
  filename = "short-extended.fas"
  print "\n".join(open(filename).read().splitlines()[:10])
  fasta_iterator = fasta_parser(filename)
  f = fasta_iterator.next()
  print f['name']
  print f['sequence'][:60]
  f = fasta_iterator.next()
  print f['name']

  print

  fast = fasta_parser("cytb.fas",
                      template=T_NR)
  f = fast.next()
  print f['gi']
  print f['accession']
  print f['description']
  print f['source']
  print f['sequence'][:60]


  print
  name = "OVAX_CHICK GENE X PROTEIN N-Term"
  seq = """
        QIKDLLVSSSTDLDTTLVLVNAIYFKGMWK
        afnaedtrempfhvtkqeskpvqmmcmnnsfnvatlpae
        KMKILELPFASGDLSMLV
        """
  print make_fasta(name, seq, width=50)


  print
  od = OrderedDict({ "First 10":  " 1 QIKDLLVSSS",
                     "Second 10": "11 tdldttlvlv" })
  print make_fasta_from_dict(od)


  print

  regex = r'^>gi\|([^|]*)\|[^|]*\|([^|]*)\|.*$'
  fields = ("gi", "accession")
  t_nrblast = FastaTemplate(regex, fields)
  fast = fasta_parser("short-extended.fas", template=t_nrblast)
  f = fast.next()
  print f['accession']
  print f['sequence'][:60]

  print
  astr = """
          > Abeta in a string
          DAEFRHDSGYEVHHQKLVFFAEDVGSNKGAIIGLMVGGVVIA
          """
  fast = string_fasta_parser(astr)
  f = fast.next()
  print f['name']
  print f['sequence']

  print
  for f in fasta_parser("short-extended.fas"):
    print f['name']
