Hi Manuel! I tried this but the generated SAM looks fine. Still i get the wrong coordinates displayed- I simplified the loop to a basic output (cpp attached). So i tried to increase the filesize to see what happens: head -n 70000 test.sam > bug2.sam illumina_80bp_3kb.000000571 19626,19706 head -n 80000 test.sam > bug2.sam illumina_80bp_3kb.000000571 19628,19708 head -n 90000 test.sam > bug2.sam illumina_80bp_3kb.000000571 19629,19709 Pretty weired! Looks to me like an overflow problem? I am running a Mac with OSX... Could you check if you run into the same problems on windows? I don't want to spam the list with parts the SAM file but you can download the entire sam file from here: http://rapidshare.com/files/453617711/test.sam Thanks! best, mat Am 3/18/11 5:06 PM, schrieb Manuel Holtgrewe: Another thing you could try is to read the SAM file, and write it out immediately after and see whether there are any problems with the generated SAM. |
//============================================================================ // Name : SAMtest.cpp // Author : // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #include <iostream> #include <iostream> #include <sstream> #include <seqan/sequence.h> // CharString, ... #include <seqan/file.h> // to stream a CharString into cout #include <seqan/misc/misc_cmdparser.h> #include <seqan/store.h> #include <seqan/file.h> #include <seqan/graph_types.h> using namespace seqan; int main(int argc, const char* argv[]) { CommandLineParser cmdParser("parser"); addOption(cmdParser,CommandLineOption("s","sam", "SAM file(s) with aligned reads", OptionType::String)); if(!parse(cmdParser,argc,argv,std::cerr)){ std::cerr << "Error parsing command line. Check the mandatory parameters." << std::endl; help(cmdParser,std::cerr); return -1; } std::string SAMFileName; typedef FragmentStore<> TFragmentStore; TFragmentStore fragStore; typedef TFragmentStore::TAlignedReadStore ARStore; typedef TFragmentStore::TReadStore TReadStore; typedef Value<TReadStore>::Type TReadStoreElement; typedef unsigned int TID; typedef unsigned int TValue; if(getOptionValueLong(cmdParser,"sam",SAMFileName)&&(length(SAMFileName)>0)){ std::cout << "Loading SAM file " << SAMFileName << std::endl; std::fstream strmReads(SAMFileName.c_str(), std::fstream::in | std::fstream::binary); if(!strmReads.is_open()){ std::cerr << "Couldn't open file " << SAMFileName.c_str() << std::endl; return -1; } else{ read(strmReads, fragStore, seqan::Sam()); std::cout << "Reads cached..." << std::endl; unsigned int nrAlignments = length(fragStore.alignedReadStore); //sortAlignedReads(fragStore.alignedReadStore, SortPairMatchId()); //sortAlignedReads(fragStore.alignedReadStore, SortId()); //std::fstream strmWrite("/Users/mat/test2.sam",std::fstream::out | std::fstream::binary); //write(strmWrite,fragStore,seqan::Sam()); TID lastPairMatchId = TReadStoreElement::INVALID_ID; TID id1,id2,cId1,cId2; //Iterate over aligned reads (sorted by pairMatchId) for (unsigned int n=0;n<nrAlignments;++n){ //if current alignment has a mate... std::cout << "n:" << n << " id: " << fragStore.alignedReadStore[n].id << std::endl; id1 = fragStore.alignedReadStore[n].id; TValue start1 = fragStore.alignedReadStore[id1].beginPos; TValue end1 = fragStore.alignedReadStore[id1].endPos; //TValue l1 = length(fragStore.contigStore[cId1].seq); // TValue l2 = length(fragStore.contigStore[cId2].seq); std::cout << fragStore.readNameStore[fragStore.alignedReadStore[id1].readId]<<std::endl; std::cout << start1 << "," << end1 << std::endl; if(fragStore.readNameStore[fragStore.alignedReadStore[id1].readId]=="illumina_80bp_3kb.000000571"){ //std::cout << fragStore.readNameStore[fragStore.alignedReadStore[id1].readId]<<std::endl; //std::cout << start1 << "," << end1 << std::endl; exit(0); } /*if(fragStore.alignedReadStore[n].pairMatchId!=TReadStoreElement::INVALID_ID){ //indexed by pairMatchID if(lastPairMatchId == fragStore.alignedReadStore[n].pairMatchId){ id2 = fragStore.alignedReadStore[n].id; cId2 = fragStore.alignedReadStore[n].contigId; //now check if contigs do not span... if(cId1==cId2){ //Now check coordinates TValue start1 = fragStore.alignedReadStore[id1].beginPos; TValue end1 = fragStore.alignedReadStore[id1].endPos; TValue start2 = fragStore.alignedReadStore[id2].beginPos; TValue end2 = fragStore.alignedReadStore[id2].endPos; //TValue l1 = length(fragStore.contigStore[cId1].seq); // TValue l2 = length(fragStore.contigStore[cId2].seq); if(fragStore.readNameStore[fragStore.alignedReadStore[id1].readId]=="illumina_80bp_3kb.000000571"){ std::cout << fragStore.readNameStore[fragStore.alignedReadStore[id1].readId]<<std::endl; std::cout << fragStore.readNameStore[fragStore.alignedReadStore[id2].readId]<<std::endl; std::cout << start1 << "," << end1 << " and " << start2 << "," << end2 << std::endl; } } lastPairMatchId = TReadStoreElement::INVALID_ID; } else { id1 = fragStore.alignedReadStore[n].id; cId1 = fragStore.alignedReadStore[n].contigId; lastPairMatchId = fragStore.alignedReadStore[n].pairMatchId; } }*/ } } } else { std::cout << "No SAM file specified...\n" << std::endl; } return 0; }