Commit 17f02c8a authored by Floreal Cabanettes's avatar Floreal Cabanettes
Browse files

Fix launch on cluster

parent 988f1c23
......@@ -3,7 +3,10 @@
import os
import re
import shutil
from dgenies.lib.paf import Index
try:
from dgenies.bin.index import Index
except ModuleNotFoundError:
from index import Index
from Bio import SeqIO
......
......@@ -5,6 +5,54 @@ import re
import gzip
class Index:
def __init__(self):
pass
@staticmethod
def load(index_file, merge_splits=False):
with open(index_file, "r") as idx_q_f:
abs_start = {}
abs_current_start = 0
c_len = 0
name = idx_q_f.readline().strip("\n")
order = []
contigs = {}
reversed_c = {}
for line in idx_q_f:
parts = line.strip("\n").split("\t")
id_c = parts[0]
is_split = False
if merge_splits:
match = re.match(r"(.+)_###_\d+", id_c)
if match is not None:
id_c = match.group(1)
is_split = True
len_c = int(parts[1])
if len(parts) > 2:
reversed_c[id_c] = parts[2] == "1"
else:
reversed_c[id_c] = False
if not is_split or (is_split and id_c not in order):
order.append(id_c)
abs_start[id_c] = abs_current_start
contigs[id_c] = len_c
else:
contigs[id_c] += len_c
c_len += len_c
abs_current_start += len_c
return name, order, contigs, reversed_c, abs_start, c_len
@staticmethod
def save(index_file, name, contigs, order, reversed_c):
with open(index_file, "w") as idx:
idx.write(name + "\n")
for contig in order:
idx.write("\t".join([contig, str(contigs[contig]), "1" if reversed_c[contig] else "0"])
+ "\n")
def index_file(fasta_path, fasta_name, out, write_fa=None):
has_header = False
next_header = False # True if next line must be a header line
......
......@@ -18,7 +18,7 @@ import traceback
from pathlib import Path
from urllib import request, parse
from dgenies.bin.split_fa import Splitter
from dgenies.bin.build_index import index_file
from dgenies.bin.index import index_file
from dgenies.bin.filter_contigs import Filter
from dgenies.bin.merge_splitted_chrms import Merger
from dgenies.bin.sort_paf import Sorter
......
......@@ -11,54 +11,7 @@ mpl.use('Agg')
from matplotlib import pyplot as plt
import json
from collections import Counter
class Index:
def __init__(self):
pass
@staticmethod
def load(index_file, merge_splits=False):
with open(index_file, "r") as idx_q_f:
abs_start = {}
abs_current_start = 0
c_len = 0
name = idx_q_f.readline().strip("\n")
order = []
contigs = {}
reversed_c = {}
for line in idx_q_f:
parts = line.strip("\n").split("\t")
id_c = parts[0]
is_split = False
if merge_splits:
match = re.match(r"(.+)_###_\d+", id_c)
if match is not None:
id_c = match.group(1)
is_split = True
len_c = int(parts[1])
if len(parts) > 2:
reversed_c[id_c] = parts[2] == "1"
else:
reversed_c[id_c] = False
if not is_split or (is_split and id_c not in order):
order.append(id_c)
abs_start[id_c] = abs_current_start
contigs[id_c] = len_c
else:
contigs[id_c] += len_c
c_len += len_c
abs_current_start += len_c
return name, order, contigs, reversed_c, abs_start, c_len
@staticmethod
def save(index_file, name, contigs, order, reversed_c):
with open(index_file, "w") as idx:
idx.write(name + "\n")
for contig in order:
idx.write("\t".join([contig, str(contigs[contig]), "1" if reversed_c[contig] else "0"])
+ "\n")
from dgenies.bin.index import Index
class Paf:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment