]> git.donarmstrong.com Git - biopieces.git/commitdiff
added --check to a number of Biopieces
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Mon, 8 Dec 2008 03:57:44 +0000 (03:57 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Mon, 8 Dec 2008 03:57:44 +0000 (03:57 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@341 74ccb610-7750-0410-82ae-013aeee3265d

code_perl/Maasha/Biopieces.pm
code_perl/Maasha/Match.pm
code_perl/Maasha/UCSC/BED.pm
code_python/Cjung/Args.pyc
code_python/Cjung/lowercase_seq

index cbd0e1f16b531913d385b88fa1282a8ee7ec646c..161f73d16eb39daa0d0f388f1082240bc10798ac 100644 (file)
@@ -328,6 +328,7 @@ sub get_options
             data_in|i=s
             cols|c=s
             num|n=s
+            check|C
         );
     }
     elsif ( $script eq "read_fixedstep" )
@@ -428,6 +429,18 @@ sub get_options
             num|n=s
         );
     }
+    elsif ( $script eq "assemble_tag_contigs" )
+    {
+        @options = qw(
+            check|C
+        );
+    }
+    elsif ( $script eq "calc_fixedstep" )
+    {
+        @options = qw(
+            check|C
+        );
+    }
     elsif ( $script eq "format_genome" )
     {
         @options = qw(
@@ -672,6 +685,7 @@ sub get_options
     {
         @options = qw(
             cols|c=s
+            check|C
             no_stream|x
             data_out|o=s
             compress|Z
@@ -988,7 +1002,7 @@ sub get_options
             use_score|u
             visibility|V=s
             color|c=s
-            chunk_size|C=s
+            check|C
         );
     }
 
@@ -1037,7 +1051,7 @@ sub get_options
 
     # print STDERR Dumper( \%options );
 
-    $real = "beg|end|word_size|wrap|chunk_size|tile_size|len|prefix_length|mismatches|offset|num|skip|cpus|window_size|step_size";
+    $real = "beg|end|word_size|wrap|tile_size|len|prefix_length|mismatches|offset|num|skip|cpus|window_size|step_size";
 
     foreach $opt ( keys %options )
     {
@@ -1448,7 +1462,7 @@ sub script_read_bed
     {
         $data_in = Maasha::Common::read_open( $file );
 
-        while ( $bed_entry = Maasha::UCSC::BED::bed_entry_get( $data_in, $cols, 1 ) )
+        while ( $bed_entry = Maasha::UCSC::BED::bed_entry_get( $data_in, $cols, $options->{ 'check' } ) )
         {
             $record = Maasha::UCSC::BED::bed2biopiece( $bed_entry );
 
@@ -2188,7 +2202,7 @@ sub script_assemble_tag_contigs
         {
             $strand = $record->{ 'STRAND' } || '+';
 
-            Maasha::UCSC::BED::bed_entry_put( $bed_entry, $fh_out, $cols, 1 );
+            Maasha::UCSC::BED::bed_entry_put( $bed_entry, $fh_out, $cols, $options->{ 'check' } );
         }
     }
 
@@ -2207,7 +2221,7 @@ sub script_assemble_tag_contigs
 
         $fh_in = Maasha::Filesys::file_read_open( $tag_file );
 
-        while ( $bed_entry = Maasha::UCSC::BED::bed_entry_get( $fh_in, $cols ) )
+        while ( $bed_entry = Maasha::UCSC::BED::bed_entry_get( $fh_in, $cols, $options->{ 'check' } ) )
         {
             if ( $record = Maasha::UCSC::BED::bed2biopiece( $bed_entry ) ) {
                 put_record( $record, $out );
@@ -2664,7 +2678,7 @@ sub script_calc_fixedstep
     while ( $record = get_record( $in ) ) 
     {
         if ( $bed_entry = Maasha::UCSC::BED::biopiece2bed( $record, $cols ) ) {
-            Maasha::UCSC::BED::bed_entry_put( $bed_entry, $fh_out, $cols, 1 );
+            Maasha::UCSC::BED::bed_entry_put( $bed_entry, $fh_out, $cols, $options->{ 'check' } );
         }
     }
 
@@ -4312,7 +4326,7 @@ sub script_write_bed
         $record = Maasha::UCSC::psl2record( $record ) if $record->{ 'tBaseInsert' }; # Dirty addition to allow Affy data from MySQL to be dumped
 
         if ( $bed_entry = Maasha::UCSC::BED::biopiece2bed( $record, $cols ) ) {
-            Maasha::UCSC::BED::bed_entry_put( $bed_entry, $fh, $cols, 1 );
+            Maasha::UCSC::BED::bed_entry_put( $bed_entry, $fh, $cols, $options->{ 'check' } );
         }
 
         put_record( $record, $out ) if not $options->{ 'no_stream' };
@@ -6195,7 +6209,7 @@ sub script_upload_to_ucsc
             $columns = $record->{ "BED_COLS" };
 
             if ( $entry = Maasha::UCSC::BED::biopiece2bed( $record, $columns ) ) {
-                Maasha::UCSC::BED::bed_entry_put( $entry, $fh_out, $columns, 1 );
+                Maasha::UCSC::BED::bed_entry_put( $entry, $fh_out, $columns, $options->{ 'check' } );
             }
         }
         elsif ( $record->{ "REC_TYPE" } eq "PATSCAN" and $record->{ "CHR" } )
@@ -6204,7 +6218,7 @@ sub script_upload_to_ucsc
             $columns = 6;
 
             if ( $entry = Maasha::UCSC::BED::biopiece2bed( $record, $columns ) ) {
-                Maasha::UCSC::BED::bed_entry_put( $entry, $fh_out, $columns, 1 );
+                Maasha::UCSC::BED::bed_entry_put( $entry, $fh_out, $columns, $options->{ 'check' } );
             }
         }
         elsif ( $record->{ "REC_TYPE" } eq "BLAST" and $record->{ "S_ID" } =~ /^chr/ )
@@ -6215,7 +6229,7 @@ sub script_upload_to_ucsc
             $record->{ "SCORE" } = $record->{ "BIT_SCORE" } * 1000;
 
             if ( $entry = Maasha::UCSC::BED::biopiece2bed( $record, $columns ) ) {
-                Maasha::UCSC::BED::bed_entry_put( $entry, $fh_out, $columns, 1 );
+                Maasha::UCSC::BED::bed_entry_put( $entry, $fh_out, $columns, $options->{ 'check' } );
             }
         }
         elsif ( $record->{ "REC_TYPE" } eq "VMATCH" and $record->{ "S_ID" } =~ /^chr/i )
@@ -6224,7 +6238,7 @@ sub script_upload_to_ucsc
             $columns = 6;
 
             if ( $entry = Maasha::UCSC::BED::biopiece2bed( $record, $columns ) ) {
-                Maasha::UCSC::BED::bed_entry_put( $entry, $fh_out, $columns, 1 );
+                Maasha::UCSC::BED::bed_entry_put( $entry, $fh_out, $columns, $options->{ 'check' } );
             }
         }
 
index 240dd8de28eb654862e385fbf950df9166b882cb..c9b5bd729fd8927b1fd38c9df2242028d97a037b 100644 (file)
@@ -207,6 +207,7 @@ sub match_vmatch
             next if $options->{ "max_hits" } and $count_list->[ $fields[ 5 ] ] > $options->{ 'max_hits' };
 
             $fields[ 1 ] = $index_files->[ $i ];                                     # S_ID
+            $fields[ 9 ] = int $fields[ 9 ];
             $fields[ 9 ] = $count_list->[ $fields[ 5 ] ] if $options->{ "count" };   # SCORE
             $fields[ 5 ] = $seq_names[ $fields[ 5 ] ];                               # Q_ID
 
index f12c8b913dc2ba73c11722da2874eeaf46733785..2fde7c941177d2e4f80518ba8a7d64d38a94082a 100644 (file)
@@ -215,13 +215,13 @@ sub bed_entry_check
         Maasha::Common::error( qq(Bad BED entry - chromEnd must be greater than chromStart - not "$bed->[ chromStart ] > $bed->[ chromEnd ]") );
     }
 
-    return if @{ $bed } == 3;
+    return if $cols == 3;
 
     if ( $bed->[ name ] =~ /\s/ ) {
         Maasha::Common::error( qq(Bad BED entry - no white space allowed in name field: "$bed->[ name ]") );
     }
 
-    return if @{ $bed } == 4;
+    return if $cols == 4;
 
     if ( $bed->[ score ] =~ /\D/ ) {
         Maasha::Common::error( qq(Bad BED entry - score must be a whole number - not "$bed->[ score ]") );
@@ -232,13 +232,13 @@ sub bed_entry_check
         Maasha::Common::error( qq(Bad BED entry - score must be between 0 and 1000 - not "$bed->[ score ]") );
     }
 
-    return if @{ $bed } == 5;
+    return if $cols == 5;
 
     if ( $bed->[ strand ] ne '+' and $bed->[ strand ] ne '-' ) {
         Maasha::Common::error( qq(Bad BED entry - strand must be + or - not "$bed->[ strand ]") );
     }
 
-    return if @{ $bed } == 6;
+    return if $cols == 6;
 
     if ( $bed->[ thickStart ] =~ /\D/ ) {
         Maasha::Common::error( qq(Bad BED entry - thickStart must be a whole number - not "$bed->[ thickStart ]") );
@@ -268,13 +268,13 @@ sub bed_entry_check
         Maasha::Common::error( qq(Bad BED entry - thickEnd must be less than chromEnd - not "$bed->[ thickEnd ] > $bed->[ chromEnd ]") );
     }
 
-    return if @{ $bed } == 8;
+    return if $cols == 8;
 
     if ( $bed->[ itemRgb ] !~ /^(0|\d{1,3},\d{1,3},\d{1,3},?)$/ ) {
         Maasha::Common::error( qq(Bad BED entry - itemRgb must be 0 or in the form of 255,0,0 - not "$bed->[ itemRgb ]") );
     }
 
-    return if @{ $bed } == 9;
+    return if $cols == 9;
 
     if ( $bed->[ blockCount ] =~ /\D/ ) {
         Maasha::Common::error( qq(Bad BED entry - blockCount must be a whole number - not "$bed->[ blockCount ]") );
index cce3509a33c7afeff94d9d5366385e2d0fbe1b33..8b121787fa51f401453d056b37e17c49ecd4e740 100644 (file)
Binary files a/code_python/Cjung/Args.pyc and b/code_python/Cjung/Args.pyc differ
index c608e80d051a31d6971b8133139acd94f426cd88..b51df83a5ebb2007de9e86f866a71c2202c1fc84 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/python
 
-import os, string, sys, getopt, Args
+import os, string, sys, getopt, Args, optparse
 
 record_delimiter = "\n---\n"
 
@@ -54,6 +54,11 @@ class Lowercase_seq:
                rec = ''
                eof_flag = False
                while not self.eo_buffer:
+                       #print "STDIN.ISATTY :", self.in_stream.isatty()
+
+                       if self.in_stream.isatty():
+                               eof_flag = True
+
                        if eof_flag:
                                if self.buffer == '':
                                        self.eo_buffer = True
@@ -103,6 +108,7 @@ class Lowercase_seq:
 
        ###########################################
        def print_usage(self, opt):
+               #print opt
                bp_dir = os.environ['BP_DIR']
                usage_path = bp_dir + os.path.sep + "bp_usage" + os.path.sep + "lowercase_seq.wiki"
                os.system("print_usage -i %s %s" % (usage_path, opt))
@@ -111,53 +117,46 @@ class Lowercase_seq:
 
 # main
 
-"""
-print "############"
-print len(sys.argv)
-print sys.argv
-print "############"
-"""
-
-
 lc_seq = Lowercase_seq()
 
-a = Args.Args('Usage: %(progname)s [-a value] [-b value] [-c] word [file...]')
-
-a.opt['-I'] = ''    # input file
-a.opt['-O'] = ''    # output file
-a.getopt('I:O:?:v')                    # get user supplied option values
-
-#print >> sys.stderr, a.opt
+try:
+       opts, args = getopt.getopt(sys.argv[1:], "I:O:?vx", ["stream_in=", "stream_out=", "help", "verbose", "no_stream"])
+except getopt.GetoptError, err:
+       # print help information and exit:
+       print str(err) # will print something like "option -a not recognized"
+       lc_seq.print_usage("")
+       sys.exit(2)
 
-word = a.shift()                       # get the first of the remaining arguments
-                                                       # use a.pop() to get the last instead
-if not word == None:
-       sys.stderr.write("Unknown argument %s\n" % (word))
-       sys.exit(1)
 
-if sys.stdin.isatty():
-       lc_seq.print_usage('')
+if len(opts)==0:
+       lc_seq.print_usage("")
        sys.exit(1)
 
-#for line in a:              # iterate over the contents of all remaining arguments (file names)
-#      if a.lineno == 1:
-#              print 'starting new file:', a.infile
-#      a.warning(line.rstrip())
-
-#print 'Options:', a.opt
-#print 'Word:', word
-#print 'Total number of lines:', a.linesum
-
-
-if a.opt.has_key('-?'):
-       lc_seq.print_usage('-?')
-       sys.exit(1)
-else:
-       try:
-               lc_seq.open_streams(a.opt['-I'], a.opt['-O'])
-       except:
-               sys.stderr.write("%s\n" % ("IOError"))
+stream_in = ""
+stream_out = ""
+verbose = False
+for o, a in opts:
+       if o in ("-I", "--stream_in"):
+               stream_in = a
+       elif o in ("-O", "--stream_out"):
+               stream_out = a
+       elif o == "-?":
+               lc_seq.print_usage("")
+               sys.exit(1)
+       elif o == "--help":
+               lc_seq.print_usage("-?")
                sys.exit(1)
+       elif o in ("-v", "--verbose"):
+               verbose = True
+       #else:
+       #       assert False
+       #       print_usage()
+
+try:
+       lc_seq.open_streams(stream_in, stream_out)
+except:
+       sys.stderr.write("%s\n" % ("IOError"))
+       sys.exit(1)
 
 
 while True: