Skip to content
Snippets Groups Projects
Commit 5067920a authored by Alexis Mergez's avatar Alexis Mergez
Browse files

GFAvc v0.4.2

Sorting paths by name
parent c78b2b80
No related branches found
Tags v1.10.8
No related merge requests found
Pipeline #257809 waiting for manual action
......@@ -5,14 +5,14 @@ GFAvc: GFA version converter.
Convert GFA from v1.1 to v1.0 (Convert walk to paths) and vice versa.
@author: alexis.mergez@inrae.fr
@version: 0.4.1
@version: 0.4.2
"""
import re
import argparse
import os
import gzip
version = "0.4.1"
version = "0.4.2"
## Argument parser
arg_parser = argparse.ArgumentParser(description='GFAvc: GFA version converter')
......@@ -92,6 +92,9 @@ def gfa11_to_gfa10(gfa1_file = args.GFA1):
_[1] = "VN:Z:1.0"
gfa[0] = "\t".join(_)
# Used to store paths are order them at the end
paths_dict = {}
#% Iterating in reverse to put paths at the end.
for lineID in sorted(range(len(gfa)), reverse = True):
if gfa[lineID][0] == "S" :
......@@ -115,13 +118,19 @@ def gfa11_to_gfa10(gfa1_file = args.GFA1):
newLine = ['P', name, ','.join(path), '*']
gfa.append('\t'.join(newLine))
paths_dict[name] = '\t'.join(newLine)
#gfa.append('\t'.join(newLine))
#% Moving path lines to the end
if gfa[lineID][0] == "P" :
curLine = gfa.pop(lineID)
gfa.append(curLine)
name = curLine.split('\t')[1]
paths_dict[name] = '\t'.join(curLine)
#gfa.append(curLine)
for name in sorted(paths_dict.keys()):
gfa.append(paths_dict[name])
return gfa
......@@ -141,6 +150,9 @@ def gfa10_to_gfa11(gfa_file = args.GFA, index = index):
sign = {"+": ">", "-": "<"}
samples = []
# Used to store paths are order them at the end
paths_dict = {}
#% Iterating in reverse to put walks at the end.
for lineID in sorted(range(len(gfa)), reverse = True):
......@@ -169,15 +181,22 @@ def gfa10_to_gfa11(gfa_file = args.GFA, index = index):
newLine = ['W'] + ID + RANGE + [f"{''.join(walk)}"]
samples.append(ID[0])
gfa.append('\t'.join(newLine))
paths_dict[splittedID[0]] = '\t'.join(newLine)
#gfa.append('\t'.join(newLine))
#% Moving walk lines to the end
if gfa[lineID][0] == "W" :
curLine = gfa.pop(lineID)
gfa.append(curLine)
name = '#'.join(curLine.split('\t')[1:4])
paths_dict[name] = '\t'.join(curLine)
#gfa.append(curLine)
for name in sorted(paths_dict.keys()):
gfa.append(paths_dict[name])
samples = list(set(samples))
#% Changing version number in header
assert gfa[0].split('\t')[1] == "VN:Z:1.0"
_ = gfa[0].split('\t')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment