小编s_b*_*man的帖子

facet的不同geom_rect()对象

我有一个数据框,我用它来创建一个ggplot对象,分成三个独立的图.

max_24h_lactate_cpet.long

First_24h_Lactate_Max,  Lactate_Above_Threshold,           Metric,           Value
2.3,                    High,                              AT_VO2_mL.kg.min, 17.00
2.3,                    High,                              VO2_Peak,         84.07
2.3,                    High,                              AT_VE_VCO2,       35.00
Run Code Online (Sandbox Code Playgroud)

在输入格式:

dput(max_24h_lactate_cpet.long)
structure(list(First_24h_Lactate_Max = c(2.3, 2.3, 2.3), Lactate_Above_Threshold = structure(c(1L, 
1L, 1L), 
.Label = c("High", "Normal"), class = "factor"), Metric = structure(1:3, .Label = c("AT_VO2_mL.kg.min", 
"VO2_Peak", "AT_VE_VCO2"), class = "factor"), Value = c(17, 84.07, 
35)), .Names = c("First_24h_Lactate_Max", "Lactate_Above_Threshold", 
"Metric", "Value"), row.names = c(44L, 192L, 340L), class = "data.frame")
Run Code Online (Sandbox Code Playgroud)

我想在每个方面上放置geom_rect()对象,但每个绘图使用不同的ymin和ymax值.

这是我目前的代码:

max_24h_lac_vs_cpet <- ggplot(max_24h_lactate_cpet.long, 
                              aes(x = max_24h_lactate_cpet.long$First_24h_Lactate_Max, 
                                  y = max_24h_lactate_cpet.long$Value))

max_24h_lac_vs_cpet + …
Run Code Online (Sandbox Code Playgroud)

r facet ggplot2

7
推荐指数
1
解决办法
3718
查看次数

如果行中的指定值与条件匹配,则从CSV返回一行

啊,我正在编写一个Python脚本来过滤一些大的CSV文件.

我只想保留符合我标准的行.

我的输入是以下格式的CSV文件

Locus         Total_Depth  Average_Depth_sample   Depth_for_17
chr1:6484996  1030         1030                   1030
chr1:6484997  14           14                     14
chr1:6484998  0            0                      0
Run Code Online (Sandbox Code Playgroud)

我想返回Total_Depth为0的行.

我一直在听这个答案来读取数据.但我坚持试图解析行并拉出符合我条件的行.

这是我到目前为止的代码:

import csv

f = open("file path", 'rb')
reader = csv.reader(f) #reader object which iterates over a csv file(f)
headers = reader.next() #assign the first row to the headers variable
column = {} #list of columns
for h in headers: #for each header
    column[h] = []
for row in reader: #for each row in the reader object …
Run Code Online (Sandbox Code Playgroud)

python csv dictionary python-2.7

5
推荐指数
1
解决办法
2万
查看次数

使用argparse进行文件名输入

嗨我正在尝试使用argparse从命令行输入文件名,但我很难让它工作.

我想从命令行(-d)传递一个字符串,该字符串对应于文件名(datbase.csv)并将其存储在变量inputargs.snp_database_location中.

这被作为我的load_search_snaps函数的输入,如下面的代码所示,它打开文件并对其进行填充(伪代码).

    import csv, sys, argparse

    parser = argparse.ArgumentParser(description='Search a list of variants against the in house database')
    parser.add_argument('-d', '--database',
        action='store',
        dest='snp_database_location',
        type=str,
        nargs=1,
        help='File location for the in house variant database',
        default='Error: Database location must be specified')

    inputargs = parser.parse_args()

    def load_search_snps(input_file):
        with open(input_file, 'r+') as varin:
            id_store_dictgroup = csv.DictReader(varin)
            #do things with id_store_dictgroup                                                                          
        return result

    load_search_snps(inputargs.snp_database_location)
Run Code Online (Sandbox Code Playgroud)

在bash中使用命令:

python3 snp_freq_V1-0_export.py -d snpstocheck.csv

当我尝试使用命令行从同一目录传递一个常规csv文件时,我收到以下错误:

将文件"snp_freq_V1-0_export.py",第33行,在load_search_snps中,打开(input_file,'r +')作为varin:TypeError:无效文件:['snpstocheck.csv']

如果我从脚本中提供文件路径,它可以完美地工作.据我所知,我得到一个与文件名字符串匹配的snp_database_location字符串,但后来我得到了错误.我错过了什么给出了类型错误?

python bash argparse python-3.x

4
推荐指数
1
解决办法
1466
查看次数

标签 统计

python ×2

argparse ×1

bash ×1

csv ×1

dictionary ×1

facet ×1

ggplot2 ×1

python-2.7 ×1

python-3.x ×1

r ×1