Example #1
0
inline void HapList::NormaliseFreqs(){
  double sum = 0;
  for(ListType::iterator h = haplist.begin(); h!=haplist.end(); h++){
    sum += h->second.Freq;
  }
  for(ListType::iterator h = haplist.begin(); h!=haplist.end(); h++){
    h->second.Freq /= sum;
  }  
}
void DirectedGraph::sort() {
	for (int id = 0; id != maxNodeId + 1; id++) {
		if (hasNode(id)) {
			ListType* fromNeighbors = inNeighborsTable[id];
			ListType* toNeighbors = outNeighborsTable[id];
			std::sort(fromNeighbors->begin(), fromNeighbors->end());
			std::sort(toNeighbors->begin(), toNeighbors->end());
		}
	}
}
Example #3
0
inline void HapList::NormaliseGroupFreqs(){
  
  for(unsigned g=0; g< haplist.begin()->second.GroupFreq.size(); g++){
    double norm = 0;
    for(ListType::iterator h = haplist.begin(); h!=haplist.end(); h++)
      norm += h->second.GroupFreq[g];
    for(ListType::iterator h = haplist.begin(); h!=haplist.end(); h++){
      h->second.GroupFreq[g] /= norm;
      h->second.GroupFreqSq[g] /= norm;
    }
  }
    
}
Example #4
0
void TasksProperty::set(const Atlas::Message::Element & val)
{
    if (!val.isList())
    {
        log(ERROR, "Task property must be a list.");
        return;
    }

    if (m_task == 0) {
        log(ERROR, "No task in ::set");
        return;
    }

    ListType tasks = val.asList();
    ListType::const_iterator I = tasks.begin();
    ListType::const_iterator Iend = tasks.end();
    for (; I != Iend; ++I) {
        if (!I->isMap()) {
            log(ERROR, "Task must be a map.");
            return;
        }
        const MapType & task = I->asMap();
        MapType::const_iterator J = task.begin();
        MapType::const_iterator Jend = task.end();
        for (J = task.begin(); J != Jend; ++J) {
            m_task->setAttr(J->first, J->second);
        }
    }
}
Example #5
0
inline typename ListType::Iterator randomFragment(const ListType& src)
{
    if( src.empty() ) return src.end();
    typename ListType::ConstIterator result = src.begin();
    ::std::advance( result, ::std::rand() % src.size() );
    return result;
}
int Linearization::mostWeightFrom(std::list<int> *X)
{
	int maxWeight = 0;
	int result = -1;
	std::map<int, double> weightTable;
	
	for (std::list<int>::iterator nodeInX = X->begin(); nodeInX != X->end();
			nodeInX++) {
		ListType* nodesNeighbors = undirectedGraph->getNeighborByNodeId(*nodeInX);
		for (ListType::iterator neighbor = nodesNeighbors->begin();
				neighbor != nodesNeighbors->end(); neighbor++) {
			if (std::find(X->begin(), X->end(), *neighbor) != X->end())
				continue;
			if (weightTable.find(*neighbor) == weightTable.end())
				weightTable[*neighbor] = 0;
			weightTable[*neighbor]++;
		}
	}
	for (std::map<int, double>::iterator i = weightTable.begin(); i != weightTable.end(); i++) {
		if (i->second > maxWeight) {
			result = i->first;
			maxWeight = i->second;
		}
	}
	return result;
}
Example #7
0
void Gear_UnpackList::clearList()
{
  ListType *listType = _LIST_OUT->type();
  for(ListType::iterator it=listType->begin(); it!=listType->end(); ++it)
    delete (*it);
  listType->clear();
}
typename ListType::FragmentType
selectBlock(const ListType& src, typename ListType::FSizeType blockSize,
    const AvailableType* available )
{
    typedef typename ListType::FragmentType FragmentType;
    typedef typename ListType::FSizeType FSizeType;
    typedef typename ListType::ConstIterator ConstIterator;
    
    if( src.empty() ) return FragmentType( 0,
        ::std::numeric_limits< FSizeType >::max() );

    ::std::deque< FSizeType > blocks;

    for( ConstIterator selectIterator = src.begin();
        selectIterator != src.end(); ++selectIterator )
    {
        FSizeType blockBegin = selectIterator->begin() / blockSize;
        FSizeType blockEnd = ( selectIterator->end() - 1 ) / blockSize;
		if ( selectIterator->begin() % blockSize )
		{
			// the start of a block is complete, but part is missing
			
			if ( !available || available[ blockBegin ] )
			{
                return FragmentType( selectIterator->begin(),
                    ::std::min( selectIterator->end(),
                    blockSize * ( blockBegin + 1 ) ) );
			}
            ++blockBegin;
		}
		if ( blockBegin <= blockEnd && selectIterator->end() % blockSize
            && selectIterator->end() < src.limit() )
		{
			// the end of a block is complete, but part is missing
			
			if ( !available || available[ blockEnd ] )
			{
                return FragmentType( blockEnd * blockSize,
                    selectIterator->end() );
			}
            --blockEnd;
		}
		// this fragment contains one or more aligned empty blocks
        if( blockEnd != ~0ULL ) for( ; blockBegin <= blockEnd; ++blockBegin )
        {
            if( !available || available[ blockBegin ] )
            {
                blocks.push_back( blockBegin );
            }
        }
	}
	
    if( blocks.empty() )  return FragmentType( 0,
        ::std::numeric_limits< FSizeType >::max() );

    FSizeType blockBegin = blocks[ ::std::rand() % blocks.size() ] * blockSize;

    return FragmentType( blockBegin, ::std::min( blockBegin + blockSize, src.limit() ) );
}
Example #9
0
inline typename ListType::ConstIterator largestFragment(const ListType& src)
{
    typedef typename ListType::ConstIterator ConstIterator;
    ConstIterator result = src.begin();
    for( ConstIterator i = result; i != src.end(); ++i )
        if( result->length() < i->length() ) result = i;
    return result;
}
Example #10
0
bool DirectedGraph::removeEdge(int fromNodeId, int toNodeId) {
	ListType::iterator neighborToRemove;
	ListType* fromNeighbors = inNeighborsTable[toNodeId];
	
	neighborToRemove = std::lower_bound(fromNeighbors->begin(), fromNeighbors->end(), fromNodeId);
	if (neighborToRemove != fromNeighbors->end() && (*neighborToRemove == fromNodeId))
		fromNeighbors->erase(neighborToRemove);
	else
		return false;
	
	ListType* toNeighbors = outNeighborsTable[fromNodeId];
	neighborToRemove = std::lower_bound(toNeighbors->begin(), toNeighbors->end(), toNodeId);
	assert(*neighborToRemove == toNodeId);
	toNeighbors->erase(neighborToRemove);
	edgeCount--;
	return true;
}
Example #11
0
void Encoder::listElementListItem(const ListType& obj)
{
    m_b.listListItem();
    ListType::const_iterator I;
    for (I = obj.begin(); I != obj.end(); I++) {
        listElementItem(*I);
    }
    m_b.listEnd();    
}
Example #12
0
inline Haplotype HapList::get_haplotype(int listpos){
  int pos = 0;
  ListType::const_iterator h = haplist.begin();
  while(pos<listpos){
    h++;
    pos++;
  }
  return (*h).first;
}
Example #13
0
void Encoder::mapElementListItem(const std::string& name, const ListType& obj)
{
    m_b.mapListItem(name);
    ListType::const_iterator I;
    for (I = obj.begin(); I != obj.end(); I++) {
        listElementItem(*I);
    }
    m_b.listEnd();
}
Example #14
0
UndirectedGraph* DirectedGraph::convertToUndirectedGraph() {
	UndirectedGraph* result = new UndirectedGraph(maxNodeId);
	for (int i = 0; i != maxNodeId + 1; i++) {
		if (!hasNode(i))
			continue;
		ListType* neighborsList = inNeighborsTable[i];
		for (ListType::iterator neighbor = neighborsList->begin();
				neighbor != neighborsList->end(); neighbor++) {
			result->addEdge(*neighbor, i);
		}
		neighborsList = outNeighborsTable[i];
		for (ListType::iterator neighbor = neighborsList->begin();
				neighbor != neighborsList->end(); neighbor++) {
			result->addEdge(*neighbor, i);
		}
	}
	result->sort();
	return result;
}
 inline AtomType operator()( ListType const &  arg ) const
 {
     AtomType ar;
     typedef typename ListType::const_iterator IT;
     IT it = arg.begin();
     for( ; arg.end() != it; ++it ) {
         ar.push( nativeToAtom(*it) );
     }
     return ar;
 }
Example #16
0
bool overlaps(const ListType& src, const ListType& match)
{
    for( typename ListType::ConstIterator matchIterator = match.begin();
        matchIterator != match.end(); ++matchIterator )
    {
        typename ListType::ConstIteratorPair matchPair
            = src.overlappingRange( *matchIterator );
        if( matchPair.first != matchPair.second ) return true;
    }
    return false;
}
Example #17
0
bool DirectedGraph::hasEdge(int fromNodeId, int toNodeId) {
	if (!hasNode(fromNodeId) || !hasNode(toNodeId))
		return false;

	ListType* toNeighbors = outNeighborsTable[fromNodeId];
	for (ListType::iterator neighbor = toNeighbors->begin();
			neighbor != toNeighbors->end(); neighbor++) {
		if (*neighbor == toNodeId)
			return true;
	}
	return false;
}
Example #18
0
std::ostream& operator <<(std::ostream& out, DirectedGraph& graph) {
	for (int id = 0; id != graph.maxNodeId + 1; id++) {
		if (graph.hasNode(id)) {
			ListType* toNeighbors = graph.outNeighborsTable[id];
			for (ListType::iterator neighbor = toNeighbors->begin();
					neighbor != toNeighbors->end(); neighbor++) {
				out << id << "\t" << (*neighbor) << std::endl;
			}
		}
	}
	return out;
}
Example #19
0
	void addToList(const typename ListType::value_type &data, ListType &list) const {
		if (length()<=0) {
			// Ensure that no dummy data will get added. Shouldn't get here.
			return;
		}
		if (startbyte()==0 && goesToEndOfFile()) {
			// favor a single chunk covering the whole file.
			list.clear();
			list.insert(list.end(), data);
			return;
		}

		typename ListType::iterator endIter=list.end(), iter=list.begin();
		Range::base_type startdata = startbyte();
		Range::base_type maxend = startdata;
		bool includeseof = false;
		while (iter != endIter) {
			// maxend is not relevant for ranges strictly above us.
			if ((*iter).startbyte() > startdata) {
				break;
			}
			if ((*iter).endbyte() > maxend) {
				maxend = (*iter).endbyte();
			}
			if ((*iter).goesToEndOfFile()) {
				includeseof = true;
			}
			// we do not want to allow for more than one
			// range starting at the same start byte--
			// If this is the case, one is guaranteed to overlap.
			if ((*iter).startbyte() >= startdata) {
				break;
			}
			++iter;
		}
		if (includeseof || (maxend > endbyte() && !goesToEndOfFile())) {
			return; // already included by another range.
		}
		iter = list.insert(iter, data);
		++iter;
		while (iter != endIter) {
			typename ListType::iterator nextIter = iter;
			++nextIter;

			if (goesToEndOfFile() ||
					(!(*iter).goesToEndOfFile() && (*iter).endbyte() <= endbyte())) {
				list.erase(iter);
			}

			iter = nextIter;
		}
	}
Example #20
0
	bool isContainedBy(const ListType &list) const {

		typename ListType::const_iterator iter = list.begin(),
			enditer = list.end();

		bool found = false;
		base_type lastEnd = 0;

		while (iter != enditer) {
			base_type start = (*iter).startbyte();
			if (mStart >= start && (*iter).goesToEndOfFile()) {
				return true;
			}
			base_type end = (*iter).endbyte();

			if (mStart >= start && mStart < end) {
				found = true;
				lastEnd = end;
				break;
			}
			++iter;
		}
		if (!found) {
			return false;
		}
		found = false;
		while (iter != enditer) {
			base_type start = (*iter).startbyte();
			if (start > lastEnd) {
				found = false; // gap in range.
				break;
			}
			base_type end = (*iter).endbyte();

			// only an infinite range can include an infinite range.
			if ((*iter).goesToEndOfFile()) {
				return true;
			}
			if (!goesToEndOfFile() && endbyte() <= end) {
				found = true;
				break;
			}
			lastEnd = end;
			++iter;
		}
		return found;
	}
Example #21
0
int main() {

  typedef std::forward_list<int>   ListType;

  ListType l = { 1,2,3,4,5,6,7 };

  l.resize(9);
  l.resize(10,99);

  l.push_front(101);

  ListType::const_iterator itr = l.begin();
  ListType::const_iterator end = l.end();

  while( itr != end ) {
    std::cout << *itr << std::endl;
    ++itr;
    }

  return 0;
}
Example #22
0
inline ListType inverse(const ListType& src)
{
    typedef typename ListType::FragmentType FragmentType;
    typedef typename ListType::PayloadType PayloadType;
    ListType result( src.limit() );
    typename ListType::FSizeType last = 0;
    for( typename ListType::ConstIterator i = src.begin(); i != src.end();
        ++i )
    {
        if( last < i->begin() )
        {
            result.insert( FragmentType( last, i->begin(),
                PayloadType() ) );
        }
        last = i->end();
    }
    if( last < src.limit() )
    {
        result.insert( FragmentType( last, src.limit(), PayloadType() ) );
    }
    return result;
}
Example #23
0
inline void HapList::ClearFreqs(){
  for(ListType::iterator h = haplist.begin(); h!=haplist.end(); h++){
    h->second.Freq = 0;
  }
}
Example #24
0
inline int HapList::get_ngroups(){ return haplist.begin()->second.GroupFreq.size();}
Example #25
0
inline int HapList::get_nloci(){ return haplist.begin()->first.get_nloci();}
Example #26
0
inline void HapList::ClearPseudoCounts(){
  for(ListType::iterator h = haplist.begin(); h!=haplist.end(); h++){
    h->second.PseudoCount = 0;
    h->second.SqPseudoCount = 0;
  }
}
Example #27
0
inline void HapList::SetupGroupFreqs(int ngroups){
  for(ListType::iterator h = haplist.begin(); h!=haplist.end(); h++){
    h->second.GroupFreq = vector<double>(ngroups,0);
    h->second.GroupFreqSq = vector<double>(ngroups,0);
  }
}
Example #28
0
inline void HapList::NormaliseSqPseudoCounts(double norm){
  for(ListType::iterator h = haplist.begin(); h!=haplist.end(); h++){
    h->second.SqPseudoCount /= norm;
  }
}
Example #29
0
inline void HapList::RandomiseFreqs(){
  for(ListType::iterator h = haplist.begin(); h!=haplist.end(); h++){
    h->second.Freq=ranf();
  }
  NormaliseFreqs();
}
Example #30
0
inline void HapList::CopyPseudoCountsToFreqs(){
  for(ListType::iterator h1 = haplist.begin(); h1 !=haplist.end(); h1++){
    (*h1).second.Freq = (*h1).second.PseudoCount;
  }
}