---
# System prepended metadata

title: Workflow (final?) Floragenex VCF to Eurofins order form

---

# Workflow (final?) Floragenex VCF to Eurofins order form

## Step 1: set working directory
in home/cjncc/Research/primer_design/full_workflow, add fileLooper.sh, removeDuplicateRADkmers.py and primer_txt2csv.sh

## Step 2: add edited VCF file
Here, I elected to use 22indiv_standard.recode.vcf, manually copied and pasted to save vcf as csv file, and renamed to 22_standard.csv in the working directory. (Initially attempted with 24_50 and 24_25 standards and relaxed, though every instance has a duplicate entry, so removeDuplicates produces a file with no SNPs).


## removeDuplicateRADkmers2fasta.py --> output to .fasta
1. in working directory:
    `$ python3 removeDuplicateRADkmers2fasta.py`
    `>>> recode csv (in this dir) to remove duplicates: (type 22_standard.csv)`
    `>>> desired output name: (DATE)_22_standard.fasta`
    
## Step 4. multiFasta --> individual fasta files
1. `$ splitfasta (DATE)_22_standard.fasta`
there will now be a directory that will be called ./(DATE)_22_standard_split_files and will contain all individual SNPs in fasta format that were generated from our starting VCF file download.

## Step 5. primer3 looper script (split fasta files --> one text file containing all generated primer designed metrics)
1. edit directories in fileLooper.sh so that we utilize split_files from (DATE)_22_standard_split_files, as demonstrated below:
```
#!/bin/bash

for FILE in /home/cjncc/Research/primer_design/full_workflow/10Jan2023_22_standard_split_files/* ; do
	printf "PRIMER_PICK_LEFT_PRIMER=1\nPRIMER_PICK_RIGHT_PRIMER=1\nPRIMER_OPT_SIZE=18\nPRIMER_MIN_SIZE=15\nPRIMER_MAX_SIZE=21\n=" >> $FILE
	sed -i '1s/^/SEQUENCE_ID=/' $FILE
	sed -i '2s/^/SEQUENCE_TEMPLATE=/' $FILE
done

for f in /home/cjncc/Research/primer_design/full_workflow/10Jan2023_22_standard_split_files/* ; do
	(primer3_core < $f) 2>&1 | tee -a ${f}_primer3_out.txt
done

for FILE in ./10Jan2023_22_standard_split_files/*out.txt; do
seqid=$ grep SEQUENCE_ID= $FILE
```
2. edit output file title at line 27 to reflect the primer metric printed text file. In this example it is titled (DATE)_22Indiv_standard_primer_metrics_printed.txt
3. Save file
4. run primer3 executing script:
    `$ sh fileLooper.sh`
We will now have a primer3_out.txt file for each .fasta within the (DATE)_22_standard_split_files, along with .fasta files that are edited for prorgam primer3. Additionally, there will be a file titled (DATE)_22Indiv_standard_primer_metrics_printed.txt, that will be a collection of primer3 outputs for each .fa file including RAD_kmer, sequence template, left and right primer sequence, and left and right Tm values.
## Step 6. primer_txt2csv.sh to condense primer3 output in a more human readable format, eases effort for completing Eurofins plate order form. This script also includes an important conditional statement that only operates with primer3 outputs that successfully generated primers.
1. edit directories as follows, to utilize correct primer3 out files, along with appropriatly named output txt files:
```
#!/bin/bash

for FILE in ./10Jan2023_22_standard_split_files/*out.txt; do

# NEED CONDTIONAL TO ONLY PARSE THROUGH PRIMER3 OUTPUTS THAT SUCCESSFULLY GENERATED SEQUENCES FOR PRIMER_0_LEFT AND PRIMER_0_RIGHT
if grep -q PRIMER_LEFT_0_SEQUENCE= "$FILE"; then
	grep -A 0 SEQUENCE_ID=< $FILE
	grep -A 0 PRIMER_LEFT_0_SEQUENCE= $FILE
	grep -A 0 PRIMER_RIGHT_0_SEQUENCE= $FILE
fi

# WRITE TO OUTPUT FILE
done > 10Jan2023_22_standard_primers_shortlist.txt

# REMOVE PRIMER3 FORMATTING

for FILEE in /home/cjncc/Research/primer_design/full_workflow/10Jan2023_22_standard_primers_shortlist.txt; do
grep 'SEQUENCE_ID=>' $FILEE | sed 's/^.*=>//'
done > 10Jan2023_22_standard_RAD_kmer_primers.txt

for FILEEE in /home/cjncc/Research/primer_design/full_workflow/10Jan2023_22_standard_primers_shortlist.txt; do
grep 'PRIMER_LEFT_0_SEQUENCE=' $FILEEE | sed 's/^.*PRIMER_LEFT_0_SEQUENCE=//'
done > 10Jan2023_22_standard_primer_seq_LEFT.txt

for FILEEE in /home/cjncc/Research/primer_design/full_workflow/10Jan2023_22_standard_primers_shortlist.txt; do
grep 'PRIMER_RIGHT_0_SEQUENCE=' $FILEEE | sed 's/^.*PRIMER_RIGHT_0_SEQUENCE=//'
done > 10Jan2023_22_standard_primer_seq_RIGHT.txt
```
2. save primer_txt2csv.sh
3. run script
```
$ sh primer_txt2csv.sh
```
This will output three txt files that can easily be addded to a Eurofins or IDT primer set order form.


