Convert citation object to a string, using standard citation formatting.  

    args:
        citation:   a dictionary potentially containing all fields from
            pypif.obj.Reference, and possibly a few others

    TODO: This is tedious and fragile.  Find a better way to get 'er done.
    TODO: This function assumes that citations are either to books or journals.
        urls are ignored.

    references: 
        http://citrineinformatics.github.io/pif-documentation/schema_definition/common/Reference.html
        http://www.scientificstyleandformat.org/Tools/SSF-Citation-Quick-Guide.html

def _citation_to_string(citation):
    """
    Convert citation object to a string, using standard citation formatting.  

    args:
        citation:   a dictionary potentially containing all fields from
            pypif.obj.Reference, and possibly a few others

    TODO: This is tedious and fragile.  Find a better way to get 'er done.
    TODO: This function assumes that citations are either to books or journals.
        urls are ignored.

    references: 
        http://citrineinformatics.github.io/pif-documentation/schema_definition/common/Reference.html
        http://www.scientificstyleandformat.org/Tools/SSF-Citation-Quick-Guide.html
    """
    output = ''
    sep = '. '

    if 'authors' in citation:
        authors = []
        for author in citation['authors']:
            if 'family_name' not in author:
                continue
            author_name = author['family_name']
            if 'given_name' in author:
                author_name += ' ' + author['given_name']
            authors.append(author_name)
        output += ', '.join(authors) + sep
    if 'year' in citation:
        output += str(citation['year']) + sep
    if 'title' in citation:
        output += citation['title'] + sep

    if 'journal' in citation:
        output += citation['journal'] + sep
        if 'volume' in citation:
            output += citation['volume']
            if 'issue' in citation:
                output += '(' + citation['issue'] + ')'
            if 'page_location' in citation:
                output += ':' + citation['page_location'] + sep
    else:   # assume for now that the reference is to a book
            # TODO(Handle url case.)
        if 'edition' in citation:
            output += citation['edition'] + sep
        if 'publication_location' in citation:
            output += citation['publication_location']
            if 'publisher' in citation:
                output += ': ' + citation['publisher'] + sep
        elif 'publisher' in citation:
            output += citation['publisher'] + sep
        if 'extent' in citation:
            output += citation['extent'] + sep
        if 'notes' in citation:
            output += citation['notes'] + sep

    return output.strip()