Example #1
0
//
// printPedigreeTableAsTabDelimited: Prints core and optional non-core columns:
//
void DataTable::printPedigreeTableAsTabDelimited(std::string filename) const{
	
	// Get the Core Column Indices:
	unsigned familyColumnIndex = getColumnOrdinal("FamilyId");
	unsigned individualColumnIndex = getColumnOrdinal("IndividualId");
	unsigned genderColumnIndex = getColumnOrdinal("Gender");
	unsigned fatherColumnIndex = getColumnOrdinal("Father");
	unsigned motherColumnIndex = getColumnOrdinal("Mother");
	int firstNameColumnIndex = (columnExists("FirstName")?(int)getColumnOrdinal("FirstName"):COLUMN_IS_MISSING);
	int lastNameColumnIndex = (columnExists("LastName")?(int)getColumnOrdinal("LastName"):COLUMN_IS_MISSING);
	unsigned j;
	
	std::ofstream pedfile(filename.c_str());
	if(pedfile.is_open()){
		// Print the header row:
		pedfile << "FamilyId\t";
		pedfile << "IndividualId\t";
		pedfile << "Gender\t";
		pedfile << "Father\t";
		pedfile << "Mother\t";
		pedfile << "Deceased\t";
		pedfile << "Proband\t";
		pedfile << "DOB\t";
		pedfile << "MZTwin\t";
		pedfile << "DZTwin\t";
		pedfile << "Affected\t";
		pedfile << "FirstName\t";
		pedfile << "LastName\n";
		// Print the data by rows
		for(j=0;j<_rows;j++){
			pedfile << (*_columnVector[familyColumnIndex])->get(j) << "\t";
			pedfile << (*_columnVector[individualColumnIndex])->get(j) << "\t";
			pedfile << (*_columnVector[genderColumnIndex])->get(j) << "\t";
			pedfile << (*_columnVector[fatherColumnIndex])->get(j) << "\t";
			pedfile << (*_columnVector[motherColumnIndex])->get(j) << "\t";
			if(_deceasedColumnIndex != COLUMN_IS_MISSING) pedfile << (*_columnVector[_deceasedColumnIndex])->get(j) << "\t";
			else pedfile << "." << "\t";
			if(_probandColumnIndex != COLUMN_IS_MISSING) pedfile << (*_columnVector[_probandColumnIndex])->get(j) << "\t";
			else pedfile << "." << "\t";
			if(_dobColumnIndex != COLUMN_IS_MISSING) pedfile << (*_columnVector[_dobColumnIndex])->get(j) << "\t";
			else pedfile << "." << "\t";
			if(_mzTwinColumnIndex != COLUMN_IS_MISSING) pedfile << (*_columnVector[_mzTwinColumnIndex])->get(j) << "\t";
			else pedfile << "." << "\t";
			if(_dzTwinColumnIndex != COLUMN_IS_MISSING) pedfile << (*_columnVector[_dzTwinColumnIndex])->get(j) << "\t";
			else pedfile << "." << "\t";
			if(_affectedColumnIndex != COLUMN_IS_MISSING) pedfile << (*_columnVector[_affectedColumnIndex])->get(j) << "\t";
			else pedfile << "." << "\t";
			if(firstNameColumnIndex != COLUMN_IS_MISSING) pedfile << (*_columnVector[firstNameColumnIndex])->get(j) << "\t";
			else pedfile << "." << "\t";
			if(lastNameColumnIndex != COLUMN_IS_MISSING) pedfile << (*_columnVector[lastNameColumnIndex])->get(j) << "\n";
			else pedfile << "." << "\n";
		}
		pedfile.close();
	}
	
}
Example #2
0
	void RPedigree:: output(char* ped){
		// Authors: Rohan L. Fernando
		// (2005) 
		// Contributors:
		ofstream pedfile(ped);
		SafeSTLVector<PNode*>::iterator vecit;
		pedfile.setf(ios::fixed | ios::right);
		for (vecit=pedVector.begin();vecit!=pedVector.end();vecit++){
			pedfile << setw(10) << (*vecit)->ind 
			<< setw(10) << (*vecit)->sire
			<< setw(10) << (*vecit)->dam
			<< setw(20) << ((*vecit)->ind_str).c_str()
			<< setw(20) << (*vecit)->f <<     endl;
		}
	}
Example #3
0
int main(int argc, char * argv[])
   {
   printf("PedWipe - (c) 2000 Goncalo Abecasis\n"
          "Automatically wipe out genotypes from a pedigree file\n\n");

   String pedfile("merlin.ped");
   String datafile("merlin.dat");
   String errorfile("merlin.err");

   bool showTallies = false;

   ParameterList pl;

   pl.Add(new StringParameter('d', "Data File", datafile));
   pl.Add(new StringParameter('p', "Pedigree File", pedfile));
   pl.Add(new StringParameter('e', "Errors File", errorfile));
   pl.Add(new SwitchParameter('t', "Show Tallies", showTallies));

   pl.Read(argc, argv);
   pl.Status();

   Pedigree ped;

   ped.Prepare(datafile);
   ped.Load(pedfile);

   StringArray errors, tokens;
   errors.Read(errorfile);

   int count = 0;
   StringIntMap perMarker, perFamily, perPerson;

   for (int i = 1; i < errors.Length(); i++)
      {
      tokens.Clear();
      tokens.AddTokens(errors[i]);

      if (tokens.Length() < 3) continue;

      Person * person = ped.FindPerson(tokens[0], tokens[1]);

      int markerid = ped.LookupMarker(tokens[2]);

      if (person == NULL)
         {
         printf("Person %s.%s not found ... \n",
                (const char *) tokens[0], (const char *) tokens[1]);
         continue;
         }

      if (markerid == -1)
         {
         printf("Marker %s not found ... \n",
             (const char *) tokens[2]);
         continue;
         }

      printf("Person %s.%s, marker %s wiped.\n",
         (const char *) tokens[0], (const char *) tokens[1],
         (const char *) tokens[2]);

      person->markers[markerid].one = 0;
      person->markers[markerid].two = 0;

      perPerson.IncrementCount(tokens[0] + "." + tokens[1]);
      perFamily.IncrementCount(tokens[0]);
      perMarker.IncrementCount(tokens[2]);

      count++;
      }

   if (perMarker.Length() == 0)
      {
      printf("No errors found in merlin.err\n");
      }
   else if (showTallies && count)
      {
      printf("\nSummary of Errors\n");
      printf("=================\n\n");

      QuickIndex index;

      printf("Per Marker:  (average = %.2f)\n"
             "-----------------------------\n",
            (double) count / (double) ped.markerCount);
      index.IndexCounts(perMarker);
      index.Reverse();
      for (int i = 0; i < perMarker.Length(); i++)
         printf(" %3d errors for marker %s\n",
                perMarker.GetCount(index[i]),
                (const char *) perMarker[index[i]]);

      printf("\nPer Family: (average = %.2f)\n"
             "----------------------------\n",
            (double) count / (double) ped.familyCount);
      index.IndexCounts(perFamily);
      index.Reverse();
      for (int i = 0; i < perFamily.Length(); i++)
         printf(" %3d errors for family %s\n",
                perFamily.GetCount(index[i]), (const char *) perFamily[index[i]]);

      printf("\nPer Person: (average = %.2f)\n"
             "----------------------------\n",
            (double) count / (double) ped.count);
      index.IndexCounts(perPerson);
      index.Reverse();
      for (int i = 0; i < perPerson.Length(); i++)
         printf(" %3d errors for person %s\n",
               perPerson.GetCount(index[i]), (const char *) perPerson[index[i]]);
      }

   printf("\nWriting out edited files [wiped.*] ...\n\n");

   if (ped.markerInfoCount)
      {
      ped.WriteMapFile("wiped.map");
      ped.WriteFreqFile("wiped.freq");
      }

   ped.WriteDataFile("wiped.dat");
   ped.WritePedigreeFile("wiped.ped");
   }