<commit_before>#<NAME>
#<EMAIL>
#UBC Microbiology - Haney Lab

import argparse, os, errno, shutil, subprocess
import itertools, sys
from Bio import SeqIO

def parse_args():
	parser = argparse.ArgumentParser(description='''
Master script for running PyParanoid process.

Note that default diamond uses 6 threads when requesting resources.
	''')
	parser.add_argument('genomedb',type=str,help='relative path to genomedb for raw data')
	parser.add_argument('strainlist',type=str,help='text file, one strain per line. names should be "species" field from genome_metadata table')
	parser.add_argument('outdir',type=str,help='folder to store output')
	parser.add_argument('--add',action='store_true',help='use if you intend to add to an existing PyParanoid output folder')
	return parser.parse_args()

def setupdir(outdir,strains,genomedb):
	try:
		os.makedirs(outdir)
	except OSError as exc:
		if exc.errno == errno.EEXIST:
			print "Database folder exists:", outdir

	for f in ["faa","dmnd","m8","out","paranoid_output"]:
		try:
			os.makedirs(os.path.join(os.path.join(outdir,f)))
		except OSError:
			print "Subfolder exists:", outdir

	for s in strains:
		try:
			shutil.copy(os.path.join(genomedb,"pep",s+".pep.fa"),os.path.join(outdir,"faa",s+".faa"))
		except IOError as exc:
			if exc.errno == 2:
				print s, 'not found in database...check your strainlist.'
				sys.exit()
	return

def make_diamond_databases(strains,outdir):
	count = len(strains)
	print "Making diamond databases for", count, "strains..."
	for s in strains:
		cmds = "diamond makedb --in {}/faa/{}.faa -d {}/dmnd/{}.dmnd --quiet --threads 6".format(outdir,s,outdir,s)
		proc = subprocess.Popen(cmds.split())
		proc.wait()
		count -= 1<commit_msg>modified fasta formatting to include species name in header<commit_after>#<NAME>
#<EMAIL>
#UBC Microbiology - Haney Lab

import argparse, os, errno, shutil, subprocess
import itertools, sys
from Bio import SeqIO

def parse_args():
	parser = argparse.ArgumentParser(description='''
Master script for running PyParanoid process.

Note that default diamond uses 6 threads when requesting resources.
	''')
	parser.add_argument('genomedb',type=str,help='relative path to genomedb for raw data')
	parser.add_argument('strainlist',type=str,help='text file, one strain per line. names should be "species" field from genome_metadata table')
	parser.add_argument('outdir',type=str,help='folder to store output')
	parser.add_argument('--add',action='store_true',help='use if you intend to add to an existing PyParanoid output folder')
	return parser.parse_args()

def setupdir(outdir,strains,genomedb):
	try:
		os.makedirs(outdir)
	except OSError as exc:
		if exc.errno == errno.EEXIST:
			print "Database folder exists:", outdir

	for f in ["faa","dmnd","m8","out","paranoid_output"]:
		try:
			os.makedirs(os.path.join(os.path.join(outdir,f)))
		except OSError:
			print "Subfolder exists:", outdir

	print "Formatting",len(strains), "fasta files..."
	for s in strains:
		try:
			i = open(os.path.join(genomedb,"pep",s+".pep.fa"),"r")
		except IOError as exc:
			if exc.errno == 2:
				print s, 'not found in database...check your strainlist.'
				sys.exit()
		o = open(os.path.join(outdir,"faa",s+".faa"),"w")
		for seq in SeqIO.parse(i,'fasta'):
			seq.id = s+"|"+str(seq.id)
			SeqIO.write(seq,o,'fasta')
		o.close()
	return

def make_diamond_databases(strains,outdir):
	count = len(strains)
	print "Making diamond databases for", count, "strains..."
	for s in strains:
		cmds = "diamond makedb --in {}/faa/{}.faa -d {}/dmnd/{}.dmnd --quiet --threads 6".format(outdir,s,outdir,s)
		proc = subprocess.Popen(cmds.split())
		proc.wait()
		count -= 1
{'fraction_non_alphanumeric': 0.1471151216844408, 'fraction_numerical': 0.0027344818156959257, 'mean_word_length': 4.890499194847021, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1246320', 'n_tokens_mistral': 1376, 'n_tokens_neox': 1269, 'n_words': 340}