包含原始数据的大文件的基本数据过滤操作
Basic data filtering operations on a big file which contains raw data
标题可能听起来很废话,但让我解释一下。我需要过滤一个txt文件。正如我所说,我应该执行的操作非常基础。我正在谈论的文件是这个:
http://gdac.broadinstitute.org/runs/analyses__2014_10_17/reports/cancer/BRCA-TP/Mutation_Assessor/BRCA-TP.maf.annotated
起初,我专注于这个任务:
请在数据文件中找到 Tumor_Sample_Barcode 列。可以看到,该列对应的所有行都是这样的格式:
TCGA-02-0001-01C-01D-0182-01
"C" 之前的两个字符在这里很关键。在示例格式中,这些字符是“01”。我正在寻找这些包含“01”的行。即,应消除具有任何其他字符对的行。
如果文件大小不是56.2MB,我用MATLAB可以轻松搞定。但是,当我尝试使用以下行在 MATLAB 中拆分文件的列时,出现错误。
[numData,textData,rawData] = xlsread('BRCA-TP.maf.annotated.csv');
虽然我最大化Java MATLAB 的堆内存,但我在编辑器中得到没有足够的内存来实现这个任务的错误。
我寻找任何替代方法。 JMP 可能对我有帮助,但我没有使用该软件的经验。即使像我上面描述的那样的基本操作对我来说也可能很痛苦。
有没有办法在MATLAB中实现我上面解释的操作?如果没有,你能帮我弄清楚如何在 JMP 中编写脚本来完成它吗?
这可以通过简单的 "awk" 命令完成:
awk ' ~ /....-..-....-01C-...-....-../' BRCA-TP.maf.annotated > BRCA-TP.maf.annotated.filtered
16表示看第16列,//里面的词是正则表达式(其中点代表任意字母)
"awk" 可用于任何类 unix 操作系统,例如 Mac OS X 和 Ubuntu,但如果您是 运行 windows 您必须下载并安装 Cygwin 或其他此类实用程序。
如果您出于特定原因想在 matlab 中执行此操作,这是另一种解决方案。基本上它遍历文件中的每一行,并隔离第 16 个制表符分隔值(条形码)。使用较新版本的 matlab(具有 strsplit)可能会更短,但正则表达式适用于旧版本
fid = fopen('tumor.csv');
%Tumor_Sample_Barcode is the 16th column
col_of_interest = 16;
sline = fgetl(fid);
while ischar(sline)
%splits the line by tabs
tokenized_line = regexp(sline,'\t','split');
%makes sure the line contains the token (this should always be true for
%your file, but just in case
if (col_of_interest <= numel(tokenized_line))
tumor_barcode = tokenized_line{col_of_interest};
if not(isempty(regexp(tumor_barcode,'....-..-....-01C-...-....-..','match')))
%if so display the line, or do other processing
disp(tumor_barcode)
end
end
sline = fgetl(fid);
end
fclose(fid);
编辑
我看到了您对其他答案的评论,如果您想搜索 01C 02C 和 03C,您可以使用范围在正则表达式中一次完成所有操作。 [1-3] 表示取 1 到 3 之间的任何值
if not(isempty(regexp(tumor_barcode,'....-..-....-0[1-3]C-...-....-..','match')))
标题可能听起来很废话,但让我解释一下。我需要过滤一个txt文件。正如我所说,我应该执行的操作非常基础。我正在谈论的文件是这个: http://gdac.broadinstitute.org/runs/analyses__2014_10_17/reports/cancer/BRCA-TP/Mutation_Assessor/BRCA-TP.maf.annotated
起初,我专注于这个任务: 请在数据文件中找到 Tumor_Sample_Barcode 列。可以看到,该列对应的所有行都是这样的格式: TCGA-02-0001-01C-01D-0182-01
"C" 之前的两个字符在这里很关键。在示例格式中,这些字符是“01”。我正在寻找这些包含“01”的行。即,应消除具有任何其他字符对的行。
如果文件大小不是56.2MB,我用MATLAB可以轻松搞定。但是,当我尝试使用以下行在 MATLAB 中拆分文件的列时,出现错误。
[numData,textData,rawData] = xlsread('BRCA-TP.maf.annotated.csv');
虽然我最大化Java MATLAB 的堆内存,但我在编辑器中得到没有足够的内存来实现这个任务的错误。
我寻找任何替代方法。 JMP 可能对我有帮助,但我没有使用该软件的经验。即使像我上面描述的那样的基本操作对我来说也可能很痛苦。
有没有办法在MATLAB中实现我上面解释的操作?如果没有,你能帮我弄清楚如何在 JMP 中编写脚本来完成它吗?
这可以通过简单的 "awk" 命令完成:
awk ' ~ /....-..-....-01C-...-....-../' BRCA-TP.maf.annotated > BRCA-TP.maf.annotated.filtered
16表示看第16列,//里面的词是正则表达式(其中点代表任意字母)
"awk" 可用于任何类 unix 操作系统,例如 Mac OS X 和 Ubuntu,但如果您是 运行 windows 您必须下载并安装 Cygwin 或其他此类实用程序。
如果您出于特定原因想在 matlab 中执行此操作,这是另一种解决方案。基本上它遍历文件中的每一行,并隔离第 16 个制表符分隔值(条形码)。使用较新版本的 matlab(具有 strsplit)可能会更短,但正则表达式适用于旧版本
fid = fopen('tumor.csv');
%Tumor_Sample_Barcode is the 16th column
col_of_interest = 16;
sline = fgetl(fid);
while ischar(sline)
%splits the line by tabs
tokenized_line = regexp(sline,'\t','split');
%makes sure the line contains the token (this should always be true for
%your file, but just in case
if (col_of_interest <= numel(tokenized_line))
tumor_barcode = tokenized_line{col_of_interest};
if not(isempty(regexp(tumor_barcode,'....-..-....-01C-...-....-..','match')))
%if so display the line, or do other processing
disp(tumor_barcode)
end
end
sline = fgetl(fid);
end
fclose(fid);
编辑
我看到了您对其他答案的评论,如果您想搜索 01C 02C 和 03C,您可以使用范围在正则表达式中一次完成所有操作。 [1-3] 表示取 1 到 3 之间的任何值
if not(isempty(regexp(tumor_barcode,'....-..-....-0[1-3]C-...-....-..','match')))