#!/usr/bin/python3

# orthologer - Pipeline for deducing orthology from fasta files.
# Copyright (C) 2005-2023 E. Zdobnov lab: F. Tegenfeldt
# <fredrik.tegenfeldt@unige.ch> based on code by E. Kriventseva
#
# This file is part of orthologer.
#
# orthologer is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# orthologer is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with orthologer.  If not, see <http://www.gnu.org/licenses/>.
'''
Plot evolutionary rate.
Pipeline usage: -
'''
from __future__ import print_function

import argparse
import numpy as np
import matplotlib.pyplot as plt


def read_data( filename,column ):
    fh = open(filename)

    val = []

    for line in fh.readlines():
        line = line.strip().rstrip('\n')
        if len(line)>0 and line[0] not in '#':
            elems = line.split()
            v = float(elems[column])
            val.append(v)
               
    return np.array(val)




parser = argparse.ArgumentParser(description='Simple plot tool')

parser.add_argument('-f', '--file', action='append', dest='filename',
                  help='read data from FILE', metavar='FILE', required=True, default=[])
parser.add_argument("-c", "--column", dest="column", type=int, default=1,
                    help="use data in COLUMN", metavar="COLUMN")
parser.add_argument("-b", "--bins", dest="bins", type=int, default=100,
                    help="number of bins")

options = parser.parse_args()

##########################################################################

fig=plt.figure(1)
first=True
i=0
data=[]
means=[]
for f in options.filename:
    val=read_data(f,options.column)
    data.append(val)
    means.append(np.mean(val))
    i=i+1
    first=False

plt.boxplot(data) #,usermedians=means)
#plt.xlabel()
#plt.ylabel()
plt.grid()
#plt.legend()

plt.show()
