Skip to content

Commit

Permalink
Ran black on grim/
Browse files Browse the repository at this point in the history
  • Loading branch information
pbashyal-nmdp committed Feb 20, 2024
1 parent dcd534a commit 506f0a0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
4 changes: 2 additions & 2 deletions grim/imputation/impute.py
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ def open_phases(self, haps, N_Loc, gl_string):
optionDict = {} # set()
if len(fq) == 0:
_list = []
for (gen, name) in self.cypher.loc_map.items():
for gen, name in self.cypher.loc_map.items():
count = 0
for i in range(len(hap_list[0])):
if hap_list[0][i].split("*", 1)[0] == gen:
Expand Down Expand Up @@ -2017,7 +2017,7 @@ def impute_file(self, config, planb=None, em_mr=False, em=False): ##em
problem = open(config["imputation_out_problem_file"], "w")

with f as lines:
for (i, name_gl) in enumerate(lines):
for i, name_gl in enumerate(lines):
try:
name_gl = name_gl.rstrip() # remove trailing whitespace
if "," in name_gl:
Expand Down
47 changes: 37 additions & 10 deletions grim/imputation/networkx_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,20 @@ def build_graph(self, nodesFile, edgesFile, allEdgesFile):
if not self.nodes_plan_a or row[2] in self.nodes_plan_a:
self.Vertices.append(row[1])
vertex_id = len(self.Vertices) - 1
self.Vertices_attributes[row[1]] = (row[2], list(map(float, row[3].split(";"))), vertex_id)
self.Vertices_attributes[row[1]] = (
row[2],
list(map(float, row[3].split(";"))),
vertex_id,
)

if not self.nodes_plan_b or row[2] in self.nodes_plan_b:
self.Whole_Vertices.append(row[1])
vertex_id = len(self.Whole_Vertices) - 1
self.Whole_Vertices_attributes[row[1]] = (
row[2], list(map(float, row[3].split(";"))), vertex_id)
row[2],
list(map(float, row[3].split(";"))),
vertex_id,
)

nodesDict[row[0]] = row[1]

Expand All @@ -70,7 +77,10 @@ def build_graph(self, nodesFile, edgesFile, allEdgesFile):
node2_id = row[1]
node1 = nodesDict[node1_id]
node2 = nodesDict[node2_id]
if node1 in self.Vertices_attributes and node2 in self.Vertices_attributes:
if (
node1 in self.Vertices_attributes
and node2 in self.Vertices_attributes
):
node1_label = self.Vertices_attributes[node1][0]
if node1_label == self.full_loci:
self.Edges.append([node2_id, node1_id])
Expand Down Expand Up @@ -145,7 +155,9 @@ def build_graph(self, nodesFile, edgesFile, allEdgesFile):
del sorted_indices

# Create a list of the first appearance of a number in the 0 column in the matrix
unique_values, first_occurrences_indices = np.unique(self.Edges[:, 0], return_index=True)
unique_values, first_occurrences_indices = np.unique(
self.Edges[:, 0], return_index=True
)

j = 0
for i in range(0, self.Vertices.shape[0]):
Expand All @@ -162,7 +174,9 @@ def build_graph(self, nodesFile, edgesFile, allEdgesFile):
del unique_values, first_occurrences_indices

# Create a list of the first appearance of a number in the 0 column in the matrix
unique_values, first_occurrences_indices = np.unique(self.Whole_Edges[:, 0], return_index=True)
unique_values, first_occurrences_indices = np.unique(
self.Whole_Edges[:, 0], return_index=True
)

j = 0
for i in range(0, self.Whole_Vertices.shape[0]):
Expand All @@ -182,7 +196,9 @@ def build_graph(self, nodesFile, edgesFile, allEdgesFile):
self.Whole_Neighbors_start.append(int(len(self.Whole_Vertices)))

self.Neighbors_start = np.array(self.Neighbors_start, dtype=np.uint32)
self.Whole_Neighbors_start = np.array(self.Whole_Neighbors_start, dtype=np.uint32)
self.Whole_Neighbors_start = np.array(
self.Whole_Neighbors_start, dtype=np.uint32
)

# Take the first column out of the Edges arrays
### Do the following to massive save of memory
Expand Down Expand Up @@ -249,7 +265,13 @@ def adjs_query(self, alleleList):
allele_id = self.Vertices_attributes[allele][2]
# Find the neighbors of the allele
allele_neighbors = self.Vertices[
self.Edges[range(self.Neighbors_start[allele_id], self.Neighbors_start[allele_id + 1])]]
self.Edges[
range(
self.Neighbors_start[allele_id],
self.Neighbors_start[allele_id + 1],
)
]
]
# The frequencies of the neighbors to the dictionary
for adj in allele_neighbors:
adjDict[adj] = self.Vertices_attributes[adj][1]
Expand All @@ -271,9 +293,14 @@ def adjs_query_by_color(self, alleleList, labelA, labelB):

if connector in self.Whole_Vertices_attributes:
connector_id = self.Whole_Vertices_attributes[connector]
alleles = self.Whole_Vertices[self.Whole_Edges[range(self.Whole_Neighbors_start[connector_id],
self.Whole_Neighbors_start[
connector_id + 1])]]
alleles = self.Whole_Vertices[
self.Whole_Edges[
range(
self.Whole_Neighbors_start[connector_id],
self.Whole_Neighbors_start[connector_id + 1],
)
]
]

for adj in alleles:
adjDict[adj] = self.Whole_Vertices_attributes[adj][1]
Expand Down

0 comments on commit 506f0a0

Please sign in to comment.