Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

print mash results to a TSV file #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion centroid.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
#Requires: mash
#Usage: python centroid.py /path/to/assemblies/

VERSION = "0.1.0"
import sys
import glob
import numpy
import operator
from operator import itemgetter
import subprocess
import argparse

def Mash_List(Mash_Index):
"""Takes in an index of Mash files and makes a list of the info from each"""
Expand Down Expand Up @@ -62,6 +64,10 @@ def Mash_List_Maker(input_assembly_list):
String1 = subprocess.check_output('mash dist ' + files + ' ' + files2, shell=True)
Output.append(String1)
Output.sort()
# write TSV to file
with open("mash-results.tsv", 'w', newline='') as tsvfile:
for item in Output:
tsvfile.write(item.decode("utf-8"))
return Output

def Mash_Centroid(input_assembly_list):
Expand All @@ -71,7 +77,18 @@ def Mash_Centroid(input_assembly_list):
Best = Averages[0][0]
return Best

Folder = sys.argv[1]

parser = argparse.ArgumentParser(
description = '''Selects optimal reference genome given a set of fasta files''',
usage = 'centroid.py [options] /path/to/fasta_files/',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)

parser.add_argument('folder', help='Folder containing *.fasta files', type=str)
parser.add_argument('--version', action='version', version=str(VERSION))
options = parser.parse_args()


Folder = options.folder
Assembly_List = glob.glob(Folder + '/*.fasta')
Centroid = Mash_Centroid(Assembly_List)
print(Centroid)
Expand Down