Commit e04a83d5 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Add nematode_mammal

parent 6976ef41
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2020 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 *
title = "Global nematode–mammal interactions (2018)"
description = """A global interaction web of interactions between nematodes and their host mammal species, extracted from the helminthR package and dataset. Nodes are annotated with species-level information.[^icon]
[^icon]: Description obtained from the [ICON](https://icon.colorado.edu) project."""
tags = ['Biological', 'Food web', 'Unweighted', 'Metadata']
url = 'https://github.com/cjcarlson/brevity/tree/master/Figure%201%20Demo%20Networks'
citation = [('T. Dallas et al. "Gauging support for macroecological patterns in helminth parasites." Glob. Ecol. Biogeogr. 27, 1437–1447 (2018)', 'https://onlinelibrary.wiley.com/doi/full/10.1111/geb.12819')]
icon_hash = '5d0d28f751da6551647736a8'
ustream_license = None
upstream_prefix = 'https://raw.githubusercontent.com/cjcarlson/brevity/master/Figure%201%20Demo%20Networks'
files = [('helminths.csv', None, 'csv')]
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]
for fnames, alt, fmt in files:
if alts is not None and alt not in alts:
continue
if isinstance(fnames, str):
fnames = [fnames]
with ExitStack() as stack:
fs = [stack.enter_context(open_upstream_file(name, fn, "r", encoding="ISO-8859-1")) for fn in fnames]
g = Graph(directed=False)
g.vp.name = g.new_vp("string")
g.vp.full_name = g.new_vp("string")
g.vp.locality = g.new_vp("string")
g.vp.group = g.new_vp("string")
g.vp.is_host = g.new_vp("bool")
hs = {}
ps = {}
reader = csv.reader(fs[0])
next(reader)
for row in reader:
s = hs.get(row[1], None)
if s is None:
s = hs[row[1]] = g.add_vertex()
g.vp.name[s] = row[1]
t = ps.get(row[2], None)
if t is None:
t = ps[row[2]] = g.add_vertex()
g.vp.name[t] = row[2]
g.add_edge(s, t)
g.vp.is_host[s] = True
g.vp.full_name[s] = row[3]
g.vp.group[s] = row[4]
g.vp.locality[s] = row[5]
g.vp.group[t] = row[6]
yield alt, g
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment