#!/usr/bin/python

# miscellaneous helper functions for GLINT analysis

import sys
from Bio import SeqIO

def get_genome_length(fastafile):
  # given a fasta file, return the length of the first sequence in it
  genome=SeqIO.read(open(fastafile), "fasta")
  return len(genome.seq)

def write_grfile(indices, data, filename, header=None):
  """
  Write a gr file given the list of sequence positions and corresponding scalars
  """

  ostr = open(filename, 'w')
  if header is not None:
    ostr.write(header)
  for ind, dat in zip(indices, data):
    ostr.write("%i %f\n" % (ind, dat))
  ostr.close()
