<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="https://www.bigdick.live/feed_style.xsl" type="text/xsl"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <tabi:metadata xmlns:tabi="https://github.com/welpo/tabi">
        <tabi:base_url>https:&#x2F;&#x2F;www.bigdick.live</tabi:base_url>
        <tabi:separator>
            •
        </tabi:separator>
        <tabi:about_feeds>This is a web feed, also known as an Atom feed. Subscribe by copying the URL from the address bar into your newsreader. Visit About Feeds to learn more and get started. It&#x27;s free.</tabi:about_feeds>
        <tabi:visit_the_site>Visit website</tabi:visit_the_site>
        <tabi:recent_posts>Recent posts</tabi:recent_posts>
        <tabi:last_updated_on>Updated on $DATE</tabi:last_updated_on>
        <tabi:default_theme></tabi:default_theme>
        <tabi:post_listing_date>date</tabi:post_listing_date>
        <tabi:current_section>Perl</tabi:current_section>
    </tabi:metadata><link rel="extra-stylesheet" href="https://www.bigdick.live/skins/black-orange.css?h=c64b7f81e34a143cd725" /><title>Yu Sun - Perl</title>
        <subtitle>Yu Sun&#x27;s personal site for bioinformatics, data science, software engineering, public resume, projects, and posts.</subtitle>
    <link href="https://www.bigdick.live/en/tags/perl/atom.xml" rel="self" type="application/atom+xml"/>
    <link href="https://www.bigdick.live/en/tags/perl/" rel="alternate" type="text/html"/>
    <generator uri="https://www.getzola.org/">Zola</generator><updated>2017-02-09T00:00:00+00:00</updated><id>https://www.bigdick.live/en/tags/perl/atom.xml</id><entry xml:lang="en">
        <title>Perl oneliners for Bioinformatics</title>
        <published>2017-02-09T00:00:00+00:00</published>
        <updated>2017-02-09T00:00:00+00:00</updated>
        <author>
            <name>Yu Sun</name>
        </author>
        <link rel="alternate" href="https://www.bigdick.live/en/blog/perl-oneliners/" type="text/html"/>
        <id>https://www.bigdick.live/en/blog/perl-oneliners/</id>
        
            <content type="html">&lt;p&gt;To use most of one-liners in this post, you should:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;If you’re working on &lt;em&gt;Windows&lt;&#x2F;em&gt;, download and install &lt;a class=&quot;external&quot; rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;downloads.activestate.com&#x2F;&quot;&gt;ActiveState Perl&lt;&#x2F;a&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;Replace variable &lt;code&gt;$file&lt;&#x2F;code&gt; at the end of scripts by the real file name.&lt;&#x2F;li&gt;
&lt;li&gt;Run the script as a command in &lt;code&gt;CMD&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;www.bigdick.live&#x2F;en&#x2F;blog&#x2F;perl-oneliners&#x2F;#extract-a-reference-sequence-from-a-single-query-fasta-file&quot;&gt;Extract a reference sequence from a single-query &lt;em&gt;FASTA&lt;&#x2F;em&gt; file&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;www.bigdick.live&#x2F;en&#x2F;blog&#x2F;perl-oneliners&#x2F;#find-plain-text-files-with-same-appendix-in-multiple-directories-recursively-and-merge-them-into-one-file&quot;&gt;Find plain-text files with same appendix in multiple directories recursively and merge them into one file&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;www.bigdick.live&#x2F;en&#x2F;blog&#x2F;perl-oneliners&#x2F;#filter-fastq-by-length-of-query&quot;&gt;Filter &lt;em&gt;FASTQ&lt;&#x2F;em&gt; by length of query&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;www.bigdick.live&#x2F;en&#x2F;blog&#x2F;perl-oneliners&#x2F;#to-flare-out-fasta-queries&quot;&gt;To “flare out” &lt;em&gt;FASTA&lt;&#x2F;em&gt; queries&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;www.bigdick.live&#x2F;en&#x2F;blog&#x2F;perl-oneliners&#x2F;#to-calculate-the-proportion-of-gaps-n-or-n-in-a-genome&quot;&gt;To calculate the proportion of gaps (“N” or “n”) in a genome&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;www.bigdick.live&#x2F;en&#x2F;blog&#x2F;perl-oneliners&#x2F;#to-get-reads-in-fastq-with-specific-length-and-count-in-descending-order&quot;&gt;To get reads in &lt;em&gt;FASTQ&lt;&#x2F;em&gt; with specific length and count in descending order&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;www.bigdick.live&#x2F;en&#x2F;blog&#x2F;perl-oneliners&#x2F;#to-calculate-positive-and-negtive-read-counts-separately&quot;&gt;To calculate positive and negtive read counts separately&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;www.bigdick.live&#x2F;en&#x2F;blog&#x2F;perl-oneliners&#x2F;#to-print-file-names-in-current-directory&quot;&gt;To print file names in current directory&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;www.bigdick.live&#x2F;en&#x2F;blog&#x2F;perl-oneliners&#x2F;#to-remove-all-patches-and-scaffolds-etc-but-leave-only-chromosomes-in-a-genome-reference-file&quot;&gt;To remove all patches and scaffolds etc., but leave only chromosomes in a genome reference file.&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;www.bigdick.live&#x2F;en&#x2F;blog&#x2F;perl-oneliners&#x2F;#to-convert-fastq-into-fasta&quot;&gt;To convert &lt;em&gt;FASTQ&lt;&#x2F;em&gt; into &lt;em&gt;FASTA&lt;&#x2F;em&gt;&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;extract-a-reference-sequence-from-a-single-query-fasta-file&quot;&gt;Extract a reference sequence from a single-query &lt;em&gt;FASTA&lt;&#x2F;em&gt; file&lt;&#x2F;h2&gt;
&lt;p&gt;Replace the scalar $start and $end with two number indicating location then execute.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;perl&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;perl -&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-function&quot;&gt;ne&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt; &amp;#39;next if &#x2F;^&amp;gt;&#x2F;; $_ =~ s&#x2F;[\r\n]+&#x2F;&#x2F;g; @a = split &#x2F;&#x2F;, $_; for (@a) {$i ++; if(($i &amp;gt;= $start) &amp;amp;&amp;amp; ($i &amp;lt;= $end)) {print}}&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable z-other z-readwrite&quot;&gt; $file&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;find-plain-text-files-with-same-appendix-in-multiple-directories-recursively-and-merge-them-into-one-file&quot;&gt;Find plain-text files with same appendix in multiple directories recursively and merge them into one file&lt;&#x2F;h2&gt;
&lt;p&gt;Replace the scalar $append with the suffix (e.g. .seq) then execute.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;perl&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;perl -MFile::Find -&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-function&quot;&gt;le&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt; &amp;quot;sub search{if (&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-escape&quot;&gt;\$&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;append&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable&quot;&gt;$&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;){(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable z-other z-readwrite&quot;&gt;$id&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;) = map{&#x2F;.+_(&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-escape&quot;&gt;\(&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;.+).seq&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable&quot;&gt;$&#x2F;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;} &lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable&quot;&gt;$_&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;; open(SEQ, qq{&amp;lt;}, &lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable z-other z-readwrite&quot;&gt;$File::Find::name&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;) or die qq{Processing:&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable z-other z-readwrite&quot;&gt;$File::Find::name&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-escape&quot;&gt;\n&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable&quot;&gt;$!&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-escape&quot;&gt;\n&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;}; while(&amp;lt;SEQ&amp;gt;) {print MERGE qq{&amp;gt;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable z-other z-readwrite&quot;&gt;$id&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;}; print MERGE &lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable&quot;&gt;$_&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;} }} open MERGE, qq{&amp;gt;}, qq{sanger.fa}; find({ wanted =&amp;gt; &lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-escape&quot;&gt;\&amp;amp;&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt;search, no_chdir =&amp;gt; 1 }, qq{.})&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable z-other z-readwrite&quot;&gt; $file&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;filter-fastq-by-length-of-query&quot;&gt;Filter &lt;em&gt;FASTQ&lt;&#x2F;em&gt; by length of query&lt;&#x2F;h2&gt;
&lt;p&gt;Replace the scalar $minlen and $maxlen with the number representing interval then execute.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;perl&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;perl -lane &lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;&amp;quot;if (&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable&quot;&gt;$.&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; % 4 == 1) {&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable z-other z-readwrite&quot;&gt;$id&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; = &lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable&quot;&gt;$_&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; =~ s&#x2F;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-escape&quot;&gt;\r\n&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;]+&#x2F;&#x2F;r} elsif (&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable&quot;&gt;$.&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; % 4 == 2) {&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable z-other z-readwrite&quot;&gt;$seq&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; = &lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable&quot;&gt;$_&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; =~ s&#x2F;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-escape&quot;&gt;\r\n&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;]+&#x2F;&#x2F;r} elsif (&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable&quot;&gt;$.&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; % 4 == 3) {&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable z-other z-readwrite&quot;&gt;$name&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; = &lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable&quot;&gt;$_&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; =~ s&#x2F;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-escape&quot;&gt;\r\n&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;]+&#x2F;&#x2F;r} else {&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable z-other z-readwrite&quot;&gt;$qual&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; = &lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable&quot;&gt;$_&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; =~ s&#x2F;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-escape&quot;&gt;\r\n&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;]+&#x2F;&#x2F;r; print qq{&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable z-other z-readwrite&quot;&gt;$id&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-escape&quot;&gt;\n&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable z-other z-readwrite&quot;&gt;$seq&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-escape&quot;&gt;\n&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable z-other z-readwrite&quot;&gt;$name&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-escape&quot;&gt;\n&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable z-other z-readwrite&quot;&gt;$qual&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;} if ((length(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable z-other z-readwrite&quot;&gt;$seq&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;) &amp;gt;= &lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable z-other z-readwrite&quot;&gt;$minlen&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;) &amp;amp;&amp;amp; (length(&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable z-other z-readwrite&quot;&gt;$seq&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt;) &amp;lt;= &lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable z-other z-readwrite&quot;&gt;$maxlen&lt;&#x2F;span&gt;&lt;span class=&quot;z-string z-punctuation z-definition z-string&quot;&gt;))}&amp;quot;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable z-other z-readwrite&quot;&gt; $file&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;to-flare-out-fasta-queries&quot;&gt;To “flare out” &lt;em&gt;FASTA&lt;&#x2F;em&gt; queries&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;em&gt;FASTA&lt;&#x2F;em&gt; is a file format and is recommended that all lines of text be shorter than 80 characters.
However, when we need to grep continuous strings in it, the line break such as &lt;code&gt;[\r\n]&lt;&#x2F;code&gt; usually cause troubles.
Use this command can remove newline characters in sequences.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;perl&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;perl -pe &lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;&amp;#39;$. == 1 ? 23333333 : &#x2F;^&amp;gt;&#x2F; ? $_ = qq{\n} . $_ : s&#x2F;[\r\n]+&#x2F;&#x2F;&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable z-other z-readwrite&quot;&gt; $file&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;to-calculate-the-proportion-of-gaps-n-or-n-in-a-genome&quot;&gt;To calculate the proportion of gaps (“N” or “n”) in a genome&lt;&#x2F;h2&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;perl&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;perl -lne &lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;&amp;#39;next if &#x2F;^&amp;gt;&#x2F;; $_ =~ s&#x2F;[\r\n]+&#x2F;&#x2F;; $total_len += length($_); $n_count += map{&#x2F;[nN]&#x2F;g} $_ }{ END{print qq{Total length: $total_len}; print qq{N count: $n_count}; $n_ratio = $n_count &#x2F; $total_len; print qq{N ratio: $n_ratio}}&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable z-other z-readwrite&quot;&gt; $file&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;to-get-reads-in-fastq-with-specific-length-and-count-in-descending-order&quot;&gt;To get reads in &lt;em&gt;FASTQ&lt;&#x2F;em&gt; with specific length and count in descending order&lt;&#x2F;h2&gt;
&lt;p&gt;Replace the scalar &lt;code&gt;$length&lt;&#x2F;code&gt; with the length you’re interested in (without unit such as “bp”) then execute.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;perl&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;perl -lne &lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;&amp;#39;next unless (($. % 4 == 2)&amp;amp;&amp;amp;(length($_) == $length)); $count{$_}++; }{ for (sort {$count{$b} &amp;lt;=&amp;gt; $count{$a}} keys %count) {print qq{$_\t$count{$_}}}&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable z-other z-readwrite&quot;&gt; $file&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;to-calculate-positive-and-negtive-read-counts-separately&quot;&gt;To calculate positive and negtive read counts separately&lt;&#x2F;h2&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;perl&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;perl -lane &lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;&amp;#39;next if &#x2F;^@&#x2F;; next if $F[1]&amp;amp;0x4; $len = eval join q{+}, map {&#x2F;(\d+)[MID]&#x2F;g} $F[5]; $pos{$len} ++ if $F[1] == 0; $neg{$len} ++ if $F[1] == 16 }{ print qq{$_\t$pos{$_}} for (keys %pos); print qq{$_\t-$neg{$_}} for (keys %neg)&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable z-other z-readwrite&quot;&gt; $file&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;to-print-file-names-in-current-directory&quot;&gt;To print file names in current directory&lt;&#x2F;h2&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;perl&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;perl -&lt;&#x2F;span&gt;&lt;span class=&quot;z-support z-function&quot;&gt;le&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt; &amp;quot;print for (glob qq{*})&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;to-remove-all-patches-and-scaffolds-etc-but-leave-only-chromosomes-in-a-genome-reference-file&quot;&gt;To remove all patches and scaffolds etc., but leave only chromosomes in a genome reference file.&lt;&#x2F;h2&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;perl&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;perl -lpe &lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;&amp;#39;&#x2F;^&amp;gt;&#x2F; &amp;amp;&amp;amp; !&#x2F;REF$&#x2F; ? last : &#x2F;^&amp;gt;&#x2F; ? $_ =~ s&#x2F;&amp;gt;(\w+)&#x2F;&amp;gt;chr$1&#x2F; : 23333333&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable z-other z-readwrite&quot;&gt; $file&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;to-convert-fastq-into-fasta&quot;&gt;To convert &lt;em&gt;FASTQ&lt;&#x2F;em&gt; into &lt;em&gt;FASTA&lt;&#x2F;em&gt;&lt;&#x2F;h2&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;perl&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;perl -F&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;&amp;#39;@&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-source&quot;&gt; -lanE&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-string z-string&quot;&gt;&amp;#39;$. % 4 == 1 ? say qq{&amp;gt;$F[1]} : $. % 4 == 2 ? say $_ : $. % 4 == 3 ? qq{Yu Sun is handsome} : 233333333&amp;#39;&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation z-definition z-variable z-variable z-other z-readwrite&quot;&gt; $file&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;</content>
        <summary type="html">Here I place some Perl-oneliners (may be not common used) by me. You can use them to modify, count , summarize or change file type on plain-text (like fastx).</summary>
        </entry>
</feed>
