danielecook
12/4/2014 - 5:09 PM

Rename samples within a single sample bcf or vcf file using the filename

Rename samples within a single sample bcf or vcf file using the filename

function rename_to_filename {
    # Renames samples with the filename.
    tmp=`mktemp -t temp`
    echo ${1/.[vb]cf/} > $tmp
    bcftools reheader -s $tmp $1 > m.$1
    mv m.$1 $1
    bcftools index $1
}

function add_sample_prefix {
    # Adds a prefix to the samples within a bcf file.
    tmp=`mktemp -t temp`
    bcftools query -l $1 | awk -v g=$2 '{ print g $0 }'  > $tmp
    bcftools reheader -s $tmp $1 > m.$1
    mv m.$1 $1
    bcftools index $1
}