@@ -51,6 +51,8 @@ class AnnotationProcessor {
5151 // (this.IdParents[parents[0]] in addChildren function).
5252 this . IdParents = { } ;
5353 this . indexIdParent = 0 ;
54+
55+ this . cds_ids = { } ;
5456 }
5557
5658 /**
@@ -358,6 +360,8 @@ class AnnotationProcessor {
358360 features . attributes ,
359361 ) ;
360362 this . geneLevelHierarchy . attributes = attributesFiltered ;
363+
364+ this . geneLevelHierarchy . subfeatures = [ ] ;
361365 } else {
362366 // Create an array if not exists for the subfeatures (exons, cds ...) of
363367 // the gene.
@@ -387,7 +391,18 @@ class AnnotationProcessor {
387391 ) ;
388392 }
389393
390- const identifiant = features . ID
394+ let identifiant = features . ID
395+
396+ // Manage case of discontinuous CDS: Same ID -> we add a suffix to avoid crashing
397+ if ( typeAttr === 'CDS' ) {
398+ if ( identifiant in this . cds_ids ) {
399+ identifiant = identifiant + "." + this . cds_ids [ identifiant ]
400+ this . cds_ids [ identifiant ] += 1
401+ } else {
402+ this . cds_ids [ identifiant ] = 1
403+ }
404+ }
405+
391406 let proteinID
392407
393408 // Complete ID parents.
@@ -446,7 +461,7 @@ class AnnotationProcessor {
446461 GeneSchema . validate ( geneWithoutId ) ;
447462 } catch ( err ) {
448463 logger . error ( err )
449- throw new Error ( 'There is something wrong with the gene collection schema ' ) ;
464+ throw new Error ( 'Current gene is not valid, stopping ' ) ;
450465 }
451466 return true ;
452467 } ;
@@ -528,7 +543,7 @@ class AnnotationProcessor {
528543 // Increment.
529544 this . nAnnotation += 1 ;
530545
531- const protein_ids = this . geneLevelHierarchy . subfeatures . flatMap ( children => {
546+ const protein_ids = this . geneLevelHierarchy . subfeatures . flatMap ( children => {
532547 if ( typeof children . protein_id === 'undefined' ) {
533548 return [ ]
534549 } else {
@@ -538,6 +553,9 @@ class AnnotationProcessor {
538553
539554 this . geneLevelHierarchy . children = this . geneLevelHierarchy . children . concat ( protein_ids )
540555
556+ // Validate schema before adding to bulk
557+ this . isValidateGeneSchema ( ) ;
558+
541559 // Add to bulk operation.
542560 this . geneBulkOperation . insert ( this . geneLevelHierarchy )
543561
@@ -547,14 +565,16 @@ class AnnotationProcessor {
547565 this . shiftSequence = 0 ;
548566 this . IdParents = { } ;
549567 this . indexIdParent = 0 ;
568+ this . cds_ids = { } ;
550569
551570 // Init new gene.
552571 this . initGeneHierarchy ( features ) ;
553572
554573 // Arbitrary break up of batch size to save ram
555574 if ( this . geneBulkOperation . length > 500 ) {
556575 this . isReset = true
557- return this . geneBulkOperation . execute ( ) ;
576+ let execute = Meteor . wrapAsync ( this . geneBulkOperation . execute , this . geneBulkOperation ) ;
577+ return execute ( )
558578 }
559579 }
560580 } else {
0 commit comments