以下一个班轮反过来打印出文件的内容
$ sed -n '1!G;h;$p' test.txt
Run Code Online (Sandbox Code Playgroud)
当sed逐行读取文件时怎么可能?你能解释一下这个意思吗?
n 旗1!Gh$p 在这个命令?
我有以下格式的文件:
(类型1数据:1)
B
B
(类型1数据:2)
B
B
B
(类型1数据:3)
B
..
现在我想重新格式化这个文件,使它看起来像:
(类型1数据:1)BB
(类型1数据:2)BBB
(类型1数据:3)B
...
我的方法是在命令行中使用perl regex,
cat file | perl -pe 's/\n(B)/ $1/smg'
Run Code Online (Sandbox Code Playgroud)
我的理由是用空格替换新的线条字符.但它似乎没有用.你能帮我么?谢谢
如何使用行名称和列名称转换以下矩阵(或表/数据框),
A B
M 27143 18324
F 29522 18875
Run Code Online (Sandbox Code Playgroud)
变成类似的东西
27143 M A
18324 M B
29522 F A
18875 F B
Run Code Online (Sandbox Code Playgroud)
这样我才能在R中做一些分析?
如何使用perl正则表达式转换以下文本:
1100101
1100111
1110001
1110101
Run Code Online (Sandbox Code Playgroud)
成
1 1 0 0 1 0 1
1 1 0 0 1 1 1
1 1 1 0 0 0 1
1 1 1 0 1 0 1
Run Code Online (Sandbox Code Playgroud)
我试过用
perl -pe 's// /g' < text.txt
Run Code Online (Sandbox Code Playgroud)
但它给了我一些有趣的结果:
1 1 0 0 1 0 1
1 1 0 0 1 1 1
1 1 1 0 0 0 1
1 1 1 0 1 0 1
Run Code Online (Sandbox Code Playgroud) 假设我有以下列表:
test<-list(c("a","b","c"),c("a"),c("c"))
>test
[[1]]
[1] "a" "b" "c"
[[2]]
[1] "a"
[[3]]
[1] "c"
Run Code Online (Sandbox Code Playgroud)
我该怎么做(或使用函数)来获取列表中的唯一项目的频率,如下所示:?
a 2
b 1
c 2
Run Code Online (Sandbox Code Playgroud)
我尝试使用表(测试),但我得到以下错误
> table(test)
Error in table(test) : all arguments must have the same length
Run Code Online (Sandbox Code Playgroud) 基本上,我想将一个列文件转换为由行数指定的多个列文件.
我不想重新发明轮子.我想在编写自定义脚本之前确保是否有unix命令/或标准方法.
例如,假设我有以下文件:
$cat input.txt
tom
jack
kim
bart
foo
bar
Run Code Online (Sandbox Code Playgroud)
我想把它变成3行文件
$ cat input.txt | my_script --every=3 --delimiter=tab
tom bart
jack foo
kim bar
Run Code Online (Sandbox Code Playgroud)
或具有不同分隔符的2行文件:
$ cat input.txt | my_script --every=2 --delimiter=,
tom,kim,foo
jack,bart,bar
Run Code Online (Sandbox Code Playgroud) 我知道
g/PATTERN/m $
Run Code Online (Sandbox Code Playgroud)
将所有匹配PATTERN的文本移动到文件末尾.我如何完成相反的工作?(即到文件的顶部)?
以下是Perl可以做的许多很酷的事情之一
my ($tmp) = ($_=~ /^>(.*)/);
Run Code Online (Sandbox Code Playgroud)
它在循环中的当前行中找到模式^>.*,并将它存储在$ tmp变量的括号中.
我很好奇的是这种语法背后的概念.如何以及为什么(在什么前提下)这有效?我的理解是片段$ _ =〜/^>(.*)/是一个布尔上下文,但括号将它呈现为列表上下文?但是,为什么只有匹配模式中括号中的内容存储在变量中?!
这是变量赋值的某种特殊情况,我必须"记住"或者这可以完全解释吗?如果是这样,这个功能叫什么(名称如"autovivifacation?")
我有一些我想要可视化的序列特征信息.这是一些玩具数据(最后重新生成数据的具体r代码)
type index variable position
...
14 CDS 14 start 31129
15 exon 15 start 32196
16 CDS 16 start 32196
17 stop_codon 17 start 32247
18 exon 1 end 12166
19 CDS 2 end 12166
...
Run Code Online (Sandbox Code Playgroud)
我用来生成以下图的命令是
qplot(position,type,data=m2data,color=type)+xlim(11950,15000)
Run Code Online (Sandbox Code Playgroud)

但是我想在"开始"和"结束"之间添加线段,这些线段与下面共享相同的"索引",这是我用油漆制作的.

如何用R中的ggplot2实现这个目标?
以下是数据
m2data<-structure(list(type = structure(c(2L, 1L, 3L, 2L, 1L, 2L, 1L,
4L, 2L, 2L, 1L, 3L, 2L, 1L, 2L, 1L, 4L, 2L, 1L, 3L, 2L, 1L, 2L,
1L, 4L, 2L, 2L, 1L, 3L, 2L, 1L, 2L, 1L, 4L), class = …Run Code Online (Sandbox Code Playgroud) 在 jinja2 中,我尝试多次使用模板动态创建 html 文档。我的 python 脚本如下所示:
# In my python script
env = Environment()
env.loader = FileSystemLoader('.')
base_template = env.get_template('base_template.html')
# each has the actual content and its associated template
content1 = ("Hello World", 'content_template.html')
content2 = ("Foo bar", 'content_template.html')
html_to_present = [content1[1], content2[1]]
# and render. I know this is wrong
# as I am not passing the actual content,
# but this is the part I am struggling with. More below
base_template.render(include_these=html_to_present, ).encode("utf-8"))
Run Code Online (Sandbox Code Playgroud)
我的基本模板如下所示:
#################
# base_template.html …Run Code Online (Sandbox Code Playgroud)