# Path: augur/utils.py
# def myopen(fname, mode):
#     if fname.endswith('.gz'):
#         import gzip
#         return gzip.open(fname, mode, encoding='utf-8')
#     else:
#         return open(fname, mode, encoding='utf-8')


import os
import logging
import numpy as np
import time
import pandas as pd
import sys
                import matplotlib.pyplot as plt
                import seaborn as sns
                    import ipdb; ipdb.set_trace()
                    import pdb; pdb.set_trace()
from collections import defaultdict
from pprint import pprint
from .utils import myopen
                from random import sample
        from scipy.stats import linregress, pearsonr
            from cvxopt import matrix, solvers
        from scipy.optimize import nnls
            from cvxopt import matrix, solvers
            from cvxopt import matrix, solvers
        >>> type(measurements)
        <class 'dict'>
        >>> len(measurements)
        11
        >>> measurements[("A/Acores/11/2013", ("A/Alabama/5/2010", "F27/10"))]
        [80.0]
        >>> len(strains)
        13
        >>> len(sources)
        5
        >>> measurements, strains, sources = TiterCollection.load_from_file("tests/data/titer_model/h3n2_titers_subset.tsv", excluded_sources=["NIMR_Sep2013_7-11.csv"])
        >>> len(measurements)
        5
        >>> measurements.get(("A/Acores/11/2013", ("A/Alabama/5/2010", "F27/10")))
        >>>
        >>> output = TiterCollection.load_from_file("tests/data/titer_model/missing.tsv")
        Traceback (most recent call last):
          File "<ipython-input-2-0ea96a90d45d>", line 1, in <module>
            open("tests/data/titer_model/missing.tsv", "r")
        FileNotFoundError: [Errno 2] No such file or directory: 'tests/data/titer_model/missing.tsv'
        """
        if excluded_sources is None:
            excluded_sources = []

        measurements = defaultdict(list)
        strains = set()
        sources = set()
        titer_files = [filenames] if type(filenames)==str else filenames

        for fname in titer_files:

# Path: augur/utils.py
# def myopen(fname, mode):
#     if fname.endswith('.gz'):
#         import gzip
#         return gzip.open(fname, mode, encoding='utf-8')
#     else:
#         return open(fname, mode, encoding='utf-8')


# Path: augur/titer_model.py
import os
import logging
import numpy as np
import time
import pandas as pd
import sys
                import matplotlib.pyplot as plt
                import seaborn as sns
                    import ipdb; ipdb.set_trace()
                    import pdb; pdb.set_trace()
from collections import defaultdict
from pprint import pprint
from .utils import myopen
                from random import sample
        from scipy.stats import linregress, pearsonr
            from cvxopt import matrix, solvers
        from scipy.optimize import nnls
            from cvxopt import matrix, solvers
            from cvxopt import matrix, solvers

        >>> type(measurements)
        <class 'dict'>
        >>> len(measurements)
        11
        >>> measurements[("A/Acores/11/2013", ("A/Alabama/5/2010", "F27/10"))]
        [80.0]
        >>> len(strains)
        13
        >>> len(sources)
        5
        >>> measurements, strains, sources = TiterCollection.load_from_file("tests/data/titer_model/h3n2_titers_subset.tsv", excluded_sources=["NIMR_Sep2013_7-11.csv"])
        >>> len(measurements)
        5
        >>> measurements.get(("A/Acores/11/2013", ("A/Alabama/5/2010", "F27/10")))
        >>>
        >>> output = TiterCollection.load_from_file("tests/data/titer_model/missing.tsv")
        Traceback (most recent call last):
          File "<ipython-input-2-0ea96a90d45d>", line 1, in <module>
            open("tests/data/titer_model/missing.tsv", "r")
        FileNotFoundError: [Errno 2] No such file or directory: 'tests/data/titer_model/missing.tsv'
        """
        if excluded_sources is None:
            excluded_sources = []

        measurements = defaultdict(list)
        strains = set()
        sources = set()
        titer_files = [filenames] if type(filenames)==str else filenames

        for fname in titer_files:

            with myopen(fname, 'r') as infile: