2

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?

jared_mamrot
  • 22,354
  • 4
  • 21
  • 46

1 Answers1

1

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?

jared_mamrot
  • 22,354
  • 4
  • 21
  • 46
  • Thankyou so much, that tips solve my problem. – Syahir Muhammad Jul 27 '23 at 07:01
  • You're welcome @SyahirMuhammad, but the comment sections isn't meant for saying 'thanks': please see [What should I do when someone answers my question?](https://stackoverflow.com/help/someone-answers) – jared_mamrot Jul 27 '23 at 10:28