From 5b2c2706555a4ff047c4678e258843c31d6f4940 Mon Sep 17 00:00:00 2001 From: Helene RIMBERT <helene.rimbert@inrae.fr> Date: Thu, 29 Jun 2023 15:31:50 +0200 Subject: [PATCH] IMPROVE: initialise chromosomeMap dict while reading input GFF --- bin/renameGffID.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/bin/renameGffID.py b/bin/renameGffID.py index 22184bf..e80826a 100755 --- a/bin/renameGffID.py +++ b/bin/renameGffID.py @@ -24,7 +24,7 @@ class renameIDs (object): self.checkInputs() # load inputs - self.loadChromosomeMap() + #self.loadChromosomeMap() # open filehandler for output files self.prepareOutputFiles() @@ -251,6 +251,14 @@ class renameIDs (object): coord=line.rstrip('\n').split('\t')[3] stop=line.rstrip('\n').split('\t')[4] geneId=self.getFeatureAttribute(gff=line, attribute='ID') + + + # check if this chromosome is in the mapping dictionaries + if (chrom not in self.chromosomeMap.keys()): + self.chromosomeMap[chrom] = chrom + self.geneMapCoord[chrom] = defaultdict() + self.newGeneMapCoord[chrom] = defaultdict() + if featureType == 'gene': while coord in self.geneMapCoord[chrom].keys(): sys.stderr.write(" WARNING: gene {} has same coordinate as gene {} \n".format(geneId, self.geneMapCoord[chrom][coord])) @@ -289,9 +297,6 @@ class renameIDs (object): for line in maprecord.readlines(): if not line.startswith('#'): (name, id) = line.rstrip('\n').split('\t') - #self.chromosomeMap[name] = id - #self.geneMapCoord[name] = defaultdict() - #self.newGeneMapCoord[name] = defaultdict() self.chromosomeMap[id] = name self.geneMapCoord[id] = defaultdict() self.newGeneMapCoord[id] = defaultdict() -- GitLab