Last active
December 12, 2018 13:30
-
-
Save afrendeiro/b1dc600029772baaa0ff9370ec7b54b7 to your computer and use it in GitHub Desktop.
Convert SVG figures from Nature Publishing Group to CellPress style, generate high quality raster and aggregated pdfs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CURRENT_DATE=20181212 | |
NUMBER_MAIN_FIGURES=5 | |
NUMBER_SUPP_FIGURES=11 | |
ROOT_DIR=/home/path/to/paper/figures | |
cd $ROOT_DIR | |
mkdir -p cropped_unlabeled_pngs | |
# Cell Press format convertion | |
## supplementary Figure to FigureS | |
echo "Supplementary Figure to FigureS" | |
for FIGURE in $(eval echo "{1..$NUMBER_SUPP_FIGURES}") | |
do | |
echo "Supplementary Figure: " $FIGURE | |
sed -i "s/Supplementary Figure /Figure S/g" FigureS${FIGURE}.svg | |
done | |
## lowercase to uppercase panel letters | |
echo "Uppercase panel letters" | |
A='>(\w)<' | |
B='>\U\1<' | |
for FIGURE in $(eval echo "{1..$NUMBER_MAIN_FIGURES}") | |
do | |
echo "Main Figure: " $FIGURE | |
sed -ri "s/$A/$B/g" Figure${FIGURE}.svg | |
done | |
for FIGURE in $(eval echo "{1..$NUMBER_SUPP_FIGURES}") | |
do | |
echo "Supplementary Figure: " $FIGURE | |
sed -ri "s/$A/$B/g" FigureS${FIGURE}.svg | |
done | |
# Usual stuff | |
echo "Figures in A4 format" | |
for FIGURE in $(eval echo "{1..$NUMBER_MAIN_FIGURES}") | |
do | |
echo "Main Figure: " $FIGURE | |
inkscape --export-pdf=Figure${FIGURE}.pdf Figure${FIGURE}.svg | |
done | |
for FIGURE in $(eval echo "{1..$NUMBER_SUPP_FIGURES}") | |
do | |
echo "Supplementary Figure: " $FIGURE | |
inkscape --export-pdf=FigureS${FIGURE}.pdf FigureS${FIGURE}.svg | |
done | |
pdfunite $(eval echo Figure"{1..$NUMBER_MAIN_FIGURES}".pdf) MainFigures.${CURRENT_DATE}.pdf | |
pdfunite $(eval echo FigureS"{1..$NUMBER_SUPP_FIGURES}".pdf) SupplementaryFigures.${CURRENT_DATE}.pdf | |
pdfunite MainFigures.${CURRENT_DATE}.pdf SupplementaryFigures.${CURRENT_DATE}.pdf AllFigures.${CURRENT_DATE}.pdf | |
echo "Trimmed figures" | |
for FIGURE in $(eval echo "{1..$NUMBER_MAIN_FIGURES}") | |
do | |
echo "Main Figure: " $FIGURE | |
sed "s/Figure $FIGURE//g" Figure${FIGURE}.svg > Figure${FIGURE}.trimmed.svg | |
inkscape --export-area-drawing --export-pdf=Figure${FIGURE}.trimmed.pdf --export-margin=5 Figure${FIGURE}.trimmed.svg | |
inkscape --export-area-drawing --export-png=cropped_unlabeled_pngs/Figure${FIGURE}.cropped_unlabeled.png --export-background=white --export-dpi=300 --export-margin=5 Figure${FIGURE}.trimmed.svg | |
done | |
for FIGURE in $(eval echo "{1..$NUMBER_SUPP_FIGURES}") | |
do | |
echo "Supplementary Figure: " $FIGURE | |
sed "s/Figure S$FIGURE//g" FigureS${FIGURE}.svg > FigureS${FIGURE}.trimmed.svg | |
inkscape --export-area-drawing --export-pdf=FigureS${FIGURE}.trimmed.pdf --export-margin=5 FigureS${FIGURE}.trimmed.svg | |
inkscape --export-area-drawing --export-png=cropped_unlabeled_pngs/FigureS${FIGURE}.cropped_unlabeled.png --export-background=white --export-dpi=300 --export-margin=5 FigureS${FIGURE}.trimmed.svg | |
done | |
pdfunite $(eval echo Figure"{1..$NUMBER_MAIN_FIGURES}".trimmed.pdf) MainFigures.${CURRENT_DATE}.cropped_unlabeled.pdf | |
pdfunite $(eval echo FigureS"{1..$NUMBER_SUPP_FIGURES}".trimmed.pdf) SupplementaryFigures.${CURRENT_DATE}.cropped_unlabeled.pdf | |
pdfunite MainFigures.${CURRENT_DATE}.cropped_unlabeled.pdf SupplementaryFigures.${CURRENT_DATE}.cropped_unlabeled.pdf AllFigures.${CURRENT_DATE}.cropped_unlabeled.pdf | |
rm $(eval echo Figure"{1..$NUMBER_MAIN_FIGURES}".trimmed.svg) | |
rm $(eval echo Figure"{1..$NUMBER_MAIN_FIGURES}".trimmed.pdf) | |
rm $(eval echo FigureS"{1..$NUMBER_SUPP_FIGURES}".trimmed.svg) | |
rm $(eval echo FigureS"{1..$NUMBER_SUPP_FIGURES}".trimmed.pdf) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment