def parse_insert_metrics(fn):
    """
    Parse the output from Picard's CollectInsertSizeMetrics and return as pandas
    Series.

    Parameters
    ----------
    filename : str of filename or file handle
        Filename of the Picard output you want to parse.

    Returns
    -------
    metrics : pandas.Series
        Insert size metrics.

    hist : pandas.Series
        Insert size histogram.

    """
    with open(fn) as f:
        lines = [x.strip().split('\t') for x in f.readlines()]

    index = lines[6]
    vals = lines[7]
    for i in range(len(index) - len(vals)):
        vals.append(np.nan)
    for i, v in enumerate(vals):
        if type(v) == str:
            try:
                vals[i] = int(v)
            except ValueError:
                try: 
                    vals[i] = float(v)
                except ValueError:
                    continue
    metrics = pd.Series(vals, index=index)
    
    vals = np.array(lines[11:-1])
    hist = pd.Series(vals[:, 1], index=[int(float(x)) for x in vals[:, 0]])
    hist = pd.to_numeric(hist)
    return metrics, hist