find_motifs function to remove the edge

36 views Asked by At

I've got little problem here which is I want to remove the edge between 2 sample of nucleic acid "CYS 6 N", "ASP 40 OD2" by using the motif argument.

from grandiso import find_motifs
import networkx as nx

host = nx.read_adjlist('number_2 copy_1.csv', delimiter = ",")

motif = nx.Graph()
motif.add_edge("CYS 6 N", "ASP 40 OD2")


list(find_motifs(motif, host))

The output of my command is:

'CYS 6 N': 'ARG 2 NE', 'ASP 40 OD2': 'HOH 1083 O'

How am I suppose to get rid the 'ARG 2 NE' and 'HOH 1083 O' and just show only

"CYS 6 N", "ASP 40 OD2"

as my output?

1

There are 1 answers

1
jared_mamrot On

I think you can get your expected output by printing the dictionary keys, e.g.

from grandiso import find_motifs
import networkx as nx

host = nx.read_adjlist('number_2 copy_1.csv', delimiter = ",")

motif = nx.Graph()
motif.add_edge("CYS 6 N", "ASP 40 OD2")


for i in list(find_motifs(motif, host)):
    print(list(i.keys()))

Using the example from https://github.com/aplbrain/grandiso-networkx:

from grandiso import find_motifs
import networkx as nx

host = nx.fast_gnp_random_graph(10, 0.5)

motif = nx.Graph()
motif.add_edge("A", "B")
motif.add_edge("B", "C")
motif.add_edge("C", "D")
motif.add_edge("D", "A")

len(find_motifs(motif, host))
# 440

list(find_motifs(motif, host))
# [{'A': 0, 'B': 1, 'C': 2, 'D': 7}, ...

for i in list(find_motifs(motif, host)):
    print(i.keys())
# dict_keys(['A', 'B', 'C', 'D'])

# without "dict_keys" in the output:
for i in list(find_motifs(motif, host)):
    print(list(i.keys()))
# ['A', 'B', 'C', 'D']

# unpack the list:
for i in list(find_motifs(motif, host)):
    print(*i.keys(), sep = ", "))
# A, B, C, D

Does that solve your problem?