Wenn ich eine genetische Hagel -Tabelle auf meinem Jupyter Python Notebook habe: < /p>
variant_qc
gq_stats info
locus alleles filters a_index was_split mean stdev min max call_rate n_called p_value_excess_het AC AF AN homozygote_count ...
locus array set int32 bool float64 float64 float64 float64 float64 int64 int64 int64 int64 int64 float64 float64 float64 array array int32 array
chr1:7756105 ["A","C"] {} 1 False 4.08e+01 3.98e+00 3.00e+00 9.90e+01 1.00e+00 414672 0 158 41333 42840 1.01e-01 1.79e-21 1.00e+00 [44347] [5.35e-02] 829344 [371832,1507]
chr1:8618725 ["C","G"] {} 1 True 8.29e+01 2.31e+01 1.00e+00 9.90e+01 1.00e+00 414829 0 1 2 2 4.82e-06 5.00e-01 5.00e-01 [2] [2.41e-06] 829658 [414827,0]
chr1:8618725 ["C","T"] {} 2 True 8.29e+01 2.31e+01 1.00e+00 9.90e+01 1.00e+00 414829 0 1 100530 403020 2.54e-01 1.05e-196 1.00e+00 [705510] [8.50e-01] 829658 [11809,302490]
< /code>
Wenn ich mich für die Spalte Locus und Allele interessiere, können Sie einige Varianten in der ersten Spalte namens Locus als wiederholt sehen, aber mit verschiedenen Allelen (2. Spalte). Wenn ich nun eine zweite .txt -Datei habe, die ich die obige Tabelle verwenden möchte: < /p>
CHR POS REF ALT A1 BETA
chr1 7756105 A C C -0.155523
chr1 8618725 C T C -0.13646
< /code>
Ich möchte die Zeilen in der ersten Tabelle herausfiltern, die nicht mit der Textdatei übereinstimmen, z. CHR1: 8618725 ["C", "G"] würde aus der ersten Tabelle gehen. < /p>
Erwartete Ausgabe: < /p>
variant_qc
gq_stats info
locus alleles filters a_index was_split mean stdev min max call_rate n_called p_value_excess_het AC AF AN homozygote_count ...
locus array set int32 bool float64 float64 float64 float64 float64 int64 int64 int64 int64 int64 float64 float64 float64 array array int32 array
chr1:7756105 ["A","C"] {} 1 False 4.08e+01 3.98e+00 3.00e+00 9.90e+01 1.00e+00 414672 0 158 41333 42840 1.01e-01 1.79e-21 1.00e+00 [44347] [5.35e-02] 829344 [371832,1507]
chr1:8618725 ["C","T"] {} 2 True 8.29e+01 2.31e+01 1.00e+00 9.90e+01 1.00e+00 414829 0 1 100530 403020 2.54e-01 1.05e-196 1.00e+00 [705510] [8.50e-01] 829658 [11809,302490]
< /code>
Der Code, den ich ausprobiert habe, ist: < /p>
# Load the filter file as a Pandas DataFrame
filter_df = pd.read_csv("list_uc_snp_list_sep.txt", sep="\t", dtype=str)
# Convert the filter file into a Hail Table
filter_ht = hl.Table.parallelize(
hl.literal(filter_df.to_dict(orient="records")),
hl.tstruct(CHR=hl.tstr, POS=hl.tstr, REF=hl.tstr, ALT=hl.tstr, A1=hl.tstr, BETA=hl.tstr)
)
# Create 'locus' and 'alleles' fields to match the Hail table
filter_ht = filter_ht.annotate(
locus=hl.locus(filter_ht.CHR, hl.int32(filter_ht.POS), reference_genome="GRCh38"),
alleles=[filter_ht.REF, filter_ht.ALT]
)
# Filter WGS_split_mt_full_list_ofSNPs by keeping only matching rows
filtered_mt = WGS_split_mt_full_list_ofSNPs.filter_rows(
hl.is_defined(filter_ht.key_by("locus", "alleles")[WGS_split_mt_full_list_ofSNPs.locus,
WGS_split_mt_full_list_ofSNPs.alleles])
)
< /code>
Aber es funktioniert nicht ... Ich erhalte einen Fehler, wenn ich den ersten Schritt mache. Ich habe Python noch nie benutzt, weiß also nicht, wie ich das tun werde. Ich spreche fließend r. Gibt es eine Möglichkeit, die Hagelstisch in R zu konvertieren, oder wenn nicht, wie kann ich Python verwenden ...
Wie filtert ich eine genetische Hagel -Tabelle basierend auf der a .txt -Datei mit den richtigen Zeilen? ⇐ Python
-
- Similar Topics
- Replies
- Views
- Last post