Skip to content

Commit

Permalink
[tred] Parse sites folder when --workdir is not cwd
Browse files Browse the repository at this point in the history
  • Loading branch information
tanghaibao committed Oct 10, 2017
1 parent ff86eb6 commit 5906473
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion sites/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Use the template in this folder to add additional STR sites to the TREDPARSE
run. By default, in addition to the 30 standard STR loci, TREDPARSE also look
for JSON files in `sites`` in the current working directory.
for JSON files in ``sites`` in the current working directory.

Most of the details can be manually filled out, however, the ``prefix`` and
``suffix`` fields need to be computed from the reference FASTA. Therefore we've
Expand Down
15 changes: 7 additions & 8 deletions tredparse/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

class TREDsRepo(dict):

def __init__(self, ref=REF, toy=False, use_sites=True):
def __init__(self, ref=REF, toy=False, sites=SITES):

# Parse ALTS first
alts = self.get_alts(ref)
Expand All @@ -41,13 +41,12 @@ def __init__(self, ref=REF, toy=False, use_sites=True):
self.df = df

# Get all user loci names by searching within sites folder
if use_sites:
for sites in glob("{}/*.json".format(SITES)):
sites = byteify(json.load(open(sites)))
for name, row in sites.items():
name = str(name) # json.loads gets a unicode
self[name] = TRED(name, row, ref=ref, alt=alts.get(name, []))
self.names.append(name)
for s in glob("{}/*.json".format(sites)):
s = byteify(json.load(open(s)))
for name, row in s.items():
name = str(name) # json.loads gets a unicode
self[name] = TRED(name, row, ref=ref, alt=alts.get(name, []))
self.names.append(name)

if toy:
tr = self.get("HD")
Expand Down
3 changes: 2 additions & 1 deletion tredparse/tred.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,10 +472,11 @@ def main(args):
logger.debug("Total samples: {}".format(len(samples)))

task_args = []
sites = op.join(os.getcwd(), "sites")
os.chdir(workdir)

ref = args.ref
repo = TREDsRepo(ref=ref, toy=args.toy)
repo = TREDsRepo(ref=ref, toy=args.toy, sites=sites)
repo.set_ploidy(args.haploid)
TRED_NAMES = repo.names
treds = args.tred or TRED_NAMES
Expand Down

0 comments on commit 5906473

Please sign in to comment.