[英]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.2 MB,我可以使用MATLAB輕松地處理它。 但是,當我嘗試使用以下行在MATLAB中拆分文件的列時,出現錯誤。
[numData,textData,rawData] = xlsread('BRCA-TP.maf.annotated.csv');
盡管我最大化了MATLAB的Java堆內存,但是卻出現了內存不足的錯誤,無法在編輯器中實現此任務。
我正在尋找其他替代方法。 JMP可能會幫助我,但我對該軟件沒有經驗。 即使是如上所述的基本操作,也可能令我痛苦。
有沒有辦法實現我上面在MATLAB中解釋的操作? 如果沒有,您可以幫我弄清楚如何用JMP編寫腳本來執行此操作嗎?
這可以通過一個簡單的“ awk”命令來完成:
awk '$16 ~ /....-..-....-01C-...-....-../' BRCA-TP.maf.annotated > BRCA-TP.maf.annotated.filtered
16表示看第16列,//內的術語是一個正則表達式(其中點代表任何字母)
“ awk”可在任何類似Unix的操作系統(例如Mac OS X和Ubuntu)上使用,但是如果您正在運行Windows,則必須下載並安裝Cygwin或其他此類實用程序。
如果您出於特定原因要在matlab中執行此操作,則可以使用另一種解決方案。 基本上,它遍歷文件中的每一行,並隔離出第16個制表符分隔值(條形碼)。 較新版本的matlab(具有strsplit)可能會更短一些,但是regexp適用於較舊的版本
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')))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.