python_code
stringlengths
0
4.04M
repo_name
stringlengths
7
58
file_path
stringlengths
5
147
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import tempfile import crypten import crypten.communicator as comm import torch import torch.nn as nn import torch.nn...
CrypTen-main
examples/mpc_autograd_cnn/mpc_autograd_cnn.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. """ To run mpc_autograd_cnn example: $ python examples/mpc_autograd_cnn/launcher.py To run mpc_linear_svm example on ...
CrypTen-main
examples/mpc_autograd_cnn/launcher.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. """ Generate function and model benchmarks To Run: $ python benchmark.py # Only function benchmarks $ python benchmar...
CrypTen-main
benchmarks/benchmark.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. """ Contains models used for benchmarking """ from dataclasses import dataclass from typing import Any import crypte...
CrypTen-main
benchmarks/models.py
CrypTen-main
benchmarks/__init__.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. """ A script to run historical benchmarks. - writes monthly data to 'dash_app/data/` - example: 'dash_app/data/201...
CrypTen-main
benchmarks/run_historical_benchmarks.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. """ Profiler with snakeviz for probing inference / training call stack Run via Jupyter """ from benchmark import Mod...
CrypTen-main
benchmarks/profiler.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. """ Contains data used for training / testing model benchmarks """ import os from pathlib import Path import crypten ...
CrypTen-main
benchmarks/data.py
CrypTen-main
benchmarks/dash_app/__init__.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import pathlib import dash import dash_core_components as dcc import dash_html_components as html import numpy as np ...
CrypTen-main
benchmarks/dash_app/app.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import os import pandas as pd def get_aggregated_data(base_dir, subdirs): """Aggregate dataframe for model and...
CrypTen-main
benchmarks/dash_app/load_data.py
CrypTen-main
configs/__init__.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import os import subprocess import uuid from argparse import ArgumentParser, REMAINDER """ Wrapper to launch MPC scr...
CrypTen-main
scripts/distributed_launcher.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. """ This file is a tool to run MPC distributed training over AWS. To run distributed training, first multiple AWS inst...
CrypTen-main
scripts/aws_launcher.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import argparse import os import torch from torchvision import datasets, transforms def _get_norm_mnist(dir, reduce...
CrypTen-main
tutorials/mnist_utils.py
#! /usr/bin/env python import sys if len(sys.argv) != 4: print 'Wrong number of arguments' print 'USAGE: ./compute_stats_helper.py $label_tsvfile $prediction_tsvfile $confidence' exit(1) label_filename = sys.argv[1] pred_filename = sys.argv[2] confidence = float(sys.argv[3]) # read label filename label...
dd-genomics-master
results_log/compute_stats_helper.py
import ddext from ddext import SD def init(): ddext.input('doc_id', 'text') ddext.input('sent_id', 'int') ddext.input('words', 'text[]') ddext.input('lemmas', 'text[]') ddext.input('poses', 'text[]') ddext.input('ners', 'text[]') ddext.returns('doc_id', 'text') ddext.returns('sent_id', 'int') ddext...
dd-genomics-master
xapp/code/gene_mentions.py
import ddext from ddext import SD def init(): ddext.input('doc_id', 'text') ddext.input('sent_id', 'int') ddext.input('words', 'text[]') ddext.input('lemmas', 'text[]') ddext.input('poses', 'text[]') ddext.input('ners', 'text[]') ddext.returns('doc_id', 'text') ddext.returns('sent_id', 'int') ddext...
dd-genomics-master
xapp/code/pheno_mentions.py
import ddext def init(): ddext.input('doc_id', 'text') ddext.input('sent_id', 'int') ddext.input('words', 'text[]') ddext.input('lemmas', 'text[]') ddext.input('poses', 'text[]') ddext.input('ners', 'text[]') ddext.input('dep_paths', 'text[]') ddext.input('dep_parents', 'int[]') ddext.input('wordidxs...
dd-genomics-master
xapp/code/pair_features.py
import ddext from ddext import SD def init(): ddext.input('doc_id', 'text') ddext.input('sent_id_1', 'int') ddext.input('mention_id_1', 'text') ddext.input('wordidxs_1', 'int[]') ddext.input('words_1', 'text[]') ddext.input('entity_1', 'text') ddext.input('type_1', 'text') ddext.input('correct_1', 'bo...
dd-genomics-master
xapp/code/gene_pheno_pairs.py
import ddext def init(): ddext.input('doc_id', 'text') ddext.input('sent_id', 'int') ddext.input('words', 'text[]') ddext.input('lemmas', 'text[]') ddext.input('poses', 'text[]') ddext.input('ners', 'text[]') ddext.input('dep_paths', 'text[]') ddext.input('dep_parents', 'int[]') ddext.input('mention...
dd-genomics-master
xapp/code/mention_features.py
#!/usr/bin/env python import sys if len(sys.argv) != 2: print 'Wrong number of arguments' print 'USAGE: ./compute_stats_helper.py $label_tsvfile $prediction_tsvfile $confidence' exit(1) old_labels_fn = sys.argv[1] with open(old_labels_fn) as f: for i, line in enumerate(f): line = line.split(...
dd-genomics-master
labeling/convert_old_gp_labels.py
#!/usr/bin/env python import json import sys import os.path # get the labeling version number version = 0 # in case the file doesn't exist if os.path.exists('version_labeling'): with open('version_labeling') as f: for i, line in enumerate(f): if i == 0: version = line[0].strip() else: print 've...
dd-genomics-master
labeling/extract_gene_labels_from_json.py
#! /usr/bin/env python import json import sys import os.path # get the labeling version number version = 0 # in case the file doesn't exist if os.path.exists('version_labeling'): with open('version_labeling') as f: for i, line in enumerate(f): if i == 0: version = line[0].strip() else: print '...
dd-genomics-master
labeling/extract_genepheno_causation_labels_from_json.py
#!/usr/bin/env python import json import sys import os.path # get the labeling version number version = 0 # in case the file doesn't exist if os.path.exists('version_labeling'): with open('version_labeling') as f: for i, line in enumerate(f): if i == 0: version = line[0].strip() else: print 've...
dd-genomics-master
labeling/extract_pheno_labels_from_json.py
#!/usr/bin/env python import sys if len(sys.argv) != 2: print 'Wrong number of arguments' print 'USAGE: ./compute_stats_helper.py $label_tsvfile $prediction_tsvfile $confidence' exit(1) old_labels_fn = sys.argv[1] with open(old_labels_fn) as f: for i, line in enumerate(f): line = line.split(...
dd-genomics-master
labeling/convert_old_g_labels.py
#! /usr/bin/env python import json import sys import os.path # get the labeling version number version = 0 # in case the file doesn't exist if os.path.exists('version_labeling'): with open('version_labeling') as f: for i, line in enumerate(f): if i == 0: version = line[0].strip() else: print '...
dd-genomics-master
labeling/extract_genepheno_association_labels_from_json.py
#!/usr/bin/env python import extractor_util as util from collections import namedtuple import os import ddlib import config import sys import re parser = util.RowParser([ ('relation_id', 'text'), ('doc_id', 'text'), ('section_id', 'text'), ('sent_id', 'int'), ('gene_me...
dd-genomics-master
code/genepheno_extract_features.py
#!/usr/bin/env python import extractor_util as util from collections import namedtuple import os import sys import ddlib import config # This defines the Row object that we read in to the extractor parser = util.RowParser([ ('doc_id', 'text'), ('section_id', 'text'), ('sent_id', 'int'), ...
dd-genomics-master
code/variant_extract_features.py
import collections import extractor_util as util import data_util as dutil import dep_util as deps import random import re import sys # This defines the Row object that we read in to the extractor parser = util.RowParser([ ('relation_id', 'text'), ('doc_id', 'text'), ('section_id',...
dd-genomics-master
code/genepheno_supervision_util.py
# -*- coding: utf-8 -*- # CONFIG # The master configuration file for candidate extraction, distant supervision and feature # extraction hyperparameters / configurations import sys import copy if sys.version_info < (2, 7): assert False, "Need Python version 2.7 at least" BOOL_VALS = [('neg', False), ('pos', True)] ...
dd-genomics-master
code/config.py
#!/usr/bin/env python import extractor_util as util from collections import namedtuple import os import sys import ddlib parser = util.RowParser([ ('relation_id', 'text'), ('doc_id', 'text'), ('section_id', 'text'), ('sent_id', 'int'), ('genevar_mention_id', 'text'), ...
dd-genomics-master
code/variantpheno_extract_features.py
#!/usr/bin/env python # -*- coding: utf-8 -*- import collections import extractor_util as util import data_util as dutil import random import re import os import sys import string import config import dep_util as deps # This defines the Row object that we read in to the extractor parser = util.RowParser([ (...
dd-genomics-master
code/variant_extract_candidates.py
#!/usr/bin/env python import collections import extractor_util as util import re import sys CACHE = dict() # Cache results of disk I/O # This defines the Row object that we read in to the extractor parser = util.RowParser([ ('doc_id', 'text'), ('section_id', 'text'), ('sent_id', 'int')...
dd-genomics-master
code/sentences_input_ner_extraction.py
"""Miscellaneous shared tools for maniuplating data used in the UDFs""" from collections import defaultdict, namedtuple import extractor_util as util import os import re import sys APP_HOME = os.environ['GDD_HOME'] onto_path = lambda p : '%s/onto/%s' % (os.environ['GDD_HOME'], p) class Dag: """Class representing a...
dd-genomics-master
code/data_util.py
#!/usr/bin/env python from collections import namedtuple import extractor_util as util import os import sys import ddlib import re import config # This defines the Row object that we read in to the extractor parser = util.RowParser([ ('doc_id', 'text'), ('section_id', 'text'), ('sent_id',...
dd-genomics-master
code/non_gene_acronyms_extract_features.py
#!/usr/bin/env python '''Link abbreviations to their full names Based on A Simple Algorithm for Identifying Abbreviations Definitions in Biomedical Text A. Schwartz and M. Hearst Biocomputing, 2003, pp 451-462. # License: GNU General Public License, see http://www.clips.ua.ac.be/~vincent/scripts/LICENSE.txt ''' __a...
dd-genomics-master
code/abbreviations.py
#! /usr/bin/env python import collections import extractor_util as util import data_util as dutil import dep_util as deps import random import re import sys import config # This defines the Row object that we read in to the extractor parser = util.RowParser([ ('relation_id', 'text'), ('doc_id'...
dd-genomics-master
code/genepheno_extract_features2.py
#!/usr/bin/env python from collections import defaultdict, namedtuple import sys import re import os import random from itertools import chain import extractor_util as util import data_util as dutil import config # This defines the Row object that we read in to the extractor parser = util.RowParser([ ('doc...
dd-genomics-master
code/pheno_acronyms_to_mentions.py
#!/usr/bin/env python import collections import extractor_util as util import data_util as dutil import dep_util as deps import os import random import re import sys import config # This defines the Row object that we read in to the extractor parser = util.RowParser([ ('doc_id', 'text'), ('section...
dd-genomics-master
code/genepheno_extract_candidates.py
#!/usr/bin/env python import collections import os import sys import abbreviations import config import extractor_util as util import levenshtein CACHE = dict() # Cache results of disk I/O # This defines the Row object that we read in to the extractor parser = util.RowParser([ ('doc_id', 'text'), ...
dd-genomics-master
code/non_gene_acronyms_extract_candidates.py
#! /usr/bin/env python import collections import extractor_util as eutil import sys from dep_alignment.alignment_util import row_to_canonical_match_tree, DepParentsCycleException, OverlappingCandidatesException, RootException from dep_alignment.multi_dep_alignment import MultiDepAlignment import os import random impor...
dd-genomics-master
code/genepheno_sv_new.py
#! /usr/bin/env python import sys import config import genepheno_supervision_util as sv if __name__ == '__main__': sr = config.GENE_PHENO_CAUSATION['SR'] hf = config.GENE_PHENO_CAUSATION['HF'] sv.supervise(sr, hf, charite_allowed=True)
dd-genomics-master
code/genepheno_causation_supervision.py
#! /usr/bin/env python import sys import config import genepheno_supervision_util as sv if __name__ == '__main__': sr = config.GENE_PHENO_CAUSATION['SR'] hf = config.GENE_PHENO_CAUSATION['HF'] sv.supervise(sr, hf, charite_allowed=False)
dd-genomics-master
code/genepheno_causation_supervision_no_charite.py
#!/usr/bin/env python from collections import defaultdict, namedtuple import sys import re import os import random from itertools import chain import extractor_util as util import data_util as dutil import config onto_path = lambda p : '%s/onto/%s' % (os.environ['GDD_HOME'], p) # This defines the Row object that we r...
dd-genomics-master
code/pheno_extract_candidates.py
#!/usr/bin/env python import collections import extractor_util as util import data_util as dutil import random import re import os import sys import string import config import dep_util as deps CACHE = dict() # Cache results of disk I/O # This defines the Row object that we read in to the extractor parser = util.Ro...
dd-genomics-master
code/gene_extract_candidates.py
#!/usr/bin/env python import extractor_util as util import os import ddlib import config # This defines the Row object that we read in to the extractor parser = util.RowParser([ ('doc_id', 'text'), ('section_id', 'text'), ('sent_id', 'int'), ('words', 'text[]'), ('lemm...
dd-genomics-master
code/pheno_extract_features.py
#!/usr/bin/env python import collections import extractor_util as util import data_util as dutil import dep_util as deps import os import random import re import sys import config # This defines the Row object that we read in to the extractor parser = util.RowParser([ ('doc_id', 'text'), ('gene_se...
dd-genomics-master
code/genevariant_extract_candidates.py
#!/usr/bin/env python import collections import os import sys import abbreviations import config import extractor_util as util import levenshtein import data_util as dutil CACHE = dict() # Cache results of disk I/O # This defines the Row object that we read in to the extractor parser = util.RowParser([ (...
dd-genomics-master
code/pheno_mentions_remove_super_dag_phenos.py
#! /usr/bin/env python import config import sys if __name__ == "__main__": disallowed_phrases = config.PHENO['HF']['disallowed-phrases'] for line in sys.stdin: take = True for dp in disallowed_phrases: if dp in line.lower(): take = False break if take: sys.stdout.write(line...
dd-genomics-master
code/create_allowed_diseases_list.py
"""Miscellaneous shared tools for extractors.""" import os import re import sys import ddlib import traceback FIX_DEP_PARENTS = True def rgx_comp(strings=[], rgxs=[]): r = r'|'.join(re.escape(w) for w in strings) if len(rgxs) > 0: if len(strings) > 0: r += r'|' r += r'(' + r')|('.join(rgxs) + r')' ...
dd-genomics-master
code/extractor_util.py
''' Created on Aug 5, 2015 @author: jbirgmei ''' # from wikipedia. let's hope it works def levenshtein(s1, s2): if len(s1) < len(s2): return levenshtein(s2, s1) # len(s1) >= len(s2) if len(s2) == 0: return len(s1) previous_row = range(len(s2) + 1) for i, c1 in enumerate(s1): current_row = [i +...
dd-genomics-master
code/levenshtein.py
#! /usr/bin/env python from data_util import get_hpo_phenos, get_parents, read_hpo_dag, read_hpo_synonyms if __name__ == "__main__": hpo_dag = read_hpo_dag() names = read_hpo_synonyms(1) synonyms = read_hpo_synonyms() allowed_phenos = set(get_hpo_phenos(hpo_dag)) for hpo_id in allowed_phenos.copy(): par...
dd-genomics-master
code/create_allowed_phenos_list.py
from collections import defaultdict # TODO: handle negations (neg, advmod + neg word) specially! # See: http://nlp.stanford.edu/software/dependencies_manual.pdf MAX_PATH_LEN = 100 class DepPathDAG: def __init__(self, dep_parents, dep_paths, words, max_path_len=None, no_count_tags=('conj',), no_count_words=('_','*...
dd-genomics-master
code/dep_util.py
#! /usr/bin/env python import dep_util import extractor_util as util import sys # This defines the Row object that we read in to the extractor parser = util.RowParser([ ('doc_id', 'text'), ('section_id', 'text'), ('sent_id', 'text'), ('dep_parents', 'int[]'), ('dep_pa...
dd-genomics-master
code/test_nlp.py
#!/usr/bin/env python import collections import os import sys import abbreviations import config import extractor_util as util import levenshtein CACHE = dict() # Cache results of disk I/O # This defines the Row object that we read in to the extractor parser = util.RowParser([ ('doc_id', 'text'), ...
dd-genomics-master
code/pheno_acronyms_extract_candidates.py
#!/usr/bin/env python from collections import namedtuple import extractor_util as util import os import sys import ddlib import re import config # This defines the Row object that we read in to the extractor parser = util.RowParser([ ('doc_id', 'text'), ('section_id', 'text'), ('sent_id',...
dd-genomics-master
code/pheno_acronyms_extract_features.py
#!/usr/bin/env python from collections import namedtuple import extractor_util as util import ddlib import re # This defines the Row object that we read in to the extractor parser = util.RowParser([ ('doc_id', 'text'), ('section_id', 'text'), ('sent_id', 'int'), ('words', 'text[...
dd-genomics-master
code/gene_extract_features.py
#!/usr/bin/env python import collections import extractor_util as util import data_util as dutil import dep_util as deps import os import random import re import sys import config # This defines the Row object that we read in to the extractor parser = util.RowParser([ ('doc_id', 'text'), ('section...
dd-genomics-master
code/variantpheno_extract_candidates.py
#! /usr/bin/env python # # This file contains the generic features library that is included with ddlib. # # The three functions that a user should want to use are load_dictionary, # get_generic_features_mention, and get_generic_features_relation. # All the rest should be considered more or less private, except perhaps ...
dd-genomics-master
code/ddlib/gen_feats.py
from collections import namedtuple,OrderedDict import re import sys from inspect import isgeneratorfunction,getargspec import csv from StringIO import StringIO def print_error(err_string): """Function to write to stderr""" sys.stderr.write("ERROR[UDF]: " + str(err_string) + "\n") BOOL_PARSER = { 't' : True, ...
dd-genomics-master
code/ddlib/util.py
from dd import * from gen_feats import * from util import *
dd-genomics-master
code/ddlib/__init__.py
import sys import collections Word = collections.namedtuple('Word', ['begin_char_offset', 'end_char_offset', 'word', 'lemma', 'pos', 'ner', 'dep_par', 'dep_label']) Span = collections.namedtuple('Span', ['begin_word_id', 'length']) Sequence = collections.namedtuple('Sequence', ['is_inversed', 'elements']) DepEdge = co...
dd-genomics-master
code/ddlib/dd.py
import dependencies import sys def index_of_sublist(subl, l): for i in range(len(l) - len(subl) + 1): if subl == l[i:i + len(subl)]: return i def intersects(a1, a2): for i in a1: if i in a2: return True return False def acyclic(a): return len(a) == len(set(a)) ...
dd-genomics-master
code/util/clf_util.py
###################################################################################### # LATTICE - MEMEX plugins for latticelib # # latticelib is an extraction framework to allow quickly building extractors by # specifying minimal target-specific code (candidate generation patterns and # supervision rules). It has ...
dd-genomics-master
code/util/memex.py
dd-genomics-master
code/util/__init__.py
#! /usr/bin/python -m trace --trace --file /dev/stderr ###################################################################################### # LATTICE - Util functions for working with dependencies # # Usage: # Start by preparing a list of dep_patterns, eg. "he <-nsubj- buy" # # sentence is an object that con...
dd-genomics-master
code/util/dependencies.py
dd-genomics-master
code/dep_alignment/__init__.py
#! /usr/bin/env python def rc_to_match_tree(mixin, sent, cands, node, children, rv=None): if rv is None: rv = [] assert False, "TODO this method unfolds DAGS into trees, don't use it or fix it first" mc = MatchCell(1) rv.append(mc) index = len(rv) for i, cand in enumerate(cands): if node == cand: ...
dd-genomics-master
code/dep_alignment/alignment_util.py
#! /usr/bin/env python import numpy as np from alignment_util import AlignmentMixin, MatchCell import sys import copy class MultiDepAlignment(AlignmentMixin): word_match_score = 5 dict_match_score = 5 lemma_match_score = 5 pos_tag_match_score = -4 skip_score = -3 mismatch_score = -5 cand_match_score = ...
dd-genomics-master
code/dep_alignment/multi_dep_alignment.py
#! /usr/bin/env python import sys import glob import os if __name__ == "__main__": num = 0 if len(sys.argv) != 2: print >>sys.stderr, 'Expecting list of folder names (without preceding numbers) in file as argument' sys.exit(1) with open(sys.argv[1]) as f: for line in f: assert num <= 99, 'Cann...
dd-genomics-master
snapshot-template/gill-reduced/number_folders.py
#! /usr/bin/env python import sys import re for line in sys.stdin: print re.sub(r'\W+', ' ', line.strip())
dd-genomics-master
onto/replace_non_alpha.py
#! /usr/bin/env python from xml.etree.ElementTree import ElementTree import sys import re def attach_diseases(diseases, excludes): excludes = [set(d.strip().split()) for d in excludes] for line in diseases.split('\n'): names = line.strip().split(';') for name in names: # if 'GLOMERULOSCLEROSIS' in n...
dd-genomics-master
onto/parse_diseases.py
#! /usr/bin/env python import sys def main(): fname = sys.argv[1] transcript = None with open(fname) as f: for line in f: if line.startswith('>'): if transcript: print '%s\t{%s}' % (transcript, ','.join(sequence)) transcript = line.strip()[1:].split()[0].split('_')[2] ...
dd-genomics-master
onto/geneIsoformsToTable.py
#! /usr/bin/env python import sys def main(): fname = sys.argv[1] transcript = None with open(fname) as f: for line in f: if line.startswith('>'): if transcript: print '%s\t{%s}' % (transcript, ','.join(sequence)) transcript = line.strip()[1:] sequence = '' c...
dd-genomics-master
onto/proteinIsoformsToTable.py
import sys import re disease_to_hpos = {} with open('data/hpo_disease_phenotypes.tsv', 'rb') as f: for line in f.readlines(): source, source_id, name, name2, hpos = line.strip().split('\t') if source == "OMIM": disease_to_hpos[source_id] = hpos.split("|") with open('raw/clinvar.tsv', 'rb') as f: for...
dd-genomics-master
onto/join_clinvar_omim_hpo.py
#!/usr/bin/env python # -*- coding: utf-8 -*- """ A constant-space parser for the GeneOntology OBO v1.2 format Version 1.0 """ from collections import defaultdict __author__ = "Uli Koehler" __copyright__ = "Copyright 2013 Uli Koehler" __license__ = "Apache v2.0" def processGOTerm(goTerm): """ In an obje...
dd-genomics-master
onto/obo_parser.py
#! /usr/bin/env python import os APP_HOME = os.environ['GDD_HOME'] import sys sys.path.append('%s/code' % APP_HOME) import data_util as dutil ### ATTENTION!!!! PLEASE PIPE THE OUTPUT OF THIS SCRIPT THROUGH sort | uniq !!! ### ### Doing it within python is a waste of resources. Linux does it much faster. ### def ge...
dd-genomics-master
onto/load_hpo_abnormalities.py
#! /usr/bin/env python import sys if len(sys.argv) != 4: print >> sys.stderr, "usage: ./blah diseases_file ps_file ps_to_omim_file" sys.exit(1) diseases_filename = sys.argv[1] ps_filename = sys.argv[2] ps_to_omim_filename = sys.argv[3] omim_to_ps = {} ps_alt_names = {} with open(ps_to_omim_filename) as f: f...
dd-genomics-master
onto/omim_alt_names_to_series.py
#! /usr/bin/env python import os APP_HOME = os.environ['GDD_HOME'] import sys sys.path.append('%s/code' % APP_HOME) import data_util as dutil import argparse ### ATTENTION!!!! PLEASE PIPE THE OUTPUT OF THIS SCRIPT THROUGH sort | uniq !!! ### ### Doing it within python is a waste of resources. Linux does it much faste...
dd-genomics-master
onto/canonicalize_gene_phenotype.py
""" Output fields: id, name, synonyms, related terms, alt IDs, parent, MeSh terms """ import argparse from obo_parser import parseGOOBO if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument('infile', help='Input HPO file in OBO v1.2 format.') parser.add_argument('outfile', hel...
dd-genomics-master
onto/parse_hpo.py
#!/usr/bin/env python import sys import re import os #from nltk.stem.snowball import SnowballStemmer #from nltk.stem import PorterStemmer from nltk.stem import WordNetLemmatizer GDD_HOME = os.environ['GDD_HOME'] # [Alex 4/12/15]: # This script is for preprocessing a dictionary of phenotype phrase - HPO code pairs to b...
dd-genomics-master
onto/prep_pheno_terms.py
#! /usr/bin/env python import fileinput import sys def getDigits(text): c = '' for i in text: if i.isdigit(): c += i if len(c) > 0: return int(c) return -1 if __name__ == "__main__": for line in fileinput.input(): comps = line.strip().split('\t') if len(comps) == 0: continue ...
dd-genomics-master
parser/md_cleanup.py
import json import os import re import lxml.etree as et class XMLTree: """ A generic tree representation which takes XML as input Includes subroutines for conversion to JSON & for visualization based on js form """ def __init__(self, xml_root): """Calls subroutines to generate JSON form of XML input""" ...
dd-genomics-master
dsr/tree_structs.py
from collections import namedtuple import re def read_ptsv_element(x): """ Parse an element in psql-compatible tsv format, i.e. {-format arrays Takes a string as input, handles float, int, str vals, and arrays of these types """ if len(x) == 0: return None if x[0] == '{': return map(read_ptsv_eleme...
dd-genomics-master
dsr/treedlib_util.py
from IPython.core.display import display_html, HTML, display_javascript, Javascript import json import os import re import lxml.etree as et class XMLTree: """ A generic tree representation which takes XML as input Includes subroutines for conversion to JSON & for visualization based on js form """ def __init...
dd-genomics-master
dsr/tree_structs_ipynb.py
#! /usr/bin/python # -*- coding: utf-8 -*- import json import sys from nltk.stem import WordNetLemmatizer import re from nltk.corpus import stopwords def load_gene_name_to_genes(ensembl_genes_path): ret = {} with open(ensembl_genes_path) as f: for line in f: eid = line.strip().split(':')[0] canoni...
dd-genomics-master
document_classifier/classification/lemmatize_gpv_stdin.py
#! /usr/bin/python # -*- coding: utf-8 -*- import json import sys from nltk.stem import WordNetLemmatizer import re from nltk.corpus import stopwords def load_gene_name_to_genes(ensembl_genes_path): ret = {} with open(ensembl_genes_path) as f: for line in f: eid = line.strip().split(':')[0] canoni...
dd-genomics-master
document_classifier/classification/lemmatize_gpv.py
#! /usr/bin/python # -*- coding: utf-8 -*- from sklearn.feature_extraction.text import CountVectorizer from sklearn.feature_extraction.text import TfidfTransformer import sys from bunch import * import numpy as np import random from sklearn.linear_model import LogisticRegression from nltk.stem import WordNetLemmatizer...
dd-genomics-master
document_classifier/classification/classify.py
#! /usr/bin/env python import sys if __name__ == "__main__": cur_pmid = -1 cur_str = '' for line in sys.stdin: comps = line.strip().split('\t') pmid = int(comps[0]) if pmid == cur_pmid: cur_str += ' ' cur_str += comps[1] else: if cur_pmid != -1: print "%s\t%s" % (cur_pm...
dd-genomics-master
document_classifier/classification/merge_lines.py
#!/usr/bin/env python from collections import defaultdict, namedtuple import sys import re import os import random from itertools import chain import extractor_util as util import data_util as dutil import config # This defines the Row object that we read in to the extractor parser = util.RowParser([ ('doc_...
dd-genomics-master
document_classifier/classification/pheno_extract_candidates.py
#! /usr/bin/python # -*- coding: utf-8 -*- from sklearn.feature_extraction.text import CountVectorizer from sklearn.feature_extraction.text import TfidfTransformer import sys from bunch import * import numpy as np import random from sklearn.linear_model import LogisticRegression from nltk.stem import WordNetLemmatizer...
dd-genomics-master
document_classifier/classification/create_classifier.py
#! /usr/bin/python # -*- coding: utf-8 -*- import json import sys import re if __name__ == "__main__": if len(sys.argv) != 2: print >>sys.stderr, "need 2 args: symbol for file (NOT used for stdin), output path" sys.exit(1) pubmed = sys.argv[1] out_path = sys.argv[2] gene_rgx = comp_gene_rgxs(ensembl_g...
dd-genomics-master
document_classifier/classification/json_to_tsv.py
#! /usr/bin/python # -*- coding: utf-8 -*- from sklearn.feature_extraction.text import CountVectorizer from sklearn.feature_extraction.text import TfidfTransformer import sys from bunch import * import numpy as np import random from sklearn.naive_bayes import MultinomialNB from sklearn.linear_model import LogisticRegr...
dd-genomics-master
document_classifier/classification/word_counter.py
#! /usr/bin/python # -*- coding: utf-8 -*- import word_counter import sys import re from bunch import * import numpy as np import random from nltk.stem import WordNetLemmatizer from nltk.corpus import stopwords from functools32 import lru_cache from nltk.stem import PorterStemmer def toBunch(mmap): rv = Bunch() r...
dd-genomics-master
document_classifier/classification/preprocess_test_data.py
#! /usr/bin/env python # -*- coding: utf-8 -*- import json import sys import re def load_unlabeled_docs(data_path): rv = {} print >>sys.stderr, "Loading JSON data" ctr = -1 with open(data_path) as f: for line in f: ctr += 1 if ctr % 100000 == 0: print >>sys.stderr, "counting %d lines" ...
dd-genomics-master
document_classifier/classification/joined_data/json_to_tsv.py
#! /usr/bin/env python import sys import re if __name__ == "__main__": no_alnum = re.compile(r'[\W_]+') with open(sys.argv[2], 'w') as out_file: with open(sys.argv[1]) as f: for line in f: comps = line.strip().split('\t') pmid = comps[0] journal = comps[1] mesh_terms_stri...
dd-genomics-master
document_classifier/classification/processed/genomics_dump_to_processed.py
"""Assess phenotype recall relative to known HPO-PMID map.""" import collections import random import sys sys.path.append('../code') import extractor_util as util import data_util as dutil NUM_ERRORS_TO_SAMPLE = 50 def main(id_file, candidate_file): # Load list of all pubmed IDs in the dataset print >> sys.stder...
dd-genomics-master
eval/pheno_recall.py
import collections import random import sys sys.path.append('../code') import extractor_util as util import data_util as dutil HPO_DAG = dutil.read_hpo_dag() def read_supervision(): """Reads genepheno supervision data (from charite).""" supervision_pairs = set() with open('%s/onto/data/hpo_phenotype_genes.tsv'...
dd-genomics-master
eval/omim_coverage.py
#! /usr/bin/env python ''' Created on Aug 3, 2015 @author: jbirgmei ''' import abbreviations if __name__ == '__main__': sentence = 'Scaffold proteins are abundant and essential components of the postsynaptic density -LRB- PSD -RRB- as well as I Hate JavaScript Proteins -LRB- IHJSP -RRB- , and a completely unrelat...
dd-genomics-master
archived/test-abbreviations.py