libsequence  1.9.5
slidingWindow.cc
1 #include <Sequence/PolySites.hpp>
2 #include <Sequence/Fasta.hpp>
3 #include <Sequence/Alignment.hpp>
4 #include <Sequence/PolySNP.hpp>
6 #include <vector>
7 #include <iostream>
8 
11 //Read in a data set of aligned sequence in Fasta
12 //format. Create a polymorphism table. Calculate
13 //Tajima's D for the whole table. Then, run a sliding
14 //window of 1 segregating site (with a jump size of 1)
15 //along the SNP table, and use that to calculate Tajima's
16 //D for each site.
17 
18 //This is a somewhat contrived example, but it illustrates
19 //the sliding window code.
20 
21 int main(int argc, char **argv)
22 {
23  const char * infilename = argv[1];
24  std::vector<Sequence::Fasta> data;
25  Sequence::Alignment::GetData(data,infilename);
26 
27  if ( Sequence::Alignment::IsAlignment(data) &&
28  Sequence::Alignment::validForPolyAnalysis(data.begin(),data.end()) )
29  {
30  Sequence::PolySites SNPtable(data);
31  if (! SNPtable.empty())
32  {
33  Sequence::PolySNP analyzeRegion(&SNPtable);
34  std::cout << "Tajima's D for the region is: "<< analyzeRegion.TajimasD() << std::endl;
35 
36  Sequence::PolyTableSlice<Sequence::PolySites> windows(SNPtable.sbegin(),
37  SNPtable.send(),1u,1u);
39  while(itr < windows.cend())
40  {
41  Sequence::PolySites window = windows.get_slice(itr);
42  Sequence::PolySNP analyzeWindow(&window);
43  std::cout << "D for window "
44  << itr-windows.cbegin()
45  << " is: "
46  << analyzeWindow.TajimasD()
47  << std::endl;
48  ++itr;
49  }
50  }
51  }
52 }
Polymorphism tables for sequence data.
Definition: PolySites.hpp:33
Molecular population genetic analysis.
Definition: PolySNP.hpp:86
declaration of Sequence::PolySNP, a class to analyze SNP data
Declaration of namespace Sequence::Alignment.
Sequence::PolySites, generates polymorphism tables from data.
const_iterator cend() const
Declaration of Sequence::Fasta streams.
A container class for "sliding windows" along a polymorphism table.
std::vector< range >::const_iterator const_iterator
const_iterator cbegin() const