<commit_before>#!/usr/bin/python
import sys
import os
import inspect
import subprocess as sub
import shlex

currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)
sys.path.insert(0, parentdir) 
import config as cfg










def writeMatlabScript(sample, species, tempDir, lowessDir, segmentDir):
	segVars = cfg.Segment()
	
#	scriptFile = tempDir + sample + '.m'
#	OUT = open(scriptFile, 'w')
	matlabName = ''.join(sample.split('_'))
	matlabName = ''.join(matlabName.split('-'))
	matlabName = ''.join(matlabName.split('.'))
	scriptFile = tempDir + matlabName + '.m'
	OUT = open(scriptFile, 'w')

	
	
	OUT.write('%Sample specific variable definitions\n')
	
	OUT.write(str("refFile = '" + segVars.binDict[species] + "';\n"))
	OUT.write(str("binFile = '" + lowessDir + sample + ".lowess.txt';\n"))
	OUT.write(str("saveFile = '" + segmentDir + sample + ".segments.txt';\n"))
	OUT.write(str("chromNum = " + str(segVars.chromNumDict[species]) + ";\n"))
	OUT.write(str("alpha = " + str(segVars.CBSalpha) + ";\n"))
#	OUT.write(str("refFile = '" + refFile + "';\n"))
#	OUT.write(str("binFile = '" + lowessDir + sample + lowessExt + "';\n"))
#	OUT.write(str("saveFile = '" + segmentDir + sample + ".segments.txt';\n"))
#	OUT.write(str("chromNum = " + str(chromNumDict[species]) + ";\n"))
#	OUT.write(str("alpha = " + str(CBSalpha) + ";\n"))

	OUT.write('\n\n\n\n\n%Generic processing code\n')
	
	
	
	IN = open(segVars.matlabBase, 'r')
	
	for x in IN:
		OUT.write(x)
	
	OUT.close()
	IN.close()
	
	return matlabName










def segmentOne(sample, species, tempDir, lowessDir, segmentDir):
	#write matlab script
	scriptName = writeMatlabScript(sample, species, tempDir, lowessDir, segmentDir)
	
	#run matlab script
	stdoutFile = tempDir + sample + '.stderr.txt'
	stdout = open(stdoutFile, 'w')
	
	cmd = 'matlab -nodisplay -r ' + scriptName
	cmd = shlex.split(cmd)
	
	p = sub.Popen(cmd, stdout = stdout, stderr = sub.STDOUT)
	p.wait()
	
	stdout.close()
	
	#delete intermediate files
#	os.remove(tempDir + scriptName + '.m')
#	os.remove(stdoutFile)
	#THIS SHOULD BE DONE IN runsegment.py WITH SHUTIL, LIKE FOR runmap.py
	
	
	
	
<commit_msg>Update segmentfile.py<commit_after>#!/usr/bin/python
import sys
import os
import inspect
import subprocess as sub
import shlex

currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)
sys.path.insert(0, parentdir) 
import config as cfg










def writeMatlabScript(sample, species, tempDir, lowessDir, segmentDir):
	segVars = cfg.Segment()
	
#	scriptFile = tempDir + sample + '.m'
#	OUT = open(scriptFile, 'w')
	matlabName = ''.join(sample.split('_'))
	matlabName = ''.join(matlabName.split('-'))
	matlabName = ''.join(matlabName.split('.'))
	scriptFile = tempDir + matlabName + '.m'
	OUT = open(scriptFile, 'w')

	
	
	OUT.write('%Sample specific variable definitions\n')
	
	OUT.write(str("refFile = '" + segVars.binDict[species] + "';\n"))
	OUT.write(str("binFile = '" + lowessDir + sample + ".lowess.txt';\n"))
	OUT.write(str("saveFile = '" + segmentDir + sample + ".segments.txt';\n"))
	OUT.write(str("chromNum = " + str(segVars.chromNumDict[species]) + ";\n"))
	OUT.write(str("alpha = " + str(segVars.CBSalpha) + ";\n"))
#	OUT.write(str("refFile = '" + refFile + "';\n"))
#	OUT.write(str("binFile = '" + lowessDir + sample + lowessExt + "';\n"))
#	OUT.write(str("saveFile = '" + segmentDir + sample + ".segments.txt';\n"))
#	OUT.write(str("chromNum = " + str(chromNumDict[species]) + ";\n"))
#	OUT.write(str("alpha = " + str(CBSalpha) + ";\n"))

	OUT.write('\n\n\n\n\n%Generic processing code\n')
	
	
	
	IN = open(segVars.matlabBase, 'r')
	
	for x in IN:
		OUT.write(x)
	
	OUT.close()
	IN.close()
	
	return matlabName










def segmentOne(sample, species, tempDir, lowessDir, segmentDir):
	#write matlab script
	scriptName = writeMatlabScript(sample, species, tempDir, lowessDir, segmentDir)
	
	print os.getcwd()
	
	#run matlab script
	stdoutFile = tempDir + sample + '.stderr.txt'
	stdout = open(stdoutFile, 'w')
	
	cmd = 'matlab -nodisplay -r ' + scriptName
	cmd = shlex.split(cmd)
	
	p = sub.Popen(cmd, stdout = stdout, stderr = sub.STDOUT)
	p.wait()
	
	stdout.close()
	
	#delete intermediate files
#	os.remove(tempDir + scriptName + '.m')
#	os.remove(stdoutFile)
	#THIS SHOULD BE DONE IN runsegment.py WITH SHUTIL, LIKE FOR runmap.py
	
	
	
	

{'fraction_non_alphanumeric': 0.1807092839394624, 'fraction_numerical': 0.00045177320984865596, 'mean_word_length': 4.215547703180212, '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': '4196282', 'n_tokens_mistral': 1708, 'n_tokens_neox': 1620, 'n_words': 329}