你好,我在使用以下代码时遇到问题,在程序所在的文件夹中名为data的文件夹中有一个fasta文件(文本)。
此文件就是这样
GI | 199581428 | GB | EU710615.1 | Flavobacterium columnare Fclis(fclIS)基因,完整的cds ATGGTAGAAACTCAATTTAAAAATACGGATATCGGGTTGATTCCTGAGGATTGGGAAGTGAAACAATTAG GAGAAGTTATAACATTAATTAATGGTCGAGCATATTCTCAGAATGAATTATTATTTAATGGAAAATACAG GGTTTTGAGAGTTGGAAATTTCTTTTCAAGTGACAAATGGTATTGGAGTAATTTAGAATTAGCAAGTAAA TTCTATGTAAATAAAGGGGATTTAATGTATGCTTGGTCTGCATCCTTTGGTCCAAAATTTTGGAAAAACG AAAAGACAATTTACCATTATCATATTTGGAAAATCGAATTATCTGAATATTTAGATAAGTTTTATCTTTT TTATGTACTTGAAAAGGATAAAGAGAATATTTTAAATCAATCACAAGGTGGAACAATGTTTCATATAACT AAGGAATCAATGGAAAAAAGAAAAATTCCAATTCCTTCTTTAAAAGAACAACAAGCCATCGCCGAAGTAT TATCTGATACCGATGCTTGGATAGAAAGCCTTGAAAAACTTATTACTAAAAAACGCTTGGTAAAACAAGG AGCAATGCAACAACTTTTAACACCCAAAGAGGATTGGGAGGTAAAGAAGTTGGGAGAAATAGCTGAAGTT AGAGATGGTACTCACCAAACTCCAACTTACGTAGAAAGTGGAATACCATTTTATAGTGTAGAAAGTGTCA CTAAAAACGATTTCAAGAATACAAAATACATTTCAGAACAAGAACATAAAATTCTTACAAAGTCCTTTAG AATTGAAAAAGGCGATATATTAATGACACGAATTGGGTCAATTGGAGATTGTAAATTAATTGATTGGGAT GTCAATGCAAGTTTTTATGTAAGCTTAGCATTATTAAAAGTAAAACCCATATTTTCAGCTAATTATTTAT GTCACTATTCAAAAACAGAAAATTTCAAAAAAGAGATAGATATAAATTCATTACAATCTGCAATTCCTAA AAAAATAAATCTAGGTCCTATTTCTAACGTAAAAATAGAATTTCCGTCACTTGATGAACAACAACGTATC GCAACCATTCTGTCCGATATGGATGCCGAAATAGAACATTTAGAAAAGAAACTCAACAAAGCCAAGCAAC TCAAACAAGGGATAATGCAACAGTTACTTACGGGTAAAATACGCTTAATTGCTGGGGATTAA
当用户STDIN是" AluI"时,我无法对输出进行排序,我想对哈希进行排序,以便通过输入' /'来排序输出的哈希值。输出中的网站从最早到最晚排序。
my $DIRNAME = 'data';
my %RE =( 'AatII' => 'GACGTC 5', 'AccI' => 'GTMKAC 2', 'AclI' => 'AACGTT 2', 'AcyI' => 'GRCGYC 2', 'AflII' => 'CTTAAG 1', 'AflIII' => 'ACRYGT 1', 'AgeI' => 'ACCGGT 1', 'AhaIII' => 'TTTAAA 3', 'AhdI' => 'GACNNNNNGTC 6', 'AluI' => 'AGCT 2', );
my $input='';
my @enz = keys %RE;
opendir(my $dh, $DIRNAME) || die 'Error opening directory: ' . $DIRNAME;
# Get the list of files
my @filenames = readdir($dh);
my $file_count = @filenames;
# Filter out files without .fa extension
@filenames = grep { /\.fa$/ } @filenames;
# Sort the filenames
@filenames = sort @filenames;
foreach my $filename (@filenames) {
my $fh;
my $path = sprintf('%s/%s', $DIRNAME, $filename);
if (!open($fh, $path)) {print 'Failed to open %s; skipping', $path;
next;
}
my $header = <$fh>;
chomp $header;
if ($header =~ />gi\|(\d+)\|gb\|(\w+)\.(\d+)\|(.+)$/) {
print '*' x 80;
print "\n";
print "filename: $filename";
print "\n";
print "gi number: $1";
print "\n";
print "accession number: $2";
print "\n";
print "version: $3";
print "\n";
print "description: $4";
print "\n";
while ($input ne 'quit') {
print "RE:";
$input = <STDIN>;
chomp $input;
foreach (@enz) {
if ($input =~ /$_/) {
#print "$_\n";
my $val = $RE{$_};
my $real = substr($val, 0, -2);
my $cut = chop $val;
my $length = length ($real);
my %ha;
my @fragaft = ();
my @fragbef = ();
my @endar = ();
while (my @line = <$fh>) {
my $join = join "", @line;
foreach ($join) {
while ($_ =~ /($real)/g) {
my $length = length($&);
#print "$length\n";
my $pos = length($`);
#print "$pos\n";
my $end = $pos + $length;
push @endar, $end;
my $endlen = $end - ($length-$cut);
#print "$endlen\n";
#print "$join\n";
my @fragbef = substr ($join, 0, $endlen);
my @fragaft = substr ($join, $endlen);
@ha{@fragbef} = @fragaft;
}
print "\n\n\t\t\tCUT POSITIONS: $_\n" foreach @endar;
foreach(keys %ha) { print "\n$_ / $ha{$_}\n"; }
}
}
}
}
}
}
}
输出在这里给出:http://i.stack.imgur.com/17LLb.jpg (我没有足够的声誉在这里发布这张图片) 在这种情况下,我希望ASDASDA / ASDASDSD订单符合&#34; CUTSITE&#34;的顺序。在顶部,甚至更好。为此显示:Cutsite:1 =&gt; A / AAAA Cutsite:3 =&gt; AAA / AAAA Cutsite:7 =&gt; AAAAAA / A,但有换行符。
任何帮助都将不胜感激。
答案 0 :(得分:0)
您在寻找
foreach ( sort keys %ha ) {
吗? - TJD是这样的 - Khuram Bhatti
这不仅仅是类似,它正是在实现您的要求
我希望ASDASDA / ASDASDSD订单与顶部“CUTSITE”的顺序相匹配......
现在为
甚至更好。为此显示:Cutsite:1 =&gt; A / AAAA Cutsite:3 =&gt; AAA / AAAA Cutsite:7 =&gt; AAAAAA / A,但有换行符。
更改
my @fragbef = substr ($join, 0, $endlen);
my @fragaft = substr ($join, $endlen);
到
push @fragbef, substr($join, 0, $endlen);
push @fragaft, substr($join, $endlen);
和
print "\n\n\t\t\tCUT POSITIONS: $_\n" foreach @endar;
foreach(keys %ha) { print "\n$_ / $ha{$_}\n"; }
到
for (0..$#endar)
{ print "Cutsite: $endar[$_] =>\n$fragbef[$_]/$fragaft[$_]\n" }