function [genV, genD, genJ] = load_Mus_TCR_genomic_segments(varargin)

fmt = 'struct';

n_varargs = length (varargin);
expect_arg = false;
for i = 1:n_varargs
    arg = varargin{i};
    if ~expect_arg && ischar (arg)
        switch arg
            case 'cell',
                fmt = 'cell';
            otherwise, error ('list_assignments:unknownarg', 'Unknown argument %q.', arg);
        end
    else
        if ~expect_arg
            error ('list_assignments:unexparg', 'Unexpected argument at position %d in varargin.', i);
        end
        expect_arg = false;
    end
end


%% load allele sequences

S=fastaread('data/GEN_DATA/genomicVs_curated_manual.fasta');
n_alleles = length(S);
h_info = regexp({S.Header},'\|','split');

names = cell(length(S),1);
seqs = upper({S.Sequence});
for i=1:length(S)
    names{i}= strtrim( h_info{i}{1});
end

names_split = regexp(names,'*','split');
names_split = reshape([names_split{:}],2,n_alleles);
genes = names_split(1,:);
alleles = names_split(2,:);

n_genes = length(genes);

    genV.seq = seqs';
    genV.name = names;
    genV.gene = genes';
    genV.gene_index = [1:n_genes]';

    genV.n_alleles = ones(n_alleles,1);
    genV.allele = ones(n_alleles,1);


%%



S=fastaread('data/GEN_DATA/genomicDs_C57BL6_manual.fasta');

n_alleles = length(S);
seqs = upper({S.Sequence});
names = cell(length(S),1);

for i=1:length(S)
    names{i}= strtrim(strtok(S(i).Header,'|'));
end

names_split = regexp(names,'*','split');
names_split = reshape([names_split{:}],2,n_alleles);
genes = names_split(1,:);
alleles = names_split(2,:);

unique_genes = unique(genes);
n_genes = length(unique_genes);

    genD.seq = seqs';
    genD.name = names;
    genD.gene = genes';
    genD.gene_index = [1:n_genes]';

    genD.n_alleles = ones(n_alleles,1);
    genD.allele = ones(n_alleles,1);


%%

    S = fastaread('data/GEN_DATA/genomicJs_C57BL6_manual.fasta');
    J_start_positions = load_data('data/GEN_DATA/genomicJs_start_positions','-delimiter','\n','-type','cell');
    P_temp = cellfun(@(x) regexp(x,',','split') , cellfun(@(s) subindex(regexp(s,' ','split'),2), J_start_positions{1}),'uni',false);
    J_start_positions = cellfun(@(x) cellfun(@str2num, x)', P_temp,'uni',false);
    
%J_until_primer = load_data('data/GEN_DATA/genomicJs_until_primer');

h_info = regexp({S.Header},'\|','split');
n_alleles = length(S);
seqs = upper({S.Sequence});
names = cell(length(S),1);

for i=1:length(S)
    names{i}= strtrim( h_info{i}{1});
end

names_split = regexp(names,'*','split');
names_split = reshape([names_split{:}],2,n_alleles);
genes = names_split(1,:);
alleles = names_split(2,:);

unique_genes = unique(genes);
n_genes = length(unique_genes);


    genJ.seq = seqs';
    genJ.name = names;
    genJ.gene = genes';
    genJ.gene_index = zeros(n_alleles,1);

    for i=1:n_alleles
        genJ.gene_index(i) = find(strcmp(unique_genes, genJ.gene(i)));
    end

    genJ.read_start_positions = J_start_positions;
    genJ.n_alleles = zeros(n_alleles,1);
    genJ.allele = zeros(n_alleles,1);
    %genJ.seq_until_primer = cell(n_alleles,1);

    for i=1:n_alleles
        this_gene_alleles = genJ.gene_index==genJ.gene_index(i);
        genJ.n_alleles(i) = sum(this_gene_alleles);
        genJ.allele(i) = sum(this_gene_alleles(1:i-1)) + 1;
        %genJ.seq_until_primer{i} = J_until_primer.Sequence_Until_Primer{genJ.gene_index(i)};
    end



%%

if strcmp(fmt,'struct')
    genV = struct_of_arrays_to_array_of_structs(genV);
    genD = struct_of_arrays_to_array_of_structs(genD);
    genJ = struct_of_arrays_to_array_of_structs(genJ);
end



end
