<commit_before>#!/usr/bin/env python

# Date located in: -
from __future__ import print_function
import os
import subprocess
import csv

projectPath = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
varScanPath = os.path.join(projectPath, "bin", "VarScan.v2.4.1.jar")

def SNPs(inputBAM, outputSNP, referenceFile, minVarFreq, minCov, log, printOnly=False, verbose=True, force=True):
    fileSNP = open(outputSNP, 'w')
    
    mpileupCmd = "samtools mpileup -f" + referenceFile + " " + inputBAM
    if(verbose):
        print(mpileupCmd, file=log)
    if(not printOnly):
        mpileup = subprocess.Popen(mpileupCmd, shell=True, stdout=subprocess.PIPE, stderr=log)
        
    varscanCmd = "java -jar " + varScanPath + " mpileup2snp  --strand-filter 0 --output-vcf --min-var-freq " + str(minVarFreq) + " --min-coverage " + str(minCov) + " --variants 1"
    if(verbose):
        print(varscanCmd, file=log)
    if(not printOnly):
        varscan = subprocess.Popen(varscanCmd, shell=True, stdin=mpileup.stdout, stdout=fileSNP, stderr=log)
        varscan.wait()
    
    fileSNP.close()    
    
def countSNPsInFile(inputFile):
    snpCount = 0
    tcSnpCount = 0
    with open(inputFile, "r") as snpFile:
            snpReader = csv.reader(snpFile, delimiter='\t')
            for row in snpReader:
                if((row[2].upper() == "T" and row[3].upper() == "C") or (row[2].upper() == "A" and row[3].upper() == "G")):
                    tcSnpCount = tcSnpCount + 1
                snpCount = snpCount + 1
    return snpCount, tcSnpCount<commit_msg>Run only if input files are newer than output files<commit_after>#!/usr/bin/env python

# Date located in: -
from __future__ import print_function
import os
import subprocess
import csv
from utils.misc import checkStep

projectPath = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
varScanPath = os.path.join(projectPath, "bin", "VarScan.v2.4.1.jar")

def SNPs(inputBAM, outputSNP, referenceFile, minVarFreq, minCov, log, printOnly=False, verbose=True, force=False):
    if(checkStep([inputBAM, referenceFile], [outputSNP], force)):
        fileSNP = open(outputSNP, 'w')
        
        mpileupCmd = "samtools mpileup -f" + referenceFile + " " + inputBAM
        if(verbose):
            print(mpileupCmd, file=log)
        if(not printOnly):
            mpileup = subprocess.Popen(mpileupCmd, shell=True, stdout=subprocess.PIPE, stderr=log)
            
        varscanCmd = "java -jar " + varScanPath + " mpileup2snp  --strand-filter 0 --output-vcf --min-var-freq " + str(minVarFreq) + " --min-coverage " + str(minCov) + " --variants 1"
        if(verbose):
            print(varscanCmd, file=log)
        if(not printOnly):
            varscan = subprocess.Popen(varscanCmd, shell=True, stdin=mpileup.stdout, stdout=fileSNP, stderr=log)
            varscan.wait()
        
        fileSNP.close()
    else:
        print("Skipping SNP calling", file=log)    
        
def countSNPsInFile(inputFile):
    snpCount = 0
    tcSnpCount = 0
    with open(inputFile, "r") as snpFile:
            snpReader = csv.reader(snpFile, delimiter='\t')
            for row in snpReader:
                if((row[2].upper() == "T" and row[3].upper() == "C") or (row[2].upper() == "A" and row[3].upper() == "G")):
                    tcSnpCount = tcSnpCount + 1
                snpCount = snpCount + 1
    return snpCount, tcSnpCount
{'fraction_non_alphanumeric': 0.1374490390215492, 'fraction_numerical': 0.008153756552125802, 'mean_word_length': 2.833705357142857, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1965678', 'n_tokens_mistral': 1220, 'n_tokens_neox': 1182, 'n_words': 251}