简体   繁体   English

从Matrix文件读取坐标而没有2D数组?

[英]Reading coordinates from Matrix file WITHOUT 2D arrays?

I'm currently working on a program (bioinformatics project) that involves reading multiple files, including a matrix, and outputting the results onto another file. 我目前正在开发一个程序(生物信息学项目),该程序涉及读取多个文件(包括矩阵)并将结果输出到另一个文件中。 What I'm having the most trouble with is how I would go about reading the matrix file like a coordinate system (for lack of a better term)? 我最麻烦的是我将如何像坐标系一样读取矩阵文件(因为缺少更好的术语)? Is there a simple way to do this without using 2D arrays? 有没有使用2D数组的简单方法? For example, if I have the following amino acids in: 例如,如果我的氨基酸如下:

fileA: CTTNCLAPLA fileB: CTTNSITPVA 文件A:CTTNCLAPLA文件B:CTTNSITPVA

The program would then read the two files, compare each letter, and refer to the matrix to find the number corresponding to the two letters, which in turn determines the probability of a letter in fileA mutating to a letter in fileB. 然后,程序将读取两个文件,比较每个字母,然后参考矩阵以找到与两个字母相对应的数字,这反过来又确定了fileA中的字母突变为fileB中的字母的概率。

Since the first letter in each file is C, the program would read the matrix and output in a separate file: 由于每个文件的第一个字母为C,因此程序将读取矩阵并在单独的文件中输出:

C T T N C L A P L A
| | | | . : : | : |
C T T N S I T P V A

The "." “。” means that the number according to the matrix was 0 but not the same letter, "|" 表示根据矩阵的数字为0,但不是相同的字母“ |” means that the letter is the same, and the ":" means that the number was greater than zero but not the same letter. 表示字母相同,“:”表示数字大于零,但字母不同。

Here is part of the matrix (the rest wouldn't fit): NOTE: The matrix I must use is in a .csv file, and does not include spaces. 这是矩阵的一部分(其余部分不适合):注意:我必须使用的矩阵位于.csv文件中,并且不包含空格。

_, A, R, N, D, C
A, 2,-2, 0, 0,-2 
R,-2, 6, 0,-1,-2
N, 0, 0, 2, 2,-4
D, 0,-1, 2, 4,-5
C,-2,-4,-4,-5,12

I apologize if my explanation is confusing. 如果我的解释令人困惑,我深表歉意。 Please let me know if you need any clarification. 如果需要任何说明,请告诉我。 Any help is greatly appreciated. 任何帮助是极大的赞赏。 Thanks in advance! 提前致谢!

为了避免使用2D数组,您可以将1D数组与线性索引一起使用,并实现便捷帮助器功能以将2D坐标转换为线性数组索引-像这里对称矩阵中的线性索引

I would just create a class / struct and then create a array of objects. 我只是创建一个类/结构,然后创建一个对象数组。 This should eliminate your need for a 2D array. 这将消除您对2D阵列的需要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM