Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions scripts/json2csv.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
"""
Convert JSON generated from Sierra processor into CSV format, retaining
only drug-specific resistance scores.
"""

import json
import csv
import argparse
Expand Down
4 changes: 4 additions & 0 deletions scripts/timing.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Script to compare sierralocal and sierrapy runtimes on a sample of 10 files.
"""

import subprocess
from sierralocal import main
import os
Expand Down
6 changes: 6 additions & 0 deletions sierralocal/jsonwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@


class JSONWriter():
"""
Define a class for handling the formatting for the final JSON output of
mutations and validation results. The main write function is in
write_to_json. Generally, @param algorithm will be an instance of the
HIVdb class.
"""
def __init__(self, algorithm, apobec_csv, unusual_csv, sdrms_csv, mutation_csv):
# possible alternative drug abbrvs
self.names = {'3TC': 'LMV'}
Expand Down
31 changes: 30 additions & 1 deletion sierralocal/nucaminohook.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,31 @@ def get_aligned_seq(self, nuc, sites):
return aligned

def makeReferenceFASTA(self, fragmentName, refSeq):
"""
Makes a temporary FASTA file for the reference sequence of a given fragment.
@param fragmentName: str, name of fragment
@param refSeq: str, reference sequence for a given fragment
@return: str, path to temporary FASTA file
"""

tempFasta = tempfile.NamedTemporaryFile('w', prefix='postalign-ref-', suffix='.fas', delete=False)
tempFasta.write(">Ref_{}\n".format(fragmentName))
tempFasta.write("{}\n".format(refSeq))
tempFasta.close()
return os.path.abspath(tempFasta.name)

def getConfigField(self, config, field):
"""
Retrieves entry information from each fragmentConfig entry in the alignment
config JSON file, and depending on whether the field is refSequence or not,
stores the corresponding FASTA file path or the field value in a dictionary
that is mapping fragmentName to field value.
@param config: dict, JSON configuration for post-align
@param field: str, field to retrieve from config
@return: dict, dictionary of fragmentName to a path to a corresponding
temporary FASTA filed and/or field value.
"""

resultmap = {}
for entry in config['fragmentConfig']:
if field == 'refSequence':
Expand Down Expand Up @@ -695,6 +713,11 @@ def is_unsequenced(self, triplet):
return (triplet.replace("-", "N").count("N") > 1) # TODO: incorporate !isInsertion &&

def is_stop_codon(self, triplet):
"""Determines whether a nucleotide triplet encodes a stop codon. ("*" is
present in the translated triplet)
@param triplet: str, nucleotide triplet as a string
@return: bool, True when it is a stop codon
"""
return ("*" in self.translate_na_triplet(triplet))

def is_apobec_drm(self, gene, consensus, position, AA):
Expand Down Expand Up @@ -739,7 +762,13 @@ def get_highest_mut_prevalance(self, mutation, gene, subtype):

def get_mut_prevalence(self, position, cons, aa, gene, subtype):
"""
???
Determines prevalence of a specific mutation in the subtype alignment, by looking up the position, consensus amino acid, mutant amino acid, gene and subtype in the prevalence dictionaries.
@param position: int, position of mutation relative to POL
@param cons: str, consensus amino acid at this position
@param aa: str, mutant amino acid at this position
@param gene: str, PR, RT, or INT
@param subtype: str, predicted from Subtyper.get_closest_subtype()
@return: float, prevalence of the mutation in the subtype alignment
"""
key2 = str(position) + str(cons) + str(aa) + subtype

Expand Down
3 changes: 3 additions & 0 deletions sierralocal/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ def update_genotype_properties(target_dir=None):
print("Couldn't update subtyper genotype property file, please get manually at: https://hivdb.stanford.edu/page/hiv-subtyper/")

def main(updater_outdir=None): # pragma: no cover
"""
Main function called when running updater.py directly.
"""
update_hivdb(updater_outdir)
update_apobec(updater_outdir)
update_is_unusual(updater_outdir)
Expand Down