History of ndc_drugs
The changes to the source code of this entry in the repository, newest first, each with the differences it made to the entry's files. They are also listed on GitLab.
[entries] Add the date when each entry was added, and remove icon_hash beff7c9
The dates are those of the commits that first added the entries' files (2020-08-11 for the entries of the initial commit); renamed entries keep the date of their first name. Changed: none
diff --git a/entries/ndc_drugs/__init__.py b/entries/ndc_drugs/__init__.py
index 4b6379b..399359d 100644
--- a/entries/ndc_drugs/__init__.py
+++ b/entries/ndc_drugs/__init__.py
@@ -37,7 +37,7 @@ tags = ['Public Health', 'Chemical', 'Unweighted', 'Timestamps', 'Metadata']
url = ['https://www.cs.cornell.edu/~arb/data/NDC-classes/',
'https://www.cs.cornell.edu/~arb/data/NDC-substances/']
citation = [('A. R. Benson, R. Abebe, M. T. Schaub, A. Jadbabaie, J. Kleinberg, "Simplicial closure and higher-order link prediction." Proceedings of the National Academy of Sciences 115(48), E11221-E11230 (2018)', 'https://doi.org/10.1073/pnas.1800683115')]
-icon_hash = None
+date_added = '2026-10-25'
upstream_license = None
upstream_prefix = 'gdrive://'
_files = {"classes": '1JXgPCwJw5VtjNV7xCWYnk2Z3OjhzdrxO:tar.gz:NDC-classes-full/NDC-classes-full',
[entries] Prefix the properties in the descriptions with (Node), (Edge) or (Graph) bc3dbbd
The lists of properties at the end of the descriptions marked edge properties with "Edge" but left node properties unmarked, or grouped them in "Nodes: `a`, ...; `b`, ..." items, so the kind of a property was often unclear. Every item now starts with (Node), (Edge) or (Graph), followed by the property names, a colon and the explanation, one item per property or group of properties; qualifications (kinds of nodes, networks) follow the names in parentheses. Properties that were only named got a short explanation, and a few items that named the wrong kind of property were corrected.
diff --git a/entries/ndc_drugs/__init__.py b/entries/ndc_drugs/__init__.py
index ed667f9..4b6379b 100644
--- a/entries/ndc_drugs/__init__.py
+++ b/entries/ndc_drugs/__init__.py
@@ -28,10 +28,11 @@ description = """Bipartite networks of drug products and their pharmaceutical cl
The networks have the following properties:
-- `is_drug`: whether the node is a drug (NDC product code), otherwise a class (`classes`) or a substance (`substances`).
-- Drug nodes: `name`, the name of the drug (empty for a few products whose name is missing in the source data); `ndc_code`, the NDC product code, as "labeler-product"; `time`, the date when the drug started being marketed, in days since 1970-01-01 (negative before 1970; the earliest date is 1900-01-01; only meaningful for drug nodes).
-- Class and substance nodes: `name`, the name of the class or substance.
-- `classes` only: `class_type`, the kind of pharmaceutical class, as given in the source: `epc` (established pharmacologic class), `moa` (mechanism of action), `pe` (physiologic effect), or `chemical/ingredient` (chemical structure). A few class names that contain a comma in the directory were split into two nodes in the source data (e.g. "antibodies" and "monoclonal [chemical/ingredient]"); for these the first part has an empty `class_type`."""
+- (Node) `is_drug`: whether the node is a drug (NDC product code), otherwise a class (`classes`) or a substance (`substances`).
+- (Node) `name`: the name of the drug (empty for a few products whose name is missing in the source data), or of the class or substance.
+- (Node) `ndc_code` (drugs): the NDC product code, as "labeler-product".
+- (Node) `time` (drugs): the date when the drug started being marketed, in days since 1970-01-01 (negative before 1970; the earliest date is 1900-01-01; only meaningful for drug nodes).
+- (Node) `class_type` (`classes` only): the kind of pharmaceutical class, as given in the source: `epc` (established pharmacologic class), `moa` (mechanism of action), `pe` (physiologic effect), or `chemical/ingredient` (chemical structure). A few class names that contain a comma in the directory were split into two nodes in the source data (e.g. "antibodies" and "monoclonal [chemical/ingredient]"); for these the first part has an empty `class_type`."""
tags = ['Public Health', 'Chemical', 'Unweighted', 'Timestamps', 'Metadata']
url = ['https://www.cs.cornell.edu/~arb/data/NDC-classes/',
'https://www.cs.cornell.edu/~arb/data/NDC-substances/']
[entries] Remove unneeded code from the entries 2c69f19
Unneeded "global files" statements, unused imports and variables, f-strings without placeholders, duplicate keys in foodweb_little_rock (keeping the order and the values used), and the second definition of get_lines() in twitter_higgs. Nothing changes in the networks or descriptions. Changed: none
diff --git a/entries/ndc_drugs/__init__.py b/entries/ndc_drugs/__init__.py
index 4e6374a..ed667f9 100644
--- a/entries/ndc_drugs/__init__.py
+++ b/entries/ndc_drugs/__init__.py
@@ -53,7 +53,6 @@ def fetch_upstream(force=False):
@coerce_props()
@annotate()
def parse(alts=None):
- global files
name = __name__.split(".")[-1]
epoch = date(1970, 1, 1).toordinal()
for fnames, alt, fmt in files:
[entries] New entry: ndc_drugs 568ec6a
diff --git a/entries/ndc_drugs/__init__.py b/entries/ndc_drugs/__init__.py
new file mode 100644
index 0000000..4e6374a
--- /dev/null
+++ b/entries/ndc_drugs/__init__.py
@@ -0,0 +1,97 @@
+#! /usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2020-2026 Tiago de Paula Peixoto <tiago@skewed.de>
+#
+# This program is free software: you can redistribute it and/or modify it under
+# the terms of the GNU Affero General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option) any
+# later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Affero General Public License along
+# with this program. If not, see <http://www.gnu.org/licenses/>.
+
+from .. import *
+import re
+from datetime import date
+
+title = "FDA National Drug Code directory (2017)"
+description = """Bipartite networks of drug products and their pharmaceutical classes or active substances, from the National Drug Code (NDC) Directory. Under the Drug Listing Act of 1972, firms must list with the US Food and Drug Administration (FDA) the drugs they manufacture or distribute commercially, and the FDA publishes this information as the NDC Directory, where each product is identified by an NDC product code (labeler code and product code). The data correspond to a version of the directory obtained around 2017 (the latest marketing date is 2017-09-21). Each drug node is one NDC product code, so the same drug substance can appear in several nodes (e.g. different dosages, forms or manufacturers), and is annotated with the date when the product started being marketed. All products in the directory are included (no size restriction). Names are lower-cased.
+
+- `classes`: each drug is connected to the pharmaceutical classes the FDA assigned to it.
+- `substances`: each drug is connected to the substances (ingredients) it is made of.
+
+The networks have the following properties:
+
+- `is_drug`: whether the node is a drug (NDC product code), otherwise a class (`classes`) or a substance (`substances`).
+- Drug nodes: `name`, the name of the drug (empty for a few products whose name is missing in the source data); `ndc_code`, the NDC product code, as "labeler-product"; `time`, the date when the drug started being marketed, in days since 1970-01-01 (negative before 1970; the earliest date is 1900-01-01; only meaningful for drug nodes).
+- Class and substance nodes: `name`, the name of the class or substance.
+- `classes` only: `class_type`, the kind of pharmaceutical class, as given in the source: `epc` (established pharmacologic class), `moa` (mechanism of action), `pe` (physiologic effect), or `chemical/ingredient` (chemical structure). A few class names that contain a comma in the directory were split into two nodes in the source data (e.g. "antibodies" and "monoclonal [chemical/ingredient]"); for these the first part has an empty `class_type`."""
+tags = ['Public Health', 'Chemical', 'Unweighted', 'Timestamps', 'Metadata']
+url = ['https://www.cs.cornell.edu/~arb/data/NDC-classes/',
+ 'https://www.cs.cornell.edu/~arb/data/NDC-substances/']
+citation = [('A. R. Benson, R. Abebe, M. T. Schaub, A. Jadbabaie, J. Kleinberg, "Simplicial closure and higher-order link prediction." Proceedings of the National Academy of Sciences 115(48), E11221-E11230 (2018)', 'https://doi.org/10.1073/pnas.1800683115')]
+icon_hash = None
+upstream_license = None
+upstream_prefix = 'gdrive://'
+_files = {"classes": '1JXgPCwJw5VtjNV7xCWYnk2Z3OjhzdrxO:tar.gz:NDC-classes-full/NDC-classes-full',
+ "substances": '1dLJt3qzAOYieay03Sp9h8ZfVMiU-nMqC:tar.gz:NDC-substances-full/NDC-substances-full'}
+files = [(tuple(f"{p}-{x}.txt" for x in ["nverts", "simplices", "times",
+ "node-labels", "simplex-labels"]),
+ alt, None) for alt, p in _files.items()]
+
+def fetch_upstream(force=False):
+ return fetch_upstream_files(__name__.split(".")[-1], upstream_prefix, files,
+ force)
+
+@cache_network()
+@coerce_props()
+@annotate()
+def parse(alts=None):
+ global files
+ name = __name__.split(".")[-1]
+ epoch = date(1970, 1, 1).toordinal()
+ for fnames, alt, fmt in files:
+ if alts is not None and alt not in alts:
+ continue
+ with ExitStack() as stack:
+ fs = [stack.enter_context(open_upstream_file(name, fn, "r")) for fn in fnames]
+ groups, members = read_simplices(fs[0], fs[1])
+ # Julia DateTime values: milliseconds, with 0001-01-01 as day 1
+ times = read_ints(fs[2]) // 86400000 - epoch
+ labels = {}
+ for line in fs[3]:
+ vid, lname = line.rstrip("\n").split(" ", 1)
+ labels[int(vid) - 1] = lname
+ # "<drug name> (<ndc code>)"
+ dnames = []
+ codes = []
+ for line in fs[4]:
+ dname, code = line.rstrip("\n").rsplit("(", 1)
+ dnames.append(dname.strip())
+ codes.append(code.rstrip(")"))
+ assert len(dnames) == len(times)
+ N = max(max(labels) + 1, members.max() + 1)
+ g = bipartite_graph(groups, members, len(times), N, "is_drug")
+ g.vp.name = g.new_vp("string")
+ if alt == "classes":
+ g.vp.class_type = g.new_vp("string")
+ for v, lname in labels.items():
+ if alt == "classes":
+ m = re.fullmatch(r"(.*) \[([^]]*)\]", lname)
+ if m is not None:
+ lname, ctype = m.groups()
+ g.vp.class_type[v] = ctype
+ g.vp.name[v] = lname
+ g.vp.ndc_code = g.new_vp("string")
+ for i, (dname, code) in enumerate(zip(dnames, codes)):
+ g.vp.name[N + i] = dname
+ g.vp.ndc_code[N + i] = code
+ g.vp.time = g.new_vp("int")
+ g.vp.time.a[N:] = times
+ yield alt, g