#from Bio.Alphabet import IUPAC
and modify the syntax in the definition of gfa_to_contigs and gfa2_to_contigs functions, to match the new SeqRecord style:
(https://biopython.org/wiki/Alphabet)
def gfa_to_contigs(args):
for lib in args.libs['gfa']:
lib_dir = os.path.dirname(os.path.abspath(lib.name) + '/')
if not os.path.exists(lib_dir):
os.makedirs(lib_dir)
prevdir = os.getcwd()
os.chdir(lib_dir)
with open('contigs.fasta', 'w') as out:
lines = [line.rstrip('\n') for line in open(lib.path[0])]
for line in lines:
parts = line.split()
if parts[0] == 'S':
# record = SeqRecord(Seq(parts[2], IUPAC.ambiguous_dna), id=parts[1], description='')
record = SeqRecord(Seq(parts[2]), id=parts[1],
description='',
annotations={'molecule_type': 'DNA'})
SeqIO.write(record, out, 'fasta')
if args.contigs == None:
args.contigs = []
args.contigs.append(os.path.abspath('contigs.fasta'))
os.chdir(prevdir)
def gfa2_to_contigs(args):
for lib in args.libs['gfa2']:
lib_dir = os.path.dirname(os.path.abspath(lib.name) + '/')
if not os.path.exists(lib_dir):
os.makedirs(lib_dir)
prevdir = os.getcwd()
os.chdir(lib_dir)
with open('contigs.fasta', 'w') as out:
lines = [line.rstrip('\n') for line in open(lib.path[0])]
for line in lines:
parts = line.split()
if parts[0] == 'S':
# record = SeqRecord(Seq(parts[3], IUPAC.ambiguous_dna), id=parts[1], description='')
record = SeqRecord(Seq(parts[3]), id=parts[1],
description='',
annotations={'molecule_type': 'DNA'})
SeqIO.write(record, out, 'fasta')
if args.contigs == None:
args.contigs = []
args.contigs.append(os.path.abspath('contigs.fasta'))
os.chdir(prevdir)
Dear Olga,
for newer installations, I suggest you to comment line 11
and modify the syntax in the definition of gfa_to_contigs and gfa2_to_contigs functions, to match the new SeqRecord style:
(https://biopython.org/wiki/Alphabet)