Instruction:
Create a Python 3 function to
append a minidom XML element to a parent ElementTree.

Response:
def append_minidom_xml_to_elementtree_xml(parent, xml, recursive=False, attributes=None):
    """
    Recursively,
    Given an ElementTree.Element as parent, and a minidom instance as xml,
    append the tags and content from xml to parent
    Used primarily for adding a snippet of XML with <italic> tags
    attributes: a list of attribute names to copy
    """

    # Get the root tag name
    if recursive is False:
        tag_name = xml.documentElement.tagName
        node = xml.getElementsByTagName(tag_name)[0]
        new_elem = SubElement(parent, tag_name)
        if attributes:
            for attribute in attributes:
                if xml.documentElement.getAttribute(attribute):
                    new_elem.set(attribute, xml.documentElement.getAttribute(attribute))
    else:
        node = xml
        tag_name = node.tagName
        new_elem = parent

    i = 0
    for child_node in node.childNodes:
        if child_node.nodeName == '#text':
            if not new_elem.text and i <= 0:
                new_elem.text = child_node.nodeValue
            elif not new_elem.text and i > 0:
                new_elem_sub.tail = child_node.nodeValue
            else:
                new_elem_sub.tail = child_node.nodeValue

        elif child_node.childNodes is not None:
            new_elem_sub = SubElement(new_elem, child_node.tagName)
            new_elem_sub = append_minidom_xml_to_elementtree_xml(new_elem_sub, child_node,
                                                                 True, attributes)

        i = i + 1

    # Debug
    #encoding = 'utf-8'
    #rough_string = ElementTree.tostring(parent, encoding)
    #print rough_string

    return parent


Instruction:
Write a Python 3 script to
rewrite the JSON content to make it valid according to the rewrite_type.

Response:
def rewrite_json(rewrite_type, soup, json_content):
    """
    Due to XML content that will not conform with the strict JSON schema validation rules,
    for elife articles only, rewrite the JSON to make it valid
    """
    if not soup:
        return json_content
    if not elifetools.rawJATS.doi(soup) or not elifetools.rawJATS.journal_id(soup):
        return json_content

    # Hook only onto elife articles for rewriting currently
    journal_id_tag = elifetools.rawJATS.journal_id(soup)
    doi_tag = elifetools.rawJATS.doi(soup)
    journal_id = elifetools.utils.node_text(journal_id_tag)
    doi = elifetools.utils.doi_uri_to_doi(elifetools.utils.node_text(doi_tag))
    if journal_id.lower() == "elife":
        function_name = rewrite_function_name(journal_id, rewrite_type)
        if function_name:
            try:
                json_content = globals()[function_name](json_content, doi)
            except KeyError:
                pass
    return json_content


Instruction:
How would you explain what the following Python 3 function does
def rewrite_references_json(json_content, rewrite_json):
    for ref in json_content:
        if ref.get("id") and ref.get("id") in rewrite_json:
            for key, value in iteritems(rewrite_json.get(ref.get("id"))):
                ref[key] = value
    return json_content

Response: general purpose references json rewriting by matching the id value


Instruction:
How would you explain what the following Python 3 function does
def elife_references_rewrite_json():
    references_rewrite_json = {}

    references_rewrite_json["10.7554/eLife.00051"] = {"bib25": {"date": "2012"}}
    references_rewrite_json["10.7554/eLife.00278"] = {"bib11": {"date": "2013"}}
    references_rewrite_json["10.7554/eLife.00444"] = {"bib2": {"date": "2013"}}
    references_rewrite_json["10.7554/eLife.00569"] = {"bib74": {"date": "1996"}}
    references_rewrite_json["10.7554/eLife.00592"] = {"bib8": {"date": "2013"}}
    references_rewrite_json["10.7554/eLife.00633"] = {"bib38": {"date": "2004"}}
    references_rewrite_json["10.7554/eLife.00646"] = {"bib1": {"date": "2012"}}
    references_rewrite_json["10.7554/eLife.00813"] = {"bib33": {"date": "2007"}}
    references_rewrite_json["10.7554/eLife.01355"] = {"bib9": {"date": "2014"}}
    references_rewrite_json["10.7554/eLife.01530"] = {"bib12": {"date": "2014"}}
    references_rewrite_json["10.7554/eLife.01681"] = {"bib5": {"date": "2000"}}
    references_rewrite_json["10.7554/eLife.01917"] = {"bib35": {"date": "2014"}}
    references_rewrite_json["10.7554/eLife.02030"] = {"bib53": {"date": "2013"}, "bib56": {"date": "2013"}}
    references_rewrite_json["10.7554/eLife.02076"] = {"bib93a": {"date": "1990"}}
    references_rewrite_json["10.7554/eLife.02217"] = {"bib27": {"date": "2009"}}
    references_rewrite_json["10.7554/eLife.02535"] = {"bib12": {"date": "2014"}}
    references_rewrite_json["10.7554/eLife.02862"] = {"bib8": {"date": "2010"}}
    references_rewrite_json["10.7554/eLife.03711"] = {"bib35": {"date": "2012"}}
    references_rewrite_json["10.7554/eLife.03819"] = {"bib37": {"date": "2008"}}
    references_rewrite_json["10.7554/eLife.04069"] = {"bib8": {"date": "2011"}}
    references_rewrite_json["10.7554/eLife.04247"] = {"bib19a": {"date": "2015"}}
    references_rewrite_json["10.7554/eLife.04333"] = {
        "bib3": {"date": "1859"},
        "bib37": {"date": "1959"}}
    references_rewrite_json["10.7554/eLife.04478"] = {"bib49": {"date": "2014"}}
    references_rewrite_json["10.7554/eLife.04580"] = {"bib139": {"date": "2014"}}
    references_rewrite_json["10.7554/eLife.05042"] = {"bib78": {"date": "2015"}}
    references_rewrite_json["10.7554/eLife.05323"] = {"bib102": {"date": "2014"}}
    references_rewrite_json["10.7554/eLife.05423"] = {"bib102": {"date": "2014"}}
    references_rewrite_json["10.7554/eLife.05503"] = {"bib94": {"date": "2016"}}
    references_rewrite_json["10.7554/eLife.05849"] = {"bib82": {"date": "2005"}}
    references_rewrite_json["10.7554/eLife.06072"] = {"bib17": {"date": "2003"}}
    references_rewrite_json["10.7554/eLife.06315"] = {"bib19": {"date": "2014"}}
    references_rewrite_json["10.7554/eLife.06426"] = {"bib39": {"date": "2015"}}
    references_rewrite_json["10.7554/eLife.07361"] = {"bib76": {"date": "2011"}}
    references_rewrite_json["10.7554/eLife.07460"] = {
        "bib1": {"date": "2013"},
        "bib2": {"date": "2014"}}
    references_rewrite_json["10.7554/eLife.08500"] = {"bib55": {"date": "2015"}}
    references_rewrite_json["10.7554/eLife.09066"] = {"bib46": {"date": "2015"}}
    references_rewrite_json["10.7554/eLife.09100"] = {"bib50": {"date": "2011"}}
    references_rewrite_json["10.7554/eLife.09148"] = {
        "bib47": {"articleTitle": "97–104"},
        "bib59": {"articleTitle": "1913–1918"}}
    references_rewrite_json["10.7554/eLife.09186"] = {
        "bib31": {"date": "2015"},
        "bib54": {"date": "2014"},
        "bib56": {"date": "2014"},
        "bib65": {"date": "2015"}}
    references_rewrite_json["10.7554/eLife.09215"] = {"bib5": {"date": "2012"}}

    references_rewrite_json["10.7554/eLife.09520"] = {
        "bib35": OrderedDict([
            ("conference", OrderedDict([
                ("name", ["WHO Expert Committee on Malaria"])
            ])),
            ("articleTitle", "WHO Expert Committee on Malaria [meeting held in Geneva from 19 to 30 October 1970]: fifteenth report"),
            ("publisher", OrderedDict([
                ("name", ["World Health Organization"]),
                ("address", OrderedDict([
                    ("formatted", ["Geneva"]),
                    ("components", OrderedDict([
                        ("locality", ["Geneva"])
                    ])),
                ])),
            ])),
        ])
    }

    references_rewrite_json["10.7554/eLife.09579"] = {
        "bib19": {"date": "2007"},
        "bib49": {"date": "2002"}}
    references_rewrite_json["10.7554/eLife.09600"] = {"bib13": {"date": "2009"}}
    references_rewrite_json["10.7554/eLife.09672"] = {
        "bib25": {"conference": {"name": ["Seventeenth Meeting of the RBM Partnership Monitoring and Evaluation Reference Group (MERG)"]}}}
    references_rewrite_json["10.7554/eLife.09771"] = {"bib22": {"date": "2012"}}
    references_rewrite_json["10.7554/eLife.09972"] = {"bib61": {"date": "2007", "discriminator": "a"}}
    references_rewrite_json["10.7554/eLife.09977"] = {"bib41": {"date": "2014"}}
    references_rewrite_json["10.7554/eLife.10032"] = {"bib45": {"date": "2016"}}
    references_rewrite_json["10.7554/eLife.10042"] = {"bib14": {"date": "2015"}}
    references_rewrite_json["10.7554/eLife.10070"] = {"bib15": {"date": "2015"}, "bib38": {"date": "2014"}}
    references_rewrite_json["10.7554/eLife.10222"] = {"bib30": {"date": "2015"}}
    references_rewrite_json["10.7554/eLife.10670"] = {"bib7": {"date": "2015"}, "bib8": {"date": "2015"}}
    references_rewrite_json["10.7554/eLife.10781"] = {"bib32": {"date": "2003"}}
    references_rewrite_json["10.7554/eLife.11273"] = {"bib43": {"date": "2004"}}
    references_rewrite_json["10.7554/eLife.11305"] = {"bib68": {"date": "2000"}}
    references_rewrite_json["10.7554/eLife.11416"] = {"bib22": {"date": "1997"}}
    references_rewrite_json["10.7554/eLife.11860"] = {"bib48": {"title": "Light-switchable gene expression system"}}
    references_rewrite_json["10.7554/eLife.12401"] = {"bib25": {"date": "2011"}}
    references_rewrite_json["10.7554/eLife.12366"] = {"bib10": {"date": "2008"}}
    references_rewrite_json["10.7554/eLife.12703"] = {"bib27": {"date": "2013"}}
    references_rewrite_json["10.7554/eLife.12735"] = {"bib35": {"date": "2014"}}
    references_rewrite_json["10.7554/eLife.12830"] = {"bib118": {"date": "1982"}}
    references_rewrite_json["10.7554/eLife.13133"] = {"bib11": {"date": "2011"}}
    references_rewrite_json["10.7554/eLife.13152"] = {"bib25": {"date": "2000"}}
    references_rewrite_json["10.7554/eLife.13195"] = {"bib6": {"date": "2013"}, "bib12": {"date": "2003"}}
    references_rewrite_json["10.7554/eLife.13479"] = {"bib5": {"date": "2016"}}
    references_rewrite_json["10.7554/eLife.13463"] = {"bib15": {"date": "2016"}}
    references_rewrite_json["10.7554/eLife.14119"] = {"bib40": {"date": "2007"}}
    references_rewrite_json["10.7554/eLife.14169"] = {"bib6": {"date": "2015"}}
    references_rewrite_json["10.7554/eLife.14523"] = {"bib7": {"date": "2013"}}
    references_rewrite_json["10.7554/eLife.15272"] = {"bib78": {"date": "2014"}}
    references_rewrite_json["10.7554/eLife.15504"] = {"bib67": {"isbn": "9780198524304"}}
    references_rewrite_json["10.7554/eLife.16105"] = {"bib2": {"date": "2013"}}
    references_rewrite_json["10.7554/eLife.16349"] = {"bib68": {"date": "2005"}}
    references_rewrite_json["10.7554/eLife.16394"] = {
        "bib6": {"type": "thesis",
        "author": {"type": "person", "name": {"preferred": "B Berret","index": "Berret, B" }},
        "publisher": {"name": ["Université de Bourgogne"]}}}
    references_rewrite_json["10.7554/eLife.16443"] = {"bib58": {"date": "1987"}}
    references_rewrite_json["10.7554/eLife.16764"] = {"bib4": {"date": "2013"}}
    references_rewrite_json["10.7554/eLife.17092"] = {"bib102": {"date": "1980"}}
    references_rewrite_json["10.7554/eLife.18044"] = {"bib25": {"date": "2005"}}
    references_rewrite_json["10.7554/eLife.18370"] = {"bib1": {"date": "2006"}}
    references_rewrite_json["10.7554/eLife.18425"] = {"bib54": {"date": "2014"}}
    references_rewrite_json["10.7554/eLife.18683"] = {"bib47": {"date": "2015"}}
    references_rewrite_json["10.7554/eLife.19532"] = {"bib27": {"date": "2015"}}
    references_rewrite_json["10.7554/eLife.19545"] = {"bib51": {"date": "1996"}}
    references_rewrite_json["10.7554/eLife.19571"] = {"bib56": {"date": "2016"}}
    references_rewrite_json["10.7554/eLife.20352"] = {"bib53": {"country": "United States"}}
    references_rewrite_json["10.7554/eLife.21864"] = {"bib2": {"date": "2016-10-24"}}
    references_rewrite_json["10.7554/eLife.20522"] = {
        "bib42": {"date": "2016"},
        "bib110": {"date": "1996"}}
    references_rewrite_json["10.7554/eLife.22053"] = {"bib123": {"date": "2016"}}

    # Reference authors data to replace, processed further below into json
    references_authors = []
    references_authors.append(("10.7554/eLife.00036", "bib8", "authors", [
        {"surname": "Butler", "given-names": "H"},
        {"surname": "Juurlink", "given-names": "BHJ"}
        ]))
    references_authors.append(("10.7554/eLife.00036", "bib30", "authors", [
        {"surname": "Joyner", "given-names": "AL"}
        ]))

    references_authors.append(("10.7554/eLife.00048", "bib15", "authors", [
        {"surname": "Guthrie", "given-names": "C"},
        {"surname": "Fink", "given-names": "GR"}
        ]))

    references_authors.append(("10.7554/eLife.00051", "bib21", "authors", [
        {"surname": "Jamison", "given-names": "DT"},
        {"surname": "Breman", "given-names": "JG"},
        {"surname": "Measham", "given-names": "AR"},
        {"surname": "Alleyne", "given-names": "G"},
        {"surname": "Claeson", "given-names": "M"},
        {"surname": "Evans", "given-names": "DB"},
        {"surname": "Jha", "given-names": "P"},
        {"surname": "Mills", "given-names": "A"},
        {"surname": "Musgrove", "given-names": "P"}
        ]))
    references_authors.append(("10.7554/eLife.00051", "bib36", "authors", [
        {"surname": "Rogers", "given-names": "RG"},
        {"surname": "Crimmins", "given-names": "EM"}
        ]))

    references_authors.append(("10.7554/eLife.00668", "bib39", "authors", [
        {"surname": "Rice", "given-names": "SA"}
        ]))

    references_authors.append(("10.7554/eLife.01730", "bib75", "authors", [
        {"collab": "Look AHEAD Research Group"}
        ]))

    references_authors.append(("10.7554/eLife.03714", "bib64", "authors", [
        {"surname": "Otwinowski", "given-names": "Z"},
        {"surname": "Minor", "given-names": "W"}
        ]))

    references_authors.append(("10.7554/eLife.04220", "bib31", "authors", [
        {"surname": "Tishby", "given-names": "N"},
        {"surname": "Polani", "given-names": "D"}
        ]))

    references_authors.append(("10.7554/eLife.04395", "bib67", "authors", [
        {"surname": "King", "given-names": "AMQ"},
        {"surname": "Adams", "given-names": "MJ"},
        {"surname": "Carstens", "given-names": "EB"},
        {"surname": "Lefkowitz", "given-names": "E"}
        ]))

    references_authors.append(("10.7554/eLife.04449", "bib62", "authors", [
        {"surname": "Shaham", "given-names": "S"}
        ]))

    references_authors.append(("10.7554/eLife.04659", "bib57", "authors", [
        {"surname": "Sambrook", "given-names": "J"},
        {"surname": "Russell", "given-names": "TW"}
        ]))

    references_authors.append(("10.7554/eLife.05423", "bib4", "authors", [
        {"surname": "Birkhead", "given-names": "TR"},
        {"surname": "Møller", "given-names": "AP"}
        ]))
    references_authors.append(("10.7554/eLife.05423", "bib5", "authors", [
        {"surname": "Birkhead", "given-names": "TR"},
        {"surname": "Møller", "given-names": "AP"}
        ]))
    references_authors.append(("10.7554/eLife.05423", "bib90", "authors", [
        {"surname": "Smith", "given-names": "RL"}
        ]))

    references_authors.append(("10.7554/eLife.05564", "bib39", "authors", [
        {"surname": "Pattyn", "given-names": "S"}
        ]))

    references_authors.append(("10.7554/eLife.05959", "bib76", "authors", [
        {"surname": "Macholán", "given-names": "M"},
        {"surname": "Baird", "given-names": "SJE"},
        {"surname": "Munclinger", "given-names": "P"},
        {"surname": "Piálek", "given-names": "J"}
        ]))

    references_authors.append(("10.7554/eLife.06565", "bib1", "authors", [
        {"surname": "Ahringer", "given-names": "J"}
        ]))

    references_authors.append(("10.7554/eLife.06576", "bib57", "authors", [
        {"surname": "Moller", "given-names": "AR"}
        ]))

    references_authors.append(("10.7554/eLife.06813", "bib54", "authors", [
        {"surname": "King", "given-names": "JA"}
        ]))

    references_authors.append(("10.7554/eLife.06813", "bib55", "authors", [
        {"surname": "Kirkland", "given-names": "Gl"},
        {"surname": "Layne", "given-names": "JN"}
        ]))

    references_authors.append(("10.7554/eLife.07460", "bib1", "authors", [
        {"surname": "Rallapalli", "given-names": "Ghanasyam"}
        ]))
    references_authors.append(("10.7554/eLife.07460", "bib2", "authors", [
        {"surname": "Bazyl", "given-names": "Steven"}
        ]))

    references_authors.append(("10.7554/eLife.07847", "bib40", "authors", [
        {"collab": "Nature Immunology"}
        ]))

    references_authors.append(("10.7554/eLife.09666", "bib9", "authors", [
        {"surname": "Schüler", "given-names": "D"}
        ]))

    references_authors.append(("10.7554/eLife.09868", "bib5", "authors", [
        {"surname": "Barlow", "given-names": "HB"}
        ]))

    references_authors.append(("10.7554/eLife.10222", "bib30", "authors", [
        {"collab": "PharmaMar"}
        ]))

    references_authors.append(("10.7554/eLife.11860", "bib48", "authors", [
        {"surname": "Yang", "given-names": "Y"},
        {"surname": "Wang", "given-names": "X"},
        {"surname": "Chen", "given-names": "X"},
        ]))

    references_authors.append(("10.7554/eLife.11945", "bib23", "authors", [
        {"surname": "Glimcher", "given-names": "P"},
        {"surname": "Fehr", "given-names": "E"}
        ]))

    references_authors.append(("10.7554/eLife.13135", "bib26", "authors", [
        {"surname": "Ivanova", "given-names": "S"},
        {"surname": "Herbreteau", "given-names": "B"},
        {"surname": "Blasdell", "given-names": "K"},
        {"surname": "Chaval", "given-names": "Y"},
        {"surname": "Buchy", "given-names": "P"},
        {"surname": "Guillard", "given-names": "B"},
        {"surname": "Morand", "given-names": "S"},
        ]))

    references_authors.append(("10.7554/eLife.13135", "bib27", "authors", [
        {"surname": "King", "given-names": "AMQ"},
        {"surname": "Adams", "given-names": "J"},
        {"surname": "Carstens", "given-names": "EB"},
        {"surname": "Lefkowitz", "given-names": "EJ"}
        ]))

    references_authors.append(("10.7554/eLife.14188", "bib1", "authors", [
        {"collab": "Avisoft Bioacoustics"}
        ]))

    references_authors.append(("10.7554/eLife.17716", "bib7", "authors", [
        {"collab": "World Health Organization"}
        ]))

    references_authors.append(("10.7554/eLife.17956", "bib4", "authors", [
        {"surname": "Barrett", "given-names": "SCH"}
        ]))

    references_authors.append(("10.7554/eLife.18109", "bib39", "authors", [
        {"surname": "Weber", "given-names": "EH"}
        ]))

    # Now turn the authors data into the json
    for author_row in references_authors:
        ref_json = OrderedDict()
        doi, id, author_type, authors = author_row
        #if id not in ref_json:
        ref_json[id] = OrderedDict()
        ref_json[id][author_type] = []
        for ref_author in authors:
            if  "collab" in ref_author:
                author_json = elifetools.utils_html.references_author_collab(ref_author)
            else:
                author_json = elifetools.utils.references_author_person(ref_author)
            if author_json:
                ref_json[id][author_type].append(author_json)
        # Add to json array, and do not verwrite existing rule of a specific bib id (if present)
        if doi not in references_rewrite_json:
            references_rewrite_json[doi] = ref_json
        else:
            for key, value in iteritems(ref_json):
                if key not in references_rewrite_json[doi]:
                    references_rewrite_json[doi][key] = value
                else:
                    # Append dict items
                    for k, v in iteritems(value):
                        references_rewrite_json[doi][key][k] = v

    return references_rewrite_json

Response: This function returns the DOI and references json replacements data for the Ife References Rewriting.


Instruction:
Write a Python 3 function that can
rewrite elife body json

Response:
def rewrite_elife_body_json(json_content, doi):
    """ rewrite elife body json """

    # Edge case add an id to a section
    if doi == "10.7554/eLife.00013":
        if (json_content and len(json_content) > 0):
            if (json_content[0].get("type") and json_content[0].get("type") == "section"
                and json_content[0].get("title") and json_content[0].get("title") =="Introduction"
                and not json_content[0].get("id")):
                json_content[0]["id"] = "s1"

    # Edge case remove an extra section
    if doi == "10.7554/eLife.04232":
        if (json_content and len(json_content) > 0):
            for outer_block in json_content:
                if outer_block.get("id") and outer_block.get("id") == "s4":
                    for mid_block in outer_block.get("content"):
                        if mid_block.get("id") and mid_block.get("id") == "s4-6":
                            for inner_block in mid_block.get("content"):
                                if inner_block.get("content") and not inner_block.get("title"):
                                    mid_block["content"] = inner_block.get("content")

    # Edge case remove unwanted sections
    if doi == "10.7554/eLife.04871":
        if (json_content and len(json_content) > 0):
            for i, outer_block in enumerate(json_content):
                if (outer_block.get("id") and outer_block.get("id") in ["s7", "s8"]
                    and not outer_block.get("title")):
                    if outer_block.get("content"):
                        json_content[i] = outer_block.get("content")[0]

    # Edge case remove an extra section
    if doi == "10.7554/eLife.05519":
        if (json_content and len(json_content) > 0):
            for outer_block in json_content:
                if outer_block.get("id") and outer_block.get("id") == "s4":
                    for mid_block in outer_block.get("content"):
                        if mid_block.get("content") and not mid_block.get("id"):
                            new_blocks = []
                            for inner_block in mid_block.get("content"):
                                 new_blocks.append(inner_block)
                            outer_block["content"] = new_blocks

    # Edge case add a title to a section
    if doi == "10.7554/eLife.07157":
        if (json_content and len(json_content) > 0):
            if (json_content[0].get("type") and json_content[0].get("type") == "section"
                and json_content[0].get("id") and json_content[0].get("id") == "s1"):
                json_content[0]["title"] = "Main text"

    # Edge case remove a section with no content
    if doi == "10.7554/eLife.09977":
        if (json_content and len(json_content) > 0):
            i_index = j_index = None
            for i, outer_block in enumerate(json_content):
                if (outer_block.get("id") and outer_block.get("id") == "s4"
                    and outer_block.get("content")):
                    # We have i
                    i_index = i
                    break
            if i_index is not None:
                for j, inner_block in enumerate(json_content[i_index].get("content")):
                    if (inner_block.get("id") and inner_block.get("id") == "s4-11"
                        and inner_block.get("content") is None):
                        # Now we have i and j for deletion outside of the loop
                        j_index = j
                        break
            # Do the deletion on the original json
            if i_index is not None and j_index is not None:
                del json_content[i_index]["content"][j_index]

    # Edge case wrap sections differently
    if doi == "10.7554/eLife.12844":
        if (json_content and len(json_content) > 0 and json_content[0].get("type")
            and json_content[0]["type"] == "section"):
            new_body = OrderedDict()
            for i, tag_block in enumerate(json_content):
                if i == 0:
                    tag_block["title"] = "Main text"
                    new_body = tag_block
                elif i > 0:
                    new_body["content"].append(tag_block)
            json_content = [new_body]

    return json_content


Instruction:
How would you explain what the following Python 3 function does
def rewrite_elife_funding_awards(json_content, doi):

    # remove a funding award
    if doi == "10.7554/eLife.00801":
        for i, award in enumerate(json_content):
            if "id" in award and award["id"] == "par-2":
                del json_content[i]

    # add funding award recipient
    if doi == "10.7554/eLife.04250":
        recipients_for_04250 = [{"type": "person", "name": {"preferred": "Eric Jonas", "index": "Jonas, Eric"}}]
        for i, award in enumerate(json_content):
            if "id" in award and award["id"] in ["par-2", "par-3", "par-4"]:
                if "recipients" not in award:
                    json_content[i]["recipients"] = recipients_for_04250

    # add funding award recipient
    if doi == "10.7554/eLife.06412":
        recipients_for_06412 = [{"type": "person", "name": {"preferred": "Adam J Granger", "index": "Granger, Adam J"}}]
        for i, award in enumerate(json_content):
            if "id" in award and award["id"] == "par-1":
                if "recipients" not in award:
                    json_content[i]["recipients"] = recipients_for_06412

    return json_content

Response: rewrite ife funding awards


Instruction:
Can you generate a brief explanation for the following Python 3 code
def rewrite_elife_authors_json(json_content, doi):

    # Convert doi from testing doi if applicable
    article_doi = elifetools.utils.convert_testing_doi(doi)

    # Edge case fix an affiliation name
    if article_doi == "10.7554/eLife.06956":
        for i, ref in enumerate(json_content):
            if ref.get("orcid") and ref.get("orcid") == "0000-0001-6798-0064":
                json_content[i]["affiliations"][0]["name"] = ["Cambridge"]

    # Edge case fix an ORCID
    if article_doi == "10.7554/eLife.09376":
        for i, ref in enumerate(json_content):
            if ref.get("orcid") and ref.get("orcid") == "000-0001-7224-925X":
                json_content[i]["orcid"] = "0000-0001-7224-925X"

    # Edge case competing interests
    if article_doi == "10.7554/eLife.00102":
        for i, ref in enumerate(json_content):
            if not ref.get("competingInterests"):
                if ref["name"]["index"].startswith("Chen,"):
                    json_content[i]["competingInterests"] = "ZJC: Reviewing Editor, eLife"
                elif ref["name"]["index"].startswith("Li,"):
                    json_content[i]["competingInterests"] = "The remaining authors have no competing interests to declare."
    if article_doi == "10.7554/eLife.00270":
        for i, ref in enumerate(json_content):
            if not ref.get("competingInterests"):
                if ref["name"]["index"].startswith("Patterson,"):
                    json_content[i]["competingInterests"] = "MP: Managing Executive Editor, eLife"

    # Remainder of competing interests rewrites
    elife_author_competing_interests = {}
    elife_author_competing_interests["10.7554/eLife.00133"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.00190"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.00230"] = "The authors have declared that no competing interests exist"
    elife_author_competing_interests["10.7554/eLife.00288"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.00352"] = "The author declares that no competing interest exist"
    elife_author_competing_interests["10.7554/eLife.00362"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.00475"] = "The remaining authors have no competing interests to declare."
    elife_author_competing_interests["10.7554/eLife.00592"] = "The other authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.00633"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.02725"] = "The other authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.02935"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.04126"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.04878"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.05322"] = "The other authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.06011"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.06416"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.07383"] = "The other authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.08421"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.08494"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.08648"] = "The other authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.08924"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.09083"] = "The other authors declare that no competing interests exists."
    elife_author_competing_interests["10.7554/eLife.09102"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.09460"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.09591"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.09600"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.10113"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.10230"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.10453"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.10635"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.11407"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.11473"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.11750"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.12217"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.12620"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.12724"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.13023"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.13732"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.14116"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.14258"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.14694"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.15085"] = "The other authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.15312"] = "The other authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.16011"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.16940"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.17023"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.17092"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.17218"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.17267"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.17523"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.17556"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.17769"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.17834"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.18101"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.18515"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.18544"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.18648"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.19071"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.19334"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.19510"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.20183"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.20242"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.20375"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.20797"] = "The other authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.21454"] = "The authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.21491"] = "The other authors declare that no competing interests exist."
    elife_author_competing_interests["10.7554/eLife.22187"] = "The authors declare that no competing interests exist."

    if article_doi in elife_author_competing_interests:
        for i, ref in enumerate(json_content):
            if not ref.get("competingInterests"):
                json_content[i]["competingInterests"] = elife_author_competing_interests[article_doi]

    # Rewrite "other authors declare" ... competing interests statements using a string match
    for i, ref in enumerate(json_content):
        if (ref.get("competingInterests") and (
            ref.get("competingInterests").startswith("The other author") or
            ref.get("competingInterests").startswith("The others author") or
            ref.get("competingInterests").startswith("The remaining authors") or
            ref.get("competingInterests").startswith("The remaining have declared")
            )):
            json_content[i]["competingInterests"] = "No competing interests declared."

    return json_content

Response: This function rewrites the elife authors json to include the correct doi.


Instruction:
Here you have a function in Python 3, explain what it does
def rewrite_elife_datasets_json(json_content, doi):

    # Add dates in bulk
    elife_dataset_dates = []
    elife_dataset_dates.append(("10.7554/eLife.00348", "used", "dataro17", u"2010"))
    elife_dataset_dates.append(("10.7554/eLife.01179", "used", "dataro4", u"2016"))
    elife_dataset_dates.append(("10.7554/eLife.01603", "used", "dataro2", u"2012"))
    elife_dataset_dates.append(("10.7554/eLife.02304", "used", "dataro15", u"2005"))
    elife_dataset_dates.append(("10.7554/eLife.02935", "used", "dataro2", u"2014"))
    elife_dataset_dates.append(("10.7554/eLife.03583", "used", "dataro5", u"2013"))
    if doi in map(lambda dataset: dataset[0], elife_dataset_dates):
        for (match_doi, used_or_generated, id, dataset_date) in elife_dataset_dates:
            if doi == match_doi:
                if json_content.get(used_or_generated):
                    for dataset in json_content[used_or_generated]:
                        if dataset.get("id") and dataset["id"] == id:
                            if not dataset.get("date"):
                                dataset["date"] = dataset_date

    # Continue with individual article JSON rewriting
    if doi == "10.7554/eLife.01311":
        if json_content.get("used"):
            for dataset in json_content["used"]:
                if dataset.get("id") and dataset["id"] in ["dataro3", "dataro4", "dataro5"]:
                    if not dataset.get("date"):
                        dataset["date"] = u"2012"
                    if not dataset.get("authors"):
                        dataset["authors"] = [{"type": "group", "name": "Duke"}]
                if dataset.get("id") and dataset["id"] == "dataro6":
                    if not dataset.get("date"):
                        dataset["date"] = u"2011"
                    if not dataset.get("authors"):
                        dataset["authors"] = [{"type": "group", "name": "FlyBase"}]
                if dataset.get("id") and dataset["id"] == "dataro7":
                    if not dataset.get("date"):
                        dataset["date"] = u"2011"
                    if not dataset.get("authors"):
                        dataset["authors"] = [{"type": "group", "name": "Baylor College of Medicine (BCM)"}]
                if dataset.get("id") and dataset["id"] in ["dataro8", "dataro9"]:
                    if not dataset.get("date"):
                        dataset["date"] = u"2012"
                    if not dataset.get("authors"):
                        dataset["authors"] = [{"type": "group", "name": "University of California, Berkeley"}]

    if doi == "10.7554/eLife.01440":
        if json_content.get("used"):
            for dataset in json_content["used"]:
                if dataset.get("id") and dataset["id"] == "dataro1":
                    if not dataset.get("authors"):
                        dataset["authors"] = [{"type": "group", "name": "EnsemblMetazoa"}]

    if doi == "10.7554/eLife.01535":
        if json_content.get("used"):
            for dataset in json_content["used"]:
                if dataset.get("id") and dataset["id"] == "dataro1":
                    if dataset.get("date") and dataset.get("date") == "2000, 2005":
                        dataset["date"] = u"2000"

    if doi == "10.7554/eLife.02304":
        if json_content.get("used"):
            for dataset in json_content["used"]:
                if dataset.get("id") and dataset["id"] == "dataro11":
                    if not dataset.get("title"):
                        dataset["title"] = u"T.gondii LDH1 ternary complex with APAD+ and oxalate"

    if doi == "10.7554/eLife.03574":
        if json_content.get("used"):
            for dataset in json_content["used"]:
                if dataset.get("id") and dataset["id"] == "dataro2":
                    if not dataset.get("date"):
                        dataset["date"] = u"2006"
                    if not dataset.get("authors"):
                        dataset["authors"] = [{"type": "group", "name": "Riley,M."}, {"type": "group", "name": "Abe,T."}, {"type": "group", "name": "Arnaud,M.B."}, {"type": "group", "name": "Berlyn,M.K."}, {"type": "group", "name": "Blattner,F.R."}, {"type": "group", "name": "Chaudhuri,R.R."}, {"type": "group", "name": "Glasner,J.D."}, {"type": "group", "name": "Horiuchi,T."}, {"type": "group", "name": "Keseler,I.M."}, {"type": "group", "name": "Kosuge,T."}, {"type": "group", "name": "Mori,H."}, {"type": "group", "name": "Perna,N.T."}, {"type": "group", "name": "Plunkett,G. III"}, {"type": "group", "name": "Rudd,K.E."}, {"type": "group", "name": "Serres,M.H."}, {"type": "group", "name": "Thomas,G.H."}, {"type": "group", "name": "Thomson,N.R."}, {"type": "group", "name": "Wishart,D."}, {"type": "group", "name": "Wanner,B.L."}]

    if doi == "10.7554/eLife.03676":
        if json_content.get("used"):
            for dataset in json_content["used"]:
                if dataset.get("id") and dataset["id"] == "dataro4":
                    if not dataset.get("date"):
                        dataset["date"] = u"2013"
                    if not dataset.get("authors"):
                        dataset["authors"] = [{"type": "group", "name": "Human Gene Sequencing Center"}]

    if doi == "10.7554/eLife.03971":
        if json_content.get("used"):
            for dataset in json_content["used"]:
                if dataset.get("id") and dataset["id"] == "dataro2":
                    if not dataset.get("authors"):
                        dataset["authors"] = [{"type": "group", "name": "Vanderperre B."}]

    if doi == "10.7554/eLife.04660":
        if json_content.get("generated"):
            for dataset in json_content["generated"]:
                if dataset.get("id") and dataset["id"] == "dataro1":
                    if dataset.get("date") and dataset.get("date") == "2014-2015":
                        dataset["date"] = u"2014"

    if doi == "10.7554/eLife.06421":
        if json_content.get("used"):
            for dataset in json_content["used"]:
                if dataset.get("id") and dataset["id"] == "dataro2":
                    if dataset.get("date") and dataset.get("date") == "NA":
                        dataset["date"] = u"2006"

    if doi == "10.7554/eLife.08445":
        if json_content.get("used"):
            for dataset in json_content["used"]:
                if dataset.get("id") and dataset["id"] == "data-ro1":
                    if not dataset.get("date"):
                        dataset["date"] = u"2006"
                    if not dataset.get("authors"):
                        dataset["authors"] = [{"type": "group", "name": "BDTNP SELEX"}]

    if doi == "10.7554/eLife.08916":
        if json_content.get("used"):
            for dataset in json_content["used"]:
                if dataset.get("id") and dataset["id"] == "dataro2":
                    if dataset.get("date") and dataset.get("date") == "2008, updated 2014":
                        dataset["date"] = u"2008"
                if dataset.get("id") and dataset["id"] == "dataro3":
                    if dataset.get("date") and dataset.get("date") == "2013, updated 2014":
                        dataset["date"] = u"2013"

    if doi == "10.7554/eLife.08955":
        if json_content.get("generated"):
            for dataset in json_content["generated"]:
                if dataset.get("id") and dataset["id"] == "dataro2":
                    if not dataset.get("authors"):
                        dataset["authors"] = [{"type": "group", "name": "Kurdistani S"}, {"type": "group", "name": "Marrban C"}, {"type": "group", "name": "Su T"}]

    if doi == "10.7554/eLife.09207":
        if json_content.get("used"):
            for dataset in json_content["used"]:
                if dataset.get("id") and dataset["id"] == "dataro1":
                    if not dataset.get("authors"):
                        dataset["authors"] = [{"type": "group", "name": "Prostate Cancer Genome Sequencing Project"}]

    if doi == "10.7554/eLife.10607":
        if json_content.get("generated"):
            for dataset in json_content["generated"]:
                if dataset.get("id") and dataset["id"] == "data-ro4":
                    if not dataset.get("authors"):
                        dataset["authors"] = [{"type": "group", "name": "Authors"}]

    if doi == "10.7554/eLife.10670":
        if json_content.get("used"):
            for dataset in json_content["used"]:
                if dataset.get("id") and dataset["id"] == "data-ro1":
                    if not dataset.get("authors"):
                        dataset["authors"] = [{"type": "group", "name": "HIVdb"}]

    # Add dates, authors, other details
    if doi == "10.7554/eLife.10856":
        if json_content.get("generated"):
            datasets_authors_for_10856 = [{"type": "group", "name": "Dagdas YF"}, {"type": "group", "name": "Belhaj K"}, {"type": "group", "name": "Maqbool A"}, {"type": "group", "name": "Chaparro-Garcia A"}, {"type": "group", "name": "Pandey P"}, {"type": "group", "name": "Petre B"}, {"type": "group", "name": "Tabassum N"}, {"type": "group", "name": "Cruz-Mireles N"}, {"type": "group", "name": "Hughes RK"}, {"type": "group", "name": "Sklenar J"}, {"type": "group", "name": "Win J"}, {"type": "group", "name": "Menke F"}, {"type": "group", "name": "Findlay K"}, {"type": "group", "name": "Banfield MJ"}, {"type": "group", "name": "Kamoun S"}, {"type": "group", "name": "Bozkurt TO"}]
            for dataset in json_content["generated"]:
                if dataset.get("id") and dataset["id"] == "dataro7":
                    if not dataset.get("date"):
                        dataset["date"] = u"2016"
                    if not dataset.get("title"):
                        dataset["title"] = u"An effector of the Irish potato famine pathogen antagonizes a host autophagy cargo receptor"
                    if not dataset.get("authors"):
                        dataset["authors"] = datasets_authors_for_10856
                    if dataset.get("uri") and dataset["uri"] == "http://www.ncbi.nlm.nih.":
                         dataset["uri"] = "https://www.ncbi.nlm.nih.gov/nuccore/976151098/"
                if dataset.get("id") and dataset["id"] == "dataro8":
                    if not dataset.get("date"):
                        dataset["date"] = u"2015"
                    if not dataset.get("title"):
                        dataset["title"] = u"An effector of the Irish potato famine pathogen antagonizes a host autophagy cargo receptor"
                    if not dataset.get("authors"):
                        dataset["authors"] = datasets_authors_for_10856
                    if dataset.get("uri") and dataset["uri"] == "http://www.ncbi.nlm.nih.":
                         dataset["uri"] = "https://www.ncbi.nlm.nih.gov/nuccore/976151096/"
                if dataset.get("id") and dataset["id"] == "dataro9":
                    if not dataset.get("authors"):
                        dataset["authors"] = datasets_authors_for_10856

    if doi == "10.7554/eLife.10877":
        if json_content.get("generated"):
            for dataset in json_content["generated"]:
                if dataset.get("id") and dataset["id"] == "dataro1":
                    if not dataset.get("title"):
                        dataset["title"] = u"Oct4 ChIP-Seq at G1 and G2/M phase of cell cycle in mouse embryonic stem cells"

    if doi == "10.7554/eLife.10921":
        if json_content.get("generated"):
            for dataset in json_content["generated"]:
                if dataset.get("id") and dataset["id"] == "dataro1":
                    if not dataset.get("authors"):
                        dataset["authors"] = [{"type": "group", "name": "Floor SN"}, {"type": "group", "name": "Doudna JA"}]
        if json_content.get("used"):
            for dataset in json_content["used"]:
                if dataset.get("id") and dataset["id"] == "dataro2":
                    if not dataset.get("authors"):
                        dataset["authors"] = [{"type": "group", "name": "Sidrauski C"}, {"type": "group", "name": "McGeachy A"}, {"type": "group", "name": "Ingolia N"}, {"type": "group", "name": "Walter P"}]

    if doi == "10.7554/eLife.11117":
        if json_content.get("used"):
            for dataset in json_content["used"]:
                if dataset.get("id") and dataset["id"] == "dataro14":
                    if not dataset.get("authors"):
                        dataset["authors"] = [{"type": "group", "name": "Authors"}]

    if doi == "10.7554/eLife.12204":
        if json_content.get("used"):
            for dataset in json_content["used"]:
                if dataset.get("id") and dataset["id"] == "dataro1":
                    if not dataset.get("authors"):
                        dataset["authors"] = [{"type": "group", "name": "Rhodes DR"}, {"type": "group", "name": "Kalyana-Sundaram S"}, {"type": "group", "name": "Mahavisno V"}, {"type": "group", "name": "Varambally R"}, {"type": "group", "name": "Yu J"}, {"type": "group", "name": "Briggs BB"}, {"type": "group", "name": "Barrette TR"}, {"type": "group", "name": "Anstet MJ"}, {"type": "group", "name": "Kincead-Beal C"}, {"type": "group", "name": "Kulkarni P"}, {"type": "group", "name": "Varambally S"}, {"type": "group", "name": "Ghosh D"}, {"type": "group", "name": "Chinnaiyan AM."}]
                if dataset.get("id") and dataset["id"] == "dataro2":
                    if not dataset.get("authors"):
                        dataset["authors"] = [{"type": "group", "name": "Gaspar C"}, {"type": "group", "name": "Cardoso J"}, {"type": "group", "name": "Franken P"}, {"type": "group", "name": "Molenaar L"}, {"type": "group", "name": "Morreau H"}, {"type": "group", "name": "Möslein G"}, {"type": "group", "name": "Sampson J"}, {"type": "group", "name": "Boer JM"}, {"type": "group", "name": "de Menezes RX"}, {"type": "group", "name": "Fodde R."}]
                if dataset.get("id") and dataset["id"] == "dataro3":
                    if not dataset.get("authors"):
                        dataset["authors"] = [{"type": "group", "name": "Graudens E"}, {"type": "group", "name": "Boulanger V"}, {"type": "group", "name": "Mollard C"}, {"type": "group", "name": "Mariage-Samson R"}, {"type": "group", "name": "Barlet X"}, {"type": "group", "name": "Grémy G"}, {"type": "group", "name": "Couillault C"}, {"type": "group", "name": "Lajémi M"}, {"type": "group", "name": "Piatier-Tonneau D"}, {"type": "group", "name": "Zaborski P"}, {"type": "group", "name": "Eveno E"}, {"type": "group", "name": "Auffray C"}, {"type": "group", "name": "Imbeaud S."}]
                if dataset.get("id") and dataset["id"] == "dataro4":
                    if not dataset.get("authors"):
                        dataset["authors"] = [{"type": "group", "name": "Hong Y"}, {"type": "group", "name": "Downey T"}, {"type": "group", "name": "Eu KW"}, {"type": "group", "name": "Koh PK"},{"type": "group", "name": "Cheah PY"}]
                if dataset.get("id") and dataset["id"] == "dataro5":
                    if not dataset.get("authors"):
                        dataset["authors"] = [{"type": "group", "name": "Kaiser S"}, {"type": "group", "name": "Park YK"}, {"type": "group", "name": "Franklin JL"}, {"type": "group", "name": "Halberg RB"}, {"type": "group", "name": "Yu M"}, {"type": "group", "name": "Jessen WJ"}, {"type": "group", "name": "Freudenberg J"}, {"type": "group", "name": "Chen X"}, {"type": "group", "name": "Haigis K"}, {"type": "group", "name": "Jegga AG"}, {"type": "group", "name": "Kong S"}, {"type": "group", "name": "Sakthivel B"}, {"type": "group", "name": "Xu H"}, {"type": "group", "name": "Reichling T"}, {"type": "group", "name": "Azhar M"}, {"type": "group", "name": "Boivin GP"}, {"type": "group", "name": "Roberts RB"}, {"type": "group", "name": "Bissahoyo AC"}, {"type": "group", "name": "Gonzales F"}, {"type": "group", "name": "Bloom GC"}, {"type": "group", "name": "Eschrich S"}, {"type": "group", "name": "Carter SL"}, {"type": "group", "name": "Aronow JE"}, {"type": "group", "name": "Kleimeyer J"}, {"type": "group", "name": "Kleimeyer M"}, {"type": "group", "name": "Ramaswamy V"}, {"type": "group", "name": "Settle SH"}, {"type": "group", "name": "Boone B"}, {"type": "group", "name": "Levy S"}, {"type": "group", "name": "Graff JM"}, {"type": "group", "name": "Doetschman T"}, {"type": "group", "name": "Groden J"}, {"type": "group", "name": "Dove WF"}, {"type": "group", "name": "Threadgill DW"}, {"type": "group", "name": "Yeatman TJ"}, {"type": "group", "name": "Coffey RJ Jr"}, {"type": "group", "name": "Aronow BJ."}]
                if dataset.get("id") and dataset["id"] == "dataro6":
                    if not dataset.get("authors"):
                        dataset["authors"] = [{"type": "group", "name": "Muzny DM et al"}]
                if dataset.get("id") and dataset["id"] == "dataro7":
                    if not dataset.get("authors"):
                        dataset["authors"] = [{"type": "group", "name": "Skrzypczak M"}, {"type": "group", "name": "Goryca K"}, {"type": "group", "name": "Rubel T"}, {"type": "group", "name": "Paziewska A"}, {"type": "group", "name": "Mikula M"}, {"type": "group", "name": "Jarosz D"}, {"type": "group", "name": "Pachlewski J"}, {"type": "group", "name": "Oledzki J"}, {"type": "group", "name": "Ostrowski J."}]
                if dataset.get("id") and dataset["id"] == "dataro8":
                    if not dataset.get("authors"):
                        dataset["authors"] = [{"type": "group", "name": "Cancer Genome Atlas Network"}]

    if doi == "10.7554/eLife.12876":
        if json_content.get("used"):
            for dataset in json_content["used"]:
                if dataset.get("id") and dataset["id"] == "dataro1":
                    if not dataset.get("authors"):
                        dataset["authors"] = [{"type": "group", "name": "Department of Human Genetics, University of Utah"}]

    if doi == "10.7554/eLife.13195":
        if json_content.get("generated"):
            for dataset in json_content["generated"]:
                if dataset.get("id") and dataset["id"] == "dataro1":
                    if not dataset.get("authors"):
                        dataset["authors"] = [{"type": "group", "name": "Microbial Ecology Group, Colorado State University"}]

    if doi == "10.7554/eLife.14158":
        if json_content.get("generated"):
            for dataset in json_content["generated"]:
                if dataset.get("id") and dataset["id"] == "data-ro1":
                    if not dataset.get("title"):
                        dataset["title"] = u"Bacterial initiation protein"
                if dataset.get("id") and dataset["id"] == "data-ro2":
                    if not dataset.get("title"):
                        dataset["title"] = u"Bacterial initiation protein in complex with Phage inhibitor protein"
        if json_content.get("used"):
            for dataset in json_content["used"]:
                if dataset.get("id") and dataset["id"] == "dataro3":
                    if not dataset.get("date"):
                        dataset["date"] = u"2007"

    if doi == "10.7554/eLife.14243":
        if json_content.get("generated"):
            for dataset in json_content["generated"]:
                if dataset.get("id") and dataset["id"] == "dataro2":
                    if not dataset.get("authors"):
                        dataset["authors"] = [{"type": "group", "name": "Tramantano M"}, {"type": "group", "name": "Sun L"}, {"type": "group", "name": "Au C"}, {"type": "group", "name": "Labuz D"}, {"type": "group", "name": "Liu Z"}, {"type": "group", "name": "Chou M"}, {"type": "group", "name": "Shen C"}, {"type": "group", "name": "Luk E"}]

    if doi == "10.7554/eLife.16078":
        if json_content.get("generated"):
            for dataset in json_content["generated"]:
                if dataset.get("id") and dataset["id"] == "dataro1":
                    if dataset.get("date") and dataset.get("date") == "current manuscript":
                        dataset["date"] = u"2016"

    if doi == "10.7554/eLife.17082":
        if json_content.get("used"):
            for dataset in json_content["used"]:
                if dataset.get("id") and dataset["id"] == "data-ro4":
                    if not dataset.get("date"):
                        dataset["date"] = u"2012"
                if dataset.get("id") and dataset["id"] == "data-ro5":
                    if not dataset.get("date"):
                        dataset["date"] = u"2014"
                if dataset.get("id") and dataset["id"] == "data-ro6":
                    if not dataset.get("date"):
                        dataset["date"] = u"2014"
                    if not dataset.get("authors"):
                        dataset["authors"] = [{"type": "group", "name": "The Cancer Genome Atlas (TCGA)"}]

    if doi == "10.7554/eLife.17473":
        if json_content.get("generated"):
            for dataset in json_content["generated"]:
                if dataset.get("id") and dataset["id"] == "dataro1":
                    if dataset.get("date") and dataset.get("date").startswith("Release date"):
                        dataset["date"] = u"2016"

    return json_content

Response: This function rewrites the elife datasets json in the current article to include the same doi as the original.


Instruction:
How would you explain what the following Python 3 function does
def rewrite_elife_editors_json(json_content, doi):

    # Remove affiliations with no name value
    for i, ref in enumerate(json_content):
        if ref.get("affiliations"):
            for aff in ref.get("affiliations"):
                if "name" not in aff:
                    del(json_content[i]["affiliations"])

    # Add editor role
    editor_roles = {}
    editor_roles["10.7554/eLife.00534"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.09376"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.10056"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.11031"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.12081"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.12241"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.12509"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.13023"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.13053"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.13426"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.13620"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.13810"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.13828"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.13887"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.13905"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.14000"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.14155"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.14170"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.14226"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.14277"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.14315"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.14316"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.14530"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.14601"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.14618"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.14749"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.14814"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.15266"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.15275"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.15292"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.15316"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.15470"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.15545"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.15716"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.15747"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.15828"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.15833"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.15915"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.15986"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.16088"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.16093"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.16127"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.16159"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.16178"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.16309"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.16777"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.16793"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.16950"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.17101"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.17180"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.17240"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.17262"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.17282"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.17463"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.17551"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.17667"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.17681"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.17978"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.17985"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.18103"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.18207"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.18246"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.18249"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.18432"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.18447"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.18458"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.18491"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.18541"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.18542"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.18579"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.18605"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.18633"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.18657"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.18919"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.18970"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.19027"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.19088"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.19089"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.19295"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.19377"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.19406"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.19466"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.19484"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.19505"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.19535"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.19568"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.19573"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.19662"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.19671"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.19686"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.19695"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.19720"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.19749"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.19766"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.19804"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.19809"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.19887"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.19976"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.19991"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.20010"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.20054"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.20070"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.20183"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.20185"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.20214"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.20236"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.20309"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.20343"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.20357"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.20362"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.20365"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.20390"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.20417"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.20515"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.20533"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.20607"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.20640"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.20667"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.20718"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.20722"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.20777"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.20782"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.20787"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.20797"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.20799"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.20813"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.20954"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.20958"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.20985"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.21032"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.21049"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.21052"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.21170"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.21172"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.21290"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.21330"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.21394"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.21397"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.21455"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.21481"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.21491"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.21589"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.21598"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.21616"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.21635"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.21728"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.21771"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.21776"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.21855"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.21886"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.21920"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.21989"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.22028"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.22053"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.22170"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.22177"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.22280"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.22409"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.22429"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.22431"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.22467"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.22472"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.22502"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.22771"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.22784"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.22866"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.23156"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.23352"] = "Reviewing Editor"
    editor_roles["10.7554/eLife.23804"] = "Reviewing Editor"

    # Edge case fix an affiliation name
    if doi in editor_roles:
        for i, ref in enumerate(json_content):
            if not ref.get("role"):
                json_content[i]["role"] = editor_roles[doi]
            elif ref.get("role"):
                json_content[i]["role"] = "Reviewing Editor"
    else:
        # Fix capitalisation on exiting role values
        for i, ref in enumerate(json_content):
            if ref.get("role") == "Reviewing editor":
                json_content[i]["role"] = "Reviewing Editor"

    # Remove duplicates
    editors_kept = []
    for i, ref in enumerate(json_content):
        editor_values = OrderedDict()
        editor_values["role"] = ref.get("role")
        if ref.get("name"):
            editor_values["name"] = ref.get("name").get("index")
        if editor_values in editors_kept:
            # remove if one is already kept
            del json_content[i]
        else:
            editors_kept.append(editor_values)

    # Merge two role values
    role_replacements = [
        {
            "role_from": ["Senior Editor", "Reviewing Editor"],
            "role_to": "Senior and Reviewing Editor"}
    ]
    for replace_rule in role_replacements:
        same_name_map = person_same_name_map(json_content, replace_rule.get('role_from'))
        role_is_set = None
        for same_id_list in same_name_map.values():
            if not same_id_list or len(same_id_list) <= 1:
                # no more than one name match, nothing to replace
                continue
            deleted_count = 0
            for same_id in same_id_list:
                if not role_is_set:
                    # reset the role for the first person record
                    json_content[same_id]["role"] = replace_rule.get("role_to")
                    role_is_set = True
                else:
                    # first one is already set, remove the duplicates
                    del json_content[same_id-deleted_count]
                    deleted_count += 1

    return json_content

Response: This function rewrites the elife editors json to include the doi and the content of the new content.


Instruction:
Can you tell what is the following Python 3 function doing
def rewrite_elife_title_prefix_json(json_content, doi):
    if not json_content:
        return json_content

    # title prefix rewrites by article DOI
    title_prefix_values = {}
    title_prefix_values["10.7554/eLife.00452"] = "Point of View"
    title_prefix_values["10.7554/eLife.00615"] = "Point of View"
    title_prefix_values["10.7554/eLife.00639"] = "Point of View"
    title_prefix_values["10.7554/eLife.00642"] = "Point of View"
    title_prefix_values["10.7554/eLife.00856"] = "Point of View"
    title_prefix_values["10.7554/eLife.01061"] = "Point of View"
    title_prefix_values["10.7554/eLife.01138"] = "Point of View"
    title_prefix_values["10.7554/eLife.01139"] = "Point of View"
    title_prefix_values["10.7554/eLife.01820"] = "Animal Models of Disease"
    title_prefix_values["10.7554/eLife.02576"] = "Point of View"
    title_prefix_values["10.7554/eLife.04902"] = "Point of View"
    title_prefix_values["10.7554/eLife.05614"] = "Point of View"
    title_prefix_values["10.7554/eLife.05635"] = "The Natural History of Model Organisms"
    title_prefix_values["10.7554/eLife.05826"] = "The Natural History of Model Organisms"
    title_prefix_values["10.7554/eLife.05835"] = "The Natural History of Model Organisms"
    title_prefix_values["10.7554/eLife.05849"] = "The Natural History of Model Organisms"
    title_prefix_values["10.7554/eLife.05861"] = "The Natural History of Model Organisms"
    title_prefix_values["10.7554/eLife.05959"] = "The Natural History of Model Organisms"
    title_prefix_values["10.7554/eLife.06024"] = "The Natural History of Model Organisms"
    title_prefix_values["10.7554/eLife.06100"] = "The Natural History of Model Organisms"
    title_prefix_values["10.7554/eLife.06793"] = "The Natural History of Model Organisms"
    title_prefix_values["10.7554/eLife.06813"] = "The Natural History of Model Organisms"
    title_prefix_values["10.7554/eLife.06956"] = "The Natural History of Model Organisms"
    title_prefix_values["10.7554/eLife.09305"] = "Point of View"
    title_prefix_values["10.7554/eLife.10825"] = "Point of View"
    title_prefix_values["10.7554/eLife.11628"] = "Living Science"
    title_prefix_values["10.7554/eLife.12708"] = "Point of View"
    title_prefix_values["10.7554/eLife.12844"] = "Point of View"
    title_prefix_values["10.7554/eLife.13035"] = "Point of View"
    title_prefix_values["10.7554/eLife.14258"] = "Cutting Edge"
    title_prefix_values["10.7554/eLife.14424"] = "Point of View"
    title_prefix_values["10.7554/eLife.14511"] = "Cell Proliferation"
    title_prefix_values["10.7554/eLife.14721"] = "Intracellular Bacteria"
    title_prefix_values["10.7554/eLife.14790"] = "Decision Making"
    title_prefix_values["10.7554/eLife.14830"] = "Progenitor Cells"
    title_prefix_values["10.7554/eLife.14953"] = "Gene Expression"
    title_prefix_values["10.7554/eLife.14973"] = "Breast Cancer"
    title_prefix_values["10.7554/eLife.15352"] = "Autoimmune Disorders"
    title_prefix_values["10.7554/eLife.15438"] = "Motor Circuits"
    title_prefix_values["10.7554/eLife.15591"] = "Protein Tagging"
    title_prefix_values["10.7554/eLife.15928"] = "Point of View"
    title_prefix_values["10.7554/eLife.15938"] = "Cancer Metabolism"
    title_prefix_values["10.7554/eLife.15957"] = "Stem Cells"
    title_prefix_values["10.7554/eLife.15963"] = "Prediction Error"
    title_prefix_values["10.7554/eLife.16019"] = "Social Networks"
    title_prefix_values["10.7554/eLife.16076"] = "mRNA Decay"
    title_prefix_values["10.7554/eLife.16207"] = "Cardiac Development"
    title_prefix_values["10.7554/eLife.16209"] = "Neural Coding"
    title_prefix_values["10.7554/eLife.16393"] = "Neural Circuits"
    title_prefix_values["10.7554/eLife.16598"] = "RNA Localization"
    title_prefix_values["10.7554/eLife.16758"] = "Adaptive Evolution"
    title_prefix_values["10.7554/eLife.16800"] = "Point of View"
    title_prefix_values["10.7554/eLife.16846"] = "Living Science"
    title_prefix_values["10.7554/eLife.16931"] = "Point of View"
    title_prefix_values["10.7554/eLife.16964"] = "Ion Channels"
    title_prefix_values["10.7554/eLife.17224"] = "Host-virus Interactions"
    title_prefix_values["10.7554/eLife.17293"] = "Ion Channels"
    title_prefix_values["10.7554/eLife.17393"] = "Point of View"
    title_prefix_values["10.7554/eLife.17394"] = "p53 Family Proteins"
    title_prefix_values["10.7554/eLife.18203"] = "Antibody Engineering"
    title_prefix_values["10.7554/eLife.18243"] = "Host-virus Interactions"
    title_prefix_values["10.7554/eLife.18365"] = "DNA Repair"
    title_prefix_values["10.7554/eLife.18431"] = "Unfolded Protein Response"
    title_prefix_values["10.7554/eLife.18435"] = "Long Distance Transport"
    title_prefix_values["10.7554/eLife.18721"] = "Decision Making"
    title_prefix_values["10.7554/eLife.18753"] = "Resource Competition"
    title_prefix_values["10.7554/eLife.18871"] = "Mathematical Modeling"
    title_prefix_values["10.7554/eLife.18887"] = "Sensorimotor Transformation"
    title_prefix_values["10.7554/eLife.19285"] = "Genetic Screen"
    title_prefix_values["10.7554/eLife.19351"] = "Motor Control"
    title_prefix_values["10.7554/eLife.19405"] = "Membrane Structures"
    title_prefix_values["10.7554/eLife.19733"] = "Focal Adhesions"
    title_prefix_values["10.7554/eLife.20043"] = "Amyloid-beta Peptides"
    title_prefix_values["10.7554/eLife.20314"] = "Plant Reproduction"
    title_prefix_values["10.7554/eLife.20468"] = "Endoplasmic Reticulum"
    title_prefix_values["10.7554/eLife.20516"] = "Innate Like Lymphocytes"
    title_prefix_values["10.7554/eLife.21070"] = "Scientific Publishing"
    title_prefix_values["10.7554/eLife.21236"] = "Developmental Neuroscience"
    title_prefix_values["10.7554/eLife.21522"] = "Developmental Neuroscience"
    title_prefix_values["10.7554/eLife.21723"] = "Living Science"
    title_prefix_values["10.7554/eLife.21863"] = "Genetic Screening"
    title_prefix_values["10.7554/eLife.21864"] = "Evolutionary Biology"
    title_prefix_values["10.7554/eLife.22073"] = "Unfolded Protein Response"
    title_prefix_values["10.7554/eLife.22186"] = "Point of View"
    title_prefix_values["10.7554/eLife.22215"] = "Neural Wiring"
    title_prefix_values["10.7554/eLife.22256"] = "Molecular Communication"
    title_prefix_values["10.7554/eLife.22471"] = "Point of View"
    title_prefix_values["10.7554/eLife.22661"] = "Reproducibility in Cancer Biology"
    title_prefix_values["10.7554/eLife.22662"] = "Reproducibility in Cancer Biology"
    title_prefix_values["10.7554/eLife.22735"] = "Motor Networks"
    title_prefix_values["10.7554/eLife.22850"] = "Heat Shock Response"
    title_prefix_values["10.7554/eLife.22915"] = "Reproducibility in Cancer Biology"
    title_prefix_values["10.7554/eLife.22926"] = "Skeletal Stem Cells"
    title_prefix_values["10.7554/eLife.23375"] = "Social Evolution"
    title_prefix_values["10.7554/eLife.23383"] = "Reproducibility in Cancer Biology"
    title_prefix_values["10.7554/eLife.23447"] = "Genetic Rearrangement"
    title_prefix_values["10.7554/eLife.23693"] = "Reproducibility in Cancer Biology"
    title_prefix_values["10.7554/eLife.23804"] = "Point of View"
    title_prefix_values["10.7554/eLife.24038"] = "Cell Division"
    title_prefix_values["10.7554/eLife.24052"] = "DNA Replication"
    title_prefix_values["10.7554/eLife.24106"] = "Germ Granules"
    title_prefix_values["10.7554/eLife.24238"] = "Tumor Angiogenesis"
    title_prefix_values["10.7554/eLife.24276"] = "Stem Cells"
    title_prefix_values["10.7554/eLife.24611"] = "Point of View"
    title_prefix_values["10.7554/eLife.24896"] = "Visual Behavior"
    title_prefix_values["10.7554/eLife.25000"] = "Chromatin Mapping"
    title_prefix_values["10.7554/eLife.25001"] = "Cell Cycle"
    title_prefix_values["10.7554/eLife.25159"] = "Ion Channels"
    title_prefix_values["10.7554/eLife.25358"] = "Cell Division"
    title_prefix_values["10.7554/eLife.25375"] = "Membrane Phase Separation"
    title_prefix_values["10.7554/eLife.25408"] = "Plain-language Summaries of Research"
    title_prefix_values["10.7554/eLife.25410"] = "Plain-language Summaries of Research"
    title_prefix_values["10.7554/eLife.25411"] = "Plain-language Summaries of Research"
    title_prefix_values["10.7554/eLife.25412"] = "Plain-language Summaries of Research"
    title_prefix_values["10.7554/eLife.25431"] = "Genetic Diversity"
    title_prefix_values["10.7554/eLife.25654"] = "Systems Biology"
    title_prefix_values["10.7554/eLife.25669"] = "Paternal Effects"
    title_prefix_values["10.7554/eLife.25700"] = "TOR Signaling"
    title_prefix_values["10.7554/eLife.25835"] = "Cutting Edge"
    title_prefix_values["10.7554/eLife.25858"] = "Developmental Biology"
    title_prefix_values["10.7554/eLife.25956"] = "Point of View"
    title_prefix_values["10.7554/eLife.25996"] = "Cancer Therapeutics"
    title_prefix_values["10.7554/eLife.26295"] = "Point of View"
    title_prefix_values["10.7554/eLife.26401"] = "Object Recognition"
    title_prefix_values["10.7554/eLife.26775"] = "Human Evolution"
    title_prefix_values["10.7554/eLife.26787"] = "Cutting Edge"
    title_prefix_values["10.7554/eLife.26942"] = "Alzheimer’s Disease"
    title_prefix_values["10.7554/eLife.27085"] = "Translational Control"
    title_prefix_values["10.7554/eLife.27198"] = "Cell Signaling"
    title_prefix_values["10.7554/eLife.27438"] = "Point of View"
    title_prefix_values["10.7554/eLife.27467"] = "Evolutionary Developmental Biology"
    title_prefix_values["10.7554/eLife.27605"] = "Population Genetics"
    title_prefix_values["10.7554/eLife.27933"] = "Ion Channels"
    title_prefix_values["10.7554/eLife.27982"] = "Living Science"
    title_prefix_values["10.7554/eLife.28339"] = "Oncogene Regulation"
    title_prefix_values["10.7554/eLife.28514"] = "Maternal Behavior"
    title_prefix_values["10.7554/eLife.28699"] = "Point of View"
    title_prefix_values["10.7554/eLife.28757"] = "Mitochondrial Homeostasis"
    title_prefix_values["10.7554/eLife.29056"] = "Gene Variation"
    title_prefix_values["10.7554/eLife.29104"] = "Cardiac Hypertrophy"
    title_prefix_values["10.7554/eLife.29502"] = "Meiotic Recombination"
    title_prefix_values["10.7554/eLife.29586"] = "Virus Evolution"
    title_prefix_values["10.7554/eLife.29942"] = "Post-translational Modifications"
    title_prefix_values["10.7554/eLife.30076"] = "Scientific Publishing"
    title_prefix_values["10.7554/eLife.30183"] = "Point of View"
    title_prefix_values["10.7554/eLife.30194"] = "Organ Development"
    title_prefix_values["10.7554/eLife.30249"] = "Tissue Regeneration"
    title_prefix_values["10.7554/eLife.30280"] = "Adverse Drug Reactions"
    title_prefix_values["10.7554/eLife.30599"] = "Living Science"
    title_prefix_values["10.7554/eLife.30865"] = "Stone Tool Use"
    title_prefix_values["10.7554/eLife.31106"] = "Sensory Neurons"
    title_prefix_values["10.7554/eLife.31328"] = "Drought Stress"
    title_prefix_values["10.7554/eLife.31697"] = "Scientific Publishing"
    title_prefix_values["10.7554/eLife.31808"] = "Tissue Engineering"
    title_prefix_values["10.7554/eLife.31816"] = "Sound Processing"
    title_prefix_values["10.7554/eLife.32011"] = "Peer Review"
    title_prefix_values["10.7554/eLife.32012"] = "Peer Review"
    title_prefix_values["10.7554/eLife.32014"] = "Peer Review"
    title_prefix_values["10.7554/eLife.32015"] = "Peer Review"
    title_prefix_values["10.7554/eLife.32016"] = "Peer Review"
    title_prefix_values["10.7554/eLife.32715"] = "Point of View"

    # Edge case fix title prefix values
    if doi in title_prefix_values:
        # Do a quick sanity check, only replace if the lowercase comparison is equal
        #  just in case the value has been changed to something else we will not replace it
        if json_content.lower() == title_prefix_values[doi].lower():
            json_content = title_prefix_values[doi]

    return json_content

Response: this function rewrites the elife title prefix json values in the article DOI to match the original article DOI.


Instruction:
Explain what the following Python 3 code does
def metadata_lint(old, new, locations):
    # ensure we don't modify the metadata
    old = old.copy()
    new = new.copy()
    # remove version info
    old.pop('$version', None)
    new.pop('$version', None)

    for old_group_name in old:
        if old_group_name not in new:
            yield LintError('', 'api group removed', api_name=old_group_name)

    for group_name, new_group in new.items():
        old_group = old.get(group_name, {'apis': {}})

        for name, api in new_group['apis'].items():
            old_api = old_group['apis'].get(name, {})
            api_locations = locations[name]
            for message in lint_api(name, old_api, api, api_locations):
                message.api_name = name
                if message.location is None:
                    message.location = api_locations['api']
                yield message

Response: Run the linter over the new metadata comparing to the old.


Instruction:
Can you write a function in Python 3 where it
lints an acceptable api metadata.

Response:
def lint_api(api_name, old, new, locations):
    """Lint an acceptable api metadata."""
    is_new_api = not old
    api_location = locations['api']
    changelog = new.get('changelog', {})
    changelog_location = api_location

    if locations['changelog']:
        changelog_location = list(locations['changelog'].values())[0]

    # apis must have documentation if they are new
    if not new.get('doc'):
        msg_type = LintError if is_new_api else LintWarning
        yield msg_type(
            'doc',
            'missing docstring documentation',
            api_name=api_name,
            location=locations.get('view', api_location)
        )

    introduced_at = new.get('introduced_at')
    if introduced_at is None:
        yield LintError(
            'introduced_at',
            'missing introduced_at field',
            location=api_location,
        )

    if not is_new_api:
        # cannot change introduced_at if we already have it
        old_introduced_at = old.get('introduced_at')
        if old_introduced_at is not None:
            if old_introduced_at != introduced_at:
                yield LintError(
                    'introduced_at',
                    'introduced_at changed from {} to {}',
                    old_introduced_at,
                    introduced_at,
                    api_name=api_name,
                    location=api_location,
                )

    # cannot change url
    if new['url'] != old.get('url', new['url']):
        yield LintError(
            'url',
            'url changed from {} to {}',
            old['url'],
            new['url'],
            api_name=api_name,
            location=api_location,
        )

    # cannot add required fields
    for removed in set(old.get('methods', [])) - set(new['methods']):
        yield LintError(
            'methods',
            'HTTP method {} removed',
            removed,
            api_name=api_name,
            location=api_location,
        )

    for schema in ['request_schema', 'response_schema']:
        new_schema = new.get(schema)
        if new_schema is None:
            continue

        schema_location = locations[schema]
        old_schema = old.get(schema, {})

        for message in walk_schema(
                schema, old_schema, new_schema, root=True, new_api=is_new_api):
            if isinstance(message, CheckChangelog):
                if message.revision not in changelog:
                    yield LintFixit(
                        message.name,
                        'No changelog entry for revision {}',
                        message.revision,
                        location=changelog_location,
                    )
            else:
                # add in here, saves passing it down the recursive call
                message.location = schema_location
                yield message


Instruction:
How would you code a function in Python 3 to
bind the service API urls to a flask app.

Response:
def bind(self, flask_app, service, group=None):
        """Bind the service API urls to a flask app."""
        if group not in self.services[service]:
            raise RuntimeError(
                'API group {} does not exist in service {}'.format(
                    group, service)
            )
        for name, api in self.services[service][group].items():
            # only bind APIs that have views associated with them
            if api.view_fn is None:
                continue
            if name not in flask_app.view_functions:
                flask_app.add_url_rule(
                    api.url, name, view_func=api.view_fn, **api.options)


Instruction:
Write a Python 3 function that can
serialize into JSONable dict and associated locations data.

Response:
def serialize(self):
        """Serialize into JSONable dict, and associated locations data."""
        api_metadata = OrderedDict()
        # $ char makes this come first in sort ordering
        api_metadata['$version'] = self.current_version
        locations = {}

        for svc_name, group in self.groups():
            group_apis = OrderedDict()
            group_metadata = OrderedDict()
            group_metadata['apis'] = group_apis
            group_metadata['title'] = group.title
            api_metadata[group.name] = group_metadata

            if group.docs is not None:
                group_metadata['docs'] = group.docs

            for name, api in group.items():
                group_apis[name] = OrderedDict()
                group_apis[name]['service'] = svc_name
                group_apis[name]['api_group'] = group.name
                group_apis[name]['api_name'] = api.name
                group_apis[name]['introduced_at'] = api.introduced_at
                group_apis[name]['methods'] = api.methods
                group_apis[name]['request_schema'] = api.request_schema
                group_apis[name]['response_schema'] = api.response_schema
                group_apis[name]['doc'] = api.docs
                group_apis[name]['changelog'] = api._changelog
                if api.title:
                    group_apis[name]['title'] = api.title
                else:
                    title = name.replace('-', ' ').replace('_', ' ').title()
                    group_apis[name]['title'] = title

                group_apis[name]['url'] = api.resolve_url()

                if api.undocumented:
                    group_apis[name]['undocumented'] = True
                if api.deprecated_at is not None:
                    group_apis[name]['deprecated_at'] = api.deprecated_at

                locations[name] = {
                    'api': api.location,
                    'request_schema': api._request_schema_location,
                    'response_schema': api._response_schema_location,
                    'changelog': api._changelog_locations,
                    'view': api.view_fn_location,
                }

        return api_metadata, locations


Instruction:
Implement a function in Python 3 to
add an AcceptableAPI to the service.

Response:
def api(self,
            url,
            name,
            introduced_at=None,
            undocumented=False,
            deprecated_at=None,
            title=None,
            **options):
        """Add an API to the service.

        :param url: This is the url that the API should be registered at.
        :param name: This is the name of the api, and will be registered with
            flask apps under.

        Other keyword arguments may be used, and they will be passed to the
        flask application when initialised. Of particular interest is the
        'methods' keyword argument, which can be used to specify the HTTP
        method the URL will be added for.
        """
        location = get_callsite_location()
        api = AcceptableAPI(
            self,
            name,
            url,
            introduced_at,
            options,
            undocumented=undocumented,
            deprecated_at=deprecated_at,
            title=title,
            location=location,
        )
        self.metadata.register_api(self.name, self.group, api)
        return api


Instruction:
How would you code a function in Python 3 to
add a django API handler to the service.

Response:
def django_api(
            self,
            name,
            introduced_at,
            undocumented=False,
            deprecated_at=None,
            title=None,
            **options):
        """Add a django API handler to the service.

        :param name: This is the name of the django url to use.

        The 'methods' paramater can be supplied as normal, you can also user
        the @api.handler decorator to link this API to its handler.

        """
        from acceptable.djangoutil import DjangoAPI
        location = get_callsite_location()
        api = DjangoAPI(
            self,
            name,
            introduced_at,
            options,
            location=location,
            undocumented=undocumented,
            deprecated_at=deprecated_at,
            title=title,
        )
        self.metadata.register_api(self.name, self.group, api)
        return api


Instruction:
Create a Python 3 function to
bind the service API urls to a flask app.

Response:
def bind(self, flask_app):
        """Bind the service API urls to a flask app."""
        self.metadata.bind(flask_app, self.name, self.group)


Instruction:
Can you tell what is the following Python 3 function doing
def changelog(self, api_version, doc):
        doc = textwrap.dedent(doc).strip()
        self._changelog[api_version] = doc
        self._changelog_locations[api_version] = get_callsite_location()

Response: Add a changelog entry for this api.


Instruction:
Explain what the following Python 3 code does
def title_prefix(soup):
    "titlePrefix for article JSON is only articles with certain display_channel values"
    prefix = None
    display_channel_match_list = ['feature article', 'insight', 'editorial']
    for d_channel in display_channel(soup):
        if d_channel.lower() in display_channel_match_list:
            if raw_parser.sub_display_channel(soup):
                prefix = node_text(first(raw_parser.sub_display_channel(soup)))
    return prefix

Response: titlePrefix for article JSON is only articles with certain display_channel values


Instruction:
Can you generate a brief explanation for the following Python 3 code
def title_prefix_json(soup):
    "titlePrefix with capitalisation changed"
    prefix = title_prefix(soup)
    prefix_rewritten = elifetools.json_rewrite.rewrite_json("title_prefix_json", soup, prefix)
    return prefix_rewritten

Response: titlePrefix with capitalisation changed


Instruction:
Can you generate a brief explanation for the following Python 3 code
def research_organism(soup):
    "Find the research-organism from the set of kwd-group tags"
    if not raw_parser.research_organism_keywords(soup):
        return []
    return list(map(node_text, raw_parser.research_organism_keywords(soup)))

Response: Find the research - organism from the set of kwd - group tags


Instruction:
Implement a function in Python 3 to
full research - organism list including inline tags such as italic

Response:
def full_research_organism(soup):
    "research-organism list including inline tags, such as italic"
    if not raw_parser.research_organism_keywords(soup):
        return []
    return list(map(node_contents_str, raw_parser.research_organism_keywords(soup)))


Instruction:
Can you generate a brief explanation for the following Python 3 code
def keywords(soup):
    if not raw_parser.author_keywords(soup):
        return []
    return list(map(node_text, raw_parser.author_keywords(soup)))

Response: Return a list of keywords from the set of keywords that are typically labeled as the author keywords.


Instruction:
Create a Python 3 function to
author keywords list including inline tags such as italic

Response:
def full_keywords(soup):
    "author keywords list including inline tags, such as italic"
    if not raw_parser.author_keywords(soup):
        return []
    return list(map(node_contents_str, raw_parser.author_keywords(soup)))


Instruction:
Here you have a function in Python 3, explain what it does
def version_history(soup, html_flag=True):
    "extract the article version history details"
    convert = lambda xml_string: xml_to_html(html_flag, xml_string)
    version_history = []
    related_object_tags = raw_parser.related_object(raw_parser.article_meta(soup))
    for tag in related_object_tags:
        article_version = OrderedDict()
        date_tag = first(raw_parser.date(tag))
        if date_tag:
            copy_attribute(date_tag.attrs, 'date-type', article_version, 'version')
            (day, month, year) = ymd(date_tag)
            article_version['day'] = day
            article_version['month'] = month
            article_version['year'] = year
            article_version['date'] = date_struct_nn(year, month, day)
        copy_attribute(tag.attrs, 'xlink:href', article_version, 'xlink_href')
        set_if_value(article_version, "comment",
                     convert(node_contents_str(first(raw_parser.comment(tag)))))
        version_history.append(article_version)
    return version_history

Response: extract the article version history details


Instruction:
Create a Python 3 function for
returning a list of article - id data

Response:
def article_id_list(soup):
    """return a list of article-id data"""
    id_list = []
    for article_id_tag in raw_parser.article_id(soup):
        id_details = OrderedDict()
        set_if_value(id_details, "type", article_id_tag.get("pub-id-type"))
        set_if_value(id_details, "value", article_id_tag.text)
        set_if_value(id_details, "assigning-authority", article_id_tag.get("assigning-authority"))
        id_list.append(id_details)
    return id_list


Instruction:
Here you have a function in Python 3, explain what it does
def copyright_holder_json(soup):
    "for json output add a full stop if ends in et al"
    holder = None
    permissions_tag = raw_parser.article_permissions(soup)
    if permissions_tag:
        holder = node_text(raw_parser.copyright_holder(permissions_tag))
    if holder is not None and holder.endswith('et al'):
        holder = holder + '.'
    return holder

Response: for json output add a full stop if ends in et al


Instruction:
Write a Python 3 script to
find the subject areas from article - categories subject tags

Response:
def subject_area(soup):
    """
    Find the subject areas from article-categories subject tags
    """
    subject_area = []

    tags = raw_parser.subject_area(soup)
    for tag in tags:
        subject_area.append(node_text(tag))

    return subject_area


Instruction:
Explain what the following Python 3 code does
def display_channel(soup):
    display_channel = []

    tags = raw_parser.display_channel(soup)
    for tag in tags:
        display_channel.append(node_text(tag))

    return display_channel

Response: Find the subject areas of type display - channel


Instruction:
Can you write a function in Python 3 where it
finds the category from subject areas

Response:
def category(soup):
    """
    Find the category from subject areas
    """
    category = []

    tags = raw_parser.category(soup)
    for tag in tags:
        category.append(node_text(tag))

    return category


Instruction:
Can you generate a brief explanation for the following Python 3 code
def ymd(soup):
    day = node_text(raw_parser.day(soup))
    month = node_text(raw_parser.month(soup))
    year = node_text(raw_parser.year(soup))
    return (day, month, year)

Response: Get the year month and day from child tags


Instruction:
Can you generate the documentation for the following Python 3 function
def pub_date(soup):
    pub_date = first(raw_parser.pub_date(soup, date_type="pub"))
    if pub_date is None:
        pub_date = first(raw_parser.pub_date(soup, date_type="publication"))
    if pub_date is None:
        return None
    (day, month, year) = ymd(pub_date)
    return date_struct(year, month, day)

Response: Return the publication date in struct format