Merge pull request #2754 from solgenomics/topic/fix_homepage_add_accessions_dialog
[sgn.git] / bin / jbrowse_vcf_tools / create_indiv.pl
blob82f9be1bb230db7793119d2d875a7198b52b7a94
1 #!/usr/bin/perl
3 use warnings;
4 use strict;
5 use Getopt::Std;
7 our ($opt_v, $opt_o);
9 getopts('v:o:');
11 my $raw_vcf_file = $opt_v;
12 my $output_dir = $opt_o;
13 my @header;
14 my $vcf_file;
15 my %already_seen;
16 my $rep;
17 my $rep_num = '';
18 my $accession_name;
20 open (SNPS, "<", $raw_vcf_file) || die "Can't open $raw_vcf_file!\n";
22 while (<SNPS>) {
24 #------------------------------------------------------------------
25 # Save header info that should be present in all files into an array
26 #-------------------------------------------------------------------
28 if ($. <= 10) {
29 print $. . "\n";
30 push @header, $_;
32 } elsif (m/^#CHROM/) {
33 last;
34 } else {
36 #--------------------------------------------------------------------------------------------------
37 # Take line with individual accession name and extract that name. Use name to create output vcf file
38 #---------------------------------------------------------------------------------------------------
40 my $full_line = $_;
41 chomp ($accession_name = $full_line);
42 print "Working on accession $accession_name\n";
43 if (exists $already_seen{$accession_name}) { # check to see if this is a repetition
44 print STDERR "Rep found for $accession_name !\n";
45 $rep_num = $already_seen{$accession_name};
46 $rep_num++;
47 $already_seen{$accession_name} = $rep_num;
48 $rep = "_rep" . $rep_num;
49 } else {
50 $already_seen{$accession_name} = 1;
53 my $column_number = $.;
54 $column_number--;
56 $vcf_file = $output_dir . "/" . $accession_name . "_2015_V6" . $rep . ".vcf_" . $column_number;
57 $rep='';
59 print $vcf_file . "\n";
60 open (OUT, ">", $vcf_file) || die "Can't open $vcf_file\n";
62 #--------------------------------------------------------------
63 # Print header and info about a single accession to output file
64 #--------------------------------------------------------------
66 foreach my $line (@header) {
67 print OUT $line;