#!/usr/bin/env python
from __future__ import print_function
#import sys

from flupan import passage_interpreter
import argparse


def parse_file(infile):
    with open(infile, "r") as passageIDs:
            for ID in passageIDs.readlines():
                 annotation = pp.parse_passage(ID) 
                 return annotation
def parse_passage(passage):
    
    p = pp.parse_passage(passage) 
    return p.summary

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='A tool to parse influenza passaging annotations')
    parser.add_argument('-f', '--infile', action='store', help = 'A files of passage IDs, ex M1 S4, one per line', required=False)
    parser.add_argument('-p', '--passage',  action='store', help = 'A single passage ID to be parsed, ex. E4', required=False)
    parser.add_argument('-o', '--outfile', action='store', help = 'An outfile to store output', required=False, default='interpreted_passage.txt')

    args = parser.parse_args()
    pp = passage_interpreter.PassageParser()

    if not args.infile and not args.passage:
        sys.exit("No arguments, either provide a file (-f) or single passage identifier (-p)")
        s
    if args.infile and args.passage:
        sys.exit("please provide either a text file of passages or a single passage ID, but not both")
       
 

    if args.infile:
        annotation = parse_file(args.infile)

    if args.passage:
        annotation = parse_passage(args.passage)
        print(",".join(annotation))

    if args.outfile:
        with open(args.outfile, "w") as outf:
             outf.write(",".join(annotation) + "\n")








