コード例 #1
0
ファイル: ArgList.cpp プロジェクト: jabogithub/fann-excel
void ArgumentList::add(const std::string& ArgumentName, const MyMatrix& value)
{
	ArgumentType thisOne = matrix;
	std::pair<std::string, ArgumentType> thisPair(ArgumentName,thisOne);
	ArgumentNames.push_back(thisPair);
	MatrixArguments.insert(std::make_pair(ArgumentName,value));
	
	RegisterName(ArgumentName, thisOne);
}
コード例 #2
0
ファイル: ArgList.cpp プロジェクト: jabogithub/fann-excel
void ArgumentList::addList(const std::string& ArgumentName, const CellMatrix& values)
{
	ArgumentType thisOne = list;
	std::pair<std::string, ArgumentType> thisPair(ArgumentName,thisOne);
	ArgumentNames.push_back(thisPair);
	ListArguments.insert(std::make_pair(ArgumentName,values));

	
	RegisterName(ArgumentName, thisOne);
}
コード例 #3
0
ファイル: ArgList.cpp プロジェクト: jabogithub/fann-excel
void ArgumentList::add(const std::string& ArgumentName, bool value)
{
	ArgumentType thisOne = boolean;
	std::pair<std::string, ArgumentType> thisPair(ArgumentName,thisOne);
	ArgumentNames.push_back(thisPair);
	BoolArguments.insert(std::make_pair(ArgumentName,value));
	
	RegisterName(ArgumentName, thisOne);

}
コード例 #4
0
ファイル: ArgList.cpp プロジェクト: jabogithub/fann-excel
void ArgumentList::add(const std::string& ArgumentName, const std::string& value)
{
	ArgumentType thisOne = string;
	std::pair<std::string, ArgumentType> thisPair(ArgumentName,thisOne);
	ArgumentNames.push_back(thisPair);

	std::pair<std::string,std::string> valuePair(ArgumentName,value);
	StringArguments.insert(valuePair);

	RegisterName(ArgumentName, thisOne);
}
コード例 #5
0
ファイル: ArgList.cpp プロジェクト: jabogithub/fann-excel
void ArgumentList::add(const std::string& ArgumentName, double value)
{
	ArgumentType thisOne = number;
	std::pair<std::string, ArgumentType> thisPair(ArgumentName,thisOne);
	ArgumentNames.push_back(thisPair);

	std::pair<std::string,double> valuePair(ArgumentName,value);
	DoubleArguments.insert(valuePair);
	
	RegisterName(ArgumentName, thisOne);
				
}
コード例 #6
0
ファイル: blox.cpp プロジェクト: francois-boyer/plink
map<Range,vector<int> > Plink::mkBlks(int null1, int null2 )
{
  

  // First SNP, vector of SNPs (inc. first)
  
  map< int, vector<int> > blocks;
  
  
  // Some constants
  
  const double cutHighCI = 0.98;
  const double cutLowCI = 0.70;
  const double cutLowCIVar [5] = {0,0,0.80,0.50,0.50};
  const double maxDist [5] = {0,0,20000,30000,1000000};
  const double recHighCI = 0.90;
  const double informFrac = 0.95;
  const double fourGameteCutoff = 0.01;
  const double mafThresh = 0.05;
  
  // Set to skip SNPs with low MAFs
  // Uses genome-wide reference number: need to allocate for all SNPs here
  
  vector<bool> skipMarker(nl_all,false);
  for (int x = 0; x < nl_all; x++)
    skipMarker[x] = locus[x]->freq < mafThresh;
  
  // Consider each chromosome one at a time; skip X for now
  
  int startChromosome = locus[ 0 ]->chr;
  int finalChromosome = locus[ nl_all - 1 ]->chr;
  
  for (int chr = startChromosome ; chr <= finalChromosome; chr++)
    {

      if ( scaffold.find(chr) == scaffold.end() )
	continue;

      int fromPosition = scaffold[chr].lstart;
      int toPosition = scaffold[chr].lstop;
      
      int nsnps = toPosition - fromPosition + 1;
      

      /////////////////////////////////////////////////////////////////////////
      // Make a list of marker pairs in "strong LD", sorted by distance apart 
      
      set<LDPair,Pair_cmp> strongPairs;
      map<int2,DPrime> dpStore;
      
      int numStrong = 0; 
      int numRec = 0; 
      int numInGroup = 0;
      
      // Each pair of markers
      
      for (int x = fromPosition; x < toPosition; x++)
	{

 	  if ( ! par::silent )
 	    {
	      std::cerr << "Chromosome " <<  locus[x]->chr
			<< ", position " << locus[x]->bp/1000000.0 
			<< "Mb                \r";
	    }
	  
	  for (int y = x+1; y <= toPosition; y++)
	    {

	      if ( locus[x]->chr != locus[y]->chr ) 
		continue;
	      
	      if ( ( locus[y]->bp - locus[x]->bp ) > par::disp_r_window_kb )
		{
		  continue;
		}

	      if ( locus[x]->freq == 0 || locus[y]->freq == 0 )
		continue;
	      
	      PairwiseLinkage thisPair(x,y);
	      thisPair.calculateLD();
	      thisPair.calculateCI();
	      
	      double lod = thisPair.lod;
	      double lowCI = thisPair.dp_lower;
	      double highCI = thisPair.dp_upper;
	      
	      int2 t(x,y);
	      DPrime d;
	      d.dp = thisPair.dp;
	      d.dpl = lowCI;
	      d.dpu = highCI;
	      d.lod = lod;
	      dpStore.insert( make_pair( t,d ) );
	      
	      // Is this pair in strong LD?
	      if (lod < -90) continue; //missing data
	      
	      if (highCI < cutHighCI || lowCI < cutLowCI) 
		continue; //must pass "strong LD" test
	
	      // Store this pair
	      LDPair p(x,y, abs( locus[x]->bp - locus[y]->bp ) );
	      
	      
	      strongPairs.insert( p );

	    }
	}

      
      // Now we have a list of SNPs in strong LD within this region
      // Now construct blocks based on this
      
      set<int> used;
      
      // #blocks:
      vector<vector<int> > blockArray;
      
      int cnt = 0;
      
      for ( set<LDPair>::reverse_iterator i = strongPairs.rbegin();
	    i != strongPairs.rend();
	    ++i )
	{

	  int numStrong = 0; 
	  int numRec = 0; 
	  int numInGroup = 0;
	  
	  vector<int> thisBlock;
	  
	  int first = i->s1; 
	  int last = i->s2;
	  long sep = i->dist;
	  

	  // See if this block overlaps with another:
	  
	  if ( used.find(first) != used.end() 
	       || used.find(last)  != used.end() ) 
	    {	      
	      continue;
	    }
	  
	  // Next, count the number of markers in the block.
	  // (nb. assume all SNPs belong)
	  
	  for (int x = first; x <=last ; x++)
	    {
	      if( !skipMarker[x] ) 
		numInGroup++;
	    }


	  // Skip it if it is too long in bases for it's size in markers
	  if (numInGroup < 4 && sep > maxDist[numInGroup]) 
	    {
	      continue;
	    }
	  
	  // Add first SNP
	  
	  thisBlock.push_back( first );

	  // Test block: requires 95% of informative markers to be "strong"

	  for (int y = first+1; y <= last; y++)
	    {
	      if (skipMarker[y]) 
		{
		  continue;
		}
	      
	      thisBlock.push_back(y);
	      
	      
	      //loop over columns in row y
	      
	      for (int x = first; x < y; x++)
		{
		  
		  if (skipMarker[x]) 
		    continue;
		  
		  double lod; 
		  double lowCI; 
		  double highCI;
		  
		  map<int2,DPrime>::iterator l = dpStore.find( int2(x,y) );
		  
		  if ( l == dpStore.end() ) 
		    {
		      // Recalculate
		      PairwiseLinkage thisPair(x,y);
		      thisPair.calculateLD();
		      thisPair.calculateCI();
		      
		      lod = thisPair.lod;
		      lowCI = thisPair.dp_lower;
		      highCI = thisPair.dp_upper;
		    }
		  else
		    {
		      // Get the right bits
		      
		      lod = l->second.lod;
		      lowCI = l->second.dpl;
		      highCI = l->second.dpu;
		    }
		  
		  
		  // Monomorphic marker error
		  if ( lod < -90)
		    continue;   
		  
		  
		  // Skip bad markers
		  if ( lod == 0 && lowCI == 0 && highCI == 0)
		    continue; 
		  
		  // For small blocks use different CI cutoffs
		  
		  if (numInGroup < 5)
		    {
		      if (lowCI > cutLowCIVar[numInGroup] && highCI >= cutHighCI) 
			numStrong++;
		    }
		  else
		    {
		      if (lowCI > cutLowCI &&  highCI >= cutHighCI) 
			numStrong++; //strong LD
		    }
		  
		  if (highCI < recHighCI) 
		    numRec++; //recombination
		  
		}
	    }
	  
	  
	  // Change the definition somewhat for small blocks
	  
	  if (numInGroup > 3)
	    {
	      if (numStrong + numRec < 6) 
		{
		  continue;
		}
	    }
	  else if (numInGroup > 2)
	    {
	      if (numStrong + numRec < 3) 
		{
		  continue;
		}
	    }
	  else
	    {
	      if (numStrong + numRec < 1) 
		{
		  continue;
		}
	    }
	  

	  // If this qualifies as a block, add to the block list, but in
	  // order by first marker number:
	  
	  if ( (double)numStrong/(double)(numStrong + numRec) > informFrac)
	    { 
	      blocks.insert( make_pair( first , thisBlock ));  
	      
	      // Track that these SNPs belong to a block
	      for (int u = first; u <= last; u++)
		used.insert(u);
	    }
	  
	  
	}
      
      
      // Next chromosome
    }


  if ( ! par::silent )
    cerr << "\n";

  map<int,vector<int> >::iterator j = blocks.begin();

  printLOG(int2str( blocks.size() ) 
	   + " blocks called, writing list to [ " 
	   + par::output_file_name + ".blocks ]\n");
  ofstream O1( (par::output_file_name+".blocks").c_str() , ios::out );
  
  printLOG("Writing extra block details to [ " + 
	   par::output_file_name + ".blocks.det ]\n");
  ofstream O2( (par::output_file_name+".blocks.det").c_str() , ios::out );

  O2 << setw(4) << "CHR" << " " 
     << setw(12) << "BP1" << " "
     << setw(12) << "BP2" << " "
     << setw(12) << "KB" << " "
     << setw(6) << "NSNPS" << " "
     << setw(4) << "SNPS" << "\n";

  while ( j != blocks.end() )
    {
      O1 << "*";
      vector<int> & b = j->second;
      for (int k=0; k<b.size(); k++)
	O1 << " " << PP->locus[b[k]]->name;
      O1 << "\n";
      
      O2 << setw(4) << PP->locus[b[0]]->chr << " " 
	 << setw(12) << PP->locus[b[0]]->bp << " "
	 << setw(12) << PP->locus[b[b.size()-1]]->bp << " "
	 << setw(12) << (double)(PP->locus[b[b.size()-1]]->bp - PP->locus[b[0]]->bp + 1)/1000.0 << " "
	 << setw(6) << b.size() << " ";
      for (int k=0; k<b.size(); k++)
	{
	  if ( k>0 )
	    O2 << "|" << PP->locus[b[k]]->name;
	  else
	    O2 << PP->locus[b[k]]->name;
	}
      O2 << "\n";

      ++j;

    }
  

  O1.close();
  O2.close();
  

  // List of blocks created here
  // (dummy; not used)

  map<Range,vector<int> > blocks0;
  return blocks0;
  
}
コード例 #7
0
void fillFiberSetContainerFromPositionsAndConnections(FiberSetContainer& outFiberSetContainer, const XMarkerList& inLinePositions, const IndexPairList& inLineConnections)
{
  outFiberSetContainer.deleteAllFiberSets();

  std::set<int> typeIDsSet;
  std::map<int, int> numPositionsPerType;
  std::map<int, std::string> typeLabels;

  // Step 1: Scan all positions and get all type ID from them
  for (XMarkerList::const_iterator it = inLinePositions.cbegin(); it != inLinePositions.cend(); ++it)
  {
    XMarker thisMarker = *it;
    typeIDsSet.insert(thisMarker.type);
    numPositionsPerType[thisMarker.type]++;
    typeLabels[thisMarker.type] = thisMarker.name();
  }

  // Step 2: Now create fibers
  for (std::set<int>::const_iterator typeIdIterator = typeIDsSet.cbegin(); typeIdIterator != typeIDsSet.cend(); ++typeIdIterator)
  {
    int thisTypeID = *typeIdIterator;

    FiberSetContainer::FiberSet* newFiberSet = outFiberSetContainer.createFiberSet();
    newFiberSet->setColor(Vector3(1, 0, 0));
    newFiberSet->setLabel(typeLabels[thisTypeID]);

    // Add all connections to the temporary connections list if type ID matches
    XMarkerList  workPositions;
    for (XMarkerList::const_iterator outPositionsIterator = inLinePositions.cbegin(); outPositionsIterator != inLinePositions.cend(); ++outPositionsIterator)
    {
      XMarker thisMarker = *outPositionsIterator;

      if (thisMarker.type == thisTypeID)
      {
        workPositions.push_back(thisMarker);
      }
    }
    MLint workPositionsSize = (MLint)workPositions.size();

    // Add all connections to the temporary connections list if type ID matches
    IndexPairList workConnections;
    for (IndexPairList::const_iterator outConnectionsIterator = inLineConnections.cbegin(); outConnectionsIterator != inLineConnections.cend(); ++outConnectionsIterator)
    {
      IndexPair thisPair = *outConnectionsIterator;

      if (thisPair.type == thisTypeID)
      {
        workConnections.push_back(thisPair);
      }
    }

    // If temporary connections list is still empty at this point: create default list
    if (workConnections.size() == 0)
    {
      int numPositionsOfThisType = numPositionsPerType[thisTypeID];

      for (int p = 0; p < numPositionsOfThisType - 1; p++)
      {
        IndexPair thisPair(p, p + 1);
        workConnections.push_back(thisPair);
      }
    }

    // Now finally create fibers from connections
    for (IndexPairList::const_iterator workListIterator = workConnections.cbegin(); workListIterator != workConnections.cend(); ++workListIterator)
    {
      IndexPair thisWorkPair = *workListIterator;

      MLint startIndex = thisWorkPair.index1;
      MLint endIndex = thisWorkPair.index2;

      if ((startIndex < workPositionsSize) && (endIndex < workPositionsSize))
      {
        XMarker startMarker = workPositions[startIndex];
        XMarker endMarker = workPositions[endIndex];

        FiberSetContainer::FiberSet::Fiber* newFiber = newFiberSet->createFiber();

        FiberSetContainer::FiberSet::Fiber::FiberPoint startPoint;
        startPoint.setCoordinates(startMarker.x(), startMarker.y(), startMarker.z());
        FiberSetContainer::FiberSet::Fiber::FiberPoint endPoint;
        endPoint.setCoordinates(endMarker.x(), endMarker.y(), endMarker.z());

        newFiber->appendPoint(startPoint);
        newFiber->appendPoint(endPoint);
        newFiber->setLabel(1.0);
      }
    }

    workPositions.clearList();
    workConnections.clearList();
  }

}