Mapper *PredictionTranscript_getcDNACoordMapper(PredictionTranscript *trans) { Mapper *mapper; int start = 1; int i; Vector *translateable; if (trans->exonCoordMapper) { return trans->exonCoordMapper; } // // the mapper is loaded with OBJECTS in place of the IDs !!!! // the objects are the contigs in the exons // // NIY: What should coordsystems be? mapper = Mapper_new( "cdna", "genomic", NULL, NULL ); translateable = PredictionTranscript_getAllTranslateableExons(trans); for (i=0; i<Vector_getNumElement(translateable); i++) { PredictionExon *exon = Vector_getElementAt(translateable,i); PredictionExon_loadGenomicMapper((Exon*)exon, mapper, (IDType)trans, start); start += PredictionExon_getLength(exon); } trans->exonCoordMapper = mapper; Vector_free(translateable); return mapper; }
AssemblyMapper *AssemblyMapper_new(AssemblyMapperAdaptor *adaptor, Vector *coordSystems) { AssemblyMapper *am; if ((am = (AssemblyMapper *)calloc(1, sizeof(AssemblyMapper))) == NULL) { fprintf(stderr, "ERROR: Failed allocating space for AssemblyMapper\n"); return NULL; } am->objectType = CLASS_ASSEMBLYMAPPER; am->funcs = &assemblyMapperFuncs; Object_incRefCount(am); AssemblyMapper_setAdaptor(am, adaptor); AssemblyMapperAdaptor_cacheSeqIdsWithMultAssemblies(adaptor); if ( Vector_getNumElement(coordSystems) != 2 ) { fprintf(stderr, "Can only map between two coordinate systems %d were provided\n", Vector_getNumElement(coordSystems)); exit(1); } // Set the component and assembled coordinate systems AssemblyMapper_setAssembledCoordSystem(am, Vector_getElementAt(coordSystems, 0)); AssemblyMapper_setComponentCoordSystem(am, Vector_getElementAt(coordSystems, 1)); AssemblyMapper_setAssembledRegister(am, IDHash_new(IDHASH_MEDIUM)); AssemblyMapper_setComponentRegister(am, IDHash_new(IDHASH_MEDIUM)); // We load the mapper calling the 'ASSEMBLED' the 'from' coord system // and the 'COMPONENT' the 'to' coord system. AssemblyMapper_setMapper(am, Mapper_new("assembled", "component", AssemblyMapper_getAssembledCoordSystem(am), AssemblyMapper_getComponentCoordSystem(am))); AssemblyMapper_setMaxPairCount(am, AM_DEFAULT_MAX_PAIR_COUNT); return am; }
int main(int argc, char *argv[]) { initEnsC(argc, argv); Mapper *mapper = Mapper_new( "rawcontig", "virtualcontig", NULL, NULL ); int nToLoad = loadSGPDump(mapper, 0 ); // loading done successfully ok(1, nToLoad == 100); { // transform a segment entirely within the first rawcontig int testOutput[][4] = {1, 2, 5, -1}; testTransform (mapper, 627012, 2, 5, -1, "rawcontig", testOutput, NumOutput(testOutput)); } { // now a split coord int testOutput[][4] = { {314696, 31917, 31937, -1}, {341, 126, 59773, -1}, {315843, 5332, 5963, +1} }; testTransform (mapper, 1, 383700, 444000, +1, "virtualcontig",testOutput, NumOutput(testOutput)); } { // now a simple gap int testOutput[][4] = { { 627011, 7447, 7507, +1 }, { 1, 273762, 273781, 0 } }; testTransform (mapper, 1, 273701, 273781, +1, "virtualcontig", testOutput, NumOutput(testOutput)); } // // check if the mapper can do merging // mapper = Mapper_new( "asm1", "asm2", NULL, NULL ); Mapper_addMapCoordinates(mapper, 1, 1, 10, 1, 1, 101, 110 ); Mapper_addMapCoordinates(mapper, 1, 21, 30, 1, 1, 121, 130 ); Mapper_addMapCoordinates(mapper, 1, 11, 20, 1, 1, 111, 120 ); { int testOutput[][4] = {{ 1, 105, 125, 1 }}; testTransform(mapper, 1, 5, 25, 1, "asm1", testOutput, NumOutput(testOutput)); } // // Slightly differnt merge case // mapper = Mapper_new( "asm1", "asm2", NULL, NULL ); Mapper_addMapCoordinates(mapper, 1, 1, 10, 1, 1, 101, 110 ); Mapper_addMapCoordinates(mapper, 1, 21, 30, 1, 1, 121, 130 ); Mapper_addMapCoordinates(mapper, 1, 12, 20, 1, 1, 112, 120 ); { int testOutput[][4] = { { 1, 105, 110, 1 }, { 1, 11, 11, 0 }, { 1, 112, 125, 1 } }; testTransform( mapper, 1, 5, 25, 1, "asm1" , testOutput, NumOutput(testOutput)); } // // dont merge on wrong orientation // mapper = Mapper_new( "asm1", "asm2", NULL, NULL ); Mapper_addMapCoordinates(mapper, 1, 1, 10, 1, 1, 101, 110 ); Mapper_addMapCoordinates(mapper, 1, 21, 30, 1, 1, 121, 130 ); Mapper_addMapCoordinates(mapper, 1, 11, 20, -1, 1, 111, 120 ); { int testOutput[][4] = { { 1, 105, 110, 1 }, { 1, 111, 120, -1 }, { 1, 121, 125, 1 } }; testTransform( mapper, 1, 5, 25, 1, "asm1" , testOutput, NumOutput(testOutput)); } // // can reverse strands merge? // mapper = Mapper_new( "asm1", "asm2", NULL, NULL ); Mapper_addMapCoordinates(mapper, 1, 1, 10, -1, 1, 121, 130 ); Mapper_addMapCoordinates(mapper, 1, 21, 30, -1, 1, 101, 110 ); Mapper_addMapCoordinates(mapper, 1, 11, 20, -1, 1, 111, 120 ); { int testOutput[][4] = {{ 1, 106, 126, -1 } }; testTransform( mapper, 1, 5, 25, 1, "asm1", testOutput, NumOutput(testOutput)); } // // normal merge, not three // mapper = Mapper_new( "asm1", "asm2", NULL, NULL ); Mapper_addMapCoordinates(mapper, 1, 1, 10, 1, 1, 101, 110 ); Mapper_addMapCoordinates(mapper, 1, 11, 20, 1, 1, 111, 120 ); Mapper_addMapCoordinates(mapper, 1, 22, 30, 1, 1, 132, 140 ); Mapper_addMapCoordinates(mapper, 1, 51, 70, 1, 1, 161, 180 ); Mapper_addMapCoordinates(mapper, 1, 31, 35, 1, 1, 141, 145 ); { int testOutput[][4] = { { 1, 105, 120, 1 }, { 1, 21, 21, 0 }, { 1, 132, 145, 1 }, { 1, 36, 45, 0 } }; testTransform( mapper, 1, 5, 45, 1, "asm1" , testOutput, NumOutput(testOutput)); } // // test tranformation of 'insertion' coordinates where end = start -1 // mapper = Mapper_new("asm1", "asm2", NULL, NULL); Mapper_addMapCoordinates(mapper,1, 1, 10, 1, 2, 101, 110); Mapper_addMapCoordinates(mapper,1, 11, 20, -1, 3, 1, 10); { // boundary insert, expect 2 edge inserts back int testOutput[][4] = { {2, 111, 110, 1}, {3, 11, 10, -1} }; testTransform(mapper, 1, 11, 10, 1, "asm1", testOutput, NumOutput(testOutput)); } { // edge insert, negative strand, expect edge insert negative strand int testOutput[][4] = {{2, 101, 100, -1}}; testTransform(mapper, 1, 1, 0, -1, "asm1", testOutput, NumOutput(testOutput)); } { // normal case, expect single insert in middle int testOutput[][4] = {{2, 102, 101, 1}}; testTransform(mapper, 1, 2, 1, 1, "asm1", testOutput, NumOutput(testOutput)); } { // expect a gap int testOutput[][4] = {{1, 100, 200, 0}}; testTransform(mapper, 1, 100, 200, 1, "asm1", testOutput, NumOutput(testOutput)); } return 0; }