#!/home/asiimwe/anaconda3/bin/python
#Extracting comparative matrix, overlaps between STAR and STAR_WASP 
import sys
import csv
import os
import string
import subprocess
from itertools import chain
import pandas as pd
from os import mkdir
import shutil
import glob
import fileinput
import stat

samples_path = "/home/asiimwe/projects/run_env/alpha_star_wasp_comparison/STAR_WASP_Runs/"
file1 = "/WASP_Reads_Sorted_Unique"
file2 =  "/STAR_WASP_vW_Tagged_Reads_Unique"

os.remove("/home/asiimwe/projects/run_env/alpha_star_wasp_comparison/read_nums.txt") 

subprocess.call(["touch", "/home/asiimwe/projects/run_env/alpha_star_wasp_comparison/read_nums.txt"])

#outputfile = open("/home/asiimwe/projects/run_env/alpha_star_wasp_comparison/read_nums.txt", "a")

#wrt_header1= "Sample" + '\t' + "Overall_reads" + '\t' + "vW_Tagged_reads" + "\n"
#outputfile.write(wrt_header1)



for path, dirs, files in os.walk(samples_path):
	#print(path)
	if path.endswith("32threads"):
		#print(path)
		os.chdir(path)
		##shutil.copy(run_file, path)
		run1 = path +  file1
		run2 = path + file2
		#print(run1)
		#print(run2, "\n")
		#subprocess.call("wc -l", run1)
		#subprocess.call("wc -l", run2)
		
		#cmd1 = "echo WASP Reads: >> /home/asiimwe/projects/run_env/alpha_star_wasp_comparison/read_nums.txt"
		cmd2 = "wc -l " + run1 + " >> /home/asiimwe/projects/run_env/alpha_star_wasp_comparison/read_nums.txt"
		#cmd3 = "echo vW_Tagged Reads: >> /home/asiimwe/projects/run_env/alpha_star_wasp_comparison/read_nums.txt"
		cmd4 = "wc -l " + run2 + " >> /home/asiimwe/projects/run_env/alpha_star_wasp_comparison/read_nums.txt"
		
		
		#print(subprocess.check_output(cmd1, shell=True))
		print(subprocess.check_output(cmd2, shell=True))
		#print(subprocess.check_output(cmd3, shell=True))
		print(subprocess.check_output(cmd4, shell=True))
