comparison libs/sratoolkit.2.8.0-centos_linux64/example/perl/splitfastq.pl @ 3:38ad1130d077 draft

planemo upload commit a4fb57231f274270afbfebd47f67df05babffa4a-dirty
author charles_s_test
date Mon, 27 Nov 2017 11:21:07 -0500
parents
children
comparison
equal deleted inserted replaced
2:0d65b71ff8df 3:38ad1130d077
1 #!/usr/bin/perl -w
2
3 use IO::File;
4
5 my $line;
6 my $state = 0;
7 my %filehandles;
8 my $current_filehandle;
9 my $base = $ARGV[ 0 ];
10
11 if ( !defined ( $base ) )
12 {
13 $base = "out";
14 }
15
16 while ( defined ( $line = <STDIN> ) )
17 {
18 #remove line-feeds, white space etc.
19 chomp( $line );
20
21 if ( $state == 0 )
22 {
23 # get the first word
24 my $word0 = ( split( /\s+/, $line ) )[ 0 ];
25
26 # start with the beginning of the word, until '/' found, continue with numbers to end of string
27 if ( $word0 =~ /^[^\/]+\/(\d+)$/ )
28 {
29 # grep what matched after the '/'
30 my $selector = $1;
31 if ( !defined ( $filehandles{$selector}) )
32 {
33 $filehandles{$selector} = new IO::File( "$base.$selector.fastq", "w" );
34 }
35 $current_filehandle = $filehandles{$selector};
36 }
37 }
38
39 if ( defined( $current_filehandle ) )
40 {
41 $current_filehandle -> print( "$line\n" );
42 }
43
44 $state ++;
45 $state &= 0x3;
46 }