Page MenuHomec4science

sequence_collection.py
No OneTemporary

File Metadata

Created
Thu, Jul 10, 06:44

sequence_collection.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-
" module containing class ClusterCollection"
##########################################################################
##########################################################################
class SequenceCollection(object):
"""
class SequenceCollection: stores the sequences and have several function to access these sequences
"""
# ------------------------------------------------------------------ #
# Constructors/Destructors #
# ------------------------------------------------------------------ #
def __init__(self):
"""__init__: the main member is an empty dictionnary that will be used to store the sequences"""
# Members ---------------------- #
# dictionnary containing the sequence collection
# la cle est une info contenue dans la sequence, mais je ne vois pas comment eviter ce doublon
# dictionnary dict
self.dict = {}
# int length
self.length = 0
def __del__(self):
"""__del__: not implemented """
pass
def addSequence(self,new_sequence):
"""addSequence : add the sequence to the present collection) """
self.dict[new_sequence.seqID] = new_sequence
return 0
def removeSequences(self,list_of_seqIDs):
"""removeSequence : remove the sequences which id correspond to the seqIDs in the list """
for seqID in list_of_seqIDs :
del self.dict[seqID]
return 0
def getSequence(self,seqID):
"""getSequence : return the sequence in the collection corresponding to the argument seqID """
return self.dict[seqID]
def modifyClusterID(self,previous_cluster_id,new_cluster_id):
"""modifyClusterID : modify the cluster id attributed to a sequence (is mainly useful if the cluster files is from 'dbc' clustering software) """
for seqID,current_sequence in self.dict.iteritems():
if current_sequence.seq_cluster_id==previous_cluster_id:
self.dict[seqID].seq_cluster_id=new_cluster_id
return 0
def actualizeLenght(self):
""" actualizeLenght : return the number of sequences of the sequence collection """
return len(self.dict)
##########################################################################
if __name__ == '__main__':
test = ClusterCollection()

Event Timeline