#!/usr/bin/env python
import re, argparse, os
from recyclelib.utils import readfq

def parse_user_input():
    parser = argparse.ArgumentParser(
        description=
        'recycle extracts cycles likely to be plasmids from metagenome and genome assembly graphs'
        )
    parser.add_argument('-g','--graph',
     help='(spades 3.50+) FASTG file to process [recommended: before_rr.fastg]',
     required=True, type=str
     )
    parser.add_argument('-o','--output',
     help='output file name for FASTA of cycles',
     required=False, type=str
     )

    return parser.parse_args()

def parse_lines(fastg, ofile):
    lines = []
    fp = open(fastg, 'r')
    count = 0
    for name,seq,qual in readfq(fp):
        count += 1
        if count % 2 == 0: continue
        name = re.sub('[:,]'," ", name[:-1]).split(" ")[0]
        line = ">"+name+"\n"+seq+"\n"
        ofile.write(line)

if __name__=='__main__':
    args = parse_user_input()
    fastg = args.graph
    fp = open(fastg, 'r')
    files_dir = os.path.dirname(fp.name)

    # output 1 - fasta of sequences
    if args.output:
        fasta_ofile = args.output
    else:
        (root,ext) = os.path.splitext(fp.name)
        fasta_ofile = root + ext.replace(".fastg", ".nodes.fasta")

    f_nodes_fasta = open(fasta_ofile, 'w')
    parse_lines(fastg, f_nodes_fasta)

@@ -172,96 +172,75 @@
    '
-recycle extracts cycles likely to be plasmids from metagenome and genome assembly graphs
+make_fasta_from_fastg converts fastg assembly graph to fasta format
 '%0A  
@@ -600,23 +600,8 @@
 e):%0A
-    lines = %5B%5D%0A
     
@@ -626,22 +626,8 @@
 r')%0A
-    count = 0%0A
     
@@ -671,113 +671,145 @@
     
-count += 1%0A        if count %25 2 == 0: continue%0A        name = re.sub('%5B:,%5D',%22 %22, name%5B:-1%5D).split(%22 %22)%5B0%5D
+name = re.sub('%5B:,%5D',%22 %22, name%5B:-1%5D).split(%22 %22)%5B0%5D%0A        if name%5B-1%5D == %22'%22: continue # only need one of forward and reverse complement
 %0A   

Update choice of node and its reverse complements to reflect changes in latest version of SPAdes Update help message as per issue #21