Seqanswers Leaderboard Ad
Collapse
Announcement
Collapse
No announcement yet.
X
-
I bet the same can be obtained by just using linux command lines, directly from the shell
$ grep '^\(ID\|RANK\)' file.txt | grep -B 1 '^RANK : species' | grep -v '^RANK'
ID : 741158
Leave a comment:
-
Yes, that is not perl indeed but awk. If you really need to include this in a bigger perl code, the equivalent can be obtained by splitting the lines and adding a couple of "if" and "else". And I bet the same can be obtained by just using linux command lines, directly from the shell.
Leave a comment:
-
So, you asked about perl. Here's a one-liner that roughly matches steven's awk script:
Code:$ perl -ne 'if(/ID *: *(\d+)/){$id=$1};if(/RANK *: *species/){print "$id\n"}' file.txt 9605
Code:my @new_list = (); my $id = ""; # this assumes you want to store IDs from files or standard in while(<>){ if(/^ID *: *(\d+)/){$id=$1}; if($id && /^RANK *: *species/){ push(@new_list, $id); } }
Code:my @new_list = (); my $id = ""; foreach(@list){ if(/^ID *: *(\d+)/){$id=$1}; if($id && /^RANK *: *species/){ push(@new_list, $id); }
Code:my @new_list = (); foreach (@list){ if(/^RANK *: *species/){ if(/^ID *: *(\d+)/){ push(@new_list, $1); } } }
I would advise you to stay away from using grep in situations like this where you're modifying things inside a loop. It would do weird things like not adding to your result array if $id were 0, and changing $_ would alter your original list. See here for more information:
Leave a comment:
-
cat file | awk '$1=="ID"{id=$0} $1=="RANK" && $3=="species"{print id}'
Assuming an ID line is provided for each entry.
If you just need the ID number, use "id=$3" instead of "id=$0".
Leave a comment:
-
regular expression in perl?
Hi,
I have a list contains:
ID : 741158
PARENT ID : 9605
RANK : species
GC ID : 1
MGC ID : 2
SCIENTIFIC NAME : Homo sp. Altai
GENBANK COMMON NAME : Denisova hominin
//
In some part of this file the rank is subspecies. I just need those ID line (first line) which belong to species not subspecies:
I used this : my @new_list = grep {$_ =~ /\bspecies$/ && /\nID +\: *([\d]+)/} @list;
but is not working. Any suggestion? ThanksTags: None
Latest Articles
Collapse
-
by seqadmin
The first FDA-approved CRISPR-based therapy marked the transition of therapeutic gene editing from a dream to reality1. CRISPR technologies have streamlined gene editing, and CRISPR screens have become an important approach for identifying genes involved in disease processes2. This technique introduces targeted mutations across numerous genes, enabling large-scale identification of gene functions, interactions, and pathways3. Identifying the full range...-
Channel: Articles
08-27-2024, 04:44 AM -
-
by seqadmin
Sequencing mRNA provides a snapshot of cellular activity, allowing researchers to study the dynamics of cellular processes, compare gene expression across different tissue types, and gain insights into the mechanisms of complex diseases. “mRNA’s central role in the dogma of molecular biology makes it a logical and relevant focus for transcriptomic studies,” stated Sebastian Aguilar Pierlé, Ph.D., Application Development Lead at Inorevia. “One of the major hurdles for...-
Channel: Articles
08-07-2024, 12:11 PM -
ad_right_rmr
Collapse
News
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by seqadmin, 08-27-2024, 04:40 AM
|
0 responses
16 views
0 likes
|
Last Post
by seqadmin
08-27-2024, 04:40 AM
|
||
New Single-Molecule Sequencing Platform Introduces Advanced Features for High-Throughput Genomics
by seqadmin
Started by seqadmin, 08-22-2024, 05:00 AM
|
0 responses
293 views
0 likes
|
Last Post
by seqadmin
08-22-2024, 05:00 AM
|
||
Started by seqadmin, 08-21-2024, 10:49 AM
|
0 responses
135 views
0 likes
|
Last Post
by seqadmin
08-21-2024, 10:49 AM
|
||
Started by seqadmin, 08-19-2024, 05:12 AM
|
0 responses
124 views
0 likes
|
Last Post
by seqadmin
08-19-2024, 05:12 AM
|
Leave a comment: