import re


def get_motif_stats(motifs):
	"""Get the GC content and the length for a list of motifs

	Parameter:
	----------
	motifs : list
		A list of gimmemotifs motif objects.
	
	Return:
	-------
	motif_stats : dict
		A dictionary containing the motif name as key and
		a list with GC content and motif length as value.
	"""

	motif_stats = dict()
	for m in motifs:
		# Remove first row
		m_woh = re.sub('^>.*\n','',m.to_pwm())
		m_pwm = m_woh.split()
		motif_length = len(m)
		gc_sum = 0
		# Get sum of G and C ratios
		for x in range(0, len(m_pwm)-1, 4):
			gc_sum += float(m_pwm[x+1]) + float(m_pwm[x+2])

		# Calc GC ratio of the motif
		gc_content = gc_sum/motif_length
		motif_name = m.id.replace('\t', ' ')
		motif_stats[motif_name] = [round(gc_content,4), motif_length]

	return motif_stats