Example #1
0
//컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴
//Procedure		ClearMessagesPri
//Author		Robert Slater
//Date			Thu 3 Jun 1999
//
//Description	
//
//Inputs		
//
//Returns	
//
//------------------------------------------------------------------------------
void	MessageBuffer::ClearMessagesPri(SLong	priority)
{
	if (priority != GAP)										//RJS 24Jun99
	{
		SLong	index;
		for (index = 0; index < NEWBUFFERSIZE; index++)
		{
			if (newbuffer[index].priority == priority)
			{
				newbuffer[index].priority = GAP;
				noBufferedMessages--;
			}
		}

		RemoveGaps(newbuffer,newbuffertop,NEWBUFFERSIZE);
	}
//DeadCode DAW 25Jun99 	SLong	index;
//DeadCode DAW 25Jun99 	for (index = 0; index < NEWBUFFERSIZE; index++)
//DeadCode DAW 25Jun99 	{
//DeadCode DAW 25Jun99 		if (newbuffer[index].priority == priority)
//DeadCode DAW 25Jun99 			newbuffer[index].priority = GAP;
//DeadCode DAW 25Jun99 	}
//DeadCode DAW 25Jun99 
//DeadCode DAW 25Jun99 	RemoveGaps(newbuffer,newbuffertop,NEWBUFFERSIZE);
}
Example #2
0
//컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴
//Procedure		ClearMessageMsg
//Author		Robert Slater
//Date			Thu 13 May 1999
//
//Description	Looks for new messages of a particular type
//				and dumps them.
//
//Inputs
//
//Returns
//
//------------------------------------------------------------------------------
void	MessageBuffer::ClearMessagesMsg(SLong	messagetype)
{
    SLong	index;
    for (index = 0; index < NEWBUFFERSIZE; index++)
    {
        if ((newbuffer[index].priority != GAP)
                &&	(newbuffer[index].messagetype == messagetype))
        {
            newbuffer[index].priority = GAP;
            noBufferedMessages--;
        }
    }

    RemoveGaps(newbuffer,newbuffertop,NEWBUFFERSIZE);
}
Example #3
0
//컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴
//Procedure		ClearMessagesMsg
//Author		Robert Slater
//Date			Mon 14 Jun 1999
//
//Description
//
//Inputs
//
//Returns
//
//------------------------------------------------------------------------------
void	MessageBuffer::ClearMessagesMsg(SLong	messagetype, ItemPtr	theTarget)
{
    SLong	index;
    for (index = 0; index < NEWBUFFERSIZE; index++)
    {
        if ((newbuffer[index].priority != GAP)					//RJS 24Jun99
                &&	(newbuffer[index].messagetype == messagetype)
                &&	(newbuffer[index].target == theTarget))
        {
            newbuffer[index].priority = GAP;
            noBufferedMessages--;
        }
    }

    RemoveGaps(newbuffer,newbuffertop,NEWBUFFERSIZE);
}
int main(int argc, char* argv[])
{
    std::string outFileName;
    unsigned contextLength = 5;
    int minSamples = 500;
    int maxSamples = 1000;
    if (argc < 3) {
        PrintUsage();
        std::exit(EXIT_FAILURE);
    }

    int argi = 1;
    std::string cmpH5FileName;
    cmpH5FileName = argv[argi++];
    outFileName = argv[argi++];
    int minAverageQual = 0;
    bool onlyMaxLength = false;

    while (argi < argc) {
        if (strcmp(argv[argi], "-contextLength") == 0) {
            contextLength = atoi(argv[++argi]);
        } else if (strcmp(argv[argi], "-minSamples") == 0) {
            minSamples = atoi(argv[++argi]);
        } else if (strcmp(argv[argi], "-maxSamples") == 0) {
            maxSamples = atoi(argv[++argi]);
        } else if (strcmp(argv[argi], "-onlyMaxLength") == 0) {
            onlyMaxLength = true;
        } else {
            PrintUsage();
            std::cout << "ERROR, bad option: " << argv[argi] << std::endl;
            std::exit(EXIT_FAILURE);
        }
        ++argi;
    }
    std::map<std::string, ScoredLength> maxLengthMap;
    OutputSampleListSet samples(contextLength);
    SMRTSequence read;

    std::ofstream sampleOut;
    CrucialOpen(outFileName, sampleOut, std::ios::out | std::ios::binary);
    int fileNameIndex;

    int numContextsReached = 0;
    int numContexts = 1 << (contextLength * 2);
    ReaderAgglomerate reader;
    samples.keyLength = contextLength;
    HDFCmpFile<CmpAlignment> cmpReader;
    cmpReader.IncludeField("QualityValue");
    cmpReader.IncludeField("DeletionQV");
    cmpReader.IncludeField("InsertionQV");
    cmpReader.IncludeField("SubstitutionQV");
    cmpReader.IncludeField("SubstitutionTag");
    cmpReader.IncludeField("DeletionTag");
    cmpReader.IncludeField("PulseIndex");
    cmpReader.IncludeField("WidthInFrames");
    cmpReader.IncludeField("PreBaseFrames");

    if (cmpReader.Initialize(cmpH5FileName, H5F_ACC_RDWR) == 0) {
        std::cout << "ERROR, could not open the cmp file." << std::endl;
        std::exit(EXIT_FAILURE);
    }
    std::cout << "Reading cmp file." << std::endl;

    CmpFile cmpFile;

    cmpReader.ReadAlignmentDescriptions(cmpFile);
    cmpReader.ReadStructure(cmpFile);
    std::cout << "done reading structure." << std::endl;
    int alignmentIndex;
    int nAlignments = cmpReader.alnInfoGroup.GetNAlignments();
    std::vector<int> alignmentToBaseMap;

    for (alignmentIndex = 0; alignmentIndex < nAlignments and !samples.Sufficient();
         alignmentIndex++) {
        //
        // For ease of use, store the length of the alignment to make another model.
        //

        ByteAlignment alignmentArray;
        cmpReader.ReadAlignmentArray(alignmentIndex, alignmentArray);
        Alignment alignment;
        ByteAlignmentToAlignment(alignmentArray, alignment);
        std::string readSequence, refSequence;
        readSequence.resize(alignmentArray.size());
        refSequence.resize(alignmentArray.size());
        DNASequence readDNA, refDNA;

        ByteAlignmentToQueryString(&alignmentArray[0], alignmentArray.size(), &readSequence[0]);
        ByteAlignmentToRefString(&alignmentArray[0], alignmentArray.size(), &refSequence[0]);
        RemoveGaps(readSequence, readSequence);
        RemoveGaps(refSequence, refSequence);

        readDNA.seq = (Nucleotide*)readSequence.c_str();
        readDNA.length = readSequence.size();
        refDNA.seq = (Nucleotide*)refSequence.c_str();
        refDNA.length = refSequence.size();
        CmpAlignment cmpAlignment;

        cmpReader.ImportReadFromCmpH5(alignmentIndex, cmpAlignment, read);

        CreateAlignmentToSequenceMap(alignmentArray, alignmentToBaseMap);

        if (read.length < contextLength) {
            continue;
        }
        int subreadLength = (cmpFile.alnInfo.alignments[alignmentIndex].GetQueryEnd() -
                             cmpFile.alnInfo.alignments[alignmentIndex].GetQueryStart());
        if (onlyMaxLength == false) {
            samples.lengths.push_back(subreadLength);
        } else {
            int score = (cmpAlignment.GetNMatch() - cmpAlignment.GetNMismatch() -
                         cmpAlignment.GetNInsertions() - cmpAlignment.GetNDeletions());
            std::stringstream nameStrm;
            nameStrm << cmpAlignment.GetMovieId() << "_" << cmpAlignment.GetHoleNumber();
            std::string nameStr = nameStrm.str();
            if (maxLengthMap.find(nameStr) == maxLengthMap.end()) {
                maxLengthMap[nameStr] = ScoredLength(score, subreadLength);
            }
        }

        int sampleEnd = alignmentArray.size() - contextLength / 2;
        int a;
        for (a = contextLength / 2; a < sampleEnd; a++) {

            // Make sure the context begins on a real nucleotide.
            while (a < sampleEnd and ((RefChar[alignmentArray[a]] == ' '))) {
                a++;
            }

            //
            // Move ab back to an index where there are contextLength/2 non-gap
            // characters, counted by nb
            //
            int ab;  //num bases
            int ae;  //alignment end
            ab = a - 1;
            int nb = 0, ne = 0;
            while (true) {
                if (RefChar[alignmentArray[ab]] != ' ') {
                    nb++;
                }
                if (ab == 0 or nb == static_cast<int>(contextLength) / 2) break;
                ab--;
            }

            //
            // Advance ae to an index where there are contextLength/2 non-gap
            // characters, counted by ne.
            //
            ae = a + 1;
            while (ae < static_cast<int>(alignmentArray.size()) and
                   ne < static_cast<int>(contextLength) / 2) {
                if (RefChar[alignmentArray[ae]] != ' ') {
                    ne++;
                }
                ae++;
            }

            //
            // Make sure there are no edge effects that prevent a context of the correct length from being assigned.
            //
            if (nb + ne + 1 != static_cast<int>(contextLength)) {
                continue;
            }
            int ai;
            std::string context;
            for (ai = ab; ai < ae; ai++) {
                if (RefChar[alignmentArray[ai]] != ' ') {
                    context.push_back(RefChar[alignmentArray[ai]]);
                }
            }
            assert(context.size() == contextLength);
            //
            // Now create the context.
            //
            OutputSample sample;

            //
            // This context is a deletion, create that.
            //
            sample.type = OutputSample::Deletion;

            //
            // This context is either an insertion or substitution
            //
            // Look to see if the previous aligned position was an
            // insertion, and move back as far as the insertion extends.
            int aq = a - 1;
            int sampleLength;

            if (QueryChar[alignmentArray[a]] == ' ') {
                sample.type = OutputSample::Deletion;
                sampleLength = 0;
            } else if (RefChar[alignmentArray[aq]] == ' ') {

                while (aq > 0 and RefChar[alignmentArray[aq]] == ' ' and
                       QueryChar[alignmentArray[aq]] != ' ') {
                    aq--;
                }
                sample.type = OutputSample::Insertion;
                sampleLength = a - aq;
            } else if (QueryChar[alignmentArray[a]] == RefChar[alignmentArray[aq]]) {
                sample.type = OutputSample::Match;
                sampleLength = 1;
            } else {
                sample.type = OutputSample::Substitution;
                sampleLength = 1;
            }

            sample.Resize(sampleLength);
            if (sampleLength > 0) {
                int seqPos = alignmentToBaseMap[aq];
                if (seqPos < static_cast<int>(read.length)) {
                    sample.CopyFromSeq(read, seqPos, sampleLength);
                    std::string nucs;
                    for (size_t n = 0; n < sample.nucleotides.size(); n++) {
                        char c = sample.nucleotides[n];
                        assert(c == 'A' or c == 'T' or c == 'G' or c == 'C');
                        nucs.push_back(sample.nucleotides[n]);
                    }
                }
            }
            samples.AppendOutputSample(context, sample);
        }
        read.Free();
    }

    if (onlyMaxLength) {
        std::map<std::string, ScoredLength>::iterator maxScoreIt;
        for (maxScoreIt = maxLengthMap.begin(); maxScoreIt != maxLengthMap.end(); ++maxScoreIt) {
            std::cout << maxScoreIt->second.length << std::endl;
            samples.lengths.push_back(maxScoreIt->second.length);
        }
    }

    samples.Write(sampleOut);

    return 0;
}
Example #5
0
//컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴
//Procedure		AddToBuffer
//Author		Robert Slater
//Date			Tue 26 Jan 1999
//
//Description	
//
//Inputs		
//
//Returns	
//
//------------------------------------------------------------------------------
Bool	MessageBuffer::AddToBuffer(const MESSAGE_STRUC&	msg)
{
	Bool 	retval;
	SLong	index,index2;
//DeadCode RJS 20Oct00 	Bool	playerRecipient = FALSE;
	Bool	throwAway;											//RJS 02May00

	if(!ShouldHearMsg(msg,throwAway))							//RJS 02May00
		return throwAway;										//RJS 02May00

	//Block messages to dead blokes
//DEADCODE CSB 07/03/00 	if (msg.callee && msg.callee->Status.deadtime)				//RJS 05May99
//DEADCODE CSB 07/03/00 		return TRUE;											//RJS 05May99

//DEADCODE CSB 07/03/00 	if (msg.caller)
//DEADCODE CSB 07/03/00 	{
//DEADCODE CSB 07/03/00 		if (msg.caller->nationality != Manual_Pilot.ControlledAC2->nationality)
//DEADCODE CSB 07/03/00 			return TRUE;
//DEADCODE CSB 07/03/00 
//DEADCODE CSB 07/03/00 		if (msg.caller->ai.radiosilent)
//DEADCODE CSB 07/03/00 		{
//DEADCODE CSB 07/03/00 			if (msg.caller->AcIsPlayer())						//RJS 24May99
//DEADCODE CSB 07/03/00 			{
//DEADCODE CSB 07/03/00 				MESSAGE_STRUC	tmpmsg(OLDSCRIPT_SILENCE,MSG_SILENCE,NULL,msg.caller,msg.caller);
//DEADCODE CSB 07/03/00 				_Radio.TriggerMsg(tmpmsg.SetVoice(VOICE_REST));
//DEADCODE CSB 07/03/00 			}
//DEADCODE CSB 07/03/00 
//DEADCODE CSB 07/03/00 			return TRUE;									//RJS 24May99
//DEADCODE CSB 07/03/00 		}
//DEADCODE CSB 07/03/00 	}
//DEADCODE CSB 07/03/00 //DeadCode RJS 06Jul99 	else
//DEADCODE CSB 07/03/00 //DeadCode RJS 05Jul99 	{
//DEADCODE CSB 07/03/00 		if (msg.callee)
//DEADCODE CSB 07/03/00 		{
//DEADCODE CSB 07/03/00 			if (msg.callee->nationality != Manual_Pilot.ControlledAC2->nationality)
//DEADCODE CSB 07/03/00 				return TRUE;
//DEADCODE CSB 07/03/00 		}
//DEADCODE CSB 07/03/00 //DeadCode RJS 05Jul99 	}
//DEADCODE CSB 07/03/00 
//DEADCODE CSB 07/03/00 	if ((msg.callee==thePlayer) || (msg.callee==theOtherOne))	//RDH 17May99
//DEADCODE CSB 07/03/00 		playerRecipient = TRUE;									//RDH 17May99

	//Does this message already exist?...
	if(!msg.decisionhandler)											//CSB 07/03/00
	{																	//CSB 07/03/00
		for (index = 0; index < OLDBUFFERSIZE; index++)
		{
			if (	(oldbuffer[index].messagetype == msg.messagetype)
				&&	(oldbuffer[index].target == msg.target)				)
			{
				//is old repeatable?
				if (	(oldbuffer[index].visibility == VIS_3)			//RJS 01Apr99
					||	(oldbuffer[index].visibility == NOTVIS_1)
					||	(oldbuffer[index].visibility == VIS_1))
				{
	//Removed because it became annoying...							//RJS 02Jun99
	//DeadCode RJS 02Jun99 				if (!playerRecipient)							//RDH 17May99
	//DeadCode RJS 02Jun99 					return (FALSE);								//RDH 17May99
	//DeadCode RJS 02Jun99 				else											//RDH 17May99
						return (TRUE);								//RDH 17May99
				}
			}
		}

		for (index = 0; index < NEWBUFFERSIZE; index++)
		{
			if (	(newbuffer[index].messagetype == msg.messagetype)
				&&	(newbuffer[index].target == msg.target)				)
			{
				//is new repeatable?
				if (	(newbuffer[index].visibility == VIS_3)
					||	(newbuffer[index].visibility == NOTVIS_1)	)
				{
	//Removed because it became annoying...							//RJS 02Jun99
	//DeadCode RJS 02Jun99 				if (!playerRecipient)							//RDH 17May99
	//DeadCode RJS 02Jun99 					return (FALSE);								//RDH 17May99
	//DeadCode RJS 02Jun99 				else											//RDH 17May99
						return (TRUE);								//RDH 17May99
				}
			}
		}
	}
	else																//CSB 09/03/00
		msg.priority = PRI_MAX;											//CSB 09/03/00

//DeadCode PD 04Mar99 	//... or not in player group...
//DeadCode PD 04Mar99 	if (	(msg.caller != thePlayer)
//DeadCode PD 04Mar99 		||	(msg.callee != thePlayer)	)
//DeadCode PD 04Mar99 		return (FALSE);
//DEADCODE CSB 07/03/00 	if (!(msg.caller==thePlayer||msg.callee==thePlayer) &&
//DEADCODE CSB 07/03/00 		!(msg.caller==theOtherOne||msg.callee==theOtherOne))		//PD 04Mar99
//DEADCODE CSB 07/03/00 	{
//DEADCODE CSB 07/03/00 		if (!msg.blockchatter)									//RJS 06Jul99
//DEADCODE CSB 07/03/00 		{
//DEADCODE CSB 07/03/00 			AirStrucPtr	checkitem = msg.caller;						//AMM 24Jun99
//DEADCODE CSB 07/03/00 			if (	(msg.voiceindex != VOICE_REST)
//DEADCODE CSB 07/03/00 				&&	(msg.voiceindex != VOICE_PLAYER)	)
//DEADCODE CSB 07/03/00 				checkitem = msg.callee;								//AMM 24Jun99
//DEADCODE CSB 07/03/00 		
//DEADCODE CSB 07/03/00 			if (!checkitem)
//DEADCODE CSB 07/03/00 				return TRUE;
//DEADCODE CSB 07/03/00 
//DEADCODE CSB 07/03/00 			if (	checkitem->PlayerInGroup()
//DEADCODE CSB 07/03/00 				||	checkitem->PlayerInFlight()	)
//DEADCODE CSB 07/03/00 			{
//DEADCODE CSB 07/03/00 				//Overhears leader & fac/tac & dentist & tower...
//DEADCODE CSB 07/03/00 				if (checkitem->AcIsFlightLeader() || checkitem->AcIsGroupLeader())
//DEADCODE CSB 07/03/00 				{
//DEADCODE CSB 07/03/00 					if (noBufferedMessages > 8)
//DEADCODE CSB 07/03/00 						return FALSE;
//DEADCODE CSB 07/03/00 				}
//DEADCODE CSB 07/03/00 				else
//DEADCODE CSB 07/03/00 					return FALSE;
//DEADCODE CSB 07/03/00 			}
//DEADCODE CSB 07/03/00 			else
//DEADCODE CSB 07/03/00 				return FALSE;
//DEADCODE CSB 07/03/00 		}
//DEADCODE CSB 07/03/00 		else
//DEADCODE CSB 07/03/00 			return TRUE;										//RJS 06Jul99
//DEADCODE CSB 07/03/00 	}															//RJS 28May99

//	thereIsANewMessage=true;

#ifdef CHATTERTRACE
// defined in rchatter.h
	if (_Radio.damageMessage)
	{
		UWord cw=GETFPCW();
		::AfxTrace("BUFFERING: %08x\n",msg.messagecnt);
		SETFPCW(cw);
	}
#endif

	noBufferedMessages++;

	if (msg.priority >= PRI_MEDMAX)				//RJS 24Jun99
	{
		newbufferbot--;
		if (newbufferbot < 0)
			newbufferbot = NEWBUFFERSIZE-1;

		newbuffer[newbufferbot] = msg;
	}
	else
	{
		// Is this buffer full?
		if (	(newbufferbot == newbuffertop)
			&&	(newbuffer[newbufferbot].priority != GAP)	)
		{
			SLong	nogaps;

			if (msg.priority != PRI_LOW)
			{
				nogaps = RemoveGaps(newbuffer,newbuffertop,NEWBUFFERSIZE);
				if (nogaps == 0)
				{
					SLong	thisone = -1;

					for (index = newbuffertop; index < NEWBUFFERSIZE; index++)
					{
						if (newbuffer[index].priority == PRI_LOW)
						{
							thisone = index;
							break;
						}
					}

					if (thisone < 0)
					{
						for (index = 0; index < newbuffertop; index++)
						{
							if (newbuffer[index].priority == PRI_LOW)
							{
								thisone = index;
								break;
							}
						}
					}

					if (thisone > 0)
					{
						// Kill 1st low priority one found...

						newbuffer[thisone].priority = GAP;

						RemoveGaps(newbuffer,newbuffertop,NEWBUFFERSIZE);
					}
				}
			}
		}

		// Is this buffer still full?
		if (	(newbufferbot == newbuffertop)
			&&	(newbuffer[newbufferbot].priority != GAP)	)
			return(FALSE);

		newbuffer[newbuffertop] = msg;

		//is this right?....
		newbuffertop++;
		if (newbuffertop >= NEWBUFFERSIZE)
			newbuffertop = 0;
	}

	return (TRUE);
}
Example #6
0
BOOL
AlignRects(LPRECT arc, DWORD cCount, DWORD iPrimary, DWORD dwFlags)
{
    LPRECT lprc, lprcL;

    //
    // Limit for loops.
    //

    lprcL = arc + cCount;

    //
    // We don't need to get all worked up if there is only one rectangle.
    //

    if (cCount > MONITORS_MAX)
    {
        return FALSE;
    }


    if (cCount > 1)
    {
        if (!(dwFlags & CUDR_NOSNAPTOGRID))
        {
            //
            // Align monitors on 8 pixel boundaries so GDI can use the same
            // brush realization on compatible devices (BIG performance win).
            // Note that we assume the size of a monitor will be in multiples
            // of 8 pixels on X and Y.  We cannot do this for the work areas so
            // we convert them to be relative to the origins of their monitors
            // for the time being.
            //
            // The way we do this alignment is to just do the overlap/gap
            // resoluton in 8 pixel space (ie divide everything by 8 beforehand
            // and multiply it by 8 afterward).
            //
            // Note: WE CAN'T USE MULTDIV HERE because it introduces one-off
            // errors when monitors span the origin.  These become eight-off
            // errors when we scale things back up and we end up trying to
            // create DCs with sizes like 632x472 etc (not too good).  It also
            // handles rounding the wierdly in both positive and negative space
            // and we just want to snap things to a grid so we compensate for
            // truncation differently here.
            //
            for (lprc = arc; lprc < lprcL; lprc++)
            {
                RECT rc;
                int d;


                CopyRect(&rc, lprc);

                d = rc.right - rc.left;

                if (rc.left < 0)
                    rc.left -= 4;
                else
                    rc.left += 3;

                rc.left /= 8;
                rc.right = rc.left + (d / 8);

                d = rc.bottom - rc.top;

                if (rc.top < 0)
                    rc.top -= 4;
                else
                    rc.top += 3;

                rc.top /= 8;
                rc.bottom = rc.top + (d / 8);

                CopyRect(lprc, &rc);
            }
        }

        //
        // RemoveGaps is designed assuming that none of the rectangles that it
        // is passed will overlap.  Thus we cannot safely call it if we have
        // skipped the call to RemoveOverlaps or it might loop forever.
        //
        if (!(dwFlags & CUDR_NORESOLVEPOSITIONS))
        {
            RemoveOverlaps(arc, cCount);

            if (!(dwFlags & CUDR_NOCLOSEGAPS))
            {
                RemoveGaps(arc, cCount);
            }
        }

        if (!(dwFlags & CUDR_NOSNAPTOGRID))
        {
            //
            // Now return the monitor rectangles to pixel units this is a
            // simple multiply and MultDiv doesn't offer us any code size
            // advantage so (I guess that assumes a bit about the compiler,
            // but...) just do it right here.
            //
            for (lprc = arc; lprc < lprcL; lprc++)
            {
                lprc->left   *= 8;
                lprc->top    *= 8;
                lprc->right  *= 8;
                lprc->bottom *= 8;
            }
        }
    }

    if (!(dwFlags & CUDR_NOPRIMARY))
    {
        //
        // Reset all the coordinates based on the primaries position,
        // so that it is always located at 0,0
        //

        LONG dx = -((arc + iPrimary)->left);
        LONG dy = -((arc + iPrimary)->top);

        for (lprc = arc; lprc < lprcL; lprc++)
        {
            OffsetRect(lprc, dx, dy);
        }
    }

    return TRUE;
}
Example #7
0
int main(int argc, char* argv[]) {


	CommandLineParser clp;
	string cmpFileName;
	vector<int> holeNumbers;
	vector<string> patterns, refGroups;
  bool printAll = false;
	clp.RegisterStringOption("cmph5filename", &cmpFileName, "input cmp h5", false);
	clp.RegisterPreviousFlagsAsHidden();
	clp.RegisterIntListOption("holeNumbers", &holeNumbers, "hole numbers to print alignments", false);
	clp.RegisterStringListOption("pattern", &patterns, "patterns to search read names to print alignments", false);	
  clp.RegisterFlagOption("all", &printAll, "Just print all alignments.", false);
  clp.RegisterStringListOption("refgroups", &refGroups, "Reference groups to print.", false);
	clp.ParseCommandLine(argc, argv);

	
	CmpFile cmpFile;
	
	/*
	 * These readers pull information from the same pls file.
	 */
	HDFCmpFile<CmpAlignment> hdfcmpFile;

	if (hdfcmpFile.Initialize(cmpFileName) == 0) {
		cout << "ERROR, could not open the cmp file." << endl;
		exit(1);
	}
	
	hdfcmpFile.Read(cmpFile);
	
	int alignmentIndex;
	for (alignmentIndex = 0; alignmentIndex < cmpFile.alnInfo.alignments.size(); alignmentIndex++) {
		int alnHoleNumber;
		alnHoleNumber = cmpFile.alnInfo.alignments[alignmentIndex].GetHoleNumber();
		int hi;
    bool printThisAlignment = false;

    //
    // Read the alignment string.  All alignments 
    //
    int refGroupId = cmpFile.alnInfo.alignments[alignmentIndex].GetRefGroupId();
    int alnGroupId  = cmpFile.alnInfo.alignments[alignmentIndex].GetAlnGroupId();

    int refGroupIndex = hdfcmpFile.refGroupIdToArrayIndex[refGroupId];
    string readGroupName = hdfcmpFile.alnGroupIdToReadGroupName[alnGroupId];
    int readGroupIndex = hdfcmpFile.refAlignGroups[refGroupIndex]->experimentNameToIndex[readGroupName];

    string refGroupPath = cmpFile.refGroup.path[refGroupIndex];

		for (hi = 0; hi < holeNumbers.size(); hi++) {
			if (alnHoleNumber == holeNumbers[hi]) {
        printThisAlignment = true;
        break;
      }
    }
    int ri;
    for (ri = 0; ri < refGroups.size(); ri++) {
      if (refGroups[ri] == refGroupPath) {
        printThisAlignment = true;
        break;
      }
    }


    if (printThisAlignment or printAll) {
      unsigned int alignStartIndex, alignEndIndex;
      UInt offsetBegin, offsetEnd;
		
      string   refSequence;
      string   readSequence;
      vector<unsigned char> byteAlignment;

      offsetBegin = cmpFile.alnInfo.alignments[alignmentIndex].GetOffsetBegin();
      offsetEnd   = cmpFile.alnInfo.alignments[alignmentIndex].GetOffsetEnd();
      int alignedSequenceLength = offsetEnd - offsetBegin;
      if (alignedSequenceLength >= 0) {
        refSequence.resize(alignedSequenceLength);
        byteAlignment.resize(alignedSequenceLength);
      }
	
      
      hdfcmpFile.refAlignGroups[refGroupIndex]->readGroups[readGroupIndex]->alignmentArray.Read(offsetBegin, 
                                                                                               offsetEnd, 
                                                                                               &byteAlignment[0]);

      readSequence.resize(byteAlignment.size());
      refSequence.resize(byteAlignment.size());

      ByteAlignmentToQueryString(&byteAlignment[0], byteAlignment.size(), &readSequence[0]);
      ByteAlignmentToRefString(&byteAlignment[0], byteAlignment.size(), &refSequence[0]);				
      string ungappedRead, ungappedRef;
      RemoveGaps(readSequence, ungappedRead);
      RemoveGaps(refSequence, ungappedRef);
      Alignment alignment;
      GappedStringsToAlignment(readSequence, refSequence, alignment);
      DNASequence qAlignedSeq, rAlignedSeq;
      qAlignedSeq.seq = (Nucleotide*) &ungappedRead[0];
      qAlignedSeq.length = ungappedRead.size();
      rAlignedSeq.seq = (Nucleotide*) &ungappedRef[0];
      rAlignedSeq.length = ungappedRef.size();
				
      int qStart = cmpFile.alnInfo.alignments[alignmentIndex].GetQueryStart();
      int tStart = cmpFile.alnInfo.alignments[alignmentIndex].GetRefStart();
      stringstream sstrm;
      sstrm << alnHoleNumber << "/" << qStart << "_" << cmpFile.alnInfo.alignments[alignmentIndex].GetQueryEnd();
      alignment.qName = sstrm.str();
      StickPrintAlignment(alignment, qAlignedSeq, rAlignedSeq, cout, qStart, tStart);
				
    }
  }
}
Example #8
0
//컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴
//Procedure		AddToBuffer
//Author		Robert Slater
//Date			Tue 26 Jan 1999
//
//Description
//
//Inputs
//
//Returns
//
//------------------------------------------------------------------------------
bool	MessageBuffer::AddToBuffer(const MESSAGE_STRUC&	msg)
{
    bool 	retval;
    SLong	index,index2;
    bool	playerRecipient = false;

    if (_Replay.Playback)										//AMM 14Apr99
        return (true);											//AMM 14Apr99

    //Block messages to dead blokes
    if (msg.callee && msg.callee->Status.deadtime)				//RJS 05May99
        return true;											//RJS 05May99

    if (msg.caller)
    {
//FIXA        if (msg.caller->nationality != Manual_Pilot.ControlledAC2->nationality)
//FIXA            return true;

        if (msg.caller->ai.radiosilent)
        {
            if (msg.caller->AcIsPlayer())						//RJS 24May99
            {
                MESSAGE_STRUC	tmpmsg(SCRIPT_SILENCE,MSG_SILENCE,NULL,msg.caller,msg.caller);
                _Radio.TriggerMsg(tmpmsg.SetVoice(VOICE_REST));
            }

            return true;									//RJS 24May99
        }
    }

    if (msg.callee)
    {
//FIXA        if (msg.callee->nationality != Manual_Pilot.ControlledAC2->nationality)
//FIXA            return true;
    }

    if ((msg.callee==thePlayer) || (msg.callee==theOtherOne))	//RDH 17May99
        playerRecipient = true;									//RDH 17May99

    //Does this message already exist?...
    for (index = 0; index < OLDBUFFERSIZE; index++)
    {
        if (	(oldbuffer[index].messagetype == msg.messagetype)
                &&	(oldbuffer[index].target == msg.target)				)
        {
            //is old repeatable?
            if (	(oldbuffer[index].visibility == VIS_3)			//RJS 01Apr99
                    ||	(oldbuffer[index].visibility == NOTVIS_1)
                    ||	(oldbuffer[index].visibility == VIS_1))
            {
                return (true);								//RDH 17May99
            }
        }
    }

    for (index = 0; index < NEWBUFFERSIZE; index++)
    {
        if (	(newbuffer[index].messagetype == msg.messagetype)
                &&	(newbuffer[index].target == msg.target)				)
        {
            //is new repeatable?
            if (	(newbuffer[index].visibility == VIS_3)
                    ||	(newbuffer[index].visibility == NOTVIS_1)	)
            {
                return (true);								//RDH 17May99
            }
        }
    }

    if (!(msg.caller==thePlayer||msg.callee==thePlayer) &&
            !(msg.caller==theOtherOne||msg.callee==theOtherOne))		//PD 04Mar99
    {
        if (!msg.blockchatter)									//RJS 06Jul99
        {
            AirStrucPtr	checkitem = msg.caller;						//AMM 24Jun99
            if (	(msg.voiceindex != VOICE_REST)
                    &&	(msg.voiceindex != VOICE_PLAYER)	)
                checkitem = msg.callee;								//AMM 24Jun99

            if (!checkitem)
                return true;

            if (	checkitem->PlayerInGroup()
                    ||	checkitem->PlayerInFlight()	)
            {
                //Overhears leader & fac/tac & dentist & tower...
                if (checkitem->AcIsFlightLeader() || checkitem->AcIsGroupLeader())
                {
                    if (noBufferedMessages > 8)
                        return false;
                }
                else
                    return false;
            }
            else
                return false;
        }
        else
            return true;										//RJS 06Jul99
    }															//RJS 28May99

//	thereIsANewMessage=true;

#ifndef NDEBUG
#ifdef CHATTERTRACE
// defined in rchatter.h
    UWord cw=GETFPCW();
    ::AfxTrace("BUFFERING: %08x\n",msg.messagecnt);
    SETFPCW(cw);
#endif
#endif

    noBufferedMessages++;

    if (msg.priority >= PRI_MEDMAX)				//RJS 24Jun99
    {
        newbufferbot--;
        if (newbufferbot < 0)
            newbufferbot = NEWBUFFERSIZE-1;

        newbuffer[newbufferbot] = msg;
    }
    else
    {
        // Is this buffer full?
        if (	(newbufferbot == newbuffertop)
                &&	(newbuffer[newbufferbot].priority != GAP)	)
        {
            SLong	nogaps;

            if (msg.priority != PRI_LOW)
            {
                nogaps = RemoveGaps(newbuffer,newbuffertop,NEWBUFFERSIZE);
                if (nogaps == 0)
                {
                    SLong	thisone = -1;

                    for (index = newbuffertop; index < NEWBUFFERSIZE; index++)
                    {
                        if (newbuffer[index].priority == PRI_LOW)
                        {
                            thisone = index;
                            break;
                        }
                    }

                    if (thisone < 0)
                    {
                        for (index = 0; index < newbuffertop; index++)
                        {
                            if (newbuffer[index].priority == PRI_LOW)
                            {
                                thisone = index;
                                break;
                            }
                        }
                    }

                    if (thisone > 0)
                    {
                        // Kill 1st low priority one found...

                        newbuffer[thisone].priority = GAP;

                        RemoveGaps(newbuffer,newbuffertop,NEWBUFFERSIZE);
                    }
                }
            }
        }

        // Is this buffer still full?
        if (	(newbufferbot == newbuffertop)
                &&	(newbuffer[newbufferbot].priority != GAP)	)
            return(false);

        newbuffer[newbuffertop] = msg;

        //is this right?....
        newbuffertop++;
        if (newbuffertop >= NEWBUFFERSIZE)
            newbuffertop = 0;
    }

    return (true);
}