Exemplo n.º 1
0
void FastaFile::AnalyzeFile() {
  MEMORY_ALLOCATE_CHECK(
      sequences = (char**) malloc(sizeof(char *) * num_of_sequences));
  sequences_names.resize(num_of_sequences);

  uint32_t id = 0;
  string str_seq;
  num_of_characters = 0;
  max_sequence_length = 0;
  str_seq.clear();
  char strRet[MAX_LINE_LEN];
  for (uint64_t i = 0; i < file_size; i++) {
    if (file_string[i] == '>') {
      if (str_seq.size() != 0) {
        MEMORY_ALLOCATE_CHECK(
            sequences[id] = (char *) malloc(
                sizeof(char) * (str_seq.size() + 1)));
        strcpy(sequences[id], str_seq.c_str());
        num_of_characters += str_seq.size();
        if (str_seq.size() > max_sequence_length) {
          max_sequence_length = str_seq.size();
        }
        str_seq.clear();
        id++;
      }
      i += GetLineFromString(&file_string[i], strRet);
      sequences_names[id] = string(strRet).substr(1);
    } else if (AA20.find_first_of(file_string[i]) != string::npos) {
      str_seq += toupper(file_string[i]);
    } else if (isalpha (file_string[i])) {
      str_seq += AA20[rand() % 20];  //todo
    }
  }
  if (str_seq.size() != 0) {
    MEMORY_ALLOCATE_CHECK(
        sequences[id] = (char *) malloc(sizeof(char) * (str_seq.size() + 1)));
    strcpy(sequences[id], str_seq.c_str());
    num_of_characters += str_seq.size();
    if (str_seq.size() > max_sequence_length) {
      max_sequence_length = str_seq.size();
    }
    str_seq.clear();
    id++;
  }
  if (id != num_of_sequences) {
    ERROR_INFO("The number of Sequences has error~!");
  }

  free (file_string);

  //////////////////////////////////////////////////////
  FILE * fout = fopen("proteins.txt", "w");
  for (uint32_t i = 0; i < num_of_sequences; i++) {
    fprintf(fout, "%d:%s\n", i, sequences_names[i].c_str());
    fprintf(fout, "%s\n", sequences[i]);
  }
  fclose(fout);
  ///////////////////////////////////////////////////////
}
Exemplo n.º 2
0
void FastaFile::GetNumOfSequences() {
  char strRet[MAX_LINE_LEN];
  for (uint64_t i = 0; i < file_size; i++) {
    if (file_string[i] == '>') {
      num_of_sequences++;
    }
    i += GetLineFromString(&file_string[i], strRet);
  }
}
	void TextureAtlasPatternFileLoader::Analyze( char* pData, int len )
	{
		char* pEnd = pData + len;

		char str[ 1024 ];

		// ファイル解析
		while( pData != pEnd ){
			GetLineFromString( &pData, pEnd, str, sizeof( str ) );
			int count = 0;
			AtlasData data;
			bool ok = false;
			MAPIL::ZeroObject( &data, sizeof( data ) );
			for( const char* pToken = ::strtok( str, "," ); pToken; pToken = ::strtok( 0, "," ) ){
				char s[ 1024 ];
				DeleteChar( s, sizeof( s ), pToken, ' ' );
				switch( count ){
					// ID
					case 0:
						if( !IsDigitString( s ) ){
							continue;
						}
						data.m_ID = ::atoi( s );
						break;
					// TexID
					case 1:
						data.m_TexID = ::atoi( s );
						break;
					// X座標
					case 2:
						data.m_PosX = ::atoi( s );
						break;
					// Y座標
					case 3:
						data.m_PosY = ::atoi( s );
						break;
					// 幅
					case 4:
						data.m_Width = ::atoi( s );
						break;
					// 高さ
					case 5:
						data.m_Height = ::atoi( s );
						ok = true;
						break;
					// レジスタ
					default:
						break;
				}
				++count;
			}
			if( ok ){
				m_AtlasData.push_back( data );
			}
		}
	}
Exemplo n.º 4
0
status_t
CDDBData::Load(const entry_ref &ref)
{
	STRACE(("CDDBData::Load(%s)\n", ref.name));

	BFile file(&ref, B_READ_ONLY);

	if (file.InitCheck() != B_OK) {
		STRACE(("CDDBData::Load failed\n"));
		return file.InitCheck();
	}

	attr_info info;

	if (file.GetAttrInfo("Audio:Genre", &info) == B_OK && info.size > 0) {
		char genreData[info.size + 2];

		if (file.ReadAttr("Audio:Genre", B_STRING_TYPE, 0, genreData, info.size) > 0)
			fGenre = genreData;
	}

	if (file.GetAttrInfo("Audio:Year", &info) == B_OK && info.size > 0) {
		int32 yearData;

		if (file.ReadAttr("Audio:Year", B_INT32_TYPE, 0, &yearData, info.size) > 0)
			fYear = yearData;
	}

	// TODO: Attempt reading the file before attempting to read the attributes
	if (file.GetAttrInfo("CD:tracks", &info) == B_OK && info.size > 0) {
		char trackData[info.size + 2];

		if (file.ReadAttr("CD:tracks", B_STRING_TYPE, 0, trackData, info.size) > 0) {
			trackData[info.size] = 0;
			BString tmp = GetLineFromString(trackData);
			char *index;

			if (fTrackList.CountItems() > 0)
				_EmptyLists();

			fArtist = tmp;
			fArtist.Truncate(fArtist.FindFirst(" - "));
			STRACE(("CDDBData::Load: Artist set to %s\n", fArtist.String()));

			fAlbum = tmp.String() + (tmp.FindFirst(" - ") + 3);
			STRACE(("CDDBData::Load: Album set to %s\n", fAlbum.String()));

			index = strchr(trackData, '\n') + 1;
			while (*index) {
				tmp = GetLineFromString(index);

				if (tmp.CountChars() > 0) {
					BString *newTrack = new BString(tmp);
					CDAudioTime *time = new CDAudioTime;
					time->SetMinutes(0);
					time->SetSeconds(0);

					STRACE(("CDDBData::Load: Adding Track %s (%ld:%ld)\n", newTrack->String(),
							time->minutes, time->seconds));

					fTrackList.AddItem(newTrack);
					fTimeList.AddItem(time);
				}

				index = strchr(index,'\n') + 1;
			}

			// We return this so that the caller knows to initialize tracktimes
			return B_NO_INIT;
		}
	}

	return B_ERROR;
}
Exemplo n.º 5
0
void
CDDBQuery::_ParseData(const BString &data)
{
	// Can't simply call MakeEmpty() because the thread is spawned when the discID kept in fCDData
	// is not the same as what's in the drive and MakeEmpty invalidates *everything* in the object.
	// Considering that we reassign everything here, simply emptying the track list should be sufficient
	for (int16 i = fCDData.CountTracks(); i >= 0; i--)
		fCDData.RemoveTrack(i);

	vector<CDAudioTime> trackTimes;
	GetTrackTimes(&fSCSIData,trackTimes);
	int32 trackCount = GetTrackCount(&fSCSIData);

	if (data.CountChars() < 1) {
		// This case occurs when the CDDB lookup fails. On these occasions, we need to generate
		// the file ourselves. This is actually pretty easy.
		fCDData.SetArtist("Artist");
		fCDData.SetAlbum("Audio CD");
		fCDData.SetGenre("Misc");

		for (int32 i = 0; i < trackCount; i++) 	{
			BString trackname("Track ");

			if (i < 9)
				trackname << "0";

			trackname << i + 1;

			CDAudioTime time = trackTimes[i + 1] - trackTimes[i];
			fCDData.AddTrack(trackname.String(), time);
		}
	}

	// TODO: This function is dog slow, but it works. Optimize.

	// Ideally, the search should be done sequentially using GetLineFromString() and strchr().
	// Order: genre(category), frame offsets, disc length, artist/album, track titles

	int32 pos;

	pos = data.FindFirst("DYEAR=");
	if (pos > 0) {
		BString artist,album;
		artist = album = GetLineFromString(data.String() + sizeof("DYEAR") + pos);

		// TODO: finish, once I find an entry which actually has a year in it
		BAlert *alert = new BAlert("SimplyVorbis", "DYEAR entry found\n", "OK");
		alert->Go();
		
	}

	pos = data.FindFirst("DTITLE=");
	if (pos > 0) {
		BString artist,album;
		artist = album = GetLineFromString(data.String() + sizeof("DTITLE") + pos);

		pos = artist.FindFirst(" / ");
		if (pos > 0)
			artist.Truncate(pos);
		fCDData.SetArtist(artist.String());

		album = album.String() + pos + sizeof(" / ") - 1;
		fCDData.SetAlbum(album.String());
	}

	BString category = GetLineFromString(data.String() + 4);
	pos = category.FindFirst(" ");
	if (pos > 0)
		category.Truncate(pos);
	fCDData.SetGenre(category.String());

	pos = data.FindFirst("TTITLE0=");
	if (pos > 0) {
		int32 trackCount = 0;
		BString searchString = "TTITLE0=";

		while (pos > 0) {
			BString trackName = data.String() + pos + searchString.Length();
			trackName.Truncate(trackName.FindFirst("\n"));

			CDAudioTime tracktime = trackTimes[trackCount + 1] - trackTimes[trackCount];
			fCDData.AddTrack(trackName.String(),tracktime);

			trackCount++;
			searchString = "TTITLE";
			searchString << trackCount << "=";
			pos = data.FindFirst(searchString.String(),pos);
		}
	}
}
Exemplo n.º 6
0
void ReadReads(const Option & opt, const CReference * refGenome,
               const CHashTable * hashTable) {
  FILE * fout = fopen(opt.outputFile.c_str(), "wb");
  CRead * reads, *reads_rev;
  CRegion * region;
  char * strReads;

  MEMORY_ALLOCATE_CHECK(
      reads = (CRead *) malloc(MAX_MAPPING_READS * sizeof(CRead)));
  MEMORY_ALLOCATE_CHECK(
      reads_rev = (CRead *) malloc(MAX_MAPPING_READS * sizeof(CRead)));
  MEMORY_ALLOCATE_CHECK(
      region = (CRegion *) malloc(
          MAX_MAPPING_READS * TOTAL_SHIFT_rev * sizeof(CRegion)));

  /* read reads from the file*/
  INFO("read reads from", opt.readsFile);
  SIZE_T readsLen = ReadWholeFile(opt.readsFile, &strReads);

  char strRead[MAX_LINE_LEN];
  SIZE_T nReadsNum = 0;
  SIZE_T readID = 0;
  map < SIZE_T, SIZE_T > mapPosCount;

  for (SIZE_T i = 0; i < readsLen; i++) {
    SIZE_T len = GetLineFromString(&strReads[i], strRead);
    i += len;
    if (strRead[0] != '>' && len != 0) {
      CHECK_READ_LEN(len, nReadsNum);
      strcpy(reads[nReadsNum].readInStr, strRead);
      reads[nReadsNum].readLen = len;
      nReadsNum++;
    }

    if (nReadsNum == MAX_MAPPING_READS
        || (nReadsNum > 0 && i >= readsLen - 1)) {
      Reverse_Kernel(reads, reads_rev, nReadsNum);
      SIZE_T NUM = TOTAL_SHIFT_rev * nReadsNum;
      TIME_INFO(
          Match_Kernel(refGenome, hashTable, reads, reads_rev, region, NUM),
          "match time");

      for (SIZE_T i = 0; i < NUM; i++) {
        for (SIZE_T j = region[i].lower; j <= region[i].upper; j++) {
          mapPosCount[hashTable->index[j] - i % TOTAL_SHIFT]++;
        }
        if ((i + 1) % TOTAL_SHIFT == 0) {
          for (map<SIZE_T, SIZE_T>::iterator it = mapPosCount.begin();
              it != mapPosCount.end(); it++) {
            if (it->second > 1) {
              fprintf(fout, "read %d: %d %d\n", i / TOTAL_SHIFT_rev, it->first,
                      it->second);
            }
          }
          mapPosCount.clear();
        }
      }
      readID += nReadsNum;
      nReadsNum = 0;
    }
  }

  fclose(fout);
  free(strReads);
  free(reads);
  free(region);
}