title: De Bruijn Graph Code Python 3
body: <p>This is for a class assignment. I'm new to coding and was advised to use Python since it is easier to deal with. The point of the assignment is to take a list of kmers and assemble the superstring, in this case DNA nucleotides and assemble the DNA sequence. We need to use the Euler path (algorithm), which I still haven't figured out to do. Right now I'm working on, one trying to load my kmer list to Python (haven't figured that out yet) and building the de Bruijn graph. NOTE: I'm not loading the list of kmers since I haven't figured out how to do that yet. This is just a random string of DNA that I'm typing in. </p>
  
  <p>Here is my code:</p>
  
  <pre><code>def de_bruijn_ize(st, k):
  edges = []
  nodes = set()
  for i in range(len(st) - k + 1):
      edges.append((st[i:+k-1], st[i+1:i+k]))
      nodes.add(st[i:i+k-1])
      nodes.add(st[i+1:i+k])
  return nodes, edges
  
  nodes, edges = de_bruijn_ize(“CCGGTTAAACGTC”, 3)
  print(nodes)
  print(edges)
  </code></pre>
  
  <p>I'm receiving the following message when I try to run it:</p>
  
  <p>File "practiceassembly.txt", line 11
      nodes, edges = de_bruijn_ize(“CCGGTTAAACGTC”, 3)
                                                 ^
  SyntaxError: invalid character in identifier</p>
  
  <p>Any help/suggestions would be appreciated. And if anybody can provide good resources for this type of problem, I would really appreciate it also. </p>
  
  <p>I made a little progress. I have managed to open my kmer file with the following:
  Yeah, I've managed to get that going:                                                                           </p>
  
  <pre><code>f = open("kmers.txt")
  print(f.read())
  st = f.read()
  def de_bruijn_ize(st, k):
  edges = []
  nodes = set()
  for i in range(len(st) - k + 1):
      edges.append((st[i:+k-1], st[i+1:i+k]))
      nodes.add(st[i:i+k-1])
      nodes.add(st[i+1:i+k])
  return nodes, edges
  
  nodes, edges = de_bruijn_ize(st, 4)
  print(nodes)
  print(edges)
  </code></pre>
  
  <p>And I get my list of kmers:</p>
  
  <p>AAAC
  AACA
  AACG
  AAGG
  ACAC
  ACAG
  ACGC
  ACGG
  ACTG
  AGCA
  AGGA
  AGGC
  ATCA
  ATTC
  CAAG
  CACA
  CACG
  CAGG
  CATC
  CGCG
  CGGT
  CGTA
  CGTG
  CTAA
  CTCT
  CTGG
  CTTA
  GACT
  GCAT
  GCGT
  GCTC
  GCTT
  GGAC
  GGCA
  GGCT
  GGGT
  GGTG
  GGTT
  GTAT
  GTGC
  GTGG
  GTTT
  TAAA
  TAAC
  TATT
  TCAA
  TCAC
  TCGT
  TCTA
  TGCT
  TGGC
  TGGG
  TTAA
  TTCA
  TTCG
  TTTC
  TTTT
  set()
  []
  But the rest is not implemented. I think I'm almost there in getting this to work (maybe I'm just being hopeful here) but I just need a little help. </p>