Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
fastas_fn = node.fastapath.split("@")
for fasta_fn in fastas_fn:
print(fasta_fn)
else:
children = node.get_children()
for child in children:
self.process_node(child)
if __name__ == "__main__":
assert (len(sys.argv) == 2)
newick_fn = sys.argv[1]
ti = TreeIndex(tree_newick_fn=newick_fn, )
ti.process_node(ti.tree.get_tree_root())
hitmasks_dict = collections.defaultdict(lambda: bitarray(hitmask_empty))
covmasks_dict = collections.defaultdict(lambda: bitarray(covmask_empty))
hitmasks_dict = collections.defaultdict(lambda: bitarray(hitmask_empty))
covmasks_dict = collections.defaultdict(lambda: bitarray(covmask_empty))
covmasks_dict = collections.defaultdict(lambda: bitarray(covmask_empty))
def evaluate_single_assignment(self, nodename):
"""Evaluate a single assignment.
Args:
nodename (str): Name of the node for which we will compute characteristics.
Returns:
assignment (dict): Assignment dictionary.
"""
#################################
# A) Start with the current masks
#################################
hitmask = bitarray(self.hitmasks_dict[nodename])
covmask = bitarray(self.covmasks_dict[nodename])
node = self.tree_index.nodename_to_node[nodename]
##########################
# B) Update from ancestors
##########################
ancestors = self.tree_index.nodename_to_upnodenames[nodename] & self.hitmasks_dict.keys()
for anc_nodename in ancestors:
hitmask |= self.hitmasks_dict[anc_nodename]
covmask |= self.covmasks_dict[anc_nodename]
##############################
# C) Calculate characteristics
##############################
hit = hitmask.count()
cov = covmask.count()
def bitarray_block(alen, blen, pos):
"""Create a bitarray containing a block of one's.
Args:
alen (int): Array length.
blen (int): Block length (within the array).
pos (int): Position of the block (0-based).
Return:
bitarray (bitarray)
"""
return bitarray(pos * "0" + blen * "1" + (alen - pos - blen) * "0")
def evaluate_single_assignment(self, nodename):
"""Evaluate a single assignment.
Args:
nodename (str): Name of the node for which we will compute characteristics.
Returns:
assignment (dict): Assignment dictionary.
"""
#################################
# A) Start with the current masks
#################################
hitmask = bitarray(self.hitmasks_dict[nodename])
covmask = bitarray(self.covmasks_dict[nodename])
node = self.tree_index.nodename_to_node[nodename]
##########################
# B) Update from ancestors
##########################
ancestors = self.tree_index.nodename_to_upnodenames[nodename] & self.hitmasks_dict.keys()
for anc_nodename in ancestors:
hitmask |= self.hitmasks_dict[anc_nodename]
covmask |= self.covmasks_dict[anc_nodename]
##############################
# C) Calculate characteristics
##############################
hit = hitmask.count()
def evaluate_single_assignment(self, nodename):
"""Evaluate a single assignment.
Args:
nodename (str): Name of the node for which we will compute characteristics.
Returns:
assignment (dict): Assignment dictionary.
"""
#################################
# A) Start with the current masks
#################################
hitmask = bitarray(self.hitmasks_dict[nodename])
covmask = bitarray(self.covmasks_dict[nodename])
##########################
# B) Update from ancestors
##########################
ancestors = self.tree_index.nodename_to_upnodenames[nodename] & self.hitmasks_dict.keys()
for anc_nodename in ancestors:
hitmask |= self.hitmasks_dict[anc_nodename]
covmask |= self.covmasks_dict[anc_nodename]
##############################
# C) Calculate characteristics
##############################
hit = hitmask.count()
cov = covmask.count()
readlen = self.krakline_parser.readlen
kcount = self.tree_index.nodename_to_kmercount[nodename]
class Rank(OrderedEnum):
NO_RANK = 7
SPECIES = 6
GENUS = 5
FAMILY = 4
ORDER = 3
CLASS = 2
PHYLUM = 1
KINGDOM = 0
str2rank = {
'species': Rank.SPECIES,
'genus': Rank.GENUS,
'family': Rank.FAMILY,
'order': Rank.ORDER,
'class': Rank.CLASS,
'phylum': Rank.PHYLUM,
'kingdom': Rank.KINGDOM,
'no rank': Rank.NO_RANK
}
def build_complete_tree(tree, log):
"""Build the taxonomic tree including internal nodes (for rank dependent evaluation)
Args:
tree (fileobject): file name of the reference tree, without internal nodes
log (fileobject): log file
"""
ncbi = NCBITaxa()
SPECIES = 6
GENUS = 5
FAMILY = 4
ORDER = 3
CLASS = 2
PHYLUM = 1
KINGDOM = 0
str2rank = {
'species': Rank.SPECIES,
'genus': Rank.GENUS,
'family': Rank.FAMILY,
'order': Rank.ORDER,
'class': Rank.CLASS,
'phylum': Rank.PHYLUM,
'kingdom': Rank.KINGDOM,
'no rank': Rank.NO_RANK
}
def build_complete_tree(tree, log):
"""Build the taxonomic tree including internal nodes (for rank dependent evaluation)
Args:
tree (fileobject): file name of the reference tree, without internal nodes
log (fileobject): log file
"""
ncbi = NCBITaxa()
original_tree = Tree(tree, format=1)
taxa = [n.taxid for n in original_tree.traverse('postorder')]
built = False