<commit_before>/*
 * Copyright (C) 2015 by <NAME> (<EMAIL>)
 *
 * Released under the MIT license, see LICENSE.cactus
 */

#include "snpbridge.h"

#include "vg/vg.hpp"
#include "Variant.h"

using namespace vcflib;
using namespace vg;
using namespace std;

SNPBridge::SNPBridge() : _vg(NULL)
{
}

SNPBridge::~SNPBridge()
{
}

void SNPBridge::processGraph(VG* vg, VariantCallFile* vcf, int offset,
                            int windowSize)
{
  _vg = vg;
  _gv1.init(offset);
  _gv2.init(offset);
  
  Variant var1(*vcf);
  Variant var2(*vcf);
  // skip to first variant after offset
  for (int vcfPos = -1; vcfPos < offset; vcfPos = var1.position)
  {
    if (!vcf->getNextVariant(var1))
    {
      // empty file
      cerr << "No variants found in VCF" << endl;
      return;
    }
  }
  _gv1.loadVariant(vg, var1);

  int graphLen = vgRefLength(var1);
  // used for detecting overlaps (a long deletion for example can
  // overlap many subsequent variants..)
  int lastRefPos = -1;

  for (; vcf->getNextVariant(var2); swap(var1, var2), swap(_gv1, _gv2))
  {
    if (var2.position >= offset + graphLen)
    {
      // stop after end of vg
      break;
    }
    
    _gv2.loadVariant(vg, var2);
    
    if (var2.position - (var1.position + var1.alleles[0].length() - 1) >
        windowSize)
    {
      // skip because further than window size
      continue;
    }

#ifdef DEBUG
    cerr << "\nv1 " << _gv1 << endl << "v2 " << _gv2 << endl;
#endif

    lastRefPos = max(lastRefPos, (int)(var1.position + var1.alleles[0].size()));
    if (var2.position < lastRefPos)
    {
      cerr << "Skipping adjacent variants at " << var1.position << " and "
           << var2.position
           << " because they overlap (each other or previous variant)" << endl;
      continue;
    }

    computeLinkCounts(var1, var2);

    for (int a1 = 1; a1 < var1.alleles.size(); ++a1)<commit_msg>change overlap logic yet again.  need to skip overlaps before loading as they can fail a sanity check<commit_after>/*
 * Copyright (C) 2015 by <NAME> (<EMAIL>)
 *
 * Released under the MIT license, see LICENSE.cactus
 */

#include "snpbridge.h"

#include "vg/vg.hpp"
#include "Variant.h"

using namespace vcflib;
using namespace vg;
using namespace std;

SNPBridge::SNPBridge() : _vg(NULL)
{
}

SNPBridge::~SNPBridge()
{
}

void SNPBridge::processGraph(VG* vg, VariantCallFile* vcf, int offset,
                            int windowSize)
{
  _vg = vg;
  _gv1.init(offset);
  _gv2.init(offset);
  
  Variant var1(*vcf);
  Variant var2(*vcf);
  // skip to first variant after offset
  for (int vcfPos = -1; vcfPos < offset; vcfPos = var1.position)
  {
    if (!vcf->getNextVariant(var1))
    {
      // empty file
      cerr << "No variants found in VCF" << endl;
      return;
    }
  }
  _gv1.loadVariant(vg, var1);

  int graphLen = vgRefLength(var1);


  for (; vcf->getNextVariant(var2); swap(var1, var2), swap(_gv1, _gv2))
  {
    // skip ahead until we're not overlapping
    bool breakOut = false;
    while (!breakOut && var2.position < var1.position + var1.alleles[0].size())
    {
      cerr << "Skipping variant at " << var2.position << " because it "
           << "overlaps previous variant at position " << var1.position << endl;
      breakOut = !vcf->getNextVariant(var2);
    }
    if (breakOut)
    {
      break;
    }

    if (var2.position >= offset + graphLen)
    {
      // stop after end of vg
      break;
    }
    
    _gv2.loadVariant(vg, var2);
    
    if (var2.position - (var1.position + var1.alleles[0].length() - 1) >
        windowSize)
    {
      // skip because further than window size
      continue;
    }

#ifdef DEBUG
    cerr << "\nv1 " << _gv1 << endl << "v2 " << _gv2 << endl;
#endif

    computeLinkCounts(var1, var2);

    for (int a1 = 1; a1 < var1.alleles.size(); ++a1)
{'fraction_non_alphanumeric': 0.1404154614777807, 'fraction_numerical': 0.023665527215356297, 'mean_word_length': 2.585296889726673, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '565353', 'n_tokens_mistral': 1420, 'n_tokens_neox': 1358, 'n_words': 351}