From: Heng Li Date: Sun, 18 Oct 2009 02:05:20 +0000 (+0000) Subject: added a small unitity to parse SRA XML files X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=963fc75c752879489adb8e42671e6fb964d6834d;p=samtools.git added a small unitity to parse SRA XML files --- diff --git a/misc/samtools.pl b/misc/samtools.pl index 12dca31..320e8aa 100755 --- a/misc/samtools.pl +++ b/misc/samtools.pl @@ -11,7 +11,7 @@ my $version = '0.3.3'; my $command = shift(@ARGV); my %func = (showALEN=>\&showALEN, pileup2fq=>\&pileup2fq, varFilter=>\&varFilter, - unique=>\&unique, uniqcmp=>\&uniqcmp); + unique=>\&unique, uniqcmp=>\&uniqcmp, sra2hdr=>\&sra2hdr); die("Unknown command \"$command\".\n") if (!defined($func{$command})); &{$func{$command}}; @@ -226,6 +226,59 @@ sub p2q_print_str { } } +# +# sra2hdr +# + +# This subroutine does not use an XML parser. It requires that the SRA +# XML files are properly formated. +sub sra2hdr { + my %opts = (); + getopts('', \%opts); + die("Usage: samtools.pl sra2hdr \n") if (@ARGV == 0); + my $pre = $ARGV[0]; + my $fh; + # read sample + my $sample = 'UNKNOWN'; + open($fh, "$pre.sample.xml") || die; + while (<$fh>) { + $sample = $1 if (/) { + if (/\s*(\S+)\s*<\/LIBRARY_NAME>/i) { + $exp2lib{$exp} = $1; + } + } + close($fh); + # read run + my ($run, @fn); + open($fh, "$pre.run.xml") || die; + while (<$fh>) { + if (//i) { + if (@fn == 1) { + print STDERR "$fn[0]\t$run\n"; + } else { + for (0 .. $#fn) { + print STDERR "$fn[$_]\t$run", "_", $_+1, "\n"; + } + } + } + } + close($fh); +} + # # unique #