[Bio] / FigMetagenomeTools / renumber_sequences.pl Repository:
ViewVC logotype

Diff of /FigMetagenomeTools/renumber_sequences.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4, Sat Apr 14 22:35:31 2007 UTC revision 1.5, Tue Jul 10 16:39:58 2007 UTC
# Line 38  Line 38 
38   elsif ($t eq "-p") {$asm_path = shift}   elsif ($t eq "-p") {$asm_path = shift}
39  }  }
40    
41  unless ($qualf) {$qualf = $fastaf.".qual"}  #unless ($qualf) {$qualf = $fastaf.".qual"}
42    
43  die $usage unless (-e $fastaf && -e $qualf);  die $usage unless (-e $fastaf);
44  my ($count, $max);  my ($count, $max);
45    
46  $dbh->begin_work();  $dbh->begin_work();
# Line 78  Line 78 
78          $genome_name = <STDIN>;          $genome_name = <STDIN>;
79          chomp($genome_name);          chomp($genome_name);
80      }      }
     my $res = $dbh->selectall_arrayref("select count from genome where name = ?", undef, $genome_name);  
     if (@$res)  
     {  
         die "The genome $genome_name already appears in the database as number $count\n";  
     }  
81    
82      $count = $res->[0]->[0];      #
83        # Allow duplicate genome names.
84        #
85        # my $res = $dbh->selectall_arrayref("select count from genome where name = ?", undef, $genome_name);
86        # if (@$res)
87        # {
88    #       die "The genome $genome_name already appears in the database as number $count\n";
89     #    }
90    
91      #   $count = $res->[0]->[0];
92    
93      if ($ask_user)      if ($ask_user)
94      {      {
# Line 123  Line 127 
127          map {$fasta->{$seqs->{$_}}=$_} keys %$seqs;          map {$fasta->{$seqs->{$_}}=$_} keys %$seqs;
128  }  }
129    
130  my $qual=Rob->read_fasta($qualf, 1);  my $qual;
131    if ($qualf)
132    {
133        $qual=Rob->read_fasta($qualf, 1);
134  map {$qual->{$_} =~ s/\s+/ /g} keys %$qual;  map {$qual->{$_} =~ s/\s+/ /g} keys %$qual;
135    }
136    
137  print "Inserting data into database and rewriting files\n";  print "Inserting data into database and rewriting files\n";
138  open (FA, ">$count.fa") || die "Can't open $count.fa for writing\n";  open (FA, ">$count.fa") || die "Can't open $count.fa for writing\n";
139    if ($qualf)
140    {
141  open (QU, ">$count.qual") || die "Can't open $count.qual for writing\n";  open (QU, ">$count.qual") || die "Can't open $count.qual for writing\n";
142    }
143    
144    $dbh->begin_work();
145  my $exc=$dbh->prepare(qq(insert into DNA ( genome, original_name, trace_file, sequence_file, quality_file)  my $exc=$dbh->prepare(qq(insert into DNA ( genome, original_name, trace_file, sequence_file, quality_file)
146                           values (?, ?, ?, ?, ?)));                           values (?, ?, ?, ?, ?)));
147    
# Line 137  Line 149 
149  {  {
150      my $id;      my $id;
151    
152      unless ($qual->{$s}) {print STDERR "No quality for $s. Skipped\n"; next}      if ($qualf)
153        {
154            if (!$qual->{$s})
155            {
156                print STDERR "No quality for $s. Skipped\n";
157                next;
158            }
159        }
160    
161      if ($genomeno)      if ($genomeno)
162      {      {
# Line 150  Line 169 
169      }      }
170    
171      print FA ">$id\n", $fasta->{$s}, "\n";      print FA ">$id\n", $fasta->{$s}, "\n";
172        if ($qualf)
173        {
174      print QU ">$id\n", $qual->{$s}, "\n";      print QU ">$id\n", $qual->{$s}, "\n";
175  }  }
176    }
177    close(FA);
178    close(QU) if $qualf;
179    $dbh->commit();

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3