-
Notifications
You must be signed in to change notification settings - Fork 10
/
MakeSuppFigures.py
87 lines (73 loc) · 2.33 KB
/
MakeSuppFigures.py
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python
# coding: utf-8
"""
Make latex file for supplementary figures
"""
import os
import argparse
import pandas
from narps import Narps
preamble = '''\\documentclass[10pt]{article}
\\usepackage[margin=1in]{geometry}
\\geometry{letterpaper}
\\usepackage{graphicx}
\\usepackage{amssymb}
\\usepackage{epstopdf}
\\usepackage{caption}
\\usepackage{hyperref}
\\title{Supplementary Figures}
\\author{Botvinick-Nezer et al.}
\\begin{document}
'''
finale = '\\end{document}\n'
def make_supp_figure_file(narps, figheight=8):
narps.dirs.get_output_dir('SupplementaryMaterials', base='figures')
# load supp figure info
latex = preamble
info = pandas.read_csv('SuppFiguresInfo.tsv', sep='\t')
for i in range(info.shape[0]):
caption = info.loc[i, 'Caption'].replace(
'#', '\\#').replace('%', '\\%')
imgfile = os.path.join(
narps.basedir,
info.loc[i, 'File']
)
latex += '\\begin{figure}[htbp]\n'
latex += '\\begin{center}\n'
latex += '\\includegraphics[height=%din]{%s}\n' % (
info.loc[i, 'Height'], imgfile)
latex += '\\caption*{Supplementary Figure %d: %s}\n' % (
info.loc[i, 'Number'],
caption)
latex += '\\end{center}\n'
latex += '\\end{figure}\n'
latex += '\\newpage\n\n'
latex += finale
outfile = os.path.join(
narps.dirs.dirs['SupplementaryMaterials'],
'SupplementaryFigures.tex'
)
with open(outfile, 'w') as f:
f.write(latex)
if __name__ == "__main__":
# parse arguments
parser = argparse.ArgumentParser(
description='Make latex file for supplementary figures')
parser.add_argument('-b', '--basedir',
help='base directory')
parser.add_argument('-t', '--test',
action='store_true',
help='use testing mode (no processing)')
args = parser.parse_args()
# set up base directory
if args.basedir is not None:
basedir = args.basedir
elif 'NARPS_BASEDIR' in os.environ:
basedir = os.environ['NARPS_BASEDIR']
print("using basedir specified in NARPS_BASEDIR")
else:
basedir = '/data'
print("using default basedir:", basedir)
narps = Narps(basedir)
if not args.test:
make_supp_figure_file(narps)