Esempio n. 1
0
void CRPSPreMF::ComputeCSeq(ifstream &SamFile, ofstream &fp, int SamOrRps){
	string line, Ref, Seq, PSeq;
	ifstream fileTemp;
	vector<string> tokens;
	cds_word location = 0;
	size_t pos_input = 0, end_input = 0;
	cds_word posPre = 0,  length_block = 0, Pos = 0, totalPos = 0;
	cds_word cluster_ref = 0, last_cluster = (cds_word)-1, next = 0;
	bitsLength = (cds_word)(ceil(log2(sizeLine.size()))); //bits used to store the line lengths
	buffer_use = last_pos = farther_pos = 0;
	last_ref = "*";
	tmp_file_string = "";
	fileTemp.open(tmp_name.c_str()); //OPEN PRESUMED SEQUENCE
	pos_input = fileTemp.tellg();
	fileTemp.seekg(0, std::ifstream::end);
	end_input = fileTemp.tellg();
	fileTemp.seekg(pos_input);
	getline(SamFile, line);
	while (SamFile.good()){
		if(line[0] != '@'){
			Tokenize(line, tokens, "\t");
			if(SamOrRps){
				Pos = atoi(tokens[1].c_str());
				Ref = tokens[0];
				Seq = tokens[2];
			}
			else{
				Pos = atoi(tokens[3].c_str());      
				Ref = tokens[2];      
				Seq = tokens[9];
			}
			if((tmp_file_string.length() - posPre) < (farther_pos - last_pos + Seq.length())){
				pos_input += posPre;
				fileTemp.seekg(pos_input);
				length_block = (end_input - pos_input);
				if(length_block > MAXRAMBYTES)
					length_block = MAXRAMBYTES;
				tmp_file_string = "";
				tmp_file_string = LoadValue<char>(fileTemp, length_block);
				posPre = 0;
			}
			if(Ref.compare("*")){ //if ref is not '*'
				if(!last_ref.compare(Ref)){
					if(farther_pos  > Pos){
						posPre += (Pos - last_pos);
						totalPos += (Pos - last_pos);
					}
					else{
						posPre += farther_pos - last_pos; 
						totalPos += farther_pos - last_pos; 
					}
				}
				else{ //NEW REFERENCE
					posPre += farther_pos - last_pos;
					totalPos += farther_pos - last_pos;
					cluster_ref = getFirstCluster(Ref, &next);
				}
				length_block = cluster_ref + Pos / IndexRate; //compute the Index position
				if(length_block != last_cluster){ //add block info and pointer to the index
					ClusterReads = ClusterIndex[length_block];
					ClusterIndex[length_block] = location;
					last_cluster = length_block;
					SetVarField(buffer, buffer_use,  buffer_use + kWordSize - 1, ClusterReads); //Save number of read in the block
					buffer_use += kWordSize;
					SetVarField(buffer, buffer_use,  buffer_use + kWordSize - 1, totalPos); //Save pointer to pressume seq
					buffer_use += kWordSize;
					location += 2 * kWordSize;
				}
			}
			else //NOT REFERENCE READ
				cout << "Error: Not referenced read are ignored so far" << endl;
			PSeq = tmp_file_string.substr(posPre, Seq.size());
			location += CompressLine(Ref, Pos, Seq, PSeq, &buffer, &buffer_use);
			check_buffer(buffer, &buffer_use, fp);
		}
		tokens.clear();
		getline(SamFile,line);
	}	
	if(buffer_use != 0)
		SaveValue(fp, buffer,  (buffer_use + kWordSize - 1) / kWordSize);
	delete [] buffer;
	buffer = NULL;
}
Esempio n. 2
0
/*---------------------*
 * Split line into two *
 *---------------------*/
BOOL SplitLine(LONG x, struct line_node *line, BOOL move_crsr, struct UserAction *buffer, struct InstData *data)
{
  struct line_node *newline;
  struct line_node *next;
  struct pos_info pos;
  LONG line_nr, lines;
  ULONG c;
  UWORD crsr_x = data->CPos_X;
  struct line_node *crsr_l = data->actualline;

  ENTER();

  OffsetToLines(x, line, &pos, data);
  lines = pos.lines;

  next = line->next;
  if((newline = AllocLine(data)) != NULL)
  {
    UWORD *styles = line->line.Styles;
    UWORD *newstyles = NULL;
    UWORD *colors = line->line.Colors;
    UWORD *newcolors = NULL;

    data->HasChanged = TRUE;
    Init_LineNode(newline, line, line->line.Contents+x, data);
    newline->line.Color = line->line.Color;
    newline->line.Flow = line->line.Flow;
    newline->line.Separator = line->line.Separator;
    if(buffer != NULL)
    {
      newline->line.Color = buffer->del.style;
      newline->line.Flow = buffer->del.flow;
      newline->line.Separator = buffer->del.separator;
    }

    if(styles != NULL)
    {
      LONG  style = 0;
      LONG  length = 0;
      UWORD *ostyles;

      while(*styles++ <= x+1)
      {
        if(*styles > 0xff)
          style &= *styles++;
        else
          style |= *styles++;
      }
      styles--;
      ostyles = styles;
      while(*(styles+length) != EOS)
        length += 2;
      length = (length*2) + 16;

      if((newstyles = MyAllocPooled(data->mypool, length)) != NULL)
      {
          UWORD *nstyles = newstyles;

        if(isFlagSet(style, BOLD))
        {
          *nstyles++ = 1;
          *nstyles++ = BOLD;
        }
        if(isFlagSet(style, ITALIC))
        {
          *nstyles++ = 1;
          *nstyles++ = ITALIC;
        }
        if(isFlagSet(style, UNDERLINE))
        {
          *nstyles++ = 1;
          *nstyles++ = UNDERLINE;
        }

        while(*styles != EOS)
        {
          *nstyles++ = (*styles++) - x;
          *nstyles++ = *styles++;
        }
        *nstyles = EOS;
      }

      if(isFlagSet(style, BOLD))
      {
        *ostyles++ = x+1;
        *ostyles++ = ~BOLD;
      }
      if(isFlagSet(style, ITALIC))
      {
        *ostyles++ = x+1;
        *ostyles++ = ~ITALIC;
      }
      if(isFlagSet(style, UNDERLINE))
      {
        *ostyles++ = x+1;
        *ostyles++ = ~UNDERLINE;
      }
      if(x != 0)
        ostyles = line->line.Styles;
      *ostyles = EOS;
    }
    newline->line.Styles = newstyles;

    if(colors != NULL)
    {
      UWORD color = GetColor(x, line);
      UWORD length = 0;
      UWORD *ocolors;

      while(*colors <= x+1)
      {
        colors += 2;
      }
      ocolors = colors;

      while(*(colors+length) != 0xffff)
        length += 2;
      length = (length*2) + 16;

      if((newcolors = MyAllocPooled(data->mypool, length)) != NULL)
      {
        UWORD *ncolors = newcolors;

        if(color && *colors-x != 1)
        {
          *ncolors++ = 1;
          *ncolors++ = color;
        }

        while(*colors != 0xffff)
        {
          *ncolors++ = (*colors++) - x;
          *ncolors++ = *colors++;
        }
        *ncolors = 0xffff;
      }
      if(x != 0)
        ocolors = line->line.Colors;
      *ocolors = 0xffff;
    }
    newline->line.Colors = newcolors;


    newline->next = next;
    if(next != NULL)
      next->previous = newline;

    *(line->line.Contents+x) = '\n';
    *(line->line.Contents+x+1) = '\0';
    line->line.Length = x+1;

/*------------------*/
    c = line->visual;
    line->visual = VisualHeight(line, data);
    CompressLine(line, data);

    line_nr = LineToVisual(line, data) + line->visual - 1;
    if(line_nr < 0)
      line_nr = 0;

    if(move_crsr)
    {
      data->CPos_X = 0;
      data->actualline = data->actualline->next;
    }

    if(x == 0)
    {
      line->line.Color = 0;
      line->line.Separator = 0;
      if(!(line->previous && line->previous->line.Flow == line->line.Flow))
      {
        line->line.Flow = MUIV_TextEditor_Flow_Left;
      }
      if(line_nr != data->maxlines)
      {
        data->totallines += 1;
        if(data->fastbackground)
        {
          if(line_nr)
          {
            ScrollDown(line_nr-1, 1, data);
            PrintLine(0, line, line_nr, FALSE, data);
          }
          else
          {
            ScrollDown(line_nr, 1, data);
          }
        }
        else  DumpText(data->visual_y+line_nr-1, line_nr-1, data->maxlines, TRUE, data);
      }
      else
      {
        data->visual_y++;
        data->totallines += 1;
        if(isFlagClear(data->flags, FLG_Quiet))
        {
          struct Hook *oldhook;

          oldhook = InstallLayerHook(data->rport->Layer, LAYERS_NOBACKFILL);
          ScrollRasterBF(data->rport, 0, data->height,
                    data->xpos, data->ypos,
                    data->xpos + data->innerwidth - 1, (data->ypos + ((data->maxlines-1) * data->height)) - 1);
          InstallLayerHook(data->rport->Layer, oldhook);

          PrintLine(0, line, data->maxlines-1, FALSE, data);
          if(!data->fastbackground)
          {
            DumpText(data->visual_y+data->maxlines-1, data->maxlines-1, data->maxlines, TRUE, data);
          }
        }
      }

      RETURN(TRUE);
      return(TRUE);
    }

    if(x == (LONG)(line->line.Length + newline->line.Length - 2))
    {
      data->totallines += 1;
      if(buffer == NULL)
      {
        line->next->line.Color = 0;
        line->next->line.Separator = 0;
      }
      SetCursor(crsr_x, crsr_l, FALSE, data);
      if(line_nr < data->maxlines)
      {
        if(data->fastbackground)
        {
          ScrollDown(line_nr, 1, data);
          if(line_nr+1 <= data->maxlines)
            PrintLine(0, line->next, line_nr+1, FALSE, data);
        }
        else  DumpText(data->visual_y+line_nr, line_nr, data->maxlines, TRUE, data);
      }

      RETURN(TRUE);
      return(TRUE);
    }
    x = line->line.Length;

    OffsetToLines(x-1, line, &pos, data);
    if(((ULONG)(line->visual + line->next->visual) >= c) && (line->visual == lines))
    {
      if((ULONG)(line->visual + line->next->visual) > c)
        data->totallines += 1;

      PrintLine(pos.bytes, line, line_nr, TRUE, data);

      if((line_nr+line->next->visual-1 < data->maxlines) && ((ULONG)(line->visual + line->next->visual) > c))
      {
        ScrollDown(line_nr+line->next->visual-1, 1, data);
      }
    }
    else
    {
      PrintLine((x-1)-pos.x, line, line_nr, TRUE, data);

      if((line_nr < data->maxlines) && ((ULONG)(line->visual + line->next->visual) < c))
      {
        data->totallines -= 1;
        ScrollUp(line_nr, 1, data);
      }
    }
/*------------------*/
    line = line->next;
    line_nr++;
    c = 0;
    while((c < line->line.Length) && (line_nr <= data->maxlines))
      c = c + PrintLine(c, line, line_nr++, TRUE, data);
  /* Her printes !HELE! den nye linie, burde optimeres! */

    RETURN(TRUE);
    return (TRUE);
  }
  else
  {
    RETURN(FALSE);
    return (FALSE);
  }
}
Esempio n. 3
0
bool wxGIFHandler::DoSaveFile(const wxImage& image, wxOutputStream *stream,
    bool WXUNUSED(verbose), bool first, int delayMilliSecs, bool loop,
    const wxRGB *pal, int palCount, int maskIndex)
{
    const unsigned long colorcount = image.CountColours(256+1);
    bool ok = colorcount && (colorcount <= 256);
    if (!ok)
    {
        return false;
    }

    int width = image.GetWidth();
    int height = image.GetHeight();
    wxCHECK_MSG( width && height, false, wxS("can't save 0-sized file") );

    int width_even = width + ((width % 2) ? 1 : 0);

    if (first)
    {
        ok = wxGIFHandler_WriteHeader(stream, width, height, loop,
            pal, palCount);
    }

    ok = ok
        && wxGIFHandler_WriteComment(stream,
            image.GetOption(wxIMAGE_OPTION_GIF_COMMENT))
        && wxGIFHandler_WriteControl(stream, maskIndex, delayMilliSecs)
        && wxGIFHandler_WriteByte(stream, GIF_MARKER_SEP)
        && wxGIFHandler_WriteRect(stream, width, height);

    // local palette
    if (first)
    {
        // we already saved the (global) palette
        ok = ok && wxGIFHandler_WriteZero(stream);
    }
    else
    {
        const int bpp = wxGIFHandler_BitSize(palCount);
        wxUint8 b;

        b = 0x80;
        b |=(bpp - 1) << 5;
        b |=(bpp - 1);
        b &=~0x40; // clear interlaced

        ok = ok && wxGIFHandler_WriteByte(stream, b)
            && wxGIFHandler_WritePalette(stream, pal, palCount, bpp);
    }

    if (!ok)
    {
        return false;
    }

    if (!InitHashTable())
    {
        wxLogError(_("Couldn't initialize GIF hash table."));
        return false;
    }

    const wxUint8 *src = image.GetData();
    wxScopedArray<wxUint8> eightBitData(width);

    SetupCompress(stream, 8);

    m_pixelCount = height * width_even;
    for (int y = 0; y < height; y++)
    {
        m_pixelCount -= width_even;
        for (int x = 0; x < width; x++)
        {
            wxRGB rgb;
            rgb.red   = src[0];
            rgb.green = src[1];
            rgb.blue  = src[2];
            int index = wxGIFHandler_PaletteFind(rgb, pal, palCount);
            wxASSERT(index != wxNOT_FOUND);
            eightBitData[x] = (wxUint8)index;
            src+=3;
        }

        ok = CompressLine(stream, eightBitData.get(), width);
        if (!ok)
        {
            break;
        }
    }

    wxDELETE(m_hashTable);

    return ok;
}