#!/usr/bin/env python 

################################################################################
### COPYRIGHT ##################################################################

# New York Genome Center

# SOFTWARE COPYRIGHT NOTICE AGREEMENT
# This software and its documentation are copyright (2014) by the New York
# Genome Center. All rights are reserved. This software is supplied without
# any warranty or guaranteed support whatsoever. The New York Genome Center
# cannot be responsible for its use, misuse, or functionality.

# Version: 0.2
# Author: Andre Corvelo

################################################################# /COPYRIGHT ###
################################################################################



################################################################################
### MODULES ####################################################################

from optparse import OptionParser
import sys

################################################################### /MODULES ###
################################################################################



################################################################################
### FUNCTIONS ##################################################################

################################################################# /FUNCTIONS ###
################################################################################



################################################################################
### ARGUMENTS,OPTIONS ##########################################################

parser = OptionParser(usage="\n%prog [options]", version="%prog v0.2")

parser.add_option(
	"-i",
	metavar = "FILE",
	type = "string",
	dest = "input_file",
	default = 'stdin',
	help = "Input fasta filename (default = 'stdin')"
	)

(opt, args) = parser.parse_args()
        
######################################################### /ARGUMENTS,OPTIONS ###
################################################################################



################################################################################
### CONSTANTS ##################################################################

################################################################# /CONSTANTS ###
################################################################################



################################################################################
### MAIN #######################################################################

if __name__ == "__main__":
	sid = None
	length = None
	
	if opt.input_file != 'stdin':
		ff = open(opt.input_file, 'r')
	else:
		ff = sys.stdin
	for line in ff:
		l = line.rstrip()
		if l != '':
			if l[0] == '>':
				if sid != None:
					sys.stdout.write(sid + '\t' + str(length) + '\n')
				sid = l[1:]
				length = 0
			else:
				length += len(l)
		else:
			continue
	sys.stdout.write(sid + '\t' + str(length) + '\n')	
	if opt.input_file != 'stdin':
		ff.close()
	
###################################################################### /MAIN ###
################################################################################
