<jupyter_start><jupyter_text>Introduction The DCC has mentioned I have a bunch of biosamples where we forgot to add the NIC.<jupyter_code>import pandas
import sys
import os
import base64
from io import BytesIO
from matplotlib import pyplot
from pathlib import Path
from IPython.display import HTML
EC = str(Path("~/proj/encoded_client").expanduser())
if EC not in sys.path:
    sys.path.append(EC)
from encoded_client.encoded import ENCODED, get_object_type
server = ENCODED("www.encodeproject.org")
server.load_netrc()
search = "https://www.encodeproject.org/search/?type=Experiment&lab.title=Barbara+Wold%2C+Caltech&lab.title=Ali+Mortazavi%2C+UCI&lab.title=Rob+Spitale%2C+UCI&audit.ERROR.category=missing+nih_institutional_certification&assay_title!=microRNA-seq"
graph = server.get_json(search)
print(len(graph["@graph"]))
graph["@graph"][0]
biosample_nic = pandas.read_csv("biosample_nic.csv", index_col="ontology")
biosample_nic
lookup = set()
patches = []
not_by_me = []
for row in graph["@graph"]:
    for replicate in row["replicates"]:        
        biosample_accession = replicate["library"]["biosample"]["accession"]
        biosample = server.get_json(biosample_accession)
        ontology_id = biosample['biosample_ontology']["@id"]
        ontology_term = biosample['biosample_ontology']["term_name"]
        if ontology_id == '/biosample-types/tissue_UBERON_0006483/':
            continue
        try:
            nic = biosample_nic.loc[ontology_id, 'nic']
        except KeyError:
            lookup.add((ontology_id, ontology_term))
            nic = None

        print(biosample_accession, ontology_id, ontology_term, nic, biosample.get("nih_institutional_certification"))
        if biosample.get("nih_institutional_certification") is None and nic is not None:
            if biosample['submitted_by']['@id'] == '/users/bc5b62f7-ce28-4a1e-b6b3-81c9c5a86d7a/' and biosample['status'] == 'in progress':
                patches.append(server.patch_json(biosample["@id"], {"nih_institutional_certification": nic}))
            else:
                not_by_me.append((biosample_accession, biosample['submitted_by']['title'], ontology_id, biosample['status'], nic))
sorted(lookup)
biosample['status']
couldnt_update = pandas.DataFrame(not_by_me, columns=['biosample', 'submitter', 'ontology_id', 'status', 'nic']).set_index('biosample')
couldnt_update
couldnt_update.to_csv('/dev/shm/couldnt_update.csv')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13091353996737357, 'fraction_numerical': 0.012234910277324634, 'mean_word_length': 5.012254901960785, 'pattern_counts': {'":': 1, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '457649', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 852, 'n_tokens_neox': 826, 'n_words': 142, 'path': 'fix-nics.ipynb', 'repo_name': 'detrout/encode4-curation', 'size': '2452'}