#!/usr/bin/env python
import immunedb.common.config as config
from immunedb.trees.clearcut import run_clearcut

if __name__ == '__main__':
    parser = config.get_base_arg_parser('Generates JSON trees for clones')
    parser.add_argument('--force', action='store_true', default=False,
                        help='''Force updating of trees''')
    parser.add_argument('--clone-ids', nargs='+', type=int,
                        help='''ID of clone from which to make a tree''')
    parser.add_argument('--subject-ids', nargs='+', type=int,
                        help='''ID of subject for which trees should be
                        made''')
    parser.add_argument('--temp', default='/tmp', help='Path for temporary'
                        'files')
    parser.add_argument('--min-mut-copies', default=0, type=int,
                        help='''The minimum number of copies which must contain
                        a mutation for it to be incorporated into tree
                        calculation.''')
    parser.add_argument('--min-mut-samples', default=0, type=int,
                        help='''The minimum number of samples in which a
                        mutation must occur to be incorporated into tree
                        calculation.''')
    parser.add_argument('--min-seq-copies', default=0, type=int,
                        help='''The minimum copy number a sequence must
                        have to be incorporated into tree calculation.''')
    parser.add_argument('--min-seq-samples', default=0, type=int,
                        help='''The minimum number of samples in which a
                        sequence must occur to be incorporated into tree
                        calculation.''')
    parser.add_argument('--exclude-stops', action='store_true',
                        help='''If specified, excludes sequences with a stop
                        codon from being included in trees.''')
    parser.add_argument('--full-seq', action='store_true',
                        help='''If specified, trees will be generated for full
                        sequences rather than just the V-region''')
    args = parser.parse_args()

    if args.subject_ids is not None and args.clone_ids is not None:
        parser.error('May only specify subject or clone IDs')

    session = config.init_db(args.db_config)
    run_clearcut(session, args)
