forked from jrcasey/PheArrMe
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscreenSubstrates.py
More file actions
executable file
·51 lines (41 loc) · 1.89 KB
/
Copy pathscreenSubstrates.py
File metadata and controls
executable file
·51 lines (41 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Check which substrates in the Biolog database are a problem for CarveMe
import pandas as pd
from src.generateMedia import load_mapping, load_baseMedium, load_soleC_lists, map_to_BiGG, build_media_tables
from src.runCarveBatch import generateMediaList, compileCommand
import subprocess
# DIRECTORIES
BASEMEDIUM_PATH = "data/biolog/baseMedium.tsv"
MAPPING_PATH = "data/biolog/mapping_Biolog_BiGG.tsv"
# load biolog mapping file
mapping = load_mapping(MAPPING_PATH)
# Check if matching BiGG ID is 'nan' or if 'include' column is 0, if not, append 'Biolog_name' to a list and 'BiGG' to another list.
matching_BiGG_IDs = []
soleC_list = []
for i in range(len(mapping)):
if not mapping.loc[i, 'BiGG'] == 'nan' and mapping.loc[i, 'include'] == 1:
matching_BiGG_IDs.append(mapping.loc[i, 'BiGG'])
soleC_list.append(mapping.loc[i, 'Biolog_name'])
# load base medium
baseMedium = load_baseMedium(BASEMEDIUM_PATH)
# generate media tables
mediaTable = build_media_tables(baseMedium, matching_BiGG_IDs, soleC_list)
# save media table to test/allMedia.tsv
mediaTable.to_csv("test/allMedia.tsv", sep='\t', index=False)
# generate a comma-separated list of the media IDs
mediaIDs = mediaTable['medium'].unique().tolist()
media_list = ','.join(mediaIDs)
# inputs for carve
genome_dir = "data/genomes/faa/13M1.1.faa" # pick a genome
mediadb_dir = "test/allMedia.tsv" # use the full media table generated above
output_dir = "test/testModel.xml"
# compile the command for each medium in the media list
for medium in mediaIDs:
cmd = compileCommand(genome_dir, medium, mediadb_dir, output_dir)
# run carve
try:
subprocess.run(cmd, check=True, stderr=subprocess.PIPE)
except subprocess.CalledProcessError as e:
# write the error to a log file
with open("test/error.log", "a") as f:
f.write(f"Command failed for medium {medium}:\n")
f.write(e.stderr.decode())