Skip to content

Commit 4bb7c24

Browse files
authored
Merge pull request #42 from pbashyal-nmdp/master
Use given data_dir for mac files.
2 parents 39b59a1 + 8b875ab commit 4bb7c24

File tree

3 files changed

+12
-31
lines changed

3 files changed

+12
-31
lines changed

pyard/pyard.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,14 @@ def __init__(self, dbversion: str='Latest',
128128

129129
imgt_hla_url = 'https://raw.githubusercontent.com/ANHIG/IMGTHLA/'
130130
ars_url = imgt_hla_url + dbversion + '/wmda/hla_nom_g.txt'
131+
allele_url = imgt_hla_url + dbversion + "/Allelelist.txt"
132+
131133
ars_file = data_dir + '/hla_nom_g.' + str(dbversion) + ".txt"
132134
allele_file = data_dir + '/AlleleList.' + str(dbversion) + ".txt"
133135
mac_file = data_dir + "/mac.txt"
134136
mac_pickle = data_dir + "/mac.pickle"
137+
# dna_relshp.csv is part of the codebase
135138
broad_file = os.path.dirname(__file__) + "/dna_relshp.csv"
136-
#print("mac_file:", mac_file)
137-
138-
allele_url = "https://raw.githubusercontent.com/ANHIG/IMGTHLA/" \
139-
+ dbversion + "/Allelelist.txt"
140139

141140
# Downloading ARS file
142141
if not os.path.isfile(ars_file):
@@ -155,7 +154,7 @@ def __init__(self, dbversion: str='Latest',
155154
if not os.path.isfile(mac_pickle):
156155
if verbose:
157156
logging.info("Downloading MAC file")
158-
self.mac = all_macs(mac_file)
157+
self.mac = all_macs(mac_file, data_dir=data_dir)
159158

160159
# Writing dict to pickle file
161160
with open(mac_pickle, 'wb') as handle:

pyard/util.py

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,37 +21,19 @@
2121
# > http://www.fsf.org/licensing/licenses/lgpl.html
2222
# > http://www.opensource.org/licenses/lgpl-license.php
2323
#
24-
import os
25-
import string
26-
import random as r
27-
from datetime import datetime, date
28-
from six import integer_types, iteritems
29-
import pandas as pd
3024
import copy
31-
import http.client
32-
import pickle
25+
import re
3326
import urllib.request
3427
import zipfile
35-
import re
28+
from datetime import datetime, date
29+
30+
import pandas as pd
31+
from six import integer_types, iteritems
3632

3733

38-
# def all_macs(csv_file, url='hml.nmdp.org'):
39-
# # conn = http.client.HTTPSConnection(url, 443)
40-
# # conn.putrequest('GET', '/mac/api/codes')
41-
# # conn.endheaders()
42-
# # response = conn.getresponse().read().decode('utf8').splitlines()
43-
# data = [l.split("\t")[1:3] for l in response]
44-
# urllib.request.urlretrieve(url, 'numeric.v3.zip')
45-
# df = pd.DataFrame(data, columns=['Code','Alleles'])
46-
# df.to_csv(csv_file, header=True, index=False)
47-
# df['Alleles'] = df['Alleles'].apply(lambda x: x.split("/"))
48-
# mac_dict = df.set_index("Code").to_dict('index')
49-
# return mac_dict
50-
51-
def all_macs(csv_file, url='https://hml.nmdp.org/mac/files/numer.v3.zip'):
34+
def all_macs(csv_file, data_dir, url='https://hml.nmdp.org/mac/files/numer.v3.zip'):
5235
urllib.request.urlretrieve(url, 'numeric.v3.zip')
5336
zip_ref = zipfile.ZipFile('numeric.v3.zip', 'r')
54-
data_dir = os.path.dirname(__file__)
5537
zip_ref.extractall(data_dir)
5638
zip_ref.close()
5739
data = []
@@ -62,7 +44,7 @@ def all_macs(csv_file, url='https://hml.nmdp.org/mac/files/numer.v3.zip'):
6244
if re.search("^\D", line) and not re.search("CODE", line) and not re.search("LAST", line):
6345
data.append(line.split("\t"))
6446
f.close()
65-
df = pd.DataFrame(data, columns=['Code','Alleles'])
47+
df = pd.DataFrame(data, columns=['Code', 'Alleles'])
6648
df.to_csv(csv_file, header=True, index=False)
6749
df['Alleles'] = df['Alleles'].apply(lambda x: x.split("/"))
6850
mac_dict = df.set_index("Code").to_dict('index')

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
setup(
4444
name='py-ard',
45-
version='0.0.16',
45+
version='0.0.17',
4646
description="ARD reduction for HLA with python",
4747
long_description=readme + '\n\n' + history,
4848
author="CIBMTR",

0 commit comments

Comments
 (0)