#!/opt/gensoft/exe/hifix/1.0.6/venv/bin/python2.7

#    Copyright (C) 2011 CNRS
#    This file is part of HiFiX. 
#
#    HiFiX 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.
#
#    HiFiX 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 HiFiX.  If not, see <http://www.gnu.org/licenses/>.

import sys
import os
import argparse
from hifixlib.HighFidelityX import HighFidelityX

def main():
    parser = argparse.ArgumentParser(description='High-Fidelity Clustering of Protein Sequences')
       
    parser.add_argument('FASTAFILE', action="store", help="protein sequences to be clustered in a fasta file (extension .fasta required). Each line should be no longer than 256 characters.")
    parser.add_argument('NETFILE', action="store", help="network output from SiLiX clustering (extension .net required)")
    parser.add_argument('FNODESFILE', action="store", help="clustering from SiLiX (extension .fnodes required)")
    
    parser.add_argument('-p', action="store", dest="path_to_louvain", default="",
                        help="absolute path to Louvain binaries, if not in the PATH environment variable")
    parser.add_argument('-t', action="store", dest="nbprocs", type=int, default=1,
                        help="number of cores (must be <= number of physical cores)") 
    parser.add_argument('-d', action="store", dest="path_to_tmp", default=None,
                        help="specific directory (absolute path) where to build temporary files (default temporary directory otherwise)")
    parser.add_argument('-n', action="store", dest="min", type=int, default=100,
                        help="minimum size of pre-families to be analyzed (default=100)")   
    parser.add_argument('-i', action="store", dest="I", type=int, default=2,
                        help="number of most connected pairs in the merging step (time consuming, default=2)")  
    parser.add_argument('--force', action="store_true", dest="force", 
                        help="force selection of small families with perfect specificity (not recommended)")   
    parser.add_argument('--version', action='version', version='%(prog)s 1.0.6')  
    options = parser.parse_args()
    fastafile = options.FASTAFILE
    if not fastafile[-6:] == ".fasta":
        print >> sys.stderr,  "[error] Wrong file extension in ",fastafile," (required extension is \".fasta\")"
        sys.exit(1)
    netfile = options.NETFILE
    if not netfile[-4:] == ".net":
        print >> sys.stderr,  "[error] Wrong file extension in ",netfile," (required extension is \".net\")"
        sys.exit(1)
    fnodesfile = options.FNODESFILE
    min = int(options.min)
    HighFidelityX(min, options.path_to_louvain).runmulticore(options.nbprocs, 
                                                             fastafile, netfile, fnodesfile, 
                                                             options.path_to_tmp, 
                                                             options.I,
                                                             options.force)    
   
if __name__ == '__main__':
    main()
