From 197ebed48e55f047d8a06834f7a4cbbd4388948e Mon Sep 17 00:00:00 2001 From: oboulle <olivier.boulle@inria.fr> Date: Thu, 18 Aug 2022 09:28:09 +0200 Subject: [PATCH] select random fragments --- cluster_consensus.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cluster_consensus.py b/cluster_consensus.py index e614c15..047a5f3 100755 --- a/cluster_consensus.py +++ b/cluster_consensus.py @@ -5,6 +5,7 @@ import sys import networkx as nx import time import argparse +import random # used to get the consensus fragments from a directory of fragments clusters @@ -124,7 +125,6 @@ def fragConsensus(frag_list, frag_length): if len(cluster) != 0: clusters_list.append(cluster) kmers_positions[kmer] = clusters_list - # construct a list of pkmers # a pkmer is an object containing a kmer & his average_position & weight # example: ACCTGAGT:23:10 @@ -222,13 +222,15 @@ def consensusOnFragDir(frag_dir_path, output_path, frag_length, n_reads): cluster_file.close() if n_reads is not None: - frag_list = frag_list[:n_reads] + frag_list = random.sample(frag_list, min(len(frag_list), n_reads)) consensus_sequence = fragConsensus(frag_list, frag_length) #if len(consensus_sequence) >= 2*frag_length/3: - + consensus_file.write(">consensus_of_"+cluster_filename+"\n") consensus_file.write(consensus_sequence+"\n") + #if len(consensus_sequence) < 2*frag_length/3: + #print(cluster_filename) computed_consensus += 1 consensus_file.close() -- GitLab