コード例 #1
0
ファイル: repository.c プロジェクト: Asquera/libgit2
void git_repository_set_index(git_repository *repo, git_index *index)
{
	assert(repo && index);

	drop_index(repo);

	repo->_index = index;
	GIT_REFCOUNT_OWN(repo->_index, repo);
	GIT_REFCOUNT_INC(index);
}
コード例 #2
0
ファイル: netdb.cpp プロジェクト: hammer/plinkseq-sxsw
void NetDBase::load( const std::string & filename )
{

  Helper::checkFileExists( filename );

  InFile F1( filename );

  // expect format g1 , g2 , score 
  // tab-delimited

  drop_index();

  sql.begin();
  
  int edge_cnt = 0 , node_cnt = 0;
  
  while ( ! F1.eof() )
    {
      std::string n1 , n2;
      double sc;
      F1 >> n1 >> n2 >> sc;
      if ( n1 == "" ) break;
      
      int nid1 = node_id( n1 );
      if ( nid1 == 0 ) { nid1 = add_node( n1 ); ++node_cnt; }

      int nid2 = node_id( n2 );
      if ( nid2 == 0 ) { nid2 = add_node( n2 ); ++node_cnt; }
      
      sql.bind_int( stmt_insert_edge , ":n1" , nid1 );
      sql.bind_int( stmt_insert_edge , ":n2" , nid2 );
      sql.bind_double( stmt_insert_edge , ":score" , sc );
      sql.step( stmt_insert_edge );
      sql.reset( stmt_insert_edge );
      
      sql.bind_int( stmt_insert_edge , ":n1" , nid2 );
      sql.bind_int( stmt_insert_edge , ":n2" , nid1 );
      sql.bind_double( stmt_insert_edge , ":score" , sc );
      sql.step( stmt_insert_edge );
      sql.reset( stmt_insert_edge );

      ++edge_cnt;

      if ( edge_cnt % 1000 == 0 ) 
	plog << edge_cnt << " edges\t" << node_id_map.size() << " nodes \n";
      
    }

  plog << "added " << node_cnt << " " << node_id_map.size() << " unique nodes, " << edge_cnt << " edges\n";

  sql.commit();
  index();

}
コード例 #3
0
ファイル: pp.cpp プロジェクト: hammer/plinkseq-sxsw
void PPH2DBase::load( const std::string & filename )
{

  drop_index();
  
  InFile F( filename );
  
  PPH2Set pset;

  // Assume file is sorted by transcript

  std::string curr = "";

  while ( ! F.eof() ) 
    {


      // format: protein transcript pos AA1 AA2 0/1/2/3 prob-score
      // where 0/1/2/3 = ?/benign/possibly/probably damaging
      
      std::vector<std::string> tok = F.tokenizeLine( );
      
      if ( tok.size() == 0 ) continue;

      if ( tok.size() != 7 ) 
	{
	  plog.warn("found input row with wrong # of columns");
	  plog << tok.size() << " : ";
	  for (int i=0; i<tok.size(); i++)
	    plog << tok[i] << " ";
	  plog << "\n";
	  continue;
	}

      if ( pset.transcript_name != tok[1] )
	{

	  if ( pset.transcript_name != "" ) 
	    {
	      insert(pset);
	      pset.reset();	      
	    }
	  pset.protein_name = tok[0];
	  pset.transcript_name = tok[1];
	}
 
      accumulate( pset , tok );
      
    }
  F.close();
  
  index();
}
コード例 #4
0
ファイル: repository.c プロジェクト: Asquera/libgit2
void git_repository_free(git_repository *repo)
{
	if (repo == NULL)
		return;

	git_cache_free(&repo->objects);
	git_repository__refcache_free(&repo->references);
	git_attr_cache_flush(repo);
	git_submodule_config_free(repo);

	git__free(repo->path_repository);
	git__free(repo->workdir);

	drop_config(repo);
	drop_index(repo);
	drop_odb(repo);

	git__free(repo);
}
コード例 #5
0
ファイル: stmt.c プロジェクト: fanyang01/sql
int _exec_stmt(DB * db, stmt_t * stmt)
{
	switch (stmt->type) {
	case STMT_CREAT_TABLE:
		return create_table(db, stmt->table, stmt->cols, stmt->ncol);
	case STMT_DROP_TABLE:
		return drop_table(db, stmt->table);
	case STMT_CREAT_INDEX:
		return create_index(db, stmt->table, stmt->attr, stmt->index);
	case STMT_DROP_INDEX:
		return drop_index(db, stmt->index);
	case STMT_INSERT:
		return insert_into(db, stmt->table, NULL, stmt->vals,
				   stmt->nval);
	case STMT_DELETE:
		return delete_from(db, stmt->table, stmt->conds, stmt->ncond);
	case STMT_SELECT:
		return select_and_print(db, stmt->table, stmt->cols, stmt->ncol,
					stmt->conds, stmt->ncond);
	}
	xerrno = ERR_INVSTMT;
	return -1;
}
コード例 #6
0
ファイル: inddb.cpp プロジェクト: hammer/plinkseq-sxsw
bool IndDBase::load_phenotypes( const std::string & filename )
{

  if ( ! attached() ) Helper::halt( "no attached INDDB" );

  if ( ! Helper::fileExists(filename) ) 
    {
      plog.warn("could not find phenotype file " + filename );
      return false;
    }

  // Expect a variant of FAM file format
  
  InFile f( filename );

  std::map<std::string,int> phe_codes1;
  std::map<int,int> phe_codes2;
  std::vector<std::string> phe_codes;
  std::map<std::string,mType> type_codes;
  
  std::map<std::string,std::string> mis_codes;
  
  int expected_col_count = -1;
  int inserted = 0;
  
  sql.begin();

  drop_index();
 
  while ( ! f.eof() )
    {
      
      std::string s = f. readLine();
      
      if ( s == "" ) continue;
      
      // Meta-information? 
      
      if ( s.size() > 2 && s.substr(0,2) == "##" )
	{
	  
	  std::vector<std::string> tok = Helper::quoted_parse( s.substr(2) );
	  
	  // need at least a name
	  if ( tok.size() < 1 ) continue;	  
	  std::string name = tok[0];

	  // defaults
	  std::string type = "Integer"; 
	  std::string miss = "0";
	  std::string desc = "Dichotomous phenotype";	  
	  if ( tok.size() >= 2 ) type = tok[1];
	  if ( tok.size() >= 3 ) miss = tok[2];
	  if ( tok.size() >= 4 ) desc = tok[3];
	  
	  int code = insert_phenotype( name, type, miss, desc );

	  phe_codes1[ name ] = code;
	  mis_codes[ name ] = miss;
	  
	  if ( Helper::is_int( type ) ) type_codes[ name ] = META_INT;
	  else if ( Helper::is_float( type ) ) type_codes[ name ] = META_FLOAT;
	  else type_codes[ name ] = META_TEXT;

	}

      // Or header line?
      
      else if ( s.substr(0,1) == "#" )
	{
	  
	  // #ID phe1 phe2 phe3
	  
	  std::vector<std::string> tok = Helper::parse( s , " \t");
	  
	  if ( tok.size() < 2 ) { plog.warn("malformed phenotype file"); continue; } 
	  if ( tok[0] != "#ID" ) { plog.warn("malformed phenotype file"); continue; } 
	  
	  for ( int i = 1 ; i < tok.size(); i++ )
	    {
	      std::map<std::string,int>::iterator k = phe_codes1.find( tok[i] );	      

	      if ( k == phe_codes1.end() ) 
		Helper::halt( tok[i] + " in header of phenotype file but not defined" );
	      
	      phe_codes2[ i ] = k->second;
	      phe_codes.push_back( tok[i] );
	      
	    }
	  expected_col_count = tok.size();
	}
      
      // Or data ? 
      
      else 
	{
	  
	  // Skip, if we haven't seen a header
	  if ( expected_col_count == -1 ) continue;
	 
	  std::vector<std::string> tok = Helper::parse( s , " \t");
	  
	  if ( tok.size() != expected_col_count ) 
	    {
	      plog.warn("row in phenotype file with wrong number of fields");
	      continue;
	    }
	  
	  int indiv_id = fetch_id( tok[0] );
	  
	  // if individual does not exist, create

	  if ( indiv_id == 0 ) 
	    {
	      std::string period = ".";

	      sql.bind_text( stmt_insert_individual , ":name" , tok[0] );
	      sql.bind_text( stmt_insert_individual , ":fid" , period );
	      sql.bind_text( stmt_insert_individual , ":fid" , period );
	      sql.bind_text( stmt_insert_individual , ":iid" , period );
	      sql.bind_text( stmt_insert_individual , ":pat" , period );
	      sql.bind_text( stmt_insert_individual , ":mat" , period );
	      sql.bind_text( stmt_insert_individual , ":sex" , period );
	      
	      sql.step( stmt_insert_individual );
	      sql.reset( stmt_insert_individual );
	      
	      // and grab the ID
	      indiv_id = fetch_id( tok[0] );

	    }
	  
	  //
	  // Insert actual phenotypes
	  //
	  
	  for ( int i = 1; i < tok.size(); i++ )
	    {

	      // skip undefined phenotypes
	      if ( phe_codes2[i] == 0 ) continue;

	      // skip missing values
	      if ( tok[i] == mis_codes[ phe_codes[i-1] ] ) continue;
	      
	      mType mt = type_codes[ phe_codes[ i-1 ] ];
	      
	      // skip invalid values for numerics (as MT will be registered)
	      
 	      if ( mt == META_INT )
 		{    
 		  int x;
 		  if ( Helper::str2int( tok[i] , x ) )
 		    insert( indiv_id , phe_codes2[i] , x );
 		}
 	      else if ( mt == META_FLOAT )
 		{
 		  double x;
 		  if ( Helper::str2dbl( tok[i] , x ) )
 		    insert( indiv_id , phe_codes2[i] , x );
 		}
 	      else 
 		{
 		  insert( indiv_id , phe_codes2[i] , tok[i] );
 		}


	    }
	  ++inserted;	    
	}
    }
  
  f.close();

  index();
  
  sql.commit();

  plog << "Processed " << inserted << " rows\n";
  
  if ( inserted && GP && GP->has_project_file() ) 
    GP->fIndex.append_to_projectfile( Helper::fullpath( filename ) , "PHE" );
    
  return true;
}