Debian Codegraph @

PKG-INFO

raw
1 Metadata-Version: 2.1
2 Name: airr
3 Version: 1.5.1
4 Summary: AIRR Community Data Representation Standard reference library for antibody and TCR sequencing data.
5 Home-page: http://docs.airr-community.org
6 Author: AIRR Community
7 Author-email:
8 License: CC BY 4.0
9 Keywords: AIRR,bioinformatics,sequencing,immunoglobulin,antibody,adaptive immunity,T cell,B cell,BCR,TCR
10 Classifier: Intended Audience :: Science/Research
11 Classifier: Natural Language :: English
12 Classifier: Operating System :: OS Independent
13 Classifier: Programming Language :: Python :: 3
14 Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
15
16 Installation
17 ------------------------------------------------------------------------------
18
19 Install in the usual manner from PyPI::
20
21 > pip3 install airr --user
22
23 Or from the `downloaded <https://github.com/airr-community/airr-standards>`__
24 source code directory::
25
26 > python3 setup.py install --user
27
28
29 Quick Start
30 ------------------------------------------------------------------------------
31
32 Deprecation Notice
33 ^^^^^^^^^^^^^^^^^^^^
34
35 The ``load_repertoire``, ``write_repertoire``, and ``validate_repertoire`` functions
36 have been deprecated for the new generic ``load_airr_data``, ``write_airr_data``, and
37 ``validate_airr_data`` functions. These new functions are backwards compatible with
38 the Repertoire metadata format but also support the new AIRR objects such as GermlineSet,
39 RepertoireGroup, GenotypeSet, Cell and Clone. This new format is defined by the DataFile
40 Schema, which describes a standard set of objects included in a file containing
41 AIRR Data Model presentations. Currently, the AIRR DataFile does not completely support
42 Rearrangement, so users should continue using AIRR TSV files and its specific functions.
43 Also, the ``repertoire_template`` function has been deprecated for the ``Schema.template``
44 method, which can now be called on any AIRR Schema to create a blank object.
45
46 Reading AIRR Data Files
47 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
48
49 The ``airr`` package contains functions to read and write AIRR Data
50 Model files. The file format is either YAML or JSON, and the package provides a
51 light wrapper over the standard parsers. The file needs a ``json``, ``yaml``, or ``yml``
52 file extension so that the proper parser is utilized. All of the AIRR objects
53 are loaded into memory at once and no streaming interface is provided::
54
55 import airr
56
57 # Load the AIRR data
58 data = airr.read_airr('input.airr.json')
59 # loop through the repertoires
60 for rep in data['Repertoire']:
61 print(rep)
62
63 Why are the AIRR objects, such as Repertoire, GermlineSet, and etc., in a list versus in a
64 dictionary keyed by their identifier (e.g., ``repertoire_id``)? There are two primary reasons for
65 this. First, the identifier might not have been assigned yet. Some systems might allow MiAIRR
66 metadata to be entered but the identifier is assigned to that data later by another process. Without
67 the identifier, the data could not be stored in a dictionary. Secondly, the list allows the data to
68 have a default ordering. If you know that the data has a unique identifier then you can quickly
69 create a dictionary object using a comprehension. For example, with repertoires::
70
71 rep_dict = { obj['repertoire_id'] : obj for obj in data['Repertoire'] }
72
73 another example with germline sets::
74
75 germline_dict = { obj['germline_set_id'] : obj for obj in data['GermlineSet'] }
76
77 Writing AIRR Data Files
78 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
79
80 Writing an AIRR Data File is also a light wrapper over standard YAML or JSON
81 parsers. Multiple AIRR objects, such as Repertoire, GermlineSet, and etc., can be
82 written together into the same file. In this example, we use the ``airr`` library ``template``
83 method to create some blank Repertoire objects, and write them to a file.
84 As with the read function, the complete list of repertoires are written at once,
85 there is no streaming interface::
86
87 import airr
88
89 # Create some blank repertoire objects in a list
90 data = { 'Repertoire': [] }
91 for i in range(5):
92 data['Repertoire'].append(airr.schema.RepertoireSchema.template())
93
94 # Write the AIRR Data
95 airr.write_airr('output.airr.json', data)
96
97 Reading AIRR Rearrangement TSV files
98 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
99
100 The ``airr`` package contains functions to read and write AIRR Rearrangement
101 TSV files as either iterables or pandas data frames. The usage is straightforward,
102 as the file format is a typical tab delimited file, but the package
103 performs some additional validation and type conversion beyond using a
104 standard CSV reader::
105
106 import airr
107
108 # Create an iteratable that returns a dictionary for each row
109 reader = airr.read_rearrangement('input.tsv')
110 for row in reader: print(row)
111
112 # Load the entire file into a pandas data frame
113 df = airr.load_rearrangement('input.tsv')
114
115 Writing AIRR Rearrangement TSV files
116 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
117
118 Similar to the read operations, write functions are provided for either creating
119 a writer class to perform row-wise output or writing the entire contents of
120 a pandas data frame to a file. Again, usage is straightforward with the ``airr``
121 output functions simply performing some type conversion and field ordering
122 operations::
123
124 import airr
125
126 # Create a writer class for iterative row output
127 writer = airr.create_rearrangement('output.tsv')
128 for row in reader: writer.write(row)
129
130 # Write an entire pandas data frame to a file
131 airr.dump_rearrangement(df, 'file.tsv')
132
133 By default, ``create_rearrangement`` will only write the ``required`` fields
134 in the output file. Additional fields can be included in the output file by
135 providing the ``fields`` parameter with an array of additional field names::
136
137 # Specify additional fields in the output
138 fields = ['new_calc', 'another_field']
139 writer = airr.create_rearrangement('output.tsv', fields=fields)
140
141 A common operation is to read an AIRR rearrangement file, and then
142 write an AIRR rearrangement file with additional fields in it while
143 keeping all of the existing fields from the original file. The
144 ``derive_rearrangement`` function provides this capability::
145
146 import airr
147
148 # Read rearrangement data and write new file with additional fields
149 reader = airr.read_rearrangement('input.tsv')
150 fields = ['new_calc']
151 writer = airr.derive_rearrangement('output.tsv', 'input.tsv', fields=fields)
152 for row in reader:
153 row['new_calc'] = 'a value'
154 writer.write(row)
155
156
157 Validating AIRR data files
158 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
159
160 The ``airr`` package can validate AIRR Data Model JSON/YAML files and Rearrangement
161 TSV files to ensure that they contain all required fields and that the fields types
162 match the AIRR Schema. This can be done using the ``airr-tools`` command
163 line program or the validate functions in the library can be called::
164
165 # Validate a rearrangement TSV file
166 airr-tools validate rearrangement -a input.tsv
167
168 # Validate an AIRR DataFile
169 airr-tools validate airr -a input.airr.json
170
171 Combining Repertoire metadata and Rearrangement files
172 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
173
174 The ``airr`` package does not currently keep track of which AIRR Data Model files
175 are associated with which Rearrangement TSV files, though there is ongoing work to define
176 a standardized manifest, so users will need to handle those
177 associations themselves. However, in the data, AIRR identifier fields, such as ``repertoire_id``,
178 form the link between objects in the AIRR Data Model.
179 The typical usage is that a program is going to perform some
180 computation on the Rearrangements, and it needs access to the Repertoire metadata
181 as part of the computation logic. This example code shows the basic framework
182 for doing that, in this case doing gender specific computation::
183
184 import airr
185
186 # Load AIRR data containing repertoires
187 data = airr.read_airr('input.airr.json')
188
189 # Put repertoires in dictionary keyed by repertoire_id
190 rep_dict = { obj['repertoire_id'] : obj for obj in data['Repertoire'] }
191
192 # Create an iteratable for rearrangement data
193 reader = airr.read_rearrangement('input.tsv')
194 for row in reader:
195 # get repertoire metadata with this rearrangement
196 rep = rep_dict[row['repertoire_id']]
197
198 # check the gender
199 if rep['subject']['sex'] == 'male':
200 # do male specific computation
201 elif rep['subject']['sex'] == 'female':
202 # do female specific computation
203 else:
204 # do other specific computation
205