zillur has asked for the wisdom of the Perl Monks concerning the following question:
Hi Shifus, I was trying to parse a csv and replace cell content according another text file. I was using this:
# This script was excerpted from http://stackoverflow.com/questions/11 +678939/replace-text-based-on-a-dictionary use strict; use warnings; use Text::CSV; open my $fh, '<', 'kegg_pathway_title.txt' or die $!; my %dict = map { chomp; split ' ', $_, 2 } <$fh>; my $re = join '|', keys %dict; open $fh, '<', 'Orthogroups_3.csv' or die $!; while (<$fh>) { next if $. < 2; s/($re)/$dict{$1}/g; print; }
It gives me near expected output but changed the dimension of the original file. Now I can't load the parsed csv in R to do other stuff. Is there anyway to replace cell content of csv without changing dimension?
> grpsTbl <- read.csv("Orthogroups_3.csv", header=T, sep = "\t", row. +names = 1, stringsAsFactors=F) > dim(grpsTbl) [1] 5791 13
> grpsTbl <- read.csv("parsed_with_perl.csv", header=T, sep = "\t", r +ow.names = 1, stringsAsFactors=F) Error in read.table(file = file, header = header, sep = sep, quote = q +uote, : more columns than column names
My orthogroups_3.csv contain multicolumn, each cell may contain 0/1/many values(name). I want exact same csv just values in each cell(names) will be replaced according do the 1st file. Best Regards Zillur
|
|---|