sub get_next_record { my($fh) = @_; my($offset); my($record) = ''; my($save_input_separator) = $/; $/ = "//\n"; $record = <$fh>; $/ = $save_input_separator; return $record; } sub parse_annotation { my($annotation) = @_; my(%results) = ( ); while( $annotation =~ /^[A-Z].*\n(^\s.*\n)*/gm ) { my $value = $&; (my $key = $value) =~ s/^([A-Z]+).*/$1/s; $results{$key} = $value; } return %results; } sub get_annotation_and_dna { my($record) = @_; my($annotation) = ''; my($dna) = ''; # Now separate the annotation from the sequence data ($annotation, $dna) = ($record =~ /^(LOCUS.*ORIGIN\s*\n)(.*)\/\/\n/s); # clean the sequence of any whitespace or / characters # (the / has to be written \/ in the character class, because # / is a metacharacter, so it must be "escaped" with \) $dna =~ s/[\s\/\d]//g; return($annotation, $dna) } sub parse_features { my($features) = @_; # entire FEATURES field in a scalar variable # Declare and initialize variables my(@features) = (); # used to store the individual features # Extract the features while( $features =~ /^ {5}\S.*\n(^ {21}\S.*\n)*/gm ) { my $feature = $&; push(@features, $feature); } return @features; } # Open library $fh = open_file($library); open(TT,">TT.txt"); while ($record = get_next_record($fh)){ #Get the fields from the first GenBank record in a library %fields = parse_annotation($annotation); #Annotation and DNA ($annotation, $dna) = get_annotation_and_dna($record); # Extract the features from the FEATURES table @features = parse_features($fields{'FEATURES'}); foreach my $id(@ids){ #Hier liegt das Problem!!! *1 if($record =~ /$id/){ print $id."\n"; print_sequence($dna, 60); # Print out the features foreach my $feature (@features) { # extract the name of the feature (or "feature key") my($featurename) = ($feature =~ /^ {5}(\S+)/); print TT "******** $featurename *********\n"; print TT $feature; } } } } close TT;