#!/bin/bash

shopt -s expand_aliases

alias ~=”:«’~bash’”

:«’~~~bash’

Usage

$ sxExtractMarker.sh plasmid_file \
    >marker1 \
    3>marker2
---
title: sxExtractMarker.sh
---
flowchart TD
    PF[(
        

plasmid_file

adapter#0040;20bp#0041; + sgRNA#0040;20bp#0041; + scaffold#0040;83/93bp#0041; + query#0040;44bp#0041; + 3bp + RCbarcode#0040;18bp#0041; + RCprimer#0040;21bp#0041;
...
)] --> SEM[sxExtractMarker.sh] SEM --> MK1[(

stdout

primer#0040;21bp#0041; + barcode#0040;18bp#0041;
...
)] SEM --> MK2[(

fd3

adapter#0040;20bp#0041; + sgRNA#0040;20bp#0041; + scaffold#0040;83/93bp#0041;
...
)]

Source

getSxPlasmidFilePrimer()
{
    # Usage: getSxPlasmidFilePrimer <plasmid_file
    rev | sed -r 's/^\s+//' | cut -c1-21 | dd conv=ucase 2>/dev/null | tr 'ACGT' 'TGCA'
}

getSxPlasmidFileBarcode()
{
    # Usage: getSxPlasmidFileBarcode <plasmid_file
    rev | sed -r 's/^\s+//' | cut -c22-39 | dd conv=ucase 2>/dev/null | tr 'ACGT' 'TGCA'
}

getSxPlasmidFileAdapter()
{
    # Usage: getSxPlasmidFileAdapter <plasmid_file
    cut -d, -f2 | cut -c1-20 | dd conv=ucase 2>/dev/null
}

getSxPlasmidFilesgRNA()
{
    # Usage: getSxPlasmidFilesgRNA <plasmid_file
    cut -d, -f2 | cut -c21-40 | dd conv=ucase 2>/dev/null
}

getSxPlasmidFileScaffold()
{
    # Usage: getSxPlasmidFileScaffold <plasmid_file
    cut -d, -f2 | sed -r 's/^[ACGTN]+//; s/[ACGTN]+\s+$//' | dd conv=ucase 2>/dev/null
}

getSxFaHead()
{
    # Usage: getSxFaHead <plasmid_file
    awk '{print ">" NR - 1}'
}

plasmid_file=$1
paste -d "" <(getSxPlasmidFilePrimer <"${plasmid_file}") <(getSxPlasmidFileBarcode <"${plasmid_file}") | paste -d "\n" <(getSxFaHead <"${plasmid_file}") - >&1

paste -d "" <(getSxPlasmidFileAdapter <"${plasmid_file}") <(getSxPlasmidFilesgRNA <"${plasmid_file}") <(getSxPlasmidFileScaffold <"${plasmid_file}") | paste -d "\n" <(getSxFaHead <"${plasmid_file}") - >&3
alias ~~~=":" # This suppresses a warning and is not part of source.