Skip to content

Commit

Permalink
Merge pull request #25 from andersen-lab/dev
Browse files Browse the repository at this point in the history
adding custom lineage metadata file for reproducibility
  • Loading branch information
joshuailevy authored Feb 4, 2022
2 parents 863ac7c + 681c9ef commit 293f7f6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
10 changes: 6 additions & 4 deletions freyja/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ def cli():
@click.argument('depths', type=click.Path(exists=True))
@click.option('--eps', default=1e-3, help='minimum abundance to include')
@click.option('--barcodes', default='-1', help='custom barcode file')
@click.option('--meta', default='-1', help='custom lineage metadata file')
@click.option('--output', default='demixing_result.csv', help='Output file',
type=click.Path(exists=False))
def demix(variants, depths, output, eps, barcodes):
def demix(variants, depths, output, eps, barcodes, meta):
locDir = os.path.abspath(os.path.join(os.path.realpath(__file__),
os.pardir))
# option for custom barcodes
Expand All @@ -37,7 +38,7 @@ def demix(variants, depths, output, eps, barcodes):
df_barcodes = pd.read_csv(os.path.join(locDir,
'data/usher_barcodes.csv'), index_col=0)
muts = list(df_barcodes.columns)
mapDict = buildLineageMap()
mapDict = buildLineageMap(meta)
print('building mix/depth matrices')
# assemble data from (possibly) mixed samples
if variants.lower().endswith('vcf'):
Expand Down Expand Up @@ -115,9 +116,10 @@ def variants(bamfile, ref, variants, depths, refname):
@click.option('--nt', default=1, help='max number of cpus to use')
@click.option('--eps', default=1e-3, help='minimum abundance to include')
@click.option('--barcodes', default='-1', help='custom barcode file')
@click.option('--meta', default='-1', help='custom lineage metadata file')
@click.option('--output_base', default='test', help='Output file basename',
type=click.Path(exists=False))
def boot(variants, depths, output_base, eps, barcodes, nb, nt):
def boot(variants, depths, output_base, eps, barcodes, meta, nb, nt):
locDir = os.path.abspath(os.path.join(os.path.realpath(__file__),
os.pardir))
# option for custom barcodes
Expand All @@ -127,7 +129,7 @@ def boot(variants, depths, output_base, eps, barcodes, nb, nt):
df_barcodes = pd.read_csv(os.path.join(locDir,
'data/usher_barcodes.csv'), index_col=0)
muts = list(df_barcodes.columns)
mapDict = buildLineageMap()
mapDict = buildLineageMap(meta)
print('building mix/depth matrices')
# assemble data from (possibly) mixed samples
mix, depths_ = build_mix_and_depth_arrays(variants, depths, muts)
Expand Down
17 changes: 11 additions & 6 deletions freyja/sample_deconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@
from tqdm import tqdm


def buildLineageMap():
def buildLineageMap(locDir):
# Parsing curated lineage data from outbreak.info
locDir = os.path.abspath(os.path.join(os.path.realpath(__file__),
os.pardir))
f0 = open(os.path.join(locDir, 'data/curated_lineages.json'))
dat = json.load(f0)
f0.close()
if locDir == '-1':
locDir = os.path.abspath(os.path.join(os.path.realpath(__file__),
os.pardir))
f0 = open(os.path.join(locDir, 'data/curated_lineages.json'))
dat = json.load(f0)
f0.close()
else:
f0 = open(locDir)
dat = json.load(f0)
f0.close()

mapDict = {}
for ind in range(len(dat)):
Expand Down
6 changes: 3 additions & 3 deletions freyja/tests/test_deconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class DeconvTests(unittest.TestCase):
def test_buildLineageMap(self):
mapDict = buildLineageMap()
mapDict = buildLineageMap('-1')
self.assertTrue('Alpha' == mapDict['B.1.1.7'])
self.assertTrue('Delta' == mapDict['AY.4'])

Expand All @@ -32,7 +32,7 @@ def test_build_mix_and_depth_plus_reindex(self):
self.assertFalse('20C' in df_barcodes.columns)

def test_constellation_mapping(self):
mapDict = buildLineageMap()
mapDict = buildLineageMap('-1')
vals = [0.1, 0.5, 0.31, 0.01, 0.02, 0.01]
strains = ['B.1.617.2', 'Q.3', 'B.1.427', 'A.2.5', 'B.1.1', 'B.1.1.7']
locDict = map_to_constellation(strains, vals, mapDict)
Expand Down Expand Up @@ -61,7 +61,7 @@ def test_demixing(self):
abundances[sample_strains.tolist().index(strain2)], mixFracs[1])

def test_boot(self):
mapDict = buildLineageMap()
mapDict = buildLineageMap('-1')
df_barcodes = pd.read_csv('freyja/data/usher_barcodes.csv',
index_col=0)
muts = list(df_barcodes.columns)
Expand Down

0 comments on commit 293f7f6

Please sign in to comment.