~ubuntu-branches/debian/sid/libvcflib/sid

« back to all changes in this revision

Viewing changes to src/vcfcleancomplex.cpp

  • Committer: Package Import Robot
  • Author(s): Andreas Tille
  • Date: 2016-09-16 15:52:29 UTC
  • Revision ID: package-import@ubuntu.com-20160916155229-24mxrntfylvsshsg
Tags: upstream-1.0.0~rc1+dfsg
ImportĀ upstreamĀ versionĀ 1.0.0~rc1+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "Variant.h"
 
2
#include "split.h"
 
3
#include <string>
 
4
#include <sstream>
 
5
#include <iostream>
 
6
 
 
7
using namespace std;
 
8
using namespace vcflib;
 
9
 
 
10
 
 
11
int main(int argc, char** argv) {
 
12
 
 
13
    if (argc != 2) {
 
14
        cerr << "usage: " << argv[0] << " <vcf file>" << endl
 
15
             << "outputs a VCF stream in which 'long' non-complex"
 
16
             << "alleles have their position corrected." << endl
 
17
             << "assumes that VCF records can't overlap 5'->3'" << endl;
 
18
        return 1;
 
19
    }
 
20
 
 
21
    string filename = argv[1];
 
22
 
 
23
    VariantCallFile variantFile;
 
24
    if (filename == "-") {
 
25
        variantFile.open(std::cin);
 
26
    } else {
 
27
        variantFile.open(filename);
 
28
    }
 
29
 
 
30
    if (!variantFile.is_open()) {
 
31
        cerr << "could not open " << filename << endl;
 
32
        return 1;
 
33
    }
 
34
 
 
35
    Variant var(variantFile);
 
36
 
 
37
    // write the new header
 
38
    cout << variantFile.header << endl;
 
39
 
 
40
    // print the records, filtering is done via the setting of varA's output sample names
 
41
    while (variantFile.getNextVariant(var)) {
 
42
        // if we just have one parsed alternate (non-complex case)
 
43
        map<string, vector<VariantAllele> > parsedAlts = var.parsedAlternates(true, true); // use mnps, and previous for indels
 
44
        // but the alt string is long
 
45
        //cerr << var.alt.size() << " " << parsedAlts.size() << endl;
 
46
        if (var.alt.size() == 1 && parsedAlts.size() > 1) {
 
47
            string& alternate = var.alt.front();
 
48
            vector<VariantAllele>& vs = parsedAlts[alternate];
 
49
            vector<VariantAllele> valleles;
 
50
            for (vector<VariantAllele>::iterator a = vs.begin(); a != vs.end(); ++a) {
 
51
                if (a->ref != a->alt) {
 
52
                    valleles.push_back(*a);
 
53
                }
 
54
            }
 
55
            if (valleles.size() == 1) {
 
56
                // do we have extra sequence hanging around?
 
57
                VariantAllele& varallele = valleles.front();
 
58
                if (vs.front().ref == vs.front().alt) {
 
59
                    var.position = varallele.position;
 
60
                    var.ref = var.ref.substr(vs.front().ref.size(), varallele.ref.size());
 
61
                    var.alt.front() = varallele.alt;
 
62
                }
 
63
            }
 
64
        }
 
65
        cout << var << endl;
 
66
    }
 
67
 
 
68
    return 0;
 
69
 
 
70
}
 
71